carlos / platform Public

release: bind a digestless channel head to its promotion record (hunt H3-M1, H6-M2)

A channel pointer signed with the account's digest marker off (the default)
carries no manifest digest, and the pass staged whatever the bucket held
under the version. A writer with s3:PutObject on the deployment bucket could
swap an already-promoted version's manifest and artifact behind the untouched
signed pointer, and a fresh box would stage and run the swap.

Promote writes a signed promotion record from the shipped bytes before every
new head, so a digestless head now binds to that record (stagePointerHead),
as stageAuthorized already binds a settings decision: no record, a record
that cannot be read, an empty digest, or a manifest that does not hash to it
refuses, and nothing is downloaded on anything weaker. A copy already staged
on the box keeps today's answer only when the manifest cannot be read at all
(zdd-4 review focus 3); a mismatch is never "unreadable". The digest-bearing
path and the CARLOS_REQUIRE_POINTER_DIGEST refusal are unchanged.

stageAuthorized is split into recordBinding and retainedOrRefused so both
record paths share the same refusals; its behaviour is unchanged.

Tests: writeBackdatedPointer now writes the record Promote would have, and
the cross-host reuse test gives a1 a hand-signed digest pointer, since its
fixture relied on a digestless head accepting a swapped manifest.

Turning the require flag on fleet-wide is a later, separate roll; this
binding needs no flag.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude Fable (hunt fix) pushed by claude agent, operated by paul@keymail.dev 0fcf7768dda70b5b248a8321e0491178037632e1 parent bcae2a7
5 files changed, +486 −38
  • internal/release/adopt.go +98 −28
  • internal/release/adopt_test.go +12 −0
  • internal/release/adoptdigest_test.go +17 −10
  • internal/release/hunt_H3-M1_test.go +242 −0
  • internal/release/hunt_H6-M2_test.go +117 −0
