Skip to content

chore: sign with github.com/coder/gpgkms instead of scripts/gpgkms - #32308

Merged
deansheather merged 4 commits into
mainfrom
secrets/gpgkms-module
Nov 18, 2026
Merged

deansheather merged 4 commits into
mainfrom
secrets/gpgkms-module

Conversation

@deansheather

@deansheather deansheather commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Replaces scripts/gpgkms with github.com/coder/gpgkms v0.2.0, the same code extracted into a shared module (terraform-provider-coder already signs its releases with it). v0.2.0 also rejects keys that aren't HSM-backed (gpg-release is HSM, and the check reads protectionLevel from the existing GetPublicKey call, so no new IAM is needed), limits each KMS request to a minute, and writes -out atomically.

  • go.mod: gpgkms is a tool dependency, so the version is pinned in go.mod/go.sum and Dependabot keeps it current. This bumps go-crypto 1.4.1 → 1.5.2, google.golang.org/api 0.308.0 → 0.311.0 and circl 1.6.3 → 1.6.5, plus a few indirect dependencies. go-crypto is now only indirect: nothing else in coder/coder imports it.
  • scripts/gpgkms.sh (new): runs it with go tool (like scripts/format_go_file.sh does for gofumpt and gci), passing the release key's OpenPGP identity (name, email, creation time, 4-year lifetime). The library takes these as flags instead of hardcoding them, so they now live in one place.
    • It also pins -fingerprint 0F685EFE0AE5A8182A473DD86E3A8E5613707520, so signing and public-key fail if the KMS key or creation time ever change. That's the fingerprint every current main build prints (e.g. run 44031030839), and I recomputed it from the KMS public key and the creation time alone, without signing anything. The fingerprint doesn't cover the user ID or lifetime; the equivalence check below does.
  • scripts/sign_with_gpg.sh and the "Print GPG KMS public key" step in build.yaml call the wrapper instead of ./scripts/gpgkms. Signatures stay armored .v2.asc files, as before.
  • scripts/gpgkms/ is deleted.

Same key, same signatures

The OpenPGP key's fingerprint depends on these exact inputs, so I checked that nothing changed. With a local RSA-4096 key standing in for KMS, the deleted newEntity/writePublicKey/sign produce the same output as the gpgkms CLI with the flags read out of scripts/gpgkms.sh:

  • The public key is byte for byte identical.
  • A signature with -prepend is armored the same way and has the same length (only the timestamp differs). Both the prepended signature and the KMS signature verify in both outputs.
  • Changing the lifetime in the wrapper by one hour makes the comparison fail, so the check is sensitive.
$ git -C gpgkms describe --tags
v0.2.0
$ WRAPPER_ARGS_FILE=wrapper-args.txt go test ./cmd/gpgkms -run TestCoderWrapperMatchesOldCoderCode -count=3 -v
=== RUN   TestCoderWrapperMatchesOldCoderCode
    equiv_coder_test.go:40: wrapper args: ["-name" "Coder Release Signing Key" "-email" "[email protected]" "-created" "2026-11-16T00:00:00Z" "-lifetime" "35040h"]
--- PASS: TestCoderWrapperMatchesOldCoderCode (0.33s)
--- PASS: TestCoderWrapperMatchesOldCoderCode (0.11s)
--- PASS: TestCoderWrapperMatchesOldCoderCode (0.20s)
ok  	github.com/coder/gpgkms/cmd/gpgkms	0.634s

# with -lifetime 35041h
    equiv_coder_test.go:56: public keys differ:
FAIL

# with the wrapper's -fingerprint pin and a random test key
    derived key has fingerprint 9794B34B5E098DE61DD6CE247E0DFD4BF203C917, want 0F685EFE0AE5A8182A473DD86E3A8E5613707520 (wrong -key, -created or KMS key?)

(The byte-for-byte comparison runs without -fingerprint, since the test key is random.)

gpgkms also has its own compatibility test against this identity (compat_test.go).

Other checks:

