Repository navigation
fix(gcb): pin cmrel install in GCB to the invoking binary's commit - #334
cert-manager-prow[bot] merged 2 commits into
Conversation
The privileged GCB jobs installed cmrel with
`go install .../cmrel@${_RELEASE_REPO_REF}` defaulting to the mutable
`master` ref, so any commit landed on cert-manager/release@master would
execute inside the build holding GITHUB_TOKEN, the decrypted docker
config and KMS signing access (CWE-829). There was no pin, module-sum or
signature binding the submitted cloudbuild.yaml to the code that ran.
Resolve the ref from cmrel's own build info (runtime/debug.ReadBuildInfo)
and set _RELEASE_REPO_REF to the exact commit the invoking binary was
built from, so GCB runs the same code the release manager built and ran
locally rather than re-resolving master. This is wired into stage,
publish and bootstrap-pgp with no change to operator invocation.
It fails closed: a modified working tree, an unstamped ("(devel)") build
or missing build info returns an error instead of falling back to a
mutable ref. The cloudbuild.yaml defaults become a
PINNED_CMREL_COMMIT_SHA_REQUIRED placeholder backstop; the manually
submitted helm test job documents supplying the SHA via --substitutions.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Felix Phipps <[email protected]>
|
Hi @FelixPhipps. Thanks for your PR. I'm waiting for a cert-manager member to verify that this patch is reasonable to test. If it is, they should reply with Tip We noticed you've done this a few times! Consider joining the org to skip this step and gain Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions 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. |
|
/ok-to-test |
SgtCoDFish
left a comment
There was a problem hiding this comment.
I think there are a few tweaks that would help readability here, and I'd really like to ensure we don't make development harder here!
| // Pin the GCB build to the commit this cmrel binary was built from, rather than | ||
| // installing cmrel from a mutable ref (e.g. "master") inside the privileged build. | ||
| repoRef, err := releaseRepoRef() | ||
| if err != nil { | ||
| return fmt.Errorf("failed to determine cmrel commit to pin GCB build: %w", err) | ||
| } | ||
| log.Printf("Pinning GCB cmrel install to cert-manager/release@%s", repoRef) | ||
| build.Substitutions["_RELEASE_REPO_REF"] = repoRef |
There was a problem hiding this comment.
suggestion: I understand the reasoning for adding this and it's a good default, but I think as written it's maybe going to make development of cmrel more difficult.
When I'm working on a change to cmrel itself, I explicitly want to test a "dirty" version and I might well change the cloudbuild.yaml to point to a development branch I've pushed somewhere.
Can we add some sort of flag to opt out of this SHAsum pinning?
There was a problem hiding this comment.
Added --skip-cmrel-pin, with it set, cmrel leaves _RELEASE_REPO_REF as written in the cloudbuild.yaml (so you can point at a pushed dev branch) and logs a warning. By default it is left off
Follow-up to pinning the GCB cmrel install to the invoking binary's commit, applying maintainer review feedback: - Move ref resolution out of cmd/cmrel/cmd (which is one-file-per subcommand) into a new pkg/releaseref package, exposing Resolve(). - Handle the !ok from debug.ReadBuildInfo() in Resolve() and pass only the *debug.BuildInfo into fromBuildInfo, keeping the resolver a single-responsibility, easily testable function. - Add a --skip-cmrel-pin opt-out to publish so cmrel development against a pushed dev branch is not blocked by the fail-closed pin; pinning remains the secure default. - Revert the stage and bootstrap-pgp changes (code and cloudbuild.yaml defaults) as those subcommands are effectively unused; only publish is pinned. Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Felix Phipps <[email protected]>
SgtCoDFish
left a comment
There was a problem hiding this comment.
/lgtm
/approve
With the skip option available there's little risk to this, so I'm happy to merge. Thank you 🚀
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: SgtCoDFish The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
cmrel stage, makestage, publish and bootstrap-pgp read their Cloud Build config from ./gcb/<cmd>/cloudbuild.yaml, so a release manager had to run cmrel from a checkout of this repository. Since cert-manager#334 the publish job also pins its own cmrel install to the commit the invoking binary was built from, which means the checkout and the binary have to match exactly, and nothing checks that they do. A stale checkout submits the wrong config silently. Building from the checkout instead is fragile too: Go marks the binary as modified if git status shows anything, including untracked files, and the pin then refuses to run. Embed the four configs in the binary. The config is now bound to the same commit as the pin, so `go install github.com/cert-manager/release/cmd/cmrel@<ref>` is the whole install procedure. --cloudbuild stays as an override for cmrel development and defaults to the embedded config. The tests fail if an embedded config stops parsing or if the publish config loses its fail-closed _RELEASE_REPO_REF placeholder. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Richard Wall <[email protected]>
Description
Problem
The privileged Google Cloud Build jobs install the release orchestrator with go install github.com/cert-manager/release/cmd/cmrel@${_RELEASE_REPO_REF}, defaulting to the mutable master ref — and cmrel then runs inside the build holding real credentials, so whatever master points at is executed at face value. Any commit landed on cert-manager/release@master is therefore trusted implicitly:
write, and KMS AsymmetricSign on the production signing key.
Solution
Resolve the ref from cmrel's own build info (runtime/debug.ReadBuildInfo) and set _RELEASE_REPO_REF to the exact commit the invoking binary was built from, so GCB runs the same code the release manager built and ran locally instead of re-resolving master. Wired into stage, publish, and bootstrap-pgp with no change to operator invocation. It fails closed: a modified tree, a (devel)/unstamped build, or missing build info errors out rather than falling back to a mutable ref. The cloudbuild.yaml defaults become a PINNED_CMREL_COMMIT_SHA_REQUIRED placeholder backstop; the manually-submitted helm test documents supplying the SHA via --substitutions. Legitimate releases behave unchanged.
Test plan