Skip to content

fix(sign): sign Helm charts with the KMS key again - #431

Merged
cert-manager-prow[bot] merged 1 commit into
cert-manager:masterfrom
wallrj-cyberark:fix-kms-pgp-signer
Nov 25, 2026
Merged

cert-manager-prow[bot] merged 1 commit into
cert-manager:masterfrom
wallrj-cyberark:fix-kms-pgp-signer

Conversation

@wallrj-cyberark

@wallrj-cyberark wallrj-cyberark commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

cmrel sign helm cannot sign with the KMS key, so no cert-manager build from master can be staged. This PR fixes it.

The v1.22.0-alpha.0 staging build failed while creating the chart's .prov file:

panic: openpgp: unknown signer type in NewSignerPrivateKey
  github.com/ProtonMail/[email protected]/openpgp/packet/private_key.go:170
  github.com/cert-manager/[email protected]/pkg/sign/kmspgp.go:150

Why it broke

  • 44fbee7 (the Helm v4 upgrade) moved pkg/sign from golang.org/x/crypto/openpgp to ProtonMail/go-crypto.
  • go-crypto's packet.NewSignerPrivateKey only accepts in-memory RSA, ECDSA and EdDSA private keys. It panics on any other crypto.Signer, including our KMS signer.
  • cert-manager master has used cmrel v1.13.0 since the makefile-modules update on 13 September. release-1.21 and release-1.20 still use a 2024 cmrel, which is why v1.21.3 and v1.20.5 built. v1.22.0-alpha.0 is the first build from master since then.

