Skip to content

Commit 79bda5c

Browse files
1stvampTrigger.dev RepoOps
authored andcommitted
fix(webapp): refuse v2 worker queue subscriptions for unmanaged groups
Unmanaged worker groups can no longer subscribe to v2 worker queues. They consume only their own queues, even if a subscription allowlist names them. Mono-RevId: 8e3a7de9b4fb3057d2000a611e00c7e17021add2
1 parent 535761f commit 79bda5c

4 files changed

Lines changed: 30 additions & 2 deletions

File tree

‎apps/webapp/app/runEngine/concerns/workerQueueDequeue.server.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ containerTest(
5050
const worker = createWorkerQueueConsumer({
5151
workerGroupId: environment.project.defaultWorkerGroupId!,
5252
workerInstanceId: "test-instance",
53+
type: "MANAGED",
5354
masterQueue: "legacy-region",
5455
region: "us-east-1",
5556
workloadType: "CONTAINER" as const,
@@ -164,6 +165,7 @@ function mixedGroup(
164165
worker: createWorkerQueueConsumer({
165166
workerGroupId: environment.project.defaultWorkerGroupId!,
166167
workerInstanceId,
168+
type: "MANAGED",
167169
masterQueue,
168170
region: "us-east-1",
169171
workloadType,

‎apps/webapp/app/runEngine/concerns/workerQueueSubscriptions.server.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const restore: WorkerQueueSubscription = { ...stable, phase: "restore" };
2222
const worker: WorkerQueueConsumerOptions = {
2323
workerGroupId: "group-container",
2424
workerInstanceId: "instance-container",
25+
type: "MANAGED",
2526
masterQueue: "legacy-container-group",
2627
region: "us-east-1",
2728
workloadType: "CONTAINER",
@@ -213,3 +214,24 @@ describe("workerServesQueue", () => {
213214
).toBe(true);
214215
});
215216
});
217+
218+
describe("an UNMANAGED worker group", () => {
219+
const unmanaged = () =>
220+
createWorkerQueueConsumer({ ...worker, type: "UNMANAGED", allowedSubscriptions: [stable] });
221+
222+
// Catches: an allowlist entry letting a project-scoped group consume a shared v2 lane.
223+
it("is refused v2 subscriptions even when its allowlist covers them", () => {
224+
expect(() => resolveWorkerQueueSubscriptions(unmanaged(), [stable])).toThrow(
225+
expect.objectContaining({ status: 403 })
226+
);
227+
});
228+
229+
// Catches: a restore or release from a project-scoped group being accepted on a shared v2 lane.
230+
it("serves only its own legacy queues", () => {
231+
expect(workerServesQueue(unmanaged(), "legacy-container-group")).toBe(true);
232+
expect(workerServesQueue(unmanaged(), "legacy-container-group:scheduled")).toBe(true);
233+
expect(workerServesQueue(unmanaged(), "us-east-1:v2:ondemand:fresh:container:stable")).toBe(
234+
false
235+
);
236+
});
237+
});

‎apps/webapp/app/runEngine/concerns/workerQueueSubscriptions.server.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
type WeightedWorkerQueueSubscription,
88
type WorkerQueueSubscription,
99
} from "@trigger.dev/core/v3/workers";
10-
import type { WorkloadType } from "@trigger.dev/database";
10+
import type { WorkerInstanceGroupType, WorkloadType } from "@trigger.dev/database";
1111
import { z } from "zod";
1212
import { ServiceValidationError } from "~/v3/services/common.server";
1313
import { baseWorkerQueue } from "./workerQueueSplit.server";
@@ -28,6 +28,8 @@ export const WorkerQueueSubscriptionPolicyEnv = z
2828
export type WorkerQueueConsumerOptions = {
2929
workerGroupId: string;
3030
workerInstanceId: string;
31+
/** An UNMANAGED group consumes only its own legacy queues, whatever its allowlist says. */
32+
type: WorkerInstanceGroupType;
3133
masterQueue: string;
3234
region: string | null;
3335
workloadType: WorkloadType;
@@ -94,7 +96,7 @@ export function resolveWorkerQueueSubscriptions(
9496

9597
for (const subscription of subscriptions) {
9698
const key = subscriptionKey(subscription);
97-
if (!worker.allowedQueues.has(key)) {
99+
if (worker.type === "UNMANAGED" || !worker.allowedQueues.has(key)) {
98100
throw new ServiceValidationError(
99101
`Worker group ${worker.workerGroupId} is not authorized to consume ${key}`,
100102
403
@@ -139,6 +141,7 @@ export function workerServesQueue(worker: WorkerQueueConsumer, workerQueue: stri
139141
return false;
140142
}
141143
return (
144+
worker.type !== "UNMANAGED" &&
142145
parsed.version === WORKER_QUEUE_VERSION &&
143146
parsed.region === (worker.region ?? baseWorkerQueue(worker.masterQueue)) &&
144147
worker.allowedQueues.has(subscriptionKey(parsed))

‎apps/webapp/test/workerQueueTemplateFallback.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const lane = (
3939

4040
const worker = (workloadType: "CONTAINER" | "MICROVM") => ({
4141
workerGroupId: "wg_test",
42+
type: "MANAGED" as const,
4243
workloadType,
4344
});
4445

0 commit comments

Comments
 (0)