Repository navigation
ci: authenticate release catalog reads with the read-only job token - #56
Conversation
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]>
Dependency Review✅ No vulnerabilities or license issues found.Scanned FilesNone |
…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]>
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]>
|
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
Findings and outcomes Round 1:
Round 2:
Round 3: Round 4: Validation at 600c501
|
|
🎉 This PR is included in version 2.22.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
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.shkeeps 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 listapi.github.com/repos/atrinik/content-toolkit/releasesthroughcrate_release.catalog(), thenapi(), thenget():scripts/release/source-version.mjs→tools/crate_prepare.py pending→known()→catalog();tools/package-release.sh→crate_prepare.py prepare→known()→catalog(). This runs only when a version is planned, which onmainis every typed commit, about 20 minutes after the plan step on the same runner.get()addsAuthorizationonly whenGH_READ_TOKENis set, and only forhttps://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()raisesValueError: public request failedand 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 unresolvedstate. The exposure is the same.Change
.github/workflows/release.yml: both steps getGH_READ_TOKEN: ${{ github.token }}in their stepenv.contents: read, and thepackagejob has no override, so the token is read-only.persist-credentials: false.envgets the token.tools/package-release.sh: this script runscargo metadata,cargo build --release,package-licenses.py,syftand other tools directly. Unlike protocol'scargo packagepath, those don't pass throughclean_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) andunsetsGH_READ_TOKEN. It passes the token back only as a prefix on thepython3 tools/crate_prepare.py prepare ...command. Insideprepare, every Cargo and verifier subprocess already runs withclean_environment(), which removes it. The dry-run path intools/validate.shhas no token and still works underset -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 iscontents: readand expires with the job.tools/test_crate_policy.py: a contract test, run in PR CI throughtools/validate.sh, pins:permissionsblock, parsed so that a blank line or a U+2028 separator can't hide an extra scope: exactlycontents: read, with nopermissionsin thepackagejob;name,on,permissions,concurrency,jobs), so no workflow-levelenvordefaultscan be added anywhere in the file;packagejob;packagejob together: exactly twogithub.tokenexpressions (counted after removing whitespace and lowercasing) and twoGH_READ_TOKENnames;github[,toJSON(github,secrets,GITHUB_ENV,GH_TOKEN,GITHUB_TOKEN,GH_INTENT_TOKENorCARGO_REGISTR*there;package-release.sh, nothing butset,export PYTHONDONTWRITEBYTECODEand thedeclare +xcopy before theunset, and exactly one pass-through, tocrate_prepare.py.tools/test_crate_release.py:get(): withGH_READ_TOKENset, it sendsAuthorization: Bearer(withNoRedirect) toapi.github.com, and no header (withPublicRedirect) to agithub.comrelease download;env=clean_environment()on every non-gitsubprocesscall intools/crate_prepare.py, now thatpreparelegitimately holds the token. It also rejectsos.system,os.popen,os.exec*andos.spawn*,pty, and aliased subprocess imports.tools/test_writable_source.py: the pinned policy-suite count goes from 4 to 5 tests.CRATE_RELEASE.mdandAGENTS.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'scrate-release.jsonfromgithub.com/.../releases/download/.... Those downloads are deliberately anonymous (tokens go only toapi.github.com) and don't count against the REST API limit. Neither path has anapi.github.comreader that ignores the variable.No digest pin covers
release.ymlhere. Content-toolkit has no counterpart to protocol'sEXPECTED_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 onlycontentsof 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 plansv2.22.0unless 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:SHA256SUMS;crate-release.json.Nothing publishes to crates.io.
crate_prepare.py pendingisfalseon currentmain(checked live), and this PR changes no Cargo version. So the manifest has no crate rows, andcrate_release.py dispatchdoes not startpublish-crate.yml. The release run for this merge is also the first to exercise both authenticated steps.Validation
600c501:python3 tools/test_crate_policy.py(5 OK),python3 -m unittest tools.test_crate_release(61 OK) andpython3 tools/test_writable_source.py(OK).${{github.token}};github['token'],toJSON(github)or aGITHUB_ENVexport;envtoken orsecrets.GITHUB_TOKEN(before or afterjobs:), a trailingdefaultsblock, a header YAML anchor, an anchor on the plan step'senvaliased into another step, or a merge key;read-all, or a U+2028-hidden scope;unset;unset;cargo build;crate_prepare;crate_prepare.py:env=clean_environment()fromcargo metadata,cargo packageor the verifier;clean_environment()keepingGH_READ_TOKEN;get(): sending the token to every host, or ignoringGH_READ_TOKEN.GH_READ_TOKENnor the holder variable, even when acatalog_read_tokenwas inherited. The prefixedpython3sees the token, and the unset case works underset -u.crate_prepare.py pendingwith a bogusGH_READ_TOKENfails withpublic request failed, which shows the token reachesapi.github.com. With a real read token it returns{"pending": false}and uses exactly one authenticated core request.test-release-policy.cjs,test-source-version.mjs,source-version.mjs(givesv2.22.0) and the release job'stest-git-auth.mjs.release.yml, ShellCheck 0.10.0 passes onpackage-release.sh, andgit diff --checkis clean.Content toolkit validationruns the fulltools/validate.shon this PR. It includes the dry-runpackage-release.sh.release.ymlchange.🤖 Generated with Claude Code