Skip to content

fix(gcb): pin cmrel install in GCB to the invoking binary's commit - #334

Merged
cert-manager-prow[bot] merged 2 commits into
cert-manager:masterfrom
FelixPhipps:unpinned-cmrel-master
Jul 13, 2026
Merged

cert-manager-prow[bot] merged 2 commits into
cert-manager:masterfrom
FelixPhipps:unpinned-cmrel-master

Conversation

@FelixPhipps

Copy link
Copy Markdown
Member

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:

  • Trust-domain bridge: go install …@master resolves the branch tip at build time with no commit pin, so a GitHub push executes in the GCP build environment.
  • No integrity binding: the main module is exempt from go.sum verification — nothing binds the submitted cloudbuild.yaml to the code that runs (unlike cosign, pinned at @v1.13.6).
  • Credential blast radius: the fetched code inherits GITHUB_TOKEN, the decrypted DOCKER_CONFIG, staging-bucket
    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

  • go build ./cmd/cmrel from a clean checkout embeds vcs.revision matching HEAD with vcs.modified=false, releaseRepoRef() pins GCB to that commit and operator invocation and the resulting go install …@ flow are unchanged.
  • TestReleaseRepoRefFromBuildInfo/clean_working_tree_pins_to_the_commit — a clean VCS build pins to vcs.revision.
  • TestReleaseRepoRefFromBuildInfo/modified_working_tree_fails_closed — a dirty tree is rejected before submit.
  • TestReleaseRepoRefFromBuildInfo/{devel,no_revision,no_build_info} — unstamped/unknown builds fail closed; module_install pins to Main.Version.
  • Verified a real go build embeds vcs.revision/vcs.modified, and all four cloudbuild.yaml files still parse via gcb.LoadBuild.
  • Existing pkg/cmd tests pass unchanged.
  • go build ./..., go vet ./..., and gofmt clean.

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]>
@cert-manager-prow cert-manager-prow Bot added dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 9, 2026
@cert-manager-prow

Copy link
Copy Markdown
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

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.

@cert-manager-prow cert-manager-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 9, 2026
@FelixPhipps

Copy link
Copy Markdown
Member Author

/ok-to-test

@cert-manager-prow cert-manager-prow Bot added ok-to-test and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 10, 2026

@SgtCoDFish SgtCoDFish left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

Comment thread pkg/releaseref/releaseref.go Resolved
Comment thread cmd/cmrel/cmd/releaseref.go Resolved
Comment thread cmd/cmrel/cmd/bootstrap_pgp.go Resolved
Comment thread cmd/cmrel/cmd/publish.go Outdated
Comment on lines +217 to +224
// 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread cmd/cmrel/cmd/stage.go Resolved
Comment thread cmd/cmrel/cmd/stage.go Resolved
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 SgtCoDFish left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve

With the skip option available there's little risk to this, so I'm happy to merge. Thank you 🚀

@cert-manager-prow cert-manager-prow Bot added the lgtm Indicates that a PR is ready to be merged. label Jul 13, 2026
@cert-manager-prow

Copy link
Copy Markdown
Contributor

[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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@cert-manager-prow cert-manager-prow Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 13, 2026
@cert-manager-prow
cert-manager-prow Bot merged commit a109b72 into cert-manager:master Jul 13, 2026
wallrj-cyberark pushed a commit to wallrj/release that referenced this pull request Nov 25, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. lgtm Indicates that a PR is ready to be merged. ok-to-test size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants