Secret Management #106
I'd like to see better management of secrets in Source. Production, Staging, and Development Environments - PR environments. Permission levels to allow members to get dev secrets, yet admins / owners only get prod. Ability to make prd secrets write only so that only ci can psh them to production. Sync to worker secrets. Parsing from env, and ability to get as env. Ability to set variables which could be publically viewable. API so that integrations (e.g. Neon) could set secrets for preview branches
What exists today#
- CI secrets in the vault scope
ci:secrets(apps/web/src/server/jobs/secrets.ts): one value per trust level (untrusted,trusted,protected), bound hosts, admin-only writes, values never readable. Jobs gettss_ph_placeholders thatJobOutboundswaps in request headers to bound hosts. - A value set only at
protectedreaches only runs on the default branch, tags and rule-protected branches. - CI variables (
repo-object/ci-variables.ts): plain values, readable by writers, admin-only writes. src secret set -f .envparses env files. No export, no environments, no worker sync, no public variables.
Plan (revised 2026-11-07): environments only#
Source is unreleased, so this drops the old model instead of keeping both. Secrets no longer have untrusted/trusted/protected values. Every secret value belongs to an environment, and the trust level becomes one of an environment's gates.
Stack, bottom to top. Each layer ships REST, MCP and src parity, docs, skill references and tests.
- #107
106-secrets-hardening(base main): masking of secret values echoed in responses, and master key rotation. 106-secret-managementEnvironments (base #107). Merge it as one change, because it replaces the old model.- Environments per repository. New repositories get
production,staging,developmentandpreview. - Each environment has the refs it deploys from (branch patterns,
protectedorpull_request), the lowest trust level a run needs, and its readers:nobody,writeoradmin. - A secret has a value per environment. It is bound to hosts and to one request header name (for example
Authorization), and it is swapped only into that header. - Each environment has its own vault data key, so production values never share a key with development values.
- Variables have a value per environment, and they follow the environment's
readers. - A CI job declares
environment:. A job that declares secrets must declare one. The job gets values only when its ref and trust level pass the environment's gates. A pull request job takes its environment from the base plan. - Values are never written to the job object's storage. The job fetches them once, into memory, when they are first used. The gates are checked again at that moment, against the environment's current settings.
- Environments per repository. New repositories get
106-secrets-read: role-gated read-back (src secret get,src env pull --env developmentwrites a.envfile), public variables, and an audit record of every read. Production is never readable.106-secrets-preview-api: a scoped-token actionsecrets:previewto set and delete preview values for one branch, for integrations such as Neon. A branch value overrides the environment value on that branch, and it is deleted when the branch or its pull request closes.106-secrets-worker-sync: an environment can name a Cloudflare account and Worker script. A protected job callssyncWorkerSecrets(), and the forge sends the values to the Cloudflare API itself.106-secrets-keys-worker: a smallgitflare-keysWorker is the only holder ofVAULT_MASTER_KEY. Its one entrypoint only wraps and unwraps data keys, so code merged to the web or runner Worker can no longer read the master key.
Decisions#
- Writers can read development and preview values back. Staging is readable by admins only. Production is write-only for everyone, including admins and owners.
- Existing secrets are not migrated, because the product is unreleased. Before merging layer 1, an admin sets this repository's deploy secrets again for the
productionenvironment. - Worker sync runs server-side, because a container never holds a secret value.
- OIDC job identity is left for later: Cloudflare API tokens can't use it.
AlemTuzlak closed this
Sign in to join this conversation.
Done in #130 and #132 (merged): CI environments for secrets, read-back, preview values, Worker sync, the keys Worker, value masking and master key rotation.