CI / Secrets and trust
Trust levels and secrets
A pull request from a fork runs code that nobody with write access has read yet, and that code must never get your tokens. Each CI run gets a trust level, and the level decides which secrets, permissions and caches the run gets.
6 min read
The level sets what the run can do, and which CI environments, with their secret values, its jobs can use. No secret value ever enters a job container. The one credential that does is the short-lived OIDC token that a job asks for.
Pick your task:
- Add a CI secret: store a value for each environment, and bind it to its hosts.
- Use a secret in a job: declare it on the job, and send it to its host.
- Approve untrusted runs: start the runs of forks, and hold protected jobs for a person.
- Connect Cloudflare: connect an environment to Cloudflare, with no token to save. Or deploy with a manual token, and sync Worker secrets.
- Read the egress and secret audits: see each request of a job, and each use of a secret.
Trust levels
The forge sets the trust level of a run from the event that started it. A workflow file cannot change the level.
untrusted
- A pull request or a push by a person without write access to the base repository, for example from a fork.
- A pull request of the TanStack Source bot, except the bot pull requests that are
trusted. - A pull request run after a factory agent pushed to the head. See Runs after a push by a factory agent.
trusted
- A pull request by a person with write access.
- A pull request of the bot from the branch of the dependency agent (
factory/deps/...), of the CI cache agent (factory/ci-cache) or of the CI pins update (factory/ci-pins/...). Code plans those changes, so they run without an approval. - A push or a
manual()run by a person with write access, on a ref that they can push to alone: a tag, or a branch with no branch rule that requires a pull request (the default branch too). - A
schedule()run when the default branch has no such rule.
protected
- A push or a
manual()run by a person with write access, on a branch whose branch rule requires a pull request. Its code came through a pull request, so no person with write access put it there alone. - A
schedule()run when the default branch has such a rule.
A repository with no branch rule that requires a pull request has no protected runs. To get them, add a rule to the branch that you deploy from:
src ci rule set main --require-pull
What only a protected run gets
- The values of an environment whose lowest trust level is
protected, like production, andsyncWorkerSecrets(). - Pushes to the default branch, a tag or a branch with a rule, and the permissions
push: ['tags'],issues: 'write',pulls: 'create'andcomment: 'any-pr'. - Saves to the
protectedcache, which other runs read. - Artifacts that the forge keeps for 90 days, not 30.
Approval gates hold only the jobs of protected runs. Only an admin runs a command in a job of a protected run.
How a run gets its level
- For a pull request, the steps come from the pull request. The secrets, permissions and egress hosts come from the base branch. If the pull request asks for more, the run shows a warning, and the job runs without it until the change is merged.
- Only a person with write access starts a
manual()run. - An
after()run gets the level of the run that ended. - A run that a CI push or a
fixup()commit starts gets the lower of two levels: the level of the run that pushed, and the level of the target. - No job result and no agent raises a level. Only a person with write access does.
Permissions
A job writes to the forge only with the permissions that it declares, for example permissions: { comment: 'own-pr' }. The default is none: the run token only reads. The trust level of the run sets a ceiling:
| Permission | untrusted | trusted | protected |
|---|---|---|---|
| Read the repository | yes | yes | yes |
comment: 'own-pr' | no | yes | yes |
push: 'own-pr', push: ['ci/*'] | no | yes | yes |
packages: 'preview' (package previews) | no | yes | yes |
idToken: true (OIDC tokens) | no | yes | yes |
push: ['main', 'tags'], issues: 'write', pulls: 'create', comment: 'any-pr' | no | no | yes |
- A trusted run never pushes to the default branch, a tag, or a branch with a branch rule. A trusted job that asks for
comment: 'any-pr'getscomment: 'own-pr'. - The run shows a warning for each permission that its level takes away.
- The forge audits every write with the run, the job, and the person who started the run. The forge does not screen the writes of trusted and protected runs.
- A hidden workflow gets no permission to write. It sends no
fixup()and saves no cache, so it writes nothing that other people read. Its logs, findings and artifacts are for admins only. Its jobs reach the hosts of theiregress, except in an untrusted run, where they reach no host.
The full permission types are in the reference.
Cache scopes
cache() keeps its entries in scopes. A run reads its own scope first, then the scopes above it. It writes only to its own scope.
- Protected runs write to
protected, and read onlyprotected. - Trusted runs write to
branch:<name>of their branch. They read it, then the base branch of their pull request when they have one, thenprotected. - Untrusted runs of a pull request write to
pr:<number>. They read it, then the base branch, thenprotected. - Untrusted runs without a pull request write nothing.
So a fork never writes an entry that a trusted or protected run reads. A repository keeps 50 GB of cache by default, and the least recently used entries go first.
The other caches use the same scopes:
- The task cache of Nx and Turborepo: a fork never saves a task output that a trusted or protected run takes. A hidden workflow saves no task output.
- The step cache: a fork never saves outputs that a trusted or protected run restores in place of running the step. A hidden workflow neither restores nor saves a step cache.
On every runner
The same rules hold on every runner. On Ravion and on a runner app, the job runs in a fresh VM, next to the agent of the forge. Each request that needs a secret value or the job token goes through the forge, which adds the value, so the VM never holds one. A runner app never gets a job of an untrusted run: that job runs on Ravion, on a clean disk that Ravion does not keep. See What the forge guarantees.