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
check additional privilages
Thiago Araujo da Silvaf9c3801645e6
diff --git a/backend/CLAUDE.md b/backend/CLAUDE.mdindex 5307686411..f5e0ea98e4 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. 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. The target's roles come from `permissionService.getActorRoleSlugs`, not from a membership lookup: a group-derived membership carries a NULL `actorIdentityId`, so `membershipIdentityDAL.getIdentityById` under-reports the target and would let a weaker actor repoint an identity that outranks it through a group. `getActorRoleSlugs` wraps the same `permissionDAL.getPermission` query the ability itself is built from, so the bounded set cannot drift from the effective one.+**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. The target's grants come from `permissionService.getActorGrantAbilities`, not from a membership lookup, and it returns one ability per grant rather than per role. Two things a role-slug resolver misses: a group-derived membership carries a NULL `actorIdentityId`, so `membershipIdentityDAL.getIdentityById` never sees it, and an additional privilege carries a raw permission blob with no slug at all, so no `*PermissionByRoles` path can express it. Either omission clears an actor that out-ranks the target's direct roles but not its effective access. `getActorGrantAbilities` reads the same `permissionDAL.getPermission` query the ability itself is built from, so the bounded set cannot drift from the effective one.**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/ee/services/permission/actor-grant-abilities.test.ts b/backend/src/ee/services/permission/actor-grant-abilities.test.tsnew file mode 100644index 0000000000..78dc696a0f--- /dev/null+++ b/backend/src/ee/services/permission/actor-grant-abilities.test.ts@@ -0,0 +1,119 @@+import { packRules } from "@casl/ability/extra";+import { vi } from "vitest";++import { AccessScope, OrgMembershipRole } from "@app/db/schemas";+import { ActorType } from "@app/services/auth/auth-type";++import { OrgPermissionIdentityActions, OrgPermissionSubjects } from "./org-permission";+import { permissionServiceFactory } from "./permission-service";++// Privilege boundaries compare the actor against every grant the target holds. An additional+// privilege carries a raw permission blob and no role slug, so a resolver that walked only+// `membership.roles` would leave it out and clear an actor that out-ranks the target's roles but+// not its grants. Group-inherited roles ride in on the same query, as ordinary membership rows.++const ELEVATED_PRIVILEGE = packRules([+ { subject: OrgPermissionSubjects.Identity, action: [OrgPermissionIdentityActions.EditAuth] }+]);++const createService = (memberships: unknown[]) => {+ const permissionDAL = { getPermission: vi.fn().mockResolvedValue(memberships) };++ const service = permissionServiceFactory({+ permissionDAL,+ roleDAL: { find: vi.fn().mockResolvedValue([]) },+ projectDAL: {} as never,+ serviceTokenDAL: {} as never,+ keyStore: {} as never,+ userDAL: {} as never,+ identityDAL: {} as never,+ additionalPrivilegeDAL: {} as never,+ groupDAL: {} as never,+ secretFolderDAL: {} as never+ } as never);++ return { service, permissionDAL };+};++const orgScope = { scope: AccessScope.Organization, orgId: "org-1" } as const;++describe("getActorGrantAbilities", () => {+ test("returns one ability per role the target holds", async () => {+ const { service } = createService([+ { roles: [{ role: OrgMembershipRole.Member }, { role: OrgMembershipRole.Admin }], additionalPrivileges: [] }+ ]);++ const grants = await service.getActorGrantAbilities({+ scopeData: orgScope,+ actorId: "identity-1",+ actorType: ActorType.IDENTITY+ });++ expect(grants).toHaveLength(2);+ });++ test("a role inherited through a group is returned like a direct one", async () => {+ const { service, permissionDAL } = createService([+ { actorIdentityId: "identity-1", roles: [{ role: OrgMembershipRole.Member }], additionalPrivileges: [] },+ { actorGroupId: "group-1", roles: [{ role: OrgMembershipRole.Admin }], additionalPrivileges: [] }+ ]);++ const grants = await service.getActorGrantAbilities({+ scopeData: orgScope,+ actorId: "identity-1",+ actorType: ActorType.IDENTITY+ });++ expect(grants).toHaveLength(2);+ expect(permissionDAL.getPermission).toHaveBeenCalledWith({+ scopeData: orgScope,+ actorId: "identity-1",+ actorType: ActorType.IDENTITY+ });+ });++ test("an additional privilege is returned as its own ability", async () => {+ const { service } = createService([+ {+ roles: [{ role: OrgMembershipRole.Member }],+ additionalPrivileges: [{ permissions: ELEVATED_PRIVILEGE }]+ }+ ]);++ const grants = await service.getActorGrantAbilities({+ scopeData: orgScope,+ actorId: "identity-1",+ actorType: ActorType.IDENTITY+ });++ expect(grants).toHaveLength(2);+ expect(+ grants.some((grant) =>+ grant.permission.can(OrgPermissionIdentityActions.EditAuth, OrgPermissionSubjects.Identity)+ )+ ).toBe(true);+ });++ test("an expired additional privilege is left out", async () => {+ const { service } = createService([+ {+ roles: [{ role: OrgMembershipRole.Member }],+ additionalPrivileges: [+ {+ permissions: ELEVATED_PRIVILEGE,+ isTemporary: true,+ temporaryAccessEndTime: new Date(Date.now() - 1000)+ }+ ]+ }+ ]);++ const grants = await service.getActorGrantAbilities({+ scopeData: orgScope,+ actorId: "identity-1",+ actorType: ActorType.IDENTITY+ });++ expect(grants).toHaveLength(1);+ });+});diff --git a/backend/src/ee/services/permission/permission-service-types.ts b/backend/src/ee/services/permission/permission-service-types.tsindex 81dd9f25f3..26d629c947 100644--- a/backend/src/ee/services/permission/permission-service-types.ts+++ b/backend/src/ee/services/permission/permission-service-types.ts@@ -212,11 +212,11 @@ export type TPermissionServiceFactory = {projectId: string;checkPermissions: ProjectPermissionSet;}) => Promise<boolean>;- getActorRoleSlugs: (arg: {+ getActorGrantAbilities: (arg: {scopeData: AccessScopeData;actorId: string;actorType: ActorType.USER | ActorType.IDENTITY;- }) => Promise<string[]>;+ }) => Promise<{ permission: MongoAbility }[]>;getMembershipPermissionAudit: (arg: TGetMembershipPermissionAuditArg) => Promise<{sources: TPermissionAuditSource[];}>;diff --git a/backend/src/ee/services/permission/permission-service.ts b/backend/src/ee/services/permission/permission-service.tsindex 4e1f496ecc..d0120e300b 100644--- a/backend/src/ee/services/permission/permission-service.ts+++ b/backend/src/ee/services/permission/permission-service.ts@@ -1198,13 +1198,34 @@ export const permissionServiceFactory = ({return sources;};- const getActorRoleSlugs: TPermissionServiceFactory["getActorRoleSlugs"] = async ({+ const getActorGrantAbilities: TPermissionServiceFactory["getActorGrantAbilities"] = async ({scopeData,actorId,actorType}) => {const memberships = await permissionDAL.getPermission({ scopeData, actorId, actorType });- return resolveMembershipRoleSlugs(memberships.flatMap((membership) => membership.roles));+ const roleSlugs = resolveMembershipRoleSlugs(memberships.flatMap((membership) => membership.roles));+ const isProjectScope = scopeData.scope === AccessScope.Project;++ const rolePermissions = isProjectScope+ ? await getProjectPermissionByRoles(roleSlugs, scopeData.projectId, { ignoreUnresolvedRoles: true })+ : await getOrgPermissionByRoles(roleSlugs, scopeData.orgId, { ignoreUnresolvedRoles: true });++ const privilegePermissions = memberships.flatMap((membership) =>+ (membership.additionalPrivileges ?? []).filter(isActiveRole).map(({ permissions }) => ({+ permission: isProjectScope+ ? createMongoAbility<ProjectPermissionSet>(+ buildProjectPermissionRules([{ role: ProjectMembershipRole.Custom, permissions: permissions || [] }]),+ { conditionsMatcher }+ )+ : createMongoAbility<OrgPermissionSet>(+ buildOrgPermissionRules([{ role: OrgMembershipRole.Custom, permissions: permissions || [] }]),+ { conditionsMatcher }+ )+ }))+ );++ return [...rolePermissions.map(({ permission }) => ({ permission })), ...privilegePermissions];};const getMembershipPermissionAudit: TPermissionServiceFactory["getMembershipPermissionAudit"] = async ({@@ -1436,7 +1457,7 @@ export const permissionServiceFactory = ({getOrgPermissionByRoles,getProjectPermissionByRoles,checkGroupProjectPermission,- getActorRoleSlugs,+ getActorGrantAbilities,getMembershipPermissionAudit,getIdentityPermissionAudit,invalidateProjectFolderPermissionCache,diff --git a/backend/src/services/identity-alicloud-auth/identity-alicloud-auth-service.ts b/backend/src/services/identity-alicloud-auth/identity-alicloud-auth-service.tsindex 43a9cede88..7acc129d2d 100644--- a/backend/src/services/identity-alicloud-auth/identity-alicloud-auth-service.ts+++ b/backend/src/services/identity-alicloud-auth/identity-alicloud-auth-service.ts@@ -55,11 +55,7 @@ type TIdentityAliCloudAuthServiceFactoryDep = {licenseService: Pick<TLicenseServiceFactory, "getPlan">;permissionService: Pick<TPermissionServiceFactory,- | "getOrgPermission"- | "getProjectPermission"- | "getOrgPermissionByRoles"- | "getProjectPermissionByRoles"- | "getActorRoleSlugs"+ "getOrgPermission" | "getProjectPermission" | "getActorGrantAbilities">;orgDAL: Pick<TOrgDALFactory, "findById" | "findOne" | "findEffectiveOrgMembership">;identityAccessTokenService: Pick<diff --git a/backend/src/services/identity-aws-auth/identity-aws-auth-service.ts b/backend/src/services/identity-aws-auth/identity-aws-auth-service.tsindex 0b85be3c25..880e0f9040 100644--- a/backend/src/services/identity-aws-auth/identity-aws-auth-service.ts+++ b/backend/src/services/identity-aws-auth/identity-aws-auth-service.ts@@ -55,11 +55,7 @@ type TIdentityAwsAuthServiceFactoryDep = {licenseService: Pick<TLicenseServiceFactory, "getPlan">;permissionService: Pick<TPermissionServiceFactory,- | "getOrgPermission"- | "getProjectPermission"- | "getOrgPermissionByRoles"- | "getProjectPermissionByRoles"- | "getActorRoleSlugs"+ "getOrgPermission" | "getProjectPermission" | "getActorGrantAbilities">;orgDAL: Pick<TOrgDALFactory, "findById" | "findOne" | "findEffectiveOrgMembership">;identityAccessTokenService: Pick<diff --git a/backend/src/services/identity-azure-auth/identity-azure-auth-service.ts b/backend/src/services/identity-azure-auth/identity-azure-auth-service.tsindex 6b31f84008..f1c9b28278 100644--- a/backend/src/services/identity-azure-auth/identity-azure-auth-service.ts+++ b/backend/src/services/identity-azure-auth/identity-azure-auth-service.ts@@ -50,11 +50,7 @@ type TIdentityAzureAuthServiceFactoryDep = {identityAccessTokenDAL: Pick<TIdentityAccessTokenDALFactory, "delete">;permissionService: Pick<TPermissionServiceFactory,- | "getOrgPermission"- | "getProjectPermission"- | "getOrgPermissionByRoles"- | "getProjectPermissionByRoles"- | "getActorRoleSlugs"+ "getOrgPermission" | "getProjectPermission" | "getActorGrantAbilities">;licenseService: Pick<TLicenseServiceFactory, "getPlan">;orgDAL: Pick<TOrgDALFactory, "findById" | "findOne" | "findEffectiveOrgMembership">;diff --git a/backend/src/services/identity-gcp-auth/identity-gcp-auth-service.ts b/backend/src/services/identity-gcp-auth/identity-gcp-auth-service.tsindex 608595257b..a3252d2396 100644--- a/backend/src/services/identity-gcp-auth/identity-gcp-auth-service.ts+++ b/backend/src/services/identity-gcp-auth/identity-gcp-auth-service.ts@@ -48,11 +48,7 @@ type TIdentityGcpAuthServiceFactoryDep = {identityAccessTokenDAL: Pick<TIdentityAccessTokenDALFactory, "delete">;permissionService: Pick<TPermissionServiceFactory,- | "getOrgPermission"- | "getProjectPermission"- | "getOrgPermissionByRoles"- | "getProjectPermissionByRoles"- | "getActorRoleSlugs"+ "getOrgPermission" | "getProjectPermission" | "getActorGrantAbilities">;licenseService: Pick<TLicenseServiceFactory, "getPlan">;orgDAL: Pick<TOrgDALFactory, "findById" | "findOne" | "findEffectiveOrgMembership">;diff --git a/backend/src/services/identity-jwt-auth/identity-jwt-auth-service.ts b/backend/src/services/identity-jwt-auth/identity-jwt-auth-service.tsindex e1fcb67736..55ff84d3df 100644--- a/backend/src/services/identity-jwt-auth/identity-jwt-auth-service.ts+++ b/backend/src/services/identity-jwt-auth/identity-jwt-auth-service.ts@@ -62,11 +62,7 @@ type TIdentityJwtAuthServiceFactoryDep = {identityAccessTokenDAL: Pick<TIdentityAccessTokenDALFactory, "delete">;permissionService: Pick<TPermissionServiceFactory,- | "getOrgPermission"- | "getProjectPermission"- | "getOrgPermissionByRoles"- | "getProjectPermissionByRoles"- | "getActorRoleSlugs"+ "getOrgPermission" | "getProjectPermission" | "getActorGrantAbilities">;licenseService: Pick<TLicenseServiceFactory, "getPlan">;kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;diff --git a/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts b/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.tsindex 37e7735886..4fd508026a 100644--- a/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts+++ b/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts@@ -106,11 +106,7 @@ type TIdentityKubernetesAuthServiceFactoryDep = {keyStore: Pick<TKeyStoreFactory, "setItemWithExpiryNX">;permissionService: Pick<TPermissionServiceFactory,- | "getOrgPermission"- | "getProjectPermission"- | "getOrgPermissionByRoles"- | "getProjectPermissionByRoles"- | "getActorRoleSlugs"+ "getOrgPermission" | "getProjectPermission" | "getActorGrantAbilities">;licenseService: Pick<TLicenseServiceFactory, "getPlan">;kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;diff --git a/backend/src/services/identity-ldap-auth/identity-ldap-auth-service.ts b/backend/src/services/identity-ldap-auth/identity-ldap-auth-service.tsindex 95bbadf71d..17a45297a7 100644--- a/backend/src/services/identity-ldap-auth/identity-ldap-auth-service.ts+++ b/backend/src/services/identity-ldap-auth/identity-ldap-auth-service.ts@@ -76,11 +76,7 @@ type TIdentityLdapAuthServiceFactoryDep = {licenseService: Pick<TLicenseServiceFactory, "getPlan">;permissionService: Pick<TPermissionServiceFactory,- | "getOrgPermission"- | "getProjectPermission"- | "getOrgPermissionByRoles"- | "getProjectPermissionByRoles"- | "getActorRoleSlugs"+ "getOrgPermission" | "getProjectPermission" | "getActorGrantAbilities">;kmsService: TKmsServiceFactory;identityDAL: Pick<TIdentityDALFactory, "findById" | "findOne">;diff --git a/backend/src/services/identity-oci-auth/identity-oci-auth-service.ts b/backend/src/services/identity-oci-auth/identity-oci-auth-service.tsindex 7e12c371f6..f1ec64634e 100644--- a/backend/src/services/identity-oci-auth/identity-oci-auth-service.ts+++ b/backend/src/services/identity-oci-auth/identity-oci-auth-service.ts@@ -53,11 +53,7 @@ type TIdentityOciAuthServiceFactoryDep = {licenseService: Pick<TLicenseServiceFactory, "getPlan">;permissionService: Pick<TPermissionServiceFactory,- | "getOrgPermission"- | "getProjectPermission"- | "getOrgPermissionByRoles"- | "getProjectPermissionByRoles"- | "getActorRoleSlugs"+ "getOrgPermission" | "getProjectPermission" | "getActorGrantAbilities">;orgDAL: Pick<TOrgDALFactory, "findById" | "findOne" | "findEffectiveOrgMembership">;identityAccessTokenService: Pick<diff --git a/backend/src/services/identity-oidc-auth/identity-oidc-auth-service.ts b/backend/src/services/identity-oidc-auth/identity-oidc-auth-service.tsindex 387db8460c..4a6b47c330 100644--- a/backend/src/services/identity-oidc-auth/identity-oidc-auth-service.ts+++ b/backend/src/services/identity-oidc-auth/identity-oidc-auth-service.ts@@ -72,11 +72,7 @@ type TIdentityOidcAuthServiceFactoryDep = {identityAccessTokenDAL: Pick<TIdentityAccessTokenDALFactory, "delete">;permissionService: Pick<TPermissionServiceFactory,- | "getOrgPermission"- | "getProjectPermission"- | "getOrgPermissionByRoles"- | "getProjectPermissionByRoles"- | "getActorRoleSlugs"+ "getOrgPermission" | "getProjectPermission" | "getActorGrantAbilities">;licenseService: Pick<TLicenseServiceFactory, "getPlan">;kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;diff --git a/backend/src/services/identity-spiffe-auth/identity-spiffe-auth-service.ts b/backend/src/services/identity-spiffe-auth/identity-spiffe-auth-service.tsindex 560b0325ba..62878bd33f 100644--- a/backend/src/services/identity-spiffe-auth/identity-spiffe-auth-service.ts+++ b/backend/src/services/identity-spiffe-auth/identity-spiffe-auth-service.ts@@ -68,11 +68,7 @@ type TIdentitySpiffeAuthServiceFactoryDep = {identityAccessTokenDAL: Pick<TIdentityAccessTokenDALFactory, "delete">;permissionService: Pick<TPermissionServiceFactory,- | "getOrgPermission"- | "getProjectPermission"- | "getOrgPermissionByRoles"- | "getProjectPermissionByRoles"- | "getActorRoleSlugs"+ "getOrgPermission" | "getProjectPermission" | "getActorGrantAbilities">;licenseService: Pick<TLicenseServiceFactory, "getPlan">;kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;diff --git a/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-service.ts b/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-service.tsindex 660997b92b..a91dfdc485 100644--- a/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-service.ts+++ b/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-service.ts@@ -171,11 +171,7 @@ type TIdentityTlsCertAuthServiceFactoryDep = {licenseService: Pick<TLicenseServiceFactory, "getPlan">;permissionService: Pick<TPermissionServiceFactory,- | "getOrgPermission"- | "getProjectPermission"- | "getOrgPermissionByRoles"- | "getProjectPermissionByRoles"- | "getActorRoleSlugs"+ "getOrgPermission" | "getProjectPermission" | "getActorGrantAbilities">;kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;orgDAL: Pick<TOrgDALFactory, "findById" | "findOne" | "findEffectiveOrgMembership">;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 5a8448c255..e7b3b2695c 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@@ -69,11 +69,7 @@ type TIdentityTokenAuthServiceFactoryDep = {>;permissionService: Pick<TPermissionServiceFactory,- | "getOrgPermission"- | "getProjectPermission"- | "getOrgPermissionByRoles"- | "getProjectPermissionByRoles"- | "getActorRoleSlugs"+ "getOrgPermission" | "getProjectPermission" | "getActorGrantAbilities">;licenseService: Pick<TLicenseServiceFactory, "getPlan">;orgDAL: Pick<TOrgDALFactory, "findById" | "findOne" | "findEffectiveOrgMembership">;diff --git a/backend/src/services/identity-ua/identity-ua-service.ts b/backend/src/services/identity-ua/identity-ua-service.tsindex 584cb56f35..755a0b01e6 100644--- a/backend/src/services/identity-ua/identity-ua-service.ts+++ b/backend/src/services/identity-ua/identity-ua-service.ts@@ -70,11 +70,7 @@ type TIdentityUaServiceFactoryDep = {membershipIdentityDAL: TMembershipIdentityDALFactory;permissionService: Pick<TPermissionServiceFactory,- | "getOrgPermission"- | "getProjectPermission"- | "getOrgPermissionByRoles"- | "getProjectPermissionByRoles"- | "getActorRoleSlugs"+ "getOrgPermission" | "getProjectPermission" | "getActorGrantAbilities">;licenseService: Pick<TLicenseServiceFactory, "getPlan">;orgDAL: Pick<TOrgDALFactory, "findById" | "findOne" | "findEffectiveOrgMembership">;diff --git a/backend/src/services/identity/identity-auth-permission-fns.test.ts b/backend/src/services/identity/identity-auth-permission-fns.test.tsindex b0e06d937c..c4c399c094 100644--- a/backend/src/services/identity/identity-auth-permission-fns.test.ts+++ b/backend/src/services/identity/identity-auth-permission-fns.test.ts@@ -23,9 +23,9 @@ import { assertIdentityAuthMutationAllowed } from "./identity-auth-permission-fn// carried none, and revoke carried one only on its org branch, so on the legacy privilege system a// principal holding `edit-auth` could repoint an identity that outranks it and authenticate as it.// `orgEditAuthOnly` models the actor that made this reachable: a custom role with `edit-auth` but-// not full admin. The target's role set comes from `getActorRoleSlugs`, which reads the same-// group-aware membership query the ability is built from, so a role held only through an identity-// group is bounded like a direct one.+// not full admin. The target's grants come from `getActorGrantAbilities`, which reads the same+// membership query the ability is built from, so a role held only through an identity group, and an+// additional privilege carrying no role slug at all, are each bounded like a direct role.const orgAdmin = createMongoAbility<MongoAbility<OrgPermissionSet>>(orgAdminPermissions);const orgMember = createMongoAbility<MongoAbility<OrgPermissionSet>>(orgMemberPermissions);@@ -54,8 +54,6 @@ const runBoundary = async ({action = OrgPermissionIdentityActions.EditAuth,scopeCalls = [],roleLookups = [],- targetRoles = ["member"],- resolvedRoles = [],principals = []}: {shouldUseNewPrivilegeSystem?: boolean;@@ -65,30 +63,20 @@ const runBoundary = async ({action?: OrgPermissionIdentityActions.EditAuth | OrgPermissionIdentityActions.CreateToken;scopeCalls?: TScopeCall[];roleLookups?: string[];- targetRoles?: string[];- resolvedRoles?: string[][];principals?: TPrincipal[];}) => {const deps = {permissionService: {getOrgPermission: () => Promise.resolve({ permission: actorPermission }),getProjectPermission: () => Promise.resolve({ permission: actorPermission }),- getOrgPermissionByRoles: (roles: string[]) => {- roleLookups.push("org");- resolvedRoles.push(roles);- return Promise.resolve(targetPermissions.map((permission) => ({ permission })));- },- getProjectPermissionByRoles: (roles: string[]) => {- roleLookups.push("project");- resolvedRoles.push(roles);- return Promise.resolve(targetPermissions.map((permission) => ({ permission })));- },- // Stands in for permissionDAL.getPermission, which returns direct and group-derived- // memberships together, so a group-inherited role is indistinguishable from a direct one here.- getActorRoleSlugs: ({ scopeData, actorId, actorType }: { scopeData: TScopeCall } & TPrincipal) => {+ // One ability per grant the target holds. The real implementation sources these from+ // permissionDAL.getPermission, so direct roles, group-inherited roles and additional+ // privileges are indistinguishable from each other by the time they reach the boundary.+ getActorGrantAbilities: ({ scopeData, actorId, actorType }: { scopeData: TScopeCall } & TPrincipal) => {scopeCalls.push(scopeData);principals.push({ actorId, actorType });- return Promise.resolve(targetRoles);+ roleLookups.push(scopeData.projectId ? "project" : "org");+ return Promise.resolve(targetPermissions.map((permission) => ({ permission })));}},orgDAL: { findById: () => Promise.resolve({ shouldUseNewPrivilegeSystem }) }@@ -142,19 +130,6 @@ describe("assertIdentityAuthMutationAllowed", () => {expect(principals).toEqual([{ actorId: "identity-1", actorType: ActorType.IDENTITY }]);});- test("the whole effective role set is forwarded, group-inherited roles included", async () => {- const resolvedRoles: string[][] = [];- await expect(- runBoundary({- actorPermission: orgEditAuthOnly,- targetPermissions: [orgAdmin],- targetRoles: ["member", "admin"],- resolvedRoles- })- ).rejects.toThrow(PermissionBoundaryError);- expect(resolvedRoles).toEqual([["member", "admin"]]);- });-test("holding the action is sufficient under the new privilege system", async () => {await expect(runBoundary({diff --git a/backend/src/services/identity/identity-auth-permission-fns.ts b/backend/src/services/identity/identity-auth-permission-fns.tsindex 5530629c84..93dd44b353 100644--- a/backend/src/services/identity/identity-auth-permission-fns.ts+++ b/backend/src/services/identity/identity-auth-permission-fns.ts@@ -17,11 +17,7 @@ const PROJECT_ACTION_BY_ORG_ACTION = {type TIdentityAuthPermissionDeps = {permissionService: Pick<TPermissionServiceFactory,- | "getOrgPermission"- | "getProjectPermission"- | "getOrgPermissionByRoles"- | "getProjectPermissionByRoles"- | "getActorRoleSlugs"+ "getOrgPermission" | "getProjectPermission" | "getActorGrantAbilities">;orgDAL: Pick<TOrgDALFactory, "findById">;};@@ -62,19 +58,13 @@ export const assertIdentityAuthMutationAllowed = async (const resolveTargetPermissions = async () => {if (shouldUseNewPrivilegeSystem) return [];- const targetRoles = await permissionService.getActorRoleSlugs({+ return permissionService.getActorGrantAbilities({scopeData: projectId? { scope: AccessScope.Project, orgId, projectId }: { scope: AccessScope.Organization, orgId },actorId: identityId,actorType: ActorType.IDENTITY});-- const rolePermissions = projectId- ? await permissionService.getProjectPermissionByRoles(targetRoles, projectId, { ignoreUnresolvedRoles: true })- : await permissionService.getOrgPermissionByRoles(targetRoles, orgId, { ignoreUnresolvedRoles: true });-- return rolePermissions.map(({ permission: rolePermission }) => ({ permission: rolePermission }));};if (projectId) {