FORGE-179: agent syncSecrets withholds the DB-routing keys (agent 0.1.110) #1259

Merged
gmackie merged 1 commit from FORGE-179-agent-secret-denylist into main 2026-11-22 22:10:09 +00:00
Owner

Issue: FORGE-179, https://tasks.gmac.io/gmacko/issue/FORGE-179

Problem

When a Cloudflare Worker target has syncSecrets: true, the node agent uploaded every stage secret that its syncSecretsInclude/syncSecretsExclude allowed, DATABASE_URL included (agent/cmd/agent/worker_secret_filter.go filterWorkerSecrets, called from cloudflare_worker.go). A Worker resolves its database from DATABASE_URL before its HYPERDRIVE binding, so a synced direct URL points the Worker at a Tailscale host the edge can't reach. That is the 2026-08-30 outage (PR #541): forgegraf.com's DB-backed routes went from 200 to 500. forge secret sync already skipped these keys (PR #1245, 3 skipped), but the agent path did not. Enabling syncSecrets on the one-box target would have repeated the outage.

Inventory taken on 2026-11-22 (names only): 7 syncSecrets targets upload a DATABASE_URL* on every deploy today. They are driftport, festigram, test-dojo, controlsfoundry (production and beta), creator and habit-app production. No target's syncSecretsInclude names a withheld key.

Change

  • One definition: agent/internal/workersecrets with an embedded keys.json. It covers the keys no Worker may receive (DATABASE_URL, DATABASE_URL_LOCAL, DATABASE_OWNER_PASSWORD), the production-only keys, and the shared WithheldReason(key, stage). forge secret sync, forge secret import and the agent's filterWorkerSecrets all read it, and their private copies are removed. A test fails if another Go file spells out the list again.
  • Agent: the shared rule applies before the include/exclude lists. syncSecretsInclude can't opt back in. A withheld key that the include list names stays withheld, and the agent log and deploy journal get a WARNING that names the key and the outage. Keys already on a Worker are left alone, because sync never deletes.
  • Guard (server): workerSecretFilterError refuses a target config whose syncSecretsInclude names a forbidden key. This covers config apply, target add and target update. A vitest keeps WORKER_FORBIDDEN_SECRET_KEYS equal to keys.json.
  • Agent version 0.1.110 (the next free version) and CHANGELOG entries.
  • syncSecrets is not enabled on any target.

Acceptance criteria

  • A syncSecrets target without an allowlist no longer receives DATABASE_URL* on deploy, and the journal names those keys as withheld. Tests: TestSyncSecretsOnOneBoxNeverDeliversDatabaseURL and TestSyncSecretsWithholdsProductionOnlyKeysOffOtherStages.
  • Both paths use the shared list. Tests: TestAgentAndCLIAgreeOnEveryKey, TestSecretSyncUsesTheSharedWithholdList, TestNoSecondCopyOfTheList, and the TS parity test.
  • The guard refuses or warns, naming the key and the outage. Tests: TestSyncSecretsIncludeCannotOptInToAWithheldKey, plus the TS "refuses a target config…" test.
  • Ships in agent 0.1.110, verified on a real deploy. The ForgeGraph production deploy still shows Synced N secrets with the same 3 skipped.

Checks run locally

go vet ./... and go test ./... in agent/ pass. tsc --noEmit passes for packages/api, and so does traffic-canary-secrets.test.ts (37 tests). TestRunReportedDeploymentCancelsAnAbortedDeploysRunningStep is timing-flaky on a loaded Mac and fails on unmodified main too.

🤖 Generated with Claude Code

Issue: FORGE-179, https://tasks.gmac.io/gmacko/issue/FORGE-179 ## Problem When a Cloudflare Worker target has `syncSecrets: true`, the node agent uploaded every stage secret that its `syncSecretsInclude`/`syncSecretsExclude` allowed, `DATABASE_URL` included (`agent/cmd/agent/worker_secret_filter.go` `filterWorkerSecrets`, called from `cloudflare_worker.go`). A Worker resolves its database from `DATABASE_URL` before its `HYPERDRIVE` binding, so a synced direct URL points the Worker at a Tailscale host the edge can't reach. That is the 2026-08-30 outage (PR #541): forgegraf.com's DB-backed routes went from 200 to 500. `forge secret sync` already skipped these keys (PR #1245, `3 skipped`), but the agent path did not. Enabling `syncSecrets` on the one-box target would have repeated the outage. Inventory taken on 2026-11-22 (names only): 7 `syncSecrets` targets upload a `DATABASE_URL*` on every deploy today. They are driftport, festigram, test-dojo, controlsfoundry (production and beta), creator and habit-app production. No target's `syncSecretsInclude` names a withheld key. ## Change - **One definition:** `agent/internal/workersecrets` with an embedded `keys.json`. It covers the keys no Worker may receive (`DATABASE_URL`, `DATABASE_URL_LOCAL`, `DATABASE_OWNER_PASSWORD`), the production-only keys, and the shared `WithheldReason(key, stage)`. `forge secret sync`, `forge secret import` and the agent's `filterWorkerSecrets` all read it, and their private copies are removed. A test fails if another Go file spells out the list again. - **Agent:** the shared rule applies before the include/exclude lists. `syncSecretsInclude` can't opt back in. A withheld key that the include list names stays withheld, and the agent log and deploy journal get a `WARNING` that names the key and the outage. Keys already on a Worker are left alone, because sync never deletes. - **Guard (server):** `workerSecretFilterError` refuses a target config whose `syncSecretsInclude` names a forbidden key. This covers config apply, target add and target update. A vitest keeps `WORKER_FORBIDDEN_SECRET_KEYS` equal to `keys.json`. - Agent version 0.1.110 (the next free version) and CHANGELOG entries. - `syncSecrets` is not enabled on any target. ## Acceptance criteria - A `syncSecrets` target without an allowlist no longer receives `DATABASE_URL*` on deploy, and the journal names those keys as withheld. Tests: `TestSyncSecretsOnOneBoxNeverDeliversDatabaseURL` and `TestSyncSecretsWithholdsProductionOnlyKeysOffOtherStages`. - Both paths use the shared list. Tests: `TestAgentAndCLIAgreeOnEveryKey`, `TestSecretSyncUsesTheSharedWithholdList`, `TestNoSecondCopyOfTheList`, and the TS parity test. - The guard refuses or warns, naming the key and the outage. Tests: `TestSyncSecretsIncludeCannotOptInToAWithheldKey`, plus the TS "refuses a target config…" test. - Ships in agent 0.1.110, verified on a real deploy. The ForgeGraph production deploy still shows `Synced N secrets` with the same 3 skipped. ## Checks run locally `go vet ./...` and `go test ./...` in `agent/` pass. `tsc --noEmit` passes for packages/api, and so does `traffic-canary-secrets.test.ts` (37 tests). `TestRunReportedDeploymentCancelsAnAbortedDeploysRunningStep` is timing-flaky on a loaded Mac and fails on unmodified main too. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
FORGE-179: agent syncSecrets withholds the DB-routing keys (agent 0.1.110)
Some checks failed
Preview / cleanup (pull_request) Has been skipped
CI / superseded (pull_request) Successful in 51s
CI / gitleaks (pull_request) Successful in 1m43s
Preview / deploy (pull_request) Has been skipped
CI / database-d1 (pull_request) Has been skipped
CI / storybook (pull_request) Successful in 4m9s
CI / unit-api (pull_request) Successful in 2m55s
CI / go (pull_request) Successful in 2m2s
CI / checks (pull_request) Successful in 5m32s
CI / web-build (pull_request) Successful in 6m44s
CI / unit-web (pull_request) Successful in 7m22s
CI / database (pull_request) Successful in 8m26s
forgegraph/ci CI passed
CI / ci (pull_request) Successful in 1m54s
Preview / e2e (pull_request) Has been cancelled
Preview / release (pull_request) Has been cancelled
bc9da5087e
The node agent's per-target syncSecrets uploaded every stage secret its
syncSecretsInclude/Exclude allowed, DATABASE_URL included. A Worker resolves
its database from DATABASE_URL ahead of its HYPERDRIVE binding, so a synced
direct URL points it at a Tailscale host the edge cannot reach: the
2026-08-30 outage of forgegraf.com. `forge secret sync` already withheld
these keys (PR #1245); the agent path did not.

- agent/internal/workersecrets: the one definition (keys.json, embedded) of
  the keys no Worker may receive (DATABASE_URL, DATABASE_URL_LOCAL,
  DATABASE_OWNER_PASSWORD) and the production-only keys, with the shared
  WithheldReason rule. `forge secret sync`, `forge secret import` and the
  agent's filterWorkerSecrets all read it; their private copies are gone. A
  test fails if another Go file spells out the list again.
- filterWorkerSecrets applies the shared rule before the target's
  include/exclude lists. syncSecretsInclude cannot opt back in: a listed
  withheld key is withheld and reported as a WARNING naming the key and the
  outage, in the agent log and the deploy journal.
- Server: workerSecretFilterError refuses a target config whose
  syncSecretsInclude names a forbidden key (config apply, target add and
  update). A vitest keeps WORKER_FORBIDDEN_SECRET_KEYS equal to keys.json.
- Agent version 0.1.110 and CHANGELOG.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gmackie force-pushed FORGE-179-agent-secret-denylist from bc9da5087e
Some checks failed
Preview / cleanup (pull_request) Has been skipped
CI / superseded (pull_request) Successful in 51s
CI / gitleaks (pull_request) Successful in 1m43s
Preview / deploy (pull_request) Has been skipped
CI / database-d1 (pull_request) Has been skipped
CI / storybook (pull_request) Successful in 4m9s
CI / unit-api (pull_request) Successful in 2m55s
CI / go (pull_request) Successful in 2m2s
CI / checks (pull_request) Successful in 5m32s
CI / web-build (pull_request) Successful in 6m44s
CI / unit-web (pull_request) Successful in 7m22s
CI / database (pull_request) Successful in 8m26s
forgegraph/ci CI passed
CI / ci (pull_request) Successful in 1m54s
Preview / e2e (pull_request) Has been cancelled
Preview / release (pull_request) Has been cancelled
to 67c05c539b
All checks were successful
CI / superseded (pull_request) Successful in 3m9s
CI / gitleaks (pull_request) Successful in 39s
Registry deps hash / pnpm-deps-hash (pull_request) Successful in 10m49s
CI / storybook (pull_request) Successful in 2m54s
CI / unit-api (pull_request) Successful in 37s
CI / database-d1 (pull_request) Has been skipped
CI / checks (pull_request) Successful in 2m10s
CI / go (pull_request) Successful in 3m5s
CI / web-build (pull_request) Successful in 5m56s
CI / unit-web (pull_request) Successful in 5m6s
CI / database (pull_request) Successful in 4m47s
forgegraph/ci CI passed
CI / ci (pull_request) Successful in 1m28s
Preview / cleanup (pull_request) Has been skipped
Preview / deploy (pull_request) Has been skipped
Preview / e2e (pull_request) Has been skipped
Preview / release (pull_request) Has been skipped
2026-11-22 20:58:32 +00:00
Compare
Sign in to join this conversation.
No description provided.