Repository navigation
Scope Leaf's Cloudflare tokens to its own Workers, and give Tend's agent the logs - #825
Conversation
… tokens `worker/README.md` now lists every Cloudflare token Leaf uses, one per holder, with the permissions read off the account rather than remembered: - `Leaf agent administration` (account-owned) serves agents on the maintainer's machine. Agents read it from the `Max` 1Password vault through the service account, which needs no approval; the README gives that command. A bare `op` call waits on a desktop prompt, which is what stopped earlier unattended sessions. - `leaf-ci-worker-deploy` (user-owned) is `publish-site`'s token in the `cloudflare-deploy` environment. The README previously described it as the same token as the one above; it is a separate token without the observability permissions. - `Leaf observability (Tend CI)` (new, account-owned) reaches Tend's agent through the `tend` environment and `sandbox_env`: Account Analytics, Workers Tail and Workers Observability, all Read. Every Tend agent, including review on `pull_request_target`, reads outside contributors' text, so this secret must never hold a token that edits Workers. The Observability query works with `Workers Observability: Read`; the README said it needed Write. Measured against the account: no token is allowed DNS, members, billing or token management, and no token can read or change a non-Leaf zone; the two that edit Workers can edit every Worker in the account. The query's account id is filled in, and the token recipe lists exact permissions instead of starting from the Edit Cloudflare Workers template. `running-tend` tells Tend's agent to query the logs when an issue or red `publish-site` concerns the deployed site. Workflows regenerated with tend 0.2.10. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Cloudflare shipped per-Worker token scoping on 2026-09-15, so the account-wide `Workers Scripts Write` that let both deploy tokens edit `tend-website` is no longer the only way to deploy `leaf-website`. Each token now names the Workers it may edit, keyed by script tag: - `Leaf agent administration` and the new `Leaf site deploy (CI)` hold `Individual Workers Editor` on Leaf's Workers and are refused on every other Worker in the account, including its code. - `Leaf site deploy (CI)` replaces `leaf-ci-worker-deploy`, which was user-owned; Cloudflare refuses a granular scope on a user-owned token. The `cloudflare-deploy` environment secret holds the new one, the old token is revoked, and publish-site run 35413097355 deployed leaf.page with it. - `Leaf observability (Tend CI)` drops account-wide `Workers Tail Read`; it never streamed a live tail. - `Leaf agent administration` drops `Workers Observability Write`, since the query in this README runs on Read. wrangler publishes a custom domain through per-Worker endpoints, so the production deploy needs nothing account-wide beyond containers and account settings. A `workers.dev` deploy also reads the account's subdomain, refused under a per-Worker scope alone, so the agent token that deploys `leaf-website-dev` adds `Workers Metadata Read-Only`, which still returns 403 on another Worker's code. The 1Password item is renamed to `Cloudflare Leaf agent administration`, after the token it actually holds rather than the read-only name it had. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
The token now rides in every tend agent's sandbox launch environment, and two of those workflows execute contributor-controlled code with it there. I don't think that blocks the change — read-only is the right call and it's your account — but it's the first credential this repo puts inside the sandbox, against a design whose stated point is that "the bot PAT and the Anthropic credential live only in the proxy, never in the agent's environment", so it seems worth deciding deliberately rather than inheriting.
The path: sandbox_env is baked into the agent's launch env, and tend's action documents sandbox_setup as running "with the agent's launch env" inside the same lifecycle step. On tend-review the disposable workspace is refs/pull/N/merge, so it holds the fork's tree — and this repo's sandbox_setup runs uv sync --frozen there, from the PR's own uv.lock, before the agent starts. The review then runs the suite from that tree per Review test selection. Egress doesn't bound the leak: tend's mitmproxy allowlist governs credential injection, and inject_credentials.py passes every non-allowlisted host through untouched so package managers keep working.
So the holder isn't only "the agent reading outside contributors' text", which is what the .config/tend.yaml comment reasons about — it's any code a fork PR ships. Read-only bounds what a leak can do, not who ends up holding it, and both of this token's permissions are account-wide: Workers Observability Read and Account Analytics Read reach every Worker and every Analytics Engine dataset on the account that, as you note, also serves tend-website and 28 other zones. The README's safety sentence is exact about what isn't at risk — "reads another Worker's code" — and silent about what is.
Two levers if you want one, either is cheap:
- Withhold the value from the workflows that check out a PR.
sandbox_envvalues render verbatim intowith:, so a${{ github.workflow != 'tend-review' && ... }}guard stays a.config/tend.yamlchange rather than a hand edit of a generated file. Watch the empty-string ternary —cond && '' || secretyields the secret in both branches, so the empty value has to be the||arm. - Or record it where the next reader meets it: the README paragraph enumerating what no token reaches is the natural place to say that a fork PR's own code runs with the Tend token, and that account-wide observability is what a leak buys.
Separately, 832797e dropped Workers Tail Read from the Tend token and the new table gives it to no one, but the same section still tells agents they may use wrangler tail — suggestion inline.
How the exposure path was established
sandbox_envreaches the agent env:claude/action.yamlat0.2.11passesinputs.sandbox_envasTEND_SANDBOX_ENVinto the sandbox env file, and describessandbox_setupas running "with the agent's launch env and the workspace as cwd".- The workspace holds the fork's tree:
shared/steps/prepare_agent_workspace.py'scheckout_reviewfetchesrefs/pull/N/merge, whichtend-review.yamlselects withcheckout_mode: review. - Egress is open:
proxy/inject_credentials.py— "A request to any other host … is passed through untouched. The proxy's--allow-hostsflag is a functionality optimization … this allowlist is the credential boundary." - The generated workflows themselves check out clean: all nine agent jobs declare
environment: tend, the rendered input matches the generator'smacros.yaml.j2position andNAME=VALUEjoin exactly, and every file parses.
A review, and a mention on a pull request, put that pull request's code in the agent's workspace, and `sandbox_setup` builds it with `uv sync` before the agent starts, all with the launch environment that carries `CLOUDFLARE_API_TOKEN`. So a fork's own code held a token that reads every Worker's logs and every Analytics Engine dataset on the account. The `sandbox_env` value is now empty on those events, by the same test Tend's workspace checkout applies; agents working from `main` keep it. The README now says what the account-wide permissions expose, and no longer offers `wrangler tail` to the Tend token, which lost `Workers Tail Read`. The agent token's `Workers Metadata Read-Only` opens a live tail on any Worker, measured on `tend-website`, and the README says so. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
The guard is keyed on the event, so it covers the two workflows whose workspace arrives holding a pull request's code — but the token stays in the launch environment of the scheduled poll that also handles fork pull requests. tend-mention-relay.yaml's own comment excludes forks because "the notifications poll covers them"; tend-notifications fires on schedule, so the expression takes the secrets.CLOUDFLARE_API_TOKEN arm; and the notifications skill routes an unreviewed PR head into a normal review, which under Review test selection in running-tend runs a test selection from that PR's tree. Fork code executing under the token is what the guard removes on tend-review; on the recovery path it stays.
The expression can't see that — the notifications workspace is main at launch, and the fork tree arrives in a worktree the session makes for itself. So it's a choice between saying so and closing it. Saying so is the suggestion inline. Closing it would be a line in running-tend's Cloudflare logs section: a scheduled session drops CLOUDFLARE_API_TOKEN from the environment before it runs a pull request's code.
Where each link in that path is stated
- Fork PRs route to the poll:
.github/workflows/tend-mention-relay.yaml, in therelayjob's comment — "Fork PRs are excluded to hold long-standing behaviour: the notifications poll covers them, and it applies author-association tiers that this path does not." - The poll is scheduled:
tend-notifications.yamlison: scheduleplusworkflow_dispatch, withcheckout_mode: base, so none ofgithub.event.pull_request,github.event.issue.pull_request, orgithub.event.client_payloadis present and the expression yields the secret. - The poll reviews:
/tend-ci-runner:notifications, step 3 — "use the normal live workflow:/tend-ci-runner:triagefor an issue,/tend-ci-runner:reviewfor an unreviewed PR head". - That review runs the tree:
running-tend, Review test selection — "Before approving a product change, choose and run the smallest test selection that exercises the failures the diff could introduce."
The previous guard withheld the token from events whose workspace starts on a pull request's code, but the scheduled notifications poll starts on `main`, kept the token, and reviews fork pull requests that the relay skips, running their code. Listing that workflow too would be one more exception. The rule is now the positive one that matches why the token exists: `issues`, `issue_comment` on an issue, and `ci-fix`'s `workflow_run` on `main` get it, which is when `running-tend` sends an agent to the logs; every other agent runs with it empty. An agent answering an issue can still fetch a pull request's code itself. `running-tend` tells it to run that code with `env -u CLOUDFLARE_API_TOKEN`, and the README says that this is an instruction, not a mechanism. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`tend-ci-fix` filters `workflow_run` on `branches: ["main"]`, which matches the triggering run's head branch rather than its base. A fork whose default branch is also `main` opens a pull request, `ci` fails, and the run arrives looking like a red run on main — so the fix session would fetch the fork's code with the token in its environment. The `workflow_run` arm now also requires `head_repository` to be this repository. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Agents on the maintainer's machine and Tend's agent in CI can now each run the Workers Observability query in
worker/README.mdwithout a person present, and none of Leaf's Cloudflare tokens can reach another Worker, another zone's settings, DNS, or token management. The account also servestend-websiteand 28 other zones; the maintainer's own login remains the only credential that can change a domain or mint a token.The Cloudflare side is already applied. Per-Worker token scoping shipped on 2026-09-15, so each token now names the Workers it may edit instead of holding account-wide
Workers Scripts Write:Leaf agent administration(agents on the maintainer's machine) holdsIndividual Workers Editoronleaf-websiteandleaf-website-dev, and Observability Read rather than Write. TheCloudflare Leaf agent administration1Password item holds it, and the service account reads it without a prompt.Leaf site deploy (CI)replaces the user-ownedleaf-ci-worker-deployas thecloudflare-deploysecret, scoped toleaf-website; Cloudflare refuses a per-Worker scope on a user-owned token. publish-site run 35413097355 deployed leaf.page with it.Leaf observability (Tend CI)is new:Workers Observability ReadandAccount Analytics Read, stored as thetendenvironment'sCLOUDFLARE_API_TOKEN.In the repository:
.config/tend.yamlpasses thetendenvironment's token into the agent's launch environment throughsandbox_env, and the regeneratedtend-*.yamlworkflows carry it. Only agents answering an issue or a red run onmainget it (issues,issue_commenton an issue,ci-fix'sworkflow_run); reviews, mentions on pull requests and the scheduled polls run with it empty, since each may run a pull request's code. A red run counts as main's only when its head repository is this one, sinceworkflow_run's branch filter matches the triggering run's head ref. An agent answering an issue that fetches a pull request itself is told to run that code with the token unset. The token is read-only; what a leak would expose is every Worker's logs on the account..claude/skills/running-tend/SKILL.mdtells Tend's agent to query the logs when an issue or a red publish-site concerns the deployed site, and to drop the token before running a pull request's code.worker/README.mdlists the three tokens with what each reaches, says which permissions stay account-wide and that what they expose is every Worker's logs, fills in the account id in the query, and drops the claim that the query needs Observability Write.Ref #772, where leaf-agent had no credentials to read these logs.
🤖 Generated with Claude Code