oficina / equipo Public

hosted: cert bundle writes the controller's certificate set

sign writes one certificate; the controller reads controller/
certificates.json as {"certificates":[...]}. bundle writes that set from
sign's output, verifying each certificate under the controller's key
file and refusing duplicates. The dev plan runs it in place of its jq
wrap; the account plan's 6.4 names it. Mutations B1-B4 recorded.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev ef284398321fcdb58ab33681931b5461ff274ca9 parent 671ff55
5 files changed, +250 −10
  • cmd/equipo-hosted-certify/bundle_test.go +125 −0
  • cmd/equipo-hosted-certify/main.go +89 −7
  • docs/superpowers/plans/2026-11-30-hosted-prod-account-plan.md +4 −1
  • docs/superpowers/plans/2026-12-01-hosted-2-dev-live-plan.md +4 −2
  • docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md +28 −0
diff --git a/cmd/equipo-hosted-certify/bundle_test.go b/cmd/equipo-hosted-certify/bundle_test.go
new file mode 100644
index 00000000..af02fedf
--- /dev/null
+++ b/cmd/equipo-hosted-certify/bundle_test.go
@@ -0,0 +1,125 @@
+package main
+
+import (
+ "context"
+ "crypto/ed25519"
+ "encoding/base64"
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+ "time"
+
+ "amadan.net/oficina/equipo/internal/hostedcert"
+ "amadan.net/oficina/equipo/internal/hostedctl/ctlcert"
+ "amadan.net/oficina/equipo/internal/isolatedjob"
+)
+
+// signed runs sign over passing evidence for launch (its own evidence
+// ID) and returns the certificate file it wrote, exactly as Paul's
+// signing machine does.
+func signed(t *testing.T, launch string) string {
+ t.Helper()
+ m := manifest()
+ e := evidence(passingReport(m, launch))
+ e.EvidenceID = "evidence-" + launch
+ f := write(t, e, ctlKey, m)
+ out := filepath.Join(t.TempDir(), "certificate.json")
+ if code, stdout, stderr := runCmd(t, "sign", "-evidence", f.evidence, "-release", f.release, "-controller-pub", f.controllerPub,
+ "-key", f.key, "-key-id", "paul-1", "-out", out); code != 0 {
+ t.Fatalf("sign = %d %s %s", code, stdout, stderr)
+ }
+ return out
+}
+
+// certKeys writes a certificate key file (controller/cert-keys.json)
+// holding pub under id.
+func certKeys(t *testing.T, id string, pub ed25519.PublicKey) string {
+ t.Helper()
+ path := filepath.Join(t.TempDir(), "cert-keys.json")
+ if err := os.WriteFile(path, []byte(`{"keys":[{"id":"`+id+`","public_key":"`+base64.StdEncoding.EncodeToString(pub)+`"}]}`), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ return path
+}
+
+// TestBundleMeetsTheController (dev drill finding 1): sign writes one
+// certificate; the controller reads controller/certificates.json as a set,
+// {"certificates":[...]}. bundle turns sign's own output into that set,
+// and the controller's loader (ctlcert.Set.Load, what reload runs) takes
+// it with the same key file.
+func TestBundleMeetsTheController(t *testing.T) {
+ a, b := signed(t, "l-1"), signed(t, "l-2")
+ keys := certKeys(t, "paul-1", paulKey.Public().(ed25519.PublicKey))
+ out := filepath.Join(t.TempDir(), "certificates.json")
+ code, stdout, stderr := runCmd(t, "bundle", "-cert-keys", keys, "-cert", a, "-cert", b, "-out", out)
+ if code != 0 {
+ t.Fatalf("bundle = %d %s %s", code, stdout, stderr)
+ }
+ keysJSON, _ := os.ReadFile(keys)
+ certsJSON, err := os.ReadFile(out)
+ if err != nil {
+ t.Fatal(err)
+ }
+ set := ctlcert.NewSet(func(img isolatedjob.ImageDigest, _ isolatedjob.Size) (string, bool) {
+ return evidence(hostedcert.Report{}).ImageVersion, img == image
+ })
+ n, err := set.Load(keysJSON, certsJSON)
+ if err != nil || n != 2 {
+ t.Fatalf("the controller loads the bundle: %d, %v\n%s", n, err, certsJSON)
+ }
+ if !strings.Contains(stdout, `"certificates":2`) || !strings.Contains(stdout, out) {
+ t.Errorf("bundle printed %s", stdout)
+ }
+ // sign's output alone is not a set: the controller refuses it, which
+ // is why the bundle step exists.
+ one, _ := os.ReadFile(a)
+ if _, err := ctlcert.NewSet(nil).Load(keysJSON, one); err == nil {
+ t.Error("the controller loaded a bare certificate as a set")
+ }
+}
+
+// TestBundleRefuses: bundle writes nothing unless every certificate
+// verifies under the key file the controller will use, none is listed
+// twice and each input is one certificate (not already a set).
+func TestBundleRefuses(t *testing.T) {
+ a := signed(t, "l-1")
+ keys := certKeys(t, "paul-1", paulKey.Public().(ed25519.PublicKey))
+ wrongKeys := certKeys(t, "paul-1", otherKey.Public().(ed25519.PublicKey))
+ set := filepath.Join(t.TempDir(), "set.json")
+ raw, _ := os.ReadFile(a)
+ if err := os.WriteFile(set, append(append([]byte(`{"certificates":[`), raw...), []byte("]}")...), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ for name, c := range map[string]struct {
+ args []string
+ exit int
+ }{
+ "another key": {[]string{"-cert-keys", wrongKeys, "-cert", a}, exitRefused},
+ "listed twice": {[]string{"-cert-keys", keys, "-cert", a, "-cert", a}, exitRefused},
+ "already a set": {[]string{"-cert-keys", keys, "-cert", set}, exitRefused},
+ "no certificates": {[]string{"-cert-keys", keys}, exitUsage},
+ } {
+ out := filepath.Join(t.TempDir(), "certificates.json")
+ code, stdout, stderr := runCmd(t, append(append([]string{"bundle"}, c.args...), "-out", out)...)
+ if code != c.exit {
+ t.Errorf("%s: bundle = %d %s %s, want %d", name, code, stdout, stderr, c.exit)
+ }
+ if _, err := os.Stat(out); !os.IsNotExist(err) {
+ t.Errorf("%s: bundle wrote %s (%v)", name, out, err)
+ }
+ }
+ // Parsing alone needs -cert-keys, -out and at least one -cert.
+ for _, args := range [][]string{
+ {"bundle", "-cert", "c.json", "-out", "o.json"},
+ {"bundle", "-cert-keys", "k.json", "-cert", "c.json"},
+ {"bundle", "-cert-keys", "k.json", "-out", "o.json"},
+ } {
+ if _, err := parseCommand(context.Background(), args, time.Now); err == nil || !strings.Contains(err.Error(), "required") {
+ t.Errorf("%v: %v, want a refusal naming it required", args, err)
+ }
+ }
+ if _, err := parseCommand(context.Background(), []string{"bundle", "-cert-keys", "k.json", "-cert", "c.json", "-out", "o.json"}, time.Now); err != nil {
+ t.Errorf("bundle with every argument: %v", err)
+ }
+}
diff --git a/cmd/equipo-hosted-certify/main.go b/cmd/equipo-hosted-certify/main.go
index 3696ba99..c32fb322 100644
--- a/cmd/equipo-hosted-certify/main.go
+++ b/cmd/equipo-hosted-certify/main.go
@@ -25,6 +25,11 @@
// verify -cert FILE -cert-keys FILE
// verifies a certificate against the certificate key file
// (controller/cert-keys.json) and prints its digest and snapshot.
+// bundle -cert-keys FILE -cert FILE [-cert FILE ...] -out FILE
+// writes the controller's certificate set (controller/certificates.json,
+// {"certificates":[...]}) from certificates sign wrote, one per -cert,
+// in order. Each must be one certificate that verifies under the key
+// file, and none may be listed twice; otherwise nothing is written.
// reload (controller flags) POST /v1/admin/reload
// alert-test (controller flags) POST /v1/admin/alert-test
//
@@ -58,6 +63,7 @@ import (
"net/http"
"os"
"path/filepath"
+ "slices"
"strconv"
"strings"
"time"
@@ -129,7 +135,7 @@ func run(ctx context.Context, args []string, stdout, stderr io.Writer, now func(
// this way, Task 32); the command it returns does the rest.
func parseCommand(ctx context.Context, args []string, now func() time.Time) (func() (any, error), error) {
if len(args) == 0 {
- return nil, usage("a command is required: launch, judge, sign, verify, reload or alert-test")
+ return nil, usage("a command is required: launch, judge, sign, verify, bundle, reload or alert-test")
}
fs := flag.NewFlagSet(args[0], flag.ContinueOnError)
fs.SetOutput(io.Discard)
@@ -178,6 +184,18 @@ func parseCommand(ctx context.Context, args []string, now func() time.Time) (fun
return nil, usage("-cert and -cert-keys are required")
}
return func() (any, error) { return verify(*cert, *keys) }, nil
+ case "bundle":
+ var certs paths
+ fs.Var(&certs, "cert", "a certificate sign wrote; repeat for each one the set keeps")
+ keys := fs.String("cert-keys", "", "the certificate key file (controller/cert-keys.json)")
+ out := fs.String("out", "", "where to write the set (controller/certificates.json)")
+ if err := parse(fs, args[1:]); err != nil {
+ return nil, err
+ }
+ if len(certs) == 0 || *keys == "" || *out == "" {
+ return nil, usage("-cert, -cert-keys and -out are required")
+ }
+ return func() (any, error) { return bundle(certs, *keys, *out) }, nil
case "reload", "alert-test":
c := controllerFlags(fs)
if err := parse(fs, args[1:]); err != nil {
@@ -312,10 +330,23 @@ func verify(certFile, keysFile string) (verifyResult, error) {
if err := hostedwire.DecodeStrict(bytes.NewReader(raw), &c); err != nil {
return verifyResult{}, refused(err)
}
- kraw, err := os.ReadFile(keysFile)
+ keys, err := readCertKeys(keysFile)
if err != nil {
return verifyResult{}, err
}
+ s, err := hostedcert.Verify(c, keys)
+ if err != nil {
+ return verifyResult{}, refused(err)
+ }
+ return verifyResult{Digest: hostedcert.Digest(c), Snapshot: s}, nil
+}
+
+// readCertKeys reads a certificate key file (controller/cert-keys.json).
+func readCertKeys(path string) (map[string]ed25519.PublicKey, error) {
+ kraw, err := os.ReadFile(path)
+ if err != nil {
+ return nil, err
+ }
var kf struct {
Keys []struct {
ID string `json:"id"`
@@ -323,21 +354,72 @@ func verify(certFile, keysFile string) (verifyResult, error) {
} `json:"keys"`
}
if err := hostedwire.DecodeStrict(bytes.NewReader(kraw), &kf); err != nil {
- return verifyResult{}, usage("certificate key file: %v", err)
+ return nil, usage("certificate key file: %v", err)
}
keys := map[string]ed25519.PublicKey{}
for _, k := range kf.Keys {
pub, err := base64.StdEncoding.Strict().DecodeString(k.PublicKey)
if err != nil || len(pub) != ed25519.PublicKeySize {
- return verifyResult{}, usage("certificate key %q is not an ed25519 public key in base64", k.ID)
+ return nil, usage("certificate key %q is not an ed25519 public key in base64", k.ID)
}
keys[k.ID] = pub
}
- s, err := hostedcert.Verify(c, keys)
+ return keys, nil
+}
+
+// ---- bundle ----
+
+// paths is a repeated file flag.
+type paths []string
+
+func (f *paths) String() string { return strings.Join(*f, ",") }
+func (f *paths) Set(v string) error { *f = append(*f, v); return nil }
+
+type bundleResult struct {
+ Out string `json:"out"`
+ Certificates int `json:"certificates"`
+ Digests []string `json:"digests"`
+}
+
+// bundle writes the controller's certificate set from certificates sign
+// wrote: the shape ctlcert.Set.Load reads, so the controller takes what
+// the signing step produces (dev drill finding 1). Each input is decoded
+// strictly as one certificate and verified under the key file the
+// controller uses; a failure, or a certificate listed twice, writes
+// nothing.
+func bundle(certFiles []string, keysFile, out string) (bundleResult, error) {
+ keys, err := readCertKeys(keysFile)
if err != nil {
- return verifyResult{}, refused(err)
+ return bundleResult{}, err
+ }
+ set := struct {
+ Certificates []hostedcert.Certificate `json:"certificates"`
+ }{Certificates: []hostedcert.Certificate{}}
+ res := bundleResult{Out: out, Digests: []string{}}
+ for _, path := range certFiles {
+ raw, err := os.ReadFile(path)
+ if err != nil {
+ return bundleResult{}, err
+ }
+ var c hostedcert.Certificate
+ if err := hostedwire.DecodeStrict(bytes.NewReader(raw), &c); err != nil {
+ return bundleResult{}, refused(fmt.Errorf("%s is not one certificate: %w", path, err))
+ }
+ if _, err := hostedcert.Verify(c, keys); err != nil {
+ return bundleResult{}, refused(fmt.Errorf("%s: %w", path, err))
+ }
+ d := hostedcert.Digest(c)
+ if slices.Contains(res.Digests, d) {
+ return bundleResult{}, refused(fmt.Errorf("%s: certificate %s is listed twice", path, d))
+ }
+ set.Certificates = append(set.Certificates, c)
+ res.Digests = append(res.Digests, d)
}
- return verifyResult{Digest: hostedcert.Digest(c), Snapshot: s}, nil
+ if err := writeJSON(out, set); err != nil {
+ return bundleResult{}, err
+ }
+ res.Certificates = len(set.Certificates)
+ return res, nil
}
// ---- the controller ----
diff --git a/docs/superpowers/plans/2026-11-30-hosted-prod-account-plan.md b/docs/superpowers/plans/2026-11-30-hosted-prod-account-plan.md
index a6268b50..e4ca3e36 100644
--- a/docs/superpowers/plans/2026-11-30-hosted-prod-account-plan.md
+++ b/docs/superpowers/plans/2026-11-30-hosted-prod-account-plan.md
@@ -558,7 +558,10 @@ runs `cert sign -evidence evidence.json -release image-manifest.json -controller
snapshot it derives from the evidence; `paul-cert-1` is the key ID 3.5 put in `controller/cert-keys.json`.
The agent writes `$P/cert-keys.json` as `{"keys": [{"id": "paul-cert-1", "public_key": "<CERT_PUB>"}]}`
(the object 3.5 uploaded) and runs `cert verify -cert "$P/certificate.json" -cert-keys
-"$P/cert-keys.json"`, `ops object put` `controller/certificates.json`, `cert reload -controller https://<controller EIP> -controller-tls-pin <pin> -controller-pub "$P/keys/controller.pub" -operator-id operator -operator-key "$P/keys/operator.key"` (reload re-fetches
+"$P/cert-keys.json"`, then `cert bundle -cert-keys "$P/cert-keys.json" -cert "$P/certificate.json" -out "$P/certificates.json"` (sign
+writes one certificate; the controller reads the set `{"certificates": [...]}`, and bundle writes that set from
+sign's output after verifying it under the same key file), `ops object put` that file as
+`controller/certificates.json`, `cert reload -controller https://<controller EIP> -controller-tls-pin <pin> -controller-pub "$P/keys/controller.pub" -operator-id operator -operator-key "$P/keys/operator.key"` (reload re-fetches
`certificates.json` from the bucket, verifies it and swaps it in; a failure keeps the old set), and
`ops assert` that `GET /v1/certs` lists it. Within 15 minutes, `ops fact` that the trail holds a data event for the image; 9.1 requires it.
diff --git a/docs/superpowers/plans/2026-12-01-hosted-2-dev-live-plan.md b/docs/superpowers/plans/2026-12-01-hosted-2-dev-live-plan.md
index efa23c90..0a21444b 100644
--- a/docs/superpowers/plans/2026-12-01-hosted-2-dev-live-plan.md
+++ b/docs/superpowers/plans/2026-12-01-hosted-2-dev-live-plan.md
@@ -630,7 +630,7 @@ rc=$?
set -e
if [ "$rc" != 0 ]; then echo "the certificate does not verify (exit $rc); ask Paul to sign again; the clock still runs"; exit 0; fi
ops wait-human cert-signed --done
-jq '{certificates: [.]}' "$H/certificate.json" > "$P/certificates.json"
+cert bundle -cert-keys "$P/cert-keys.json" -cert "$H/certificate.json" -out "$P/certificates.json"
ops object put --bucket "$CONFIG_BUCKET" --key controller/certificates.json --file "$P/certificates.json"
set +e
cert reload -controller "$CTL" -controller-tls-pin "$PIN_HEX" -controller-pub "$P/keys/controller.pub" -operator-id operator -operator-key "$P/keys/operator.key"
@@ -641,7 +641,9 @@ ops assert cert-listed "$IMAGE_DIGEST"
```
`cert sign` writes one certificate; the controller's `certificates.json` is a set,
-`{"certificates": [...]}` (`internal/hostedctl/ctlcert/certs.go`), so the block wraps it.
+`{"certificates": [...]}` (`internal/hostedctl/ctlcert/certs.go`). `cert bundle` writes that set
+from sign's output, verifying each certificate under the same key file first
+(`TestBundleMeetsTheController` loads its output with the controller's own loader).
## 6. Staging wired, and three hosted checks
diff --git a/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md b/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md
index e30be260..07bf3f86 100644
--- a/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md
+++ b/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md
@@ -3322,3 +3322,31 @@ Mutation checks, each restored and green again:
- **RN3** the setting migration file back at `0125_hosted_checks_setting.sql`. `./internal/equipo -run TestHostedSettingMigrationOff`:
FAIL `hosted_settings_test.go:127: the hosted setting migration must be 0126, after 0124`.
`./internal/equipo/chat -run TestMigrationAdditive`: FAIL `hosted_jobs_test.go:561: no 0126_hosted_checks_setting, or <nil>`.
+
+## Dev drill run-kit fixes (2026-12-01)
+
+### Fix 1: certificates.json shapes meet
+
+`equipo-hosted-certify sign` writes one certificate; the controller's `ctlcert.Set.Load` reads
+`{"certificates":[...]}`. New `cert bundle -cert-keys FILE -cert FILE [-cert FILE ...] -out FILE`
+writes that set from sign's output: each input decoded strictly as one certificate, verified under
+the key file the controller uses, none listed twice; any failure writes nothing (exit 3; a missing
+argument exits 2). The dev plan's 5.x block runs `cert bundle` in place of its `jq` wrap; the
+account plan's 6.4 names the step.
+
+Red: `go test ./cmd/equipo-hosted-certify -run TestBundle -count=1`: FAIL, `unknown command "bundle"`
+for every case. Green: the whole package, ok.
+
+Tests: `TestBundleMeetsTheController` (two certificates from the real `sign`, bundled, then loaded by
+`ctlcert.Set.Load`, what reload runs: 2 loaded; a bare certificate is refused by that loader),
+`TestBundleRefuses` (another key, listed twice, already a set, no `-cert`; nothing written; parse
+needs `-cert-keys`, `-out` and a `-cert`). `TestPlanCertInvocationsParse` reads the new plan lines.
+
+Mutation checks, each restored and green again:
+- **B1** the Verify check skipped (`false && err != nil`). `-run TestBundleRefuses`: FAIL
+ `bundle_test.go:106: another key: bundle = 0 {...}` and `:109 ... bundle wrote .../certificates.json`.
+- **B2** the twice-listed check skipped. `-run TestBundleRefuses`: FAIL `bundle_test.go:106: listed twice: bundle = 0 {...}`.
+- **B3** the bare list written (`writeJSON(out, set.Certificates)`). `-run TestBundleMeetsTheController`:
+ FAIL `bundle_test.go:69: the controller loads the bundle: 0, ctlcert: certificate files are not valid: ... not an object`.
+- **B4** the dev plan's bundle line given `-outt`. `-run TestPlanCertInvocationsParse`: FAIL
+ `plan_test.go:33: 2026-12-01-hosted-2-dev-live-plan.md: cert bundle ... -outt ...: flag provided but not defined: -outt`.