Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
Merge remote-tracking branch 'origin/main' into misc/privilege-management-v2-transition
Sheen Capadngandb8a4bd26d3a
diff --cc backend/src/ee/services/group/group-service.tsindex fdb582bbfb,27e847896b..52f8970225--- a/backend/src/ee/services/group/group-service.ts+++ b/backend/src/ee/services/group/group-service.ts@@@ -88,15 -88,13 +88,18 @@@ export const groupServiceFactory = ();const isCustomRole = Boolean(customRole);- const hasRequiredPriviledges = validatePrivilegeChangeOperation(- const permissionBoundary = validatePermissionBoundary(permission, rolePermission);++ const permissionBoundary = validatePrivilegeChangeOperation(+ OrgPermissionGroupActions.ManagePrivileges,+ OrgPermissionSubjects.Groups,+ permission,+ rolePermission+ );-- if (!hasRequiredPriviledges)- throw new ForbiddenRequestError({ message: "Failed to create a more privileged group" });+ if (!permissionBoundary.isValid)+ throw new ForbiddenRequestError({+ name: "PermissionBoundaryError",+ message: "Failed to create a more privileged group",+ details: { missingPermissions: permissionBoundary.missingPermissions }+ });const group = await groupDAL.transaction(async (tx) => {const existingGroup = await groupDAL.findOne({ orgId: actorOrgId, name }, tx);@@@ -163,15 -161,13 +166,18 @@@);const isCustomRole = Boolean(customOrgRole);- const hasRequiredNewRolePermission = validatePrivilegeChangeOperation(- const permissionBoundary = validatePermissionBoundary(permission, rolePermission);++ const permissionBoundary = validatePrivilegeChangeOperation(+ OrgPermissionGroupActions.ManagePrivileges,+ OrgPermissionSubjects.Groups,+ permission,+ rolePermission+ );-- if (!hasRequiredNewRolePermission)- throw new ForbiddenRequestError({ message: "Failed to create a more privileged group" });+ if (!permissionBoundary.isValid)+ throw new ForbiddenRequestError({+ name: "PermissionBoundaryError",+ message: "Failed to update a more privileged group",+ details: { missingPermissions: permissionBoundary.missingPermissions }+ });if (isCustomRole) customRole = customOrgRole;}@@@ -342,15 -338,13 +348,18 @@@const { permission: groupRolePermission } = await permissionService.getOrgPermissionByRole(group.role, actorOrgId);// check if user has broader or equal to privileges than group- const hasRequiredPrivileges = validatePrivilegeChangeOperation(- OrgPermissionGroupActions.AddMembers,- const permissionBoundary = validatePermissionBoundary(permission, groupRolePermission);++ const permissionBoundary = validatePrivilegeChangeOperation(++ OrgPermissionGroupActions.ManagePrivileges,+ OrgPermissionSubjects.Groups,+ permission,+ groupRolePermission+ );-- if (!hasRequiredPrivileges)- throw new ForbiddenRequestError({ message: "Failed to add user to more privileged group" });+ if (!permissionBoundary.isValid)+ throw new ForbiddenRequestError({+ name: "PermissionBoundaryError",+ message: "Failed to add user to more privileged group",+ details: { missingPermissions: permissionBoundary.missingPermissions }+ });const user = await userDAL.findOne({ username });if (!user) throw new NotFoundError({ message: `Failed to find user with username ${username}` });@@@ -415,15 -409,13 +424,18 @@@const { permission: groupRolePermission } = await permissionService.getOrgPermissionByRole(group.role, actorOrgId);// check if user has broader or equal to privileges than group- const hasRequiredPrivileges = validatePrivilegeChangeOperation(- OrgPermissionGroupActions.RemoveMembers,- const permissionBoundary = validatePermissionBoundary(permission, groupRolePermission);++ const permissionBoundary = validatePrivilegeChangeOperation(++ OrgPermissionGroupActions.ManagePrivileges,+ OrgPermissionSubjects.Groups,+ permission,+ groupRolePermission+ );-- if (!hasRequiredPrivileges)- throw new ForbiddenRequestError({ message: "Failed to delete user from more privileged group" });+ if (!permissionBoundary.isValid)+ throw new ForbiddenRequestError({+ name: "PermissionBoundaryError",+ message: "Failed to delete user from more privileged group",+ details: { missingPermissions: permissionBoundary.missingPermissions }+ });const user = await userDAL.findOne({ username });if (!user) throw new NotFoundError({ message: `Failed to find user with username ${username}` });diff --cc backend/src/ee/services/identity-project-additional-privilege-v2/identity-project-additional-privilege-v2-service.tsindex 6fbc277022,3c984585c6..03bbbd8eba--- a/backend/src/ee/services/identity-project-additional-privilege-v2/identity-project-additional-privilege-v2-service.ts+++ b/backend/src/ee/services/identity-project-additional-privilege-v2/identity-project-additional-privilege-v2-service.ts@@@ -79,14 -79,13 +79,18 @@@ export const identityProjectAdditionalP// we need to validate that the privilege given is not higher than the assigning users permission// @ts-expect-error this is expected error because of one being really accurate rule definition other being a bit more broader. Both are valid casl rulestargetIdentityPermission.update(targetIdentityPermission.rules.concat(customPermission));- const hasRequiredPrivileges = validatePrivilegeChangeOperation(- const permissionBoundary = validatePermissionBoundary(permission, targetIdentityPermission);++ const permissionBoundary = validatePrivilegeChangeOperation(+ ProjectPermissionIdentityActions.ManagePrivileges,+ ProjectPermissionSub.Identity,+ permission,+ targetIdentityPermission+ );- if (!hasRequiredPrivileges)- throw new ForbiddenRequestError({ message: "Failed to update more privileged identity" });+ if (!permissionBoundary.isValid)+ throw new ForbiddenRequestError({+ name: "PermissionBoundaryError",+ message: "Failed to update more privileged identity",+ details: { missingPermissions: permissionBoundary.missingPermissions }+ });const existingSlug = await identityProjectAdditionalPrivilegeDAL.findOne({slug,@@@ -166,14 -165,13 +170,18 @@@// we need to validate that the privilege given is not higher than the assigning users permission// @ts-expect-error this is expected error because of one being really accurate rule definition other being a bit more broader. Both are valid casl rulestargetIdentityPermission.update(targetIdentityPermission.rules.concat(data.permissions || []));- const hasRequiredPrivileges = validatePrivilegeChangeOperation(- const permissionBoundary = validatePermissionBoundary(permission, targetIdentityPermission);++ const permissionBoundary = validatePrivilegeChangeOperation(+ ProjectPermissionIdentityActions.ManagePrivileges,+ ProjectPermissionSub.Identity,+ permission,+ targetIdentityPermission+ );- if (!hasRequiredPrivileges)- throw new ForbiddenRequestError({ message: "Failed to update more privileged identity" });+ if (!permissionBoundary.isValid)+ throw new ForbiddenRequestError({+ name: "PermissionBoundaryError",+ message: "Failed to update more privileged identity",+ details: { missingPermissions: permissionBoundary.missingPermissions }+ });if (data?.slug) {const existingSlug = await identityProjectAdditionalPrivilegeDAL.findOne({@@@ -249,14 -247,13 +257,18 @@@actorOrgId,actionProjectType: ActionProjectType.Any});- const hasRequiredPriviledges = validatePrivilegeChangeOperation(- const permissionBoundary = validatePermissionBoundary(permission, identityRolePermission);++ const permissionBoundary = validatePrivilegeChangeOperation(+ ProjectPermissionIdentityActions.ManagePrivileges,+ ProjectPermissionSub.Identity,+ permission,+ identityRolePermission+ );- if (!hasRequiredPriviledges)- throw new ForbiddenRequestError({ message: "Failed to update more privileged identity" });+ if (!permissionBoundary.isValid)+ throw new ForbiddenRequestError({+ name: "PermissionBoundaryError",+ message: "Failed to update more privileged identity",+ details: { missingPermissions: permissionBoundary.missingPermissions }+ });const deletedPrivilege = await identityProjectAdditionalPrivilegeDAL.deleteById(identityPrivilege.id);return {diff --cc backend/src/ee/services/identity-project-additional-privilege/identity-project-additional-privilege-service.tsindex 3b9021b30d,22e4c19844..513a933bfc--- a/backend/src/ee/services/identity-project-additional-privilege/identity-project-additional-privilege-service.ts+++ b/backend/src/ee/services/identity-project-additional-privilege/identity-project-additional-privilege-service.ts@@@ -93,14 -88,13 +93,18 @@@ export const identityProjectAdditionalP// we need to validate that the privilege given is not higher than the assigning users permission// @ts-expect-error this is expected error because of one being really accurate rule definition other being a bit more broader. Both are valid casl rulestargetIdentityPermission.update(targetIdentityPermission.rules.concat(customPermission));- const hasRequiredPrivileges = validatePrivilegeChangeOperation(- const permissionBoundary = validatePermissionBoundary(permission, targetIdentityPermission);++ const permissionBoundary = validatePrivilegeChangeOperation(+ ProjectPermissionIdentityActions.ManagePrivileges,+ ProjectPermissionSub.Identity,+ permission,+ targetIdentityPermission+ );- if (!hasRequiredPrivileges)- throw new ForbiddenRequestError({ message: "Failed to update more privileged identity" });+ if (!permissionBoundary.isValid)+ throw new ForbiddenRequestError({+ name: "PermissionBoundaryError",+ message: "Failed to update more privileged identity",+ details: { missingPermissions: permissionBoundary.missingPermissions }+ });const existingSlug = await identityProjectAdditionalPrivilegeDAL.findOne({slug,@@@ -182,14 -176,13 +186,18 @@@// we need to validate that the privilege given is not higher than the assigning users permission// @ts-expect-error this is expected error because of one being really accurate rule definition other being a bit more broader. Both are valid casl rulestargetIdentityPermission.update(targetIdentityPermission.rules.concat(data.permissions || []));- const hasRequiredPrivileges = validatePrivilegeChangeOperation(- const permissionBoundary = validatePermissionBoundary(permission, targetIdentityPermission);++ const permissionBoundary = validatePrivilegeChangeOperation(+ ProjectPermissionIdentityActions.ManagePrivileges,+ ProjectPermissionSub.Identity,+ permission,+ targetIdentityPermission+ );- if (!hasRequiredPrivileges)- throw new ForbiddenRequestError({ message: "Failed to update more privileged identity" });+ if (!permissionBoundary.isValid)+ throw new ForbiddenRequestError({+ name: "PermissionBoundaryError",+ message: "Failed to update more privileged identity",+ details: { missingPermissions: permissionBoundary.missingPermissions }+ });const identityPrivilege = await identityProjectAdditionalPrivilegeDAL.findOne({slug,@@@ -283,14 -276,13 +291,18 @@@actorOrgId,actionProjectType: ActionProjectType.Any});-- const hasRequiredPrivileges = validatePrivilegeChangeOperation(- const permissionBoundary = validatePermissionBoundary(permission, identityRolePermission);++ const permissionBoundary = validatePrivilegeChangeOperation(+ ProjectPermissionIdentityActions.ManagePrivileges,+ ProjectPermissionSub.Identity,+ permission,+ identityRolePermission+ );- if (!hasRequiredPrivileges) throw new ForbiddenRequestError({ message: "Failed to edit more privileged identity" });+ if (!permissionBoundary.isValid)+ throw new ForbiddenRequestError({+ name: "PermissionBoundaryError",+ message: "Failed to edit more privileged identity",+ details: { missingPermissions: permissionBoundary.missingPermissions }+ });const identityPrivilege = await identityProjectAdditionalPrivilegeDAL.findOne({slug,diff --cc backend/src/ee/services/permission/permission-fns.tsindex b7913888a1,80a58db0a5..08e7b866ec--- a/backend/src/ee/services/permission/permission-fns.ts+++ b/backend/src/ee/services/permission/permission-fns.ts@@@ -1,7 -1,4 +1,7 @@@+import { MongoAbility } from "@casl/ability";+import { TOrganizations } from "@app/db/schemas";- import { isAtLeastAsPrivileged } from "@app/lib/casl";++import { validatePermissionBoundary } from "@app/lib/casl/boundary";import { ForbiddenRequestError, UnauthorizedError } from "@app/lib/errors";import { ActorAuthMethod, AuthMethod } from "@app/services/auth/auth-type";@@@ -49,19 -43,4 +49,26 @@@ const escapeHandlebarsMissingMetadatareturn new Proxy(obj, handler);};-export { escapeHandlebarsMissingMetadata, isAuthMethodSaml, validateOrgSSO };+// This function serves as a transition layer between the old and new privilege management system+// the old privilege management system is based on the actor having more privileges than the managed permission+// the new privilege management system is based on the actor having the appropriate permission to perform the privilege change,+// regardless of the actor's privilege level.+const validatePrivilegeChangeOperation = (+ action: OrgPermissionSet[0] | ProjectPermissionSet[0],+ subject: OrgPermissionSet[1] | ProjectPermissionSet[1],+ actorPermission: MongoAbility,+ managedPermission: MongoAbility+) => {+ // first we ensure if the actor has the permission to manage the privilege- // if not, we check if the actor is indeed more privileged than the managed permission- return actorPermission.can(action, subject) || isAtLeastAsPrivileged(actorPermission, managedPermission);++ if (actorPermission.can(action, subject)) {++ return {++ isValid: true,++ missingPermissions: []++ };++ }++++ // if not, we check if the actor is indeed more privileged than the managed permission - this is the old system++ return validatePermissionBoundary(actorPermission, managedPermission);+};++export { escapeHandlebarsMissingMetadata, isAuthMethodSaml, validateOrgSSO, validatePrivilegeChangeOperation };diff --cc backend/src/ee/services/project-user-additional-privilege/project-user-additional-privilege-service.tsindex f2b37d606b,e406d9c887..167ce09645--- a/backend/src/ee/services/project-user-additional-privilege/project-user-additional-privilege-service.ts+++ b/backend/src/ee/services/project-user-additional-privilege/project-user-additional-privilege-service.ts@@@ -80,16 -76,13 +80,18 @@@ export const projectUserAdditionalPrivi// we need to validate that the privilege given is not higher than the assigning users permission// @ts-expect-error this is expected error because of one being really accurate rule definition other being a bit more broader. Both are valid casl rulestargetUserPermission.update(targetUserPermission.rules.concat(customPermission));-- const hasRequiredPriviledges = validatePrivilegeChangeOperation(- const permissionBoundary = validatePermissionBoundary(permission, targetUserPermission);++ const permissionBoundary = validatePrivilegeChangeOperation(+ ProjectPermissionMemberActions.ManagePrivileges,+ ProjectPermissionSub.Member,+ permission,+ targetUserPermission+ );-- if (!hasRequiredPriviledges)- throw new ForbiddenRequestError({ message: "Failed to update more privileged identity" });+ if (!permissionBoundary.isValid)+ throw new ForbiddenRequestError({+ name: "PermissionBoundaryError",+ message: "Failed to update more privileged user",+ details: { missingPermissions: permissionBoundary.missingPermissions }+ });const existingSlug = await projectUserAdditionalPrivilegeDAL.findOne({slug,@@@ -174,14 -167,13 +176,18 @@@// we need to validate that the privilege given is not higher than the assigning users permission// @ts-expect-error this is expected error because of one being really accurate rule definition other being a bit more broader. Both are valid casl rulestargetUserPermission.update(targetUserPermission.rules.concat(dto.permissions || []));- const hasRequiredPrivileges = validatePrivilegeChangeOperation(- const permissionBoundary = validatePermissionBoundary(permission, targetUserPermission);++ const permissionBoundary = validatePrivilegeChangeOperation(+ ProjectPermissionMemberActions.ManagePrivileges,+ ProjectPermissionSub.Member,+ permission,+ targetUserPermission+ );- if (!hasRequiredPrivileges)- throw new ForbiddenRequestError({ message: "Failed to update more privileged identity" });+ if (!permissionBoundary.isValid)+ throw new ForbiddenRequestError({+ name: "PermissionBoundaryError",- message: "Failed to update more privileged identity",++ message: "Failed to update more privileged user",+ details: { missingPermissions: permissionBoundary.missingPermissions }+ });if (dto?.slug) {const existingSlug = await projectUserAdditionalPrivilegeDAL.findOne({diff --cc backend/src/services/group-project/group-project-service.tsindex 000380a8e4,b408e2e954..445141540f--- a/backend/src/services/group-project/group-project-service.ts+++ b/backend/src/services/group-project/group-project-service.ts@@@ -102,16 -102,13 +102,18 @@@ export const groupProjectServiceFactorproject.id);- const hasRequiredPrivileges = validatePrivilegeChangeOperation(- const permissionBoundary = validatePermissionBoundary(permission, rolePermission);++ const permissionBoundary = validatePrivilegeChangeOperation(+ ProjectPermissionGroupActions.ManagePrivileges,+ ProjectPermissionSub.Groups,+ permission,+ rolePermission+ );-- if (!hasRequiredPrivileges) {- throw new ForbiddenRequestError({ message: "Failed to assign group to a more privileged role" });- }+ if (!permissionBoundary.isValid)+ throw new ForbiddenRequestError({+ name: "PermissionBoundaryError",+ message: "Failed to assign group to a more privileged role",+ details: { missingPermissions: permissionBoundary.missingPermissions }+ });}// validate custom roles input@@@ -272,17 -269,13 +274,18 @@@requestedRoleChange,project.id);-- const hasRequiredPrivileges = validatePrivilegeChangeOperation(- const permissionBoundary = validatePermissionBoundary(permission, rolePermission);++ const permissionBoundary = validatePrivilegeChangeOperation(+ ProjectPermissionGroupActions.ManagePrivileges,+ ProjectPermissionSub.Groups,+ permission,+ rolePermission+ );-- if (!hasRequiredPrivileges) {- throw new ForbiddenRequestError({ message: "Failed to assign group to a more privileged role" });- }+ if (!permissionBoundary.isValid)+ throw new ForbiddenRequestError({+ name: "PermissionBoundaryError",+ message: "Failed to assign group to a more privileged role",+ details: { missingPermissions: permissionBoundary.missingPermissions }+ });}// validate custom roles inputdiff --cc backend/src/services/identity-aws-auth/identity-aws-auth-service.tsindex ad48223c0f,ddd9e02787..a11fa64ea2--- a/backend/src/services/identity-aws-auth/identity-aws-auth-service.ts+++ b/backend/src/services/identity-aws-auth/identity-aws-auth-service.ts@@@ -339,16 -339,12 +339,17 @@@ export const identityAwsAuthServiceFactactorOrgId);- if (- !validatePrivilegeChangeOperation(- OrgPermissionIdentityActions.RevokeAuth,- OrgPermissionSubjects.Identity,- permission,- rolePermission- )- )- const permissionBoundary = validatePermissionBoundary(permission, rolePermission);++ const permissionBoundary = validatePrivilegeChangeOperation(++ OrgPermissionIdentityActions.RevokeAuth,++ OrgPermissionSubjects.Identity,++ permission,++ rolePermission++ );+ if (!permissionBoundary.isValid)throw new ForbiddenRequestError({- message: "Failed to revoke aws auth of identity with more privileged role"+ name: "PermissionBoundaryError",+ message: "Failed to revoke aws auth of identity with more privileged role",+ details: { missingPermissions: permissionBoundary.missingPermissions }});const revokedIdentityAwsAuth = await identityAwsAuthDAL.transaction(async (tx) => {diff --cc backend/src/services/identity-azure-auth/identity-azure-auth-service.tsindex f011654a5c,01878dbb3d..2e70138529--- a/backend/src/services/identity-azure-auth/identity-azure-auth-service.ts+++ b/backend/src/services/identity-azure-auth/identity-azure-auth-service.ts@@@ -312,17 -312,12 +312,17 @@@ export const identityAzureAuthServiceFaactorAuthMethod,actorOrgId);-- if (- !validatePrivilegeChangeOperation(- OrgPermissionIdentityActions.RevokeAuth,- OrgPermissionSubjects.Identity,- permission,- rolePermission- )- )- const permissionBoundary = validatePermissionBoundary(permission, rolePermission);++ const permissionBoundary = validatePrivilegeChangeOperation(++ OrgPermissionIdentityActions.RevokeAuth,++ OrgPermissionSubjects.Identity,++ permission,++ rolePermission++ );+ if (!permissionBoundary.isValid)throw new ForbiddenRequestError({- message: "Failed to revoke azure auth of identity with more privileged role"+ name: "PermissionBoundaryError",+ message: "Failed to revoke azure auth of identity with more privileged role",+ details: { missingPermissions: permissionBoundary.missingPermissions }});const revokedIdentityAzureAuth = await identityAzureAuthDAL.transaction(async (tx) => {diff --cc backend/src/services/identity-gcp-auth/identity-gcp-auth-service.tsindex 9aea92dba4,7b0dd4390c..cf88129808--- a/backend/src/services/identity-gcp-auth/identity-gcp-auth-service.ts+++ b/backend/src/services/identity-gcp-auth/identity-gcp-auth-service.ts@@@ -358,17 -358,12 +358,17 @@@ export const identityGcpAuthServiceFactactorAuthMethod,actorOrgId);-- const hasRequiredPrivileges = validatePrivilegeChangeOperation(- const permissionBoundary = validatePermissionBoundary(permission, rolePermission);++ const permissionBoundary = validatePrivilegeChangeOperation(+ OrgPermissionIdentityActions.RevokeAuth,+ OrgPermissionSubjects.Identity,+ permission,+ rolePermission+ );-- if (!hasRequiredPrivileges)+ if (!permissionBoundary.isValid)throw new ForbiddenRequestError({- message: "Failed to revoke gcp auth of identity with more privileged role"+ name: "PermissionBoundaryError",+ message: "Failed to revoke gcp auth of identity with more privileged role",+ details: { missingPermissions: permissionBoundary.missingPermissions }});const revokedIdentityGcpAuth = await identityGcpAuthDAL.transaction(async (tx) => {diff --cc backend/src/services/identity-jwt-auth/identity-jwt-auth-service.tsindex 011a224659,2c9b6306ec..92bad6c46a--- a/backend/src/services/identity-jwt-auth/identity-jwt-auth-service.ts+++ b/backend/src/services/identity-jwt-auth/identity-jwt-auth-service.ts@@@ -508,19 -508,13 +508,18 @@@ export const identityJwtAuthServiceFactactorOrgId);- // revoke auth identity - org permission- if (- !validatePrivilegeChangeOperation(- OrgPermissionIdentityActions.RevokeAuth,- OrgPermissionSubjects.Identity,- permission,- rolePermission- )- ) {- const permissionBoundary = validatePermissionBoundary(permission, rolePermission);++ const permissionBoundary = validatePrivilegeChangeOperation(++ OrgPermissionIdentityActions.RevokeAuth,++ OrgPermissionSubjects.Identity,++ permission,++ rolePermission++ );+ if (!permissionBoundary.isValid)throw new ForbiddenRequestError({- message: "Failed to revoke JWT auth of identity with more privileged role"+ name: "PermissionBoundaryError",+ message: "Failed to revoke jwt auth of identity with more privileged role",+ details: { missingPermissions: permissionBoundary.missingPermissions }});- }const revokedIdentityJwtAuth = await identityJwtAuthDAL.transaction(async (tx) => {const deletedJwtAuth = await identityJwtAuthDAL.delete({ identityId }, tx);diff --cc backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.tsindex 1be1eda3fc,c7b2c5c8d0..4a6467af51--- a/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts+++ b/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts@@@ -487,17 -487,12 +487,17 @@@ export const identityKubernetesAuthServactorAuthMethod,actorOrgId);-- if (- !validatePrivilegeChangeOperation(- OrgPermissionIdentityActions.RevokeAuth,- OrgPermissionSubjects.Identity,- permission,- rolePermission- )- )- const permissionBoundary = validatePermissionBoundary(permission, rolePermission);++ const permissionBoundary = validatePrivilegeChangeOperation(++ OrgPermissionIdentityActions.RevokeAuth,++ OrgPermissionSubjects.Identity,++ permission,++ rolePermission++ );+ if (!permissionBoundary.isValid)throw new ForbiddenRequestError({- message: "Failed to revoke kubernetes auth of identity with more privileged role"+ name: "PermissionBoundaryError",+ message: "Failed to revoke kubernetes auth of identity with more privileged role",+ details: { missingPermissions: permissionBoundary.missingPermissions }});const revokedIdentityKubernetesAuth = await identityKubernetesAuthDAL.transaction(async (tx) => {diff --cc backend/src/services/identity-oidc-auth/identity-oidc-auth-service.tsindex bfdaba6d7a,3c947f5041..f8deb63c7d--- a/backend/src/services/identity-oidc-auth/identity-oidc-auth-service.ts+++ b/backend/src/services/identity-oidc-auth/identity-oidc-auth-service.ts@@@ -428,18 -428,13 +428,18 @@@ export const identityOidcAuthServiceFacactorOrgId);- if (- !validatePrivilegeChangeOperation(- OrgPermissionIdentityActions.RevokeAuth,- OrgPermissionSubjects.Identity,- permission,- rolePermission- )- ) {- const permissionBoundary = validatePermissionBoundary(permission, rolePermission);++ const permissionBoundary = validatePrivilegeChangeOperation(++ OrgPermissionIdentityActions.RevokeAuth,++ OrgPermissionSubjects.Identity,++ permission,++ rolePermission++ );+ if (!permissionBoundary.isValid)throw new ForbiddenRequestError({- message: "Failed to revoke OIDC auth of identity with more privileged role"+ name: "PermissionBoundaryError",+ message: "Failed to revoke oidc auth of identity with more privileged role",+ details: { missingPermissions: permissionBoundary.missingPermissions }});- }const revokedIdentityOidcAuth = await identityOidcAuthDAL.transaction(async (tx) => {const deletedOidcAuth = await identityOidcAuthDAL.delete({ identityId }, tx);diff --cc backend/src/services/identity-project/identity-project-service.tsindex 5f14e3ace9,e16ffb3d48..cabed77510--- a/backend/src/services/identity-project/identity-project-service.ts+++ b/backend/src/services/identity-project/identity-project-service.ts@@@ -90,16 -91,13 +90,18 @@@ export const identityProjectServiceFactprojectId);- const hasRequiredPriviledges = validatePrivilegeChangeOperation(- const permissionBoundary = validatePermissionBoundary(permission, rolePermission);++ const permissionBoundary = validatePrivilegeChangeOperation(+ ProjectPermissionIdentityActions.ManagePrivileges,+ ProjectPermissionSub.Identity,+ permission,+ rolePermission+ );-- if (!hasRequiredPriviledges) {- throw new ForbiddenRequestError({ message: "Failed to change to a more privileged role" });- }+ if (!permissionBoundary.isValid)+ throw new ForbiddenRequestError({+ name: "PermissionBoundaryError",+ message: "Failed to assign to a more privileged role",+ details: { missingPermissions: permissionBoundary.missingPermissions }+ });}// validate custom roles input@@@ -189,15 -187,13 +191,18 @@@projectId);- const hasRequiredPriviledges = validatePrivilegeChangeOperation(- const permissionBoundary = validatePermissionBoundary(permission, rolePermission);++ const permissionBoundary = validatePrivilegeChangeOperation(+ ProjectPermissionIdentityActions.ManagePrivileges,+ ProjectPermissionSub.Identity,+ permission,+ rolePermission+ );- if (!hasRequiredPriviledges) {- throw new ForbiddenRequestError({ message: "Failed to change to a more privileged role" });- }+ if (!permissionBoundary.isValid)+ throw new ForbiddenRequestError({+ name: "PermissionBoundaryError",+ message: "Failed to change to a more privileged role",+ details: { missingPermissions: permissionBoundary.missingPermissions }+ });}// validate custom roles inputdiff --cc backend/src/services/identity-token-auth/identity-token-auth-service.tsindex 74a47e1a07,d9e2d66fad..4dcba69100--- a/backend/src/services/identity-token-auth/identity-token-auth-service.ts+++ b/backend/src/services/identity-token-auth/identity-token-auth-service.ts@@@ -245,18 -245,13 +245,18 @@@ export const identityTokenAuthServiceFaactorOrgId);- if (- !validatePrivilegeChangeOperation(- OrgPermissionIdentityActions.RevokeAuth,- OrgPermissionSubjects.Identity,- permission,- rolePermission- )- ) {- const permissionBoundary = validatePermissionBoundary(permission, rolePermission);++ const permissionBoundary = validatePrivilegeChangeOperation(++ OrgPermissionIdentityActions.RevokeAuth,++ OrgPermissionSubjects.Identity,++ permission,++ rolePermission++ );+ if (!permissionBoundary.isValid)throw new ForbiddenRequestError({- message: "Failed to revoke Token Auth of identity with more privileged role"+ name: "PermissionBoundaryError",+ message: "Failed to revoke token auth of identity with more privileged role",+ details: { missingPermissions: permissionBoundary.missingPermissions }});- }const revokedIdentityTokenAuth = await identityTokenAuthDAL.transaction(async (tx) => {const deletedTokenAuth = await identityTokenAuthDAL.delete({ identityId }, tx);@@@ -302,17 -297,12 +302,18 @@@actorAuthMethod,actorOrgId);- const permissionBoundary = validatePermissionBoundary(permission, rolePermission);+- const hasPriviledge = validatePrivilegeChangeOperation(++ const permissionBoundary = validatePrivilegeChangeOperation(+ OrgPermissionIdentityActions.CreateToken,+ OrgPermissionSubjects.Identity,+ permission,+ rolePermission+ );-- if (!hasPriviledge)+ if (!permissionBoundary.isValid)throw new ForbiddenRequestError({- message: "Failed to create token for identity with more privileged role"+ name: "PermissionBoundaryError",+ message: "Failed to create token for identity with more privileged role",+ details: { missingPermissions: permissionBoundary.missingPermissions }});const identityTokenAuth = await identityTokenAuthDAL.findOne({ identityId });@@@ -429,17 -419,12 +430,17 @@@actorAuthMethod,actorOrgId);-- const hasPriviledge = validatePrivilegeChangeOperation(- const permissionBoundary = validatePermissionBoundary(permission, rolePermission);++ const permissionBoundary = validatePrivilegeChangeOperation(+ OrgPermissionIdentityActions.CreateToken,+ OrgPermissionSubjects.Identity,+ permission,+ rolePermission+ );-- if (!hasPriviledge)+ if (!permissionBoundary.isValid)throw new ForbiddenRequestError({- message: "Failed to update token for identity with more privileged role"+ name: "PermissionBoundaryError",+ message: "Failed to update token for identity with more privileged role",+ details: { missingPermissions: permissionBoundary.missingPermissions }});const [token] = await identityAccessTokenDAL.update(diff --cc backend/src/services/identity-ua/identity-ua-service.tsindex 9a57d7edae,078b50c082..77e6ad3f37--- a/backend/src/services/identity-ua/identity-ua-service.ts+++ b/backend/src/services/identity-ua/identity-ua-service.ts@@@ -367,17 -367,12 +367,17 @@@ export const identityUaServiceFactoryactorAuthMethod,actorOrgId);-- if (- !validatePrivilegeChangeOperation(- OrgPermissionIdentityActions.RevokeAuth,- OrgPermissionSubjects.Identity,- permission,- rolePermission- )- )- const permissionBoundary = validatePermissionBoundary(permission, rolePermission);++ const permissionBoundary = validatePrivilegeChangeOperation(++ OrgPermissionIdentityActions.RevokeAuth,++ OrgPermissionSubjects.Identity,++ permission,++ rolePermission++ );+ if (!permissionBoundary.isValid)throw new ForbiddenRequestError({- message: "Failed to revoke universal auth of identity with more privileged role"+ name: "PermissionBoundaryError",+ message: "Failed to revoke universal auth of identity with more privileged role",+ details: { missingPermissions: permissionBoundary.missingPermissions }});const revokedIdentityUniversalAuth = await identityUaDAL.transaction(async (tx) => {@@@ -422,17 -417,12 +422,17 @@@actorAuthMethod,actorOrgId);-- if (- !validatePrivilegeChangeOperation(- OrgPermissionIdentityActions.CreateToken,- OrgPermissionSubjects.Identity,- permission,- rolePermission- )- )- const permissionBoundary = validatePermissionBoundary(permission, rolePermission);++ const permissionBoundary = validatePrivilegeChangeOperation(++ OrgPermissionIdentityActions.CreateToken,++ OrgPermissionSubjects.Identity,++ permission,++ rolePermission++ );+ if (!permissionBoundary.isValid)throw new ForbiddenRequestError({- message: "Failed to add identity to project with more privileged role"+ name: "PermissionBoundaryError",+ message: "Failed to create client secret for a more privileged identity.",+ details: { missingPermissions: permissionBoundary.missingPermissions }});const appCfg = getConfig();@@@ -490,16 -480,12 +490,17 @@@actorOrgId);- if (- !validatePrivilegeChangeOperation(- OrgPermissionIdentityActions.GetToken,- OrgPermissionSubjects.Identity,- permission,- rolePermission- )- )- const permissionBoundary = validatePermissionBoundary(permission, rolePermission);++ const permissionBoundary = validatePrivilegeChangeOperation(++ OrgPermissionIdentityActions.GetToken,++ OrgPermissionSubjects.Identity,++ permission,++ rolePermission++ );+ if (!permissionBoundary.isValid)throw new ForbiddenRequestError({- message: "Failed to get identity client secret with more privileged role"+ name: "PermissionBoundaryError",+ message: "Failed to get identity client secret with more privileged role",+ details: { missingPermissions: permissionBoundary.missingPermissions }});const identityUniversalAuth = await identityUaDAL.findOne({@@@ -546,17 -532,12 +547,17 @@@actorAuthMethod,actorOrgId);-- if (- !validatePrivilegeChangeOperation(- OrgPermissionIdentityActions.GetToken,- OrgPermissionSubjects.Identity,- permission,- rolePermission- )- )- const permissionBoundary = validatePermissionBoundary(permission, rolePermission);++ const permissionBoundary = validatePrivilegeChangeOperation(++ OrgPermissionIdentityActions.GetToken,++ OrgPermissionSubjects.Identity,++ permission,++ rolePermission++ );+ if (!permissionBoundary.isValid)throw new ForbiddenRequestError({- message: "Failed to read identity client secret of project with more privileged role"+ name: "PermissionBoundaryError",+ message: "Failed to read identity client secret of identity with more privileged role",+ details: { missingPermissions: permissionBoundary.missingPermissions }});const clientSecret = await identityUaClientSecretDAL.findById(clientSecretId);@@@ -596,23 -577,17 +597,25 @@@actorAuthMethod,actorOrgId);- const permissionBoundary = validatePermissionBoundary(permission, rolePermission);- if (!permissionBoundary.isValid)+- if (- !validatePrivilegeChangeOperation(- OrgPermissionIdentityActions.DeleteToken,- OrgPermissionSubjects.Identity,- permission,- rolePermission- )- ) {++ const permissionBoundary = validatePrivilegeChangeOperation(++ OrgPermissionIdentityActions.DeleteToken,++ OrgPermissionSubjects.Identity,++ permission,++ rolePermission++ );++ if (!permissionBoundary.isValid) {throw new ForbiddenRequestError({- message: "Failed to revoke identity client secret with more privileged role"+ name: "PermissionBoundaryError",+ message: "Failed to revoke identity client secret with more privileged role",+ details: { missingPermissions: permissionBoundary.missingPermissions }});+ }const clientSecret = await identityUaClientSecretDAL.updateById(clientSecretId, {isClientSecretRevoked: true});++return { ...clientSecret, identityId, orgId: identityMembershipOrg.orgId };};diff --cc backend/src/services/identity/identity-service.tsindex d17d6476a0,8ada2a5d1a..41252bf255--- a/backend/src/services/identity/identity-service.ts+++ b/backend/src/services/identity/identity-service.ts@@@ -57,14 -58,13 +57,18 @@@ export const identityServiceFactory = (orgId);const isCustomRole = Boolean(customRole);- const hasRequiredPriviledges = validatePrivilegeChangeOperation(- const permissionBoundary = validatePermissionBoundary(permission, rolePermission);++ const permissionBoundary = validatePrivilegeChangeOperation(+ OrgPermissionIdentityActions.ManagePrivileges,+ OrgPermissionSubjects.Identity,+ permission,+ rolePermission+ );- if (!hasRequiredPriviledges)- throw new ForbiddenRequestError({ message: "Failed to create a more privileged identity" });+ if (!permissionBoundary.isValid)+ throw new ForbiddenRequestError({+ name: "PermissionBoundaryError",+ message: "Failed to create a more privileged identity",+ details: { missingPermissions: permissionBoundary.missingPermissions }+ });const plan = await licenseService.getPlan(orgId);@@@ -134,15 -149,13 +138,18 @@@);const isCustomRole = Boolean(customOrgRole);- const hasRequiredNewRolePermission = validatePrivilegeChangeOperation(- const appliedRolePermissionBoundary = validatePermissionBoundary(permission, rolePermission);++ const appliedRolePermissionBoundary = validatePrivilegeChangeOperation(+ OrgPermissionIdentityActions.ManagePrivileges,+ OrgPermissionSubjects.Identity,+ permission,+ rolePermission+ );-- if (!hasRequiredNewRolePermission)- throw new ForbiddenRequestError({ message: "Failed to create a more privileged identity" });+ if (!appliedRolePermissionBoundary.isValid)+ throw new ForbiddenRequestError({+ name: "PermissionBoundaryError",+ message: "Failed to create a more privileged identity",+ details: { missingPermissions: appliedRolePermissionBoundary.missingPermissions }+ });if (isCustomRole) customRole = customOrgRole;}@@@ -207,7 -220,21 +214,8 @@@actorAuthMethod,actorOrgId);- ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Delete, OrgPermissionSubjects.Identity);- const { permission: identityRolePermission } = await permissionService.getOrgPermission(- ActorType.IDENTITY,- id,- identityOrgMembership.orgId,- actorAuthMethod,- actorOrgId- );- const permissionBoundary = validatePermissionBoundary(permission, identityRolePermission);- if (!permissionBoundary.isValid)- throw new ForbiddenRequestError({- name: "PermissionBoundaryError",- message: "Failed to delete more privileged identity",- details: { missingPermissions: permissionBoundary.missingPermissions }- });+++ ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Delete, OrgPermissionSubjects.Identity);const deletedIdentity = await identityDAL.deleteById(id);diff --cc backend/src/services/project-membership/project-membership-service.tsindex 18e42dc035,f47a372222..ecc7f83d0b--- a/backend/src/services/project-membership/project-membership-service.ts+++ b/backend/src/services/project-membership/project-membership-service.ts@@@ -274,18 -274,13 +274,18 @@@ export const projectMembershipServiceFaprojectId);- const hasRequiredPriviledges = validatePrivilegeChangeOperation(- const permissionBoundary = validatePermissionBoundary(permission, rolePermission);++ const permissionBoundary = validatePrivilegeChangeOperation(+ ProjectPermissionMemberActions.ManagePrivileges,+ ProjectPermissionSub.Member,+ permission,+ rolePermission+ );-- if (!hasRequiredPriviledges) {+ if (!permissionBoundary.isValid)throw new ForbiddenRequestError({- message: `Failed to change to a more privileged role ${requestedRoleChange}`+ name: "PermissionBoundaryError",+ message: `Failed to change to a more privileged role ${requestedRoleChange}`,+ details: { missingPermissions: permissionBoundary.missingPermissions }});- }}// validate custom roles input