Skip to content

Read-only job token for the workflows that hold TOKEN_FOR_GITHUB - #3137

Open
Totara-thib wants to merge 4 commits into
rust-unofficial:mainfrom
Totara-thib:ci-read-only-job-tokens
Open

Totara-thib wants to merge 4 commits into
rust-unofficial:mainfrom
Totara-thib:ci-read-only-job-tokens

Conversation

@Totara-thib

@Totara-thib Totara-thib commented Dec 1, 2026 •

Copy link
Copy Markdown
  • - I have read the CONTRIBUTING.md and my pull request fulfills the criteria therein

Not a list entry, a workflow change.

approve.yml and pr_tidyup.yml run on pull_request_target with TOKEN_FOR_GITHUB and a write-all GITHUB_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: read in the four workflows. Approvals and the tidyup keep using TOKEN_FOR_GITHUB, untouched.
  • persist-credentials: false: checkouts keep no token.
  • The two toolchain steps call the runner's own rustup, same stable toolchain, instead of a branch that can fetch an installer.
  • actions.lock, GitHub's workflow dependency lockfile from gh actions-lock, records the commit behind each action tag. Major tags become exact releases, same commits. Rerun it after editing a uses: line. An allowed-actions list by tag needs owner/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. The pull_request_target workflows 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.

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.
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.

1 participant