Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

take group inheritence into account

Thiago Araujo da Silvad660760b0863
diff --git a/backend/CLAUDE.md b/backend/CLAUDE.md
index 1e00f8e627..5307686411 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.
+**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.
**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/permission-service-types.ts b/backend/src/ee/services/permission/permission-service-types.ts
index fbeba9b91a..81dd9f25f3 100644
--- a/backend/src/ee/services/permission/permission-service-types.ts
+++ b/backend/src/ee/services/permission/permission-service-types.ts
@@ -3,7 +3,13 @@ import { PackRule } from "@casl/ability/extra";
import { MongoQuery } from "@ucast/mongo2js";
import { Knex } from "knex";
-import { ActionProjectType, OrganizationActionScope, ResourceType, TMemberships } from "@app/db/schemas";
+import {
+ AccessScopeData,
+ ActionProjectType,
+ OrganizationActionScope,
+ ResourceType,
+ TMemberships
+} from "@app/db/schemas";
import { ActorAuthMethod, ActorType } from "@app/services/auth/auth-type";
import { OrgPermissionSet } from "./org-permission";
@@ -206,6 +212,11 @@ export type TPermissionServiceFactory = {
projectId: string;
checkPermissions: ProjectPermissionSet;
}) => Promise<boolean>;
+ getActorRoleSlugs: (arg: {
+ scopeData: AccessScopeData;
+ actorId: string;
+ actorType: ActorType.USER | ActorType.IDENTITY;
+ }) => Promise<string[]>;
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.ts
index 1838e00b63..4e1f496ecc 100644
--- a/backend/src/ee/services/permission/permission-service.ts
+++ b/backend/src/ee/services/permission/permission-service.ts
@@ -50,6 +50,7 @@ import { requestMemoize } from "@app/lib/request-context/request-memoizer";
import { TAdditionalPrivilegeDALFactory } from "@app/services/additional-privilege/additional-privilege-dal";
import { ActorType } from "@app/services/auth/auth-type";
import { TIdentityDALFactory } from "@app/services/identity/identity-dal";
+import { resolveMembershipRoleSlugs } from "@app/services/membership/membership-fns";
import {
applyOauthScopeToOrgRules,
applyOauthScopeToProjectRules,
@@ -1197,6 +1198,15 @@ export const permissionServiceFactory = ({
return sources;
};
+ const getActorRoleSlugs: TPermissionServiceFactory["getActorRoleSlugs"] = async ({
+ scopeData,
+ actorId,
+ actorType
+ }) => {
+ const memberships = await permissionDAL.getPermission({ scopeData, actorId, actorType });
+ return resolveMembershipRoleSlugs(memberships.flatMap((membership) => membership.roles));
+ };
+
const getMembershipPermissionAudit: TPermissionServiceFactory["getMembershipPermissionAudit"] = async ({
actor,
actorId,
@@ -1426,6 +1436,7 @@ export const permissionServiceFactory = ({
getOrgPermissionByRoles,
getProjectPermissionByRoles,
checkGroupProjectPermission,
+ getActorRoleSlugs,
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.ts
index 73fb6311ba..43a9cede88 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,7 +55,11 @@ type TIdentityAliCloudAuthServiceFactoryDep = {
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
permissionService: Pick<
TPermissionServiceFactory,
- "getOrgPermission" | "getProjectPermission" | "getOrgPermissionByRoles" | "getProjectPermissionByRoles"
+ | "getOrgPermission"
+ | "getProjectPermission"
+ | "getOrgPermissionByRoles"
+ | "getProjectPermissionByRoles"
+ | "getActorRoleSlugs"
>;
orgDAL: Pick<TOrgDALFactory, "findById" | "findOne" | "findEffectiveOrgMembership">;
identityAccessTokenService: Pick<
@@ -307,7 +311,7 @@ export const identityAliCloudAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
@@ -430,7 +434,7 @@ export const identityAliCloudAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
@@ -578,7 +582,7 @@ export const identityAliCloudAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
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.ts
index 0ad9fc60ce..0b85be3c25 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,7 +55,11 @@ type TIdentityAwsAuthServiceFactoryDep = {
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
permissionService: Pick<
TPermissionServiceFactory,
- "getOrgPermission" | "getProjectPermission" | "getOrgPermissionByRoles" | "getProjectPermissionByRoles"
+ | "getOrgPermission"
+ | "getProjectPermission"
+ | "getOrgPermissionByRoles"
+ | "getProjectPermissionByRoles"
+ | "getActorRoleSlugs"
>;
orgDAL: Pick<TOrgDALFactory, "findById" | "findOne" | "findEffectiveOrgMembership">;
identityAccessTokenService: Pick<
@@ -405,7 +409,7 @@ export const identityAwsAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
@@ -531,7 +535,7 @@ export const identityAwsAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
@@ -681,7 +685,7 @@ export const identityAwsAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
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.ts
index fad0da4e2c..6b31f84008 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,7 +50,11 @@ type TIdentityAzureAuthServiceFactoryDep = {
identityAccessTokenDAL: Pick<TIdentityAccessTokenDALFactory, "delete">;
permissionService: Pick<
TPermissionServiceFactory,
- "getOrgPermission" | "getProjectPermission" | "getOrgPermissionByRoles" | "getProjectPermissionByRoles"
+ | "getOrgPermission"
+ | "getProjectPermission"
+ | "getOrgPermissionByRoles"
+ | "getProjectPermissionByRoles"
+ | "getActorRoleSlugs"
>;
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
orgDAL: Pick<TOrgDALFactory, "findById" | "findOne" | "findEffectiveOrgMembership">;
@@ -306,7 +310,7 @@ export const identityAzureAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
@@ -432,7 +436,7 @@ export const identityAzureAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
@@ -584,7 +588,7 @@ export const identityAzureAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
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.ts
index 98d285b1e0..608595257b 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,7 +48,11 @@ type TIdentityGcpAuthServiceFactoryDep = {
identityAccessTokenDAL: Pick<TIdentityAccessTokenDALFactory, "delete">;
permissionService: Pick<
TPermissionServiceFactory,
- "getOrgPermission" | "getProjectPermission" | "getOrgPermissionByRoles" | "getProjectPermissionByRoles"
+ | "getOrgPermission"
+ | "getProjectPermission"
+ | "getOrgPermissionByRoles"
+ | "getProjectPermissionByRoles"
+ | "getActorRoleSlugs"
>;
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
orgDAL: Pick<TOrgDALFactory, "findById" | "findOne" | "findEffectiveOrgMembership">;
@@ -351,7 +355,7 @@ export const identityGcpAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
@@ -478,7 +482,7 @@ export const identityGcpAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
@@ -632,7 +636,7 @@ export const identityGcpAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
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.ts
index a6901d7c8e..e1fcb67736 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,7 +62,11 @@ type TIdentityJwtAuthServiceFactoryDep = {
identityAccessTokenDAL: Pick<TIdentityAccessTokenDALFactory, "delete">;
permissionService: Pick<
TPermissionServiceFactory,
- "getOrgPermission" | "getProjectPermission" | "getOrgPermissionByRoles" | "getProjectPermissionByRoles"
+ | "getOrgPermission"
+ | "getProjectPermission"
+ | "getOrgPermissionByRoles"
+ | "getProjectPermissionByRoles"
+ | "getActorRoleSlugs"
>;
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
@@ -472,7 +476,7 @@ export const identityJwtAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
@@ -627,7 +631,7 @@ export const identityJwtAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
@@ -837,7 +841,7 @@ export const identityJwtAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
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.ts
index 8949e7a784..37e7735886 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,7 +106,11 @@ type TIdentityKubernetesAuthServiceFactoryDep = {
keyStore: Pick<TKeyStoreFactory, "setItemWithExpiryNX">;
permissionService: Pick<
TPermissionServiceFactory,
- "getOrgPermission" | "getProjectPermission" | "getOrgPermissionByRoles" | "getProjectPermissionByRoles"
+ | "getOrgPermission"
+ | "getProjectPermission"
+ | "getOrgPermissionByRoles"
+ | "getProjectPermissionByRoles"
+ | "getActorRoleSlugs"
>;
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
@@ -882,7 +886,7 @@ export const identityKubernetesAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
@@ -1240,7 +1244,7 @@ export const identityKubernetesAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
@@ -1787,7 +1791,7 @@ export const identityKubernetesAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
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.ts
index f3b7a36200..95bbadf71d 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,7 +76,11 @@ type TIdentityLdapAuthServiceFactoryDep = {
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
permissionService: Pick<
TPermissionServiceFactory,
- "getOrgPermission" | "getProjectPermission" | "getOrgPermissionByRoles" | "getProjectPermissionByRoles"
+ | "getOrgPermission"
+ | "getProjectPermission"
+ | "getOrgPermissionByRoles"
+ | "getProjectPermissionByRoles"
+ | "getActorRoleSlugs"
>;
kmsService: TKmsServiceFactory;
identityDAL: Pick<TIdentityDALFactory, "findById" | "findOne">;
@@ -393,7 +397,7 @@ export const identityLdapAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
@@ -626,7 +630,7 @@ export const identityLdapAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
@@ -897,7 +901,7 @@ export const identityLdapAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
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.ts
index cdb2fc426e..7e12c371f6 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,7 +53,11 @@ type TIdentityOciAuthServiceFactoryDep = {
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
permissionService: Pick<
TPermissionServiceFactory,
- "getOrgPermission" | "getProjectPermission" | "getOrgPermissionByRoles" | "getProjectPermissionByRoles"
+ | "getOrgPermission"
+ | "getProjectPermission"
+ | "getOrgPermissionByRoles"
+ | "getProjectPermissionByRoles"
+ | "getActorRoleSlugs"
>;
orgDAL: Pick<TOrgDALFactory, "findById" | "findOne" | "findEffectiveOrgMembership">;
identityAccessTokenService: Pick<
@@ -319,7 +323,7 @@ export const identityOciAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
@@ -444,7 +448,7 @@ export const identityOciAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
@@ -595,7 +599,7 @@ export const identityOciAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
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.ts
index d10ba61fc5..387db8460c 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,7 +72,11 @@ type TIdentityOidcAuthServiceFactoryDep = {
identityAccessTokenDAL: Pick<TIdentityAccessTokenDALFactory, "delete">;
permissionService: Pick<
TPermissionServiceFactory,
- "getOrgPermission" | "getProjectPermission" | "getOrgPermissionByRoles" | "getProjectPermissionByRoles"
+ | "getOrgPermission"
+ | "getProjectPermission"
+ | "getOrgPermissionByRoles"
+ | "getProjectPermissionByRoles"
+ | "getActorRoleSlugs"
>;
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
@@ -658,7 +662,7 @@ export const identityOidcAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
@@ -863,7 +867,7 @@ export const identityOidcAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
@@ -1132,7 +1136,7 @@ export const identityOidcAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
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.ts
index 217c95c362..560b0325ba 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,7 +68,11 @@ type TIdentitySpiffeAuthServiceFactoryDep = {
identityAccessTokenDAL: Pick<TIdentityAccessTokenDALFactory, "delete">;
permissionService: Pick<
TPermissionServiceFactory,
- "getOrgPermission" | "getProjectPermission" | "getOrgPermissionByRoles" | "getProjectPermissionByRoles"
+ | "getOrgPermission"
+ | "getProjectPermission"
+ | "getOrgPermissionByRoles"
+ | "getProjectPermissionByRoles"
+ | "getActorRoleSlugs"
>;
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
@@ -546,7 +550,7 @@ export const identitySpiffeAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
@@ -709,7 +713,7 @@ export const identitySpiffeAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
@@ -925,7 +929,7 @@ export const identitySpiffeAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
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.ts
index e89a03f1fb..660997b92b 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,7 +171,11 @@ type TIdentityTlsCertAuthServiceFactoryDep = {
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
permissionService: Pick<
TPermissionServiceFactory,
- "getOrgPermission" | "getProjectPermission" | "getOrgPermissionByRoles" | "getProjectPermissionByRoles"
+ | "getOrgPermission"
+ | "getProjectPermission"
+ | "getOrgPermissionByRoles"
+ | "getProjectPermissionByRoles"
+ | "getActorRoleSlugs"
>;
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
orgDAL: Pick<TOrgDALFactory, "findById" | "findOne" | "findEffectiveOrgMembership">;
@@ -536,7 +540,7 @@ export const identityTlsCertAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
@@ -672,7 +676,7 @@ export const identityTlsCertAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
@@ -854,7 +858,7 @@ export const identityTlsCertAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
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.ts
index 882c481845..5a8448c255 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,7 +69,11 @@ type TIdentityTokenAuthServiceFactoryDep = {
>;
permissionService: Pick<
TPermissionServiceFactory,
- "getOrgPermission" | "getProjectPermission" | "getOrgPermissionByRoles" | "getProjectPermissionByRoles"
+ | "getOrgPermission"
+ | "getProjectPermission"
+ | "getOrgPermissionByRoles"
+ | "getProjectPermissionByRoles"
+ | "getActorRoleSlugs"
>;
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
orgDAL: Pick<TOrgDALFactory, "findById" | "findOne" | "findEffectiveOrgMembership">;
@@ -151,7 +155,7 @@ export const identityTokenAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
@@ -272,7 +276,7 @@ export const identityTokenAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
@@ -425,7 +429,7 @@ export const identityTokenAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
@@ -519,7 +523,7 @@ export const identityTokenAuthServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
diff --git a/backend/src/services/identity-ua/identity-ua-service.ts b/backend/src/services/identity-ua/identity-ua-service.ts
index 219f9740dd..584cb56f35 100644
--- a/backend/src/services/identity-ua/identity-ua-service.ts
+++ b/backend/src/services/identity-ua/identity-ua-service.ts
@@ -70,7 +70,11 @@ type TIdentityUaServiceFactoryDep = {
membershipIdentityDAL: TMembershipIdentityDALFactory;
permissionService: Pick<
TPermissionServiceFactory,
- "getOrgPermission" | "getProjectPermission" | "getOrgPermissionByRoles" | "getProjectPermissionByRoles"
+ | "getOrgPermission"
+ | "getProjectPermission"
+ | "getOrgPermissionByRoles"
+ | "getProjectPermissionByRoles"
+ | "getActorRoleSlugs"
>;
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
orgDAL: Pick<TOrgDALFactory, "findById" | "findOne" | "findEffectiveOrgMembership">;
@@ -496,7 +500,7 @@ export const identityUaServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
@@ -652,7 +656,7 @@ export const identityUaServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
@@ -827,7 +831,7 @@ export const identityUaServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
@@ -918,7 +922,7 @@ export const identityUaServiceFactory = ({
}
await assertIdentityAuthMutationAllowed(
- { permissionService, orgDAL, membershipIdentityDAL },
+ { permissionService, orgDAL },
{
identityId,
orgId: identityMembershipOrg.scopeOrgId,
diff --git a/backend/src/services/identity/identity-auth-permission-fns.test.ts b/backend/src/services/identity/identity-auth-permission-fns.test.ts
index a8b7db5b0c..b0e06d937c 100644
--- a/backend/src/services/identity/identity-auth-permission-fns.test.ts
+++ b/backend/src/services/identity/identity-auth-permission-fns.test.ts
@@ -23,7 +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.
+// 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.
const orgAdmin = createMongoAbility<MongoAbility<OrgPermissionSet>>(orgAdminPermissions);
const orgMember = createMongoAbility<MongoAbility<OrgPermissionSet>>(orgMemberPermissions);
@@ -42,6 +44,7 @@ const projectCreateTokenOnly = createMongoAbility<MongoAbility<ProjectPermission
]);
type TScopeCall = { scope: AccessScope; orgId: string; projectId?: string };
+type TPrincipal = { actorId: string; actorType: ActorType };
const runBoundary = async ({
shouldUseNewPrivilegeSystem = false,
@@ -50,7 +53,10 @@ const runBoundary = async ({
projectId,
action = OrgPermissionIdentityActions.EditAuth,
scopeCalls = [],
- roleLookups = []
+ roleLookups = [],
+ targetRoles = ["member"],
+ resolvedRoles = [],
+ principals = []
}: {
shouldUseNewPrivilegeSystem?: boolean;
actorPermission: MongoAbility;
@@ -59,27 +65,33 @@ 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: () => {
+ getOrgPermissionByRoles: (roles: string[]) => {
roleLookups.push("org");
+ resolvedRoles.push(roles);
return Promise.resolve(targetPermissions.map((permission) => ({ permission })));
},
- getProjectPermissionByRoles: () => {
+ getProjectPermissionByRoles: (roles: string[]) => {
roleLookups.push("project");
+ resolvedRoles.push(roles);
return Promise.resolve(targetPermissions.map((permission) => ({ permission })));
- }
- },
- orgDAL: { findById: () => Promise.resolve({ shouldUseNewPrivilegeSystem }) },
- membershipIdentityDAL: {
- getIdentityById: ({ scopeData }: { scopeData: TScopeCall }) => {
+ },
+ // 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) => {
scopeCalls.push(scopeData);
- return Promise.resolve({ roles: [{ role: "member" }] });
+ principals.push({ actorId, actorType });
+ return Promise.resolve(targetRoles);
}
- }
+ },
+ orgDAL: { findById: () => Promise.resolve({ shouldUseNewPrivilegeSystem }) }
} as unknown as Parameters<typeof assertIdentityAuthMutationAllowed>[0];
await assertIdentityAuthMutationAllowed(deps, {
@@ -122,6 +134,27 @@ describe("assertIdentityAuthMutationAllowed", () => {
expect(scopeCalls).toEqual([{ scope: AccessScope.Organization, orgId: "org-1" }]);
});
+ // `actorId` in the DTO is the caller, so passing it here instead of the target would compare the
+ // caller against itself and pass every time. Nothing else in this file would notice.
+ test("the roles resolved are the target's, not the caller's", async () => {
+ const principals: TPrincipal[] = [];
+ await runBoundary({ actorPermission: orgAdmin, targetPermissions: [orgMember], principals });
+ 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({
@@ -174,6 +207,17 @@ describe("assertIdentityAuthMutationAllowed", () => {
expect(scopeCalls).toEqual([{ scope: AccessScope.Project, orgId: "org-1", projectId: "project-1" }]);
});
+ test("the roles resolved are the target's, not the caller's", async () => {
+ const principals: TPrincipal[] = [];
+ await runBoundary({
+ actorPermission: projectAdmin,
+ targetPermissions: [projectMember],
+ projectId: "project-1",
+ principals
+ });
+ expect(principals).toEqual([{ actorId: "identity-1", actorType: ActorType.IDENTITY }]);
+ });
+
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.ts
index 0199329ac6..5530629c84 100644
--- a/backend/src/services/identity/identity-auth-permission-fns.ts
+++ b/backend/src/services/identity/identity-auth-permission-fns.ts
@@ -6,8 +6,6 @@ import { ProjectPermissionIdentityActions, ProjectPermissionSub } from "@app/ee/
import { requestMemoKeys } from "@app/lib/request-context/memo-keys";
import { requestMemoize } from "@app/lib/request-context/request-memoizer";
import { ActorAuthMethod, ActorType } from "@app/services/auth/auth-type";
-import { resolveMembershipRoleSlugs } from "@app/services/membership/membership-fns";
-import { TMembershipIdentityDALFactory } from "@app/services/membership-identity/membership-identity-dal";
import { TOrgDALFactory } from "@app/services/org/org-dal";
const PROJECT_ACTION_BY_ORG_ACTION = {
@@ -19,10 +17,13 @@ const PROJECT_ACTION_BY_ORG_ACTION = {
type TIdentityAuthPermissionDeps = {
permissionService: Pick<
TPermissionServiceFactory,
- "getOrgPermission" | "getProjectPermission" | "getOrgPermissionByRoles" | "getProjectPermissionByRoles"
+ | "getOrgPermission"
+ | "getProjectPermission"
+ | "getOrgPermissionByRoles"
+ | "getProjectPermissionByRoles"
+ | "getActorRoleSlugs"
>;
orgDAL: Pick<TOrgDALFactory, "findById">;
- membershipIdentityDAL: Pick<TMembershipIdentityDALFactory, "getIdentityById">;
};
type TAssertIdentityAuthMutationAllowedDTO = {
@@ -41,7 +42,7 @@ type TAssertIdentityAuthMutationAllowedDTO = {
// 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,
+ { permissionService, orgDAL }: TIdentityAuthPermissionDeps,
{
identityId,
orgId,
@@ -61,13 +62,13 @@ export const assertIdentityAuthMutationAllowed = async (
const resolveTargetPermissions = async () => {
if (shouldUseNewPrivilegeSystem) return [];
- const targetMembership = await membershipIdentityDAL.getIdentityById({
+ const targetRoles = await permissionService.getActorRoleSlugs({
scopeData: projectId
? { scope: AccessScope.Project, orgId, projectId }
: { scope: AccessScope.Organization, orgId },
- identityId
+ actorId: identityId,
+ actorType: ActorType.IDENTITY
});
- const targetRoles = targetMembership ? resolveMembershipRoleSlugs(targetMembership.roles) : [];
const rolePermissions = projectId
? await permissionService.getProjectPermissionByRoles(targetRoles, projectId, { ignoreUnresolvedRoles: true })