Repository navigation
Read-only job token for the workflows that hold TOKEN_FOR_GITHUB - #3137
Open
Totara-thib wants to merge 4 commits into
Open
Totara-thib wants to merge 4 commits into
Totara-thib wants to merge 4 commits into
Conversation
No workflow declares permissions, so every job gets the repository default, which is a token with write access to contents, actions, pull requests and the rest. That includes the two workflows that run on pull_request_target next to TOKEN_FOR_GITHUB. Nothing uses that job token for more than the checkout. The run approvals and the pull request clean-up go through TOKEN_FOR_GITHUB, which is not touched here, and the link checker reads the same secret. So each workflow now asks for contents: read only. Pull requests from forks already run rust.yml and lint.yml with a read-only token.
actions/checkout stores the job token in a git credential file until the end of the job, where the later steps can read it: the build scripts of the cargo dependencies, the downloaded mktoc binary. No job here runs a git command against the remote after its checkout. The only later git call is the local `git diff --exit-code` of the table of contents check. So the five checkouts set persist-credentials: false.
rust.yml and pr_tidyup.yml followed the master branch of dtolnay/rust-toolchain: whatever lands on that branch runs in the job that holds TOKEN_FOR_GITHUB, with no release in between. The action is also able to fetch and run the rustup installer. On ubuntu-24.04 it does neither today. The image ships rustup, and the action only calls it. So the two jobs now make the same calls themselves: the stable toolchain, minimal profile, no self update, with rustfmt in rust.yml, then set as the default. Not carried over: the retry loop for a release server that is mid update, and three variables the action exported. CARGO_INCREMENTAL=0 is still set by Swatinem/rust-cache, CARGO_TERM_COLOR is already in rust.yml (pr_tidyup.yml loses the colours in its log), and CARGO_HOME was the default path. Swatinem/rust-cache hashes those variables into its key, so each of the two dependency caches is rebuilt once.
Every action here is named by a tag, and a tag can be moved. The approve action and the Rust cache run next to TOKEN_FOR_GITHUB, so a moved tag would run someone else's code with that token. .github/workflows/actions.lock is GitHub's workflow dependency lockfile, written by `gh actions-lock`. It records the commit each of the six actions resolves to today, and the runner then runs that commit whatever the tag says later. The tool also narrows major tags to the exact release they point to: actions/checkout v7 to v7.0.1, actions/cache v5 to v5.1.0 and Swatinem/rust-cache v2 to v2.9.3. These are the commits the runs of today already download. addnab/docker-run-action has no exact release and stays on v3, with its commit in the lockfile. After a `uses:` line is edited by hand, run `gh actions-lock` again and commit the result.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Not a list entry, a workflow change.
approve.ymlandpr_tidyup.ymlrun onpull_request_targetwithTOKEN_FOR_GITHUBand a write-allGITHUB_TOKEN(log), since no workflow sets permissions. Their actions are named by tag, or by branch (dtolnay/rust-toolchain@master). A moved ref, as in tj-actions (CVE-2025-30066), would run with both.permissions: contents: readin the four workflows. Approvals and the tidyup keep usingTOKEN_FOR_GITHUB, untouched.persist-credentials: false: checkouts keep no token.rustup, same stable toolchain, instead of a branch that can fetch an installer.actions.lock, GitHub's workflow dependency lockfile fromgh actions-lock, records the commit behind each action tag. Major tags become exact releases, same commits. Rerun it after editing auses:line. An allowed-actions list by tag needsowner/action@*. Own commit, say so and I drop it.On my fork lint passes and both Rust jobs build, then stop for lack of
TOKEN_FOR_GITHUB. Thepull_request_targetworkflows only act here: the first pull request after a merge shows them.Found and fixed with Plumber (D 31/100 before, C 70/100 after), reviewed and submitted by me.