Skip to content

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

add permission boundary on legacy system for identity auth

Thiago Araujo da Silva0c80ffd0fd28
diff --git a/backend/CLAUDE.md b/backend/CLAUDE.md
index 3eb094b0f5..a0a284bf1d 100644
--- a/backend/CLAUDE.md
+++ b/backend/CLAUDE.md
@@ -490,6 +490,10 @@ Uses CASL (`@casl/ability`) with MongoDB-style rules. Permission logic lives in
Built-in roles: `Admin`, `Member`, `Viewer`, `NoAccess`. Custom roles use unpacked CASL rules stored in the database. Rules can include conditions with operators `$IN`, `$EQ`, `$NEQ`, `$GLOB` (for pattern matching like `prod-*`). See `PermissionConditionSchema` in `permission-types.ts`.
+**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.
+
**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.
- **Long-lived data payload** (10m TTL) in Redis — holds the full permission blob plus a fingerprint hash.
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 324e47601a..73fb6311ba 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
@@ -6,22 +6,12 @@ import { AxiosError } from "axios";
import { AccessScope, ActionProjectType, IdentityAuthMethod, OrganizationActionScope } from "@app/db/schemas";
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
import { OrgPermissionIdentityActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
-import {
- constructPermissionErrorMessage,
- validatePrivilegeChangeOperation
-} from "@app/ee/services/permission/permission-fns";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import { ProjectPermissionIdentityActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
import { TKeyStoreFactory } from "@app/keystore/keystore";
import { getConfig } from "@app/lib/config/env";
import { request } from "@app/lib/config/request";
-import {
- BadRequestError,
- ForbiddenRequestError,
- NotFoundError,
- PermissionBoundaryError,
- UnauthorizedError
-} from "@app/lib/errors";
+import { BadRequestError, ForbiddenRequestError, NotFoundError, UnauthorizedError } from "@app/lib/errors";
import { extractIPDetails, isValidIpOrCidr, TIp } from "@app/lib/ip";
import { logger } from "@app/lib/logger";
import { requestMemoKeys } from "@app/lib/request-context/memo-keys";
@@ -35,6 +25,7 @@ import {
} from "@app/lib/telemetry/metrics";
import { ActorType } from "../auth/auth-type";
+import { assertIdentityAuthMutationAllowed } from "../identity/identity-auth-permission-fns";
import { TIdentityDALFactory } from "../identity/identity-dal";
import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";
import { TIdentityAccessTokenServiceFactory } from "../identity-access-token/identity-access-token-service";
@@ -62,7 +53,10 @@ type TIdentityAliCloudAuthServiceFactoryDep = {
membershipIdentityDAL: Pick<TMembershipIdentityDALFactory, "findOne" | "update" | "getIdentityById">;
keyStore: Pick<TKeyStoreFactory, "setItemWithExpiryNX">;
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
- permissionService: Pick<TPermissionServiceFactory, "getOrgPermission" | "getProjectPermission">;
+ permissionService: Pick<
+ TPermissionServiceFactory,
+ "getOrgPermission" | "getProjectPermission" | "getOrgPermissionByRoles" | "getProjectPermissionByRoles"
+ >;
orgDAL: Pick<TOrgDALFactory, "findById" | "findOne" | "findEffectiveOrgMembership">;
identityAccessTokenService: Pick<
TIdentityAccessTokenServiceFactory,
@@ -312,6 +306,21 @@ export const identityAliCloudAuthServiceFactory = ({
);
}
+ await assertIdentityAuthMutationAllowed(
+ { permissionService, orgDAL, membershipIdentityDAL },
+ {
+ identityId,
+ orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.EditAuth,
+ baseMessage: "Failed to add Alibaba Cloud auth to identity with more privileged role",
+ actor,
+ actorId,
+ actorAuthMethod,
+ actorOrgId
+ }
+ );
+
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
const reformattedAccessTokenTrustedIps = accessTokenTrustedIps.map((accessTokenTrustedIp) => {
@@ -420,6 +429,21 @@ export const identityAliCloudAuthServiceFactory = ({
);
}
+ await assertIdentityAuthMutationAllowed(
+ { permissionService, orgDAL, membershipIdentityDAL },
+ {
+ identityId,
+ orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.EditAuth,
+ baseMessage: "Failed to update Alibaba Cloud auth of identity with more privileged role",
+ actor,
+ actorId,
+ actorAuthMethod,
+ actorOrgId
+ }
+ );
+
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
const reformattedAccessTokenTrustedIps = accessTokenTrustedIps?.map((accessTokenTrustedIp) => {
@@ -551,39 +575,22 @@ export const identityAliCloudAuthServiceFactory = ({
actorOrgId
});
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Edit, OrgPermissionSubjects.Identity);
+ }
- const { permission: rolePermission } = await permissionService.getOrgPermission({
- scope: OrganizationActionScope.Any,
- actor: ActorType.IDENTITY,
- actorId: identityMembershipOrg.identity.id,
+ await assertIdentityAuthMutationAllowed(
+ { permissionService, orgDAL, membershipIdentityDAL },
+ {
+ identityId,
orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.RevokeAuth,
+ baseMessage: "Failed to revoke Alibaba Cloud auth of identity with more privileged role",
+ actor,
+ actorId,
actorAuthMethod,
actorOrgId
- });
-
- const { shouldUseNewPrivilegeSystem } = await requestMemoize(
- requestMemoKeys.orgFindById(identityMembershipOrg.scopeOrgId),
- () => orgDAL.findById(identityMembershipOrg.scopeOrgId)
- );
- const permissionBoundary = validatePrivilegeChangeOperation(
- shouldUseNewPrivilegeSystem,
- OrgPermissionIdentityActions.RevokeAuth,
- OrgPermissionSubjects.Identity,
- permission,
- rolePermission
- );
-
- if (!permissionBoundary.isValid)
- throw new PermissionBoundaryError({
- message: constructPermissionErrorMessage(
- "Failed to revoke Alibaba Cloud auth of identity with more privileged role",
- shouldUseNewPrivilegeSystem,
- OrgPermissionIdentityActions.RevokeAuth,
- OrgPermissionSubjects.Identity
- ),
- details: { missingPermissions: permissionBoundary.missingPermissions }
- });
- }
+ }
+ );
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
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 1512900334..0ad9fc60ce 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
@@ -7,22 +7,12 @@ import RE2 from "re2";
import { AccessScope, ActionProjectType, IdentityAuthMethod, OrganizationActionScope } from "@app/db/schemas";
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
import { OrgPermissionIdentityActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
-import {
- constructPermissionErrorMessage,
- validatePrivilegeChangeOperation
-} from "@app/ee/services/permission/permission-fns";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import { ProjectPermissionIdentityActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
import { TKeyStoreFactory } from "@app/keystore/keystore";
import { getConfig } from "@app/lib/config/env";
import { request } from "@app/lib/config/request";
-import {
- BadRequestError,
- ForbiddenRequestError,
- NotFoundError,
- PermissionBoundaryError,
- UnauthorizedError
-} from "@app/lib/errors";
+import { BadRequestError, ForbiddenRequestError, NotFoundError, UnauthorizedError } from "@app/lib/errors";
import { extractIPDetails, isValidIpOrCidr, TIp } from "@app/lib/ip";
import { logger } from "@app/lib/logger";
import { requestMemoKeys } from "@app/lib/request-context/memo-keys";
@@ -36,6 +26,7 @@ import {
} from "@app/lib/telemetry/metrics";
import { ActorType } from "../auth/auth-type";
+import { assertIdentityAuthMutationAllowed } from "../identity/identity-auth-permission-fns";
import { TIdentityDALFactory } from "../identity/identity-dal";
import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";
import { TIdentityAccessTokenServiceFactory } from "../identity-access-token/identity-access-token-service";
@@ -62,7 +53,10 @@ type TIdentityAwsAuthServiceFactoryDep = {
membershipIdentityDAL: Pick<TMembershipIdentityDALFactory, "findOne" | "update" | "getIdentityById">;
keyStore: Pick<TKeyStoreFactory, "setItemWithExpiryNX">;
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
- permissionService: Pick<TPermissionServiceFactory, "getOrgPermission" | "getProjectPermission">;
+ permissionService: Pick<
+ TPermissionServiceFactory,
+ "getOrgPermission" | "getProjectPermission" | "getOrgPermissionByRoles" | "getProjectPermissionByRoles"
+ >;
orgDAL: Pick<TOrgDALFactory, "findById" | "findOne" | "findEffectiveOrgMembership">;
identityAccessTokenService: Pick<
TIdentityAccessTokenServiceFactory,
@@ -410,6 +404,21 @@ export const identityAwsAuthServiceFactory = ({
);
}
+ await assertIdentityAuthMutationAllowed(
+ { permissionService, orgDAL, membershipIdentityDAL },
+ {
+ identityId,
+ orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.EditAuth,
+ baseMessage: "Failed to add aws auth to identity with more privileged role",
+ actor,
+ actorId,
+ actorAuthMethod,
+ actorOrgId
+ }
+ );
+
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
const reformattedAccessTokenTrustedIps = accessTokenTrustedIps.map((accessTokenTrustedIp) => {
@@ -521,6 +530,21 @@ export const identityAwsAuthServiceFactory = ({
);
}
+ await assertIdentityAuthMutationAllowed(
+ { permissionService, orgDAL, membershipIdentityDAL },
+ {
+ identityId,
+ orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.EditAuth,
+ baseMessage: "Failed to update aws auth of identity with more privileged role",
+ actor,
+ actorId,
+ actorAuthMethod,
+ actorOrgId
+ }
+ );
+
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
const reformattedAccessTokenTrustedIps = accessTokenTrustedIps?.map((accessTokenTrustedIp) => {
@@ -654,39 +678,22 @@ export const identityAwsAuthServiceFactory = ({
actorOrgId
});
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Edit, OrgPermissionSubjects.Identity);
+ }
- const { permission: rolePermission } = await permissionService.getOrgPermission({
- scope: OrganizationActionScope.Any,
- actor: ActorType.IDENTITY,
- actorId: identityMembershipOrg.identity.id,
+ await assertIdentityAuthMutationAllowed(
+ { permissionService, orgDAL, membershipIdentityDAL },
+ {
+ identityId,
orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.RevokeAuth,
+ baseMessage: "Failed to revoke aws auth of identity with more privileged role",
+ actor,
+ actorId,
actorAuthMethod,
actorOrgId
- });
-
- const { shouldUseNewPrivilegeSystem } = await requestMemoize(
- requestMemoKeys.orgFindById(identityMembershipOrg.scopeOrgId),
- () => orgDAL.findById(identityMembershipOrg.scopeOrgId)
- );
- const permissionBoundary = validatePrivilegeChangeOperation(
- shouldUseNewPrivilegeSystem,
- OrgPermissionIdentityActions.RevokeAuth,
- OrgPermissionSubjects.Identity,
- permission,
- rolePermission
- );
-
- if (!permissionBoundary.isValid)
- throw new PermissionBoundaryError({
- message: constructPermissionErrorMessage(
- "Failed to revoke aws auth of identity with more privileged role",
- shouldUseNewPrivilegeSystem,
- OrgPermissionIdentityActions.RevokeAuth,
- OrgPermissionSubjects.Identity
- ),
- details: { missingPermissions: permissionBoundary.missingPermissions }
- });
- }
+ }
+ );
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
const revokedIdentityAwsAuth = await identityAwsAuthDAL.transaction(async (tx) => {
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 059bb6b717..fad0da4e2c 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
@@ -4,21 +4,11 @@ import { requestContext } from "@fastify/request-context";
import { AccessScope, ActionProjectType, IdentityAuthMethod, OrganizationActionScope } from "@app/db/schemas";
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
import { OrgPermissionIdentityActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
-import {
- constructPermissionErrorMessage,
- validatePrivilegeChangeOperation
-} from "@app/ee/services/permission/permission-fns";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import { ProjectPermissionIdentityActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
import { TKeyStoreFactory } from "@app/keystore/keystore";
import { getConfig } from "@app/lib/config/env";
-import {
- BadRequestError,
- ForbiddenRequestError,
- NotFoundError,
- PermissionBoundaryError,
- UnauthorizedError
-} from "@app/lib/errors";
+import { BadRequestError, ForbiddenRequestError, NotFoundError, UnauthorizedError } from "@app/lib/errors";
import { extractIPDetails, isValidIpOrCidr, TIp } from "@app/lib/ip";
import { requestMemoKeys } from "@app/lib/request-context/memo-keys";
import { RequestContextKey } from "@app/lib/request-context/request-context-keys";
@@ -31,6 +21,7 @@ import {
} from "@app/lib/telemetry/metrics";
import { ActorType } from "../auth/auth-type";
+import { assertIdentityAuthMutationAllowed } from "../identity/identity-auth-permission-fns";
import { TIdentityDALFactory } from "../identity/identity-dal";
import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";
import { TIdentityAccessTokenServiceFactory } from "../identity-access-token/identity-access-token-service";
@@ -57,7 +48,10 @@ type TIdentityAzureAuthServiceFactoryDep = {
membershipIdentityDAL: Pick<TMembershipIdentityDALFactory, "findOne" | "update" | "getIdentityById">;
keyStore: Pick<TKeyStoreFactory, "setItemWithExpiryNX">;
identityAccessTokenDAL: Pick<TIdentityAccessTokenDALFactory, "delete">;
- permissionService: Pick<TPermissionServiceFactory, "getOrgPermission" | "getProjectPermission">;
+ permissionService: Pick<
+ TPermissionServiceFactory,
+ "getOrgPermission" | "getProjectPermission" | "getOrgPermissionByRoles" | "getProjectPermissionByRoles"
+ >;
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
orgDAL: Pick<TOrgDALFactory, "findById" | "findOne" | "findEffectiveOrgMembership">;
identityAccessTokenService: Pick<
@@ -311,6 +305,21 @@ export const identityAzureAuthServiceFactory = ({
);
}
+ await assertIdentityAuthMutationAllowed(
+ { permissionService, orgDAL, membershipIdentityDAL },
+ {
+ identityId,
+ orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.EditAuth,
+ baseMessage: "Failed to add azure auth to identity with more privileged role",
+ actor,
+ actorId,
+ actorAuthMethod,
+ actorOrgId
+ }
+ );
+
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
const reformattedAccessTokenTrustedIps = accessTokenTrustedIps.map((accessTokenTrustedIp) => {
@@ -422,6 +431,21 @@ export const identityAzureAuthServiceFactory = ({
);
}
+ await assertIdentityAuthMutationAllowed(
+ { permissionService, orgDAL, membershipIdentityDAL },
+ {
+ identityId,
+ orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.EditAuth,
+ baseMessage: "Failed to update azure auth of identity with more privileged role",
+ actor,
+ actorId,
+ actorAuthMethod,
+ actorOrgId
+ }
+ );
+
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
const reformattedAccessTokenTrustedIps = accessTokenTrustedIps?.map((accessTokenTrustedIp) => {
@@ -557,37 +581,22 @@ export const identityAzureAuthServiceFactory = ({
actorOrgId
});
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Edit, OrgPermissionSubjects.Identity);
+ }
- const { permission: rolePermission } = await permissionService.getOrgPermission({
- scope: OrganizationActionScope.Any,
- actor: ActorType.IDENTITY,
- actorId: identityMembershipOrg.identity.id,
+ await assertIdentityAuthMutationAllowed(
+ { permissionService, orgDAL, membershipIdentityDAL },
+ {
+ identityId,
orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.RevokeAuth,
+ baseMessage: "Failed to revoke azure auth of identity with more privileged role",
+ actor,
+ actorId,
actorAuthMethod,
actorOrgId
- });
- const { shouldUseNewPrivilegeSystem } = await requestMemoize(
- requestMemoKeys.orgFindById(identityMembershipOrg.scopeOrgId),
- () => orgDAL.findById(identityMembershipOrg.scopeOrgId)
- );
- const permissionBoundary = validatePrivilegeChangeOperation(
- shouldUseNewPrivilegeSystem,
- OrgPermissionIdentityActions.RevokeAuth,
- OrgPermissionSubjects.Identity,
- permission,
- rolePermission
- );
- if (!permissionBoundary.isValid)
- throw new PermissionBoundaryError({
- message: constructPermissionErrorMessage(
- "Failed to revoke azure auth of identity with more privileged role",
- shouldUseNewPrivilegeSystem,
- OrgPermissionIdentityActions.RevokeAuth,
- OrgPermissionSubjects.Identity
- ),
- details: { missingPermissions: permissionBoundary.missingPermissions }
- });
- }
+ }
+ );
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
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 8f0c5a6892..98d285b1e0 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
@@ -4,21 +4,11 @@ import { requestContext } from "@fastify/request-context";
import { AccessScope, ActionProjectType, IdentityAuthMethod, OrganizationActionScope } from "@app/db/schemas";
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
import { OrgPermissionIdentityActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
-import {
- constructPermissionErrorMessage,
- validatePrivilegeChangeOperation
-} from "@app/ee/services/permission/permission-fns";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import { ProjectPermissionIdentityActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
import { TKeyStoreFactory } from "@app/keystore/keystore";
import { getConfig } from "@app/lib/config/env";
-import {
- BadRequestError,
- ForbiddenRequestError,
- NotFoundError,
- PermissionBoundaryError,
- UnauthorizedError
-} from "@app/lib/errors";
+import { BadRequestError, ForbiddenRequestError, NotFoundError, UnauthorizedError } from "@app/lib/errors";
import { extractIPDetails, isValidIpOrCidr, TIp } from "@app/lib/ip";
import { requestMemoKeys } from "@app/lib/request-context/memo-keys";
import { RequestContextKey } from "@app/lib/request-context/request-context-keys";
@@ -31,6 +21,7 @@ import {
} from "@app/lib/telemetry/metrics";
import { ActorType } from "../auth/auth-type";
+import { assertIdentityAuthMutationAllowed } from "../identity/identity-auth-permission-fns";
import { TIdentityDALFactory } from "../identity/identity-dal";
import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";
import { TIdentityAccessTokenServiceFactory } from "../identity-access-token/identity-access-token-service";
@@ -55,7 +46,10 @@ type TIdentityGcpAuthServiceFactoryDep = {
membershipIdentityDAL: Pick<TMembershipIdentityDALFactory, "findOne" | "update" | "getIdentityById">;
keyStore: Pick<TKeyStoreFactory, "setItemWithExpiryNX">;
identityAccessTokenDAL: Pick<TIdentityAccessTokenDALFactory, "delete">;
- permissionService: Pick<TPermissionServiceFactory, "getOrgPermission" | "getProjectPermission">;
+ permissionService: Pick<
+ TPermissionServiceFactory,
+ "getOrgPermission" | "getProjectPermission" | "getOrgPermissionByRoles" | "getProjectPermissionByRoles"
+ >;
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
orgDAL: Pick<TOrgDALFactory, "findById" | "findOne" | "findEffectiveOrgMembership">;
identityAccessTokenService: Pick<
@@ -356,6 +350,21 @@ export const identityGcpAuthServiceFactory = ({
);
}
+ await assertIdentityAuthMutationAllowed(
+ { permissionService, orgDAL, membershipIdentityDAL },
+ {
+ identityId,
+ orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.EditAuth,
+ baseMessage: "Failed to add gcp auth to identity with more privileged role",
+ actor,
+ actorId,
+ actorAuthMethod,
+ actorOrgId
+ }
+ );
+
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
const reformattedAccessTokenTrustedIps = accessTokenTrustedIps.map((accessTokenTrustedIp) => {
@@ -468,6 +477,21 @@ export const identityGcpAuthServiceFactory = ({
);
}
+ await assertIdentityAuthMutationAllowed(
+ { permissionService, orgDAL, membershipIdentityDAL },
+ {
+ identityId,
+ orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.EditAuth,
+ baseMessage: "Failed to update gcp auth of identity with more privileged role",
+ actor,
+ actorId,
+ actorAuthMethod,
+ actorOrgId
+ }
+ );
+
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
const reformattedAccessTokenTrustedIps = accessTokenTrustedIps?.map((accessTokenTrustedIp) => {
@@ -605,36 +629,22 @@ export const identityGcpAuthServiceFactory = ({
actorOrgId
});
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Edit, OrgPermissionSubjects.Identity);
- const { permission: rolePermission } = await permissionService.getOrgPermission({
- scope: OrganizationActionScope.Any,
- actor: ActorType.IDENTITY,
- actorId: identityMembershipOrg.identity.id,
+ }
+
+ await assertIdentityAuthMutationAllowed(
+ { permissionService, orgDAL, membershipIdentityDAL },
+ {
+ identityId,
orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.RevokeAuth,
+ baseMessage: "Failed to revoke gcp auth of identity with more privileged role",
+ actor,
+ actorId,
actorAuthMethod,
actorOrgId
- });
- const { shouldUseNewPrivilegeSystem } = await requestMemoize(
- requestMemoKeys.orgFindById(identityMembershipOrg.scopeOrgId),
- () => orgDAL.findById(identityMembershipOrg.scopeOrgId)
- );
- const permissionBoundary = validatePrivilegeChangeOperation(
- shouldUseNewPrivilegeSystem,
- OrgPermissionIdentityActions.RevokeAuth,
- OrgPermissionSubjects.Identity,
- permission,
- rolePermission
- );
- if (!permissionBoundary.isValid)
- throw new PermissionBoundaryError({
- message: constructPermissionErrorMessage(
- "Failed to revoke gcp auth of identity with more privileged role",
- shouldUseNewPrivilegeSystem,
- OrgPermissionIdentityActions.RevokeAuth,
- OrgPermissionSubjects.Identity
- ),
- details: { missingPermissions: permissionBoundary.missingPermissions }
- });
- }
+ }
+ );
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
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 0a8e14db1d..a6901d7c8e 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
@@ -13,22 +13,12 @@ import {
} from "@app/db/schemas";
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
import { OrgPermissionIdentityActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
-import {
- constructPermissionErrorMessage,
- validatePrivilegeChangeOperation
-} from "@app/ee/services/permission/permission-fns";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import { ProjectPermissionIdentityActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
import { TKeyStoreFactory } from "@app/keystore/keystore";
import { getConfig } from "@app/lib/config/env";
import { crypto } from "@app/lib/crypto";
-import {
- BadRequestError,
- ForbiddenRequestError,
- NotFoundError,
- PermissionBoundaryError,
- UnauthorizedError
-} from "@app/lib/errors";
+import { BadRequestError, ForbiddenRequestError, NotFoundError, UnauthorizedError } from "@app/lib/errors";
import { extractIPDetails, isValidIpOrCidr, TIp } from "@app/lib/ip";
import { requestMemoKeys } from "@app/lib/request-context/memo-keys";
import { RequestContextKey } from "@app/lib/request-context/request-context-keys";
@@ -43,6 +33,7 @@ import { getValueByDot } from "@app/lib/template/dot-access";
import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";
import { ActorType } from "../auth/auth-type";
+import { assertIdentityAuthMutationAllowed } from "../identity/identity-auth-permission-fns";
import { TIdentityDALFactory } from "../identity/identity-dal";
import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";
import { TIdentityAccessTokenServiceFactory } from "../identity-access-token/identity-access-token-service";
@@ -69,7 +60,10 @@ type TIdentityJwtAuthServiceFactoryDep = {
membershipIdentityDAL: Pick<TMembershipIdentityDALFactory, "findOne" | "update" | "getIdentityById">;
keyStore: Pick<TKeyStoreFactory, "setItemWithExpiryNX">;
identityAccessTokenDAL: Pick<TIdentityAccessTokenDALFactory, "delete">;
- permissionService: Pick<TPermissionServiceFactory, "getOrgPermission" | "getProjectPermission">;
+ permissionService: Pick<
+ TPermissionServiceFactory,
+ "getOrgPermission" | "getProjectPermission" | "getOrgPermissionByRoles" | "getProjectPermissionByRoles"
+ >;
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
orgDAL: Pick<TOrgDALFactory, "findById" | "findOne" | "findEffectiveOrgMembership">;
@@ -477,6 +471,21 @@ export const identityJwtAuthServiceFactory = ({
);
}
+ await assertIdentityAuthMutationAllowed(
+ { permissionService, orgDAL, membershipIdentityDAL },
+ {
+ identityId,
+ orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.EditAuth,
+ baseMessage: "Failed to add jwt auth to identity with more privileged role",
+ actor,
+ actorId,
+ actorAuthMethod,
+ actorOrgId
+ }
+ );
+
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
@@ -617,6 +626,21 @@ export const identityJwtAuthServiceFactory = ({
);
}
+ await assertIdentityAuthMutationAllowed(
+ { permissionService, orgDAL, membershipIdentityDAL },
+ {
+ identityId,
+ orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.EditAuth,
+ baseMessage: "Failed to update jwt auth of identity with more privileged role",
+ actor,
+ actorId,
+ actorAuthMethod,
+ actorOrgId
+ }
+ );
+
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
const reformattedAccessTokenTrustedIps = accessTokenTrustedIps?.map((accessTokenTrustedIp) => {
@@ -810,38 +834,22 @@ export const identityJwtAuthServiceFactory = ({
});
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Edit, OrgPermissionSubjects.Identity);
+ }
- const { permission: rolePermission } = await permissionService.getOrgPermission({
- scope: OrganizationActionScope.Any,
- actor: ActorType.IDENTITY,
- actorId: identityMembershipOrg.identity.id,
+ await assertIdentityAuthMutationAllowed(
+ { permissionService, orgDAL, membershipIdentityDAL },
+ {
+ identityId,
orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.RevokeAuth,
+ baseMessage: "Failed to revoke jwt auth of identity with more privileged role",
+ actor,
+ actorId,
actorAuthMethod,
actorOrgId
- });
-
- const { shouldUseNewPrivilegeSystem } = await requestMemoize(
- requestMemoKeys.orgFindById(identityMembershipOrg.scopeOrgId),
- () => orgDAL.findById(identityMembershipOrg.scopeOrgId)
- );
- const permissionBoundary = validatePrivilegeChangeOperation(
- shouldUseNewPrivilegeSystem,
- OrgPermissionIdentityActions.RevokeAuth,
- OrgPermissionSubjects.Identity,
- permission,
- rolePermission
- );
- if (!permissionBoundary.isValid)
- throw new PermissionBoundaryError({
- message: constructPermissionErrorMessage(
- "Failed to revoke jwt auth of identity with more privileged role",
- shouldUseNewPrivilegeSystem,
- OrgPermissionIdentityActions.RevokeAuth,
- OrgPermissionSubjects.Identity
- ),
- details: { missingPermissions: permissionBoundary.missingPermissions }
- });
- }
+ }
+ );
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
const revokedIdentityJwtAuth = await identityJwtAuthDAL.transaction(async (tx) => {
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 604edf3e93..8949e7a784 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
@@ -31,22 +31,12 @@ import {
OrgPermissionMachineIdentityAuthTemplateActions,
OrgPermissionSubjects
} from "@app/ee/services/permission/org-permission";
-import {
- constructPermissionErrorMessage,
- validatePrivilegeChangeOperation
-} from "@app/ee/services/permission/permission-fns";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import { ProjectPermissionIdentityActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
import { TKeyStoreFactory } from "@app/keystore/keystore";
import { getConfig } from "@app/lib/config/env";
import { request } from "@app/lib/config/request";
-import {
- BadRequestError,
- ForbiddenRequestError,
- NotFoundError,
- PermissionBoundaryError,
- UnauthorizedError
-} from "@app/lib/errors";
+import { BadRequestError, ForbiddenRequestError, NotFoundError, UnauthorizedError } from "@app/lib/errors";
import { GatewayHttpProxyActions, GatewayProxyProtocol, withGatewayProxy } from "@app/lib/gateway";
import { withGatewayV2Proxy } from "@app/lib/gateway-v2/gateway-v2";
import { extractIPDetails, isValidIpOrCidr, TIp } from "@app/lib/ip";
@@ -64,6 +54,7 @@ import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";
import { getSharedHttpsAgent, safeRequest } from "@app/lib/validator/safe-request";
import { ActorType } from "../auth/auth-type";
+import { assertIdentityAuthMutationAllowed } from "../identity/identity-auth-permission-fns";
import { TIdentityDALFactory } from "../identity/identity-dal";
import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";
import { TIdentityAccessTokenServiceFactory } from "../identity-access-token/identity-access-token-service";
@@ -113,7 +104,10 @@ type TIdentityKubernetesAuthServiceFactoryDep = {
identityAuthTemplateDAL: Pick<TIdentityAuthTemplateDALFactory, "findByIdAndOrgId">;
membershipIdentityDAL: Pick<TMembershipIdentityDALFactory, "findOne" | "update" | "getIdentityById">;
keyStore: Pick<TKeyStoreFactory, "setItemWithExpiryNX">;
- permissionService: Pick<TPermissionServiceFactory, "getOrgPermission" | "getProjectPermission">;
+ permissionService: Pick<
+ TPermissionServiceFactory,
+ "getOrgPermission" | "getProjectPermission" | "getOrgPermissionByRoles" | "getProjectPermissionByRoles"
+ >;
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
gatewayService: TGatewayServiceFactory;
@@ -887,6 +881,21 @@ export const identityKubernetesAuthServiceFactory = ({
);
}
+ await assertIdentityAuthMutationAllowed(
+ { permissionService, orgDAL, membershipIdentityDAL },
+ {
+ identityId,
+ orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.EditAuth,
+ baseMessage: "Failed to add kubernetes auth to identity with more privileged role",
+ actor,
+ actorId,
+ actorAuthMethod,
+ actorOrgId
+ }
+ );
+
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
const { encryptor, decryptor } = await kmsService.createCipherPairWithDataKey({
type: KmsDataKey.Organization,
@@ -1230,6 +1239,21 @@ export const identityKubernetesAuthServiceFactory = ({
);
}
+ await assertIdentityAuthMutationAllowed(
+ { permissionService, orgDAL, membershipIdentityDAL },
+ {
+ identityId,
+ orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.EditAuth,
+ baseMessage: "Failed to update kubernetes auth of identity with more privileged role",
+ actor,
+ actorId,
+ actorAuthMethod,
+ actorOrgId
+ }
+ );
+
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
const { encryptor, decryptor } = await kmsService.createCipherPairWithDataKey({
type: KmsDataKey.Organization,
@@ -1760,37 +1784,22 @@ export const identityKubernetesAuthServiceFactory = ({
actorOrgId
});
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.RevokeAuth,
+ baseMessage: "Failed to revoke kubernetes auth of 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.RevokeAuth,
- OrgPermissionSubjects.Identity,
- permission,
- rolePermission
- );
- if (!permissionBoundary.isValid)
- throw new PermissionBoundaryError({
- message: constructPermissionErrorMessage(
- "Failed to revoke kubernetes auth of identity with more privileged role",
- shouldUseNewPrivilegeSystem,
- OrgPermissionIdentityActions.RevokeAuth,
- OrgPermissionSubjects.Identity
- ),
- details: { missingPermissions: permissionBoundary.missingPermissions }
- });
- }
+ actorOrgId
+ }
+ );
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
const revokedIdentityKubernetesAuth = await identityKubernetesAuthDAL.transaction(async (tx) => {
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 5ec50ff6bc..f3b7a36200 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
@@ -12,10 +12,6 @@ import {
OrgPermissionMachineIdentityAuthTemplateActions,
OrgPermissionSubjects
} from "@app/ee/services/permission/org-permission";
-import {
- constructPermissionErrorMessage,
- validatePrivilegeChangeOperation
-} from "@app/ee/services/permission/permission-fns";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import { ProjectPermissionIdentityActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
import { TKeyStoreFactory } from "@app/keystore/keystore";
@@ -24,7 +20,6 @@ import {
BadRequestError,
ForbiddenRequestError,
NotFoundError,
- PermissionBoundaryError,
RateLimitError,
UnauthorizedError
} from "@app/lib/errors";
@@ -42,6 +37,7 @@ import {
import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";
import { ActorType } from "../auth/auth-type";
+import { assertIdentityAuthMutationAllowed } from "../identity/identity-auth-permission-fns";
import { TIdentityDALFactory } from "../identity/identity-dal";
import {
clearIdentityLockoutsForAuthMethod,
@@ -78,7 +74,10 @@ type TIdentityLdapAuthServiceFactoryDep = {
>;
membershipIdentityDAL: Pick<TMembershipIdentityDALFactory, "findOne" | "update" | "getIdentityById">;
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
- permissionService: Pick<TPermissionServiceFactory, "getOrgPermission" | "getProjectPermission">;
+ permissionService: Pick<
+ TPermissionServiceFactory,
+ "getOrgPermission" | "getProjectPermission" | "getOrgPermissionByRoles" | "getProjectPermissionByRoles"
+ >;
kmsService: TKmsServiceFactory;
identityDAL: Pick<TIdentityDALFactory, "findById" | "findOne">;
identityAuthTemplateDAL: TIdentityAuthTemplateDALFactory;
@@ -393,6 +392,21 @@ export const identityLdapAuthServiceFactory = ({
);
}
+ await assertIdentityAuthMutationAllowed(
+ { permissionService, orgDAL, membershipIdentityDAL },
+ {
+ identityId,
+ orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.EditAuth,
+ baseMessage: "Failed to add LDAP auth to identity with more privileged role",
+ actor,
+ actorId,
+ actorAuthMethod,
+ actorOrgId
+ }
+ );
+
if (templateId) {
ForbiddenError.from(orgPermission).throwUnlessCan(
OrgPermissionMachineIdentityAuthTemplateActions.AttachTemplates,
@@ -611,6 +625,21 @@ export const identityLdapAuthServiceFactory = ({
);
}
+ await assertIdentityAuthMutationAllowed(
+ { permissionService, orgDAL, membershipIdentityDAL },
+ {
+ identityId,
+ orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.EditAuth,
+ baseMessage: "Failed to update LDAP auth of identity with more privileged role",
+ actor,
+ actorId,
+ actorAuthMethod,
+ actorOrgId
+ }
+ );
+
if (templateId) {
ForbiddenError.from(orgPermission).throwUnlessCan(
OrgPermissionMachineIdentityAuthTemplateActions.AttachTemplates,
@@ -865,39 +894,22 @@ export const identityLdapAuthServiceFactory = ({
actorOrgId
});
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.RevokeAuth,
+ baseMessage: "Failed to revoke LDAP auth of 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.RevokeAuth,
- OrgPermissionSubjects.Identity,
- permission,
- rolePermission
- );
-
- if (!permissionBoundary.isValid)
- throw new PermissionBoundaryError({
- message: constructPermissionErrorMessage(
- "Failed to revoke LDAP auth of identity with more privileged role",
- shouldUseNewPrivilegeSystem,
- OrgPermissionIdentityActions.RevokeAuth,
- OrgPermissionSubjects.Identity
- ),
- details: { missingPermissions: permissionBoundary.missingPermissions }
- });
- }
+ actorOrgId
+ }
+ );
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
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 7c8f09cafd..cdb2fc426e 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
@@ -7,22 +7,12 @@ import RE2 from "re2";
import { AccessScope, ActionProjectType, IdentityAuthMethod, OrganizationActionScope } from "@app/db/schemas";
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
import { OrgPermissionIdentityActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
-import {
- constructPermissionErrorMessage,
- validatePrivilegeChangeOperation
-} from "@app/ee/services/permission/permission-fns";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import { ProjectPermissionIdentityActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
import { TKeyStoreFactory } from "@app/keystore/keystore";
import { getConfig } from "@app/lib/config/env";
import { request } from "@app/lib/config/request";
-import {
- BadRequestError,
- ForbiddenRequestError,
- NotFoundError,
- PermissionBoundaryError,
- UnauthorizedError
-} from "@app/lib/errors";
+import { BadRequestError, ForbiddenRequestError, NotFoundError, UnauthorizedError } from "@app/lib/errors";
import { extractIPDetails, isValidIpOrCidr, TIp } from "@app/lib/ip";
import { logger } from "@app/lib/logger";
import { requestMemoKeys } from "@app/lib/request-context/memo-keys";
@@ -36,6 +26,7 @@ import {
} from "@app/lib/telemetry/metrics";
import { ActorType } from "../auth/auth-type";
+import { assertIdentityAuthMutationAllowed } from "../identity/identity-auth-permission-fns";
import { TIdentityDALFactory } from "../identity/identity-dal";
import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";
import { TIdentityAccessTokenServiceFactory } from "../identity-access-token/identity-access-token-service";
@@ -60,7 +51,10 @@ type TIdentityOciAuthServiceFactoryDep = {
membershipIdentityDAL: Pick<TMembershipIdentityDALFactory, "findOne" | "update" | "getIdentityById">;
keyStore: Pick<TKeyStoreFactory, "setItemWithExpiryNX">;
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
- permissionService: Pick<TPermissionServiceFactory, "getOrgPermission" | "getProjectPermission">;
+ permissionService: Pick<
+ TPermissionServiceFactory,
+ "getOrgPermission" | "getProjectPermission" | "getOrgPermissionByRoles" | "getProjectPermissionByRoles"
+ >;
orgDAL: Pick<TOrgDALFactory, "findById" | "findOne" | "findEffectiveOrgMembership">;
identityAccessTokenService: Pick<
TIdentityAccessTokenServiceFactory,
@@ -324,6 +318,21 @@ export const identityOciAuthServiceFactory = ({
);
}
+ await assertIdentityAuthMutationAllowed(
+ { permissionService, orgDAL, membershipIdentityDAL },
+ {
+ identityId,
+ orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.EditAuth,
+ baseMessage: "Failed to add OCI auth to identity with more privileged role",
+ actor,
+ actorId,
+ actorAuthMethod,
+ actorOrgId
+ }
+ );
+
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
@@ -434,6 +443,21 @@ export const identityOciAuthServiceFactory = ({
);
}
+ await assertIdentityAuthMutationAllowed(
+ { permissionService, orgDAL, membershipIdentityDAL },
+ {
+ identityId,
+ orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.EditAuth,
+ baseMessage: "Failed to update OCI auth of identity with more privileged role",
+ actor,
+ actorId,
+ actorAuthMethod,
+ actorOrgId
+ }
+ );
+
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
@@ -568,38 +592,22 @@ export const identityOciAuthServiceFactory = ({
actorOrgId
});
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.RevokeAuth,
+ baseMessage: "Failed to revoke OCI auth of identity with more privileged role",
+ actor,
+ actorId,
actorAuthMethod,
- actorOrgId,
- scope: OrganizationActionScope.Any
- });
-
- const { shouldUseNewPrivilegeSystem } = await requestMemoize(requestMemoKeys.orgFindById(actorOrgId), () =>
- orgDAL.findById(actorOrgId)
- );
- const permissionBoundary = validatePrivilegeChangeOperation(
- shouldUseNewPrivilegeSystem,
- OrgPermissionIdentityActions.RevokeAuth,
- OrgPermissionSubjects.Identity,
- permission,
- rolePermission
- );
-
- if (!permissionBoundary.isValid)
- throw new PermissionBoundaryError({
- message: constructPermissionErrorMessage(
- "Failed to revoke OCI auth of identity with more privileged role",
- shouldUseNewPrivilegeSystem,
- OrgPermissionIdentityActions.RevokeAuth,
- OrgPermissionSubjects.Identity
- ),
- details: { missingPermissions: permissionBoundary.missingPermissions }
- });
- }
+ actorOrgId
+ }
+ );
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
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 1dd60c3141..d10ba61fc5 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
@@ -21,23 +21,13 @@ import {
OrgPermissionMachineIdentityAuthTemplateActions,
OrgPermissionSubjects
} from "@app/ee/services/permission/org-permission";
-import {
- constructPermissionErrorMessage,
- validatePrivilegeChangeOperation
-} from "@app/ee/services/permission/permission-fns";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import { ProjectPermissionIdentityActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
import { TKeyStoreFactory } from "@app/keystore/keystore";
import { getConfig } from "@app/lib/config/env";
import { request } from "@app/lib/config/request";
import { crypto } from "@app/lib/crypto";
-import {
- BadRequestError,
- ForbiddenRequestError,
- NotFoundError,
- PermissionBoundaryError,
- UnauthorizedError
-} from "@app/lib/errors";
+import { BadRequestError, ForbiddenRequestError, NotFoundError, UnauthorizedError } from "@app/lib/errors";
import { extractIPDetails, isValidIpOrCidr, TIp } from "@app/lib/ip";
import { logger } from "@app/lib/logger";
import { requestMemoKeys } from "@app/lib/request-context/memo-keys";
@@ -53,6 +43,7 @@ import { getValueByDot } from "@app/lib/template/dot-access";
import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";
import { ActorType } from "../auth/auth-type";
+import { assertIdentityAuthMutationAllowed } from "../identity/identity-auth-permission-fns";
import { TIdentityDALFactory } from "../identity/identity-dal";
import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";
import { TIdentityAccessTokenServiceFactory } from "../identity-access-token/identity-access-token-service";
@@ -79,7 +70,10 @@ type TIdentityOidcAuthServiceFactoryDep = {
membershipIdentityDAL: Pick<TMembershipIdentityDALFactory, "findOne" | "update" | "getIdentityById">;
keyStore: Pick<TKeyStoreFactory, "setItemWithExpiryNX">;
identityAccessTokenDAL: Pick<TIdentityAccessTokenDALFactory, "delete">;
- permissionService: Pick<TPermissionServiceFactory, "getOrgPermission" | "getProjectPermission">;
+ permissionService: Pick<
+ TPermissionServiceFactory,
+ "getOrgPermission" | "getProjectPermission" | "getOrgPermissionByRoles" | "getProjectPermissionByRoles"
+ >;
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
orgDAL: Pick<TOrgDALFactory, "findById" | "findOne" | "findEffectiveOrgMembership">;
@@ -663,6 +657,21 @@ export const identityOidcAuthServiceFactory = ({
);
}
+ await assertIdentityAuthMutationAllowed(
+ { permissionService, orgDAL, membershipIdentityDAL },
+ {
+ identityId,
+ orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.EditAuth,
+ baseMessage: "Failed to add oidc auth to identity with more privileged role",
+ actor,
+ actorId,
+ actorAuthMethod,
+ actorOrgId
+ }
+ );
+
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
@@ -853,6 +862,21 @@ export const identityOidcAuthServiceFactory = ({
);
}
+ await assertIdentityAuthMutationAllowed(
+ { permissionService, orgDAL, membershipIdentityDAL },
+ {
+ identityId,
+ orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.EditAuth,
+ baseMessage: "Failed to update oidc auth of identity with more privileged role",
+ actor,
+ actorId,
+ actorAuthMethod,
+ actorOrgId
+ }
+ );
+
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
@@ -1105,39 +1129,22 @@ export const identityOidcAuthServiceFactory = ({
});
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.RevokeAuth,
+ baseMessage: "Failed to revoke oidc auth of 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.RevokeAuth,
- OrgPermissionSubjects.Identity,
- permission,
- rolePermission
- );
-
- if (!permissionBoundary.isValid)
- throw new PermissionBoundaryError({
- message: constructPermissionErrorMessage(
- "Failed to revoke oidc auth of identity with more privileged role",
- shouldUseNewPrivilegeSystem,
- OrgPermissionIdentityActions.RevokeAuth,
- OrgPermissionSubjects.Identity
- ),
- details: { missingPermissions: permissionBoundary.missingPermissions }
- });
- }
+ actorOrgId
+ }
+ );
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
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 04f37f65a1..217c95c362 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
@@ -12,21 +12,11 @@ import {
} from "@app/db/schemas";
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
import { OrgPermissionIdentityActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
-import {
- constructPermissionErrorMessage,
- validatePrivilegeChangeOperation
-} from "@app/ee/services/permission/permission-fns";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import { ProjectPermissionIdentityActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
import { TKeyStoreFactory } from "@app/keystore/keystore";
import { getConfig } from "@app/lib/config/env";
-import {
- BadRequestError,
- ForbiddenRequestError,
- NotFoundError,
- PermissionBoundaryError,
- UnauthorizedError
-} from "@app/lib/errors";
+import { BadRequestError, ForbiddenRequestError, NotFoundError, UnauthorizedError } from "@app/lib/errors";
import { extractIPDetails, isValidIpOrCidr, TIp } from "@app/lib/ip";
import { logger } from "@app/lib/logger";
import { requestMemoKeys } from "@app/lib/request-context/memo-keys";
@@ -41,6 +31,7 @@ import {
import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";
import { ActorType } from "../auth/auth-type";
+import { assertIdentityAuthMutationAllowed } from "../identity/identity-auth-permission-fns";
import { TIdentityDALFactory } from "../identity/identity-dal";
import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";
import { TIdentityAccessTokenServiceFactory } from "../identity-access-token/identity-access-token-service";
@@ -75,7 +66,10 @@ type TIdentitySpiffeAuthServiceFactoryDep = {
membershipIdentityDAL: Pick<TMembershipIdentityDALFactory, "findOne" | "update" | "getIdentityById">;
keyStore: Pick<TKeyStoreFactory, "setItemWithExpiryNX">;
identityAccessTokenDAL: Pick<TIdentityAccessTokenDALFactory, "delete">;
- permissionService: Pick<TPermissionServiceFactory, "getOrgPermission" | "getProjectPermission">;
+ permissionService: Pick<
+ TPermissionServiceFactory,
+ "getOrgPermission" | "getProjectPermission" | "getOrgPermissionByRoles" | "getProjectPermissionByRoles"
+ >;
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
orgDAL: Pick<TOrgDALFactory, "findById" | "findOne" | "findEffectiveOrgMembership">;
@@ -551,6 +545,21 @@ export const identitySpiffeAuthServiceFactory = ({
);
}
+ await assertIdentityAuthMutationAllowed(
+ { permissionService, orgDAL, membershipIdentityDAL },
+ {
+ identityId,
+ orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.EditAuth,
+ baseMessage: "Failed to add SPIFFE auth to identity with more privileged role",
+ actor,
+ actorId,
+ actorAuthMethod,
+ actorOrgId
+ }
+ );
+
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
@@ -699,6 +708,21 @@ export const identitySpiffeAuthServiceFactory = ({
);
}
+ await assertIdentityAuthMutationAllowed(
+ { permissionService, orgDAL, membershipIdentityDAL },
+ {
+ identityId,
+ orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.EditAuth,
+ baseMessage: "Failed to update SPIFFE auth of identity with more privileged role",
+ actor,
+ actorId,
+ actorAuthMethod,
+ actorOrgId
+ }
+ );
+
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
@@ -898,38 +922,22 @@ export const identitySpiffeAuthServiceFactory = ({
});
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Edit, OrgPermissionSubjects.Identity);
+ }
- const { permission: rolePermission } = await permissionService.getOrgPermission({
- scope: OrganizationActionScope.Any,
- actor: ActorType.IDENTITY,
- actorId: identityMembershipOrg.identity.id,
+ await assertIdentityAuthMutationAllowed(
+ { permissionService, orgDAL, membershipIdentityDAL },
+ {
+ identityId,
orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.RevokeAuth,
+ baseMessage: "Failed to revoke SPIFFE auth of identity with more privileged role",
+ actor,
+ actorId,
actorAuthMethod,
actorOrgId
- });
-
- const { shouldUseNewPrivilegeSystem } = await requestMemoize(
- requestMemoKeys.orgFindById(identityMembershipOrg.scopeOrgId),
- () => orgDAL.findById(identityMembershipOrg.scopeOrgId)
- );
- const permissionBoundary = validatePrivilegeChangeOperation(
- shouldUseNewPrivilegeSystem,
- OrgPermissionIdentityActions.RevokeAuth,
- OrgPermissionSubjects.Identity,
- permission,
- rolePermission
- );
- if (!permissionBoundary.isValid)
- throw new PermissionBoundaryError({
- message: constructPermissionErrorMessage(
- "Failed to revoke SPIFFE auth of identity with more privileged role",
- shouldUseNewPrivilegeSystem,
- OrgPermissionIdentityActions.RevokeAuth,
- OrgPermissionSubjects.Identity
- ),
- details: { missingPermissions: permissionBoundary.missingPermissions }
- });
- }
+ }
+ );
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
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 5fa2b3e06e..e89a03f1fb 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
@@ -4,23 +4,13 @@ import { requestContext } from "@fastify/request-context";
import { AccessScope, ActionProjectType, IdentityAuthMethod, OrganizationActionScope } from "@app/db/schemas";
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
import { OrgPermissionIdentityActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
-import {
- constructPermissionErrorMessage,
- validatePrivilegeChangeOperation
-} from "@app/ee/services/permission/permission-fns";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import { ProjectPermissionIdentityActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
import { TKeyStoreFactory } from "@app/keystore/keystore";
import { extractX509CertFromChain } from "@app/lib/certificates/extract-certificate";
import { getConfig } from "@app/lib/config/env";
import { crypto } from "@app/lib/crypto/cryptography";
-import {
- BadRequestError,
- ForbiddenRequestError,
- NotFoundError,
- PermissionBoundaryError,
- UnauthorizedError
-} from "@app/lib/errors";
+import { BadRequestError, ForbiddenRequestError, NotFoundError, UnauthorizedError } from "@app/lib/errors";
import { extractIPDetails, isValidIpOrCidr, TIp } from "@app/lib/ip";
import { logger } from "@app/lib/logger";
import { requestMemoKeys } from "@app/lib/request-context/memo-keys";
@@ -34,6 +24,7 @@ import {
} from "@app/lib/telemetry/metrics";
import { ActorType } from "../auth/auth-type";
+import { assertIdentityAuthMutationAllowed } from "../identity/identity-auth-permission-fns";
import { TIdentityDALFactory } from "../identity/identity-dal";
import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";
import { TIdentityAccessTokenServiceFactory } from "../identity-access-token/identity-access-token-service";
@@ -178,7 +169,10 @@ type TIdentityTlsCertAuthServiceFactoryDep = {
membershipIdentityDAL: Pick<TMembershipIdentityDALFactory, "findOne" | "update" | "getIdentityById">;
keyStore: Pick<TKeyStoreFactory, "setItemWithExpiryNX">;
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
- permissionService: Pick<TPermissionServiceFactory, "getOrgPermission" | "getProjectPermission">;
+ permissionService: Pick<
+ TPermissionServiceFactory,
+ "getOrgPermission" | "getProjectPermission" | "getOrgPermissionByRoles" | "getProjectPermissionByRoles"
+ >;
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
orgDAL: Pick<TOrgDALFactory, "findById" | "findOne" | "findEffectiveOrgMembership">;
identityAccessTokenService: Pick<
@@ -541,6 +535,21 @@ export const identityTlsCertAuthServiceFactory = ({
);
}
+ await assertIdentityAuthMutationAllowed(
+ { permissionService, orgDAL, membershipIdentityDAL },
+ {
+ identityId,
+ orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.EditAuth,
+ baseMessage: "Failed to add TLS Certificate auth to identity with more privileged role",
+ actor,
+ actorId,
+ actorAuthMethod,
+ actorOrgId
+ }
+ );
+
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
@@ -662,6 +671,21 @@ export const identityTlsCertAuthServiceFactory = ({
);
}
+ await assertIdentityAuthMutationAllowed(
+ { permissionService, orgDAL, membershipIdentityDAL },
+ {
+ identityId,
+ orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.EditAuth,
+ baseMessage: "Failed to update TLS Certificate auth of identity with more privileged role",
+ actor,
+ actorId,
+ actorAuthMethod,
+ actorOrgId
+ }
+ );
+
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
@@ -827,35 +851,22 @@ export const identityTlsCertAuthServiceFactory = ({
actorOrgId
});
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Edit, OrgPermissionSubjects.Identity);
+ }
- const { permission: rolePermission, memberships } = 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.RevokeAuth,
+ baseMessage: "Failed to revoke TLS Certificate auth of identity with more privileged role",
+ actor,
+ actorId,
actorAuthMethod,
- actorOrgId,
- scope: OrganizationActionScope.Any
- });
- const shouldUseNewPrivilegeSystem = Boolean(memberships?.[0]?.shouldUseNewPrivilegeSystem);
- const permissionBoundary = validatePrivilegeChangeOperation(
- shouldUseNewPrivilegeSystem,
- OrgPermissionIdentityActions.RevokeAuth,
- OrgPermissionSubjects.Identity,
- permission,
- rolePermission
- );
-
- if (!permissionBoundary.isValid)
- throw new PermissionBoundaryError({
- message: constructPermissionErrorMessage(
- "Failed to revoke TLS Certificate auth of identity with more privileged role",
- shouldUseNewPrivilegeSystem,
- OrgPermissionIdentityActions.RevokeAuth,
- OrgPermissionSubjects.Identity
- ),
- details: { missingPermissions: permissionBoundary.missingPermissions }
- });
- }
+ actorOrgId
+ }
+ );
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
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 dec4dcb2b5..0425d357a8 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
@@ -28,6 +28,7 @@ import { requestMemoKeys } from "@app/lib/request-context/memo-keys";
import { requestMemoize } from "@app/lib/request-context/request-memoizer";
import { ActorType } from "../auth/auth-type";
+import { assertIdentityAuthMutationAllowed } from "../identity/identity-auth-permission-fns";
import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";
import { computeTokenAuthRevokeMarkerExpiry } from "../identity-access-token/identity-access-token-fns";
import { TIdentityAccessTokenServiceFactory } from "../identity-access-token/identity-access-token-service";
@@ -66,7 +67,10 @@ type TIdentityTokenAuthServiceFactoryDep = {
| "markPerTokenRevocation"
| "invalidateTrustedIpsCache"
>;
- permissionService: Pick<TPermissionServiceFactory, "getOrgPermission" | "getProjectPermission">;
+ permissionService: Pick<
+ TPermissionServiceFactory,
+ "getOrgPermission" | "getProjectPermission" | "getOrgPermissionByRoles" | "getProjectPermissionByRoles"
+ >;
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
orgDAL: Pick<TOrgDALFactory, "findById" | "findOne" | "findEffectiveOrgMembership">;
};
@@ -146,6 +150,21 @@ export const identityTokenAuthServiceFactory = ({
);
}
+ await assertIdentityAuthMutationAllowed(
+ { permissionService, orgDAL, membershipIdentityDAL },
+ {
+ identityId,
+ orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.EditAuth,
+ baseMessage: "Failed to add token auth to identity with more privileged role",
+ actor,
+ actorId,
+ actorAuthMethod,
+ actorOrgId
+ }
+ );
+
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
@@ -252,6 +271,21 @@ export const identityTokenAuthServiceFactory = ({
);
}
+ await assertIdentityAuthMutationAllowed(
+ { permissionService, orgDAL, membershipIdentityDAL },
+ {
+ identityId,
+ orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.EditAuth,
+ baseMessage: "Failed to update token auth of identity with more privileged role",
+ actor,
+ actorId,
+ actorAuthMethod,
+ actorOrgId
+ }
+ );
+
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
@@ -388,38 +422,22 @@ export const identityTokenAuthServiceFactory = ({
actorOrgId
});
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.RevokeAuth,
+ baseMessage: "Failed to revoke token auth of 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.RevokeAuth,
- OrgPermissionSubjects.Identity,
- permission,
- rolePermission
- );
- if (!permissionBoundary.isValid)
- throw new PermissionBoundaryError({
- message: constructPermissionErrorMessage(
- "Failed to revoke token auth of identity with more privileged role",
- shouldUseNewPrivilegeSystem,
- OrgPermissionIdentityActions.RevokeAuth,
- 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.ts
index 3eda256ce9..f076f04d70 100644
--- a/backend/src/services/identity-ua/identity-ua-service.ts
+++ b/backend/src/services/identity-ua/identity-ua-service.ts
@@ -34,6 +34,7 @@ import {
} from "@app/lib/telemetry/metrics";
import { ActorType } from "../auth/auth-type";
+import { assertIdentityAuthMutationAllowed } from "../identity/identity-auth-permission-fns";
import { TIdentityDALFactory } from "../identity/identity-dal";
import {
clearIdentityLockoutsForAuthMethod,
@@ -67,7 +68,10 @@ type TIdentityUaServiceFactoryDep = {
identityUaDAL: TIdentityUaDALFactory;
identityUaClientSecretDAL: TIdentityUaClientSecretDALFactory;
membershipIdentityDAL: TMembershipIdentityDALFactory;
- permissionService: Pick<TPermissionServiceFactory, "getOrgPermission" | "getProjectPermission">;
+ permissionService: Pick<
+ TPermissionServiceFactory,
+ "getOrgPermission" | "getProjectPermission" | "getOrgPermissionByRoles" | "getProjectPermissionByRoles"
+ >;
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
orgDAL: Pick<TOrgDALFactory, "findById" | "findOne" | "findEffectiveOrgMembership">;
identityAccessTokenService: Pick<
@@ -491,6 +495,21 @@ export const identityUaServiceFactory = ({
);
}
+ await assertIdentityAuthMutationAllowed(
+ { permissionService, orgDAL, membershipIdentityDAL },
+ {
+ identityId,
+ orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.EditAuth,
+ baseMessage: "Failed to add universal auth to identity with more privileged role",
+ actor,
+ actorId,
+ actorAuthMethod,
+ actorOrgId
+ }
+ );
+
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
@@ -632,6 +651,21 @@ export const identityUaServiceFactory = ({
);
}
+ await assertIdentityAuthMutationAllowed(
+ { permissionService, orgDAL, membershipIdentityDAL },
+ {
+ identityId,
+ orgId: identityMembershipOrg.scopeOrgId,
+ projectId: identityMembershipOrg.identity.projectId,
+ action: OrgPermissionIdentityActions.EditAuth,
+ baseMessage: "Failed to update universal auth of identity with more privileged role",
+ actor,
+ actorId,
+ actorAuthMethod,
+ actorOrgId
+ }
+ );
+
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
@@ -790,37 +824,22 @@ export const identityUaServiceFactory = ({
actorOrgId
});
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.RevokeAuth,
+ baseMessage: "Failed to revoke universal auth of 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.RevokeAuth,
- OrgPermissionSubjects.Identity,
- permission,
- rolePermission
- );
- if (!permissionBoundary.isValid)
- throw new PermissionBoundaryError({
- message: constructPermissionErrorMessage(
- "Failed to revoke universal auth of identity with more privileged role",
- shouldUseNewPrivilegeSystem,
- OrgPermissionIdentityActions.RevokeAuth,
- OrgPermissionSubjects.Identity
- ),
- details: { missingPermissions: permissionBoundary.missingPermissions }
- });
- }
+ actorOrgId
+ }
+ );
await validateIdentityUpdateForSuperAdminPrivileges(identityId, isActorSuperAdmin);
const revokedIdentityUniversalAuth = await identityUaDAL.transaction(async (tx) => {
diff --git a/backend/src/services/identity/identity-auth-permission-fns.test.ts b/backend/src/services/identity/identity-auth-permission-fns.test.ts
new file mode 100644
index 0000000000..012707f7fd
--- /dev/null
+++ b/backend/src/services/identity/identity-auth-permission-fns.test.ts
@@ -0,0 +1,169 @@
+import { createMongoAbility, MongoAbility } from "@casl/ability";
+
+import { AccessScope } from "@app/db/schemas";
+import { projectAdminPermissions, projectMemberPermissions } from "@app/ee/services/permission/default-roles";
+import {
+ orgAdminPermissions,
+ orgMemberPermissions,
+ OrgPermissionIdentityActions,
+ OrgPermissionSet,
+ OrgPermissionSubjects
+} from "@app/ee/services/permission/org-permission";
+import {
+ ProjectPermissionIdentityActions,
+ ProjectPermissionSet,
+ ProjectPermissionSub
+} from "@app/ee/services/permission/project-permission";
+import { PermissionBoundaryError } from "@app/lib/errors";
+import { ActorType } from "@app/services/auth/auth-type";
+
+import { assertIdentityAuthMutationAllowed } from "./identity-auth-permission-fns";
+
+// Regression guard for the privilege boundary on identity auth-method mutations. Attach and update
+// 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.
+
+const orgAdmin = createMongoAbility<MongoAbility<OrgPermissionSet>>(orgAdminPermissions);
+const orgMember = createMongoAbility<MongoAbility<OrgPermissionSet>>(orgMemberPermissions);
+const orgEditAuthOnly = createMongoAbility<MongoAbility<OrgPermissionSet>>([
+ { action: OrgPermissionIdentityActions.EditAuth, subject: OrgPermissionSubjects.Identity },
+ { action: OrgPermissionIdentityActions.RevokeAuth, subject: OrgPermissionSubjects.Identity }
+]);
+
+const projectAdmin = createMongoAbility<MongoAbility<ProjectPermissionSet>>(projectAdminPermissions);
+const projectMember = createMongoAbility<MongoAbility<ProjectPermissionSet>>(projectMemberPermissions);
+const projectEditAuthOnly = createMongoAbility<MongoAbility<ProjectPermissionSet>>([
+ { action: ProjectPermissionIdentityActions.EditAuth, subject: ProjectPermissionSub.Identity }
+]);
+
+type TScopeCall = { scope: AccessScope; orgId: string; projectId?: string };
+
+const runBoundary = async ({
+ shouldUseNewPrivilegeSystem = false,
+ actorPermission,
+ targetPermissions,
+ projectId,
+ scopeCalls = []
+}: {
+ shouldUseNewPrivilegeSystem?: boolean;
+ actorPermission: MongoAbility;
+ targetPermissions: MongoAbility[];
+ projectId?: string;
+ scopeCalls?: TScopeCall[];
+}) => {
+ const deps = {
+ permissionService: {
+ getOrgPermission: () => Promise.resolve({ permission: actorPermission }),
+ getProjectPermission: () => Promise.resolve({ permission: actorPermission }),
+ getOrgPermissionByRoles: () => Promise.resolve(targetPermissions.map((permission) => ({ permission }))),
+ getProjectPermissionByRoles: () => Promise.resolve(targetPermissions.map((permission) => ({ permission })))
+ },
+ orgDAL: { findById: () => Promise.resolve({ shouldUseNewPrivilegeSystem }) },
+ membershipIdentityDAL: {
+ getIdentityById: ({ scopeData }: { scopeData: TScopeCall }) => {
+ scopeCalls.push(scopeData);
+ return Promise.resolve({ roles: [{ role: "member" }] });
+ }
+ }
+ } as unknown as Parameters<typeof assertIdentityAuthMutationAllowed>[0];
+
+ await assertIdentityAuthMutationAllowed(deps, {
+ identityId: "identity-1",
+ orgId: "org-1",
+ projectId,
+ action: OrgPermissionIdentityActions.EditAuth,
+ baseMessage: "Failed to add token auth to identity with more privileged role",
+ actor: ActorType.USER,
+ actorId: "user-1",
+ actorAuthMethod: null,
+ actorOrgId: "org-1"
+ });
+};
+
+describe("assertIdentityAuthMutationAllowed", () => {
+ describe("organization-level identity", () => {
+ test("an admin actor may configure a member identity's auth", async () => {
+ await expect(runBoundary({ actorPermission: orgAdmin, targetPermissions: [orgMember] })).resolves.toBeUndefined();
+ });
+
+ test("an edit-auth-only actor may not configure an admin identity's auth", async () => {
+ await expect(runBoundary({ actorPermission: orgEditAuthOnly, targetPermissions: [orgAdmin] })).rejects.toThrow(
+ PermissionBoundaryError
+ );
+ });
+
+ test("every role the target holds is bounded, not just the first", async () => {
+ await expect(
+ runBoundary({ actorPermission: orgAdmin, targetPermissions: [orgMember, orgAdmin] })
+ ).resolves.toBeUndefined();
+ await expect(
+ runBoundary({ actorPermission: orgEditAuthOnly, targetPermissions: [orgEditAuthOnly, orgAdmin] })
+ ).rejects.toThrow(PermissionBoundaryError);
+ });
+
+ test("the target's roles are resolved in organization scope", async () => {
+ const scopeCalls: TScopeCall[] = [];
+ await runBoundary({ actorPermission: orgAdmin, targetPermissions: [orgMember], scopeCalls });
+ expect(scopeCalls).toEqual([{ scope: AccessScope.Organization, orgId: "org-1" }]);
+ });
+
+ test("holding the action is sufficient under the new privilege system", async () => {
+ await expect(
+ runBoundary({
+ shouldUseNewPrivilegeSystem: true,
+ actorPermission: orgEditAuthOnly,
+ targetPermissions: [orgAdmin]
+ })
+ ).resolves.toBeUndefined();
+ await expect(
+ runBoundary({ shouldUseNewPrivilegeSystem: true, actorPermission: orgMember, targetPermissions: [orgMember] })
+ ).rejects.toThrow(PermissionBoundaryError);
+ });
+ });
+
+ describe("project-level identity", () => {
+ test("an admin actor may configure a member identity's auth", async () => {
+ await expect(
+ runBoundary({ actorPermission: projectAdmin, targetPermissions: [projectMember], projectId: "project-1" })
+ ).resolves.toBeUndefined();
+ });
+
+ test("an edit-auth-only actor may not configure an admin identity's auth", async () => {
+ await expect(
+ runBoundary({ actorPermission: projectEditAuthOnly, targetPermissions: [projectAdmin], projectId: "project-1" })
+ ).rejects.toThrow(PermissionBoundaryError);
+ });
+
+ test("the target's roles are resolved in project scope", async () => {
+ const scopeCalls: TScopeCall[] = [];
+ await runBoundary({
+ actorPermission: projectAdmin,
+ targetPermissions: [projectMember],
+ projectId: "project-1",
+ scopeCalls
+ });
+ expect(scopeCalls).toEqual([{ scope: AccessScope.Project, orgId: "org-1", projectId: "project-1" }]);
+ });
+
+ test("holding the action is sufficient under the new privilege system", async () => {
+ await expect(
+ runBoundary({
+ shouldUseNewPrivilegeSystem: true,
+ actorPermission: projectEditAuthOnly,
+ targetPermissions: [projectAdmin],
+ projectId: "project-1"
+ })
+ ).resolves.toBeUndefined();
+ await expect(
+ runBoundary({
+ shouldUseNewPrivilegeSystem: true,
+ actorPermission: projectMember,
+ targetPermissions: [projectMember],
+ projectId: "project-1"
+ })
+ ).rejects.toThrow(PermissionBoundaryError);
+ });
+ });
+});
diff --git a/backend/src/services/identity/identity-auth-permission-fns.ts b/backend/src/services/identity/identity-auth-permission-fns.ts
new file mode 100644
index 0000000000..328fcaba0d
--- /dev/null
+++ b/backend/src/services/identity/identity-auth-permission-fns.ts
@@ -0,0 +1,117 @@
+import { AccessScope, ActionProjectType, OrganizationActionScope } from "@app/db/schemas";
+import { OrgPermissionIdentityActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
+import { assertRoleSetBoundary } from "@app/ee/services/permission/permission-fns";
+import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
+import { ProjectPermissionIdentityActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
+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 = {
+ [OrgPermissionIdentityActions.EditAuth]: ProjectPermissionIdentityActions.EditAuth,
+ [OrgPermissionIdentityActions.RevokeAuth]: ProjectPermissionIdentityActions.RevokeAuth
+} as const;
+
+type TIdentityAuthPermissionDeps = {
+ permissionService: Pick<
+ TPermissionServiceFactory,
+ "getOrgPermission" | "getProjectPermission" | "getOrgPermissionByRoles" | "getProjectPermissionByRoles"
+ >;
+ orgDAL: Pick<TOrgDALFactory, "findById">;
+ membershipIdentityDAL: Pick<TMembershipIdentityDALFactory, "getIdentityById">;
+};
+
+type TAssertIdentityAuthMutationAllowedDTO = {
+ identityId: string;
+ orgId: string;
+ projectId?: string | null;
+ action: keyof typeof PROJECT_ACTION_BY_ORG_ACTION;
+ baseMessage: string;
+ actor: ActorType;
+ actorId: string;
+ actorAuthMethod: ActorAuthMethod;
+ 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
+// `assertRoleSetBoundary` reduces to the action check the caller already ran.
+export const assertIdentityAuthMutationAllowed = async (
+ { permissionService, orgDAL, membershipIdentityDAL }: TIdentityAuthPermissionDeps,
+ {
+ identityId,
+ orgId,
+ projectId,
+ action,
+ baseMessage,
+ actor,
+ actorId,
+ actorAuthMethod,
+ actorOrgId
+ }: TAssertIdentityAuthMutationAllowedDTO
+) => {
+ const { shouldUseNewPrivilegeSystem } = await requestMemoize(requestMemoKeys.orgFindById(orgId), () =>
+ orgDAL.findById(orgId)
+ );
+
+ // Roles rather than the target's own ability, because `getProjectPermission` stamps whichever actor
+ // it was called for onto the request context the audit log reads.
+ const targetMembership = await membershipIdentityDAL.getIdentityById({
+ scopeData: projectId
+ ? { scope: AccessScope.Project, orgId, projectId }
+ : { scope: AccessScope.Organization, orgId },
+ identityId
+ });
+ const targetRoles = targetMembership ? resolveMembershipRoleSlugs(targetMembership.roles) : [];
+
+ if (projectId) {
+ const { permission } = await permissionService.getProjectPermission({
+ actionProjectType: ActionProjectType.Any,
+ actor,
+ actorId,
+ projectId,
+ actorAuthMethod,
+ actorOrgId
+ });
+ const targetPermissions = await permissionService.getProjectPermissionByRoles(targetRoles, projectId, {
+ ignoreUnresolvedRoles: true
+ });
+
+ assertRoleSetBoundary({
+ shouldUseNewPrivilegeSystem,
+ opActions: PROJECT_ACTION_BY_ORG_ACTION[action],
+ opSubject: ProjectPermissionSub.Identity,
+ actorPermission: permission,
+ // Dropping `role` keeps `assignableRole` out of the subject, so the fields match the gate the
+ // caller already passed and nothing tightens for new-privilege-system orgs.
+ targetPermissions: targetPermissions.map(({ permission: rolePermission }) => ({ permission: rolePermission })),
+ baseMessage,
+ subjectFields: { identityId }
+ });
+ return;
+ }
+
+ const { permission } = await permissionService.getOrgPermission({
+ scope: OrganizationActionScope.Any,
+ actor,
+ actorId,
+ orgId,
+ actorAuthMethod,
+ actorOrgId
+ });
+ const targetPermissions = await permissionService.getOrgPermissionByRoles(targetRoles, orgId, {
+ ignoreUnresolvedRoles: true
+ });
+
+ assertRoleSetBoundary({
+ shouldUseNewPrivilegeSystem,
+ opActions: action,
+ opSubject: OrgPermissionSubjects.Identity,
+ actorPermission: permission,
+ targetPermissions: targetPermissions.map(({ permission: rolePermission }) => ({ permission: rolePermission })),
+ baseMessage
+ });
+};