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 audit log placement
Thiago Araujo da Silva23db40d699c1
diff --git a/backend/AGENTS.md b/backend/AGENTS.mdindex 4df148a834..42b806e96e 100644--- a/backend/AGENTS.md+++ b/backend/AGENTS.md@@ -924,7 +924,9 @@ itself whether the actor still reaches the org.rows an actor holds aren't bounded. PAM cancellations, the `revoke-org-project-access` audit log and usagemeters fire after each batch commits and only when something was removed, so replays are silent.- **The audit event is written for admins.** The actor is the platform; `reason` is an- `OrgAccessRemovalCause` mapped from the event type. Actors and the group are recorded by id only: a name+ `OrgAccessRemovalCause` mapped from the event type. `revokeActorsInOrgs` returns one entry per (org, actor)+ and each is logged under that org, so a sub-org admin sees the revoke in their own log when a root+ removal cascaded into their org. Actors and the group are recorded by id only: a namelookup after the revoke commits could fail, and the retry would find nothing left to log. `projectIds` areproject memberships, `resources` the resource grants.- **The daily `org-access-reconcile-sweep` cron is a backstop, not a substitute.** It looks for project anddiff --git a/backend/src/services/membership/project-access-revoke-service.test.ts b/backend/src/services/membership/project-access-revoke-service.test.tsindex c25d007519..35f6216acd 100644--- a/backend/src/services/membership/project-access-revoke-service.test.ts+++ b/backend/src/services/membership/project-access-revoke-service.test.ts@@ -20,6 +20,7 @@ const tx = {} as never;type TRow = {id: string;+ scopeOrgId?: string;actorUserId?: string;actorIdentityId?: string;scopeProjectId: string;@@ -34,7 +35,13 @@ const build = (opts?: { projectRows?: TRow[]; resourceRows?: TRow[] }) => {membershipDAL: {find: vi.fn(),delete: vi.fn((filter: { $in?: { actorUserId?: string[]; actorIdentityId?: string[] } }) =>- Promise.resolve(ofActor(opts?.projectRows ?? [], filter).map((row) => ({ ...row, scope: AccessScope.Project })))+ Promise.resolve(+ ofActor(opts?.projectRows ?? [], filter).map((row) => ({+ scopeOrgId: ORG_ID,+ ...row,+ scope: AccessScope.Project+ }))+ ))},projectDAL: { find: vi.fn().mockResolvedValue([{ id: PROJECT_A }, { id: PROJECT_B }, { id: PROJECT_C }]) },@@ -49,7 +56,7 @@ const build = (opts?: { projectRows?: TRow[]; resourceRows?: TRow[] }) => {? filter.userIds.includes(row.actorUserId): filter.identityIds.includes(row.actorIdentityId!))- .map((row) => ({ ...row, scope: RESOURCE_SCOPE }))+ .map((row) => ({ scopeOrgId: ORG_ID, ...row, scope: RESOURCE_SCOPE }))))},@@ -84,7 +91,7 @@ describe("projectAccessRevokeService", () => {const { service, deps } = build({projectRows: [{ id: uuid(100), actorUserId: USER_ID, scopeProjectId: PROJECT_A },- { id: uuid(101), actorUserId: USER_ID, scopeProjectId: PROJECT_B }+ { id: uuid(101), scopeOrgId: SUB_ORG_ID, actorUserId: USER_ID, scopeProjectId: PROJECT_B }]});const orgIds = [ORG_ID, SUB_ORG_ID];@@ -119,7 +126,10 @@ describe("projectAccessRevokeService", () => {expect.objectContaining({ orgIds, userIds: [USER_ID], tx }));expect(send).toBe(sendPamCancellations);- expect(revoked).toEqual([{ userId: USER_ID, projectIds: [PROJECT_A, PROJECT_B], resources: [] }]);+ expect(revoked).toEqual([+ { orgId: ORG_ID, userId: USER_ID, projectIds: [PROJECT_A], resources: [] },+ { orgId: SUB_ORG_ID, userId: USER_ID, projectIds: [PROJECT_B], resources: [] }+ ]);});test("removes an identity's rows and resource grants and reports them per actor", async () => {@@ -150,6 +160,7 @@ describe("projectAccessRevokeService", () => {expect(deps.alertChannelRecipientDAL.pruneOutOfScopeRecipients).not.toHaveBeenCalled();expect(revoked).toEqual([{+ orgId: ORG_ID,identityId: IDENTITY_ID,projectIds: [PROJECT_A],resources: [{ projectId: PROJECT_A, resourceType: "pam-account", resourceId: uuid(302) }]@@ -174,6 +185,7 @@ describe("projectAccessRevokeService", () => {expect(revoked).toEqual([{+ orgId: ORG_ID,userId: USER_ID,projectIds: [],resources: [{ projectId: PROJECT_C, resourceType: "pam-folder", resourceId: uuid(303) }]diff --git a/backend/src/services/membership/project-access-revoke-service.ts b/backend/src/services/membership/project-access-revoke-service.tsindex ffa242a2d0..9a49020985 100644--- a/backend/src/services/membership/project-access-revoke-service.ts+++ b/backend/src/services/membership/project-access-revoke-service.ts@@ -31,6 +31,7 @@ export type TProjectAccessRevokeServiceFactory = ReturnType<typeof projectAccesstype TRevokedProjectResource = { projectId: string; resourceType: string; resourceId: string };export type TRevokedProjectAccess = {+ orgId: string;userId?: string;identityId?: string;projectIds: string[];@@ -106,21 +107,20 @@ export const projectAccessRevokeServiceFactory = ({tx});- const rows = [...userRows, ...identityRows, ...resourceRows];- const revoked: TRevokedProjectAccess[] = [- ...Object.entries(- groupBy(- rows.filter((row) => row.actorUserId),- (row) => row.actorUserId as string- )- ).map(([userId, actorRows]) => ({ userId, ...toRevoked(actorRows) })),- ...Object.entries(- groupBy(- rows.filter((row) => row.actorIdentityId),- (row) => row.actorIdentityId as string- )- ).map(([identityId, actorRows]) => ({ identityId, ...toRevoked(actorRows) }))- ];+ const rows = [...userRows, ...identityRows, ...resourceRows].filter(+ (row) => row.actorUserId || row.actorIdentityId+ );+ const revoked: TRevokedProjectAccess[] = Object.values(+ groupBy(rows, (row) => `${row.scopeOrgId}|${row.actorUserId ?? ""}|${row.actorIdentityId ?? ""}`)+ ).map((actorRows) => {+ const [{ scopeOrgId, actorUserId, actorIdentityId }] = actorRows;+ return {+ orgId: scopeOrgId as string,+ userId: actorUserId ?? undefined,+ identityId: actorIdentityId ?? undefined,+ ...toRevoked(actorRows)+ };+ });return { revoked, sendPamCancellations };};diff --git a/backend/src/services/org/org-access-fns.ts b/backend/src/services/org/org-access-fns.tsindex 21289e8aa5..3369bea654 100644--- a/backend/src/services/org/org-access-fns.ts+++ b/backend/src/services/org/org-access-fns.ts@@ -10,18 +10,16 @@ import { OrgAccessRemovalCause } from "./org-membership-events";export const auditRevokedProjectAccess = async ({auditLogService,- orgId,revoked,reason,groupId}: {auditLogService: Pick<TAuditLogServiceFactory, "createAuditLog">;- orgId: string;revoked: TRevokedProjectAccess[];reason: OrgAccessRemovalCause;groupId?: string;}) => {- for await (const { userId, identityId, projectIds, resources } of revoked) {+ for await (const { orgId, userId, identityId, projectIds, resources } of revoked) {await auditLogService.createAuditLog({orgId,actor: { type: ActorType.PLATFORM, metadata: {} },diff --git a/backend/src/services/org/org-access-reconcile-consumer.test.ts b/backend/src/services/org/org-access-reconcile-consumer.test.tsindex 0e1362b686..df3103e36f 100644--- a/backend/src/services/org/org-access-reconcile-consumer.test.ts+++ b/backend/src/services/org/org-access-reconcile-consumer.test.ts@@ -34,7 +34,8 @@ const userRemovedFromOrg = (orgId = ORG_ID) =>// The revoke service only reports actors it found rows for.const build = (opts?: {withAccess?: { userIds?: string[]; identityIds?: string[] };- revoked?: TRevokedProjectAccess[];+ // The mock stamps the org it was called for, like the real service does from the rows.+ revoked?: Omit<TRevokedProjectAccess, "orgId">[];orgs?: Record<string, unknown>;childOrgs?: string[];}) => {@@ -61,6 +62,7 @@ const build = (opts?: {projectAccessRevokeService: {revokeActorsInOrgs: vi.fn(async ({+ orgIds,userIds = [],identityIds = []}: {@@ -68,11 +70,13 @@ const build = (opts?: {userIds?: string[];identityIds?: string[];}) => ({- revoked: (opts?.revoked ?? []).filter(- (entry) =>- (entry.userId && userIds.includes(entry.userId)) ||- (entry.identityId && identityIds.includes(entry.identityId))- ),+ revoked: (opts?.revoked ?? [])+ .filter(+ (entry) =>+ (entry.userId && userIds.includes(entry.userId)) ||+ (entry.identityId && identityIds.includes(entry.identityId))+ )+ .map((entry) => ({ ...entry, orgId: orgIds[0] })),sendPamCancellations}))diff --git a/backend/src/services/org/org-access-reconcile-consumer.ts b/backend/src/services/org/org-access-reconcile-consumer.tsindex 4053ac7854..b6934dcb77 100644--- a/backend/src/services/org/org-access-reconcile-consumer.ts+++ b/backend/src/services/org/org-access-reconcile-consumer.ts@@ -127,7 +127,6 @@ export const orgAccessReconcileConsumerFactory = ({if (outcome?.revoked.length) {await auditRevokedProjectAccess({auditLogService,- orgId,revoked: outcome.revoked,reason: scope.reason,groupId: scope.groupIddiff --git a/backend/src/services/org/org-fns.ts b/backend/src/services/org/org-fns.tsindex bbc518a362..58f6121533 100644--- a/backend/src/services/org/org-fns.ts+++ b/backend/src/services/org/org-fns.ts@@ -146,7 +146,7 @@ export const deleteOrgMembershipsFn = async ({});sendPamCancellations();- await auditRevokedProjectAccess({ auditLogService, orgId, revoked, reason: OrgAccessRemovalCause.RemovedFromOrg });+ await auditRevokedProjectAccess({ auditLogService, revoked, reason: OrgAccessRemovalCause.RemovedFromOrg });return deletedMemberships;};diff --git a/frontend/src/hooks/api/pam/mutations.tsx b/frontend/src/hooks/api/pam/mutations.tsxindex ecf78abc53..6663fee237 100644--- a/frontend/src/hooks/api/pam/mutations.tsx+++ b/frontend/src/hooks/api/pam/mutations.tsx@@ -530,6 +530,7 @@ export const useAddPamProductUserMember = () => {onSuccess: (_, { projectId }) => {queryClient.invalidateQueries({ queryKey: pamKeys.all });queryClient.invalidateQueries({ queryKey: projectKeys.getProjectUsers(projectId) });+ queryClient.invalidateQueries({ queryKey: projectKeys.getProjectUsers(projectId, true) });queryClient.invalidateQueries({ queryKey: projectKeys.getAvailableProjectUsers(projectId) });}});@@ -549,6 +550,7 @@ export const useAddPamProductGroupMember = () => {queryClient.invalidateQueries({queryKey: projectKeys.getProjectGroupMemberships(projectId)});+ queryClient.invalidateQueries({ queryKey: projectKeys.getProjectUsers(projectId, true) });}});};@@ -595,6 +597,7 @@ export const useRemovePamProductUserMember = () => {onSuccess: (_, { projectId }) => {queryClient.invalidateQueries({ queryKey: pamKeys.all });queryClient.invalidateQueries({ queryKey: projectKeys.getProjectUsers(projectId) });+ queryClient.invalidateQueries({ queryKey: projectKeys.getProjectUsers(projectId, true) });queryClient.invalidateQueries({ queryKey: projectKeys.getAvailableProjectUsers(projectId) });}});@@ -612,6 +615,7 @@ export const useRemovePamProductGroupMember = () => {queryClient.invalidateQueries({queryKey: projectKeys.getProjectGroupMemberships(projectId)});+ queryClient.invalidateQueries({ queryKey: projectKeys.getProjectUsers(projectId, true) });}});};