diff --git a/internal/release/adopt.go b/internal/release/adopt.go
index d3b5c56b3..6d8acaa7b 100644
--- a/internal/release/adopt.go
+++ b/internal/release/adopt.go
@@ -1603,10 +1603,12 @@ func adoptHost(ctx context.Context, work hostwrite.Work, reg *registry.Registry,
// The evidence that authorizes ver (settings spec §4.1). Only today's
// adoption of the head, and a request whose T is still the head, rest on
// the signed pointer and its digest; everything else needs a promotion
- // record with a matching manifest digest (stageAuthorized). The pointer
- // branch is refused for any build but the head itself: a non-head build
- // has no pointer digest, and staging it unbound on a digested channel is
- // the #253 replay (invariant 3).
+ // record with a matching manifest digest (stageAuthorized). A head whose
+ // pointer carries no digest rests on that record too (stagePointerHead):
+ // the pointer alone never binds the bytes. The pointer branch is refused
+ // for any build but the head itself: a non-head build has no pointer
+ // digest, and staging it unbound on a digested channel is the #253
+ // replay (invariant 3).
var m *Manifest
switch {
case !settings || dec.Evidence == EvidencePointer:
@@ -1615,7 +1617,7 @@ func adoptHost(ctx context.Context, work hostwrite.Work, reg *registry.Registry,
cfg.proof.clear(rt.Host)
return
}
- m, err = ensureStagedDigest(ctx, s, optDir, RouteAccount(rt), rt.App, ver, rt.Host, ptr.DigestOf(ver), cfg.stage)
+ m, err = stagePointerHead(ctx, s, cfg.pub, optDir, RouteAccount(rt), rt.App, ver, rt.Host, ptr.DigestOf(ver), cfg.stage)
case dec.Evidence == EvidenceRecord:
m, err = stageAuthorized(ctx, s, cfg.pub, optDir, RouteAccount(rt), rt.App, ver, rt.Host, cfg.stage)
default:
@@ -2292,24 +2294,29 @@ func ensureStagedChecked(ctx context.Context, s Store, optDir, acct, app, ver, h
if !staged {
return nil, fmt.Errorf("manifest for %s/%s: %w", app, ver, err)
}
- // The binary IS staged, which is this function's whole promise, and
- // the canonical manifest cannot be read to compare it with. A sibling
- // already on disk is the manifest in hand, exactly as before this
- // check existed. Without one, a fetch failure is only worth a line;
- // backfillManifest retries on every pass.
- sib, serr := ReadStagedManifest(optDir, acct, ver, app)
- if serr == nil && sib != nil {
- return sib, nil
- }
- if serr != nil {
- fmt.Printf(" %s: staged manifest for %s: %v\n", host, ver, serr)
- }
- fmt.Printf(" %s: back-fill manifest for %s: %v\n", host, ver, err)
- return nil, nil
+ return stagedTodaysAnswer(optDir, acct, app, ver, host, err)
}
return stageFrom(ctx, s, optDir, acct, app, ver, host, chk, staged, m, raw, false)
}
+// stagedTodaysAnswer is ensureStaged's rule for a binary that IS staged
+// when the canonical manifest cannot be read to compare it with (err): the
+// copy keeps today's answer. A sibling already on disk is the manifest in
+// hand, exactly as before this check existed. Without one, a fetch failure
+// is only worth a line; backfillManifest retries on every pass. Nothing is
+// downloaded or restaged.
+func stagedTodaysAnswer(optDir, acct, app, ver, host string, err error) (*Manifest, error) {
+ sib, serr := ReadStagedManifest(optDir, acct, ver, app)
+ if serr == nil && sib != nil {
+ return sib, nil
+ }
+ if serr != nil {
+ fmt.Printf(" %s: staged manifest for %s: %v\n", host, ver, serr)
+ }
+ fmt.Printf(" %s: back-fill manifest for %s: %v\n", host, ver, err)
+ return nil, nil
+}
+
// stageFrom is ensureStagedChecked from the point it holds the canonical
// manifest: m and raw, its exact bytes, read once by the caller. staged says
// whether a copy was on disk under the name. bound says m passed the
@@ -2644,25 +2651,88 @@ func orDetail(d string) string {
// digest. A failure to read the record is never read as "no record".
// Nothing is backfilled.
func stageAuthorized(ctx context.Context, s Store, pub ed25519.PublicKey, optDir, acct, app, ver, host string, chk stageCheck) (*Manifest, error) {
- rec, err := ReadPromotionRecord(ctx, s, pub, acct, app, ver)
- var refused error
- switch {
- case err == nil && rec.ManifestDigest == "":
- refused = fmt.Errorf("%s: promotion record carries no manifest digest", ver)
- case err == nil:
- m, serr := ensureStagedDigest(ctx, s, optDir, acct, app, ver, host, rec.ManifestDigest, chk)
+ want, refused := recordBinding(ctx, s, pub, acct, app, ver)
+ if refused == nil {
+ m, serr := ensureStagedDigest(ctx, s, optDir, acct, app, ver, host, want, chk)
if serr == nil {
return m, nil
}
refused = serr
+ }
+ return retainedOrRefused(optDir, acct, app, ver, host, refused)
+}
+
+// recordBinding reads ver's promotion record and returns the manifest
+// digest that binds its bytes, or the refusal stageAuthorized and
+// stagePointerHead share: no record, a record that cannot be read (never
+// read as "no record"), or one that carries no digest.
+func recordBinding(ctx context.Context, s Store, pub ed25519.PublicKey, acct, app, ver string) (string, error) {
+ rec, err := ReadPromotionRecord(ctx, s, pub, acct, app, ver)
+ switch {
+ case err == nil && rec.ManifestDigest == "":
+ return "", fmt.Errorf("%s: promotion record carries no manifest digest", ver)
+ case err == nil:
+ return rec.ManifestDigest, nil
case errors.Is(err, ErrNoPromotionRecord):
- refused = fmt.Errorf("%s: %s", ver, updatewords.Text("settings.evidence.no-record"))
+ return "", fmt.Errorf("%s: %s", ver, updatewords.Text("settings.evidence.no-record"))
default:
- refused = fmt.Errorf("%s: promotion record: %w", ver, err)
+ return "", fmt.Errorf("%s: promotion record: %w", ver, err)
}
+}
+
+// retainedOrRefused is the record paths' last word on a refusal: this box's
+// own verified staged copy (RetainedStaged, §4.1) is recovered, anything
+// less is refused.
+func retainedOrRefused(optDir, acct, app, ver, host string, refused error) (*Manifest, error) {
if id, m := RetainedStaged(optDir, acct, app, ver); id != nil {
fmt.Printf(" %s: %s recovered from this box's verified staged copy (%v)\n", host, ver, refused)
return m, nil
}
return nil, refused
}
+
+// stagePointerHead stages the head the signed channel pointer names, bound
+// to a manifest digest the publisher signed. A pointer that carries one
+// binds the head itself (ensureStagedDigest, #253). A pointer that carries
+// none (the account's digest marker off, which is the default, or a pointer
+// signed before digests existed) used to stage whatever the bucket held
+// under the version: a writer with s3:PutObject on the deployment bucket
+// could swap the manifest and artifact behind an untouched signed head, and
+// a fresh box would stage and run the swap (hunt H3-M1, H6-M2). Promote
+// writes a signed promotion record from the shipped bytes before every new
+// head (release.go), so a digestless head binds to that record instead, as
+// stageAuthorized binds a settings decision: no record, one that cannot be
+// read, an empty digest, or a manifest that does not hash to it refuse, and
+// nothing is downloaded on anything weaker than the record's digest. Only
+// this box's own verified staged copy recovers a refusal (RetainedStaged),
+// and a fresh box has none. A head promoted before records existed has no
+// record; `carlos releases authorize` writes it.
+//
+// One rule of the unbound path stays, because it downloads nothing: a copy
+// already staged on this box keeps today's answer when the record is good
+// but the manifest cannot be read at all (stagedTodaysAnswer, zdd-4 review
+// focus 3). A manifest that reads and does not hash to the record is a
+// mismatch, never "unreadable".
+//
+// The require flag (CARLOS_REQUIRE_POINTER_DIGEST) still refuses a
+// digestless pointer outright before this point (DigestRatchet.Admit); the
+// binding here needs no flag.
+func stagePointerHead(ctx context.Context, s Store, pub ed25519.PublicKey, optDir, acct, app, ver, host, want string, chk stageCheck) (*Manifest, error) {
+ if want != "" {
+ return ensureStagedDigest(ctx, s, optDir, acct, app, ver, host, want, chk)
+ }
+ want, refused := recordBinding(ctx, s, pub, acct, app, ver)
+ if refused == nil {
+ m, raw, err := CheckManifestDigest(ctx, s, acct, app, ver, want)
+ _, statErr := os.Stat(VersionPath(optDir, acct, ver, app))
+ staged := statErr == nil
+ switch {
+ case err == nil:
+ return stageFrom(ctx, s, optDir, acct, app, ver, host, chk, staged, m, raw, true)
+ case staged && !errors.Is(err, ErrManifestDigest):
+ return stagedTodaysAnswer(optDir, acct, app, ver, host, err)
+ }
+ refused = fmt.Errorf("manifest for %s/%s: %w", app, ver, err)
+ }
+ return retainedOrRefused(optDir, acct, app, ver, host, refused)
+}
diff --git a/internal/release/adopt_test.go b/internal/release/adopt_test.go
index 85cbcf96f..ad622f27c 100644
--- a/internal/release/adopt_test.go
+++ b/internal/release/adopt_test.go
@@ -664,6 +664,18 @@ func writeBackdatedPointer(t *testing.T, s Store, priv ed25519.PrivateKey, acct,
if err != nil {
t.Fatalf("marshal backdated wrapper: %v", err)
}
+ // The promotion record Promote writes before every new head
+ // (release.go), from the shipped manifest: a digestless head binds to it
+ // (stagePointerHead), so a pointer forged without one would be refused
+ // as a legacy head, not adopted. A version that was never shipped gets
+ // no record, as in production.
+ if _, raw, err := GetManifestRaw(context.Background(), s, acct, app, version); err == nil {
+ if err := RootSigner(priv).WritePromotionRecord(context.Background(), s, PromotionRecord{
+ Account: acct, App: app, Version: version, ManifestDigest: ManifestDigest(raw), Channel: channel,
+ }); err != nil {
+ t.Fatalf("write backdated pointer's promotion record: %v", err)
+ }
+ }
if _, err := s.Put(context.Background(), ChannelKey(acct, app, channel), wrapper, ""); err != nil {
t.Fatalf("write backdated pointer: %v", err)
}
diff --git a/internal/release/adoptdigest_test.go b/internal/release/adoptdigest_test.go
index 9e9a77c32..e4e1d89b2 100644
--- a/internal/release/adoptdigest_test.go
+++ b/internal/release/adoptdigest_test.go
@@ -236,11 +236,11 @@ func TestDigestBoundStagingRefusesAManifestThatNoLongerHashesToTheDigest(t *test
}
// A copy this pass verified against one manifest is not proof against
-// another. a1 follows a channel promoted before the marker (no digest) and
-// reuses the staged v2 against the manifest the bucket answers first; b1
-// follows a channel whose pointer signs a different v2 manifest. b1 must not
-// reuse that copy on the strength of the pass's "already verified" memory:
-// it hashes the copy against its own checked manifest, finds it differs, and
+// another. a1 follows a channel whose pointer signs the v2 manifest the
+// bucket answers first and reuses the staged v2 against it; b1 follows a
+// channel whose pointer signs a different v2 manifest. b1 must not reuse
+// that copy on the strength of the pass's "already verified" memory: it
+// hashes the copy against its own checked manifest, finds it differs, and
// since a1 now runs it, refuses.
func TestADigestBoundHostNeverTrustsACopyVerifiedAgainstAnotherManifest(t *testing.T) {
s := NewDirStore(t.TempDir())
@@ -249,7 +249,15 @@ func TestADigestBoundHostNeverTrustsACopyVerifiedAgainstAnotherManifest(t *testi
opt := t.TempDir()
reg := testRegistry(t)
shipRelease(t, s, "bab", "myapp", "v2", adoptPlatform, []byte("signed v2"))
- if err := Promote(ctx, s, priv, "bab", "myapp", "canary/a", "v2"); err != nil {
+ // a1's channel signs the digest of a v2 manifest for the "unsigned v2"
+ // bytes, written by hand: Promote signs the shipped bytes, and a
+ // digestless head binds to the promotion record, which names the shipped
+ // bytes too (stagePointerHead), so no head verifies the copy against
+ // this manifest unless its pointer signs it.
+ unsigned := putRawRelease(t, NewDirStore(t.TempDir()), "bab", "myapp", "v2", []byte("unsigned v2"), "")
+ if _, err := s.Put(ctx, ChannelKey("bab", "myapp", "canary/a"), signedPointerBytes(t, priv, &ChannelPointer{
+ Account: "bab", App: "myapp", Channel: "canary/a", Version: "v2", Digest: ManifestDigest(unsigned),
+ }), ""); err != nil {
t.Fatal(err)
}
markerOn(t, s, priv, "bab")
@@ -259,9 +267,8 @@ func TestADigestBoundHostNeverTrustsACopyVerifiedAgainstAnotherManifest(t *testi
if err := StageArtifact(opt, "bab", "v2", "myapp", []byte("unsigned v2")); err != nil {
t.Fatal(err)
}
- // The bucket answers the first read of v2's manifest with one for the
- // staged "unsigned v2" bytes, and every later read with the signed one.
- unsigned := putRawRelease(t, NewDirStore(t.TempDir()), "bab", "myapp", "v2", []byte("unsigned v2"), "")
+ // The bucket answers the first read of v2's manifest with the one a1's
+ // pointer signs, and every later read with the signed (shipped) one.
flip := &flipStore{Store: s, key: ManifestKey("bab", "myapp", "v2"), first: unsigned}
addRoute(t, reg, "a1.example.com", "myapp", "canary/a", false)
addRoute(t, reg, "b1.example.com", "myapp", "canary/b", false)
@@ -272,7 +279,7 @@ func TestADigestBoundHostNeverTrustsACopyVerifiedAgainstAnotherManifest(t *testi
}
})
if v, _ := LiveVersion(opt, "a1.example.com"); v != "v2" {
- t.Fatalf("setup: a1 live = %q, want v2 (it has no digest to check):\n%s", v, out.String())
+ t.Fatalf("setup: a1 live = %q, want v2 (its pointer signs that manifest):\n%s", v, out.String())
}
if v, _ := LiveVersion(opt, "b1.example.com"); v != "" {
t.Fatalf("b1 live on %q: a digest-bound host reused a copy verified against another manifest:\n%s", v, out.String())
diff --git a/internal/release/hunt_H3-M1_test.go b/internal/release/hunt_H3-M1_test.go
new file mode 100644
index 000000000..7fda4cbe4
--- /dev/null
+++ b/internal/release/hunt_H3-M1_test.go
@@ -0,0 +1,242 @@
+package release
+
+import (
+ "bytes"
+ "context"
+ "crypto/ed25519"
+ "encoding/json"
+ "os"
+ "testing"
+
+ "github.com/carlosframework/platform/internal/registry"
+)
+
+// hunt H3-M1: a box-role writer (unconditioned s3:PutObject on the deployment
+// bucket) overwrites an already-promoted version's manifest and artifact. The
+// signed channel pointer is untouched. With the account's digest marker off
+// (the default: emission is opt-in per account), the pointer signs no
+// manifest digest, so a fresh box staging the version must refuse the bytes
+// the publisher never shipped. SECURE expectation: the evil bytes are never
+// staged or pointed live.
+func huntSwapRelease(t *testing.T, s Store, acct, app, ver string, evil []byte) {
+ t.Helper()
+ ctx := context.Background()
+ // Build the attacker's manifest+artifact the way any writer could, in a
+ // scratch store, then write the two objects over the real keys with an
+ // unconditioned (etag-matched) Put: the box role has no create-only
+ // condition, only Ship does (putImmutable).
+ scratch := NewDirStore(t.TempDir())
+ shipRelease(t, scratch, acct, app, ver, adoptPlatform, evil)
+ m, err := GetManifest(ctx, scratch, acct, app, ver)
+ if err != nil {
+ t.Fatal(err)
+ }
+ art := m.Artifacts[adoptPlatform]
+ for _, key := range []string{ArtifactKey(acct, app, ver, art.File), ManifestKey(acct, app, ver)} {
+ body, _, err := scratch.Get(ctx, key)
+ if err != nil {
+ t.Fatal(err)
+ }
+ _, etag, err := s.Get(ctx, key)
+ if err != nil {
+ t.Fatalf("victim object %s: %v", key, err)
+ }
+ if _, err := s.Put(ctx, key, body, etag); err != nil {
+ t.Fatalf("overwrite %s: %v", key, err)
+ }
+ }
+}
+
+func TestHunt_H3_M1_ManifestSwapBehindDigestlessPointer(t *testing.T) {
+ s := NewDirStore(t.TempDir())
+ ctx := context.Background()
+ priv, pub := testKeys(t)
+ opt := t.TempDir() // a FRESH box: nothing staged, no ratchet marks
+ reg := testRegistry(t)
+
+ shipRelease(t, s, "bab", "victim", "v1", adoptPlatform, []byte("the publisher's build"))
+ if err := Promote(ctx, s, priv, "bab", "victim", "canary/x", "v1"); err != nil {
+ t.Fatalf("Promote: %v", err)
+ }
+ ptrBefore, _, _ := s.Get(ctx, ChannelKey("bab", "victim", "canary/x"))
+
+ evil := []byte("attacker bytes nobody shipped")
+ huntSwapRelease(t, s, "bab", "victim", "v1", evil)
+
+ // The signed pointer was not touched.
+ ptrAfter, _, _ := s.Get(ctx, ChannelKey("bab", "victim", "canary/x"))
+ if !bytes.Equal(ptrBefore, ptrAfter) {
+ t.Fatal("test setup: pointer changed")
+ }
+
+ addRoute(t, reg, "victim.example.com", "victim", "canary/x", false)
+ var restarted []string
+ restart := func(h string) error { restarted = append(restarted, h); return nil }
+ var out bytes.Buffer
+ withCapturedStdout(t, &out, func() {
+ // Production-shaped options: the box's digest ratchet (fresh dirs) and
+ // a bake dir, as the agent's adopt loop arms them.
+ if err := Pass(ctx, reg, s, pub, opt, restart,
+ BakeDir(t.TempDir()),
+ WithDigestRatchet(NewDigestRatchet(t.TempDir(), nil, false))); err != nil {
+ t.Fatalf("Pass: %v", err)
+ }
+ })
+ body, err := os.ReadFile(VersionPath(opt, "bab", "v1", "victim"))
+ live, _ := LiveVersion(opt, "victim.example.com")
+ if err == nil && bytes.Equal(body, evil) {
+ t.Fatalf("H3-M1 CONFIRMED: the box staged attacker bytes %q behind the untouched signed pointer (live=%q, restarted=%v); pass output:\n%s",
+ body, live, restarted, out.String())
+ }
+ if live == "v1" {
+ t.Fatalf("H3-M1: the swapped release went live (staged bytes %q)", body)
+ }
+}
+
+// The control: with the account's digest marker ON, the pointer signs the
+// manifest digest and the same swap is refused (ErrManifestDigest). This is
+// the gate that exists, and it is opt-in per account.
+func TestHunt_H3_M1_ManifestSwapBehindDigestPointerIsRefused(t *testing.T) {
+ s := NewDirStore(t.TempDir())
+ ctx := context.Background()
+ priv, pub := testKeys(t)
+ opt := t.TempDir()
+ reg := testRegistry(t)
+ markerOn(t, s, priv, "bab")
+
+ shipRelease(t, s, "bab", "victim", "v1", adoptPlatform, []byte("the publisher's build"))
+ if err := Promote(ctx, s, priv, "bab", "victim", "canary/x", "v1"); err != nil {
+ t.Fatalf("Promote: %v", err)
+ }
+ evil := []byte("attacker bytes nobody shipped")
+ huntSwapRelease(t, s, "bab", "victim", "v1", evil)
+ addRoute(t, reg, "victim.example.com", "victim", "canary/x", false)
+ var out bytes.Buffer
+ withCapturedStdout(t, &out, func() {
+ if err := Pass(ctx, reg, s, pub, opt, nil,
+ WithDigestRatchet(NewDigestRatchet(t.TempDir(), nil, false))); err != nil {
+ t.Fatalf("Pass: %v", err)
+ }
+ })
+ if body, err := os.ReadFile(VersionPath(opt, "bab", "v1", "victim")); err == nil && bytes.Equal(body, evil) {
+ t.Fatalf("digest-bound pointer still staged the swapped bytes")
+ }
+ if live, _ := LiveVersion(opt, "victim.example.com"); live != "" {
+ t.Fatalf("live %q under a digest-bound pointer over a swapped manifest", live)
+ }
+}
+
+// ---- Opus verifier (independent of the tests above, which an earlier
+// verifier run left in this file) ----------------------------------------
+
+// opusOverwrite models the box role's unconditioned s3:PutObject: read the
+// current etag and write over it.
+func opusOverwrite(t *testing.T, s Store, key string, body []byte) {
+ t.Helper()
+ ctx := context.Background()
+ _, etag, err := s.Get(ctx, key)
+ if err != nil {
+ t.Fatalf("read %s: %v", key, err)
+ }
+ if _, err := s.Put(ctx, key, body, etag); err != nil {
+ t.Fatalf("overwrite %s: %v", key, err)
+ }
+}
+
+// opusSwapArtifact rewrites the shipped manifest in place so this platform's
+// artifact names evil's sha256 and size, then replaces the artifact bytes.
+// Every other manifest field is the publisher's.
+func opusSwapArtifact(t *testing.T, s Store, acct, app, ver string, evil []byte) {
+ t.Helper()
+ m, _, err := GetManifestRaw(context.Background(), s, acct, app, ver)
+ if err != nil {
+ t.Fatal(err)
+ }
+ a := m.Artifacts[adoptPlatform]
+ a.SHA256, a.Size = etagOf(evil), int64(len(evil))
+ m.Artifacts[adoptPlatform] = a
+ raw, err := json.MarshalIndent(m, "", " ")
+ if err != nil {
+ t.Fatal(err)
+ }
+ opusOverwrite(t, s, ArtifactKey(acct, app, ver, a.File), evil)
+ opusOverwrite(t, s, ManifestKey(acct, app, ver), raw)
+}
+
+// opusAgentPass runs Pass with the options internal/host/agent.go:1323 arms
+// that matter here: BakeDir and the digest ratchet with the require flag off
+// (the default, ratchet.go:47).
+func opusAgentPass(t *testing.T, reg *registry.Registry, s Store, pub ed25519.PublicKey, opt string) string {
+ t.Helper()
+ var out bytes.Buffer
+ withCapturedStdout(t, &out, func() {
+ if err := Pass(context.Background(), reg, s, pub, opt, func(string) error { return nil },
+ BakeDir(t.TempDir()),
+ WithDigestRatchet(NewDigestRatchet(t.TempDir(), nil, false))); err != nil {
+ t.Fatalf("Pass: %v", err)
+ }
+ })
+ return out.String()
+}
+
+// Stable, the channel every route follows by default (adopt.go:1340), on a
+// fresh box. SECURE: bytes the publisher never shipped are never staged.
+func TestHunt_H3_M1_OpusStableSwapFreshBox(t *testing.T) {
+ s := NewDirStore(t.TempDir())
+ ctx := context.Background()
+ priv, pub := testKeys(t)
+ shipRelease(t, s, "bab", "shop", "v1", adoptPlatform, []byte("publisher build v1"))
+ if err := Promote(ctx, s, priv, "bab", "shop", "stable", "v1"); err != nil {
+ t.Fatal(err)
+ }
+ evil := []byte("opus: build nobody shipped")
+ opusSwapArtifact(t, s, "bab", "shop", "v1", evil)
+
+ opt := t.TempDir()
+ reg := testRegistry(t)
+ addRoute(t, reg, "shop.example.com", "shop", "", false)
+ log := opusAgentPass(t, reg, s, pub, opt)
+ body, _ := os.ReadFile(VersionPath(opt, "bab", "v1", "shop"))
+ live, _ := LiveVersion(opt, "shop.example.com")
+ if bytes.Equal(body, evil) || live == "v1" {
+ t.Fatalf("H3-M1 (stable): staged %q, live %q, behind a pointer the attacker never touched; pass log:\n%s", body, live, log)
+ }
+}
+
+// Digests on for the account, but a pointer the account signed before the
+// marker is put back (M5) on a box that has never seen a digested pointer for
+// the channel. The ratchet is per box (ratchet.go:103), so a fresh box admits
+// it, and the swap behind it lands. SECURE: refused.
+func TestHunt_H3_M1_OpusMarkerOnReplayToFreshBox(t *testing.T) {
+ s := NewDirStore(t.TempDir())
+ ctx := context.Background()
+ priv, pub := testKeys(t)
+ shipRelease(t, s, "bab", "shop", "v1", adoptPlatform, []byte("publisher build v1"))
+ if err := Promote(ctx, s, priv, "bab", "shop", "stable", "v1"); err != nil {
+ t.Fatal(err)
+ }
+ old, _, _ := s.Get(ctx, ChannelKey("bab", "shop", "stable"))
+ // Emission goes on; the next promotion carries a digest.
+ markerOn(t, s, priv, "bab")
+ shipRelease(t, s, "bab", "shop", "v2", adoptPlatform, []byte("publisher build v2"))
+ if err := Promote(ctx, s, priv, "bab", "shop", "stable", "v2"); err != nil {
+ t.Fatal(err)
+ }
+ if p, err := Channel(ctx, s, pub, "bab", "shop", "stable"); err != nil || p.Digest == "" {
+ t.Fatalf("setup: stable should carry a digest now: %+v, %v", p, err)
+ }
+ // The attacker: put the pre-marker pointer back and swap v1's bytes.
+ opusOverwrite(t, s, ChannelKey("bab", "shop", "stable"), old)
+ evil := []byte("opus: build nobody shipped")
+ opusSwapArtifact(t, s, "bab", "shop", "v1", evil)
+
+ opt := t.TempDir()
+ reg := testRegistry(t)
+ addRoute(t, reg, "shop.example.com", "shop", "", false)
+ log := opusAgentPass(t, reg, s, pub, opt)
+ body, _ := os.ReadFile(VersionPath(opt, "bab", "v1", "shop"))
+ live, _ := LiveVersion(opt, "shop.example.com")
+ if bytes.Equal(body, evil) || live == "v1" {
+ t.Fatalf("H3-M1 (marker on, replay): staged %q, live %q on a fresh box; pass log:\n%s", body, live, log)
+ }
+}
diff --git a/internal/release/hunt_H6-M2_test.go b/internal/release/hunt_H6-M2_test.go
new file mode 100644
index 000000000..364cf55a9
--- /dev/null
+++ b/internal/release/hunt_H6-M2_test.go
@@ -0,0 +1,117 @@
+package release
+
+import (
+ "bytes"
+ "context"
+ "fmt"
+ "os"
+ "path/filepath"
+ "testing"
+)
+
+// huntOverwrite is a bucket writer's unconditional PutObject: read the
+// current etag and replace the object, which S3 allows any principal with
+// s3:PutObject on the key.
+func huntOverwrite(t *testing.T, s Store, key string, body []byte) {
+ t.Helper()
+ ctx := context.Background()
+ _, etag, err := s.Get(ctx, key)
+ if err != nil {
+ t.Fatalf("read %s: %v", key, err)
+ }
+ if _, err := s.Put(ctx, key, body, etag); err != nil {
+ t.Fatalf("overwrite %s: %v", key, err)
+ }
+}
+
+// huntReplaceRelease swaps a shipped version's manifest and artifact for
+// attacker bytes, keeping app/version so GetManifestRaw's checks pass. The
+// signed channel pointer is not touched.
+func huntReplaceRelease(t *testing.T, s Store, acct, app, ver string, body []byte) {
+ t.Helper()
+ huntOverwrite(t, s, ArtifactKey(acct, app, ver, adoptPlatform), body)
+ raw := []byte(fmt.Sprintf(`{"schema":1,"app":%q,"version":%q,"kind":"binary","artifacts":{%q:{"file":%q,"sha256":%q,"size":%d}}}`,
+ app, ver, adoptPlatform, adoptPlatform, etagOf(body), len(body)))
+ huntOverwrite(t, s, ManifestKey(acct, app, ver), raw)
+}
+
+type huntM2Case struct {
+ marker bool // the account's digest emission marker is on at promote time
+ require bool // CARLOS_REQUIRE_POINTER_DIGEST on the consumer
+}
+
+func huntM2Run(t *testing.T, c huntM2Case) (stagedBytes []byte, live string, ptr *ChannelPointer, out string) {
+ t.Helper()
+ s := NewDirStore(t.TempDir())
+ ctx := context.Background()
+ priv, pub := testKeys(t)
+ opt := t.TempDir()
+ reg := testRegistry(t)
+ if c.marker {
+ markerOn(t, s, priv, "bab")
+ }
+ 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)
+ }
+ shippedDigest := manifestDigestOf(t, s, "bab", "km", "v1")
+ if !c.marker {
+ // With the marker off, Promote still writes a signed promotion
+ // record binding v1 to the shipped manifest (release.go:887-895).
+ rec, rerr := ReadPromotionRecord(ctx, s, pub, "bab", "km", "v1")
+ if rerr != nil || rec.ManifestDigest != shippedDigest {
+ t.Fatalf("setup: promotion record %+v, %v; want digest %s", rec, rerr, shippedDigest)
+ }
+ }
+ // The attacker: replace manifest + artifact behind the signed head.
+ huntReplaceRelease(t, s, "bab", "km", "v1", []byte("bytes nobody promoted"))
+
+ // A fresh consumer: empty opt dir, empty ratchet dirs, the production
+ // ratchet armed exactly as internal/host's pointerRatchet arms it.
+ rat := NewDigestRatchet(filepath.Join(t.TempDir(), "root-marks"), []string{filepath.Join(t.TempDir(), "edge-marks")}, c.require)
+ addRoute(t, reg, "a.example.com", "km", "canary/x", false)
+ var buf bytes.Buffer
+ withCapturedStdout(t, &buf, func() {
+ _ = Pass(ctx, reg, s, pub, opt, nil, WithDigestRatchet(rat))
+ })
+ b, _ := os.ReadFile(VersionPath(opt, "bab", "v1", "km"))
+ v, _ := LiveVersion(opt, "a.example.com")
+ return b, v, p, buf.String()
+}
+
+// H6-M2: a legitimately promoted digestless head (marker off) lets a bucket
+// writer replace manifest+artifact; a fresh consumer without the require flag
+// stages and points live bytes nobody promoted. SECURE expectation: refused.
+func TestHunt_H6_M2_DigestlessHeadReplacementIsRefused(t *testing.T) {
+ staged, live, ptr, out := huntM2Run(t, huntM2Case{marker: false, require: false})
+ if ptr.Digest != "" {
+ t.Fatalf("setup: marker off still produced a digest %q", ptr.Digest)
+ }
+ if string(staged) == "bytes nobody promoted" || live == "v1" {
+ t.Fatalf("H6-M2: digestless signed head admitted substituted bytes: staged=%q live=%q (pointer Digest=%q; a signed promotion record with the real manifest digest exists but was not consulted)\n%s",
+ staged, live, ptr.Digest, out)
+ }
+}
+
+// Control: the same replacement under a digest-bearing pointer is refused.
+func TestHunt_H6_M2_ControlDigestBearingPointerRefuses(t *testing.T) {
+ staged, live, ptr, out := huntM2Run(t, huntM2Case{marker: true, require: false})
+ if ptr.Digest == "" {
+ t.Fatal("setup: marker on produced no digest")
+ }
+ if string(staged) == "bytes nobody promoted" || live == "v1" {
+ t.Fatalf("control: digest-bearing pointer admitted substituted bytes: staged=%q live=%q\n%s", staged, live, out)
+ }
+}
+
+// Control: the require flag refuses the digestless pointer outright.
+func TestHunt_H6_M2_ControlRequireFlagRefuses(t *testing.T) {
+ staged, live, _, out := huntM2Run(t, huntM2Case{marker: false, require: true})
+ if string(staged) == "bytes nobody promoted" || live == "v1" {
+ t.Fatalf("control: require flag admitted substituted bytes: staged=%q live=%q\n%s", staged, live, out)
+ }
+}