feat(release): sign checksums and publish an SBOM
Releases carry SHA256SUMS signed in the minisign format (prehashed Ed25519, the release tag as trusted comment) and an SPDX SBOM of the Go modules and the npm packages the frontend build bundles. internal/signing signs and verifies; the release keys are committed in release.pub and compiled in, so the self-updating agents can check their downloads. Without the RELEASE_SIGNING_KEY secret a release is published unsigned with a warning. Closes #34 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
d2d6bf9f44
commit
b1ca8eb19f
9 files changed
+676
-5
No files matched your search
@@ -0,0 +1,85 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/signing"
|
||||
)
|
||||
|
||||
// signFile signs path for release tag; the tag becomes the trusted comment,
|
||||
// so a signature cannot be passed off for another release.
|
||||
func signFile(path, tag string) error {
|
||||
if _, err := parseVersion(tag); err != nil {
|
||||
return err
|
||||
}
|
||||
raw := os.Getenv("RELEASE_SIGNING_KEY")
|
||||
if raw == "" {
|
||||
return errors.New("release: RELEASE_SIGNING_KEY is not set")
|
||||
}
|
||||
key, err := signing.ParsePrivateKey(raw)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !trusted(key.Public()) {
|
||||
return fmt.Errorf("release: key %s is not in internal/signing/release.pub", key.Public().IDString())
|
||||
}
|
||||
msg, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sig, err := signing.Sign(key, msg, tag)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(path+".minisig", sig, 0o644)
|
||||
}
|
||||
|
||||
func trusted(k signing.PublicKey) bool {
|
||||
for _, r := range signing.ReleaseKeys() {
|
||||
if r.ID == k.ID && r.Key.Equal(k.Key) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func verifyFile(path string) error {
|
||||
msg, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sig, err := os.ReadFile(path + ".minisig")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tag, err := signing.Verify(signing.ReleaseKeys(), msg, sig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("%s: good signature for %s\n", path, tag)
|
||||
return nil
|
||||
}
|
||||
|
||||
// keygen writes a new signing key to secretPath, readable only by the
|
||||
// owner, and prints the public key for internal/signing/release.pub.
|
||||
func keygen(secretPath string) error {
|
||||
k, err := signing.GenerateKey()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
f, err := os.OpenFile(secretPath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0o600)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := fmt.Fprintln(f, k.String()); err != nil {
|
||||
_ = f.Close()
|
||||
return err
|
||||
}
|
||||
if err := f.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("untrusted comment: uptimesebi release key %s\n%s\n", k.Public().IDString(), k.Public())
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user