$ ./scripts/gpgkms.sh public-key                 # from the repo root (build.yaml)
gpgkms: -key is required
$ cd scripts && ./gpgkms.sh public-key           # from scripts/ (build_go.sh -> execrelative)
gpgkms: -key is required
$ ./gpgkms.sh sign -key x -prepend ../no-such-file -out o.asc ../go.mod   # relative paths resolve from the caller
gpgkms: read prepend signature: open ../no-such-file: no such file or directory
$ shellcheck -x scripts/gpgkms.sh scripts/sign_with_gpg.sh   # clean
$ shfmt -d scripts/gpgkms.sh scripts/sign_with_gpg.sh        # clean
$ actionlint .github/workflows/build.yaml                    # clean
$ go build ./... && go mod tidy -diff                        # clean

Not run here: real signing through Cloud KMS. The first main build after merging prints the public key in the job summary; it should be identical to the one printed by current main builds.


AI disclosure: this PR was written by an AI coding agent (Xum) at my direction, and the agent ran the verification above. It stays a draft until I've reviewed it.

Replaces scripts/gpgkms with the shared github.com/coder/gpgkms module (v0.1.2),
pinned as a go.mod tool dependency. scripts/gpgkms.sh supplies the release key's
OpenPGP identity, which the module takes as flags; the derived public key is
byte-identical to the one scripts/gpgkms produced.
@deansheather
deansheather temporarily deployed to main November 17, 2026 07:13 — with GitHub Actions Inactive
@deansheather
deansheather temporarily deployed to main November 17, 2026 07:13 — with GitHub Actions Inactive
go tool is how the repo runs its other go.mod tools; it caches the build and
needs no temporary directory.
@deansheather
deansheather temporarily deployed to main November 17, 2026 07:20 — with GitHub Actions Inactive
@deansheather
deansheather temporarily deployed to main November 17, 2026 07:20 — with GitHub Actions Inactive
@deansheather
deansheather marked this pull request as ready for review November 17, 2026 07:24
@deansheather
deansheather requested a review from a team November 17, 2026 07:24
@deansheather
deansheather temporarily deployed to main November 17, 2026 07:24 — with GitHub Actions Inactive
@deansheather

Copy link
Copy Markdown
Collaborator Author

@codex review

@deansheather

Copy link
Copy Markdown
Collaborator Author

@codex security-review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-17T07:53:58.136790Z a6409d5 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Summary

  • Security review found that caller-supplied arguments were appended after the pinned OpenPGP identity flags, allowing duplicate name, email, created, or lifetime flags to override the audited release-signing identity.
  • Updated the wrapper to reject both single-dash and double-dash forms of protected identity flags, including flag=value syntax, while preserving argument handling after --. scripts/gpgkms.shL23-L34
  • The wrapper continues to invoke the pinned gpgkms tool with the expected release-key identity and four-year lifetime. scripts/gpgkms.shL36-L43
  • Committed the change as b805677 (fix(scripts): prevent release identity overrides) and recorded the follow-up pull request through make_pr.

Testing

  • ✅ bash -n scripts/gpgkms.sh
  • ✅ for flag in -name=attacker --email [email protected] -created=1970-01-01T00:00:00Z --lifetime=0h; do ...; done — verified every protected identity override is rejected.
  • ✅ PATH="$tmp:$PATH" ./scripts/gpgkms.sh sign -key example -out out.asc input.tar — verified normal arguments are forwarded with the pinned identity values.
  • ✅ diff -u <(cat <<'EOF' ... EOF) "$tmp/args" — verified the exact go tool gpgkms argument sequence.
  • ✅ git diff --check
  • ✅ git status --short --branch — working tree is clean after the commit.

View task →

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: a6409d5045

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@deansheather
deansheather temporarily deployed to main November 17, 2026 08:00 — with GitHub Actions Inactive
@deansheather
deansheather temporarily deployed to main November 17, 2026 08:00 — with GitHub Actions Inactive
@deansheather
deansheather temporarily deployed to main November 17, 2026 08:02 — with GitHub Actions Inactive
@deansheather
deansheather temporarily deployed to main November 17, 2026 08:02 — with GitHub Actions Inactive
@deansheather
deansheather merged commit d974fef into main Nov 18, 2026
31 of 32 checks passed
@deansheather
deansheather deleted the secrets/gpgkms-module branch November 18, 2026 04:37
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 18, 2026

This branch had an error being deployed

1 failed and 1 inactive deployments
main — 1f391772 Deployed Nov 18, 2026 by deansheather via cla #259130
docs-preview — 1f391772 Deployed Nov 18, 2026 by deansheather via cleanup #199
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants