Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
fix(project-roles): unblock duplicating the built-in Admin role
Claude88b5f44780a6
diff --git a/backend/src/ee/services/permission/project-permission.test.ts b/backend/src/ee/services/permission/project-permission.test.tsindex 02bb3f419d..fbc934e6bd 100644--- a/backend/src/ee/services/permission/project-permission.test.ts+++ b/backend/src/ee/services/permission/project-permission.test.ts@@ -1,3 +1,6 @@+import { ProjectType } from "@app/db/schemas";+import { getPredefinedRoles } from "@app/services/project-role/project-role-fns";+import { projectAdminPermissions, projectMemberPermissions, projectViewerPermission } from "./default-roles";import {ProjectPermissionActions,@@ -38,3 +41,36 @@ describe("ProjectPermissionV2Schema certificate-application actions", () => {});});});++describe("built-in project roles round-trip through the role API schema", () => {+ // Actions the role API deliberately refuses because they are only obtainable through another+ // flow, so a duplicate of a built-in role cannot carry them. The duplicate flow strips them.+ const NON_GRANTABLE_ACTIONS_BY_SUBJECT: Record<string, string[]> = {+ [ProjectPermissionSub.SecretFolders]: [ProjectPermissionSecretFolderActions.ManageAccess]+ };++ // The roles tab lists whatever getPredefinedRoles returns and duplicates a role by re-submitting+ // its rules, so enumerate that rather than hardcoding a list of built-in roles here.+ const builtInRoles = [+ ...new Map(+ Object.values(ProjectType)+ .flatMap((projectType) => getPredefinedRoles({ projectId: "project-id", projectType }))+ .map((role) => [role.slug, role.permissions])+ ).entries()+ ];++ test.each(builtInRoles)("every rule of the built-in %s role is writable", (_slug, permissions) => {+ permissions.forEach((rule) => {+ const nonGrantableActions = NON_GRANTABLE_ACTIONS_BY_SUBJECT[String(rule.subject)] ?? [];+ const action = [rule.action].flat().filter((el) => !nonGrantableActions.includes(String(el)));+ if (!action.length) return;++ const result = ProjectPermissionV2Schema.safeParse({ ...rule, action });++ expect(+ result.success,+ `The built-in roles grant '${String(rule.subject)}' but ProjectPermissionV2Schema rejects it, so duplicating the role fails. Add the subject or action to the schema in project-permission.ts, or add it to NON_GRANTABLE_ACTIONS_BY_SUBJECT here and strip it in the duplicate flow.`+ ).toBe(true);+ });+ });+});diff --git a/frontend/src/pages/project/RoleDetailsBySlugPage/components/DuplicateProjectRoleModal.tsx b/frontend/src/pages/project/RoleDetailsBySlugPage/components/DuplicateProjectRoleModal.tsxindex 70a83e451b..2bb6910522 100644--- a/frontend/src/pages/project/RoleDetailsBySlugPage/components/DuplicateProjectRoleModal.tsx+++ b/frontend/src/pages/project/RoleDetailsBySlugPage/components/DuplicateProjectRoleModal.tsx@@ -23,7 +23,10 @@ import {Skeleton} from "@app/components/v3";import { ProjectPermissionSub, useOrganization, useProject, useSubscription } from "@app/context";-import { ProjectPermissionSecretActions } from "@app/context/ProjectPermissionContext/types";+import {+ ProjectPermissionSecretActions,+ ProjectPermissionSecretFolderActions+} from "@app/context/ProjectPermissionContext/types";import { getProjectBaseURL } from "@app/helpers/project";import { useCreateProjectRole, useGetProjectRoleBySlug } from "@app/hooks/api";import { TProjectRole } from "@app/hooks/api/roles/types";@@ -84,20 +87,33 @@ const Content = ({ role, onClose }: ContentProps) => {return;}- const sanitizedPermission = role.permissions.map((permission) => {+ const sanitizedPermission = role.permissions.flatMap((permission) => {if (permission.subject === ProjectPermissionSub.Secrets &&(permission.action.includes(ProjectPermissionSecretActions.DescribeSecret) ||permission.action.includes(ProjectPermissionSecretActions.ReadValue))) {- return {- ...permission,- action: (permission.action as string[])?.filter(- (action) => action !== ProjectPermissionSecretActions.DescribeAndReadValue- )- };+ return [+ {+ ...permission,+ action: (permission.action as string[])?.filter(+ (action) => action !== ProjectPermissionSecretActions.DescribeAndReadValue+ )+ }+ ];}- return permission;++ if (permission.subject === ProjectPermissionSub.SecretFolders) {+ // manage-access is only obtainable through the folder access flow, so the role API rejects+ // it; the built-in Admin role grants it and would otherwise fail validation here.+ const action = [permission.action]+ .flat()+ .filter((el) => el !== ProjectPermissionSecretFolderActions.ManageAccess);++ return action.length ? [{ ...permission, action }] : [];+ }++ return [permission];});const newRole = await createRole.mutateAsync({