Skip to content

codex: scope refresher PAT to a main-only environment - #510

Merged
max-sixty merged 2 commits into
mainfrom
env-scope-codex-refresh
May 15, 2026
Merged

max-sixty merged 2 commits into
mainfrom
env-scope-codex-refresh

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Summary

The codex-auth-refresh workflow needs a fine-grained PAT with secrets: read+write to update CODEX_AUTH_JSON from outside a consumer run. Stored as a plain repo secret, that PAT is a meaningful escalation over the bot's existing write-collaborator role — the bot has workflow scope and can push workflow files to feature branches that read repo secrets, so any bot-controlled workflow could read the PAT and rewrite every repo secret (including BOT_TOKEN and CODEX_AUTH_JSON itself).

This change scopes the PAT to a GitHub Environment (codex-auth-refresh) pinned to main only. GitHub evaluates the workflow's ref against the environment's branch policy before injecting secrets, so a bot-pushed feature-branch dispatch is rejected before the secret is exposed. Branch protection on main already prevents the bot from landing workflow changes there.

Changes

  • .github/workflows/codex-auth-refresh.yaml — add environment: codex-auth-refresh to the refresher job.
  • docs/security-model.md — extend the rotation-hazard writeup with the env-scoping rationale.
  • plugins/install-tend/skills/install-tend/SKILL.md §7b step 4 — walk through env creation, branch-policy pinning, and PAT storage. Pre-filled fine-grained PAT URL with no expiry (the env's branch policy is the actual security boundary; calendar rotation adds little here).

The env, branch policy, and PAT are already provisioned on max-sixty/tend — this PR just lands the workflow change that makes the refresher reference them.

Test plan

  • Pre-commit + actionlint pass (verified locally)
  • After merge: gh workflow run codex-auth-refresh.yaml --repo max-sixty/tend succeeds and CODEX_AUTH_JSON.updated_at advances
  • Subsequent nightly cron fires unattended

The refresher needs a fine-grained PAT with secrets:read+write,
which is a meaningful escalation over the bot's existing write
collaborator role — the bot has `workflow` scope and can push
workflow files to feature branches that read repo secrets, so a
plain repo secret would let the bot exfiltrate the PAT and rewrite
any repo secret (including BOT_TOKEN, CODEX_AUTH_JSON).

Mitigation: store the PAT in a GitHub Environment scoped to `main`
only. GitHub gates secret injection on the workflow ref before the
job starts, so bot-pushed feature-branch runs can't read it.

Workflow: add `environment: codex-auth-refresh` to the refresher job.

install-tend skill §7b step 4: walk through env creation, branch
policy pinning, and PAT storage with a pre-filled fine-grained PAT
URL (no expiry — the env's branch policy is the actual security
boundary).

security-model.md: document the env scoping requirement alongside
the existing rotation hazard writeup.

Co-Authored-By: Claude <[email protected]>

@tend-agent tend-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Env-scoping the refresher PAT is a clear escalation-prevention win, and the install walkthrough lays the env+policy+PAT setup out cleanly.

One small skill-consistency nit inline: the new CODEX_REFRESH_PAT step jumps from "have the user mint a PAT" to --body "$PAT" without telling the install bot to ask the user to paste the result back, where the sibling ANTHROPIC_API_KEY, manual CLAUDE_CODE_OAUTH_TOKEN, and OPENAI_API_KEY blocks all do.

Mirror the ANTHROPIC_API_KEY / OPENAI_API_KEY pattern so the
install bot doesn't jump from "have the user mint a PAT" to the
secret-set command without prompting for the value.

Co-Authored-By: Claude <[email protected]>
@max-sixty
max-sixty merged commit 6f46a95 into main May 15, 2026
6 checks passed
@max-sixty
max-sixty deleted the env-scope-codex-refresh branch May 15, 2026 19:14
max-sixty added a commit that referenced this pull request May 16, 2026
## Summary

Flips tend's own CI from the Claude harness to the Codex harness by
setting `harness: codex` in `.config/tend.yaml` and regenerating the
eight `tend-*.yaml` workflows. Each now invokes
`max-sixty/tend/[email protected]` with `CODEX_AUTH_JSON` instead of
`max-sixty/tend@<v>` with `CLAUDE_CODE_OAUTH_TOKEN`.

Motivation is cost: API billing scales per token; a flat-rate ChatGPT
subscription funds unlimited runs. tend dogfoods its own setup, so it
should run the harness we recommend for cost-sensitive adopters.

The net diff is small — config (+ `harness: codex`, + `secrets.allowed:
[CODEX_AUTH_JSON]`) and the regenerated workflow files (action ref, auth
secret, model, skill-invocation syntax). Supporting infrastructure
landed separately on main:

- `codex-auth-refresh.yaml` + env-scoped `CODEX_REFRESH_PAT` rotation
(#500, #510)
- `CODEX_AUTH_JSON` as a repo secret, refresher writes it back at repo
scope (#514)
- Codex-on-GHA fixes, all in release 0.0.22: sandbox
`danger-full-access` (#519), npm prebuilt install (#522), base64
`final_message` capture (#525)

## Validation

The original "do not merge until…" prerequisite is **satisfied**:

- `tend-review-runs` `workflow_dispatch` on this branch (pinned
`[email protected]`) ran **green end-to-end** — codex authenticated,
installed via npm, ran without the `bwrap` block, executed the full
agent (real review-runs work: posted evidence to the tracking issue,
commented on the outage issue), and the action exited 0.
- Deterministic CI (`test`, `test-worker`, `lint`) green; `tend-review`
(Claude harness via `pull_request_target`) approved.

Each codex blocker found during stabilization was fixed and released:
auth scoping → sandbox → install → output framing. The smoke test going
green on 0.0.22 confirms convergence.

## Post-merge follow-up

Watch the first unattended nightly `codex-auth-refresh` cron (`17 3 * *
*`) succeed. Manual dispatches (incl. the post-#514 recovery) have all
succeeded; this just confirms the scheduled path runs without a human.
Failure degrades gracefully over the ~8-day refresh window, with manual
rotation as fallback.

---------

Co-authored-by: Claude <[email protected]>
max-sixty added a commit that referenced this pull request May 16, 2026
## Summary

Flips tend's own CI from the Claude harness to the Codex harness by
setting `harness: codex` in `.config/tend.yaml` and regenerating the
eight `tend-*.yaml` workflows. Each now invokes
`max-sixty/tend/[email protected]` with `CODEX_AUTH_JSON` instead of
`max-sixty/tend@<v>` with `CLAUDE_CODE_OAUTH_TOKEN`.

Motivation is cost: API billing scales per token; a flat-rate ChatGPT
subscription funds unlimited runs. tend dogfoods its own setup, so it
should run the harness we recommend for cost-sensitive adopters.

The net diff is small — config (+ `harness: codex`, + `secrets.allowed:
[CODEX_AUTH_JSON]`) and the regenerated workflow files (action ref, auth
secret, model, skill-invocation syntax). Supporting infrastructure
landed separately on main:

- `codex-auth-refresh.yaml` + env-scoped `CODEX_REFRESH_PAT` rotation
(#500, #510)
- `CODEX_AUTH_JSON` as a repo secret, refresher writes it back at repo
scope (#514)
- Codex-on-GHA fixes, all in release 0.0.22: sandbox
`danger-full-access` (#519), npm prebuilt install (#522), base64
`final_message` capture (#525)

## Validation

The original "do not merge until…" prerequisite is **satisfied**:

- `tend-review-runs` `workflow_dispatch` on this branch (pinned
`[email protected]`) ran **green end-to-end** — codex authenticated,
installed via npm, ran without the `bwrap` block, executed the full
agent (real review-runs work: posted evidence to the tracking issue,
commented on the outage issue), and the action exited 0.
- Deterministic CI (`test`, `test-worker`, `lint`) green; `tend-review`
(Claude harness via `pull_request_target`) approved.

Each codex blocker found during stabilization was fixed and released:
auth scoping → sandbox → install → output framing. The smoke test going
green on 0.0.22 confirms convergence.

## Post-merge follow-up

Watch the first unattended nightly `codex-auth-refresh` cron (`17 3 * *
*`) succeed. Manual dispatches (incl. the post-#514 recovery) have all
succeeded; this just confirms the scheduled path runs without a human.
Failure degrades gracefully over the ~8-day refresh window, with manual
rotation as fallback.

---------

Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants