Skip to content

ci: authenticate release catalog reads with the read-only job token - #56

Merged
zoeyrose merged 6 commits into
mainfrom
ci/plan-step-read-token
Nov 23, 2026
Merged

zoeyrose merged 6 commits into
mainfrom
ci/plan-step-read-token

Conversation

@zoeyrose

@zoeyrose zoeyrose commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Summary

Gives two Semantic Release steps the job's read-only Actions token as GH_READ_TOKEN: "Plan the actual source version without write credentials" and "Prepare every immutable source and crate asset". Their GitHub release-catalog reads then authenticate and no longer share the hosted runner IP's anonymous API limit. tools/package-release.sh keeps the token away from Cargo, build scripts and every other tool, so compilation stays credential-free. This matches atrinik/protocol#69.

Why

On main, both steps list api.github.com/repos/atrinik/content-toolkit/releases through crate_release.catalog(), then api(), then get():

  • plan: scripts/release/source-version.mjs → tools/crate_prepare.py pending → known() → catalog();
  • prepare: tools/package-release.sh → crate_prepare.py prepare → known() → catalog(). This runs only when a version is planned, which on main is every typed commit, about 20 minutes after the plan step on the same runner.

get() adds Authorization only when GH_READ_TOKEN is set, and only for https://api.github.com/ URLs. Without the token, the request counts against GitHub's 60/hour anonymous limit for the runner's shared IP. When that limit is spent, get() raises ValueError: public request failed and the release fails.

atrinik/protocol has the same code path. Its plan step failed this way twice on 2026-11-23 and blocked a crate publication. Content-toolkit's release runs have not hit it yet: its October failures were the earlier owned crate registry readiness unresolved state. The exposure is the same.

