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,92 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/signing"
|
||||
)
|
||||
|
||||
func TestSBOM(t *testing.T) {
|
||||
self, err := os.Executable()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
pj := []byte(`{"scripts":{"build":"tailwindcss -o x && cp node_modules/axios/dist/a.js node_modules/@fontsource/ibm-plex-sans/files/b.woff2 out/"}}`)
|
||||
pl := []byte(`{"packages":{"node_modules/axios":{"version":"1.21.1"},"node_modules/@fontsource/ibm-plex-sans":{"version":"5.3.0"},"node_modules/tailwindcss":{"version":"4.3.5"}}}`)
|
||||
v, _ := parseVersion("v1.2.3")
|
||||
raw, err := sbom(v, []string{self}, pj, pl, time.Date(2026, 1, 2, 3, 4, 5, 0, time.UTC), "https://git.example/o/r")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var doc spdxDoc
|
||||
if err := json.Unmarshal(raw, &doc); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
purls := map[string]bool{}
|
||||
ids := map[string]bool{}
|
||||
for _, p := range doc.Packages {
|
||||
if ids[p.SPDXID] {
|
||||
t.Errorf("duplicate SPDXID %s", p.SPDXID)
|
||||
}
|
||||
ids[p.SPDXID] = true
|
||||
for _, r := range p.ExternalRefs {
|
||||
purls[r.Locator] = true
|
||||
}
|
||||
}
|
||||
for _, want := range []string{"pkg:npm/axios@1.21.1", "pkg:npm/%40fontsource/ibm-plex-sans@5.3.0", "pkg:golang/golang.org/x/crypto@", "pkg:golang/stdlib@v1."} {
|
||||
if !hasPrefix(purls, want) {
|
||||
t.Errorf("SBOM lacks %s", want)
|
||||
}
|
||||
}
|
||||
if hasPrefix(purls, "pkg:npm/tailwindcss") {
|
||||
t.Error("build tools are not shipped")
|
||||
}
|
||||
if doc.Packages[0].VersionInfo != "v1.2.3" || doc.Packages[0].LicenseDeclared != "AGPL-3.0-only" ||
|
||||
len(doc.Relationships) != len(doc.Packages) || doc.CreationInfo.Created != "2026-01-02T03:04:05Z" {
|
||||
t.Errorf("document = %+v", doc.Packages[0])
|
||||
}
|
||||
|
||||
if _, err := bundledNPM([]byte(`{"scripts":{"b":"cp node_modules/missing/x ."}}`), pl); err == nil {
|
||||
t.Error("a package missing from the lock file was accepted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSignFile(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
path := filepath.Join(dir, "SHA256SUMS")
|
||||
if err := os.WriteFile(path, []byte("abc x.tar.gz\n"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
k, _ := signing.GenerateKey()
|
||||
t.Setenv("RELEASE_SIGNING_KEY", k.String())
|
||||
if err := signFile(path, "v1.0.0"); err == nil || !strings.Contains(err.Error(), "release.pub") {
|
||||
t.Errorf("a key not in release.pub signed: %v", err)
|
||||
}
|
||||
t.Setenv("RELEASE_SIGNING_KEY", "")
|
||||
if err := signFile(path, "v1.0.0"); err == nil {
|
||||
t.Error("signed without a key")
|
||||
}
|
||||
if err := keygen(filepath.Join(dir, "k")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := keygen(filepath.Join(dir, "k")); err == nil {
|
||||
t.Error("keygen overwrote a key")
|
||||
}
|
||||
if st, _ := os.Stat(filepath.Join(dir, "k")); st.Mode().Perm() != 0o600 {
|
||||
t.Errorf("key file mode = %v", st.Mode())
|
||||
}
|
||||
}
|
||||
|
||||
func hasPrefix(set map[string]bool, prefix string) bool {
|
||||
for s := range set {
|
||||
if strings.HasPrefix(s, prefix) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
Reference in new issue
Block a user