Skip to content

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

fix(agent-vault): keep delegation edits and revoke answers current

Scott Wilson4dc03eb7bfe6
diff --git a/backend/e2e-test/routes/v1/agent-vault.spec.ts b/backend/e2e-test/routes/v1/agent-vault.spec.ts
index 30d0060dfe..17111bf8d3 100644
--- a/backend/e2e-test/routes/v1/agent-vault.spec.ts
+++ b/backend/e2e-test/routes/v1/agent-vault.spec.ts
@@ -5026,6 +5026,44 @@ describe("Agent Vault V1 Router", async () => {
}
});
+ test("a revoke that finds the acting identity just deleted reports the session as it is now", async () => {
+ const bundle = await createAccessBundle(`obo-revoke-race-${Date.now()}`);
+ const bot = await createMemberIdentity(`obo-revoke-race-bot-${Date.now()}`);
+ try {
+ await grantBundle(bundle.id, { machineIdentityIds: [bot.id] });
+ await delegate(bot, { scope: "selected", userIds: [seedData1.id] });
+ const minted = await mintFor(bot, { userId: seedData1.id }, bundle.name);
+ expect(minted.statusCode).toBe(200);
+ const sessionId = minted.json().session.id as string;
+
+ // The revoke reads the session first, then queues its write behind this lock. Deleting the identity sets
+ // actingIdentityId to NULL, so the write skips the row and the answer comes from a read of the primary.
+ const trx = await testDb.transaction();
+ try {
+ const { rows } = await trx.raw("select pg_backend_pid() as pid");
+ await trx("agent_vault_sessions").where({ id: sessionId }).forUpdate().first();
+
+ const pending = inject("POST", `${sessionsUrl}/${sessionId}/revoke`);
+ await waitUntilBlockedBy(rows[0].pid);
+ await trx("agent_vault_sessions").where({ id: sessionId }).update({ actingIdentityId: null });
+ await trx.commit();
+
+ const revoked = await pending;
+ expect(revoked.statusCode).toBe(200);
+ expect(revoked.json().session).toMatchObject({
+ status: "revoked",
+ revokedAt: null,
+ actingIdentity: { id: null, name: expect.stringContaining("obo-revoke-race-bot-") }
+ });
+ } catch (err) {
+ if (!trx.isCompleted()) await trx.rollback();
+ throw err;
+ }
+ } finally {
+ await bot.cleanup();
+ }
+ });
+
test("a delegation names Agent Vault members, and only an admin or the identity itself reads it", async () => {
const projectId = await getProjectId();
const bot = await createMemberIdentity(`obo-api-bot-${Date.now()}`);
diff --git a/backend/src/ee/services/agent-vault-session/agent-vault-session-service.ts b/backend/src/ee/services/agent-vault-session/agent-vault-session-service.ts
index 065e78307b..47adf864c5 100644
--- a/backend/src/ee/services/agent-vault-session/agent-vault-session-service.ts
+++ b/backend/src/ee/services/agent-vault-session/agent-vault-session-service.ts
@@ -334,7 +334,12 @@ export const agentVaultSessionServiceFactory = ({
...session,
revokedAt: current.revokedAt ?? null,
userId: current.userId ?? null,
- identityId: current.identityId ?? null
+ identityId: current.identityId ?? null,
+ actingIdentityId: current.actingIdentityId ?? null,
+ actingIdentity: session.actingIdentity && {
+ ...session.actingIdentity,
+ id: current.actingIdentityId ?? null
+ }
}
: session
),
diff --git a/frontend/src/hooks/api/agentVault/mutations.tsx b/frontend/src/hooks/api/agentVault/mutations.tsx
index 0c4a83d390..bd7421b7d4 100644
--- a/frontend/src/hooks/api/agentVault/mutations.tsx
+++ b/frontend/src/hooks/api/agentVault/mutations.tsx
@@ -56,8 +56,13 @@ export const useSetAgentVaultDelegation = () => {
);
return data.delegation;
},
- onSuccess: () => {
- queryClient.invalidateQueries({ queryKey: agentVaultKeys.delegations(currentOrg.id) });
+ // A save sends the whole list, so the next edit has to start from this one, not from a refetch
+ // that reads a replica which may not have the write yet.
+ onSuccess: (delegation, { machineIdentityId }) => {
+ queryClient.setQueryData(
+ agentVaultKeys.delegation(currentOrg.id, machineIdentityId),
+ delegation
+ );
}
});
};
@@ -72,8 +77,8 @@ export const useDeleteAgentVaultDelegation = () => {
);
return data.delegation;
},
- onSuccess: () => {
- queryClient.invalidateQueries({ queryKey: agentVaultKeys.delegations(currentOrg.id) });
+ onSuccess: (_, { machineIdentityId }) => {
+ queryClient.setQueryData(agentVaultKeys.delegation(currentOrg.id, machineIdentityId), null);
}
});
};