Replaces `scripts/gpgkms` with [`github.com/coder/gpgkms`](https://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" "security@coder.com" "-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.
34 lines
1.2 KiB
Bash
Executable File
34 lines
1.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# Runs github.com/coder/gpgkms (a go.mod tool dependency) with the
|
|
# OpenPGP identity of the Cloud KMS release signing key.
|
|
#
|
|
# Usage: ./scripts/gpgkms.sh public-key|sign [flags...]
|
|
#
|
|
# The OpenPGP key is derived from the KMS public key and the identity below, so
|
|
# none of it may change: the creation time is part of the fingerprint, and the
|
|
# user ID and lifetime are covered by the self-signature. -fingerprint makes
|
|
# gpgkms fail if the KMS key or creation time ever change; it does not cover the
|
|
# user ID or lifetime. Credentials come from Application Default Credentials
|
|
# (GOOGLE_APPLICATION_CREDENTIALS).
|
|
|
|
set -euo pipefail
|
|
# shellcheck source=scripts/lib.sh
|
|
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
|
|
|
|
if [[ $# -lt 1 ]]; then
|
|
error "Usage: $0 public-key|sign [flags...]"
|
|
fi
|
|
cmd="$1"
|
|
shift
|
|
|
|
# go tool needs a working directory inside the module; it is not changed here
|
|
# so relative paths in the arguments keep working.
|
|
exec go tool github.com/coder/gpgkms/cmd/gpgkms "$cmd" \
|
|
-name "Coder Release Signing Key" \
|
|
-email "security@coder.com" \
|
|
-created "2026-11-16T00:00:00Z" \
|
|
-lifetime "$((4 * 365 * 24))h" \
|
|
-fingerprint "0F685EFE0AE5A8182A473DD86E3A8E5613707520" \
|
|
"$@"
|