Skip to content

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

fix lint

Thiago Araujo da Silva8fc0c714023f
diff --git a/backend/src/db/migrations/20260707000000_identity-edit-auth-permission.ts b/backend/src/db/migrations/20260707000000_identity-edit-auth-permission.ts
index 15474d536e..e20e7ad2f9 100644
--- a/backend/src/db/migrations/20260707000000_identity-edit-auth-permission.ts
+++ b/backend/src/db/migrations/20260707000000_identity-edit-auth-permission.ts
@@ -5,12 +5,12 @@ import { TableName } from "../schemas";
// Auth-method configuration (attach/update) used to reuse the generic identity
// `create`/`edit` actions. It now requires the dedicated `edit-auth` action. To
-// avoid silently stripping this ability from existing custom roles on upgrade,
-// grandfather `edit-auth` onto any custom role that could already configure auth
-// methods (i.e. has an identity rule referencing `create` or `edit`), preserving
-// each source rule's conditions so identity-scoping is retained.
+// avoid silently stripping this ability on upgrade, grandfather `edit-auth` onto
+// any stored permission set that could already configure auth methods (i.e. has
+// an identity rule referencing `create` or `edit`), preserving each source
+// rule's conditions so identity-scoping is retained.
//
-// This mirrors BOTH allow (non-inverted) and deny (inverted) source rules: a role
+// This mirrors BOTH allow (non-inverted) and deny (inverted) source rules: a set
// that broadly allows `edit` on identities but denies it for a specific
// `identityId` must keep that exclusion for `edit-auth`, otherwise it could
// configure auth methods on an identity it was explicitly barred from editing.
@@ -18,10 +18,20 @@ import { TableName } from "../schemas";
// the last matching rule as the winner, so a deny that overrode an allow before
// continues to override it for `edit-auth`.
//
-// Both org roles (projectId IS NULL) and project roles live in the `roles`
-// table and use the same `identity` subject + action strings, so a single pass
-// covers both. Built-in roles (admin/member/no-access) are handled in code and
-// are not stored here, so they are unaffected.
+// Stored CASL rules live in two tables, both keyed by `id` with a `permissions`
+// column in the same packed format, so a single pass over each covers them:
+// - `roles`: both org roles (projectId IS NULL) and project custom roles.
+// - `additional_privileges`: per-actor privilege augmentations for BOTH users
+// (actorUserId) and machine identities (actorIdentityId). Permission
+// resolution reads this table's `permissions` for either actor, so an
+// additional privilege granting identity create/edit would otherwise silently
+// lose the ability to configure other identities' auth methods.
+// Built-in roles (admin/member/no-access) are handled in code and are not stored,
+// so they are unaffected. The legacy identity_project_additional_privilege /
+// project_user_additional_privilege tables are no longer read by permission
+// resolution, so they are intentionally not touched.
+
+const PERMISSIONED_TABLES = [TableName.Role, TableName.AdditionalPrivilege] as const;
const IDENTITY_SUBJECT = "identity";
const CREATE_ACTION = "create";
@@ -46,101 +56,109 @@ const conditionSignature = (conditions: unknown) =>
// dedup key must include the inverted flag.
const ruleSignature = (rule: CaslRule) => `${rule.inverted ? "deny" : "allow"}:${conditionSignature(rule.conditions)}`;
+const unpackPermissions = (permissions: unknown) =>
+ unpackRules((permissions ?? []) as Parameters<typeof unpackRules>[0]) as CaslRule[];
+
+const packPermissions = (rules: CaslRule[]) => JSON.stringify(packRules(rules as Parameters<typeof packRules>[0]));
+
+// up(): add an `edit-auth` rule mirroring each identity create/edit rule. Returns
+// null when nothing needs to change so the caller can skip the row.
+const addEditAuth = (rules: CaslRule[]): CaslRule[] | null => {
+ // Signatures (inverted flag + conditions) for which an edit-auth rule already
+ // exists, so we don't duplicate it.
+ const existingEditAuth = new Set(
+ rules
+ .filter((rule) => includes(rule.subject, IDENTITY_SUBJECT) && includes(rule.action, EDIT_AUTH_ACTION))
+ .map(ruleSignature)
+ );
+
+ // Source rules that scoped the ability to configure auth methods, in their
+ // original relative order. Both allows (grant edit-auth) and denies (exclude
+ // edit-auth) are mirrored so identity-scoping is preserved.
+ const sourceRules = rules.filter(
+ (rule) =>
+ includes(rule.subject, IDENTITY_SUBJECT) &&
+ (includes(rule.action, CREATE_ACTION) || includes(rule.action, EDIT_ACTION))
+ );
+
+ const rulesToAdd: CaslRule[] = [];
+ const addedSignatures = new Set<string>();
+ for (const rule of sourceRules) {
+ const signature = ruleSignature(rule);
+ if (!existingEditAuth.has(signature) && !addedSignatures.has(signature)) {
+ addedSignatures.add(signature);
+ const newRule: CaslRule =
+ rule.conditions === undefined
+ ? { action: EDIT_AUTH_ACTION, subject: IDENTITY_SUBJECT }
+ : { action: EDIT_AUTH_ACTION, subject: IDENTITY_SUBJECT, conditions: rule.conditions };
+ if (rule.inverted) newRule.inverted = true;
+ rulesToAdd.push(newRule);
+ }
+ }
+
+ if (rulesToAdd.length === 0) return null;
+ return [...rules, ...rulesToAdd];
+};
+
+// down(): strip edit-auth from identity rules (both allows and denies), mirroring
+// up(). Returns null when nothing changed so the caller can skip the row.
+const removeEditAuth = (rules: CaslRule[]): CaslRule[] | null => {
+ let wasModified = false;
+ const filteredRules = rules.reduce<CaslRule[]>((acc, rule) => {
+ if (!includes(rule.subject, IDENTITY_SUBJECT) || !includes(rule.action, EDIT_AUTH_ACTION)) {
+ acc.push(rule);
+ return acc;
+ }
+
+ wasModified = true;
+ if (Array.isArray(rule.action)) {
+ const withoutEditAuth = rule.action.filter((a) => a !== EDIT_AUTH_ACTION);
+ // Copy into a new rule so the original (shared) rule object is left untouched.
+ if (withoutEditAuth.length > 0) acc.push({ ...rule, action: withoutEditAuth });
+ return acc;
+ }
+ // Single action that is edit-auth, drop the rule entirely.
+ return acc;
+ }, []);
+
+ if (!wasModified) return null;
+ return filteredRules;
+};
+
+const transformTable = async (
+ trx: Knex,
+ tableName: (typeof PERMISSIONED_TABLES)[number],
+ transform: (rules: CaslRule[]) => CaslRule[] | null
+) => {
+ const rows = await trx(tableName).select("*");
+
+ const toUpdate = rows
+ .map((row) => {
+ const nextRules = transform(unpackPermissions(row.permissions));
+ if (nextRules === null) return null;
+ return { ...row, permissions: packPermissions(nextRules) };
+ })
+ .filter(Boolean) as typeof rows;
+
+ if (toUpdate.length > 0) {
+ await trx(tableName).insert(toUpdate).onConflict("id").merge();
+ }
+};
+
export async function up(knex: Knex): Promise<void> {
await knex.transaction(async (trx) => {
- const customRoles = await trx(TableName.Role).select("*");
-
- const toUpdate = customRoles
- .map((role) => {
- const rules = unpackRules((role.permissions ?? []) as Parameters<typeof unpackRules>[0]) as CaslRule[];
-
- // Signatures (inverted flag + conditions) for which an edit-auth rule
- // already exists, so we don't duplicate it.
- const existingEditAuth = new Set(
- rules
- .filter((rule) => includes(rule.subject, IDENTITY_SUBJECT) && includes(rule.action, EDIT_AUTH_ACTION))
- .map(ruleSignature)
- );
-
- // Source rules that scoped the ability to configure auth methods, in their
- // original relative order. Both allows (grant edit-auth) and denies
- // (exclude edit-auth) are mirrored so identity-scoping is preserved.
- const sourceRules = rules.filter(
- (rule) =>
- includes(rule.subject, IDENTITY_SUBJECT) &&
- (includes(rule.action, CREATE_ACTION) || includes(rule.action, EDIT_ACTION))
- );
-
- const rulesToAdd: CaslRule[] = [];
- const addedSignatures = new Set<string>();
- for (const rule of sourceRules) {
- const signature = ruleSignature(rule);
- if (!existingEditAuth.has(signature) && !addedSignatures.has(signature)) {
- addedSignatures.add(signature);
- const newRule: CaslRule =
- rule.conditions === undefined
- ? { action: EDIT_AUTH_ACTION, subject: IDENTITY_SUBJECT }
- : { action: EDIT_AUTH_ACTION, subject: IDENTITY_SUBJECT, conditions: rule.conditions };
- if (rule.inverted) newRule.inverted = true;
- rulesToAdd.push(newRule);
- }
- }
-
- if (rulesToAdd.length === 0) return null;
-
- return {
- ...role,
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
- // @ts-ignore-error packRules type mismatch
- permissions: JSON.stringify(packRules([...rules, ...rulesToAdd]))
- };
- })
- .filter(Boolean) as typeof customRoles;
-
- if (toUpdate.length > 0) {
- await trx(TableName.Role).insert(toUpdate).onConflict("id").merge();
+ for (const tableName of PERMISSIONED_TABLES) {
+ // eslint-disable-next-line no-await-in-loop
+ await transformTable(trx, tableName, addEditAuth);
}
});
}
export async function down(knex: Knex): Promise<void> {
await knex.transaction(async (trx) => {
- const customRoles = await trx(TableName.Role).select("*");
-
- const toUpdate = customRoles
- .map((role) => {
- const rules = unpackRules((role.permissions ?? []) as Parameters<typeof unpackRules>[0]) as CaslRule[];
-
- let wasModified = false;
- const filteredRules = rules.filter((rule) => {
- // Mirrors up(): strip edit-auth from identity rules, both allows and denies.
- if (!includes(rule.subject, IDENTITY_SUBJECT) || !includes(rule.action, EDIT_AUTH_ACTION)) return true;
-
- wasModified = true;
- if (Array.isArray(rule.action)) {
- const withoutEditAuth = rule.action.filter((a) => a !== EDIT_AUTH_ACTION);
- if (withoutEditAuth.length === 0) return false;
- // eslint-disable-next-line no-param-reassign
- rule.action = withoutEditAuth;
- return true;
- }
- // Single action that is edit-auth, remove the rule entirely.
- return false;
- });
-
- if (!wasModified) return null;
-
- return {
- ...role,
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
- // @ts-ignore-error packRules type mismatch
- permissions: JSON.stringify(packRules(filteredRules))
- };
- })
- .filter(Boolean) as typeof customRoles;
-
- if (toUpdate.length > 0) {
- await trx(TableName.Role).insert(toUpdate).onConflict("id").merge();
+ for (const tableName of PERMISSIONED_TABLES) {
+ // eslint-disable-next-line no-await-in-loop
+ await transformTable(trx, tableName, removeEditAuth);
}
});
}
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 7dd613be70..ed44f723b8 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
@@ -424,7 +424,10 @@ export const identityAliCloudAuthServiceFactory = ({
actorAuthMethod,
actorOrgId
});
- ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.EditAuth, OrgPermissionSubjects.Identity);
+ ForbiddenError.from(permission).throwUnlessCan(
+ OrgPermissionIdentityActions.EditAuth,
+ OrgPermissionSubjects.Identity
+ );
}
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
const reformattedAccessTokenTrustedIps = accessTokenTrustedIps?.map((accessTokenTrustedIp) => {
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 bb13c13d84..779106f11b 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
@@ -525,7 +525,10 @@ export const identityAwsAuthServiceFactory = ({
actorAuthMethod,
actorOrgId
});
- ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.EditAuth, OrgPermissionSubjects.Identity);
+ ForbiddenError.from(permission).throwUnlessCan(
+ OrgPermissionIdentityActions.EditAuth,
+ OrgPermissionSubjects.Identity
+ );
}
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
const reformattedAccessTokenTrustedIps = accessTokenTrustedIps?.map((accessTokenTrustedIp) => {
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 f823466fd4..14a753b35e 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
@@ -425,7 +425,10 @@ export const identityAzureAuthServiceFactory = ({
actorAuthMethod,
actorOrgId
});
- ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.EditAuth, OrgPermissionSubjects.Identity);
+ ForbiddenError.from(permission).throwUnlessCan(
+ OrgPermissionIdentityActions.EditAuth,
+ OrgPermissionSubjects.Identity
+ );
}
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
const reformattedAccessTokenTrustedIps = accessTokenTrustedIps?.map((accessTokenTrustedIp) => {
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 6bc44ccaf0..63e7527a37 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
@@ -472,7 +472,10 @@ export const identityGcpAuthServiceFactory = ({
actorAuthMethod,
actorOrgId
});
- ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.EditAuth, OrgPermissionSubjects.Identity);
+ ForbiddenError.from(permission).throwUnlessCan(
+ OrgPermissionIdentityActions.EditAuth,
+ OrgPermissionSubjects.Identity
+ );
}
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
const reformattedAccessTokenTrustedIps = accessTokenTrustedIps?.map((accessTokenTrustedIp) => {
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 441149832d..70d3b7f0b9 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
@@ -620,7 +620,10 @@ export const identityJwtAuthServiceFactory = ({
actorOrgId
});
- ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.EditAuth, OrgPermissionSubjects.Identity);
+ ForbiddenError.from(permission).throwUnlessCan(
+ OrgPermissionIdentityActions.EditAuth,
+ OrgPermissionSubjects.Identity
+ );
}
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
const reformattedAccessTokenTrustedIps = accessTokenTrustedIps?.map((accessTokenTrustedIp) => {
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 d434b27acb..e9777018f1 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
@@ -1123,7 +1123,10 @@ export const identityKubernetesAuthServiceFactory = ({
actorAuthMethod,
actorOrgId
});
- ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.EditAuth, OrgPermissionSubjects.Identity);
+ ForbiddenError.from(permission).throwUnlessCan(
+ OrgPermissionIdentityActions.EditAuth,
+ OrgPermissionSubjects.Identity
+ );
}
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
const reformattedAccessTokenTrustedIps = accessTokenTrustedIps?.map((accessTokenTrustedIp) => {
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 739e6ef782..9fdf5cd000 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
@@ -438,7 +438,10 @@ export const identityOciAuthServiceFactory = ({
actorAuthMethod,
actorOrgId
});
- ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.EditAuth, OrgPermissionSubjects.Identity);
+ ForbiddenError.from(permission).throwUnlessCan(
+ OrgPermissionIdentityActions.EditAuth,
+ OrgPermissionSubjects.Identity
+ );
}
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
diff --git a/backend/src/services/identity-oidc-auth/identity-oidc-auth-service.ts b/backend/src/services/identity-oidc-auth/identity-oidc-auth-service.ts
index c0c1437d0c..4c71247c43 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
@@ -781,7 +781,10 @@ export const identityOidcAuthServiceFactory = ({
actorOrgId
});
- ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.EditAuth, OrgPermissionSubjects.Identity);
+ ForbiddenError.from(permission).throwUnlessCan(
+ OrgPermissionIdentityActions.EditAuth,
+ OrgPermissionSubjects.Identity
+ );
}
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
diff --git a/backend/src/services/identity-spiffe-auth/identity-spiffe-auth-service.ts b/backend/src/services/identity-spiffe-auth/identity-spiffe-auth-service.ts
index 3df762a8b9..ffc87d9249 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
@@ -702,7 +702,10 @@ export const identitySpiffeAuthServiceFactory = ({
actorOrgId
});
- ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.EditAuth, OrgPermissionSubjects.Identity);
+ ForbiddenError.from(permission).throwUnlessCan(
+ OrgPermissionIdentityActions.EditAuth,
+ OrgPermissionSubjects.Identity
+ );
}
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);
diff --git a/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-service.ts b/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-service.ts
index c269c28153..8869b0cbaf 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
@@ -558,7 +558,10 @@ export const identityTlsCertAuthServiceFactory = ({
actorAuthMethod,
actorOrgId
});
- ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.EditAuth, OrgPermissionSubjects.Identity);
+ ForbiddenError.from(permission).throwUnlessCan(
+ OrgPermissionIdentityActions.EditAuth,
+ OrgPermissionSubjects.Identity
+ );
}
const plan = await licenseService.getPlan(identityMembershipOrg.scopeOrgId);