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(agent-vault): name the session in its revoke and label audit events
Scott Wilsonad96b27adbdf
diff --git a/backend/src/ee/routes/v1/agent-vault-routers/agent-vault-session-router.ts b/backend/src/ee/routes/v1/agent-vault-routers/agent-vault-session-router.tsindex e4f971f2ba..d6f1bb342f 100644--- a/backend/src/ee/routes/v1/agent-vault-routers/agent-vault-session-router.ts+++ b/backend/src/ee/routes/v1/agent-vault-routers/agent-vault-session-router.ts@@ -7,7 +7,8 @@ import {import { AgentVaultSessionScope, AgentVaultSessionStatus } from "@app/ee/services/agent-vault/agent-vault-enums";import {agentVaultSessionLabelSchema,- agentVaultSessionLabelUpdateSchema+ agentVaultSessionLabelUpdateSchema,+ describeSessionForAudit} from "@app/ee/services/agent-vault-session/agent-vault-session-fns";import {AGENT_VAULT_MAX_SESSION_BUNDLES,@@ -263,7 +264,12 @@ export const registerAgentVaultSessionRouter = async (server: FastifyZodProviderprojectId: req.internalAgentVaultProjectId,event: {type: EventType.AGENT_VAULT_SESSION_UPDATE,- metadata: { sessionId: session.id, label: session.label, previousLabel }+ metadata: {+ sessionId: session.id,+ label: session.label,+ previousLabel,+ ...describeSessionForAudit(session)+ }}});}@@ -300,7 +306,7 @@ export const registerAgentVaultSessionRouter = async (server: FastifyZodProviderprojectId: req.internalAgentVaultProjectId,event: {type: EventType.AGENT_VAULT_SESSION_REVOKE,- metadata: { sessionId: session.id, label: session.label }+ metadata: { sessionId: session.id, label: session.label, ...describeSessionForAudit(session) }}});diff --git a/backend/src/ee/services/agent-vault-session-log/agent-vault-session-log-service.test.ts b/backend/src/ee/services/agent-vault-session-log/agent-vault-session-log-service.test.tsindex e4a0515628..eb583c77a2 100644--- a/backend/src/ee/services/agent-vault-session-log/agent-vault-session-log-service.test.ts+++ b/backend/src/ee/services/agent-vault-session-log/agent-vault-session-log-service.test.ts@@ -312,16 +312,17 @@ describe("createChunkUploadUrl: the retirement grace window", () => {});});+ // Deleting the owner clears both ids and a trigger stamps revokedAt, so these rows carry it like a revoke would.test("a session whose owner was deleted still accepts what the proxy held, for a day", async () => {const { service } = build({- session: { ...liveSession(), userId: null, identityId: null, updatedAt: hoursAgo(23) }+ session: { ...liveSession(), userId: null, identityId: null, revokedAt: hoursAgo(23) }});await expect(record(service)).resolves.toHaveProperty("uploadUrl");});- test("a session whose owner was deleted more than a day ago is refused", async () => {+ test("a session whose owner was deleted more than a day ago stays refused after a later edit", async () => {const { service } = build({- session: { ...liveSession(), userId: null, identityId: null, updatedAt: hoursAgo(25) }+ session: { ...liveSession(), userId: null, identityId: null, revokedAt: hoursAgo(25), updatedAt: new Date() }});await expect(record(service)).rejects.toMatchObject({message: "Session ended too long ago to accept session logs"diff --git a/backend/src/ee/services/agent-vault-session/agent-vault-session-fns.test.ts b/backend/src/ee/services/agent-vault-session/agent-vault-session-fns.test.tsnew file mode 100644index 0000000000..a1d1bfe279--- /dev/null+++ b/backend/src/ee/services/agent-vault-session/agent-vault-session-fns.test.ts@@ -0,0 +1,47 @@+import { describe, expect, test } from "vitest";++import { AgentVaultMemberType } from "../agent-vault/agent-vault-enums";+import { describeSessionForAudit } from "./agent-vault-session-fns";++describe("describeSessionForAudit", () => {+ test("names a user's session by email, and the bundle it carried", () => {+ expect(+ describeSessionForAudit({+ actor: {+ type: AgentVaultMemberType.User,+ id: "u1",+ username: "alice",+ email: "[email protected]",+ firstName: "Alice",+ lastName: null+ },+ accessBundles: [{ name: "release" }]+ })+ ).toEqual({ sessionOwner: "[email protected]", accessBundleName: "release" });+ });++ test("falls back to the username when a user has no email", () => {+ expect(+ describeSessionForAudit({+ actor: {+ type: AgentVaultMemberType.User,+ id: null,+ username: "alice",+ email: null,+ firstName: null,+ lastName: null+ },+ accessBundles: [{ name: "release" }]+ }).sessionOwner+ ).toBe("alice");+ });++ test("names a machine identity's session by the identity, and allows a session with no bundle left", () => {+ expect(+ describeSessionForAudit({+ actor: { type: AgentVaultMemberType.MachineIdentity, id: "i1", name: "github-actions" },+ accessBundles: []+ })+ ).toEqual({ sessionOwner: "github-actions", accessBundleName: null });+ });+});diff --git a/backend/src/ee/services/agent-vault-session/agent-vault-session-fns.ts b/backend/src/ee/services/agent-vault-session/agent-vault-session-fns.tsindex 1d048fcf56..7d1c76cb37 100644--- a/backend/src/ee/services/agent-vault-session/agent-vault-session-fns.ts+++ b/backend/src/ee/services/agent-vault-session/agent-vault-session-fns.ts@@ -5,7 +5,8 @@ import { z } from "zod";import { ActorType } from "@app/services/auth/auth-type";-import { AgentVaultSessionStatus } from "../agent-vault/agent-vault-enums";+import { AgentVaultMemberType, AgentVaultSessionStatus } from "../agent-vault/agent-vault-enums";+import { TAgentVaultSessionActor } from "./agent-vault-session-types";export const AGENT_VAULT_SESSION_TOKEN_PREFIX = "agv_";@@ -70,3 +71,15 @@ export const deriveSessionStatus = (if (session.expiresAt && session.expiresAt <= now) return AgentVaultSessionStatus.Expired;return AgentVaultSessionStatus.Active;};++// Most sessions have no label, so a session's audit event also names whose session it is and what it carried.+export const describeSessionForAudit = (session: {+ actor: TAgentVaultSessionActor;+ accessBundles: { name: string }[];+}) => ({+ sessionOwner:+ session.actor.type === AgentVaultMemberType.MachineIdentity+ ? session.actor.name+ : (session.actor.email ?? session.actor.username),+ accessBundleName: session.accessBundles[0]?.name ?? null+});diff --git a/backend/src/ee/services/audit-log/audit-log-types.ts b/backend/src/ee/services/audit-log/audit-log-types.tsindex 1b99635a34..0757e901dd 100644--- a/backend/src/ee/services/audit-log/audit-log-types.ts+++ b/backend/src/ee/services/audit-log/audit-log-types.ts@@ -6788,6 +6788,8 @@ interface AgentVaultSessionUpdateEvent {sessionId: string;label: string | null;previousLabel: string | null;+ sessionOwner: string;+ accessBundleName: string | null;};}@@ -6796,6 +6798,8 @@ interface AgentVaultSessionRevokeEvent {metadata: {sessionId: string;label: string | null;+ sessionOwner: string;+ accessBundleName: string | null;};}