Skip to content

build(deploy): sign turbo cache entries so no branch build reaches production - #2426

Closed
fforootd wants to merge 1 commit into
mainfrom
claude/fervent-shaw-f06bb7
Closed

fforootd wants to merge 1 commit into
mainfrom
claude/fervent-shaw-f06bb7

Conversation

@fforootd

@fforootd fforootd commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Summary

Why: this is about turbo's build logic, which the hosted cloud's Vercel builds use and which may replace moon one day. Any build that can write turbo's shared cache could plant an entry that production then builds from; with signed entries, production takes only what production's own key signed.

Every Vercel build of the cloud project and every ci-turbo run gets a token that can write any entry of the team's remote cache, and an entry's key follows from the commit (VERCEL_TARGET_ENV is hashed wherever it is set). So anyone who can push a branch could plant an entry that production restores: the console's bundle, the packages it and the docs bundle, and with #2425 the built-in schemas and the docs' generated sources. The Codex review on #2425 showed it for the launcher, which #2425 leaves uncached.

This turns on turbo's artifact signatures:

  • turbo.json: remoteCache.signature: true (turbo signs each upload with TURBO_REMOTE_CACHE_SIGNATURE_KEY and takes an entry it cannot verify for a miss) and futureFlags.longerSignatureKey: true. Without the flag, turbo 2.11.7 accepts an empty key with a warning, and two empty-key runs verify each other's entries. With it, a key under 32 bytes fails any run that uses the remote cache.
  • Two keys. Production builds and ci-turbo on main sign with production's key. Previews and every other ci-turbo run sign with the previews' key.
  • ci-turbo.yml: the job takes its key from the GitHub environment turbo-cache-main (on main) or turbo-cache-branches (anywhere else), with deployment: false so no deployment is recorded. A step after the OIDC token step copies the key into GITHUB_ENV, so the setup actions and the install never see it. Without a key, the job falls back to the local cache with a warning.
  • CACHE_SIGNER (main or branches, in globalEnv) keeps the two CI populations' hashes apart, as VERCEL_TARGET_ENV does on Vercel. Without it, main's runs and branch runs would keep rejecting and re-uploading each other's entries.
  • Docs: a "Remote cache" section in turborepo.md (who holds which key, the gotchas), the plan's "Who may write to the cache" plus decision 11, and the runbook's variable table and a "Cache signatures" bullet.

Secrets to add before merging

Generate two keys on a trusted machine, each with openssl rand -hex 32: production's key and the previews' key. Nothing in this PR reads or sets them.

Where Name Scope Value
Vercel, team zitadel, project cloud TURBO_REMOTE_CACHE_SIGNATURE_KEY Production, sensitive production's key
Vercel, same project TURBO_REMOTE_CACHE_SIGNATURE_KEY Preview (all branches), sensitive the previews' key
GitHub zitadel/nextgen, new environment turbo-cache-main secret TURBO_REMOTE_CACHE_SIGNATURE_KEY Deployment branches: selected, one rule: main production's key
GitHub, new environment turbo-cache-branches secret TURBO_REMOTE_CACHE_SIGNATURE_KEY no branch rule the previews' key
# Vercel, from a checkout linked to the cloud project; each value on stdin
vercel env add TURBO_REMOTE_CACHE_SIGNATURE_KEY production --sensitive --yes
vercel env add TURBO_REMOTE_CACHE_SIGNATURE_KEY preview --sensitive --yes

# GitHub: the branch rule first, then the secret
gh api -X PUT repos/zitadel/nextgen/environments/turbo-cache-main --input - <<<'{"deployment_branch_policy":{"protected_branches":false,"custom_branch_policies":true}}'
gh api -X POST repos/zitadel/nextgen/environments/turbo-cache-main/deployment-branch-policies -f name=main -f type=branch
gh secret set TURBO_REMOTE_CACHE_SIGNATURE_KEY --env turbo-cache-main --repo zitadel/nextgen
gh api -X PUT repos/zitadel/nextgen/environments/turbo-cache-branches
gh secret set TURBO_REMOTE_CACHE_SIGNATURE_KEY --env turbo-cache-branches --repo zitadel/nextgen
  • Add turbo-cache-main's branch rule before its secret. GitHub creates any environment a workflow names, without rules.
  • Give neither environment required reviewers, a wait timer or custom protection rules. Reviewers and timers would hold every run, and a deployment: false job fails outright under custom rules.
  • Don't reuse the existing Production / Preview environments. Vercel's deployment statuses use them, and they have no branch rules.
  • Merging before the keys exist is safe but uncached. Vercel builds warn artifact signature error and build everything; ci-turbo warns and uses its local cache.
  • After merging, every service misses once, since all older entries are unsigned. On the next production deployment, the console's build log should show cache hit again.

Validation

