Skip to content

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

use primary on mgmt

Thiago Araujo da Silva60f9235558bf
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 adc29e6a03..0e1362b686 100644
--- a/backend/src/services/org/org-access-reconcile-consumer.test.ts
+++ b/backend/src/services/org/org-access-reconcile-consumer.test.ts
@@ -39,9 +39,11 @@ const build = (opts?: {
childOrgs?: string[];
}) => {
const tx = { raw: vi.fn().mockResolvedValue(undefined) };
+ const primary = { node: "primary" };
const sendPamCancellations = vi.fn();
const deps = {
orgDAL: {
+ primaryNode: vi.fn(() => primary),
findById: vi.fn((id: string) => {
const orgs = opts?.orgs ?? { [ORG_ID]: { id: ORG_ID }, [SUB_ORG_ID]: { id: SUB_ORG_ID } };
const org = orgs[id];
@@ -79,7 +81,7 @@ const build = (opts?: {
usageMeteringService: { emit: vi.fn() }
};
const consumer = orgAccessReconcileConsumerFactory(deps as never);
- return { consumer, deps, tx, sendPamCancellations };
+ return { consumer, deps, tx, primary, sendPamCancellations };
};
const auditMetadata = (deps: ReturnType<typeof build>["deps"], call = 0) =>
@@ -158,11 +160,12 @@ describe("org access reconcile consumer", () => {
});
test("an org membership removal also rechecks the org's sub-orgs", async () => {
- const { consumer, deps } = build({ childOrgs: [SUB_ORG_ID] });
+ const { consumer, deps, primary } = build({ childOrgs: [SUB_ORG_ID] });
await consumer.handle([userRemovedFromOrg()]);
- expect(deps.orgDAL.find).toHaveBeenCalledWith({ rootOrgId: ORG_ID });
+ expect(deps.orgDAL.find).toHaveBeenCalledWith({ rootOrgId: ORG_ID }, { tx: primary });
+ expect(deps.orgDAL.findById).toHaveBeenCalledWith(ORG_ID, primary);
expect(deps.orgDAL.findActorsWithOrgAccess).toHaveBeenCalledTimes(2);
});
});
diff --git a/backend/src/services/org/org-access-reconcile-consumer.ts b/backend/src/services/org/org-access-reconcile-consumer.ts
index e394dcc67b..4053ac7854 100644
--- a/backend/src/services/org/org-access-reconcile-consumer.ts
+++ b/backend/src/services/org/org-access-reconcile-consumer.ts
@@ -38,7 +38,7 @@ const RECONCILE_STATEMENT_TIMEOUT_MS = 30_000;
type TOrgAccessReconcileConsumerDep = {
orgDAL: Pick<
TOrgDALFactory,
- "findById" | "find" | "findActorsWithOrgAccess" | "lockActorsForOrgAccess" | "transaction"
+ "findById" | "find" | "findActorsWithOrgAccess" | "lockActorsForOrgAccess" | "transaction" | "primaryNode"
>;
projectAccessRevokeService: Pick<TProjectAccessRevokeServiceFactory, "revokeActorsInOrgs">;
auditLogService: Pick<TAuditLogServiceFactory, "createAuditLog">;
@@ -92,7 +92,7 @@ export const orgAccessReconcileConsumerFactory = ({
const { orgId, ...actor } = OrgMembershipRemovedPayloadSchema.parse(event.payload);
const reason = ORG_ACCESS_REMOVAL_CAUSE_BY_EVENT[event.eventType];
return async () => {
- const childOrgs = await orgDAL.find({ rootOrgId: orgId });
+ const childOrgs = await orgDAL.find({ rootOrgId: orgId }, { tx: orgDAL.primaryNode() });
return { orgIds: [orgId, ...childOrgs.map((org) => org.id)], actors: [actor], reason };
};
}
@@ -115,9 +115,10 @@ export const orgAccessReconcileConsumerFactory = ({
});
// 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.
+ // batch after commit and only when rows went, so replays are no-ops. The org and sub-org reads go to the
+ // primary: a row the replica hasn't seen yet would otherwise mark the event delivered with nothing done.
const $reconcileOrg = async (orgId: string, scope: TReconcileScope) => {
- const org = await orgDAL.findById(orgId);
+ const org = await orgDAL.findById(orgId, orgDAL.primaryNode());
if (!org) return;
for await (const actors of chunkArray(scope.actors, ACTORS_PER_RECONCILE_TX)) {
diff --git a/backend/src/services/org/org-dal.ts b/backend/src/services/org/org-dal.ts
index c6aedde288..21b3d04d15 100644
--- a/backend/src/services/org/org-dal.ts
+++ b/backend/src/services/org/org-dal.ts
@@ -1405,6 +1405,7 @@ export const orgDALFactory = (db: TDbClient) => {
deleteMembershipsById,
updateMembership,
findIdentityOrganization,
- findRootOrgDetails
+ findRootOrgDetails,
+ primaryNode: () => db.primaryNode()
});
};