Store CI secrets without a host and header, and swap bound secrets in request bodies #252
Problem#
A CI secret is a stored value, but the forge treats every secret as one a job uses: it demands a host and a header for each. A secret that is only stored, read back or synced to a Cloudflare Worker (a DATABASE_URL, a signing key the Worker uses) needs an invented host and header.
A job also cannot send a secret in a request body, which an OAuth client-credentials grant and some JSON APIs need.
An earlier version of this issue proposed "exposed" secrets, whose real value enters the job. That is dropped: it breaks the rule that no secret value enters a CI container, and it does not make Postgres, SMTP or SSH work, because a job reaches only allowlisted https hosts on port 443. It can come back as its own issue when someone needs in-container signing or a value that a build inlines.
Design#
A secret is a name and a value for each CI environment. The host and header are an optional binding, needed only for a job or an agent to use the secret.
Unbound secrets
- A secret may have no host and no header. It gets no placeholder, so no job and no agent can send it anywhere.
- A job that declares an unbound secret with a value runs, with no variable for it. Declaring it is what lets
syncWorkerSecrets()sync it. syncWorkerSecrets()syncs unbound secrets too.- An unbound value may hold line breaks (a PEM key). A value with a line break is never put in a header.
- Binding an unbound secret later counts as gaining a host: its values in write-only environments are deleted.
- A binding can be removed again.
Body swap, opt-in for each secret
- A bound secret gets a
bodysetting, off by default, set by an admin. - With it on, the outbound handler swaps the placeholder in a JSON or form-encoded request body to a bound host, encoded for the body type. Only bodies with a known length of at most 1 MiB.
- It is opt-in because servers store bodies: a job could post a placeholder in content that the host publishes. Turn it on only for hosts such as token endpoints.
- Turning it on deletes the values in write-only environments, as gaining a host does.
- A secret may be bound for bodies only, with no header.
- A bound secret gets a
Not in scope#
- Exposed secrets (the real value in the job).
- A per-secret switch that keeps a secret out of the Worker sync. A workflow already picks what it syncs with the job's
secretsandnames.
Done when#
- REST, MCP,
srcand the web set, list and clear the binding and thebodysetting (parity tests pass). - Tests cover: an unbound secret gets no placeholder and does not skip a job, the sync includes it, binding drops write-only values, the body swap for JSON and form bodies, no swap without the setting, to another host or in another body type, and response masking of a body-swapped value.
docs/ci/trust-and-secrets.md, the CI skill, the source skill and the landing page say what the code does. The rule "no secret value enters a CI container" stays as it is.
tombeckenham changed the title
Sign in to join this conversation.