Skip to content

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

move orgId and projectId out of the top level

Thiago Araujo da Silvaaad20acf8796
diff --git a/backend/CLAUDE.md b/backend/CLAUDE.md
index 3942de91f7..0c29c77b9f 100644
--- a/backend/CLAUDE.md
+++ b/backend/CLAUDE.md
@@ -710,9 +710,7 @@ await someDAL.transaction(async (tx) => {
await eventEmitter.emit(
{
eventType: "approval.workflow.request_opened",
- orgId,
- projectId,
- payload: { resourceType: "approval.workflow", resourceId: policyId, targetIds: [request.id] }
+ payload: { orgId, projectId, resourceType: "approval.workflow", resourceId: policyId, targetIds: [request.id] }
},
tx
);
@@ -744,10 +742,11 @@ await someDAL.transaction(async (tx) => {
result can't clear the new owner's lock or drop its outcome. `commitResults` returns how many rows it
settled and `drain` logs a short settle: that count is the only signal that a batch went out twice, since
the fence protects the bookkeeping but delivery stays at-least-once.
-- **The envelope carries only what the outbox queries on.** `consumer`, `eventType`, the retry and lock
- columns, and the tenant pair (`orgId`, `projectId`) handed to every consumer. Which resource an event
- is about lives in `payload` under a shape the consumer's `payloadSchema` declares; the outbox never
- groups, filters or indexes on it.
+- **The envelope carries only what the outbox queries on.** `consumer`, `eventType`, and the retry and
+ lock columns. Which tenant and resource an event concerns lives in `payload` under a shape the
+ consumer's `payloadSchema` declares, and that schema is where it is validated (the alert consumer
+ requires `orgId` as a UUID). The outbox never groups, filters or indexes on any of it, so don't add a
+ tenant or resource column back for a query nothing runs.
- **Discovery only looks at consumers registered in this process.** A row for any other name has nowhere
to go here. It waits and shows up on the oldest-pending gauge instead.
- **Don't let one event's failure escape `handle`.** The outbox retries the whole batch when `handle`
@@ -774,7 +773,8 @@ new consumer gets them for free.
**Adding an event-triggered alert** needs no outbox code: declare the event with
`triggerType: AlertTriggerType.Event`, implement `findTargetsByIds`, and emit with
-`payload: { resourceType, resourceId, targetIds, ...facts }` where `resourceType` is the provider's. A
+`payload: { orgId, projectId, resourceType, resourceId, targetIds, ...facts }` where `resourceType` is the
+provider's. A
`resourceType` that doesn't declare the `eventType` fails the row terminally with both named, so a bad
emit site shows up in the logs on its first event.
diff --git a/backend/e2e-test/event-outbox.spec.ts b/backend/e2e-test/event-outbox.spec.ts
index 884fb8701d..bd84531e62 100644
--- a/backend/e2e-test/event-outbox.spec.ts
+++ b/backend/e2e-test/event-outbox.spec.ts
@@ -22,8 +22,7 @@ const KEY = { consumer: CONSUMER };
const makeRow = (overrides?: Partial<TOutboxInsertRow>): TOutboxInsertRow => ({
consumer: CONSUMER,
eventType: "e2e.resource.happened",
- orgId: ORG_ID,
- payload: { resourceType: "e2e.resource", resourceId: "res-1", targetIds: ["t-1"] },
+ payload: { orgId: ORG_ID, resourceType: "e2e.resource", resourceId: "res-1", targetIds: ["t-1"] },
occurredAt: new Date(),
...overrides
});
diff --git a/backend/src/db/migrations/20260908000000_event-outbox.ts b/backend/src/db/migrations/20260908000000_event-outbox.ts
index 5783f1d9a6..e1fb858103 100644
--- a/backend/src/db/migrations/20260908000000_event-outbox.ts
+++ b/backend/src/db/migrations/20260908000000_event-outbox.ts
@@ -9,8 +9,6 @@ export async function up(knex: Knex): Promise<void> {
t.bigIncrements("id").primary();
t.string("consumer").notNullable();
t.string("eventType").notNullable();
- t.uuid("orgId").notNullable();
- t.string("projectId");
t.jsonb("payload").notNullable();
t.string("idempotencyKey");
t.timestamp("occurredAt", { useTz: true }).notNullable().defaultTo(knex.fn.now());
diff --git a/backend/src/db/schemas/event-outbox.ts b/backend/src/db/schemas/event-outbox.ts
index 3aa420d4cd..66bacf9a4b 100644
--- a/backend/src/db/schemas/event-outbox.ts
+++ b/backend/src/db/schemas/event-outbox.ts
@@ -11,8 +11,6 @@ export const EventOutboxSchema = z.object({
id: z.coerce.number(),
consumer: z.string(),
eventType: z.string(),
- orgId: z.string().uuid(),
- projectId: z.string().nullable().optional(),
payload: z.unknown(),
idempotencyKey: z.string().nullable().optional(),
occurredAt: z.date(),
diff --git a/backend/src/services/alert/alert-event-consumer.test.ts b/backend/src/services/alert/alert-event-consumer.test.ts
index bc86ee3fbb..21b100bc9b 100644
--- a/backend/src/services/alert/alert-event-consumer.test.ts
+++ b/backend/src/services/alert/alert-event-consumer.test.ts
@@ -15,6 +15,8 @@ const EVENT_TYPE = "approval.workflow.request_opened";
const makeAlert = (id: string) => ({ id, resourceType: "approval.workflow", orgId: ORG_ID }) as never;
const makePayload = (overrides?: Record<string, unknown>) => ({
+ orgId: ORG_ID,
+ projectId: null,
resourceType: "approval.workflow",
resourceId: "policy-1",
targetIds: ["req-1"],
@@ -25,8 +27,6 @@ const makeEvent = (overrides?: Partial<TEvent>): TEvent =>
({
id: 1,
eventType: EVENT_TYPE,
- orgId: ORG_ID,
- projectId: null,
payload: makePayload(),
occurredAt: new Date(),
progress: null,
diff --git a/backend/src/services/alert/alert-event-consumer.ts b/backend/src/services/alert/alert-event-consumer.ts
index 74ced93733..8b3ee344c4 100644
--- a/backend/src/services/alert/alert-event-consumer.ts
+++ b/backend/src/services/alert/alert-event-consumer.ts
@@ -15,9 +15,9 @@ import { AlertTriggerType, MAX_TARGET_IDS_PER_EVENT } from "./alert-types";
export const ALERT_EVENT_CONSUMER = "alert";
-// Emitters name the resource and its targets by id and the provider rehydrates them at delivery.
-// Keeping the payload to ids is what lets one consumer serve every provider.
export const AlertEventPayloadSchema = z.object({
+ orgId: z.string().uuid(),
+ projectId: z.string().trim().min(1).max(255).nullish(),
resourceType: z.string().trim().min(1).max(255),
resourceId: z.string().trim().min(1).max(255),
targetIds: z.array(z.string().trim().min(1).max(255)).min(1).max(MAX_TARGET_IDS_PER_EVENT)
@@ -64,7 +64,7 @@ export const alertEventConsumerFactory = ({
error: `Unreadable alert event payload: ${payload.error.issues.map((issue) => issue.message).join(", ")}`
};
}
- const { resourceType, resourceId, targetIds } = payload.data;
+ const { orgId, projectId, resourceType, resourceId, targetIds } = payload.data;
if (!$isDeclaredEvent(event.eventType, resourceType)) {
return {
@@ -78,8 +78,8 @@ export const alertEventConsumerFactory = ({
const delivered = new Set(progress.success ? progress.data.deliveredChannelIds : []);
const alerts = await findAlerts({
- orgId: event.orgId,
- projectId: event.projectId,
+ orgId,
+ projectId,
resourceType,
resourceId,
eventType: event.eventType
diff --git a/backend/src/services/event-outbox/event-outbox-dal.test.ts b/backend/src/services/event-outbox/event-outbox-dal.test.ts
index ae7c460e12..21ab6b6228 100644
--- a/backend/src/services/event-outbox/event-outbox-dal.test.ts
+++ b/backend/src/services/event-outbox/event-outbox-dal.test.ts
@@ -121,8 +121,7 @@ describe("event outbox dal", () => {
{
consumer: "alert",
eventType: "approval.workflow.request_opened",
- orgId: "org-1",
- payload: { resourceType: "approval.workflow", resourceId: "policy-1", targetIds: ["req-1"] },
+ payload: { orgId: "org-1", resourceType: "approval.workflow", resourceId: "policy-1", targetIds: ["req-1"] },
occurredAt: new Date()
}
],
diff --git a/backend/src/services/event-outbox/event-outbox-dal.ts b/backend/src/services/event-outbox/event-outbox-dal.ts
index 62106bcd5a..8c7dc8f79d 100644
--- a/backend/src/services/event-outbox/event-outbox-dal.ts
+++ b/backend/src/services/event-outbox/event-outbox-dal.ts
@@ -18,8 +18,6 @@ export type TOutboxClaim = {
export type TOutboxInsertRow = {
consumer: string;
eventType: string;
- orgId: string;
- projectId?: string | null;
payload: unknown;
idempotencyKey?: string | null;
occurredAt: Date;
@@ -34,7 +32,6 @@ export const eventOutboxDALFactory = (db: TDbClient) => {
rows.map((row) => ({
...row,
payload: JSON.stringify(row.payload),
- projectId: row.projectId ?? null,
idempotencyKey: row.idempotencyKey ?? null
}))
)
diff --git a/backend/src/services/event-outbox/event-outbox-service.test.ts b/backend/src/services/event-outbox/event-outbox-service.test.ts
index cf11e32204..c0bc2079d5 100644
--- a/backend/src/services/event-outbox/event-outbox-service.test.ts
+++ b/backend/src/services/event-outbox/event-outbox-service.test.ts
@@ -29,10 +29,17 @@ vi.mock("@app/lib/telemetry/metrics", () => ({
const ORG_ID = "11111111-1111-1111-1111-111111111111";
+const makePayload = (overrides?: Record<string, unknown>) => ({
+ orgId: ORG_ID,
+ resourceType: "approval.workflow",
+ resourceId: "policy-1",
+ targetIds: ["req-1"],
+ ...overrides
+});
+
const makeEvent = (overrides?: Partial<TEventInput>): TEventInput => ({
eventType: "approval.workflow.request_opened",
- orgId: ORG_ID,
- payload: { resourceType: "approval.workflow", resourceId: "policy-1", targetIds: ["req-1"] },
+ payload: makePayload(),
...overrides
});
@@ -103,7 +110,7 @@ describe("event outbox emit", () => {
test("throws when the payload does not match the consumer's schema", async () => {
const { service, inserted } = buildService([makeConsumer()]);
- await expect(service.emit(makeEvent({ payload: { targetIds: [] } }), TX)).rejects.toThrow(
+ await expect(service.emit(makeEvent({ payload: makePayload({ targetIds: [] }) }), TX)).rejects.toThrow(
"the 'alert' consumer cannot accept"
);
expect(inserted).toHaveLength(0);
@@ -123,7 +130,7 @@ describe("event outbox emit", () => {
test("throws on a malformed event envelope", async () => {
const { service } = buildService([makeConsumer()]);
- await expect(service.emit(makeEvent({ orgId: "not-a-uuid" }), TX)).rejects.toThrow("Invalid outbox event");
+ await expect(service.emit(makeEvent({ eventType: "Not A Key" }), TX)).rejects.toThrow("Invalid outbox event");
});
// Swallowing it would hand the caller a poisoned transaction instead of the real error.
@@ -149,9 +156,7 @@ describe("event outbox drain", () => {
id: 1,
consumer: "alert",
eventType: "approval.workflow.request_opened",
- orgId: ORG_ID,
- projectId: null,
- payload: { resourceType: "approval.workflow", resourceId: "policy-1", targetIds: ["req-1"] },
+ payload: makePayload(),
idempotencyKey: null,
occurredAt: new Date(),
status: EventOutboxStatus.Processing,
diff --git a/backend/src/services/event-outbox/event-outbox-service.ts b/backend/src/services/event-outbox/event-outbox-service.ts
index 05bb5080fd..a08cf531a6 100644
--- a/backend/src/services/event-outbox/event-outbox-service.ts
+++ b/backend/src/services/event-outbox/event-outbox-service.ts
@@ -110,8 +110,6 @@ export const eventOutboxServiceFactory = ({ eventOutboxDAL, eventOutboxRegistry
return {
consumer: consumer.name,
eventType: validated.eventType,
- orgId: validated.orgId,
- projectId: validated.projectId ?? null,
payload: validated.payload,
idempotencyKey: validated.idempotencyKey ?? null,
occurredAt
diff --git a/backend/src/services/event-outbox/event-outbox-types.ts b/backend/src/services/event-outbox/event-outbox-types.ts
index 76d8271740..0286662e99 100644
--- a/backend/src/services/event-outbox/event-outbox-types.ts
+++ b/backend/src/services/event-outbox/event-outbox-types.ts
@@ -50,8 +50,6 @@ const keySchema = z
export const EventInputSchema = z.object({
eventType: keySchema,
- orgId: z.string().uuid(),
- projectId: z.string().trim().min(1).max(MAX_OUTBOX_KEY_LENGTH).nullish(),
payload: z.record(z.unknown()),
idempotencyKey: z.string().trim().min(1).max(MAX_OUTBOX_KEY_LENGTH).optional(),
occurredAt: z.date().optional()
@@ -64,10 +62,7 @@ export type TEventEmitter = {
};
// What a consumer sees. Lock, attempt, and status columns are the outbox's business, not the consumer's.
-export type TEvent = Pick<
- TEventOutbox,
- "id" | "eventType" | "orgId" | "projectId" | "payload" | "progress" | "occurredAt"
->;
+export type TEvent = Pick<TEventOutbox, "id" | "eventType" | "payload" | "progress" | "occurredAt">;
export enum EventResultStatus {
Delivered = "delivered",
diff --git a/backend/src/services/identity/identity-auth-method-events.ts b/backend/src/services/identity/identity-auth-method-events.ts
index f303ba1794..80197cf784 100644
--- a/backend/src/services/identity/identity-auth-method-events.ts
+++ b/backend/src/services/identity/identity-auth-method-events.ts
@@ -44,9 +44,9 @@ export const emitIdentityAuthMethodChanged = (
eventEmitter.emit(
{
eventType: IDENTITY_AUTH_METHOD_CHANGED_EVENT,
- orgId: membership.scopeOrgId,
- projectId: membership.identity.projectId,
payload: {
+ orgId: membership.scopeOrgId,
+ projectId: membership.identity.projectId,
resourceType: IDENTITY_AUTHENTICATION_RESOURCE_TYPE,
resourceId: membership.identity.id,
targetIds: [membership.identity.id],