Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions docs/cloudflare-tail.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ Cloudflare Tail is an authenticated Factorize Job trigger for native uncaught Wo

## Configure the job and relay

1. Create a Job, add a **Cloudflare Tail** trigger, and save it. Copy its relay destination and signing secret.
2. From the repository root, run `npm ci` and set `FACTORIZE_TAIL_DESTINATION` as a Wrangler variable in `packages/tail-relay/wrangler.jsonc`.
3. Authenticate Wrangler to the producer Workers' Cloudflare account, then run `npm exec --workspace=factorize-tail-relay -- wrangler secret put FACTORIZE_TAIL_SECRET` and `npm run deploy:tail-relay`. Keep the relay name `factorize-tail-relay`; Factorize excludes its own relay traces to prevent loops.
4. Add the relay to every producer Worker. One relay can consume multiple producers and forwards each event with its `scriptName`:
1. In **Settings → Integrations**, install Cloudflare Tail. Give the installation a name and either paste a signing secret or generate one. Generated secrets are returned only once, so copy it during setup.
2. Create a Job, add a **Cloudflare Tail** trigger, select the installation, and save it. Copy the Job's relay destination.
3. From the repository root, run `npm ci` and set `FACTORIZE_TAIL_DESTINATION` as a Wrangler variable in `packages/tail-relay/wrangler.jsonc`.
4. Authenticate Wrangler to the producer Workers' Cloudflare account, then run `npm exec --workspace=factorize-tail-relay -- wrangler secret put FACTORIZE_TAIL_SECRET` and `npm run deploy:tail-relay`. Use the selected installation's secret. Keep the relay name `factorize-tail-relay`; Factorize excludes its own relay traces to prevent loops.
5. Add the relay to every producer Worker. One relay can consume multiple producers and forwards each event with its `scriptName`:

