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
Revert "fix(agent-vault): read an added delegation after commit"
Scott Wilsonc56082b37f81
diff --git a/backend/src/ee/services/agent-vault-delegation/agent-vault-delegation-dal.ts b/backend/src/ee/services/agent-vault-delegation/agent-vault-delegation-dal.tsindex 8bd019dfd0..c30e79d8b9 100644--- a/backend/src/ee/services/agent-vault-delegation/agent-vault-delegation-dal.ts+++ b/backend/src/ee/services/agent-vault-delegation/agent-vault-delegation-dal.ts@@ -164,11 +164,10 @@ export const agentVaultDelegationDALFactory = (db: TDbClient) => {limit,offset = 0}: { projectId: string; identityIds?: string[]; limit?: number; offset?: number },- tx?: Knex,- { readFromPrimary = false }: { readFromPrimary?: boolean } = {}+ tx?: Knex): Promise<{ delegations: TAgentVaultDelegationView[]; totalCount: number }> => {try {- const conn = tx || (readFromPrimary ? db : db.replicaNode());+ const conn = tx || db.replicaNode();const filtered = () => {const query = conn(TableName.AgentVaultDelegation).where(`${TableName.AgentVaultDelegation}.projectId`,diff --git a/backend/src/ee/services/agent-vault-delegation/agent-vault-delegation-service.ts b/backend/src/ee/services/agent-vault-delegation/agent-vault-delegation-service.tsindex 9c9c0b2d2c..62555cf317 100644--- a/backend/src/ee/services/agent-vault-delegation/agent-vault-delegation-service.ts+++ b/backend/src/ee/services/agent-vault-delegation/agent-vault-delegation-service.ts@@ -404,7 +404,7 @@ export const agentVaultDelegationServiceFactory = ({}};- const isChanged = await agentVaultDelegationDAL.transaction(async (tx) => {+ const { delegation, isChanged } = await agentVaultDelegationDAL.transaction(async (tx) => {// The same order a save takes them in: memberships, then the delegation row.const memberships = await agentVaultDelegationDAL.lockMemberships({ projectId, identityId: machineIdentityId, userIds, groupIds },@@ -428,17 +428,12 @@ export const agentVaultDelegationServiceFactory = ({{ delegationId: row.id, membershipIds: membershipIdsNaming(memberships, userIds, groupIds) },tx);- return added > 0;- });-- // Read after commit so the lock isn't held for the whole list, and from the primary, which already has the write.- const {- delegations: [delegation]- } = await agentVaultDelegationDAL.findViews({ projectId, identityIds: [machineIdentityId] }, undefined, {- readFromPrimary: true+ // Read in the transaction because the replica may not have the write yet.+ const {+ delegations: [written]+ } = await agentVaultDelegationDAL.findViews({ projectId, identityIds: [machineIdentityId] }, tx);+ return { delegation: written, isChanged: added > 0 };});- // Only a concurrent delete between the commit and this read leaves nothing to return.- if (!delegation) throw notFound(machineIdentityId);// isChanged lets the caller audit only a real change: naming users and groups already in it writes nothing.return { delegation, isChanged };