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
fix token issuance
Thiago Araujo da Silvab58900c67da2
diff --git a/backend/CLAUDE.md b/backend/CLAUDE.mdindex a0a284bf1d..1e00f8e627 100644--- a/backend/CLAUDE.md+++ b/backend/CLAUDE.md@@ -492,7 +492,7 @@ Built-in roles: `Admin`, `Member`, `Viewer`, `NoAccess`. Custom roles use unpack**Privilege boundaries mean different things on the two privilege systems.** `organizations.shouldUseNewPrivilegeSystem` (default `true`, backfilled `false` for orgs predating March 2025) picks which. `validatePrivilegeChangeOperation` / `assertRoleSetBoundary` (`permission-fns.ts`) are the shim: on the new system they collapse to `actorPermission.can(action, subject)`, on the legacy one they run `validatePermissionBoundary`, requiring the actor to out-rank every role the target holds. So a boundary at a call site that already gated on the same action is a no-op for new-system orgs and the only protection for legacy ones. Two consequences: "the route checks the action" is not a substitute for a boundary, and adding one is not a behavior change for most tenants. Prefer `getOrgPermissionByRoles` / `getProjectPermissionByRoles` + `assertRoleSetBoundary` over fetching the target's merged ability. It bounds each role separately, and it avoids `getProjectPermission`, which stamps whichever actor it was called for onto the request context the audit log reads.-**Identity auth-method mutations go through `assertIdentityAuthMutationAllowed`** (`src/services/identity/identity-auth-permission-fns.ts`), because repointing an identity's auth trust lets the caller authenticate as that identity. All 13 auth services call it once per attach/update/revoke, after the `throwUnlessCan` gate and outside the `identity.projectId` branch so both scopes are covered. A new auth method calls it too. The token and UA client-secret paths still carry their own inline boundary, org branch only.+**Identity auth-method mutations go through `assertIdentityAuthMutationAllowed`** (`src/services/identity/identity-auth-permission-fns.ts`), because repointing an identity's auth trust lets the caller authenticate as that identity. All 13 auth services call it once per attach/update/revoke, after the `throwUnlessCan` gate and outside the `identity.projectId` branch so both scopes are covered. A new auth method calls it too. Credential issuance (`createTokenAuthToken`, `createUniversalAuthClientSecret`) goes through it as well, under `create-token`, since minting a credential is the same escalation as repointing the trust. The remaining token read/rename/revoke paths still carry their own inline boundary, org branch only.**Project permission caching** uses a fingerprint-based two-tier cache (`withCacheFingerprint` in `src/lib/cache/with-cache.ts`):- **Short-lived marker** (10s TTL) in Redis — while present, cached data is served with 0 DB reads.diff --git a/backend/src/services/identity-token-auth/identity-token-auth-service.ts b/backend/src/services/identity-token-auth/identity-token-auth-service.tsindex 0425d357a8..882c481845 100644--- a/backend/src/services/identity-token-auth/identity-token-auth-service.ts+++ b/backend/src/services/identity-token-auth/identity-token-auth-service.ts@@ -516,38 +516,22 @@ export const identityTokenAuthServiceFactory = ({});ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Edit, OrgPermissionSubjects.Identity);+ }- const { permission: rolePermission } = await permissionService.getOrgPermission({- actor: ActorType.IDENTITY,- actorId: identityMembershipOrg.identity.id,+ await assertIdentityAuthMutationAllowed(+ { permissionService, orgDAL, membershipIdentityDAL },+ {+ identityId,orgId: identityMembershipOrg.scopeOrgId,+ projectId: identityMembershipOrg.identity.projectId,+ action: OrgPermissionIdentityActions.CreateToken,+ baseMessage: "Failed to create token for identity with more privileged role",+ actor,+ actorId,actorAuthMethod,- actorOrgId,- scope: OrganizationActionScope.Any- });-- const { shouldUseNewPrivilegeSystem } = await requestMemoize(- requestMemoKeys.orgFindById(identityMembershipOrg.scopeOrgId),- () => orgDAL.findById(identityMembershipOrg.scopeOrgId)- );- const permissionBoundary = validatePrivilegeChangeOperation(- shouldUseNewPrivilegeSystem,- OrgPermissionIdentityActions.CreateToken,- OrgPermissionSubjects.Identity,- permission,- rolePermission- );- if (!permissionBoundary.isValid)- throw new PermissionBoundaryError({- message: constructPermissionErrorMessage(- "Failed to create token for identity with more privileged role",- shouldUseNewPrivilegeSystem,- OrgPermissionIdentityActions.CreateToken,- OrgPermissionSubjects.Identity- ),- details: { missingPermissions: permissionBoundary.missingPermissions }- });- }+ actorOrgId+ }+ );await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);diff --git a/backend/src/services/identity-ua/identity-ua-service.ts b/backend/src/services/identity-ua/identity-ua-service.tsindex f076f04d70..219f9740dd 100644--- a/backend/src/services/identity-ua/identity-ua-service.ts+++ b/backend/src/services/identity-ua/identity-ua-service.ts@@ -915,37 +915,22 @@ export const identityUaServiceFactory = ({OrgPermissionIdentityActions.Create,OrgPermissionSubjects.Identity);+ }- const { permission: rolePermission } = await permissionService.getOrgPermission({- actor: ActorType.IDENTITY,- actorId: identityMembershipOrg.identity.id,+ await assertIdentityAuthMutationAllowed(+ { permissionService, orgDAL, membershipIdentityDAL },+ {+ identityId,orgId: identityMembershipOrg.scopeOrgId,+ projectId: identityMembershipOrg.identity.projectId,+ action: OrgPermissionIdentityActions.CreateToken,+ baseMessage: "Failed to create client secret for identity with more privileged role",+ actor,+ actorId,actorAuthMethod,- actorOrgId,- scope: OrganizationActionScope.Any- });- const { shouldUseNewPrivilegeSystem } = await requestMemoize(- requestMemoKeys.orgFindById(identityMembershipOrg.scopeOrgId),- () => orgDAL.findById(identityMembershipOrg.scopeOrgId)- );- const permissionBoundary = validatePrivilegeChangeOperation(- shouldUseNewPrivilegeSystem,- OrgPermissionIdentityActions.CreateToken,- OrgPermissionSubjects.Identity,- permission,- rolePermission- );- if (!permissionBoundary.isValid)- throw new PermissionBoundaryError({- message: constructPermissionErrorMessage(- "Failed to create client secret for identity.",- shouldUseNewPrivilegeSystem,- OrgPermissionIdentityActions.CreateToken,- OrgPermissionSubjects.Identity- ),- details: { missingPermissions: permissionBoundary.missingPermissions }- });- }+ actorOrgId+ }+ );await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);diff --git a/backend/src/services/identity/identity-auth-permission-fns.test.ts b/backend/src/services/identity/identity-auth-permission-fns.test.tsindex b8eb6a02c7..a8b7db5b0c 100644--- a/backend/src/services/identity/identity-auth-permission-fns.test.ts+++ b/backend/src/services/identity/identity-auth-permission-fns.test.ts@@ -37,6 +37,9 @@ const projectMember = createMongoAbility<MongoAbility<ProjectPermissionSet>>(proconst projectEditAuthOnly = createMongoAbility<MongoAbility<ProjectPermissionSet>>([{ action: ProjectPermissionIdentityActions.EditAuth, subject: ProjectPermissionSub.Identity }]);+const projectCreateTokenOnly = createMongoAbility<MongoAbility<ProjectPermissionSet>>([+ { action: ProjectPermissionIdentityActions.CreateToken, subject: ProjectPermissionSub.Identity }+]);type TScopeCall = { scope: AccessScope; orgId: string; projectId?: string };@@ -45,6 +48,7 @@ const runBoundary = async ({actorPermission,targetPermissions,projectId,+ action = OrgPermissionIdentityActions.EditAuth,scopeCalls = [],roleLookups = []}: {@@ -52,6 +56,7 @@ const runBoundary = async ({actorPermission: MongoAbility;targetPermissions: MongoAbility[];projectId?: string;+ action?: OrgPermissionIdentityActions.EditAuth | OrgPermissionIdentityActions.CreateToken;scopeCalls?: TScopeCall[];roleLookups?: string[];}) => {@@ -81,7 +86,7 @@ const runBoundary = async ({identityId: "identity-1",orgId: "org-1",projectId,- action: OrgPermissionIdentityActions.EditAuth,+ action,baseMessage: "Failed to add token auth to identity with more privileged role",actor: ActorType.USER,actorId: "user-1",@@ -203,4 +208,42 @@ describe("assertIdentityAuthMutationAllowed", () => {expect(roleLookups).toEqual([]);});});++ describe("credential issuance", () => {+ test("a create-token-only actor may not mint a credential for an admin identity", async () => {+ await expect(+ runBoundary({+ actorPermission: projectCreateTokenOnly,+ targetPermissions: [projectAdmin],+ projectId: "project-1",+ action: OrgPermissionIdentityActions.CreateToken+ })+ ).rejects.toThrow(PermissionBoundaryError);+ await expect(+ runBoundary({+ actorPermission: orgMember,+ targetPermissions: [orgAdmin],+ action: OrgPermissionIdentityActions.CreateToken+ })+ ).rejects.toThrow(PermissionBoundaryError);+ });++ test("an admin actor may mint a credential for a member identity", async () => {+ await expect(+ runBoundary({+ actorPermission: projectAdmin,+ targetPermissions: [projectMember],+ projectId: "project-1",+ action: OrgPermissionIdentityActions.CreateToken+ })+ ).resolves.toBeUndefined();+ await expect(+ runBoundary({+ actorPermission: orgAdmin,+ targetPermissions: [orgMember],+ action: OrgPermissionIdentityActions.CreateToken+ })+ ).resolves.toBeUndefined();+ });+ });});diff --git a/backend/src/services/identity/identity-auth-permission-fns.ts b/backend/src/services/identity/identity-auth-permission-fns.tsindex af16053faa..0199329ac6 100644--- a/backend/src/services/identity/identity-auth-permission-fns.ts+++ b/backend/src/services/identity/identity-auth-permission-fns.ts@@ -12,7 +12,8 @@ import { TOrgDALFactory } from "@app/services/org/org-dal";const PROJECT_ACTION_BY_ORG_ACTION = {[OrgPermissionIdentityActions.EditAuth]: ProjectPermissionIdentityActions.EditAuth,- [OrgPermissionIdentityActions.RevokeAuth]: ProjectPermissionIdentityActions.RevokeAuth+ [OrgPermissionIdentityActions.RevokeAuth]: ProjectPermissionIdentityActions.RevokeAuth,+ [OrgPermissionIdentityActions.CreateToken]: ProjectPermissionIdentityActions.CreateToken} as const;type TIdentityAuthPermissionDeps = {@@ -36,8 +37,8 @@ type TAssertIdentityAuthMutationAllowedDTO = {actorOrgId: string;};-// Repointing an identity's auth trust lets you authenticate as that identity, so the actor has to-// out-rank every role the target holds. Only bites on the legacy privilege system: on the new one+// Repointing an identity's auth trust, or minting a credential for it, lets you authenticate as that+// identity, so the actor has to out-rank every role the target holds. Only bites on the legacy privilege system: on the new one// `assertRoleSetBoundary` reduces to the action check the caller already ran.export const assertIdentityAuthMutationAllowed = async ({ permissionService, orgDAL, membershipIdentityDAL }: TIdentityAuthPermissionDeps,