All runs used turbo 2.11.7 from this checkout, against a local fake remote cache: a Node server for turbo's /v8/artifacts API that stores each upload with its x-artifact-tag. Every run was turbo run build --filter=@zitadel/design-tokens (generate + build) with TURBO_CACHE=remote:rw, as on Vercel, and two random 32-byte keys.

  • Planted entry. A preview-key run with VERCEL_TARGET_ENV=production wrote both tasks under production's hashes. The production-key run then reported cache miss for both, rebuilt them and re-signed them; the next production run had 2/2 hits.
  • Tampered body. That task missed. Unsigned entry: missed.
  • CI populations. CACHE_SIGNER=main (production's key) and CACHE_SIGNER=branches (the previews' key) give different hashes, and each hit its own entries on rerun. A previews'-key run with CACHE_SIGNER=main uploaded under main's hashes, and main's next run rejected those entries.
  • Without a key.
    • No remote cache (a contributor's run): the second run had 2/2 local hits.
    • Remote cache on, no key: exit 0, WARNING artifact signature error, nothing uploaded.
    • Empty key, remote cache on: exit 1 before any task.
    • Empty key with TURBO_CACHE=local:rw (the workflow's fallback): exit 0.
  • Graph and checks.
    • turbo run <ci-mode's 50 graph tasks> --dry=json resolves all 389 tasks with CACHE_SIGNER unset, main and branches; @zitadel/console#build gets three different hashes.
    • The new workflow step's script, run with and without a key, writes GITHUB_ENV or warns and exits 1.
    • node scripts/check-pr-title.mjs and node scripts/check-changesets-status.mjs --base origin/main both pass.
  • Not run: ci-turbo itself (a run would create the environments), a Vercel build, and Vercel's real remote cache. How Vercel treats a second upload under an existing hash is unknown; the fake cache replaces it.

Release notes / changeset

No changeset required — no shipped behavior changed.

Notes

🤖 Generated with Claude Code

…oduction

Every Vercel build and every ci-turbo run gets a token that can write any
entry of the team's remote cache, under a hash anyone can compute from the
commit, so a branch could plant an entry that production restores: the
console's bundle among them.

Turn on turbo's artifact signatures (remoteCache.signature) and require
keys of at least 32 bytes (futureFlags.longerSignatureKey). Production
builds and ci-turbo on main sign with production's key, previews and every
other ci-turbo run with the previews' key; a restore that fails to verify is
a miss. ci-turbo takes its key from the GitHub environment turbo-cache-main
(branch rule: main) or turbo-cache-branches, without recording a deployment,
and hashes its two populations apart with CACHE_SIGNER, as VERCEL_TARGET_ENV
does on Vercel. The merge queue signs as a branch until only it can create
its gh-readonly-queue/ branches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cloud Ready Ready Preview Oct 28, 2026 3:50am UTC

Request Review

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ No Changeset found

Latest commit: 2126ff7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@fforootd
fforootd marked this pull request as ready for review October 28, 2026 03:48
@fforootd
fforootd requested review from mridang and a balanced review from Copilot October 28, 2026 03:48
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-10-28T03:52:54.733153Z 2126ff7 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The change's correctness hinges on out-of-band Vercel/GitHub secrets and environment branch rules that the diff can't confirm, and the ci-turbo workflow was never exercised during validation.

No open issues 🎉

What changed in this PR

This PR hardens the hosted cloud's Turborepo remote cache against supply-chain poisoning. Today every Vercel build of the cloud project and every ci-turbo run holds a token that can write any entry of the team's shared remote cache, and cache keys are derivable from the commit — so anyone who can push a branch could plant an entry (the console bundle, built-in schemas, generated docs sources) that a production build would restore. The change turns on Turborepo's artifact signatures so a run only restores entries signed with its own key, splitting production's key from the previews' key across both Vercel and CI, and documents the operational setup.

Changes:

  • turbo.json: enable remoteCache.signature and futureFlags.longerSignatureKey, and add CACHE_SIGNER to globalEnv so CI's main and branch populations hash apart (mirroring VERCEL_TARGET_ENV on Vercel).
  • ci-turbo.yml: select the GitHub environment (turbo-cache-main on main, else turbo-cache-branches) with deployment: false, add a post-OIDC step that copies the environment's signing-key secret into GITHUB_ENV, and fall back to local-only cache when no token or key is present.
  • Docs: new "Remote cache" section in turborepo.md, runbook env-var rows and a "Cache signatures" bullet in cloud.md, and migration-plan decision 11 / "Who may write to the cache" updates.
File Description
turbo.json Enables signed remote-cache entries, the 32-byte key future flag, and adds CACHE_SIGNER as a hashed global env to separate CI populations.
.github/​workflows/​ci-turbo.yml Binds the job to a GitHub environment per ref, injects the signing key after OIDC setup, and reworks the local-cache fallback to key off the signing-key step outcome.
docs/​runbooks/​cloud.md Adds the two TURBO_REMOTE_CACHE_SIGNATURE_KEY Vercel variables and a cache-signatures operational bullet with rotation guidance.
docs/​design/​build/​turborepo.md New "Remote cache" section: key-holder table, the gh-readonly-queue caveat, and no-key/short-key behavior.
docs/​design/​build/​turborepo-migration.md Records signatures as decision 11 and updates the "Who may write to the cache" rationale.

Notes for the human reviewer: correctness here depends on infrastructure that isn't visible in the diff — the two Vercel variables, the two new GitHub environments, and turbo-cache-main's main-only branch rule must exist (and be created in the documented order) before/at merge, and the PR notes that ci-turbo itself and a real Vercel build were not exercised in validation. These are operational considerations rather than code defects.

Review effort: Balanced

@fforootd fforootd closed this Oct 28, 2026
@github-project-automation github-project-automation Bot moved this from Inbox to Done in Engineering Kanban Oct 28, 2026

This branch was successfully deployed

1 active deployment
Preview — 2126ff7d Deployed Oct 28, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants