The Open Framework for Building Agents
fix(eve): auth - accept global Vercel OIDC issuer (#2530)
Andrew Barba7eae011d7c5c
diff --git a/.changeset/tidy-plums-travel.md b/.changeset/tidy-plums-travel.mdnew file mode 100644index 000000000..eee93f5ea--- /dev/null+++ b/.changeset/tidy-plums-travel.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Accept Vercel OIDC tokens issued from the global issuer in `vercelOidc()` and `verifyVercelOidc()`.diff --git a/packages/eve/src/channel/auth/oidc.ts b/packages/eve/src/channel/auth/oidc.tsindex ea908758e..2a716a464 100644--- a/packages/eve/src/channel/auth/oidc.ts+++ b/packages/eve/src/channel/auth/oidc.ts@@ -6,6 +6,7 @@ import {areTokenClaimMatchersSatisfied,createJwtAuthenticatedCallerPrincipal,} from "#channel/auth/token-claims.js";+import { isVercelOidcIssuer } from "#shared/vercel-project.js";import type {ResolvedOidcAuthStrategy,RouteStrategyAuthenticationResult,@@ -50,7 +51,7 @@ export async function authenticateOidcStrategy(input: {const hasExternalSubject =input.strategy.acceptCurrentVercelProject &&- input.strategy.issuer.startsWith("https://oidc.vercel.com/") &&+ isVercelOidcIssuer(input.strategy.issuer) &&verified.payload.external_sub !== undefined;if (hasExternalSubject) {if (@@ -78,7 +79,7 @@ export async function authenticateOidcStrategy(input: {const hasDevelopmentUserSubject =input.strategy.acceptCurrentVercelProject &&- input.strategy.issuer.startsWith("https://oidc.vercel.com/") &&+ isVercelOidcIssuer(input.strategy.issuer) &&verified.payload.user_id !== undefined;if (hasDevelopmentUserSubject) {if (@@ -212,7 +213,7 @@ function isCurrentVercelProjectToken(input: {readonly payload: JWTPayload;readonly strategy: ResolvedOidcAuthStrategy;}): boolean {- if (!input.issuer.startsWith("https://oidc.vercel.com")) {+ if (!isVercelOidcIssuer(input.issuer)) {return false;}diff --git a/packages/eve/src/public/channels/auth.test.ts b/packages/eve/src/public/channels/auth.test.tsindex 4d318731d..53802d543 100644--- a/packages/eve/src/public/channels/auth.test.ts+++ b/packages/eve/src/public/channels/auth.test.ts@@ -873,6 +873,19 @@ describe("verifyVercelOidc", () => {}});+ it("authenticates a current-project token from the global Vercel issuer", async () => {+ const issuer = await installMockedVercelIssuer("global-issuer", "global");+ try {+ const token = await issuer.signToken({ project_id: "prj_current" });++ await expect(+ verifyVercelOidc(token, { currentVercelProject: { projectId: "prj_current" } }),+ ).resolves.toMatchObject({ ok: true });+ } finally {+ issuer.restore();+ }+ });+it("authenticates a development Vercel user token as a user principal", async () => {vi.stubEnv("VERCEL_PROJECT_ID", "prj_current");vi.stubEnv("VERCEL_TARGET_ENV", "development");@@ -1300,7 +1313,10 @@ describe("verifyVercelOidc", () => {* jose's module-level JWKS cache (keyed on the JWKS URL) does not bleed* keys across tests when several cases run in the same file.*/-async function installMockedVercelIssuer(slug: string): Promise<{+async function installMockedVercelIssuer(+ slug: string,+ issuerMode: "global" | "team" = "team",+): Promise<{readonly issuer: string;readonly signToken: (claims: Record<string, unknown>,@@ -1309,7 +1325,8 @@ async function installMockedVercelIssuer(slug: string): Promise<{readonly restore: () => void;}> {const teamSlug = `${slug}-${crypto.randomUUID()}`;- const issuer = `https://oidc.vercel.com/${teamSlug}`;+ const issuer =+ issuerMode === "global" ? "https://oidc.vercel.com" : `https://oidc.vercel.com/${teamSlug}`;const audience = `https://vercel.com/${teamSlug}`;const jwksUrl = `${issuer}/.well-known/jwks.json`;const discoveryUrl = `${issuer}/.well-known/openid-configuration`;diff --git a/packages/eve/src/public/channels/auth.ts b/packages/eve/src/public/channels/auth.tsindex 2a256dc23..ca2487e8f 100644--- a/packages/eve/src/public/channels/auth.ts+++ b/packages/eve/src/public/channels/auth.ts@@ -22,6 +22,7 @@ import {type ResolvedOidcAuthStrategy,type RouteStrategyAuthenticationResult,} from "#channel/auth/types.js";+import { isVercelOidcIssuer } from "#shared/vercel-project.js";const vercelOidcLog = createLogger("auth.vercel-oidc");import {@@ -847,8 +848,6 @@ const LOCAL_DEV_SESSION_AUTH_CONTEXT: SessionAuthContext = {principalType: "local-dev",};-const VERCEL_OIDC_ISSUER_PREFIX = "https://oidc.vercel.com/";-/*** Expected prefix for the `aud` claim of a Vercel-minted OIDC token* (`https://vercel.com/<owner-slug>`). Requiring it gives a real audience@@ -923,7 +922,7 @@ export async function verifyVercelOidc(return { ok: false };}- if (!claims.issuer.startsWith(VERCEL_OIDC_ISSUER_PREFIX)) {+ if (!isVercelOidcIssuer(claims.issuer)) {vercelOidcLog.debug("Rejected token whose issuer is not a Vercel OIDC issuer.", {issuer: claims.issuer,});diff --git a/packages/eve/src/runtime/connections/principal.ts b/packages/eve/src/runtime/connections/principal.tsindex 51caf4625..0192ab80c 100644--- a/packages/eve/src/runtime/connections/principal.ts+++ b/packages/eve/src/runtime/connections/principal.ts@@ -14,6 +14,7 @@ import { type AlsContext, contextStorage } from "#context/container.js";import { AuthKey, type SessionAuthContext } from "#context/keys.js";import { ConnectionAuthorizationFailedError } from "#public/connections/errors.js";import type { AuthorizationDefinition, ConnectionPrincipal } from "#shared/connection-types.js";+import { isVercelOidcIssuer } from "#shared/vercel-project.js";/*** Stable string key identifying one principal within a connection's@@ -124,7 +125,7 @@ export function resolveConnectionPrincipalFromAuth(function isVercelDevelopmentUser(current: SessionAuthContext): boolean {return (current.authenticator === "oidc" &&- current.issuer?.startsWith("https://oidc.vercel.com/") === true &&+ isVercelOidcIssuer(current.issuer) &¤t.attributes.environment === "development" &¤t.subject === current.attributes.user_id);diff --git a/packages/eve/src/shared/vercel-project.ts b/packages/eve/src/shared/vercel-project.tsindex fb8f9a3fd..be5670852 100644--- a/packages/eve/src/shared/vercel-project.ts+++ b/packages/eve/src/shared/vercel-project.ts@@ -11,6 +11,11 @@ export interface VercelOidcTokenClaims {}const EMPTY_CLAIMS: VercelOidcTokenClaims = { ownerId: undefined, projectId: undefined };+const VERCEL_OIDC_ISSUER = "https://oidc.vercel.com";++export function isVercelOidcIssuer(issuer: string | undefined): boolean {+ return issuer === VERCEL_OIDC_ISSUER || issuer?.startsWith(`${VERCEL_OIDC_ISSUER}/`) === true;+}/*** Decodes the payload claims of a Vercel OIDC token. Values that are not