Skip to content
Source
Sign inSign up
TanStack/source

Secret Management #106

Closedtombeckenham opened this issue 1 comment
tombeckenhamcommented

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 get tss_ph_ placeholders that JobOutbound swaps in request headers to bound hosts.
  • A value set only at protected reaches 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 .env parses 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.

  1. #107 106-secrets-hardening (base main): masking of secret values echoed in responses, and master key rotation.
  2. 106-secret-management Environments (base #107). Merge it as one change, because it replaces the old model.
    • Environments per repository. New repositories get production, staging, development and preview.
    • Each environment has the refs it deploys from (branch patterns, protected or pull_request), the lowest trust level a run needs, and its readers: nobody, write or admin.
    • 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.
  3. 106-secrets-read: role-gated read-back (src secret get, src env pull --env development writes a .env file), public variables, and an audit record of every read. Production is never readable.
  4. 106-secrets-preview-api: a scoped-token action secrets:preview to 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.
  5. 106-secrets-worker-sync: an environment can name a Cloudflare account and Worker script. A protected job calls syncWorkerSecrets(), and the forge sends the values to the Cloudflare API itself.
  6. 106-secrets-keys-worker: a small gitflare-keys Worker is the only holder of VAULT_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 production environment.
  • 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.
  1. 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.

  2. AlemTuzlak closed this

Sign in to join this conversation.