```jsonc
{
Expand All @@ -17,7 +18,7 @@ Cloudflare Tail is an authenticated Factorize Job trigger for native uncaught Wo

Deploy each producer after changing `tail_consumers`.

MCP clients create or update a Job with a `cloudflareTail` webhook trigger and an execution target returned by `list_execution_targets`. Protected REST and MCP never return the signing secret. After rotating it, update `FACTORIZE_TAIL_SECRET` in Wrangler and redeploy the relay.
Jobs refer to the installation by `integrationId`; secrets are encrypted and are never included in list, status, Job, REST, or MCP responses. Rotating an installation updates every Job that selects it after the relay secret is updated and redeployed. Factorize refuses to disconnect installations still referenced by Jobs, so a missing installation can never turn into unsigned ingestion.

The relay redacts sensitive key names (authorization, cookies, tokens, secrets, credentials, prompts, and bodies), truncates oversized structures, signs the exact body with HMAC-SHA256, and aborts delivery after three seconds. Factorize sanitizes again before activity or agent context, rejects deliveries older than 60 seconds, deduplicates delivery IDs, and rate-limits repeated event fingerprints.

Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/flow-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const webhookCommonSchema = z.object({ handlerCode: z.string().max(16_384).optio
export const webhookTriggerConfigSchema = z.discriminatedUnion("provider", [
webhookCommonSchema.extend({ provider: z.literal("linear"), projectId: z.string().min(1), matchRules: z.array(matchRuleSchema).min(1) }).strict(),
webhookCommonSchema.extend({ provider: z.literal("github"), installationId: z.number().int().positive(), repositoryId: z.number().int().positive(), event: z.string().min(1).default("pull_request"), action: z.string().min(1).default("dequeued") }).strict(),
webhookCommonSchema.extend({ provider: z.literal("cloudflareTail"), signingSecret: z.string().min(16).optional(), handlerCode: z.string().max(16_384).optional() }).strict(),
webhookCommonSchema.extend({ provider: z.literal("cloudflareTail"), integrationId: z.string().min(1) }).strict(),
]);
export const triggerSchema = z.discriminatedUnion("kind", [
z.object({ id: z.string().min(1).optional(), slug: z.string().regex(/^trigger-[1-9][0-9]*$/).optional(), kind: z.literal("manual"), enabled: z.boolean().default(true), config: z.object({}).strict().default({}) }).strict(),
Expand Down
1 change: 1 addition & 0 deletions packages/app/src/flow-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class ApiService {
}

listExeConnections() { return this.call("flows:read", "/connections/status").then((value: any) => value.exeConnections ?? []); }
listTailIntegrations() { return this.call("flows:read", "/connections/cloudflare-tail"); }
listRuns(query: URLSearchParams) { return this.call("runs:read", `/v1/runs?${query}`); }
getRun(runId: string) { return this.call("runs:read", `/v1/runs/${encodeURIComponent(runId)}`); }
stopRun(runId: string) { return this.call("runs:write", `/v1/runs/${encodeURIComponent(runId)}/stop`, { method: "POST" }); }
Expand Down
20 changes: 20 additions & 0 deletions packages/app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,26 @@ app.get("/api/connections/status", async (c) => {
const session = await owner(c); if (!session) return c.json({ error: "Unauthorized" }, 401);
return tenant(c, session.tenantId).fetch("https://tenant/connections/status");
});
app.get("/api/connections/cloudflare-tail", async (c) => {
const session = await owner(c); if (!session) return c.json({ error: "Unauthorized" }, 401);
return tenant(c, session.tenantId).fetch("https://tenant/connections/cloudflare-tail");
});
app.post("/api/connections/cloudflare-tail", async (c) => {
const session = await owner(c); if (!session) return c.json({ error: "Unauthorized" }, 401);
return tenant(c, session.tenantId).fetch("https://tenant/connections/cloudflare-tail", { method: "POST", headers: { "Content-Type": "application/json" }, body: await c.req.text() });
});
app.put("/api/connections/cloudflare-tail/:id", async (c) => {
const session = await owner(c); if (!session) return c.json({ error: "Unauthorized" }, 401);
return tenant(c, session.tenantId).fetch(`https://tenant/connections/cloudflare-tail/${encodeURIComponent(c.req.param("id"))}`, { method: "PUT", headers: { "Content-Type": "application/json" }, body: await c.req.text() });
});
app.post("/api/connections/cloudflare-tail/:id/test", async (c) => {
const session = await owner(c); if (!session) return c.json({ error: "Unauthorized" }, 401);
return tenant(c, session.tenantId).fetch(`https://tenant/connections/cloudflare-tail/${encodeURIComponent(c.req.param("id"))}/test`, { method: "POST" });
});
app.delete("/api/connections/cloudflare-tail/:id", async (c) => {
const session = await owner(c); if (!session) return c.json({ error: "Unauthorized" }, 401);
return tenant(c, session.tenantId).fetch(`https://tenant/connections/cloudflare-tail/${encodeURIComponent(c.req.param("id"))}`, { method: "DELETE" });
});
app.get("/api/linear/projects", async (c) => {
const session = await owner(c); if (!session) return c.json({ error: "Unauthorized" }, 401);
return tenant(c, session.tenantId).fetch("https://tenant/linear/projects");
Expand Down
2 changes: 2 additions & 0 deletions packages/app/src/protected-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export async function protectedApiFetch(request: Request, env: Env, auth: OAuthP
if (!path.startsWith("/api/v1")) return Response.json({ error: { code: "not_found", message: "Not found" } }, { status: 404 });
if (request.method === "GET" && path === "/api/v1/exe-connections") return Response.json(await service.listExeConnections());
if (request.method === "GET" && path === "/api/v1/execution-targets") return Response.json(await service.listExecutionTargets());
if (request.method === "GET" && path === "/api/v1/integrations/cloudflare-tail") return Response.json(await service.listTailIntegrations());
if (request.method === "GET" && path === "/api/v1/jobs") return Response.json(await service.listJobs());
if (request.method === "POST" && path === "/api/v1/jobs") return Response.json(await service.createJob(jobInputSchema.parse(await request.json())), { status: 201 });
if (request.method === "POST" && path === "/api/v1/job-handlers/test") return Response.json(await service.testJobHandler(jobHandlerTestSchema.parse(await request.json())));
Expand Down Expand Up @@ -83,6 +84,7 @@ async function mcp(request: Request, service: ApiService, env: Env, ctx: Executi
tool("list_job_webhook_activity", "List matching, rejected, duplicate, and accepted webhook activity for a job", z.object({ jobId: z.string().min(1), limit: z.number().int().min(1).max(100).default(50) }), ({ jobId, limit }: any) => service.listJobEvents(jobId, limit));
tool("test_job_webhook_handler", "Test an isolated synchronous Job webhook handler without creating a run. Returns the decision and never accepts credentials.", jobHandlerTestSchema, (input: any) => service.testJobHandler(input));
tool("list_execution_targets", "List non-secret execution target metadata and capabilities", z.object({}), () => service.listExecutionTargets());
tool("list_cloudflare_tail_integrations", "List installed Cloudflare Tail integrations and reference counts. Signing secrets are never returned.", z.object({}), () => service.listTailIntegrations());
const transport = new WebStandardStreamableHTTPServerTransport({ sessionIdGenerator: undefined });
await server.connect(transport);
const appHostname = new URL(env.APP_ORIGIN).hostname;
Expand Down
Loading