Repository navigation
Conversation
A release branch's `go` directive is frozen at branch cut: it is the branch's compatibility floor for every consumer and selects the GODEBUG defaults compiled into the binary. A base-image run raised it on rhdh-must-gather release-2.1 from a stale copy of the rhdh-base-images skill, and auto-merge landed it before anyone noticed — skill-side guards cannot cover an installed copy that predates them, so the branch has to protect itself. The check compares go.mod at the pull request base and head. A raise fails, with the revert instruction; a revert is allowed, so a branch that already carries a raised directive can be repaired. `toolchain` is deliberately not checked: it follows the go-toolset image on every branch. A security fix that cannot land without the raise is the one exception, and the contract is the `kind/security` label that Renovate adds to its vulnerability alerts: without the label the check fails, so accepting the raise is a deliberate reviewer action rather than an emergent side effect. The script receives the base branch and decides whether the request is in scope, so the check reports on every pull request instead of staying pending when a paths filter does not match. Adding the job to the branch protection rules for release-* is what makes it block auto-merge. Assisted-by: OpenCode
PR Summary by QodoBlock Go directive raises on release-branch PRs
AI Description
Merge Risk
|
|
/cherrypick release-2.1 |
|
@rm3l: once the present PR merges, I will cherry-pick it on top of DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
Important The |
Review finding: a pull request could change the workflow or the script that judges its own go directive, and pass. Move the check to pull_request_target, which runs the workflow definition and the script from the default branch rather than the pull request's merge commit. The proposed head is now read strictly as data: its go.mod is fetched into a file with `git show` and handed to the script, and nothing from the pull request is checked out or executed. Permissions stay read-only and no secrets are used. The script no longer touches git at all — it compares two files — so the trust boundary is explicit: trusted code, untrusted data. pull_request_target also runs for pull requests whose target branch does not carry this file, so a release branch is covered as soon as main has it. Assisted-by: OpenCode
Sonar gate S7631 ("Forked repository code should not be checked out in
privileged workflow contexts") flags any actions/checkout in a
pull_request_target workflow, whatever its ref. Drop it.
The job now initialises a scratch repository, fetches the default branch, the
target branch and the pull request head into private refs, reads the policy
script from the default-branch ref with `git show`, and reads go.mod from each
side as data. No tree is ever checked out, so the warning and the pattern it
guards against are both gone while the trust boundary is unchanged.
Assisted-by: OpenCode
| return 1 | ||
| } | ||
|
|
||
| if [[ "${BASE_REF}" != release-* ]]; then |
There was a problem hiding this comment.
should this be explicitly for main rather than anything but a release-* branch? wondering if this will impact PRs on topic branches (and if that's good or bad).
There was a problem hiding this comment.
--base-ref is the target branch, so a topic branch PR only reaches this comparison if it targets a release branch. A PR from any topic branch against main is out of scope, which is intended per the policy.
That said, I realized that release-* alone seems too broad. I've updated the condition accordingly. Thanks.
| exit 0 | ||
| fi | ||
|
|
||
| if [[ " ${LABELS} " == *" kind/security "* ]]; then |
There was a problem hiding this comment.
this is a cool nuance/rationale/workaround. wasn't aware of this rule.
There was a problem hiding this comment.
yeah, had to clarify this recently on a security PR against release-1.10. The go directive isn't just a minimum toolchain version; it also selects some of the default settings that get compiled into the binary, so raising it on a release branch can silently change runtime behavior.
The trusted-ref copy is written to ${WORK}/check-go-directive-policy.sh so
the invocation in the next step matches the path in the repository rather
than a generic check.sh.
Document that --base-ref is the branch the pull request targets, so a pull
request against main or a topic branch is out of scope, and that a raise
parked on an intermediate branch is still caught by the pull request that
finally targets the release branch.
Co-authored-by: Nick Boldt <nickboldt@gmail.com>
Assisted-by: OpenCode
Address the remaining review findings from the Qodo pass: - a go.mod path that cannot be read now exits 2 instead of passing as "no go directive"; the workflow always writes both files (empty when a side has no Go module), so an unreadable file means the invocation is wrong, not that a side predates the module; - the workflow also runs on `edited`, so a pull request retargeted from main to a release branch is judged against the branch it ends up targeting rather than the one it was opened against; - a kind/security-labeled raise must keep the base branch's `godebug default=` pin unchanged when the base carries one, because that pin is what preserves the branch-cut GODEBUG defaults across the raise; a base without a pin, a branch cut before the pin existed, has nothing to preserve and is not required to grow one. Assisted-by: OpenCode
The release-* glob also matched automation parking branches such as release-1.10-automated-base-images, which are intermediate branches, not protected release branches — a pull request targeting one would have been judged as if it targeted the release branch itself, and could have failed the very base-image automation this check exists to guard. The scope is now release-<major>.<minor> only (release-2.1, release-1.10), matched on the whole branch name. Parking branches, topic branches, the legacy X.Y.x branches, and main are out of scope: whatever they carry is judged by the pull request that finally targets the release branch. Co-authored-by: Nick Boldt <nickboldt@gmail.com> Assisted-by: OpenCode
|
go directive on a release branch



Description
A release branch's
godirective ingo.modis frozen at branch cut: it is the branch's compatibility floor for every consumer and it selects the GODEBUG defaults compiled into the binary.The same policy guard in
rhdh-skillswas defeated in practice: a base-image run from an installed copy of therhdh-base-imagesskill that predated the guard raisedgo 1.26.0→1.27.0onrhdh-must-gatherrelease-2.1(rhdh-must-gather#648), and the auto-approve workflow merged it. The same automation covers this repository, so the branch has to protect itself.This adds
hack/check-go-directive-policy.shand aGo Directive Policyworkflow that comparesgo.modat the pull request base and head:toolchainis not checked — it follows the go-toolset image on every branch;kind/securitylabel, which Renovate adds to its vulnerability alerts. The label is the contract: without it the check fails, so accepting a raise is a deliberate reviewer action.The check cannot be disabled by the pull request it judges
The workflow uses
pull_request_target, so GitHub runs the workflow definition andhack/check-go-directive-policy.shfrom the default branch, never from the pull request. The proposed head is read strictly as data:refs/pull/N/headis fetched into a private ref,go.modis read withgit showinto a file, and the script compares two files without invoking git at all. Nothing from the pull request is checked out or executed. Permissions arecontents: readonly and no secrets are used.pull_request_targetalso runs when the pull request's target branch does not carry this file, so the check covers a release branch as soon asmainhas it — no backports needed forrelease-2.1,release-1.10, orrelease-1.9.PR acceptance criteria
How to test changes / Special notes to the reviewer
Verified locally against a fixture repository: raise on
release-*fails; unchanged, revert, and toolchain-only change pass;mainpasses; a raise withkind/securitypasses; missing arguments exit 2. The fetch-and-read pipeline was exercised against real refs.shellcheckandactionlintare clean.Still needed outside this PR: add
Go Directive Policyto the required status checks forrelease-*. Without that, Prow/auto-merge still merges when the other required checks pass.Assisted-by: OpenCode