Skip to content

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

adjust audit log

Thiago Araujo da Silvaa65d861c3955
diff --git a/backend/CLAUDE.md b/backend/CLAUDE.md
index 4ec6cd852c..2c404cb254 100644
--- a/backend/CLAUDE.md
+++ b/backend/CLAUDE.md
@@ -920,9 +920,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 usage
meters 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, and `username` / `identityName` / `groupName` are
- read at log time (left out when the row is already gone, e.g. a deleted group). `projectIds` are project
- memberships, `resources` the resource grants.
+ `OrgAccessRemovalCause` mapped from the event type. Actors and the group are recorded by id only: a name
+ lookup after the revoke commits could fail, and the retry would find nothing left to log. `projectIds` are
+ project memberships, `resources` the resource grants.
- **The daily `org-access-reconcile-sweep` cron is a backstop, not a substitute.** It looks for project and
resource rows whose actor no longer reaches the org (ghost users skipped) and emits a `membership` event
per (actor, org) pair, capped at 5000 per run, in a replica tx with a 3 minute `statement_timeout`.
diff --git a/backend/src/ee/services/audit-log/audit-log-types.ts b/backend/src/ee/services/audit-log/audit-log-types.ts
index c2a69ac2c9..667def8db1 100644
--- a/backend/src/ee/services/audit-log/audit-log-types.ts
+++ b/backend/src/ee/services/audit-log/audit-log-types.ts
@@ -2935,21 +2935,18 @@ interface UnlinkGroupFromSubOrgEvent {
};
}
-// Written by the reconcile consumer, so the actor is the platform and `reason` / `groupId` say why. Names
-// are looked up at log time and missing if the row's already gone. `resources` are resource-level grants
-// (PAM, Agent Vault, PKI apps, signers), including ones in projects only reached through a group.
+// Written by the reconcile consumer, so the actor is the platform and `reason` / `groupId` say why.
+// `resources` are resource-level grants (PAM, Agent Vault, PKI apps, signers), including ones in projects
+// only reached through a group.
interface RevokeOrgProjectAccessEvent {
type: EventType.REVOKE_ORG_PROJECT_ACCESS;
metadata: {
userId?: string;
- username?: string;
identityId?: string;
- identityName?: string;
projectIds: string[];
resources: { projectId: string; resourceType: string; resourceId: string }[];
reason: OrgAccessRemovalCause;
groupId?: string;
- groupName?: string;
};
}
diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.ts
index 641a4afda2..11f9a501d9 100644
--- a/backend/src/server/routes/index.ts
+++ b/backend/src/server/routes/index.ts
@@ -3197,9 +3197,6 @@ export const registerRoutes = async (
eventOutboxRegistry.register(
orgAccessReconcileConsumerFactory({
orgDAL,
- userDAL,
- identityDAL,
- groupDAL,
projectAccessRevokeService,
auditLogService,
usageMeteringService
diff --git a/backend/src/services/org/org-access-reconcile-consumer.test.ts b/backend/src/services/org/org-access-reconcile-consumer.test.ts
index fb19f33ed0..639d803ac1 100644
--- a/backend/src/services/org/org-access-reconcile-consumer.test.ts
+++ b/backend/src/services/org/org-access-reconcile-consumer.test.ts
@@ -37,7 +37,6 @@ const build = (opts?: {
revoked?: TRevokedProjectAccess[];
orgs?: Record<string, unknown>;
childOrgs?: string[];
- groupExists?: boolean;
}) => {
const tx = { raw: vi.fn().mockResolvedValue(undefined) };
const sendPamCancellations = vi.fn();
@@ -57,11 +56,6 @@ const build = (opts?: {
lockActorsForOrgAccess: vi.fn().mockResolvedValue(undefined),
transaction: vi.fn(async (cb: (trx: unknown) => Promise<unknown>) => cb(tx))
},
- userDAL: { findById: vi.fn(async (id: string) => ({ id, username: `${id}@example.com` })) },
- identityDAL: { findById: vi.fn(async (id: string) => ({ id, name: `identity-${id}` })) },
- groupDAL: {
- findById: vi.fn(async (id: string) => ((opts?.groupExists ?? true) ? { id, name: "platform-team" } : undefined))
- },
projectAccessRevokeService: {
revokeActorsInOrgs: vi.fn(
async ({
@@ -202,7 +196,6 @@ describe("org access reconcile consumer", () => {
]);
expect(result.status).toBe(EventResultStatus.Delivered);
expect(deps.orgDAL.transaction).not.toHaveBeenCalled();
- expect(deps.groupDAL.findById).toHaveBeenCalledWith(GROUP_ID);
const [orgResult] = await consumer.handle([userRemovedFromOrg()]);
@@ -223,21 +216,19 @@ describe("org access reconcile consumer", () => {
type: EventType.REVOKE_ORG_PROJECT_ACCESS,
metadata: {
userId: USER_ID,
- username: `${USER_ID}@example.com`,
+ identityId: undefined,
projectIds: [PROJECT_A, PROJECT_B],
resources: [],
reason: OrgAccessRemovalCause.RemovedFromOrg,
- groupId: undefined,
- groupName: undefined
+ groupId: undefined
}
}
})
);
- expect(deps.groupDAL.findById).toHaveBeenCalledTimes(1);
expect(deps.usageMeteringService.emit).toHaveBeenCalledTimes(3);
});
- test("names the identity and the group that carried the lost path, and says which grants went", async () => {
+ test("records the identity and the group that carried the lost path, and says which grants went", async () => {
const { consumer, deps, tx } = build({
revoked: [
{
@@ -262,19 +253,17 @@ describe("org access reconcile consumer", () => {
tx
);
expect(auditMetadata(deps)).toEqual({
+ userId: undefined,
identityId: IDENTITY_ID,
- identityName: `identity-${IDENTITY_ID}`,
projectIds: [PROJECT_A],
resources: [{ projectId: PROJECT_A, resourceType: "pam-account", resourceId: uuid(302) }],
reason: OrgAccessRemovalCause.RemovedFromGroup,
- groupId: GROUP_ID,
- groupName: "platform-team"
+ groupId: GROUP_ID
});
});
- test("a deleted group is logged by id only, with the deletion as the cause", async () => {
+ test("a group delete is logged with the deletion as the cause", async () => {
const { consumer, deps } = build({
- groupExists: false,
revoked: [{ userId: USER_ID, projectIds: [PROJECT_A], resources: [] }]
});
@@ -288,8 +277,7 @@ describe("org access reconcile consumer", () => {
expect(auditMetadata(deps)).toMatchObject({
reason: OrgAccessRemovalCause.GroupDeleted,
- groupId: GROUP_ID,
- groupName: undefined
+ groupId: GROUP_ID
});
});
@@ -363,7 +351,6 @@ describe("org access reconcile consumer", () => {
// Nothing in the DB says who to recheck anymore, only the payloads do.
test("still reaps when the group lost its link and its member before the events were handled", async () => {
const { consumer, deps } = build({
- groupExists: false,
revoked: [{ userId: USER_ID, projectIds: [PROJECT_A], resources: [] }]
});
@@ -422,6 +409,5 @@ describe("org access reconcile consumer", () => {
);
expect(deps.orgDAL.lockActorsForOrgAccess).toHaveBeenNthCalledWith(2, userIds.slice(ACTORS_PER_RECONCILE_TX), tx);
expect(deps.auditLogService.createAuditLog).toHaveBeenCalledTimes(userIds.length);
- expect(deps.groupDAL.findById).toHaveBeenCalledTimes(1);
});
});
diff --git a/backend/src/services/org/org-access-reconcile-consumer.ts b/backend/src/services/org/org-access-reconcile-consumer.ts
index 74d38e507f..cb29dc997a 100644
--- a/backend/src/services/org/org-access-reconcile-consumer.ts
+++ b/backend/src/services/org/org-access-reconcile-consumer.ts
@@ -1,5 +1,4 @@
import { EventType, TAuditLogServiceFactory } from "@app/ee/services/audit-log/audit-log-types";
-import { TGroupDALFactory } from "@app/ee/services/group/group-dal";
import { chunkArray } from "@app/lib/fn";
import { logger } from "@app/lib/logger";
import { ActorType } from "@app/services/auth/auth-type";
@@ -9,14 +8,9 @@ import {
TEvent,
TEventConsumerResult
} from "@app/services/event-outbox/event-outbox-types";
-import { TIdentityDALFactory } from "@app/services/identity/identity-dal";
import { AgentVaultIdentities, PamIdentities, SecretIdentities } from "@app/services/license-client";
import { TUsageMeteringServiceFactory } from "@app/services/license-client/usage";
-import {
- TProjectAccessRevokeServiceFactory,
- TRevokedProjectAccess
-} from "@app/services/membership/project-access-revoke-service";
-import { TUserDALFactory } from "@app/services/user/user-dal";
+import { TProjectAccessRevokeServiceFactory } from "@app/services/membership/project-access-revoke-service";
import { TOrgDALFactory } from "./org-dal";
import {
@@ -45,9 +39,6 @@ export type TOrgAccessReconcileConsumerDep = {
TOrgDALFactory,
"findById" | "find" | "findActorsWithOrgAccess" | "lockActorsForOrgAccess" | "transaction"
>;
- userDAL: Pick<TUserDALFactory, "findById">;
- identityDAL: Pick<TIdentityDALFactory, "findById">;
- groupDAL: Pick<TGroupDALFactory, "findById">;
projectAccessRevokeService: Pick<TProjectAccessRevokeServiceFactory, "revokeActorsInOrgs">;
auditLogService: Pick<TAuditLogServiceFactory, "createAuditLog">;
usageMeteringService: Pick<TUsageMeteringServiceFactory, "emit">;
@@ -70,9 +61,6 @@ const splitActors = (actors: TOrgMembershipActor[]) => ({
// validation already rejects these actors) and safe to re-run.
export const orgAccessReconcileConsumerFactory = ({
orgDAL,
- userDAL,
- identityDAL,
- groupDAL,
projectAccessRevokeService,
auditLogService,
usageMeteringService
@@ -125,18 +113,9 @@ export const orgAccessReconcileConsumerFactory = ({
return projectAccessRevokeService.revokeActorsInOrgs({ orgIds: [orgId], userIds, identityIds }, tx);
});
- const $describeActor = async ({ userId, identityId }: Pick<TRevokedProjectAccess, "userId" | "identityId">) => {
- if (userId) {
- const user = await userDAL.findById(userId);
- return { userId, username: user?.username };
- }
- const identity = identityId ? await identityDAL.findById(identityId) : undefined;
- return { identityId, identityName: identity?.name };
- };
-
// Small actor batches, each in its own short tx, since what they hold isn't bounded. Side effects fire per
// batch after commit and only when rows went, so replays are no-ops.
- const $reconcileOrg = async (orgId: string, scope: TReconcileScope, groupName?: string) => {
+ const $reconcileOrg = async (orgId: string, scope: TReconcileScope) => {
const org = await orgDAL.findById(orgId);
if (!org) return;
@@ -144,19 +123,19 @@ export const orgAccessReconcileConsumerFactory = ({
const outcome = await $revokeActors(orgId, splitActors(actors));
if (outcome) outcome.sendPamCancellations();
if (outcome?.revoked.length) {
- for await (const { projectIds, resources, ...actor } of outcome.revoked) {
+ for await (const { userId, identityId, projectIds, resources } of outcome.revoked) {
await auditLogService.createAuditLog({
orgId,
actor: { type: ActorType.PLATFORM, metadata: {} },
event: {
type: EventType.REVOKE_ORG_PROJECT_ACCESS,
metadata: {
- ...(await $describeActor(actor)),
+ userId,
+ identityId,
projectIds,
resources,
reason: scope.reason,
- groupId: scope.groupId,
- groupName
+ groupId: scope.groupId
}
}
});
@@ -183,10 +162,8 @@ export const orgAccessReconcileConsumerFactory = ({
}
let scope: TReconcileScope;
- let groupName: string | undefined;
try {
scope = await resolveScope();
- if (scope.groupId) groupName = (await groupDAL.findById(scope.groupId))?.name;
} catch (error) {
logger.error(error, `org-access-reconcile: failed to resolve the orgs and actors to recheck [eventId=${id}]`);
return {
@@ -199,7 +176,7 @@ export const orgAccessReconcileConsumerFactory = ({
const errors: string[] = [];
for await (const orgId of scope.orgIds) {
try {
- await $reconcileOrg(orgId, scope, groupName);
+ await $reconcileOrg(orgId, scope);
} catch (error) {
logger.error(error, `org-access-reconcile: failed for org ${orgId} (event ${id})`);
errors.push(`org ${orgId}: ${error instanceof Error ? error.message : "Unknown error"}`);