Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
add sso permission to token exchange
Thiago Araujo da Silva8ed2672eb237
diff --git a/backend/CLAUDE.md b/backend/CLAUDE.mdindex 8e7aafaf6d..a0f01ba98f 100644--- a/backend/CLAUDE.md+++ b/backend/CLAUDE.md@@ -198,6 +198,13 @@ without it, any token that issuer signed for any application in the customer's eEnabling the grant or changing the audience therefore requires `OrgPermissionSsoActions.Edit` on top ofthe usual `OauthClients` check.+**That gate covers secret rotation too, and leaving it off any one path defeats it.** Rotation returns+the new secret in its response, so on an exchange application it hands the caller a working credential+for acting as any of the org's users — the same authority as enabling the grant. `OauthClients` Edit+alone would otherwise be enough to rotate an existing exchange application's secret and use it, making+the check on create/update a speed bump. Any future operation that establishes this trust or hands out a+credential for it goes through `checkSsoConfigPermission` (`oauth-client-service.ts`) as well.+**Deprecated auth modes (do not use in new code):**- **API_KEY** — user API keys (from `x-api-key` header). Deprecated — use identity access tokens instead.- **SERVICE_TOKEN** — service tokens (Bearer tokens starting with `st.` prefix). Deprecated — use identity access tokens instead.diff --git a/backend/e2e-test/routes/v1/oauth-token-exchange.spec.ts b/backend/e2e-test/routes/v1/oauth-token-exchange.spec.tsindex b26d6dc464..08d8911ac0 100644--- a/backend/e2e-test/routes/v1/oauth-token-exchange.spec.ts+++ b/backend/e2e-test/routes/v1/oauth-token-exchange.spec.ts@@ -21,6 +21,13 @@ const deleteClient = async (clientDbId: string) =>headers: { authorization: `Bearer ${jwtAuthToken}` }});+const rotateClientSecret = async (clientDbId: string) =>+ testServer.inject({+ method: "POST",+ url: `/api/v1/oauth/clients/${clientDbId}/rotate-secret`,+ headers: { authorization: `Bearer ${jwtAuthToken}` }+ });+const postToken = async (body: Record<string, string>) =>testServer.inject({method: "POST",@@ -101,6 +108,29 @@ describe("OAuth client grant type registration", async () => {expect(res.payload).toContain("audience only applies");});+ // Rotation on a token exchange application needs SSO edit permission on top of OauthClients edit, but+ // it must stay a plain OauthClients operation for every other application. The seed actor holds both+ // permissions, so this pins the non-exchange path rather than the denial.+ test("rotating a redirect-flow application's secret needs no SSO permission", async () => {+ const created = await createClient({+ name: "e2e-rotate-redirect-client",+ redirectUris: ["https://app.example.com/callback"]+ });++ const { client, clientSecret } = JSON.parse(created.payload) as {+ client: { id: string };+ clientSecret: string;+ };++ const rotated = await rotateClientSecret(client.id);++ expect(rotated.statusCode).toBe(200);+ const { clientSecret: rotatedSecret } = JSON.parse(rotated.payload) as { clientSecret: string };+ expect(rotatedSecret).not.toBe(clientSecret);++ await deleteClient(client.id);+ });+// The seed org has no OIDC config, and that config is the only trust anchor token exchange has.test("the token exchange grant cannot be enabled without an active OIDC SSO configuration", async () => {const res = await createClient({diff --git a/backend/src/services/oauth-client/oauth-client-service.ts b/backend/src/services/oauth-client/oauth-client-service.tsindex 4cb8b929ed..e7beb7a236 100644--- a/backend/src/services/oauth-client/oauth-client-service.ts+++ b/backend/src/services/oauth-client/oauth-client-service.ts@@ -12,7 +12,7 @@ import { TPermissionServiceFactory } from "@app/ee/services/permission/permissioimport { KeyStorePrefixes, KeyStoreTtls, TKeyStoreFactory } from "@app/keystore/keystore";import { getConfig } from "@app/lib/config/env";import { crypto } from "@app/lib/crypto";-import { BadRequestError, NotFoundError, UnauthorizedError } from "@app/lib/errors";+import { BadRequestError, ForbiddenRequestError, NotFoundError, UnauthorizedError } from "@app/lib/errors";import { getMinExpiresIn } from "@app/lib/fn";import { ms } from "@app/lib/ms";import { OrgServiceActor } from "@app/lib/types";@@ -147,10 +147,14 @@ export const oauthClientServiceFactory = ({ForbiddenError.from(permission).throwUnlessCan(action, OrgPermissionSubjects.OauthClients);};- // Enabling this grant, or changing the audience it accepts, decides whose externally-issued tokens- // become Infisical user tokens. That is a change to the org's federation trust, so it needs the- // permission that already owns the SSO configuration.- const checkSsoConfigPermission = async (actor: OrgServiceActor) => {+ // The token exchange grant converts externally-issued tokens into Infisical user tokens, so anything+ // that establishes that trust or hands out a working credential for it is a change to the org's+ // federation posture, not just an application edit. Those operations need the permission that already+ // owns the SSO configuration on top of the usual OauthClients check.+ //+ // `action` names the operation in the error, because the reason an OAuth application change needs SSO+ // permission is not self-evident to the admin who hits it.+ const checkSsoConfigPermission = async (actor: OrgServiceActor, action: string) => {const { permission } = await permissionService.getOrgPermission({actor: actor.type,actorId: actor.id,@@ -160,7 +164,11 @@ export const oauthClientServiceFactory = ({scope: OrganizationActionScope.ParentOrganization});- ForbiddenError.from(permission).throwUnlessCan(OrgPermissionSsoActions.Edit, OrgPermissionSubjects.Sso);+ if (permission.cannot(OrgPermissionSsoActions.Edit, OrgPermissionSubjects.Sso)) {+ throw new ForbiddenRequestError({+ message: `You do not have permission to ${action}. Applications using the '${OauthGrantType.TokenExchange}' grant turn tokens from your organization's identity provider into Infisical user tokens, so managing them also requires permission to edit the organization's SSO configuration.`+ });+ }};// Loads a client scoped to the actor's org (so one org can never address another's client) and@@ -215,7 +223,9 @@ export const oauthClientServiceFactory = ({const grantTypes = dedupeGrantTypes(dto.grantTypes);const enablesTokenExchange = hasTokenExchangeGrant(grantTypes);- if (enablesTokenExchange) await checkSsoConfigPermission(actor);+ if (enablesTokenExchange) {+ await checkSsoConfigPermission(actor, "register an OAuth application that uses token exchange");+ }assertValidOauthClientGrantConfig({grantTypes,@@ -292,7 +302,9 @@ export const oauthClientServiceFactory = ({dto.tokenExchangeAudience !== undefined ||dto.tokenExchangeIdpSatisfiesMfa !== undefined;- if (isTokenExchangeEnabled && touchesTokenExchangeConfig) await checkSsoConfigPermission(actor);+ if (isTokenExchangeEnabled && touchesTokenExchangeConfig) {+ await checkSsoConfigPermission(actor, "change the token exchange configuration of an OAuth application");+ }assertValidOauthClientGrantConfig({grantTypes,@@ -340,6 +352,10 @@ export const oauthClientServiceFactory = ({const client = await getOrgClientOrThrow(clientDbId, actor.orgId);+ if (hasTokenExchangeGrant(client.grantTypes as OauthGrantType[])) {+ await checkSsoConfigPermission(actor, "rotate the secret of an OAuth application that uses token exchange");+ }+const appCfg = getConfig();const clientSecret = crypto.randomBytes(32).toString("hex");const clientSecretHash = await crypto.hashing().createHash(clientSecret, appCfg.SALT_ROUNDS);diff --git a/docs/documentation/platform/oauth-token-exchange.mdx b/docs/documentation/platform/oauth-token-exchange.mdxindex 09e40b3529..d6429e34ce 100644--- a/docs/documentation/platform/oauth-token-exchange.mdx+++ b/docs/documentation/platform/oauth-token-exchange.mdx@@ -91,7 +91,7 @@ Two things it deliberately cannot do:## Registering your middleware-You need permission to manage both OAuth applications and SSO in the organization, because enabling token exchange decides whose externally issued tokens Infisical will convert into user tokens.+You need permission to manage both OAuth applications and SSO in the organization, because enabling token exchange decides whose externally issued tokens Infisical will convert into user tokens. The same applies to changing an existing application's audience or rotating its client secret, since either one grants the ability to act as your users.<Steps><Step title="Open the OAuth Applications page">