Repository navigation
GitLab CI guide: run the token exchange once on a GitLab Runner for every job it builds - #631
Merged
Merged
Conversation
The guide had each project run the exchange in a hidden job. A new section, "Every project on a runner", shows how a GitLab Runner of your own runs it for every job it builds, so that each job restores with the realm rule's read-only role and only a job a trusted publisher matches can push: - the realm rule names the projects by their namespaces (a subgroup is a namespace of its own; gitlab.com needs project IDs as well); - the runner's pre_build_script, which runs in the job's shell right before its before_script, exchanges only in a job that has a token, for a project whose nuget.config names Forge, and exports the key and the NuGet source credentials; - each project asks for the token under default: and runs no exchange of its own, since a token exchanges once; - a runner without workload identity can carry a service account's read token in its environment, a secret every job on it can read. A job with a before_script of its own no longer repeats the exchange: it lists !reference [.forge, before_script] first. The troubleshooting table names the runner's exchange as a cause of a 401. Fixes #630 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012e6DJbNRFYp72ZsDpL9kCF
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.
Fixes #630
GitLab CI with workload identity had each project run the token exchange in a hidden job. An organization with its own runner had to copy that job into every project.
Changes
docs/gitlab-ci.mdgets a new section, Every project on a runner. Each job restores with the realm rule's read-only role, and only a job a trusted publisher matches can push.https://gitlab.comneeds project IDs as well. The role stays read-only, and a project with a role of its own goes into an earlier rule.pre_build_script(config.toml) runs in the job's shell right before itsbefore_script. It exchanges only in a job that has a token, for a project whosenuget.confignames$FORGE_URL. It exportsFORGE_KEYandNuGetPackageSourceCredentials_forge, and a failed exchange fails the job. The section also states the limits:curl,sed,findand a POSIX shell;forge;default:and runs no exchange of its own, since a token exchanges once. The release job pushes with the runner's$FORGE_KEY.environmentinstead. The section says that every job on the runner can then read that secret.Smaller changes in the same guide:
before_scriptof its own no longer repeats the exchange; it lists!reference [.forge, before_script]first.docs/changes/2.1.1/630.docs.md.Testing
tomllib, and ran itspre_build_scriptundersh -e(dash) with a stubcurl:nuget.config: skipped;nuget.configwith another feed: skipped;src/app/NuGet.Confignaming Forge:FORGE_KEYand the NuGet credentials exported, with the expected exchange request;cargo xtask docs --check(links and anchors) andcargo xtask changelog --checkpass.Not verified
pre_build_scriptcomes first in the same shell asbefore_scriptandscript, so its exports reach the job. It also relies onid_tokensbeing allowed underdefault:.docs.gitlab.com.Worth a run on a runner before merging.
🤖 Generated with Claude Code
https://claude.ai/code/session_012e6DJbNRFYp72ZsDpL9kCF