What changes

  • deriveEntity builds the private key packet by hand. go-crypto's RSA signing already accepts any crypto.Signer (signature.go#L1003-L1004). The PubKeyAlgo and KeyId fix-ups are no longer needed, because both come from the copied public key.
  • cmrel gcb bootstrap-pgp now writes a usable public key. It reaches the same code, so it panicked too. Without a second change it would print a key with no identity signature, because go-crypto serializes Identity.Signatures, not SelfSignature (keys.go#L798). The identity code moves into addSelfSignedIdentity, which sets both.
  • KMS signing errors are logged. go-crypto drops the error from an RSA crypto.Signer (its err is redeclared inside the case), so a failed KMS call would otherwise only show up later as a missing signature.
  • HelmChart and BootstrapPGPFromGCP are split so that the parts after KMS can be tested.

What we want from you

Please review. After it merges, we will tag v1.13.1, point cert-manager master at it, and use it for v1.22.0-alpha.1 (cert-manager/cert-manager#9553).

How this was tested, and what it does not prove
  • New test TestBootstrapKeyVerifiesSignedChart uses a stand-in KMS signer: a crypto.Signer that only accepts SHA-512 digests, like the real key. It bootstraps the armored public key, signs a packaged chart, then verifies the chart with Helm's Verify, using only the armored key.
  • With NewSignerPrivateKey put back, the test fails with the same panic as the staging build.
  • Without the Signatures line, it fails with openpgp: invalid data: v4 entity without any identities.
  • make test, go vet ./... and gofmt pass.
  • This has not been run against the real KMS key. The first real run will be the v1.22.0-alpha.1 staging build.

[with Claude]

@cert-manager-prow

Copy link
Copy Markdown
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@cert-manager-prow cert-manager-prow Bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. labels Nov 24, 2026

@wallrj-cyberark wallrj-cyberark left a comment

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.

Notes for reviewers on the two places where the change is not obvious from the diff.

Comment thread pkg/sign/kmspgp.go
// > // supports both *rsa.PrivateKey and crypto.Signer
return &openpgp.Entity{
PrimaryKey: publicKey,
PrivateKey: &packet.PrivateKey{

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.

The old code set PubKeyAlgo and KeyId on the private key after NewSignerPrivateKey, to work around key IDs not matching. Copying *publicKey into the packet gives it the same algorithm and key ID as PrimaryKey, so both lines are no longer needed. The test checks this: verification looks the key up by the signature's issuer key ID.

Comment thread pkg/sign/kmspgp_test.go Outdated

// publicEntity returns the public half of entity with a self-signed identity,
// which go-crypto needs before it will use the key to verify.
func publicEntity(t *testing.T, entity *openpgp.Entity) *openpgp.Entity {

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.

This repeats the identity self-signing from BootstrapPGPFromGCP. go-crypto will not use a key to verify without a self-signed identity. I kept it in the test rather than refactoring BootstrapPGPFromGCP, to keep this fix small.

@cert-manager-prow cert-manager-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 24, 2026
- `cmrel sign helm` panics with "openpgp: unknown signer type in
  NewSignerPrivateKey" since the move to ProtonMail/go-crypto for
  Helm v4. That function only accepts in-memory private key types,
  and the KMS signer is not one of them.
- Build the private key packet by hand instead. go-crypto's RSA
  signing already accepts any crypto.Signer.
- `cmrel gcb bootstrap-pgp` reaches the same code, and would then
  print a public key with no identity signature: go-crypto serializes
  `Identity.Signatures`, not `SelfSignature`. Set both.
- Log KMS signing errors in kmssigner, because go-crypto drops the
  error returned by an RSA crypto.Signer.
- Add a test that bootstraps a key and signs a chart with a stand-in
  KMS signer, then verifies the chart with helm using only the
  armored public key. It fails without either fix.

Signed-off-by: Richard Wall <[email protected]>
Co-Authored-By: Claude <[email protected]>

@wallrj-cyberark wallrj-cyberark left a comment

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.

Updated after a review pass. cmrel gcb bootstrap-pgp now writes the identity signature, KMS errors are logged, and the test now checks the whole path: it bootstraps the key, signs a chart, and verifies it with helm using only the armored key. My earlier inline comments are about the previous commit and no longer apply.

@wallrj-cyberark

Copy link
Copy Markdown
Member Author

This fix worked against the real KMS key in the v1.22.0-alpha.0 release. Staging signed the chart with it, and helm verify accepts the result using the published cert-manager keyring.

We tested it stacked with #376 and #377, so this shows the three work together.

Evidence from the release

The first tag-triggered build used cert-manager's own cmrel pin (v1.13.0) and failed with the panic this PR fixes. I staged again with cmrel makestage from a laptop, passing CMREL_VERSION=v1.13.1-0.20261124144211-c647a8274a51 (the stack with this PR) to make upload-release. The build log shows:

downloaded .../tools/[email protected]_go1.27.4_linux_amd64
.../_bin/tools/cmrel sign helm --chart-path "cert-manager-v1.22.0-alpha.0.tgz" --key "projects/cert-manager-release/.../cert-manager-release-signing-key/cryptoKeyVersions/1"

helm verify --keyring cert-manager-keyring-2021-09-20-1020CF3C033D4F35BAE1C19E1226061C665DF13E.gpg on the staged chart:

Signed by: cert-manager Maintainers <[email protected]>
Using Key With Fingerprint: 1020CF3C033D4F35BAE1C19E1226061C665DF13E
Chart Hash Verified: sha256:2f69c97394eb0653ad448e590b579835b3752daf54f7fc39413fdbf118ad850c

helm pull --verify on the published OCI chart gives the same chart hash.

What this release did not test
  • bootstrap-pgp did not run. Only the unit test covers its identity-signature change.
  • cert-manager master still pins cmrel v1.13.0, so the next tag-triggered build will fail the same way. We need a release of this repository with this fix, and cert-manager pointed at it, before beta.0.

[with Claude]

@wallrj
wallrj marked this pull request as ready for review November 24, 2026 17:26
@cert-manager-prow cert-manager-prow Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 24, 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.

/lgtm
/approve

My main reaction is "if it works it works" and there's not much to review here.

Given the general rubbishness of PGP I look at this and think "should we just drop helm chart signatures altogether so we don't have to deal with this any more"... but I guess the signing hasn't really needed much maintenance since I wrote it and a little maintenance is fine - as such, approving.

@cert-manager-prow cert-manager-prow Bot added the lgtm Indicates that a PR is ready to be merged. label Nov 25, 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 Nov 25, 2026
@cert-manager-prow
cert-manager-prow Bot merged commit e9adf9b into cert-manager:master Nov 25, 2026
3 checks passed
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. 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