Skip to content

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

fix(pam): seed identity creator as admin when bootstrapping PAM project for identity-created sub-orgs

bernie-g3839604e5157
diff --git a/backend/src/ee/services/pam-project/pam-project-bootstrap.ts b/backend/src/ee/services/pam-project/pam-project-bootstrap.ts
index f466a9f9b5..414709d73c 100644
--- a/backend/src/ee/services/pam-project/pam-project-bootstrap.ts
+++ b/backend/src/ee/services/pam-project/pam-project-bootstrap.ts
@@ -20,6 +20,7 @@ type TBootstrapDeps = {
type TBootstrapInput = {
orgId: string;
adminUserIds?: string[];
+ adminIdentityIds?: string[];
};
export type TDefaultTemplate = {
@@ -184,7 +185,7 @@ export const DEFAULT_ACCOUNT_TEMPLATES: TDefaultTemplate[] = [
];
export const bootstrapPamProject = async (
- { orgId, adminUserIds = [] }: TBootstrapInput,
+ { orgId, adminUserIds = [], adminIdentityIds = [] }: TBootstrapInput,
{ projectDAL, membershipDAL, membershipRoleDAL }: TBootstrapDeps,
tx: Knex
): Promise<{ project: TProjects; created: boolean }> => {
@@ -230,6 +231,29 @@ export const bootstrapPamProject = async (
);
}
+ for (const identityId of adminIdentityIds) {
+ // eslint-disable-next-line no-await-in-loop
+ const membership = await membershipDAL.create(
+ {
+ scope: AccessScope.Project,
+ scopeOrgId: orgId,
+ scopeProjectId: project.id,
+ actorIdentityId: identityId,
+ isActive: true
+ },
+ tx
+ );
+
+ // eslint-disable-next-line no-await-in-loop
+ await membershipRoleDAL.create(
+ {
+ membershipId: membership.id,
+ role: ProjectMembershipRole.Admin
+ },
+ tx
+ );
+ }
+
for (const template of DEFAULT_ACCOUNT_TEMPLATES) {
// eslint-disable-next-line no-await-in-loop
await tx(TableName.PamAccountTemplate).insert({
diff --git a/backend/src/ee/services/sub-org/sub-org-service.ts b/backend/src/ee/services/sub-org/sub-org-service.ts
index c4cfd634a5..217a3a272b 100644
--- a/backend/src/ee/services/sub-org/sub-org-service.ts
+++ b/backend/src/ee/services/sub-org/sub-org-service.ts
@@ -110,7 +110,8 @@ export const subOrgServiceFactory = ({
await bootstrapPamProject(
{
orgId: org.id,
- adminUserIds: permission.type === ActorType.USER ? [permission.id] : []
+ adminUserIds: permission.type === ActorType.USER ? [permission.id] : [],
+ adminIdentityIds: permission.type === ActorType.IDENTITY ? [permission.id] : []
},
{ projectDAL, membershipDAL, membershipRoleDAL },
tx