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
do not load target permision in new system
Thiago Araujo da Silvabf6c7e665f8a
diff --git a/backend/src/services/identity/identity-auth-permission-fns.test.ts b/backend/src/services/identity/identity-auth-permission-fns.test.tsindex 012707f7fd..b8eb6a02c7 100644--- a/backend/src/services/identity/identity-auth-permission-fns.test.ts+++ b/backend/src/services/identity/identity-auth-permission-fns.test.ts@@ -45,20 +45,28 @@ const runBoundary = async ({actorPermission,targetPermissions,projectId,- scopeCalls = []+ scopeCalls = [],+ roleLookups = []}: {shouldUseNewPrivilegeSystem?: boolean;actorPermission: MongoAbility;targetPermissions: MongoAbility[];projectId?: string;scopeCalls?: TScopeCall[];+ roleLookups?: string[];}) => {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 })))+ getOrgPermissionByRoles: () => {+ roleLookups.push("org");+ return Promise.resolve(targetPermissions.map((permission) => ({ permission })));+ },+ getProjectPermissionByRoles: () => {+ roleLookups.push("project");+ return Promise.resolve(targetPermissions.map((permission) => ({ permission })));+ }},orgDAL: { findById: () => Promise.resolve({ shouldUseNewPrivilegeSystem }) },membershipIdentityDAL: {@@ -121,6 +129,20 @@ describe("assertIdentityAuthMutationAllowed", () => {runBoundary({ shouldUseNewPrivilegeSystem: true, actorPermission: orgMember, targetPermissions: [orgMember] })).rejects.toThrow(PermissionBoundaryError);});++ test("the target is not looked up at all under the new privilege system", async () => {+ const scopeCalls: TScopeCall[] = [];+ const roleLookups: string[] = [];+ await runBoundary({+ shouldUseNewPrivilegeSystem: true,+ actorPermission: orgEditAuthOnly,+ targetPermissions: [orgAdmin],+ scopeCalls,+ roleLookups+ });+ expect(scopeCalls).toEqual([]);+ expect(roleLookups).toEqual([]);+ });});describe("project-level identity", () => {@@ -165,5 +187,20 @@ describe("assertIdentityAuthMutationAllowed", () => {})).rejects.toThrow(PermissionBoundaryError);});++ test("the target is not looked up at all under the new privilege system", async () => {+ const scopeCalls: TScopeCall[] = [];+ const roleLookups: string[] = [];+ await runBoundary({+ shouldUseNewPrivilegeSystem: true,+ actorPermission: projectEditAuthOnly,+ targetPermissions: [projectAdmin],+ projectId: "project-1",+ scopeCalls,+ roleLookups+ });+ expect(scopeCalls).toEqual([]);+ expect(roleLookups).toEqual([]);+ });});});diff --git a/backend/src/services/identity/identity-auth-permission-fns.ts b/backend/src/services/identity/identity-auth-permission-fns.tsindex 328fcaba0d..af16053faa 100644--- a/backend/src/services/identity/identity-auth-permission-fns.ts+++ b/backend/src/services/identity/identity-auth-permission-fns.ts@@ -57,15 +57,23 @@ export const assertIdentityAuthMutationAllowed = async (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) : [];+ const resolveTargetPermissions = async () => {+ if (shouldUseNewPrivilegeSystem) return [];++ const targetMembership = await membershipIdentityDAL.getIdentityById({+ scopeData: projectId+ ? { scope: AccessScope.Project, orgId, projectId }+ : { scope: AccessScope.Organization, orgId },+ identityId+ });+ const targetRoles = targetMembership ? resolveMembershipRoleSlugs(targetMembership.roles) : [];++ const rolePermissions = projectId+ ? await permissionService.getProjectPermissionByRoles(targetRoles, projectId, { ignoreUnresolvedRoles: true })+ : await permissionService.getOrgPermissionByRoles(targetRoles, orgId, { ignoreUnresolvedRoles: true });++ return rolePermissions.map(({ permission: rolePermission }) => ({ permission: rolePermission }));+ };if (projectId) {const { permission } = await permissionService.getProjectPermission({@@ -76,18 +84,13 @@ export const assertIdentityAuthMutationAllowed = async (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 })),+ targetPermissions: await resolveTargetPermissions(),baseMessage,subjectFields: { identityId }});@@ -102,16 +105,13 @@ export const assertIdentityAuthMutationAllowed = async (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 })),+ targetPermissions: await resolveTargetPermissions(),baseMessage});};