carlos / platform Public

release: StageSignedHead binds a digestless head to its promotion record (hunt H3-M1/H6-M2 sibling path)

Named-unit recovery stages a unit's channel head through StageSignedHead,
not through adoptHost, so the binding Task 1 added (stagePointerHead) did
not cover it: a digestless pointer still staged whatever manifest and
artifact the bucket held under the version, and a fresh box recovering a
unit staged a swap made after promotion. StageSignedHead now goes through
stagePointerHead: a pointer digest binds the head, otherwise the signed
promotion record does, and a missing or unreadable record or a manifest
that does not hash to it refuses. HeldAuthorized is unchanged.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude Fable (hunt fix) pushed by claude agent, operated by paul@keymail.dev ff8bdb4d949d4a5da81a090070d98ee422a7c396 parent a8ea8fd
2 files changed, +129 −1
  • internal/release/hunt_H3-M1_signedhead_test.go +116 −0
  • internal/release/signedhead.go +13 −1
diff --git a/internal/release/hunt_H3-M1_signedhead_test.go b/internal/release/hunt_H3-M1_signedhead_test.go
new file mode 100644
index 000000000..a905d02d0
--- /dev/null
+++ b/internal/release/hunt_H3-M1_signedhead_test.go
@@ -0,0 +1,116 @@
+package release
+
+import (
+ "bytes"
+ "context"
+ "os"
+ "path/filepath"
+ "testing"
+
+ "github.com/carlosframework/platform/internal/registry"
+)
+
+// huntSignedHeadBox is the fresh box named-unit recovery runs on
+// (internal/host/namedrecovery.go, namedrecovery_active.go): an empty opt
+// dir, empty ratchet dirs, the require flag off, and a route that names the
+// account the way the host's unit binding does. It ships and promotes v1
+// with the account's digest marker off (the default), so the signed head
+// carries no digest and a promotion record with the shipped manifest's
+// digest is the only binding.
+func huntSignedHeadBox(t *testing.T) (ctx context.Context, s Store, pub []byte, rat *DigestRatchet, opt string, rt registry.Route) {
+ t.Helper()
+ ctx = context.Background()
+ s = NewDirStore(t.TempDir())
+ priv, pub := testKeys(t)
+ opt = t.TempDir()
+ shipRelease(t, s, "bab", "km", "v1", adoptPlatform, []byte("the bytes the publisher shipped"))
+ if err := Promote(ctx, s, priv, "bab", "km", "canary/x", "v1"); err != nil {
+ t.Fatal(err)
+ }
+ p, err := Channel(ctx, s, pub, "bab", "km", "canary/x")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if p.Digest != "" || p.CarriesDigests() {
+ t.Fatalf("setup: marker off still produced a digest %q", p.Digest)
+ }
+ rec, err := ReadPromotionRecord(ctx, s, pub, "bab", "km", "v1")
+ if err != nil || rec.ManifestDigest != manifestDigestOf(t, s, "bab", "km", "v1") {
+ t.Fatalf("setup: promotion record %+v, %v", rec, err)
+ }
+ rat = NewDigestRatchet(filepath.Join(t.TempDir(), "root-marks"), []string{filepath.Join(t.TempDir(), "edge-marks")}, false)
+ rt = registry.Route{Host: "a.example.com", Kind: "instance", App: "km", Channel: "canary/x"}
+ rt.Account = "bab"
+ return ctx, s, pub, rat, opt, rt
+}
+
+// H3-M1 sibling path: the adopt pass binds a digestless head to its
+// promotion record (stagePointerHead), but StageSignedHead, which named-unit
+// recovery calls to restage the head on a box, is a second way to stage the
+// same pointer. A bucket writer swaps manifest+artifact after promotion; the
+// signed pointer is untouched; a fresh box has no retained copy. SECURE
+// expectation: StageSignedHead refuses, and the swapped bytes are never
+// written under the version.
+func TestHunt_H3_M1_SignedHeadRefusesManifestSwap(t *testing.T) {
+ ctx, s, pub, rat, opt, rt := huntSignedHeadBox(t)
+ evil := []byte("bytes nobody promoted")
+ huntReplaceRelease(t, s, "bab", "km", "v1", evil)
+
+ var out bytes.Buffer
+ var p *ChannelPointer
+ var m *Manifest
+ var err error
+ withCapturedStdout(t, &out, func() {
+ p, m, err = StageSignedHead(ctx, s, pub, rat, opt, rt)
+ })
+ staged, rerr := os.ReadFile(VersionPath(opt, "bab", "v1", "km"))
+ if err == nil || rerr == nil || bytes.Equal(staged, evil) {
+ t.Fatalf("H3-M1 (StageSignedHead): digestless signed head admitted substituted bytes: err=%v ptr=%+v manifest=%+v staged=%q (a signed promotion record with the real manifest digest exists but was not consulted)\n%s",
+ err, p, m, staged, out.String())
+ }
+}
+
+// A head promoted before records existed, or whose record a writer removed,
+// has nothing to bind its bytes: a fresh box refuses it rather than staging
+// whatever the bucket holds. (`carlos releases authorize` writes the record.)
+func TestHunt_H3_M1_SignedHeadRefusesMissingRecord(t *testing.T) {
+ ctx, s, pub, rat, opt, rt := huntSignedHeadBox(t)
+ key := PromotionRecordKey("bab", "km", "v1")
+ _, etag, err := s.Get(ctx, key)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := s.(*DirStore).DeleteIfMatch(ctx, key, etag); err != nil {
+ t.Fatal(err)
+ }
+ var out bytes.Buffer
+ withCapturedStdout(t, &out, func() {
+ _, _, err = StageSignedHead(ctx, s, pub, rat, opt, rt)
+ })
+ if _, rerr := os.ReadFile(VersionPath(opt, "bab", "v1", "km")); err == nil || rerr == nil {
+ t.Fatalf("H3-M1 (StageSignedHead): digestless head with no promotion record was staged on a fresh box: err=%v\n%s", err, out.String())
+ }
+}
+
+// Control: the untouched head still stages through StageSignedHead on a
+// fresh box, bound to the record, and comes back with its binary manifest.
+func TestHunt_H3_M1_SignedHeadStagesUnswappedHead(t *testing.T) {
+ ctx, s, pub, rat, opt, rt := huntSignedHeadBox(t)
+ var out bytes.Buffer
+ var p *ChannelPointer
+ var m *Manifest
+ var err error
+ withCapturedStdout(t, &out, func() {
+ p, m, err = StageSignedHead(ctx, s, pub, rat, opt, rt)
+ })
+ if err != nil {
+ t.Fatalf("control: StageSignedHead refused the untouched head: %v\n%s", err, out.String())
+ }
+ if p.Version != "v1" || m == nil || m.Kind != "binary" {
+ t.Fatalf("control: pointer %+v manifest %+v", p, m)
+ }
+ staged, rerr := os.ReadFile(VersionPath(opt, "bab", "v1", "km"))
+ if rerr != nil || string(staged) != "the bytes the publisher shipped" {
+ t.Fatalf("control: staged %q, %v", staged, rerr)
+ }
+}
diff --git a/internal/release/signedhead.go b/internal/release/signedhead.go
index e57fbd89a..e4c6dc209 100644
--- a/internal/release/signedhead.go
+++ b/internal/release/signedhead.go
@@ -8,6 +8,18 @@ import (
"github.com/carlosframework/platform/internal/registry"
)
+// StageSignedHead stages the head the route's signed channel pointer names
+// and returns the pointer and the staged binary manifest. Named-unit
+// recovery (internal/host) calls it to restage a unit's head on a box, so
+// it is a second entry to the bytes adoptHost stages, and it binds them the
+// same way (stagePointerHead): a pointer that carries a digest binds the
+// head itself; a digestless pointer binds to the version's signed promotion
+// record, and a missing record, an unreadable one, or a manifest that does
+// not hash to it refuse the head. Before that binding a bucket writer could
+// swap manifest+artifact behind an untouched digestless head and a fresh
+// box recovering a named unit staged the swap (hunt H3-M1, H6-M2 sibling
+// path). The ratchet's verdict (digest marks, the require flag, the
+// watermark) still comes first.
func StageSignedHead(ctx context.Context, s Store, pub ed25519.PublicKey, ratchet *DigestRatchet, optDir string, rt registry.Route) (*ChannelPointer, *Manifest, error) {
p, err := Channel(ctx, s, pub, rt.Account, rt.App, rt.Channel)
if err != nil {
@@ -16,7 +28,7 @@ func StageSignedHead(ctx context.Context, s Store, pub ed25519.PublicKey, ratche
if err := ratchet.Admit(rt.Account, p); err != nil {
return nil, nil, err
}
- m, err := ensureStagedDigest(ctx, s, optDir, rt.Account, rt.App, p.Version, rt.Host, p.DigestOf(p.Version), stageCheck{})
+ m, err := stagePointerHead(ctx, s, pub, optDir, rt.Account, rt.App, p.Version, rt.Host, p.DigestOf(p.Version), stageCheck{})
if err != nil {
return nil, nil, err
}