Change

  • .github/workflows/release.yml: both steps get GH_READ_TOKEN: ${{ github.token }} in their step env.

    • The workflow permissions stay contents: read, and the package job has no override, so the token is read-only.
    • Checkout keeps persist-credentials: false.
    • No other step and no job-level env gets the token.
  • tools/package-release.sh: this script runs cargo metadata, cargo build --release, package-licenses.py, syft and other tools directly. Unlike protocol's cargo package path, those don't pass through clean_environment(). So, before running any command, the script copies the token into a non-exported shell variable (declare +x, so an inherited variable of the same name can't export it) and unsets GH_READ_TOKEN. It passes the token back only as a prefix on the python3 tools/crate_prepare.py prepare ... command. Inside prepare, every Cargo and verifier subprocess already runs with clean_environment(), which removes it. The dry-run path in tools/validate.sh has no token and still works under set -u.

    This limits accidental exposure; it is not a sandbox. A process running as the same user could still read the token from a parent's /proc/PID/environ. The token is contents: read and expires with the job.

  • tools/test_crate_policy.py: a contract test, run in PR CI through tools/validate.sh, pins:

    • the single top-level permissions block, parsed so that a blank line or a U+2028 separator can't hide an extra scope: exactly contents: read, with no permissions in the package job;
    • the token in exactly those two steps, in that order;
    • fixed top-level keys (name, on, permissions, concurrency, jobs), so no workflow-level env or defaults can be added anywhere in the file;
    • no YAML anchors, aliases or merge keys up to the end of the package job;
    • over the workflow header and the package job together: exactly two github.token expressions (counted after removing whitespace and lowercasing) and two GH_READ_TOKEN names;
    • none of github[, toJSON(github, secrets, GITHUB_ENV, GH_TOKEN, GITHUB_TOKEN, GH_INTENT_TOKEN or CARGO_REGISTR* there;
    • in package-release.sh, nothing but set, export PYTHONDONTWRITEBYTECODE and the declare +x copy before the unset, and exactly one pass-through, to crate_prepare.py.
  • tools/test_crate_release.py:

    • a unit test pins get(): with GH_READ_TOKEN set, it sends Authorization: Bearer (with NoRedirect) to api.github.com, and no header (with PublicRedirect) to a github.com release download;
    • an AST contract test requires env=clean_environment() on every non-git subprocess call in tools/crate_prepare.py, now that prepare legitimately holds the token. It also rejects os.system, os.popen, os.exec* and os.spawn*, pty, and aliased subprocess imports.
  • tools/test_writable_source.py: the pinned policy-suite count goes from 4 to 5 tests.

  • CRATE_RELEASE.md and AGENTS.md: they now describe both token-carrying steps and the non-inheritance scoping. AGENTS.md's "compiler jobs remain credential-free" becomes "compiler processes inherit no credentials; the source job passes its read-only token only to its planning and preparation catalog reads".

Other readers on these paths: catalog() also downloads each release's crate-release.json from github.com/.../releases/download/.... Those downloads are deliberately anonymous (tokens go only to api.github.com) and don't count against the REST API limit. Neither path has an api.github.com reader that ignores the variable.

No digest pin covers release.yml here. Content-toolkit has no counterpart to protocol's EXPECTED_SOURCE_WORKFLOW_SHA256, and nothing in the workspace pins this workflow's bytes, so nothing needs re-anchoring.

Accepted exposure: in the plan step, the commit analyzer runs in the same Node process as the token. Its top-level packages are pinned (--ignore-scripts), but their dependencies resolve by range. The token can read only contents of this public repository, and it expires with the job. The release job already gives a write-capable token to semantic-release and its plugins.

Release consequence

Merging cuts a source release. On main, every Conventional Commit type releases a minor version (scripts/release/release-policy.cjs), so this plans v2.22.0 unless another release lands first. Running the plan step locally on this branch under main's rules gave {"version":"2.22.0"}. That GitHub release contains:

  • the source archive;
  • the CLI and MCP binaries;
  • the application crate archives, the content assets, the SBOM and SHA256SUMS;
  • an attested crate-release.json.

Nothing publishes to crates.io. crate_prepare.py pending is false on current main (checked live), and this PR changes no Cargo version. So the manifest has no crate rows, and crate_release.py dispatch does not start publish-crate.yml. The release run for this merge is also the first to exercise both authenticated steps.

Validation

  • On 600c501: python3 tools/test_crate_policy.py (5 OK), python3 -m unittest tools.test_crate_release (61 OK) and python3 tools/test_writable_source.py (OK).
  • Mutation check: each of these changes makes the suites fail, and restoring the files makes them pass again (40 across three rounds):
    • workflow token placement:
      • dropping either step's token;
      • giving another step the token, including spelled ${{github.token}};
      • adding github['token'], toJSON(github) or a GITHUB_ENV export;
      • a job-level token, a top-level env token or secrets.GITHUB_TOKEN (before or after jobs:), a trailing defaults block, a header YAML anchor, an anchor on the plan step's env aliased into another step, or a merge key;
    • workflow permissions: an extra scope after a blank line, read-all, or a U+2028-hidden scope;
    • the script:
      • a plain (exportable) holder assignment, or exporting the holder;
      • no unset;
      • a command before the unset;
      • passing the token to cargo build;
      • dropping it from crate_prepare;
    • crate_prepare.py:
      • removing env=clean_environment() from cargo metadata, cargo package or the verifier;
      • an aliased subprocess import;
      • clean_environment() keeping GH_READ_TOKEN;
    • get(): sending the token to every host, or ignoring GH_READ_TOKEN.
  • Shell scoping behavior: with the script's two scoping lines, child processes see neither GH_READ_TOKEN nor the holder variable, even when a catalog_read_token was inherited. The prefixed python3 sees the token, and the unset case works under set -u.
  • Live plan path: crate_prepare.py pending with a bogus GH_READ_TOKEN fails with public request failed, which shows the token reaches api.github.com. With a real read token it returns {"pending": false} and uses exactly one authenticated core request.
  • With the pinned npm packages, these pass: test-release-policy.cjs, test-source-version.mjs, source-version.mjs (gives v2.22.0) and the release job's test-git-auth.mjs.
  • actionlint 1.7.12 passes on release.yml, ShellCheck 0.10.0 passes on package-release.sh, and git diff --check is clean.
  • Content toolkit validation runs the full tools/validate.sh on this PR. It includes the dry-run package-release.sh.
  • The contract tests guard against accidental regressions. Deliberately obfuscated workflow YAML, for example tagged anchors inside flow collections, is left to human review of any release.yml change.

🤖 Generated with Claude Code

On main, the plan step runs scripts/release/source-version.mjs, which calls
tools/crate_prepare.py pending. That lists this repository's releases through
api.github.com via crate_release.get(), which sends a token only when
GH_READ_TOKEN is set. Without it the call shares the runner IP's 60/hour
unauthenticated limit; atrinik/protocol's identical step failed twice on
2026-11-23 with "public request failed" and blocked a crate publication.

Give only the plan step the job's read-only Actions token (workflow
permissions stay contents: read, and the package job has no override). A
contract test pins the token to that one step and keeps write credentials and
secrets out of the package job, so packaging and compilation stay
credential-free.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues found.

Scanned Files

None

zoeyrose and others added 3 commits November 23, 2026 07:02
…urce check

tools/test_writable_source.py runs tools/validate.sh up to its first Cargo
command and pins the crate policy suite's test count to prove that suite ran.
The plan-step token contract test raises it from 4 to 5.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
On main, "Prepare every immutable source and crate asset" runs
tools/package-release.sh, which calls crate_prepare.py prepare, then known(),
then catalog(). That makes the same anonymous api.github.com release listing
as the plan step, about 20 minutes later on the same runner. Give that step
the read-only job token too, matching atrinik/protocol#69.

package-release.sh runs cargo metadata, cargo build --release, syft and other
tools directly, so it moves the token into an unexported shell variable
before any command and passes it only to crate_prepare.py prepare.
clean_environment() already strips it from that script's Cargo and verifier
children.

The contract test now:
- pins the token to exactly the plan and preparation steps;
- counts every spelling of github.token;
- rejects secrets, github[...], toJSON(github) and GITHUB_ENV exports in the
  package job;
- pins package-release.sh's scoping.

A unit test pins get(): it sends GH_READ_TOKEN only to api.github.com, and
release downloads stay anonymous.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…talog reads

CRATE_RELEASE.md now covers both steps that hold GH_READ_TOKEN and how
package-release.sh limits it to crate_prepare.py prepare. AGENTS.md replaces
"compiler jobs remain credential-free": the package job compiles and now
holds a read-only token in two steps, so the guide states the actual
boundary, which is that compilation stays credential-free.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zoeyrose zoeyrose changed the title ci: authenticate the source version plan's release catalog reads ci: authenticate release catalog reads with the read-only job token Nov 23, 2026
zoeyrose and others added 2 commits November 23, 2026 07:35
Delta review of e2ef3ac/9e0c97d found four gaps:
- The policy test counted token expressions only inside the package job.
  A workflow-level env, a secret or a header YAML anchor could hand the token
  to every step, and a blank line inside the permissions block could add a
  write scope. The test now counts over the header and the package job, and
  parses the single top-level permissions block, which must be exactly
  contents: read.
- prepare() now holds GH_READ_TOKEN, so env=clean_environment() on its
  Cargo and verifier subprocesses is load-bearing. An AST contract test
  requires it on every non-git subprocess call in crate_prepare.py and rejects
  other process launchers and aliased subprocess imports.
- package-release.sh used a plain assignment for its holder. An inherited
  variable of the same name would have exported the token, so it now uses
  declare +x.
- The docs said "never reaches". They now describe inheritance and state
  that this limits accidental exposure and is not a sandbox.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Second delta review: a workflow-level env: written after jobs:, or a
YAML anchor on the plan step's env aliased into another package step, could
hand the token to Cargo steps while the contract test stayed green. Pin the
column-0 keys and reject anchors, aliases and merge keys up to the end of the
package job. The test guards against accidental regressions; deliberately
obfuscated workflow edits are left to review.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zoeyrose

Copy link
Copy Markdown
Member Author

Self-review of #56 through head 600c501. Four fresh-context reviewers looked at it, each a new Agent with an explicit brief and no fork.

What was reviewed

  • Round 1: the whole diff 94f090f..465fbd2 (the reviewer also saw 3c747dc), plus the code it touches:
    • release.yml, all jobs;
    • source-version.mjs;
    • crate_prepare.py: pending, known, clean_environment and preparation_boundary;
    • crate_release.py: get, api, catalog, asset_bytes, registry_source_branch and boundary;
    • test-git-auth.mjs and validate.sh.
  • Round 2: delta 3c747dc..9e0c97d (the prepare-step token, the scoping in package-release.sh, the rewritten contract test, the get() unit test, docs).
  • Round 3: delta 9e0c97d..53427f8.
  • Round 4: delta 53427f8..600c501.

Findings and outcomes

Round 1:

  1. P1: tools/test_writable_source.py pinned Ran 4 tests, so validation went red with the new policy test. Fixed in 3c747dc; CI caught it too.
  2. P3: the token count in the contract test could be bypassed by spelling (${{github.token}}, github['token'], toJSON(github), a GITHUB_ENV export). Fixed in e2ef3ac and 53427f8: the count now ignores whitespace and case, and those fragments are rejected.
  3. P3: nothing pinned how get() uses the token. Fixed in e2ef3ac with a unit test: Bearer plus NoRedirect only for api.github.com; release downloads stay anonymous.
  4. P3: the prepare step's catalog() read was still unauthenticated. Fixed in e2ef3ac, which also matches fix(release): authenticate source catalog reads with the read-only job token protocol#69 at the coordinator's direction. package-release.sh keeps the token from being inherited by cargo, syft and other tools, and passes it only to crate_prepare.py prepare.
  5. P3: the AGENTS.md wording and the job name "Prepare credential-free source release" read loosely.
    • AGENTS.md: fixed in 9e0c97d and 53427f8.
    • Job rename: declined. The job still holds no write credential, it is not a required check, and renaming is outside the approved scope.
  6. P3: the intent brief called the npm modules "pinned". Corrected in the PR body: only the top-level packages are pinned, and transitive dependencies resolve by range. The impact is a contents: read token that expires with the job.

Round 2:
7. P2: the contract test ignored the workflow header. A top-level env or secret, a header anchor, or a permissions scope after a blank line stayed green. Fixed in 53427f8: counts now run over the header plus the package job, and the single top-level permissions block is parsed and must be exactly contents: read.
8. P3: env=clean_environment() in prepare became load-bearing but was untested. Fixed in 53427f8 with an AST test: every non-git subprocess must pass it, and other process launchers and aliased imports are rejected.

  • Declined: popping the token into a module-level value in get(). get() and clean_environment() stay byte-identical to protocol#69's copy, and the AST test pins the same guarantee.
  1. P3: the docs overclaimed ("never reaches"). Fixed in 53427f8: they now describe non-inheritance and say it is not a sandbox.
    • Declined: changing the crate_prepare.py docstring and the preparation_boundary message. Both describe the write-credential boundary that function enforces.
  2. P3 nit: an inherited variable of the holder's name would export the token. Fixed in 53427f8 with declare +x.

Round 3:
11. P3: a workflow-level env: after jobs: stayed green. Fixed in 600c501 by pinning the column-0 keys.
12. P3: an anchor on the plan step's env aliased into another package step stayed green. Fixed in 600c501 by rejecting anchors, aliases and merge keys up to the end of the package job.
13. Optional hardening for deliberately odd subprocess spellings (R.subprocess.run, import signal, subprocess as sp). Declined: that is deliberate obfuscation, outside the test's accidental-regression threat model, and release.yml edits are reviewed anyway.

Round 4:
14. No defects. The reviewer confirmed with PyYAML that both round-3 gaps are closed, and found no false positive on the current workflow.
15. Optional: add a msg= to the anchor assertNotRegex. Declined. Its known false positives (a leading && or glob in block scalars) fail loudly in PR CI and print the matched text.

Validation at 600c501

  • Test suites:
    • test_crate_policy: 5 OK;
    • test_crate_release: 61 OK;
    • test_writable_source: OK.
  • Mutation checks: 40 mutations across three rounds, every one red, and the clean tree is green.
  • Static checks: actionlint 1.7.12, ShellCheck 0.10.0 and git diff --check are all clean.
  • Live checks:
    • with a bogus GH_READ_TOKEN, crate_prepare.py pending fails with public request failed;
    • with a real read token it returns {"pending": false}, using one authenticated request;
    • the pinned-npm source-version.mjs plans v2.22.0.
  • PR CI on 600c501 is green: validation, corpus, CodeQL, PR title and Dependency review (no vulnerable or changed dependencies).

@zoeyrose
zoeyrose marked this pull request as ready for review November 23, 2026 13:56
@zoeyrose zoeyrose self-assigned this Nov 23, 2026
@zoeyrose
zoeyrose requested a review from a team November 23, 2026 13:56
@zoeyrose
zoeyrose merged commit 0dbade3 into main Nov 23, 2026
12 checks passed
@zoeyrose
zoeyrose deleted the ci/plan-step-read-token branch November 23, 2026 14:04
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 2.22.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant