carlos / platform Public

stop receipts carry the fence's roster numeral and the binding (roster binding task 4, N1, B2)

hostguard.FenceTarget gains RosterRevision, the roster write counter
the stop's requester read. Root copies StopRequest.RosterRevision (and
WritersStoppedRequest's) into the cleanup, stop and no-process targets,
and BeginFence persists it before any stop effect. sameAuthority clears
it beside the bookkeeping fields (B2): a retry after unrelated roster
writes resumes the persisted fence, and BeginFence and ExistingFence
return the original target with its original numeral. Exact stored
target comparisons stay exact.

Every receipt constructor (normal, recovered, no-process) takes
directory_revision from the target's persisted numeral and carries the
installation's stamp in the new binding field. A target without a
numeral is refused before any drain or kill. The box-side receipt
checks (validateTransportStop, verifyRetirementReceipt, the legacy
journal proof digest, readMigrationStop) compare binding, and the
transport and retirement checks also require the numeral the fence
persisted. Producers send actor.Revision (launch owners carry it, so a
stop of a recorded launch uses the launch's numeral). hostops is
unchanged: git diff v0.28.4 of evidence.go, wake_reset_transport.go and
record.go is empty.

Tests: TestBeginFenceResumesAfterUnrelatedClaimCAS extended (B2, both
lookups); L7a TestStopReceiptCarriesNumeralAndBinding; N1
TestRecoveredReceiptKeepsRosterNumeral (crash after BeginFence, hold
churn, restarted root's RecoverPending, accepted by the unchanged
StopBeforeTeardown and WakeResetTransport.VerifyReceipt, a fence
without a numeral refused); L7b TestPurgeAcceptsC1ReceiptOnUnchangedVerifier;
L7c TestWakeResetAcceptsC1ReceiptOnUnchangedVerifier;
TestClaimStopCrashAfterBeginReusesDurableFenceID now pins the persisted
numeral; TestClaimStopRefusesFenceWithoutRosterNumeral. Fixtures that
hand-build receipts take the numeral the same way.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 1aaaec4e6495e8762e017c3d9873debac7ee7e81 parent b1ea7b0
42 files changed, +719 −67
  • internal/host/claim_binding_receipt_test.go +476 −0
  • internal/host/claim_binding_test.go +10 −0
  • internal/host/claimconstruction.go +1 −1
  • internal/host/claimfilesseed_cli_rootrunner_linux_test.go +1 −1
  • internal/host/claimjournal_proof.go +2 −2
  • internal/host/claimlaunch_root_test.go +1 −1
  • internal/host/claimparticipation_retired_test.go +2 −2
  • internal/host/claimretire_transport.go +4 −1
  • internal/host/claimretryrecovery_test.go +1 −1
  • internal/host/claimroleassembly.go +1 −1
  • internal/host/claimservinghandover_linux_test.go +2 −2
  • internal/host/claimservinglegacy.go +2 −2
  • internal/host/claimservinglegacyroot_linux_test.go +1 −1
  • internal/host/claimservingpark_linux_test.go +1 −1
  • internal/host/claimservingpark_rootrunner_linux_test.go +2 −2
  • internal/host/claimservingpeer_rootrunner_linux_test.go +1 −1
  • internal/host/claimservingretire_linux_test.go +1 −1
  • internal/host/claimservingwriter_rootrunner_linux_test.go +1 −1
  • internal/host/claimstop.go +51 −6
  • internal/host/claimstop_evidence_integration_test.go +20 −2
  • internal/host/claimstop_recovery.go +7 −1
  • internal/host/claimstop_test.go +40 −2
  • internal/host/claimstop_transport.go +8 −2
  • internal/host/claimstop_writers.go +8 −3
  • internal/host/claimstop_writers_test.go +1 −1
  • internal/host/claimwakestop.go +9 −2
  • internal/host/plan14_bound_retirement_root_linux_test.go +1 −1
  • internal/host/plan14_delete_participation_test.go +2 −2
  • internal/host/plan14_generation_parked_linux_test.go +2 −2
  • internal/host/plan9_d4_retire_linux_test.go +2 −2
  • internal/host/plan9_journal_proof_test.go +1 −1
  • internal/host/plan9fix1_journal_linux_test.go +1 −1
  • internal/host/relocationdischarge_linux_test.go +2 −2
  • internal/host/relocationdischarge_restart_unix_test.go +2 −2
  • internal/host/relocationeffects.go +1 −1
  • internal/host/relocationfirstwake_unix_test.go +2 −2
  • internal/host/relocationstopprobe_unix_test.go +4 −4
  • internal/host/rootgeneration_retired_linux_test.go +2 −2
  • internal/host/rootmigration_evidence.go +6 −2
  • internal/host/rootmigration_historic_linux_test.go +1 −1
  • internal/hostguard/fence.go +11 −0
  • internal/hostguard/fence_test.go +25 −2
diff --git a/internal/host/claim_binding_receipt_test.go b/internal/host/claim_binding_receipt_test.go
new file mode 100644
index 000000000..f9e84ea0d
--- /dev/null
+++ b/internal/host/claim_binding_receipt_test.go
@@ -0,0 +1,476 @@
+package host
+
+import (
+ "bytes"
+ "context"
+ "crypto/ed25519"
+ "encoding/json"
+ "errors"
+ "fmt"
+ "os"
+ "path/filepath"
+ "strconv"
+ "strings"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/hostactors"
+ "github.com/carlosframework/platform/internal/hostbox"
+ "github.com/carlosframework/platform/internal/hostclaim"
+ "github.com/carlosframework/platform/internal/hostevidence"
+ "github.com/carlosframework/platform/internal/hostguard"
+ "github.com/carlosframework/platform/internal/hostops"
+ "github.com/carlosframework/platform/internal/release"
+)
+
+// receiptWorld is one box's stop path over a signed roster: the production
+// roster identity, the box's evidence key bound as its census key by the
+// real BindCensusKey writer, a stored claim, the real hostguard fence and
+// ClaimStopCoordinator, and receipts published into the deployment store
+// the unchanged v0.28.4 console verifiers read. Only the kernel's
+// observation and the producer drain are fixtures: they are not the path
+// under test. The receipt's numeral and binding are.
+type receiptWorld struct {
+ t *testing.T
+ roster *bindingRosterFixture
+ key ed25519.PrivateKey
+ host string
+ serving bool
+ data string
+ locks string
+ kernel *receiptKernel
+ ids int
+ // installed is the actor whose binding stamps the installation.
+ installed hostbox.Actor
+}
+
+type receiptKernel struct {
+ fail error
+ recovered []hostguard.FenceTarget
+}
+
+func receiptKernelEvidence() StopKernelEvidence {
+ return StopKernelEvidence{ObservedBootID: "boot-1", InventorySHA256: strings.Repeat("b", 64), LocalJournalSHA256: strings.Repeat("c", 64), CgroupIdentities: []string{"cg-1"}, UnitInvocationIDs: []string{"unit-1"}}
+}
+
+func (k *receiptKernel) VerifyStopped(context.Context, hostguard.FenceTarget, StopInventory, DrainAcknowledgement) (StopKernelEvidence, error) {
+ if k.fail != nil {
+ return StopKernelEvidence{}, k.fail
+ }
+ return receiptKernelEvidence(), nil
+}
+
+func (k *receiptKernel) RecoverStopped(_ context.Context, t hostguard.FenceTarget, _ StopInventory) (StopKernelEvidence, DrainAcknowledgement, error) {
+ k.recovered = append(k.recovered, t)
+ return receiptKernelEvidence(), DrainClaimAcknowledgement(t.FenceID, t.ControllerID, "start-dead", nil), nil
+}
+
+func (k *receiptKernel) VerifyNoProcess(context.Context, hostguard.FenceTarget, StopInventory) (StopKernelEvidence, error) {
+ e := receiptKernelEvidence()
+ e.UnitInvocationIDs = []string{}
+ return e, nil
+}
+
+const receiptWorldHost = "shop.bab.oncarlos.com"
+
+// newReceiptWorld creates the box, binds its census key, creates the claim
+// and holds it at writer session 5: an operation's stop (op purge-1) or, with
+// serving, an ordinary serving writer's.
+func newReceiptWorld(t *testing.T, serving bool) *receiptWorld {
+ t.Helper()
+ ctx := t.Context()
+ w := &receiptWorld{t: t, roster: newBindingRosterFixture(t, "box-1", "ie"), key: ed25519.NewKeyFromSeed(bytes.Repeat([]byte{7}, ed25519.SeedSize)), host: receiptWorldHost, serving: serving, kernel: &receiptKernel{}}
+ row := w.roster.row()
+ binding := hostactors.CensusKeyBinding{Bucket: bindingFixtureBucket, Box: "box-1", Enrollment: row.Enrollment, PublicKey: w.key.Public().(ed25519.PublicKey)}
+ raw, err := json.Marshal(binding)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if _, err := w.roster.dir.BindCensusKey(ctx, w.roster.signer, w.roster.read(), binding, ed25519.Sign(w.key, raw)); err != nil {
+ t.Fatal("bind census key:", err)
+ }
+ if w.installed, err = w.roster.identity().Verify(ctx); err != nil {
+ t.Fatal(err)
+ }
+ now := time.Now().UTC().Truncate(time.Second)
+ in := hostclaim.NewHolder{Family: "instance", Key: "apps/bab/jam/instances/" + w.host + ".json", Account: "bab", App: "jam", Host: w.host, Region: "ie", RecordRegion: "ie", CreatedAt: now}
+ body := []byte(`{"schema":1,"host":"` + w.host + `","account":"bab","app":"jam","region":"ie","created_at":"` + now.Format(time.RFC3339) + `"}`)
+ absent, err := hostclaim.Read(ctx, w.roster.store, w.host)
+ if err != nil {
+ t.Fatal(err)
+ }
+ o, err := hostclaim.Update(ctx, w.roster.store, absent, hostclaim.BeginCreate(in, body, "create", "console", now))
+ if err != nil {
+ t.Fatal(err)
+ }
+ if o, err = hostclaim.Update(ctx, w.roster.store, o, hostclaim.CompleteCreate("create", "box-1")); err != nil {
+ t.Fatal(err)
+ }
+ if _, err = hostclaim.Update(ctx, w.roster.store, o, func(c *hostclaim.Claim) error {
+ h := c.Holder
+ h.Session, h.WriterBox, h.Generation = 5, "box-1", "g5"
+ h.Admissions = []hostclaim.AdmissionRecord{{Region: "ie", Session: 5, Box: "box-1", Generation: "g5", Mode: "fresh"}}
+ if !serving {
+ c.Op = hostclaim.Op{Kind: hostclaim.KindMoving, ID: "purge-1", Phase: "stopping", Exec: "box-1"}
+ }
+ return nil
+ }); err != nil {
+ t.Fatal(err)
+ }
+ w.data, w.locks = t.TempDir(), t.TempDir()
+ if err := os.Mkdir(filepath.Join(w.data, "hostguard"), 0770); err != nil {
+ t.Fatal(err)
+ }
+ if err := w.guard().Activate(ctx, w.host, "box-1", nil); err != nil {
+ t.Fatal(err)
+ }
+ return w
+}
+
+func (w *receiptWorld) claim() hostclaim.Observed {
+ w.t.Helper()
+ o, err := hostclaim.Read(w.t.Context(), w.roster.store, w.host)
+ if err != nil {
+ w.t.Fatal(err)
+ }
+ return o
+}
+
+func (w *receiptWorld) guard() hostguard.Guard {
+ return hostguard.Guard{DataDir: w.data, LockDir: w.locks, Claims: hostguard.StoreReader{Store: w.roster.store}}
+}
+
+// coordinator is root's stop coordinator as one process builds it; a new
+// call is a restarted root over the same persisted fence records.
+func (w *receiptWorld) coordinator() ClaimStopCoordinator {
+ inventory := func(_ context.Context, host string) (StopInventory, error) {
+ h := w.claim().Claim.Holder
+ return StopInventory{Host: host, Incarnation: h.Incarnation, InstallationStamp: h.Stamp, Box: "box-1", Enrollment: w.installed.Enrollment, DirectoryRevision: w.installed.Binding, Complete: true, Entries: []StopInventoryEntry{{Kind: "path", ArtifactID: "artifact-1", ManagedRoot: "data", RelativePath: "instances/" + host}}}, nil
+ }
+ return ClaimStopCoordinator{EvidenceSigner: w.key, RequestLimit: hostbox.RequestLimit, Guard: w.guard(), Claims: hostguard.StoreReader{Store: w.roster.store}, CarlosUID: 1001, Evidence: w.roster.store,
+ Peers: stopPeerFunc(func(context.Context) (StopPeer, error) {
+ return StopPeer{UID: 1001, PID: 42, ProcessStart: "start-42", BootID: "boot-1", ControllerID: "controller-1"}, nil
+ }),
+ Inventory: exactEvidenceInventory{stopInventoryFunc(inventory)},
+ Drainer: stopDrainFunc(func(_ context.Context, _ StopRequest, fence string) (DrainAcknowledgement, error) {
+ return DrainClaimAcknowledgement(fence, "controller-1", "start-42", nil), nil
+ }),
+ Kernel: w.kernel, Now: time.Now,
+ NewID: func() string { w.ids++; return fmt.Sprintf("id-%d", w.ids) }}
+}
+
+// request is the agent's stop request as its producers build it from a
+// fresh actor: the installation's binding and the roster counter it read.
+func (w *receiptWorld) request(actor hostbox.Actor) StopRequest {
+ w.t.Helper()
+ o := w.claim()
+ h := o.Claim.Holder
+ r := StopRequest{Region: actor.Region, Host: w.host, Incarnation: h.Incarnation, InstallationStamp: h.Stamp, WriterSession: h.Session, Box: actor.Box, Enrollment: actor.Enrollment,
+ BootID: "boot-1", ControllerID: "controller-1", ExpectedClaimETag: o.ETag, ExpectedDirectoryRevision: w.installed.Binding, RosterRevision: actor.Revision}
+ if !w.serving {
+ r.OperationID, r.Phase, r.ObligationID = "purge-1", "stopping", "pre-teardown-stop"
+ }
+ return r
+}
+
+func (w *receiptWorld) fresh() hostbox.Actor {
+ w.t.Helper()
+ a, err := w.roster.identity().Verify(w.t.Context())
+ if err != nil {
+ w.t.Fatal(err)
+ }
+ return a
+}
+
+func decodeStopReceipt(t *testing.T, raw []byte) StopReceipt {
+ t.Helper()
+ var r StopReceipt
+ if err := json.Unmarshal(raw, &r); err != nil {
+ t.Fatal(err)
+ }
+ return r
+}
+
+// purgeVerify runs the unchanged console's StopBeforeTeardown twice, as the
+// purge's first phase does: the first collects and verifies the receipt and
+// cites it in the claim (ErrPending), the second verifies the citation.
+func (w *receiptWorld) purgeVerify() error {
+ authority := hostops.ProductionAuthority{Store: w.roster.store, Directory: w.roster.dir, Now: time.Now}
+ err := authority.StopBeforeTeardown(w.t.Context(), w.claim())
+ if !errors.Is(err, hostops.ErrPending) {
+ return err
+ }
+ return authority.StopBeforeTeardown(w.t.Context(), w.claim())
+}
+
+// wakeResetVerify is the unchanged console's WakeResetTransport.VerifyReceipt
+// for this serving session's stop, named at the claim the stop was asked at.
+func (w *receiptWorld) wakeResetVerify(stopped hostclaim.Observed) error {
+ h := stopped.Claim.Holder
+ now := time.Now().UTC()
+ r := hostops.WakeResetRequest{Admission: hostops.WakeResetAdmission{Account: "bab", App: "jam", AppID: "app-1", Registration: "registration-1", Epoch: 1, Owner: hostops.RegistrationOwner{Console: "console", Enrollment: strings.Repeat("d", 32), Controller: "console-controller"}},
+ V: 1, ID: strings.Repeat("f", 64), Bucket: bindingFixtureBucket, Console: "console", ConsoleEnrollment: strings.Repeat("d", 32), Namespace: "platform", Host: w.host,
+ ClaimETag: stopped.ETag, ClaimGen: stopped.Claim.Gen, Incarnation: h.Incarnation, Stamp: h.Stamp, Session: h.Session, Episode: "episode-1",
+ Attempt: hostclaim.WakeRetryAttempt{ID: "attempt-1", Box: "box-1", Enrollment: w.installed.Enrollment, BootID: "boot-1", ControllerID: "controller-1"}, IssuedAt: now, Expires: now.Add(time.Minute)}
+ return hostops.WakeResetTransport{Store: w.roster.store, Directory: w.roster.dir, Now: time.Now}.VerifyReceipt(w.t.Context(), r)
+}
+
+// L7a (roster binding task 4): the normal and no-process receipt
+// constructors take directory_revision from the stop target's roster
+// numeral, never the binding, and carry the installation's binding in
+// binding. The numeral is the counter of the roster the requester read; a
+// retry after roster writes resumes the persisted fence and returns the
+// original receipt with its original numeral.
+func TestStopReceiptCarriesNumeralAndBinding(t *testing.T) {
+ ctx := t.Context()
+ for _, serving := range []bool{false, true} {
+ t.Run(fmt.Sprintf("serving=%v", serving), func(t *testing.T) {
+ w := newReceiptWorld(t, serving)
+ actor := w.fresh()
+ if !hostactors.ValidBinding(actor.Binding) || actor.Binding != w.installed.Binding {
+ t.Fatalf("actor binding %q", actor.Binding)
+ }
+ req := w.request(actor)
+ result, err := w.coordinator().FenceAndStop(ctx, req)
+ if err != nil {
+ t.Fatal(err)
+ }
+ r := decodeStopReceipt(t, result.Bytes)
+ if r.DirectoryRevision != strconv.FormatUint(actor.Revision, 10) || r.Binding != actor.Binding || result.Target.RosterRevision != actor.Revision || result.Target.DirectoryRevision != actor.Binding {
+ t.Fatalf("receipt numeral %q binding %q target %+v; want numeral %d binding %s", r.DirectoryRevision, r.Binding, result.Target, actor.Revision, actor.Binding)
+ }
+ if _, err := validateTransportStop(req, result); err != nil {
+ t.Fatal("agent refused the receipt:", err)
+ }
+ if err := verifyRetirementReceipt(ctx, hostguard.FenceReceipt{Target: result.Target, Bytes: result.Bytes, EvidenceAt: result.EvidenceAt}); err != nil {
+ t.Fatal("root's retirement check refused the receipt:", err)
+ }
+
+ // Two console creates' holds land; the agent retries with the newer
+ // numeral. Same fence, same receipt, the original numeral.
+ w.roster.holdChurn()
+ w.roster.holdChurn()
+ later := w.fresh()
+ if later.Revision != actor.Revision+4 || later.Binding != actor.Binding {
+ t.Fatalf("hold churn moved revision %d -> %d, binding %v", actor.Revision, later.Revision, later.Binding == actor.Binding)
+ }
+ retry := w.request(later)
+ again, err := w.coordinator().FenceAndStop(ctx, retry)
+ if err != nil {
+ t.Fatal("retry after hold churn:", err)
+ }
+ if !bytes.Equal(again.Bytes, result.Bytes) || again.Target != result.Target {
+ t.Fatal("retry after hold churn did not return the original receipt")
+ }
+ if _, err := validateTransportStop(retry, again); err != nil {
+ t.Fatal("agent refused the original numeral on retry:", err)
+ }
+ })
+ }
+
+ // The no-process witness (writer session zero): no fence, the witness's
+ // own target is the one source.
+ w := newReceiptWorld(t, true)
+ o := w.claim()
+ if _, err := hostclaim.Update(ctx, w.roster.store, o, func(c *hostclaim.Claim) error {
+ c.Holder.Session, c.Holder.WriterBox, c.Holder.Generation, c.Holder.Admissions = 0, "", "", nil
+ return nil
+ }); err != nil {
+ t.Fatal(err)
+ }
+ actor := w.fresh()
+ req := w.request(actor)
+ result, err := w.coordinator().FenceAndStop(ctx, req)
+ if err != nil {
+ t.Fatal("no-process witness:", err)
+ }
+ r := decodeStopReceipt(t, result.Bytes)
+ if r.Kind != StopReceiptNoProcess || r.DirectoryRevision != strconv.FormatUint(actor.Revision, 10) || r.Binding != actor.Binding || result.Target.RosterRevision != actor.Revision {
+ t.Fatalf("no-process receipt numeral %q binding %q kind %q", r.DirectoryRevision, r.Binding, r.Kind)
+ }
+ if _, err := validateTransportStop(req, result); err != nil {
+ t.Fatal("agent refused the no-process receipt:", err)
+ }
+ if err := validateServingLegacyStop(servingLegacyStop{Observed: o, Result: result}); err == nil {
+ // o is the claim before the session reset; the stored legacy stop
+ // names the claim the witness read.
+ t.Fatal("legacy stop validated against the wrong claim")
+ }
+ if err := validateServingLegacyStop(servingLegacyStop{Observed: w.claim(), Result: result}); err != nil {
+ t.Fatal("retained no-process stop:", err)
+ }
+}
+
+// N1 (roster binding task 4): the fence persists the requester's roster
+// numeral before any stop effect. Root crashes after BeginFence and before
+// CompleteFence; holds land; a restarted root's RecoverPending recovers the
+// stop from the fence alone. The recovered receipt's directory_revision is
+// the persisted numeral and its binding the installation's stamp, and the
+// branch's unchanged console verifiers accept it: the purge's
+// StopBeforeTeardown for an operation stop, WakeResetTransport.VerifyReceipt
+// for a serving stop. A fence persisted without a numeral is refused.
+func TestRecoveredReceiptKeepsRosterNumeral(t *testing.T) {
+ ctx := t.Context()
+ for _, serving := range []bool{false, true} {
+ t.Run(fmt.Sprintf("serving=%v", serving), func(t *testing.T) {
+ w := newReceiptWorld(t, serving)
+ actor := w.fresh()
+ req := w.request(actor)
+ stopped := w.claim()
+ crash := errors.New("root crashed after the fence")
+ w.kernel.fail = crash
+ if _, err := w.coordinator().FenceAndStop(ctx, req); !errors.Is(err, crash) {
+ t.Fatal(err)
+ }
+ pending, err := w.guard().PendingStopFences(ctx)
+ if err != nil || len(pending) != 1 || pending[0].RosterRevision != actor.Revision || pending[0].DirectoryRevision != actor.Binding {
+ t.Fatalf("persisted fence %+v %v", pending, err)
+ }
+
+ w.roster.holdChurn()
+ w.roster.activationChurn()
+ w.kernel.fail = nil
+ if err := (ClaimStopHTTP{Coordinator: w.coordinator()}).RecoverPending(ctx); err != nil {
+ t.Fatal("restarted root's recovery:", err)
+ }
+ if len(w.kernel.recovered) != 1 {
+ t.Fatalf("recovered %d", len(w.kernel.recovered))
+ }
+ durable, err := w.guard().FenceReceiptFor(ctx, pending[0])
+ if err != nil {
+ t.Fatal(err)
+ }
+ r := decodeStopReceipt(t, durable.Bytes)
+ if r.DirectoryRevision != strconv.FormatUint(actor.Revision, 10) || r.Binding != actor.Binding {
+ t.Fatalf("recovered receipt numeral %q binding %q; want %d and %s", r.DirectoryRevision, r.Binding, actor.Revision, actor.Binding)
+ }
+
+ // The agent's next stop request carries the newer numeral and is
+ // a recovery of the dead controller's tuple: root publishes the
+ // recovered receipt, unchanged.
+ later := w.fresh()
+ if later.Revision != actor.Revision+4 || later.Binding != actor.Binding {
+ t.Fatalf("churn moved revision %d -> %d", actor.Revision, later.Revision)
+ }
+ retry := w.request(later)
+ retry.Recover = true
+ result, err := w.coordinator().FenceAndStop(ctx, retry)
+ if err != nil {
+ t.Fatal("publication of the recovered receipt:", err)
+ }
+ if !bytes.Equal(result.Bytes, durable.Bytes) || result.Target != pending[0] {
+ t.Fatal("published another receipt than the recovered one")
+ }
+ if _, err := validateTransportStop(retry, result); err != nil {
+ t.Fatal("agent refused the recovered receipt:", err)
+ }
+ if serving {
+ if err := w.wakeResetVerify(stopped); err != nil {
+ t.Fatal("unchanged wake-reset verifier refused the recovered receipt:", err)
+ }
+ } else if err := w.purgeVerify(); err != nil {
+ t.Fatal("unchanged purge verifier refused the recovered receipt:", err)
+ }
+ })
+ }
+
+ // A fence persisted before roster binding has no numeral: recovery
+ // refuses it before any kill and journals nothing.
+ w := newReceiptWorld(t, false)
+ actor := w.fresh()
+ req := w.request(actor)
+ legacy := hostguard.FenceTarget{FenceID: "legacy", ClaimGen: w.claim().Claim.Gen, Region: req.Region, Host: req.Host, Incarnation: req.Incarnation, Stamp: req.InstallationStamp, Session: req.WriterSession, Op: req.OperationID, Phase: req.Phase, ObligationID: req.ObligationID,
+ Box: req.Box, Enrollment: req.Enrollment, BootID: req.BootID, ControllerID: req.ControllerID, ClaimETag: req.ExpectedClaimETag, DirectoryRevision: req.ExpectedDirectoryRevision}
+ if _, err := w.guard().BeginFence(ctx, legacy); err != nil {
+ t.Fatal(err)
+ }
+ if err := (ClaimStopHTTP{Coordinator: w.coordinator()}).RecoverPending(ctx); !errors.Is(err, ErrClaimStopReceipt) || len(w.kernel.recovered) != 0 {
+ t.Fatalf("legacy fence recovery: %v, kills %d", err, len(w.kernel.recovered))
+ }
+ if _, err := w.guard().FenceReceiptFor(ctx, legacy); !errors.Is(err, hostguard.ErrNoFenceReceipt) {
+ t.Fatalf("legacy fence journaled a receipt: %v", err)
+ }
+}
+
+// publishTampered publishes body, re-signed with the box's evidence key,
+// under a fresh receipt id: a receipt only a wrong producer would write.
+func (w *receiptWorld) publishTampered(result StopResult, edit func(map[string]any)) {
+ w.t.Helper()
+ var fields map[string]any
+ if err := json.Unmarshal(result.Bytes, &fields); err != nil {
+ w.t.Fatal(err)
+ }
+ edit(fields)
+ fields["id"] = "tampered"
+ body, err := json.Marshal(fields)
+ if err != nil {
+ w.t.Fatal(err)
+ }
+ r := decodeStopReceipt(w.t, body)
+ if err := hostevidence.Publish(w.t.Context(), w.roster.store, w.key, stopEvidenceKey(r.Host, r.OperationID, r.Box, r.ID), body); err != nil {
+ w.t.Fatal(err)
+ }
+}
+
+// stopUnpublished collects a genuine receipt through the real coordinator
+// without publishing it into the deployment store.
+func (w *receiptWorld) stopUnpublished(req StopRequest) StopResult {
+ w.t.Helper()
+ c := w.coordinator()
+ c.Evidence = release.NewDirStore(w.t.TempDir())
+ result, err := c.FenceAndStop(w.t.Context(), req)
+ if err != nil {
+ w.t.Fatal(err)
+ }
+ return result
+}
+
+// L7b (roster binding R1, mixed version): a task 4 receipt, signed with the
+// box's evidence key under the operation's evidence/ key, passes the
+// branch's unchanged StopBeforeTeardown and verifyEvidence after further
+// roster writes. The same receipt with the binding in directory_revision is
+// refused.
+func TestPurgeAcceptsC1ReceiptOnUnchangedVerifier(t *testing.T) {
+ w := newReceiptWorld(t, false)
+ if _, err := w.coordinator().FenceAndStop(t.Context(), w.request(w.fresh())); err != nil {
+ t.Fatal(err)
+ }
+ w.roster.holdChurn()
+ if err := w.purgeVerify(); err != nil {
+ t.Fatal("unchanged purge verifier refused a task 4 receipt:", err)
+ }
+
+ w = newReceiptWorld(t, false)
+ result := w.stopUnpublished(w.request(w.fresh()))
+ w.publishTampered(result, func(f map[string]any) { f["directory_revision"] = f["binding"]; delete(f, "binding") })
+ if err := w.purgeVerify(); !errors.Is(err, hostops.ErrIdentity) {
+ t.Fatalf("purge verifier with the binding in directory_revision: %v", err)
+ }
+}
+
+// L7c (roster binding R1, mixed version): the same through the unchanged
+// WakeResetTransport.VerifyReceipt under serving-evidence/, and a
+// quarantined actor is still refused before any receipt is read.
+func TestWakeResetAcceptsC1ReceiptOnUnchangedVerifier(t *testing.T) {
+ w := newReceiptWorld(t, true)
+ stopped := w.claim()
+ if _, err := w.coordinator().FenceAndStop(t.Context(), w.request(w.fresh())); err != nil {
+ t.Fatal(err)
+ }
+ w.roster.holdChurn()
+ if err := w.wakeResetVerify(stopped); err != nil {
+ t.Fatal("unchanged wake-reset verifier refused a task 4 receipt:", err)
+ }
+ w.roster.quarantine("loss_1")
+ if err := w.wakeResetVerify(stopped); !errors.Is(err, hostops.ErrIdentity) {
+ t.Fatalf("wake reset for a quarantined actor: %v", err)
+ }
+
+ w = newReceiptWorld(t, true)
+ stopped = w.claim()
+ result := w.stopUnpublished(w.request(w.fresh()))
+ w.publishTampered(result, func(f map[string]any) { f["directory_revision"] = f["binding"]; delete(f, "binding") })
+ if err := w.wakeResetVerify(stopped); !errors.Is(err, hostops.ErrWakeResetUncertain) {
+ t.Fatalf("wake-reset verifier with the binding in directory_revision: %v", err)
+ }
+}
diff --git a/internal/host/claim_binding_test.go b/internal/host/claim_binding_test.go
index c22c98537..1088cbe1e 100644
--- a/internal/host/claim_binding_test.go
+++ b/internal/host/claim_binding_test.go
@@ -1,12 +1,22 @@
package host
import (
+ "strconv"
"strings"
"testing"
"github.com/carlosframework/platform/internal/hostbox"
+ "github.com/carlosframework/platform/internal/hostguard"
)
+// testReceiptNumeral is a hand-built receipt's directory_revision, taken the
+// way every production receipt constructor takes it: from the fence target's
+// persisted RosterRevision (roster binding N1). The receipt's binding is the
+// target's DirectoryRevision.
+func testReceiptNumeral(t hostguard.FenceTarget) string {
+ return strconv.FormatUint(t.RosterRevision, 10)
+}
+
// servingPriorBinding is equality with the fresh actor's binding, never an
// ordering: an older numeral stamp, a stamp from before a readmission, or
// any stamp against an actor without a binding is refused.
diff --git a/internal/host/claimconstruction.go b/internal/host/claimconstruction.go
index dfc7bc189..ef0dbaec9 100644
--- a/internal/host/claimconstruction.go
+++ b/internal/host/claimconstruction.go
@@ -323,7 +323,7 @@ func OpenProductionClaimAssembly(ctx context.Context, store release.Store, r Cla
return nil, hostwrite.ErrUnavailable
}
h := o.Claim.Holder
- target := hostguard.FenceTarget{Host: o.Host, Incarnation: h.Incarnation, Stamp: h.Stamp, Session: h.Session, Op: o.Claim.Op.ID, Phase: o.Claim.Op.Phase, Box: actor.Box, Region: actor.Region, Enrollment: actor.Enrollment, BootID: strings.TrimSpace(string(boot)), ControllerID: controller, ClaimETag: o.ETag, DirectoryRevision: actor.Binding}
+ target := hostguard.FenceTarget{Host: o.Host, Incarnation: h.Incarnation, Stamp: h.Stamp, Session: h.Session, Op: o.Claim.Op.ID, Phase: o.Claim.Op.Phase, Box: actor.Box, Region: actor.Region, Enrollment: actor.Enrollment, BootID: strings.TrimSpace(string(boot)), ControllerID: controller, ClaimETag: o.ETag, DirectoryRevision: actor.Binding, RosterRevision: actor.Revision}
return producers.Ensure(target, processStart, launches.RecordProducer, launches.CompleteProducer)
}
wake.Roles = &ClaimRoleAssembly{Guard: guard, Claims: store, Manager: r.Manager, Journal: launches, Inventory: inventory, ManagedRoots: roots, Identity: owners.Identity, BootID: strings.TrimSpace(string(boot)), ControllerID: controller}
diff --git a/internal/host/claimfilesseed_cli_rootrunner_linux_test.go b/internal/host/claimfilesseed_cli_rootrunner_linux_test.go
index 612b71f38..4c16d281c 100644
--- a/internal/host/claimfilesseed_cli_rootrunner_linux_test.go
+++ b/internal/host/claimfilesseed_cli_rootrunner_linux_test.go
@@ -304,7 +304,7 @@ func TestFilesSeedCLIStopFixture(t *testing.T) {
c.RetainNoProcess = f.p.retainLegacyNoProcess
o := f.f.read()
h := o.Claim.Holder
- req := StopRequest{Region: f.actor.Region, Host: o.Host, Incarnation: h.Incarnation, InstallationStamp: h.Stamp, Box: f.actor.Box, Enrollment: f.actor.Enrollment, BootID: f.f.peer.BootID, ControllerID: f.f.peer.ControllerID, ExpectedClaimETag: o.ETag, ExpectedDirectoryRevision: f.actor.Binding}
+ req := StopRequest{Region: f.actor.Region, Host: o.Host, Incarnation: h.Incarnation, InstallationStamp: h.Stamp, Box: f.actor.Box, Enrollment: f.actor.Enrollment, BootID: f.f.peer.BootID, ControllerID: f.f.peer.ControllerID, ExpectedClaimETag: o.ETag, ExpectedDirectoryRevision: f.actor.Binding, RosterRevision: f.actor.Revision}
if _, err := c.FenceAndStop(t.Context(), req); err != nil {
t.Fatal("CLI fixture no-process", err)
}
diff --git a/internal/host/claimjournal_proof.go b/internal/host/claimjournal_proof.go
index 742e49244..b19152c2a 100644
--- a/internal/host/claimjournal_proof.go
+++ b/internal/host/claimjournal_proof.go
@@ -103,7 +103,7 @@ func legacyJournalProof(store release.Store, directory hostactors.Directory) fun
return err
}
target := in.Target
- wanted := StopReceipt{Host: target.Host, Incarnation: target.Incarnation, InstallationStamp: target.Stamp, WriterSession: target.Session, Box: target.Box, Enrollment: target.Enrollment, BootID: target.BootID, ControllerID: target.ControllerID, OperationID: target.Op, Region: target.Region, DirectoryRevision: inventory.DirectoryRevision, InventorySHA256: digestStop(inventory), LocalJournalSHA256: digestStop(journal)}
+ wanted := StopReceipt{Host: target.Host, Incarnation: target.Incarnation, InstallationStamp: target.Stamp, WriterSession: target.Session, Box: target.Box, Enrollment: target.Enrollment, BootID: target.BootID, ControllerID: target.ControllerID, OperationID: target.Op, Region: target.Region, Binding: inventory.DirectoryRevision, InventorySHA256: digestStop(inventory), LocalJournalSHA256: digestStop(journal)}
if _, ok := cached.matches[legacyJournalProofMatch(wanted)]; ok {
return nil
}
@@ -111,7 +111,7 @@ func legacyJournalProof(store release.Store, directory hostactors.Directory) fun
}
}
func legacyJournalProofMatch(p StopReceipt) string {
- return digestStop([]any{p.Host, p.Incarnation, p.InstallationStamp, p.WriterSession, p.Box, p.Enrollment, p.BootID, p.ControllerID, p.OperationID, p.Region, p.DirectoryRevision, p.InventorySHA256, p.LocalJournalSHA256})
+ return digestStop([]any{p.Host, p.Incarnation, p.InstallationStamp, p.WriterSession, p.Box, p.Enrollment, p.BootID, p.ControllerID, p.OperationID, p.Region, p.Binding, p.InventorySHA256, p.LocalJournalSHA256})
}
// A shared batch can cover many rows, but no individual network request may
diff --git a/internal/host/claimlaunch_root_test.go b/internal/host/claimlaunch_root_test.go
index ef7a4f2f8..136b12c1d 100644
--- a/internal/host/claimlaunch_root_test.go
+++ b/internal/host/claimlaunch_root_test.go
@@ -163,7 +163,7 @@ func newLaunchFixtureHost(t *testing.T, op hostclaim.Op, host string) *launchFix
previousAgentRoot := claimContainmentAgentRoot
claimContainmentAgentRoot = func(context.Context) (string, error) { return "/sys/fs/cgroup/system.slice/carlos-edge.service", nil }
t.Cleanup(func() { claimContainmentAgentRoot = previousAgentRoot })
- target := hostguard.FenceTarget{Region: "eu", Host: host, Incarnation: "inc-1", Stamp: 11, Session: 13, Op: op.ID, Phase: op.Phase, Box: "box-1", Enrollment: "enrollment-1", BootID: boot, ControllerID: "controller-1", ClaimETag: "etag-1", DirectoryRevision: "7"}
+ target := hostguard.FenceTarget{Region: "eu", Host: host, Incarnation: "inc-1", Stamp: 11, Session: 13, Op: op.ID, Phase: op.Phase, Box: "box-1", Enrollment: "enrollment-1", BootID: boot, ControllerID: "controller-1", ClaimETag: "etag-1", DirectoryRevision: "7", RosterRevision: 7}
if err = journal.Prelaunch(t.Context(), hostbox.LaunchInventory{ControllerPID: os.Getpid(), ProcessStart: start, Target: target, Groups: []hostbox.LaunchGroup{{RelativePath: filepath.Join("system.slice/carlos-edge.service", cgroup.ExecName(claimContainmentName(target))), Device: 1, Inode: 9}}, NoState: true}); err != nil {
t.Fatal(err)
}
diff --git a/internal/host/claimparticipation_retired_test.go b/internal/host/claimparticipation_retired_test.go
index 109952478..e9849d404 100644
--- a/internal/host/claimparticipation_retired_test.go
+++ b/internal/host/claimparticipation_retired_test.go
@@ -16,9 +16,9 @@ func TestPlan14RetiredParticipationDischarge(t *testing.T) {
t.Run(mode, func(t *testing.T) {
binding := execlease.Binding{Host: "shop.example", Incarnation: "inc", Op: "delete", Box: "box", Enrollment: "enrollment"}
o := hostclaim.Observed{Host: binding.Host, Claim: &hostclaim.Claim{Host: binding.Host, Holder: &hostclaim.Holder{Incarnation: "inc", Stamp: 3, Session: 4}, Op: hostclaim.Op{Kind: hostclaim.KindParking, ID: "delete"}}}
- target := hostguard.FenceTarget{Host: binding.Host, Incarnation: "inc", Stamp: 3, Session: 4, Box: "box", Enrollment: "enrollment", Op: "delete", Phase: "park", ObligationID: "park-local", FenceID: "fence", BootID: "boot", ControllerID: "controller", ClaimETag: "etag", ClaimGen: 5, DirectoryRevision: "1", Region: "ie"}
+ target := hostguard.FenceTarget{Host: binding.Host, Incarnation: "inc", Stamp: 3, Session: 4, Box: "box", Enrollment: "enrollment", Op: "delete", Phase: "park", ObligationID: "park-local", FenceID: "fence", BootID: "boot", ControllerID: "controller", ClaimETag: "etag", ClaimGen: 5, DirectoryRevision: "1", RosterRevision: 1, Region: "ie"}
at := time.Now().UTC()
- s := StopReceipt{V: 1, Kind: "stopped", Host: target.Host, Incarnation: target.Incarnation, InstallationStamp: target.Stamp, WriterSession: target.Session, Box: target.Box, Enrollment: target.Enrollment, OperationID: target.Op, Phase: target.Phase, ObligationID: target.ObligationID, FenceID: target.FenceID, BootID: target.BootID, ControllerID: target.ControllerID, ClaimETag: target.ClaimETag, ClaimGen: target.ClaimGen, DirectoryRevision: target.DirectoryRevision, Region: target.Region, EvidenceAt: at}
+ s := StopReceipt{V: 1, Kind: "stopped", Host: target.Host, Incarnation: target.Incarnation, InstallationStamp: target.Stamp, WriterSession: target.Session, Box: target.Box, Enrollment: target.Enrollment, OperationID: target.Op, Phase: target.Phase, ObligationID: target.ObligationID, FenceID: target.FenceID, BootID: target.BootID, ControllerID: target.ControllerID, ClaimETag: target.ClaimETag, ClaimGen: target.ClaimGen, DirectoryRevision: testReceiptNumeral(target), Binding: target.DirectoryRevision, Region: target.Region, EvidenceAt: at}
captured := hostguard.Captured{Incarnation: "inc", Stamp: 3}
view := hostguard.FenceView{Installation: hostguard.RootInstallation{Host: binding.Host, Incarnation: "inc", Stamp: 3, Box: "box", Enrollment: "enrollment"}, Retired: []hostguard.Captured{captured}, Receipts: []hostguard.FenceReceipt{{Target: target, Bytes: mustMarshalStopReceipt(s), EvidenceAt: at}}}
switch mode {
diff --git a/internal/host/claimretire_transport.go b/internal/host/claimretire_transport.go
index b45cd1948..44c6dcb20 100644
--- a/internal/host/claimretire_transport.go
+++ b/internal/host/claimretire_transport.go
@@ -177,7 +177,10 @@ func verifyRetirementReceipt(_ context.Context, receipt hostguard.FenceReceipt)
return ErrClaimStopReceipt
}
t := receipt.Target
- if s.Kind != "stopped" || s.Region != t.Region || s.ClaimETag != t.ClaimETag || s.ClaimGen != t.ClaimGen || s.ObligationID != t.ObligationID || s.FenceID != t.FenceID || s.Host != t.Host || s.Incarnation != t.Incarnation || s.InstallationStamp != t.Stamp || s.WriterSession != t.Session || s.OperationID != t.Op || s.Phase != t.Phase || s.Box != t.Box || s.Enrollment != t.Enrollment || s.BootID != t.BootID || s.ControllerID != t.ControllerID || s.DirectoryRevision != t.DirectoryRevision || !s.EvidenceAt.Equal(receipt.EvidenceAt) {
+ if s.Kind != "stopped" || s.Region != t.Region || s.ClaimETag != t.ClaimETag || s.ClaimGen != t.ClaimGen || s.ObligationID != t.ObligationID || s.FenceID != t.FenceID || s.Host != t.Host || s.Incarnation != t.Incarnation || s.InstallationStamp != t.Stamp || s.WriterSession != t.Session || s.OperationID != t.Op || s.Phase != t.Phase || s.Box != t.Box || s.Enrollment != t.Enrollment || s.BootID != t.BootID || s.ControllerID != t.ControllerID || s.Binding != t.DirectoryRevision || !s.EvidenceAt.Equal(receipt.EvidenceAt) {
+ return ErrClaimStopReceipt
+ }
+ if numeral, err := stopReceiptNumeral(t); err != nil || s.DirectoryRevision != numeral {
return ErrClaimStopReceipt
}
return nil
diff --git a/internal/host/claimretryrecovery_test.go b/internal/host/claimretryrecovery_test.go
index 09429886f..5894be165 100644
--- a/internal/host/claimretryrecovery_test.go
+++ b/internal/host/claimretryrecovery_test.go
@@ -243,7 +243,7 @@ func recoveryTuple(o hostclaim.Observed, l claimStopLocal) hostguard.FenceTarget
if stamp == "" {
stamp = fmt.Sprint(l.Actor.Revision)
}
- return hostguard.FenceTarget{Region: l.Actor.Region, Host: o.Host, Incarnation: h.Incarnation, Stamp: h.Stamp, Session: h.Session, Box: l.Actor.Box, Enrollment: l.Actor.Enrollment, BootID: l.BootID, ControllerID: l.ControllerID, ClaimETag: o.ETag, DirectoryRevision: stamp}
+ return hostguard.FenceTarget{Region: l.Actor.Region, Host: o.Host, Incarnation: h.Incarnation, Stamp: h.Stamp, Session: h.Session, Box: l.Actor.Box, Enrollment: l.Actor.Enrollment, BootID: l.BootID, ControllerID: l.ControllerID, ClaimETag: o.ETag, DirectoryRevision: stamp, RosterRevision: l.Actor.Revision}
}
// root is instance-control's coordinator for one request. The live peer is
diff --git a/internal/host/claimroleassembly.go b/internal/host/claimroleassembly.go
index d67fbbbbb..9308f8eba 100644
--- a/internal/host/claimroleassembly.go
+++ b/internal/host/claimroleassembly.go
@@ -54,7 +54,7 @@ func (a *ClaimRoleAssembly) launchTarget(ctx context.Context, o hostclaim.Observ
return hostguard.FenceTarget{}, err
}
h := o.Claim.Holder
- return hostguard.FenceTarget{Region: actor.Region, Host: o.Host, Incarnation: h.Incarnation, Stamp: h.Stamp, Session: h.Session, Op: o.Claim.Op.ID, Phase: o.Claim.Op.Phase, Box: actor.Box, Enrollment: actor.Enrollment, BootID: a.BootID, ControllerID: a.ControllerID, ClaimETag: o.ETag, DirectoryRevision: actor.Binding}, nil
+ return hostguard.FenceTarget{Region: actor.Region, Host: o.Host, Incarnation: h.Incarnation, Stamp: h.Stamp, Session: h.Session, Op: o.Claim.Op.ID, Phase: o.Claim.Op.Phase, Box: actor.Box, Enrollment: actor.Enrollment, BootID: a.BootID, ControllerID: a.ControllerID, ClaimETag: o.ETag, DirectoryRevision: actor.Binding, RosterRevision: actor.Revision}, nil
}
// Preflight admits a launch before retry reservation, admission or state
diff --git a/internal/host/claimservinghandover_linux_test.go b/internal/host/claimservinghandover_linux_test.go
index b40186979..aab31fe0f 100644
--- a/internal/host/claimservinghandover_linux_test.go
+++ b/internal/host/claimservinghandover_linux_test.go
@@ -210,7 +210,7 @@ func TestServingHandoverLegacy(t *testing.T) {
}
f.f.peer.BootID = boot
o := f.f.read()
- req := StopRequest{Region: f.actor.Region, Host: o.Host, Incarnation: o.Claim.Holder.Incarnation, InstallationStamp: o.Claim.Holder.Stamp, Box: f.actor.Box, Enrollment: f.actor.Enrollment, BootID: boot, ControllerID: "controller", ExpectedClaimETag: o.ETag, ExpectedDirectoryRevision: "7"}
+ req := StopRequest{Region: f.actor.Region, Host: o.Host, Incarnation: o.Claim.Holder.Incarnation, InstallationStamp: o.Claim.Holder.Stamp, Box: f.actor.Box, Enrollment: f.actor.Enrollment, BootID: boot, ControllerID: "controller", ExpectedClaimETag: o.ETag, ExpectedDirectoryRevision: "7", RosterRevision: 7}
if _, err := coordinator.FenceAndStop(t.Context(), req); err != nil {
t.Fatal(err)
}
@@ -359,7 +359,7 @@ func TestServingStoppedWriterSecondHandover(t *testing.T) {
t.Fatal(err)
}
o := f.f.read()
- req := StopRequest{Region: f.actor.Region, Host: o.Host, Incarnation: f.current.Incarnation, InstallationStamp: f.current.Stamp, WriterSession: f.current.Session, Box: f.actor.Box, Enrollment: f.actor.Enrollment, BootID: f.receipt.Target.BootID, ControllerID: "controller", ExpectedClaimETag: o.ETag, ExpectedDirectoryRevision: "7"}
+ req := StopRequest{Region: f.actor.Region, Host: o.Host, Incarnation: f.current.Incarnation, InstallationStamp: f.current.Stamp, WriterSession: f.current.Session, Box: f.actor.Box, Enrollment: f.actor.Enrollment, BootID: f.receipt.Target.BootID, ControllerID: "controller", ExpectedClaimETag: o.ETag, ExpectedDirectoryRevision: "7", RosterRevision: 7}
drain := stopDrainFunc(func(_ context.Context, req StopRequest, fence string) (DrainAcknowledgement, error) {
return DrainClaimAcknowledgement(fence, req.ControllerID, "edge-start", nil), nil
})
diff --git a/internal/host/claimservinglegacy.go b/internal/host/claimservinglegacy.go
index 0c26886b4..5bb4446ba 100644
--- a/internal/host/claimservinglegacy.go
+++ b/internal/host/claimservinglegacy.go
@@ -45,8 +45,8 @@ func validateServingLegacyStop(s servingLegacyStop) error {
if json.Unmarshal(result.Bytes, &r) != nil || !bytes.Equal(result.Bytes, mustMarshalStopReceipt(r)) || r.V != 1 || r.Kind != StopReceiptNoProcess || !stopComponent(r.ID) || r.ProducerDrainDigest != "" || !stopDigest(r.InventorySHA256) || !stopDigest(r.LocalJournalSHA256) || len(r.CgroupIdentities) == 0 || len(r.UnitInvocationIDs) != 0 || r.ClaimETag != o.ETag || r.ClaimGen != c.Gen || result.EvidenceAt.IsZero() || result.Key != stopEvidenceKey(o.Host, "", t.Box, r.ID) {
return ErrClaimStopReceipt
}
- req := StopRequest{Region: t.Region, Host: t.Host, Incarnation: t.Incarnation, InstallationStamp: t.Stamp, Box: t.Box, Enrollment: t.Enrollment, BootID: t.BootID, ControllerID: t.ControllerID, ExpectedClaimETag: o.ETag, ExpectedDirectoryRevision: t.DirectoryRevision}
- if t.Region == "" || t.Box == "" || t.Enrollment == "" || t.BootID == "" || t.ControllerID == "" || t.DirectoryRevision == "" {
+ req := StopRequest{Region: t.Region, Host: t.Host, Incarnation: t.Incarnation, InstallationStamp: t.Stamp, Box: t.Box, Enrollment: t.Enrollment, BootID: t.BootID, ControllerID: t.ControllerID, ExpectedClaimETag: o.ETag, ExpectedDirectoryRevision: t.DirectoryRevision, RosterRevision: t.RosterRevision}
+ if t.Region == "" || t.Box == "" || t.Enrollment == "" || t.BootID == "" || t.ControllerID == "" || t.DirectoryRevision == "" || t.RosterRevision == 0 {
return ErrClaimStopReceipt
}
_, err := validateTransportStop(req, result)
diff --git a/internal/host/claimservinglegacyroot_linux_test.go b/internal/host/claimservinglegacyroot_linux_test.go
index c14eac0e6..1780d741f 100644
--- a/internal/host/claimservinglegacyroot_linux_test.go
+++ b/internal/host/claimservinglegacyroot_linux_test.go
@@ -92,7 +92,7 @@ func newServingLegacyRootFixture(t *testing.T, empty bool, beforeAdmission ...fu
f := fx.f
o := f.read()
h := o.Claim.Holder
- req := StopRequest{Region: "ie", Host: o.Host, Incarnation: h.Incarnation, InstallationStamp: h.Stamp, Box: "box-1", Enrollment: "enrollment", BootID: "boot", ControllerID: "controller", ExpectedClaimETag: o.ETag, ExpectedDirectoryRevision: "7"}
+ req := StopRequest{Region: "ie", Host: o.Host, Incarnation: h.Incarnation, InstallationStamp: h.Stamp, Box: "box-1", Enrollment: "enrollment", BootID: "boot", ControllerID: "controller", ExpectedClaimETag: o.ETag, ExpectedDirectoryRevision: "7", RosterRevision: 7}
if _, err := coordinator.FenceAndStop(t.Context(), req); err != nil {
t.Fatalf("no-process: %v", err)
}
diff --git a/internal/host/claimservingpark_linux_test.go b/internal/host/claimservingpark_linux_test.go
index f16f0a929..ad3d2d3fb 100644
--- a/internal/host/claimservingpark_linux_test.go
+++ b/internal/host/claimservingpark_linux_test.go
@@ -60,7 +60,7 @@ func (f *servingParkDiskFixture) evidence(n uint64, legacy bool, state string) (
next.Stamp, next.Session, next.Generation = n+1, n+1, fmt.Sprintf("G%d", n+1)
target := f.target
target.Stamp, target.Session, target.FenceID = n, n, fmt.Sprintf("stop-%d", n)
- s := StopReceipt{V: 1, ID: target.FenceID, Kind: StopReceiptStopped, Region: target.Region, ClaimETag: target.ClaimETag, ClaimGen: target.ClaimGen, FenceID: target.FenceID, Host: target.Host, Incarnation: target.Incarnation, InstallationStamp: target.Stamp, WriterSession: target.Session, Box: target.Box, Enrollment: target.Enrollment, BootID: target.BootID, ControllerID: target.ControllerID, DirectoryRevision: target.DirectoryRevision, EvidenceAt: f.now}
+ s := StopReceipt{V: 1, ID: target.FenceID, Kind: StopReceiptStopped, Region: target.Region, ClaimETag: target.ClaimETag, ClaimGen: target.ClaimGen, FenceID: target.FenceID, Host: target.Host, Incarnation: target.Incarnation, InstallationStamp: target.Stamp, WriterSession: target.Session, Box: target.Box, Enrollment: target.Enrollment, BootID: target.BootID, ControllerID: target.ControllerID, DirectoryRevision: testReceiptNumeral(target), Binding: target.DirectoryRevision, EvidenceAt: f.now}
receipts := []hostguard.FenceReceipt{{Target: target, Bytes: mustMarshalStopReceipt(s), EvidenceAt: f.now}}
if state != "missing" && !legacy {
if err := f.ledger.journal.Prelaunch(t.Context(), hostbox.LaunchInventory{Target: target, ControllerPID: 77, ProcessStart: "controller-start", NoState: true, Groups: []hostbox.LaunchGroup{{RelativePath: "carlos/parent", Device: 1, Inode: 2}}}); err != nil {
diff --git a/internal/host/claimservingpark_rootrunner_linux_test.go b/internal/host/claimservingpark_rootrunner_linux_test.go
index 53ad534b3..06fb59121 100644
--- a/internal/host/claimservingpark_rootrunner_linux_test.go
+++ b/internal/host/claimservingpark_rootrunner_linux_test.go
@@ -154,8 +154,8 @@ func servingRunnerPark(t *testing.T, data string, state rootstate.Store) serving
// Stop authorization remains explicitly fixture-backed. It is encoded in
// the production record format so the reboot inspector reads the ledger.
at := time.Now().UTC()
- target := hostguard.FenceTarget{Host: current.Host, Box: current.Box, Region: current.Region, Incarnation: current.Incarnation, Stamp: 1, Session: 1, FenceID: "runner-stop", Enrollment: "runner-enrollment", BootID: source.BootID, ControllerID: "runner-controller", DirectoryRevision: "1", ClaimETag: "runner-claim", ClaimGen: 1}
- receipt := StopReceipt{V: 1, ID: target.FenceID, Kind: StopReceiptStopped, Region: target.Region, Host: target.Host, Box: target.Box, Incarnation: target.Incarnation, InstallationStamp: target.Stamp, WriterSession: target.Session, FenceID: target.FenceID, Enrollment: target.Enrollment, BootID: target.BootID, ControllerID: target.ControllerID, DirectoryRevision: target.DirectoryRevision, ClaimETag: target.ClaimETag, ClaimGen: target.ClaimGen, EvidenceAt: at}
+ target := hostguard.FenceTarget{Host: current.Host, Box: current.Box, Region: current.Region, Incarnation: current.Incarnation, Stamp: 1, Session: 1, FenceID: "runner-stop", Enrollment: "runner-enrollment", BootID: source.BootID, ControllerID: "runner-controller", DirectoryRevision: "1", RosterRevision: 1, ClaimETag: "runner-claim", ClaimGen: 1}
+ receipt := StopReceipt{V: 1, ID: target.FenceID, Kind: StopReceiptStopped, Region: target.Region, Host: target.Host, Box: target.Box, Incarnation: target.Incarnation, InstallationStamp: target.Stamp, WriterSession: target.Session, FenceID: target.FenceID, Enrollment: target.Enrollment, BootID: target.BootID, ControllerID: target.ControllerID, DirectoryRevision: testReceiptNumeral(target), Binding: target.DirectoryRevision, ClaimETag: target.ClaimETag, ClaimGen: target.ClaimGen, EvidenceAt: at}
r := servingParkRecord{Version: 1, Authorization: a, Source: source, Disposition: servingParkRetain, Receipts: []hostguard.FenceReceipt{{Target: target, Bytes: mustMarshalStopReceipt(receipt), EvidenceAt: at}}}
save := func() error {
l := servingParkLedger{state: state}
diff --git a/internal/host/claimservingpeer_rootrunner_linux_test.go b/internal/host/claimservingpeer_rootrunner_linux_test.go
index b22aaab39..d443dffb5 100644
--- a/internal/host/claimservingpeer_rootrunner_linux_test.go
+++ b/internal/host/claimservingpeer_rootrunner_linux_test.go
@@ -570,7 +570,7 @@ func runServingParkPeerNamespace(t *testing.T, handover, writer bool, namespace
stops := 0
retries := activator.ServingRetries{Claims: f.f.claims, Box: f.actor.Box, Enrollment: f.actor.Enrollment, BootID: next.BootID, ControllerID: next.ControllerID, Now: func() time.Time { return f.f.now }, NewID: f.f.newID, Inputs: func(context.Context, registry.Route) (string, error) { return "seed-inputs", nil }, ExactHealth: func(context.Context, *exec.Cmd, hostclaim.WakeRetryAttempt) error { return hostbox.ErrChanged }, StopAttempt: func(ctx context.Context, o hostclaim.Observed, a hostclaim.WakeRetryAttempt) error {
stops++
- req := StopRequest{Region: f.actor.Region, Recover: true, Host: o.Host, Incarnation: o.Claim.Holder.Incarnation, InstallationStamp: o.Claim.Holder.Stamp, WriterSession: o.Claim.Holder.Session, Box: f.actor.Box, Enrollment: f.actor.Enrollment, BootID: a.BootID, ControllerID: a.ControllerID, ExpectedClaimETag: o.ETag, ExpectedDirectoryRevision: pre.Launch.Target.DirectoryRevision}
+ req := StopRequest{Region: f.actor.Region, Recover: true, Host: o.Host, Incarnation: o.Claim.Holder.Incarnation, InstallationStamp: o.Claim.Holder.Stamp, WriterSession: o.Claim.Holder.Session, Box: f.actor.Box, Enrollment: f.actor.Enrollment, BootID: a.BootID, ControllerID: a.ControllerID, ExpectedClaimETag: o.ETag, ExpectedDirectoryRevision: pre.Launch.Target.DirectoryRevision, RosterRevision: pre.Launch.Target.RosterRevision}
command(servingPeerCommand{Action: "stop", Stop: req}, false)
return nil
}}
diff --git a/internal/host/claimservingretire_linux_test.go b/internal/host/claimservingretire_linux_test.go
index 52c7a0483..8f392d89b 100644
--- a/internal/host/claimservingretire_linux_test.go
+++ b/internal/host/claimservingretire_linux_test.go
@@ -175,7 +175,7 @@ func servingStopFor(t *testing.T, f *recoveryFixture, o hostclaim.Observed, acto
if _, err := f.guard.BeginFence(t.Context(), target); err != nil {
t.Fatal(err)
}
- s := StopReceipt{V: 1, ID: target.FenceID, Kind: StopReceiptStopped, Region: target.Region, ClaimETag: target.ClaimETag, ClaimGen: target.ClaimGen, FenceID: target.FenceID, Host: target.Host, Incarnation: target.Incarnation, InstallationStamp: target.Stamp, WriterSession: target.Session, Box: target.Box, Enrollment: target.Enrollment, BootID: target.BootID, ControllerID: target.ControllerID, DirectoryRevision: target.DirectoryRevision, EvidenceAt: f.now}
+ s := StopReceipt{V: 1, ID: target.FenceID, Kind: StopReceiptStopped, Region: target.Region, ClaimETag: target.ClaimETag, ClaimGen: target.ClaimGen, FenceID: target.FenceID, Host: target.Host, Incarnation: target.Incarnation, InstallationStamp: target.Stamp, WriterSession: target.Session, Box: target.Box, Enrollment: target.Enrollment, BootID: target.BootID, ControllerID: target.ControllerID, DirectoryRevision: testReceiptNumeral(target), Binding: target.DirectoryRevision, EvidenceAt: f.now}
body := mustMarshalStopReceipt(s)
receipt := hostguard.FenceReceipt{Target: target, Bytes: body, EvidenceAt: f.now}
if err := f.guard.CompleteFence(t.Context(), target, body, f.now, func(ctx context.Context, _ hostguard.FenceTarget, _ []byte, _ time.Time) error {
diff --git a/internal/host/claimservingwriter_rootrunner_linux_test.go b/internal/host/claimservingwriter_rootrunner_linux_test.go
index bbc0add8d..ca4019c25 100644
--- a/internal/host/claimservingwriter_rootrunner_linux_test.go
+++ b/internal/host/claimservingwriter_rootrunner_linux_test.go
@@ -179,7 +179,7 @@ func runServingPeerStoppedWriter(t *testing.T, f *servingRootFixture, binary str
t.Fatal(err)
}
current := f.f.read()
- req := StopRequest{Region: f.actor.Region, Host: current.Host, Incarnation: f.current.Incarnation, InstallationStamp: f.current.Stamp, WriterSession: f.current.Session, Box: f.actor.Box, Enrollment: f.actor.Enrollment, BootID: peer.BootID, ControllerID: peer.ControllerID, ExpectedClaimETag: current.ETag, ExpectedDirectoryRevision: "7"}
+ req := StopRequest{Region: f.actor.Region, Host: current.Host, Incarnation: f.current.Incarnation, InstallationStamp: f.current.Stamp, WriterSession: f.current.Session, Box: f.actor.Box, Enrollment: f.actor.Enrollment, BootID: peer.BootID, ControllerID: peer.ControllerID, ExpectedClaimETag: current.ETag, ExpectedDirectoryRevision: "7", RosterRevision: 7}
stop := servingPeerCommand{Action: "stop", Stop: req}
checkNoReceipt := func() {
t.Helper()
diff --git a/internal/host/claimstop.go b/internal/host/claimstop.go
index e61c6893a..22a4c5c3b 100644
--- a/internal/host/claimstop.go
+++ b/internal/host/claimstop.go
@@ -10,6 +10,7 @@ import (
"encoding/json"
"errors"
"fmt"
+ "strconv"
"strings"
"time"
@@ -59,6 +60,10 @@ type StopRequest struct {
BootID, ControllerID string
ExpectedClaimETag string
ExpectedDirectoryRevision string
+ // RosterRevision is the roster write counter of the roster the requester
+ // read. Root persists it in the fence target; it becomes the receipt's
+ // directory_revision numeral (roster binding N1).
+ RosterRevision uint64
}
type StopClaimReader interface {
@@ -90,6 +95,11 @@ type StopKernelVerifier interface {
VerifyStopped(context.Context, hostguard.FenceTarget, StopInventory, DrainAcknowledgement) (StopKernelEvidence, error)
}
+// StopReceipt is root's signed stop evidence. DirectoryRevision is the
+// roster write counter, a numeral, taken from the fence target's persisted
+// RosterRevision: the v0.28.4 console bounds it by 0 < n <= roster.Revision.
+// Binding is the installation's binding; box-side receipt comparisons use it
+// (roster binding N1, R1).
type StopReceipt struct {
RequestLimitNS int64 `json:"request_limit_ns"`
Region string `json:"region,omitempty"`
@@ -110,6 +120,7 @@ type StopReceipt struct {
ControllerID string `json:"controller_id"`
ClaimGen uint64 `json:"claim_gen"`
DirectoryRevision string `json:"directory_revision"`
+ Binding string `json:"binding,omitempty"`
Kind string `json:"kind"`
EvidenceAt time.Time `json:"evidence_at"`
FenceID string `json:"fence_id"`
@@ -172,12 +183,32 @@ func (c ClaimStopCoordinator) validateShape(r StopRequest) error {
if c.CarlosUID == 0 || c.Peers == nil || c.Claims == nil || c.Inventory == nil || c.Drainer == nil || c.Kernel == nil || c.Evidence == nil || c.NewID == nil || c.Now == nil ||
!stopComponent(r.Host) || !stopOperationTuple(r.OperationID, r.Phase, r.ObligationID) || !stopComponent(r.Box) ||
!stopComponent(r.Enrollment) || r.Incarnation == "" || r.InstallationStamp == 0 ||
- r.BootID == "" || r.ControllerID == "" || r.ExpectedClaimETag == "" || r.ExpectedDirectoryRevision == "" {
+ r.BootID == "" || r.ControllerID == "" || r.ExpectedClaimETag == "" || r.ExpectedDirectoryRevision == "" || r.RosterRevision == 0 {
return ErrClaimStopUnavailable
}
return nil
}
+// stopReceiptNumeral is a receipt's directory_revision, read from the one
+// persisted source: the fence target's RosterRevision. A target without one
+// (written before roster binding) cannot produce a receipt.
+func stopReceiptNumeral(t hostguard.FenceTarget) (string, error) {
+ if t.RosterRevision == 0 {
+ return "", ErrClaimStopReceipt
+ }
+ return strconv.FormatUint(t.RosterRevision, 10), nil
+}
+
+// receiptRosterRevision parses a receipt's directory_revision numeral: a
+// canonical non-zero decimal.
+func receiptRosterRevision(s string) (uint64, bool) {
+ n, err := strconv.ParseUint(s, 10, 64)
+ if err != nil || n == 0 || strconv.FormatUint(n, 10) != s {
+ return 0, false
+ }
+ return n, true
+}
+
// The receipt kinds: a stopped writer session, and the no-process witness
// for an installation whose holder never admitted a writer (R4).
const (
@@ -220,7 +251,7 @@ func (c ClaimStopCoordinator) FenceAndStop(ctx context.Context, req StopRequest)
var observed hostclaim.Observed
var cleanupTarget *hostguard.FenceTarget
if req.Cleanup {
- want := hostguard.FenceTarget{Region: req.Region, Host: req.Host, Incarnation: req.Incarnation, Stamp: req.InstallationStamp, Session: req.WriterSession, Op: req.OperationID, Phase: req.Phase, ObligationID: req.ObligationID, Box: req.Box, Enrollment: req.Enrollment, BootID: req.BootID, ControllerID: req.ControllerID, ClaimETag: req.ExpectedClaimETag, DirectoryRevision: req.ExpectedDirectoryRevision}
+ want := hostguard.FenceTarget{Region: req.Region, Host: req.Host, Incarnation: req.Incarnation, Stamp: req.InstallationStamp, Session: req.WriterSession, Op: req.OperationID, Phase: req.Phase, ObligationID: req.ObligationID, Box: req.Box, Enrollment: req.Enrollment, BootID: req.BootID, ControllerID: req.ControllerID, ClaimETag: req.ExpectedClaimETag, DirectoryRevision: req.ExpectedDirectoryRevision, RosterRevision: req.RosterRevision}
durable, err := c.Guard.ExistingFence(ctx, want)
if err != nil {
return StopResult{}, err
@@ -266,7 +297,7 @@ func (c ClaimStopCoordinator) FenceAndStop(ctx context.Context, req StopRequest)
}
target := hostguard.FenceTarget{Region: req.Region, ClaimGen: gen, ObligationID: req.ObligationID, FenceID: fenceID, Host: req.Host, Incarnation: req.Incarnation, Stamp: req.InstallationStamp,
Session: req.WriterSession, Op: req.OperationID, Phase: req.Phase, Box: req.Box, Enrollment: req.Enrollment,
- BootID: req.BootID, ControllerID: req.ControllerID, ClaimETag: req.ExpectedClaimETag, DirectoryRevision: req.ExpectedDirectoryRevision}
+ BootID: req.BootID, ControllerID: req.ControllerID, ClaimETag: req.ExpectedClaimETag, DirectoryRevision: req.ExpectedDirectoryRevision, RosterRevision: req.RosterRevision}
if cleanupTarget != nil {
target = *cleanupTarget
err = c.Guard.ResumeFence(ctx, target)
@@ -277,6 +308,14 @@ func (c ClaimStopCoordinator) FenceAndStop(ctx context.Context, req StopRequest)
return StopResult{}, err
}
fenceID = target.FenceID
+ // The receipt numeral comes from the persisted fence target, never from
+ // this request: a retry after roster writes resumes the original fence
+ // and its original numeral (B2). A fence persisted without one cannot
+ // produce a receipt and is refused before any drain or kill (N1).
+ numeral, err := stopReceiptNumeral(target)
+ if err != nil {
+ return StopResult{}, err
+ }
if durable, err := c.Guard.FenceReceiptFor(ctx, target); err == nil {
result, err := stopResultFromDurable(req, durable)
if err != nil {
@@ -332,7 +371,7 @@ func (c ClaimStopCoordinator) FenceAndStop(ctx context.Context, req StopRequest)
InstallationStamp: req.InstallationStamp, WriterSession: req.WriterSession, OperationID: req.OperationID,
Phase: req.Phase, ObligationID: req.ObligationID, Box: req.Box, Enrollment: req.Enrollment,
BootID: req.BootID, ControllerID: req.ControllerID, ClaimGen: target.ClaimGen,
- DirectoryRevision: req.ExpectedDirectoryRevision, Kind: StopReceiptStopped, EvidenceAt: evidenceAt, FenceID: fenceID,
+ DirectoryRevision: numeral, Binding: target.DirectoryRevision, Kind: StopReceiptStopped, EvidenceAt: evidenceAt, FenceID: fenceID,
InventorySHA256: kernel.InventorySHA256, LocalJournalSHA256: kernel.LocalJournalSHA256,
ProducerDrainDigest: ack.Digest, CgroupIdentities: append([]string(nil), kernel.CgroupIdentities...),
UnitInvocationIDs: append([]string(nil), kernel.UnitInvocationIDs...)}
@@ -396,7 +435,7 @@ func (c ClaimStopCoordinator) witnessNoProcess(ctx context.Context, req StopRequ
}
target := hostguard.FenceTarget{Region: req.Region, ClaimGen: claim.Gen, ObligationID: req.ObligationID, Host: req.Host, Incarnation: req.Incarnation, Stamp: req.InstallationStamp,
Op: req.OperationID, Phase: req.Phase, Box: req.Box, Enrollment: req.Enrollment, BootID: req.BootID, ControllerID: req.ControllerID,
- ClaimETag: req.ExpectedClaimETag, DirectoryRevision: req.ExpectedDirectoryRevision}
+ ClaimETag: req.ExpectedClaimETag, DirectoryRevision: req.ExpectedDirectoryRevision, RosterRevision: req.RosterRevision}
if claim.Op.Kind == hostclaim.KindServing {
if req.OperationID != "" || req.Region == "" || claim.Op.Exec != req.Box {
return StopResult{}, ErrClaimStopIdentity
@@ -404,6 +443,12 @@ func (c ClaimStopCoordinator) witnessNoProcess(ctx context.Context, req StopRequ
} else if !hostguard.StopAuthorityMatches(claim, target) {
return StopResult{}, ErrClaimStopIdentity
}
+ // No session ran, so there is no fence: the witness's own target is the
+ // receipt's one source, retained with the result.
+ numeral, err := stopReceiptNumeral(target)
+ if err != nil {
+ return StopResult{}, err
+ }
inv, err := c.Inventory.ReadStopInventory(ctx, req.Host)
if err != nil {
return StopResult{}, err
@@ -430,7 +475,7 @@ func (c ClaimStopCoordinator) witnessNoProcess(ctx context.Context, req StopRequ
}
receipt := StopReceipt{RequestLimitNS: int64(c.RequestLimit), Region: req.Region, ClaimETag: req.ExpectedClaimETag, ObservedBootID: kernelEvidence.ObservedBootID, V: 1, ID: receiptID, Host: req.Host,
Incarnation: req.Incarnation, InstallationStamp: req.InstallationStamp, OperationID: req.OperationID, Phase: req.Phase, ObligationID: req.ObligationID,
- Box: req.Box, Enrollment: req.Enrollment, BootID: req.BootID, ControllerID: req.ControllerID, ClaimGen: claim.Gen, DirectoryRevision: req.ExpectedDirectoryRevision,
+ Box: req.Box, Enrollment: req.Enrollment, BootID: req.BootID, ControllerID: req.ControllerID, ClaimGen: claim.Gen, DirectoryRevision: numeral, Binding: target.DirectoryRevision,
Kind: StopReceiptNoProcess, EvidenceAt: evidenceAt, InventorySHA256: kernelEvidence.InventorySHA256, LocalJournalSHA256: kernelEvidence.LocalJournalSHA256,
CgroupIdentities: append([]string(nil), kernelEvidence.CgroupIdentities...), UnitInvocationIDs: append([]string{}, kernelEvidence.UnitInvocationIDs...)}
body, err := json.Marshal(receipt)
diff --git a/internal/host/claimstop_evidence_integration_test.go b/internal/host/claimstop_evidence_integration_test.go
index bd60ee634..69032653b 100644
--- a/internal/host/claimstop_evidence_integration_test.go
+++ b/internal/host/claimstop_evidence_integration_test.go
@@ -7,6 +7,7 @@ import (
"encoding/json"
"errors"
"fmt"
+ "reflect"
"testing"
"github.com/carlosframework/platform/internal/hostbox"
@@ -88,7 +89,22 @@ func TestClaimPendingStopRecoveryProducesPublishableSignedReceipt(t *testing.T)
if err := json.Unmarshal(result.Bytes, &producer); err != nil {
t.Fatal(err)
}
- decoder := json.NewDecoder(bytes.NewReader(result.Bytes))
+ // The receipt adds exactly one field the unchanged console does not
+ // declare, binding (roster binding R1; hostops' decoder tolerates it).
+ // Every other field is the console's, with the same values.
+ var fields map[string]json.RawMessage
+ if err := json.Unmarshal(result.Bytes, &fields); err != nil {
+ t.Fatal(err)
+ }
+ if string(fields["binding"]) != `"`+req.ExpectedDirectoryRevision+`"` || string(fields["directory_revision"]) != `"7"` {
+ t.Fatalf("recovered receipt stamps: numeral %s binding %s", fields["directory_revision"], fields["binding"])
+ }
+ delete(fields, "binding")
+ rest, err := json.Marshal(fields)
+ if err != nil {
+ t.Fatal(err)
+ }
+ decoder := json.NewDecoder(bytes.NewReader(rest))
decoder.DisallowUnknownFields()
if err := decoder.Decode(&consumer); err != nil {
t.Fatal(err)
@@ -100,7 +116,9 @@ func TestClaimPendingStopRecoveryProducesPublishableSignedReceipt(t *testing.T)
if err != nil {
t.Fatal(err)
}
- if string(consumerBytes) != string(result.Bytes) {
+ var got map[string]any
+ var want map[string]any
+ if json.Unmarshal(consumerBytes, &got) != nil || json.Unmarshal(rest, &want) != nil || !reflect.DeepEqual(got, want) {
t.Fatal("producer and consumer receipt fields differ")
}
if _, err := validateTransportStop(req, result); err != nil {
diff --git a/internal/host/claimstop_recovery.go b/internal/host/claimstop_recovery.go
index 3d73d8b0a..b519cd3d8 100644
--- a/internal/host/claimstop_recovery.go
+++ b/internal/host/claimstop_recovery.go
@@ -54,6 +54,12 @@ func (c ClaimStopCoordinator) RecoverStopped(ctx context.Context, target hostgua
if !ok {
return StopResult{}, ErrClaimStopInventory
}
+ // A fence persisted without a roster numeral cannot produce a receipt the
+ // console accepts; refuse it before any kill (roster binding N1).
+ numeral, err := stopReceiptNumeral(target)
+ if err != nil {
+ return StopResult{}, err
+ }
if err := c.Guard.ResumeFence(ctx, target); err != nil {
return StopResult{}, err
}
@@ -79,7 +85,7 @@ func (c ClaimStopCoordinator) RecoverStopped(ctx context.Context, target hostgua
if at.IsZero() || !stopDigest(evidence.InventorySHA256) || !stopDigest(evidence.LocalJournalSHA256) || len(evidence.CgroupIdentities) == 0 {
return StopResult{}, ErrClaimStopReceipt
}
- receipt := StopReceipt{RequestLimitNS: int64(c.RequestLimit), Region: target.Region, ClaimETag: target.ClaimETag, ObservedBootID: evidence.ObservedBootID, V: 1, ID: id, ClaimGen: target.ClaimGen, Host: target.Host, Incarnation: target.Incarnation, InstallationStamp: target.Stamp, WriterSession: target.Session, OperationID: target.Op, Phase: target.Phase, ObligationID: target.ObligationID, Box: target.Box, Enrollment: target.Enrollment, BootID: target.BootID, ControllerID: target.ControllerID, DirectoryRevision: target.DirectoryRevision, Kind: "stopped", EvidenceAt: at, FenceID: target.FenceID, InventorySHA256: evidence.InventorySHA256, LocalJournalSHA256: evidence.LocalJournalSHA256, ProducerDrainDigest: ack.Digest, CgroupIdentities: evidence.CgroupIdentities, UnitInvocationIDs: evidence.UnitInvocationIDs}
+ receipt := StopReceipt{RequestLimitNS: int64(c.RequestLimit), Region: target.Region, ClaimETag: target.ClaimETag, ObservedBootID: evidence.ObservedBootID, V: 1, ID: id, ClaimGen: target.ClaimGen, Host: target.Host, Incarnation: target.Incarnation, InstallationStamp: target.Stamp, WriterSession: target.Session, OperationID: target.Op, Phase: target.Phase, ObligationID: target.ObligationID, Box: target.Box, Enrollment: target.Enrollment, BootID: target.BootID, ControllerID: target.ControllerID, DirectoryRevision: numeral, Binding: target.DirectoryRevision, Kind: "stopped", EvidenceAt: at, FenceID: target.FenceID, InventorySHA256: evidence.InventorySHA256, LocalJournalSHA256: evidence.LocalJournalSHA256, ProducerDrainDigest: ack.Digest, CgroupIdentities: evidence.CgroupIdentities, UnitInvocationIDs: evidence.UnitInvocationIDs}
body, err := json.Marshal(receipt)
if err != nil {
return StopResult{}, err
diff --git a/internal/host/claimstop_test.go b/internal/host/claimstop_test.go
index 395c92d4f..123f02dd7 100644
--- a/internal/host/claimstop_test.go
+++ b/internal/host/claimstop_test.go
@@ -75,7 +75,7 @@ func claimStopFixture(t *testing.T) (ClaimStopCoordinator, StopRequest, *failPut
req := StopRequest{Host: host, Incarnation: "inc-1", InstallationStamp: 11, WriterSession: 13,
OperationID: "operation-1", Phase: "stopping", ObligationID: "obligation-1", Box: "box-1",
Enrollment: "enrollment-1", BootID: "boot-1", ControllerID: "controller-1",
- ExpectedClaimETag: "etag-1", ExpectedDirectoryRevision: "directory-1"}
+ ExpectedClaimETag: "etag-1", ExpectedDirectoryRevision: "directory-1", RosterRevision: 7}
base := release.NewDirStore(t.TempDir())
store := &failPutStore{Store: base}
ids := []string{"fence-1", "receipt-1", "fence-retry", "receipt-retry"}
@@ -163,12 +163,16 @@ func TestClaimStopPublicationRetryKeepsBytesAndEvidenceTime(t *testing.T) {
}
}
+// The fence was persisted with roster numeral 5 before the crash; the retry
+// arrives after two roster writes with numeral 7. The retry resumes the
+// durable fence, and its receipt carries the persisted numeral and the
+// installation's binding (roster binding B2, N1).
func TestClaimStopCrashAfterBeginReusesDurableFenceID(t *testing.T) {
c, req, _ := claimStopFixture(t)
original := hostguard.FenceTarget{ObligationID: req.ObligationID, ClaimGen: 19, FenceID: "fence-before-crash", Host: req.Host, Incarnation: req.Incarnation,
Stamp: req.InstallationStamp, Session: req.WriterSession, Op: req.OperationID, Phase: req.Phase,
Box: req.Box, Enrollment: req.Enrollment, BootID: req.BootID, ControllerID: req.ControllerID,
- ClaimETag: req.ExpectedClaimETag, DirectoryRevision: req.ExpectedDirectoryRevision}
+ ClaimETag: req.ExpectedClaimETag, DirectoryRevision: req.ExpectedDirectoryRevision, RosterRevision: req.RosterRevision - 2}
if _, err := c.Guard.BeginFence(t.Context(), original); err != nil {
t.Fatal(err)
}
@@ -188,6 +192,40 @@ func TestClaimStopCrashAfterBeginReusesDurableFenceID(t *testing.T) {
if seen != original.FenceID || receipt.FenceID != original.FenceID {
t.Fatalf("retry used fence %q, receipt %q, want durable %q", seen, receipt.FenceID, original.FenceID)
}
+ if result.Target != original || receipt.DirectoryRevision != "5" || receipt.Binding != req.ExpectedDirectoryRevision {
+ t.Fatalf("retry target %+v, receipt numeral %q binding %q; want the persisted fence's", result.Target, receipt.DirectoryRevision, receipt.Binding)
+ }
+ if _, err := validateTransportStop(req, result); err != nil {
+ t.Fatal("the agent refused the original numeral:", err)
+ }
+}
+
+// A fence persisted before roster binding has no numeral: a retry resumes
+// it, and it is refused before any drain, with the deny kept.
+func TestClaimStopRefusesFenceWithoutRosterNumeral(t *testing.T) {
+ c, req, _ := claimStopFixture(t)
+ legacy := hostguard.FenceTarget{ObligationID: req.ObligationID, ClaimGen: 19, FenceID: "legacy-fence", Host: req.Host, Incarnation: req.Incarnation,
+ Stamp: req.InstallationStamp, Session: req.WriterSession, Op: req.OperationID, Phase: req.Phase,
+ Box: req.Box, Enrollment: req.Enrollment, BootID: req.BootID, ControllerID: req.ControllerID,
+ ClaimETag: req.ExpectedClaimETag, DirectoryRevision: req.ExpectedDirectoryRevision}
+ if _, err := c.Guard.BeginFence(t.Context(), legacy); err != nil {
+ t.Fatal(err)
+ }
+ c.Drainer = stopDrainFunc(func(context.Context, StopRequest, string) (DrainAcknowledgement, error) {
+ t.Fatal("a fence without a numeral was drained")
+ return DrainAcknowledgement{}, nil
+ })
+ if _, err := c.FenceAndStop(t.Context(), req); !errors.Is(err, ErrClaimStopReceipt) {
+ t.Fatalf("legacy fence: %v", err)
+ }
+ if pending, err := c.Guard.PendingFences(t.Context()); err != nil || len(pending) != 1 || pending[0] != legacy {
+ t.Fatalf("legacy fence not kept: %+v %v", pending, err)
+ }
+ zero := req
+ zero.RosterRevision = 0
+ if _, err := c.FenceAndStop(t.Context(), zero); !errors.Is(err, ErrClaimStopUnavailable) {
+ t.Fatalf("a request without a numeral: %v", err)
+ }
}
func TestClaimStopCompletedRetryPublishesOriginalEvidence(t *testing.T) {
diff --git a/internal/host/claimstop_transport.go b/internal/host/claimstop_transport.go
index 62589b7c1..09caf0576 100644
--- a/internal/host/claimstop_transport.go
+++ b/internal/host/claimstop_transport.go
@@ -204,11 +204,17 @@ func validateTransportStop(req StopRequest, result StopResult) (StopResult, erro
if err := json.Unmarshal(result.Bytes, &receipt); err != nil {
return StopResult{}, err
}
- if receipt.Region != req.Region || receipt.Host != req.Host || receipt.Incarnation != req.Incarnation || receipt.InstallationStamp != req.InstallationStamp || receipt.WriterSession != req.WriterSession || receipt.OperationID != req.OperationID || receipt.Phase != req.Phase || receipt.ObligationID != req.ObligationID || receipt.Box != req.Box || receipt.Enrollment != req.Enrollment || receipt.BootID != req.BootID || receipt.ControllerID != req.ControllerID || receipt.DirectoryRevision != req.ExpectedDirectoryRevision || !result.EvidenceAt.Equal(receipt.EvidenceAt) {
+ if receipt.Region != req.Region || receipt.Host != req.Host || receipt.Incarnation != req.Incarnation || receipt.InstallationStamp != req.InstallationStamp || receipt.WriterSession != req.WriterSession || receipt.OperationID != req.OperationID || receipt.Phase != req.Phase || receipt.ObligationID != req.ObligationID || receipt.Box != req.Box || receipt.Enrollment != req.Enrollment || receipt.BootID != req.BootID || receipt.ControllerID != req.ControllerID || receipt.Binding != req.ExpectedDirectoryRevision || !result.EvidenceAt.Equal(receipt.EvidenceAt) {
return StopResult{}, ErrClaimStopIdentity
}
+ // The numeral is the fence's, not this request's: a retry after roster
+ // writes returns the original receipt with its original numeral.
+ numeral, ok := receiptRosterRevision(receipt.DirectoryRevision)
+ if !ok {
+ return StopResult{}, ErrClaimStopReceipt
+ }
- expected := hostguard.FenceTarget{Region: receipt.Region, FenceID: receipt.FenceID, ClaimGen: receipt.ClaimGen, ObligationID: receipt.ObligationID, Host: receipt.Host, Incarnation: receipt.Incarnation, Stamp: receipt.InstallationStamp, Session: receipt.WriterSession, Op: receipt.OperationID, Phase: receipt.Phase, Box: receipt.Box, Enrollment: receipt.Enrollment, BootID: receipt.BootID, ControllerID: receipt.ControllerID, ClaimETag: receipt.ClaimETag, DirectoryRevision: receipt.DirectoryRevision}
+ expected := hostguard.FenceTarget{Region: receipt.Region, FenceID: receipt.FenceID, ClaimGen: receipt.ClaimGen, ObligationID: receipt.ObligationID, Host: receipt.Host, Incarnation: receipt.Incarnation, Stamp: receipt.InstallationStamp, Session: receipt.WriterSession, Op: receipt.OperationID, Phase: receipt.Phase, Box: receipt.Box, Enrollment: receipt.Enrollment, BootID: receipt.BootID, ControllerID: receipt.ControllerID, ClaimETag: receipt.ClaimETag, DirectoryRevision: receipt.Binding, RosterRevision: numeral}
if result.Target != expected {
return StopResult{}, ErrClaimStopIdentity
}
diff --git a/internal/host/claimstop_writers.go b/internal/host/claimstop_writers.go
index 362accb25..56cc445c0 100644
--- a/internal/host/claimstop_writers.go
+++ b/internal/host/claimstop_writers.go
@@ -37,6 +37,7 @@ type WritersStoppedRequest struct {
ControllerID string `json:"controller_id"`
ExpectedClaimETag string `json:"expected_claim_etag"`
ExpectedDirectoryRevision string `json:"expected_directory_revision"`
+ RosterRevision uint64 `json:"roster_revision"`
Replicator []stopevidence.DescriptorHint `json:"replicator"`
}
@@ -83,7 +84,7 @@ type stopWritersKernel interface {
func (c ClaimStopCoordinator) WritersStopped(ctx context.Context, req WritersStoppedRequest) (WritersStoppedEvidence, error) {
if ctx == nil || c.CarlosUID == 0 || c.Peers == nil || c.Claims == nil || c.Inventory == nil || c.Kernel == nil || c.Now == nil ||
!stopComponent(req.Host) || !stopComponent(req.Box) || !stopComponent(req.Enrollment) || req.Incarnation == "" || req.InstallationStamp == 0 || req.WriterSession == 0 ||
- req.BootID == "" || req.ControllerID == "" || req.ExpectedClaimETag == "" || req.ExpectedDirectoryRevision == "" {
+ req.BootID == "" || req.ControllerID == "" || req.ExpectedClaimETag == "" || req.ExpectedDirectoryRevision == "" || req.RosterRevision == 0 {
return WritersStoppedEvidence{}, ErrClaimStopUnavailable
}
kernel, ok := c.Kernel.(stopWritersKernel)
@@ -106,7 +107,7 @@ func (c ClaimStopCoordinator) WritersStopped(ctx context.Context, req WritersSto
}
claim, holder := observed.Claim, observed.Claim.Holder
target := hostguard.FenceTarget{Region: req.Region, ClaimGen: claim.Gen, Host: req.Host, Incarnation: req.Incarnation, Stamp: req.InstallationStamp, Session: req.WriterSession,
- Op: claim.Op.ID, Phase: claim.Op.Phase, Box: req.Box, Enrollment: req.Enrollment, BootID: req.BootID, ControllerID: req.ControllerID, ClaimETag: req.ExpectedClaimETag, DirectoryRevision: req.ExpectedDirectoryRevision}
+ Op: claim.Op.ID, Phase: claim.Op.Phase, Box: req.Box, Enrollment: req.Enrollment, BootID: req.BootID, ControllerID: req.ControllerID, ClaimETag: req.ExpectedClaimETag, DirectoryRevision: req.ExpectedDirectoryRevision, RosterRevision: req.RosterRevision}
// The session is this box's writer: the holder names it, and the claim
// gives this box the authority a stop of it would need.
if claim.Host != req.Host || holder.WriterBox != req.Box || !hostguard.StopAuthorityMatches(claim, target) {
@@ -240,11 +241,15 @@ func (a ClaimAssembly) writersStopped(ctx context.Context, host string, read fun
if revision == "" {
revision = local.Actor.Binding
}
+ rosterRevision := t.RosterRevision
+ if rosterRevision == 0 {
+ rosterRevision = local.Actor.Revision
+ }
att.mu.Lock()
hints := slices.Clone(att.replicatorFDs)
att.mu.Unlock()
req := WritersStoppedRequest{Region: local.Actor.Region, Host: host, Incarnation: t.Incarnation, InstallationStamp: t.Stamp, WriterSession: t.Session, Box: t.Box, Enrollment: t.Enrollment,
- BootID: t.BootID, ControllerID: t.ControllerID, ExpectedClaimETag: observed.ETag, ExpectedDirectoryRevision: revision, Replicator: hints}
+ BootID: t.BootID, ControllerID: t.ControllerID, ExpectedClaimETag: observed.ETag, ExpectedDirectoryRevision: revision, RosterRevision: rosterRevision, Replicator: hints}
ev, err := collect(ctx, req)
if err != nil {
return ClaimWritersDrained{}, WritersStoppedEvidence{}, err
diff --git a/internal/host/claimstop_writers_test.go b/internal/host/claimstop_writers_test.go
index 211aba91b..3fd1a1786 100644
--- a/internal/host/claimstop_writers_test.go
+++ b/internal/host/claimstop_writers_test.go
@@ -43,7 +43,7 @@ func writersFixtureCoordinator(t *testing.T) (ClaimStopCoordinator, WritersStopp
kernel := &writersKernelFake{}
c.Kernel = kernel
w := WritersStoppedRequest{Region: req.Region, Host: req.Host, Incarnation: req.Incarnation, InstallationStamp: req.InstallationStamp, WriterSession: req.WriterSession,
- Box: req.Box, Enrollment: req.Enrollment, BootID: req.BootID, ControllerID: req.ControllerID, ExpectedClaimETag: req.ExpectedClaimETag, ExpectedDirectoryRevision: req.ExpectedDirectoryRevision,
+ Box: req.Box, Enrollment: req.Enrollment, BootID: req.BootID, ControllerID: req.ControllerID, ExpectedClaimETag: req.ExpectedClaimETag, ExpectedDirectoryRevision: req.ExpectedDirectoryRevision, RosterRevision: req.RosterRevision,
Replicator: []stopevidence.DescriptorHint{{FD: 7, Device: 1, Inode: 2}}}
return c, w, kernel
}
diff --git a/internal/host/claimwakestop.go b/internal/host/claimwakestop.go
index 20214edfa..3177ac38c 100644
--- a/internal/host/claimwakestop.go
+++ b/internal/host/claimwakestop.go
@@ -31,6 +31,7 @@ type claimStopLocal struct {
type claimLaunchOwner struct {
BootID, ControllerID string
DirectoryRevision string
+ RosterRevision uint64
PID int
ProcessStart string
}
@@ -45,7 +46,7 @@ func (o claimLaunchOwner) local(l claimStopLocal) bool {
}
func ownerOf(in hostbox.LaunchInventory) claimLaunchOwner {
- return claimLaunchOwner{BootID: in.Target.BootID, ControllerID: in.Target.ControllerID, DirectoryRevision: in.Target.DirectoryRevision, PID: in.ControllerPID, ProcessStart: in.ProcessStart}
+ return claimLaunchOwner{BootID: in.Target.BootID, ControllerID: in.Target.ControllerID, DirectoryRevision: in.Target.DirectoryRevision, RosterRevision: in.Target.RosterRevision, PID: in.ControllerPID, ProcessStart: in.ProcessStart}
}
// recoveryStopDrain refuses. A recovered controller's producers ended with it,
@@ -309,7 +310,13 @@ func (a ClaimAssembly) collectCapturedStop(ctx context.Context, captured hostcla
// No record was found. Root still requires exact journal evidence.
directoryRevision = actor.Binding
}
- req := StopRequest{Region: actor.Region, Recover: recovering, Host: observed.Host, Incarnation: holder.Incarnation, InstallationStamp: holder.Stamp, WriterSession: holder.Session, OperationID: claim.Op.ID, Phase: claim.Op.Phase, ObligationID: obligation, Box: actor.Box, Enrollment: actor.Enrollment, BootID: owner.BootID, ControllerID: owner.ControllerID, ExpectedClaimETag: observed.ETag, ExpectedDirectoryRevision: directoryRevision}
+ // The receipt numeral: the launch record's roster counter, or this
+ // actor's when no record (or a record from before roster binding) names one.
+ rosterRevision := owner.RosterRevision
+ if rosterRevision == 0 {
+ rosterRevision = actor.Revision
+ }
+ req := StopRequest{Region: actor.Region, Recover: recovering, Host: observed.Host, Incarnation: holder.Incarnation, InstallationStamp: holder.Stamp, WriterSession: holder.Session, OperationID: claim.Op.ID, Phase: claim.Op.Phase, ObligationID: obligation, Box: actor.Box, Enrollment: actor.Enrollment, BootID: owner.BootID, ControllerID: owner.ControllerID, ExpectedClaimETag: observed.ETag, ExpectedDirectoryRevision: directoryRevision, RosterRevision: rosterRevision}
target := hostguard.FenceTarget{Region: req.Region, Host: req.Host, Incarnation: req.Incarnation, Stamp: req.InstallationStamp, Session: req.WriterSession, Op: req.OperationID, Phase: req.Phase, ObligationID: req.ObligationID, Box: req.Box}
if zero && claim.Op.Kind == hostclaim.KindServing {
// A never-admitted holder may be a new creator or an adopted legacy
diff --git a/internal/host/plan14_bound_retirement_root_linux_test.go b/internal/host/plan14_bound_retirement_root_linux_test.go
index 16aa080db..31d8fff6f 100644
--- a/internal/host/plan14_bound_retirement_root_linux_test.go
+++ b/internal/host/plan14_bound_retirement_root_linux_test.go
@@ -42,7 +42,7 @@ func plan14CombinedBoundRetirement(t *testing.T, dir string, f *launchFixture, m
t.Fatal("combined fence", err)
}
at := time.Now().UTC()
- receipt := StopReceipt{V: 1, Kind: "stopped", ID: "combined-receipt", FenceID: target.FenceID, Host: target.Host, Incarnation: target.Incarnation, InstallationStamp: target.Stamp, WriterSession: target.Session, Region: target.Region, ClaimETag: target.ClaimETag, ClaimGen: target.ClaimGen, OperationID: target.Op, Phase: target.Phase, ObligationID: target.ObligationID, Box: target.Box, Enrollment: target.Enrollment, BootID: target.BootID, ControllerID: target.ControllerID, DirectoryRevision: target.DirectoryRevision, EvidenceAt: at}
+ receipt := StopReceipt{V: 1, Kind: "stopped", ID: "combined-receipt", FenceID: target.FenceID, Host: target.Host, Incarnation: target.Incarnation, InstallationStamp: target.Stamp, WriterSession: target.Session, Region: target.Region, ClaimETag: target.ClaimETag, ClaimGen: target.ClaimGen, OperationID: target.Op, Phase: target.Phase, ObligationID: target.ObligationID, Box: target.Box, Enrollment: target.Enrollment, BootID: target.BootID, ControllerID: target.ControllerID, DirectoryRevision: testReceiptNumeral(target), Binding: target.DirectoryRevision, EvidenceAt: at}
raw, _ := json.Marshal(receipt)
if err = f.root.Guard.CompleteFence(t.Context(), target, raw, at, func(ctx context.Context, t hostguard.FenceTarget, body []byte, when time.Time) error {
return verifyRetirementReceipt(ctx, hostguard.FenceReceipt{Target: t, Bytes: body, EvidenceAt: when})
diff --git a/internal/host/plan14_delete_participation_test.go b/internal/host/plan14_delete_participation_test.go
index 1a92a2f6d..be20abbc6 100644
--- a/internal/host/plan14_delete_participation_test.go
+++ b/internal/host/plan14_delete_participation_test.go
@@ -28,14 +28,14 @@ func TestPlan14OrdinaryDeleteParticipation(t *testing.T) {
}
target := iq.Target
target.Session, target.ClaimETag, target.ClaimGen = o.Claim.Holder.Session, o.ETag, o.Claim.Gen
- target.FenceID, target.Region, target.BootID, target.ControllerID, target.DirectoryRevision = "delete-stop", "ie", "boot", "controller", "1"
+ target.FenceID, target.Region, target.BootID, target.ControllerID, target.DirectoryRevision, target.RosterRevision = "delete-stop", "ie", "boot", "controller", "1", 1
if mode != "live" {
if target, err = root.Stop.Coordinator.Guard.BeginFence(t.Context(), target); err != nil {
t.Fatal(err)
}
if mode != "pending" {
at := time.Now().UTC()
- receipt := StopReceipt{V: 1, Kind: "stopped", ID: "delete-stop-receipt", FenceID: target.FenceID, Host: target.Host, Incarnation: target.Incarnation, InstallationStamp: target.Stamp, WriterSession: target.Session, Region: target.Region, ClaimETag: target.ClaimETag, ClaimGen: target.ClaimGen, Box: target.Box, Enrollment: target.Enrollment, BootID: target.BootID, ControllerID: target.ControllerID, DirectoryRevision: target.DirectoryRevision, EvidenceAt: at}
+ receipt := StopReceipt{V: 1, Kind: "stopped", ID: "delete-stop-receipt", FenceID: target.FenceID, Host: target.Host, Incarnation: target.Incarnation, InstallationStamp: target.Stamp, WriterSession: target.Session, Region: target.Region, ClaimETag: target.ClaimETag, ClaimGen: target.ClaimGen, Box: target.Box, Enrollment: target.Enrollment, BootID: target.BootID, ControllerID: target.ControllerID, DirectoryRevision: testReceiptNumeral(target), Binding: target.DirectoryRevision, EvidenceAt: at}
raw, _ := json.Marshal(receipt)
if err = root.Stop.Coordinator.Guard.CompleteFence(t.Context(), target, raw, at, func(ctx context.Context, t hostguard.FenceTarget, b []byte, at time.Time) error {
return verifyRetirementReceipt(ctx, hostguard.FenceReceipt{Target: t, Bytes: b, EvidenceAt: at})
diff --git a/internal/host/plan14_generation_parked_linux_test.go b/internal/host/plan14_generation_parked_linux_test.go
index ba159b096..5359f273a 100644
--- a/internal/host/plan14_generation_parked_linux_test.go
+++ b/internal/host/plan14_generation_parked_linux_test.go
@@ -43,8 +43,8 @@ func generationParkedFixture(t *testing.T, currentBoot ...bool) (generationInven
t.Fatal(err)
}
in.Entries = append(in.Entries, hostbox.StopInventoryEntry{Identity: inventoryIdentityFixture(t, root, "instances/"+host), Kind: "path", ArtifactID: "state", ManagedRoot: "data", RelativePath: "instances/" + host, Ownership: "owner", Materialization: "materialized", Device: uint64(st.Dev), Inode: st.Ino, Type: unix.S_IFDIR})
- target := hostguard.FenceTarget{Host: host, Incarnation: in.Incarnation, Stamp: 1, Session: 1, Box: in.Box, Enrollment: in.Enrollment, DirectoryRevision: in.DirectoryRevision, FenceID: "retire", BootID: in.Entries[len(in.Entries)-1].Identity.Boot, ControllerID: "controller", Op: "op", Phase: "retiring", ObligationID: "park"}
- receipt := StopReceipt{V: 1, ID: "receipt", Kind: "stopped", Host: host, Incarnation: target.Incarnation, InstallationStamp: target.Stamp, WriterSession: target.Session, Box: target.Box, Enrollment: target.Enrollment, DirectoryRevision: target.DirectoryRevision, FenceID: target.FenceID, BootID: target.BootID, ControllerID: target.ControllerID, OperationID: target.Op, Phase: target.Phase, ObligationID: target.ObligationID, EvidenceAt: time.Unix(100, 0).UTC()}
+ target := hostguard.FenceTarget{Host: host, Incarnation: in.Incarnation, Stamp: 1, Session: 1, Box: in.Box, Enrollment: in.Enrollment, DirectoryRevision: in.DirectoryRevision, RosterRevision: 1, FenceID: "retire", BootID: in.Entries[len(in.Entries)-1].Identity.Boot, ControllerID: "controller", Op: "op", Phase: "retiring", ObligationID: "park"}
+ receipt := StopReceipt{V: 1, ID: "receipt", Kind: "stopped", Host: host, Incarnation: target.Incarnation, InstallationStamp: target.Stamp, WriterSession: target.Session, Box: target.Box, Enrollment: target.Enrollment, DirectoryRevision: testReceiptNumeral(target), Binding: target.DirectoryRevision, FenceID: target.FenceID, BootID: target.BootID, ControllerID: target.ControllerID, OperationID: target.Op, Phase: target.Phase, ObligationID: target.ObligationID, EvidenceAt: time.Unix(100, 0).UTC()}
raw, err := json.Marshal(receipt)
if err != nil {
t.Fatal(err)
diff --git a/internal/host/plan9_d4_retire_linux_test.go b/internal/host/plan9_d4_retire_linux_test.go
index 64d2bfee3..0190feca7 100644
--- a/internal/host/plan9_d4_retire_linux_test.go
+++ b/internal/host/plan9_d4_retire_linux_test.go
@@ -346,7 +346,7 @@ func TestPlan9D4WriterStopIsTheLandingsOwnWriterOnly(t *testing.T) {
o := d.f.read()
h := o.Claim.Holder
return StopRequest{Region: "ie", Host: recoveryHost, Incarnation: h.Incarnation, InstallationStamp: h.Stamp, WriterSession: h.Session, OperationID: "m1", Phase: o.Claim.Op.Phase,
- ObligationID: hostguard.WriterStopObligation(h.Session), Box: "box-1", Enrollment: "enrollment-1", BootID: "boot-1", ControllerID: "controller-1", ExpectedClaimETag: o.ETag, ExpectedDirectoryRevision: "7"}
+ ObligationID: hostguard.WriterStopObligation(h.Session), Box: "box-1", Enrollment: "enrollment-1", BootID: "boot-1", ControllerID: "controller-1", ExpectedClaimETag: o.ETag, ExpectedDirectoryRevision: "7", RosterRevision: 7}
}
if _, err := d.f.root(recoveryStopDrain{}).FenceAndStop(ctx, request()); !errors.Is(err, ErrClaimStopIdentity) {
t.Fatalf("root stopped the source's session as box-1's writer: %v", err)
@@ -404,7 +404,7 @@ func TestPlan9D4RetirementRequiresTheWriterStopReceipt(t *testing.T) {
t.Fatal(err)
}
r := StopRequest{Region: "ie", Host: recoveryHost, Incarnation: h.Incarnation, InstallationStamp: h.Stamp, WriterSession: h.Session, OperationID: "m1", Phase: o.Claim.Op.Phase,
- ObligationID: "probe-chore", Box: "box-1", Enrollment: "enrollment-1", BootID: "boot-1", ControllerID: "controller-1", ExpectedClaimETag: o.ETag, ExpectedDirectoryRevision: "7"}
+ ObligationID: "probe-chore", Box: "box-1", Enrollment: "enrollment-1", BootID: "boot-1", ControllerID: "controller-1", ExpectedClaimETag: o.ETag, ExpectedDirectoryRevision: "7", RosterRevision: 7}
if _, err := d.f.root(drain).FenceAndStop(t.Context(), r); err != nil {
t.Fatal(err)
}
diff --git a/internal/host/plan9_journal_proof_test.go b/internal/host/plan9_journal_proof_test.go
index 40c40f222..c108b8e48 100644
--- a/internal/host/plan9_journal_proof_test.go
+++ b/internal/host/plan9_journal_proof_test.go
@@ -55,7 +55,7 @@ func TestPlan9LegacyJournalNeedsExactRootSignedStop(t *testing.T) {
t.Fatal("unproven legacy accepted")
}
target := in.Target
- receipt := StopReceipt{FenceID: "fence", ClaimGen: 1, ObservedBootID: "boot", DirectoryRevision: "1", CgroupIdentities: []string{"session"}, V: 1, ID: "stop1", Kind: "stopped", Host: target.Host, Incarnation: target.Incarnation, InstallationStamp: target.Stamp, WriterSession: target.Session, Box: target.Box, Enrollment: target.Enrollment, BootID: target.BootID, ControllerID: target.ControllerID, OperationID: target.Op, RequestLimitNS: int64(hostbox.RequestLimit), EvidenceAt: time.Now().UTC(), InventorySHA256: digestStop(inventory), LocalJournalSHA256: digestStop(journal)}
+ receipt := StopReceipt{FenceID: "fence", ClaimGen: 1, ObservedBootID: "boot", DirectoryRevision: "1", Binding: "1", CgroupIdentities: []string{"session"}, V: 1, ID: "stop1", Kind: "stopped", Host: target.Host, Incarnation: target.Incarnation, InstallationStamp: target.Stamp, WriterSession: target.Session, Box: target.Box, Enrollment: target.Enrollment, BootID: target.BootID, ControllerID: target.ControllerID, OperationID: target.Op, RequestLimitNS: int64(hostbox.RequestLimit), EvidenceAt: time.Now().UTC(), InventorySHA256: digestStop(inventory), LocalJournalSHA256: digestStop(journal)}
raw, _ = json.Marshal(receipt)
key := "control/hosts/app.example/evidence/operation/box/stop1.json"
if _, err = store.Put(t.Context(), key, raw, ""); err != nil {
diff --git a/internal/host/plan9fix1_journal_linux_test.go b/internal/host/plan9fix1_journal_linux_test.go
index 642ef8bbe..4e56c3275 100644
--- a/internal/host/plan9fix1_journal_linux_test.go
+++ b/internal/host/plan9fix1_journal_linux_test.go
@@ -199,7 +199,7 @@ func TestPlan9Fix1LegacyProofAcceptsServingEvidence(t *testing.T) {
}
inventory := hostbox.StopInventory{Complete: true, Host: in.Target.Host, Incarnation: "inc", InstallationStamp: 1, Box: "box", Enrollment: enrollment, DirectoryRevision: "1"}
target := in.Target
- receipt := StopReceipt{FenceID: "fence", ClaimGen: 1, ObservedBootID: "boot", DirectoryRevision: "1", CgroupIdentities: []string{"session"}, V: 1, ID: "stop1", Kind: "stopped", Host: target.Host, Incarnation: target.Incarnation, InstallationStamp: target.Stamp, WriterSession: target.Session, Box: target.Box, Enrollment: target.Enrollment, BootID: target.BootID, ControllerID: target.ControllerID, RequestLimitNS: int64(hostbox.RequestLimit), EvidenceAt: time.Now().UTC(), InventorySHA256: digestStop(inventory), LocalJournalSHA256: digestStop(journal)}
+ receipt := StopReceipt{FenceID: "fence", ClaimGen: 1, ObservedBootID: "boot", DirectoryRevision: "1", Binding: "1", CgroupIdentities: []string{"session"}, V: 1, ID: "stop1", Kind: "stopped", Host: target.Host, Incarnation: target.Incarnation, InstallationStamp: target.Stamp, WriterSession: target.Session, Box: target.Box, Enrollment: target.Enrollment, BootID: target.BootID, ControllerID: target.ControllerID, RequestLimitNS: int64(hostbox.RequestLimit), EvidenceAt: time.Now().UTC(), InventorySHA256: digestStop(inventory), LocalJournalSHA256: digestStop(journal)}
body, _ := json.Marshal(receipt)
key := stopEvidenceKey(target.Host, "", target.Box, receipt.ID)
if err = hostevidence.Publish(t.Context(), store, signer, key, body); err != nil {
diff --git a/internal/host/relocationdischarge_linux_test.go b/internal/host/relocationdischarge_linux_test.go
index 8708702e2..14ecd3175 100644
--- a/internal/host/relocationdischarge_linux_test.go
+++ b/internal/host/relocationdischarge_linux_test.go
@@ -40,7 +40,7 @@ func (b *participationBox) probeStopped() (hostclaim.Observed, hostguard.FenceTa
}
h := probing.Claim.Holder
target := hostguard.FenceTarget{FenceID: "fence-1", Region: "ie", Host: participationHost, Incarnation: h.Incarnation, Stamp: h.Stamp, Session: 12, Op: "rel-1", Phase: hostclaim.PhaseRelocatingProbing,
- ObligationID: hostguard.WriterStopObligation(12), Box: "dst", Enrollment: b.actor.Enrollment, BootID: "boot", ControllerID: "ctl", ClaimETag: probing.ETag, DirectoryRevision: "4"}
+ ObligationID: hostguard.WriterStopObligation(12), Box: "dst", Enrollment: b.actor.Enrollment, BootID: "boot", ControllerID: "ctl", ClaimETag: probing.ETag, DirectoryRevision: "4", RosterRevision: 4}
// The probe's launch is in the box's launch journal, as the wake
// journals it: main's ordinary cleanup would stop that session again.
if err := b.launches.Prelaunch(ctx, hostbox.LaunchInventory{ControllerPID: 4101, ProcessStart: "start-1", Target: target,
@@ -53,7 +53,7 @@ func (b *participationBox) probeStopped() (hostclaim.Observed, hostguard.FenceTa
at := time.Date(2026, 10, 7, 3, 1, 0, 0, time.UTC)
receipt := mustMarshalStopReceipt(StopReceipt{V: 1, ID: "r1", Kind: StopReceiptStopped, Region: "ie", ClaimETag: probing.ETag, ObligationID: target.ObligationID, FenceID: "fence-1", Host: participationHost,
Incarnation: h.Incarnation, InstallationStamp: h.Stamp, WriterSession: 12, OperationID: "rel-1", Phase: hostclaim.PhaseRelocatingProbing, Box: "dst", Enrollment: b.actor.Enrollment,
- BootID: "boot", ControllerID: "ctl", DirectoryRevision: "4", EvidenceAt: at})
+ BootID: "boot", ControllerID: "ctl", DirectoryRevision: testReceiptNumeral(target), Binding: "4", EvidenceAt: at})
if err := b.guard.CompleteFence(ctx, target, receipt, at, func(context.Context, hostguard.FenceTarget, []byte, time.Time) error { return nil }); err != nil {
b.t.Fatal(err)
}
diff --git a/internal/host/relocationdischarge_restart_unix_test.go b/internal/host/relocationdischarge_restart_unix_test.go
index 96c2d62e6..07bb8a69a 100644
--- a/internal/host/relocationdischarge_restart_unix_test.go
+++ b/internal/host/relocationdischarge_restart_unix_test.go
@@ -92,13 +92,13 @@ func TestRelocationRestartDischargeSurvivesAFailedClaimRead(t *testing.T) {
// The probe's writer-session stop, completed with root's receipt
// (ruling 49), while the op was still relocating/probing.
prior := hostguard.FenceTarget{FenceID: "fence-1", Region: "ie", Host: host, Incarnation: inc, Stamp: 9, Session: 12, Op: "rel-1", Phase: hostclaim.PhaseRelocatingProbing,
- ObligationID: hostguard.WriterStopObligation(12), Box: box, Enrollment: "enr", BootID: "boot", ControllerID: "ctl", ClaimETag: "e1", DirectoryRevision: "1"}
+ ObligationID: hostguard.WriterStopObligation(12), Box: box, Enrollment: "enr", BootID: "boot", ControllerID: "ctl", ClaimETag: "e1", DirectoryRevision: "1", RosterRevision: 1}
if _, err := guard.BeginFence(ctx, prior); err != nil {
t.Fatal(err)
}
at := time.Date(2026, 10, 11, 9, 0, 0, 0, time.UTC)
receipt := mustMarshalStopReceipt(StopReceipt{V: 1, ID: "r1", Kind: StopReceiptStopped, Region: "ie", ClaimETag: "e1", ObligationID: prior.ObligationID, FenceID: "fence-1", Host: host, Incarnation: inc,
- InstallationStamp: 9, WriterSession: 12, OperationID: "rel-1", Phase: hostclaim.PhaseRelocatingProbing, Box: box, Enrollment: "enr", BootID: "boot", ControllerID: "ctl", DirectoryRevision: "1", EvidenceAt: at})
+ InstallationStamp: 9, WriterSession: 12, OperationID: "rel-1", Phase: hostclaim.PhaseRelocatingProbing, Box: box, Enrollment: "enr", BootID: "boot", ControllerID: "ctl", DirectoryRevision: testReceiptNumeral(prior), Binding: "1", EvidenceAt: at})
if err := guard.CompleteFence(ctx, prior, receipt, at, func(context.Context, hostguard.FenceTarget, []byte, time.Time) error { return nil }); err != nil {
t.Fatal(err)
}
diff --git a/internal/host/relocationeffects.go b/internal/host/relocationeffects.go
index 303f4cea0..7850849fc 100644
--- a/internal/host/relocationeffects.go
+++ b/internal/host/relocationeffects.go
@@ -272,7 +272,7 @@ func releaseStopRequest(obs hostclaim.Observed, id RelocationIdentity) StopReque
c, h := obs.Claim, obs.Claim.Holder
return StopRequest{Region: id.Actor.Region, Host: c.Host, Incarnation: h.Incarnation, InstallationStamp: h.Stamp, WriterSession: h.Session,
OperationID: c.Op.ID, Phase: c.Op.Phase, ObligationID: RelocationReleaseObligation, Box: id.Actor.Box, Enrollment: id.Actor.Enrollment,
- BootID: id.BootID, ControllerID: id.ControllerID, ExpectedClaimETag: obs.ETag, ExpectedDirectoryRevision: id.Actor.Binding}
+ BootID: id.BootID, ControllerID: id.ControllerID, ExpectedClaimETag: obs.ETag, ExpectedDirectoryRevision: id.Actor.Binding, RosterRevision: id.Actor.Revision}
}
// replayDischarged returns the release whose receipt already discharged
diff --git a/internal/host/relocationfirstwake_unix_test.go b/internal/host/relocationfirstwake_unix_test.go
index d8ac69136..f16bc93ff 100644
--- a/internal/host/relocationfirstwake_unix_test.go
+++ b/internal/host/relocationfirstwake_unix_test.go
@@ -68,10 +68,10 @@ func TestCompletionPassThenFirstServingWakeWithRegionHAOff(t *testing.T) {
// 1. The probe stop, root's writer-session stop standing as Wake.Stop.
h := o.Claim.Holder
target := hostguard.FenceTarget{FenceID: "fence-1", Region: "ie", Host: recoveryHost, Incarnation: h.Incarnation, Stamp: 9, Session: 12, Op: op, Phase: hostclaim.PhaseRelocatingProbing,
- ObligationID: hostguard.WriterStopObligation(12), Box: box, Enrollment: local.Actor.Enrollment, BootID: local.BootID, ControllerID: local.ControllerID, ClaimETag: o.ETag, DirectoryRevision: "7"}
+ ObligationID: hostguard.WriterStopObligation(12), Box: box, Enrollment: local.Actor.Enrollment, BootID: local.BootID, ControllerID: local.ControllerID, ClaimETag: o.ETag, DirectoryRevision: "7", RosterRevision: 7}
at := f.now.Add(time.Minute)
receipt := mustMarshalStopReceipt(StopReceipt{V: 1, ID: "r1", Kind: StopReceiptStopped, Region: "ie", ClaimETag: o.ETag, ObligationID: target.ObligationID, FenceID: "fence-1", Host: recoveryHost, Incarnation: h.Incarnation,
- InstallationStamp: 9, WriterSession: 12, OperationID: op, Phase: hostclaim.PhaseRelocatingProbing, Box: box, Enrollment: local.Actor.Enrollment, BootID: local.BootID, ControllerID: local.ControllerID, DirectoryRevision: "7", EvidenceAt: at})
+ InstallationStamp: 9, WriterSession: 12, OperationID: op, Phase: hostclaim.PhaseRelocatingProbing, Box: box, Enrollment: local.Actor.Enrollment, BootID: local.BootID, ControllerID: local.ControllerID, DirectoryRevision: testReceiptNumeral(target), Binding: "7", EvidenceAt: at})
var order []string
act := newStopProbeActivator(&order)
probeAssembly := ClaimAssembly{Claims: f.claims, Guard: f.guard, stopLocal: func(context.Context) (claimStopLocal, error) { return local, nil },
diff --git a/internal/host/relocationstopprobe_unix_test.go b/internal/host/relocationstopprobe_unix_test.go
index 69ab5d864..866d4169b 100644
--- a/internal/host/relocationstopprobe_unix_test.go
+++ b/internal/host/relocationstopprobe_unix_test.go
@@ -106,10 +106,10 @@ func newStopProbeFixture(t *testing.T) *stopProbeFixture {
t.Fatal(err)
}
f.target = hostguard.FenceTarget{FenceID: "fence-1", Region: "ie", Host: host, Incarnation: inc, Stamp: 9, Session: 12, Op: "rel-1", Phase: hostclaim.PhaseRelocatingProbing,
- ObligationID: hostguard.WriterStopObligation(12), Box: box, Enrollment: "enr", BootID: "boot", ControllerID: "ctl", ClaimETag: "e1", DirectoryRevision: "1"}
+ ObligationID: hostguard.WriterStopObligation(12), Box: box, Enrollment: "enr", BootID: "boot", ControllerID: "ctl", ClaimETag: "e1", DirectoryRevision: "1", RosterRevision: 1}
at := created.Add(2 * time.Hour)
f.receipt = mustMarshalStopReceipt(StopReceipt{V: 1, ID: "r1", Kind: StopReceiptStopped, Region: "ie", ClaimETag: "e1", ObligationID: f.target.ObligationID, FenceID: "fence-1", Host: host, Incarnation: inc,
- InstallationStamp: 9, WriterSession: 12, OperationID: "rel-1", Phase: hostclaim.PhaseRelocatingProbing, Box: box, Enrollment: "enr", BootID: "boot", ControllerID: "ctl", DirectoryRevision: "1", EvidenceAt: at})
+ InstallationStamp: 9, WriterSession: 12, OperationID: "rel-1", Phase: hostclaim.PhaseRelocatingProbing, Box: box, Enrollment: "enr", BootID: "boot", ControllerID: "ctl", DirectoryRevision: testReceiptNumeral(f.target), Binding: "1", EvidenceAt: at})
wake := &ClaimWakeAssembly{Stop: func(ctx context.Context, o hostclaim.Observed) error {
f.order = append(f.order, "wake-stop")
// Root's writer-session stop: deterministic, so a repeat meets the
@@ -351,13 +351,13 @@ func TestRelocationStopProbeRefusesTwoCompletedStopsOfTheSession(t *testing.T) {
// roster revision, which main's fence target carries, so the guard
// journals it beside the first rather than meeting it again.
second := f.target
- second.FenceID, second.DirectoryRevision = "fence-2", "2"
+ second.FenceID, second.DirectoryRevision, second.RosterRevision = "fence-2", "2", 2
if _, err := f.a.Guard.BeginFence(ctx, second); err != nil {
t.Fatal(err)
}
at := time.Date(2026, 10, 7, 4, 0, 0, 0, time.UTC)
receipt := mustMarshalStopReceipt(StopReceipt{V: 1, ID: "r2", Kind: StopReceiptStopped, Region: "ie", ClaimETag: "e1", ObligationID: second.ObligationID, FenceID: "fence-2", Host: f.obs.Host, Incarnation: second.Incarnation,
- InstallationStamp: 9, WriterSession: 12, OperationID: "rel-1", Phase: hostclaim.PhaseRelocatingProbing, Box: "dst", Enrollment: "enr", BootID: "boot", ControllerID: "ctl", DirectoryRevision: "2", EvidenceAt: at})
+ InstallationStamp: 9, WriterSession: 12, OperationID: "rel-1", Phase: hostclaim.PhaseRelocatingProbing, Box: "dst", Enrollment: "enr", BootID: "boot", ControllerID: "ctl", DirectoryRevision: testReceiptNumeral(second), Binding: "2", EvidenceAt: at})
if err := f.a.Guard.CompleteFence(ctx, second, receipt, at, func(context.Context, hostguard.FenceTarget, []byte, time.Time) error { return nil }); err != nil {
t.Fatal(err)
}
diff --git a/internal/host/rootgeneration_retired_linux_test.go b/internal/host/rootgeneration_retired_linux_test.go
index 88ad9f797..5b6d5e984 100644
--- a/internal/host/rootgeneration_retired_linux_test.go
+++ b/internal/host/rootgeneration_retired_linux_test.go
@@ -18,9 +18,9 @@ import (
func TestPlan14RetiredGenerationBoundary(t *testing.T) {
for _, mode := range []string{"retired", "active sibling", "live installation", "pending pin", "open pin", "named", "legacy process", "open writers", "pending unit", "foreign receipt", "bad receipt", "barrier", "missing installation", "missing launches", "missing reservation"} {
t.Run(mode, func(t *testing.T) {
- target := hostguard.FenceTarget{Host: "shop.example", Incarnation: "inc", Stamp: 3, Session: 4, Box: "box", Enrollment: "en", BootID: "boot", ControllerID: "controller", FenceID: "fence", Op: "delete", ObligationID: "park"}
+ target := hostguard.FenceTarget{Host: "shop.example", Incarnation: "inc", Stamp: 3, Session: 4, Box: "box", Enrollment: "en", BootID: "boot", ControllerID: "controller", FenceID: "fence", Op: "delete", ObligationID: "park", RosterRevision: 1}
at := time.Now().UTC()
- s := StopReceipt{Kind: "stopped", Host: target.Host, Incarnation: target.Incarnation, InstallationStamp: target.Stamp, WriterSession: target.Session, Box: target.Box, Enrollment: target.Enrollment, BootID: target.BootID, ControllerID: target.ControllerID, FenceID: target.FenceID, OperationID: target.Op, ObligationID: target.ObligationID, EvidenceAt: at}
+ s := StopReceipt{Kind: "stopped", DirectoryRevision: testReceiptNumeral(target), Host: target.Host, Incarnation: target.Incarnation, InstallationStamp: target.Stamp, WriterSession: target.Session, Box: target.Box, Enrollment: target.Enrollment, BootID: target.BootID, ControllerID: target.ControllerID, FenceID: target.FenceID, OperationID: target.Op, ObligationID: target.ObligationID, EvidenceAt: at}
view := hostguard.FenceView{Host: target.Host, Installation: hostguard.RootInstallation{Host: target.Host, Incarnation: target.Incarnation, Stamp: target.Stamp}, Retired: []hostguard.Captured{{Incarnation: target.Incarnation, Stamp: target.Stamp}}, Receipts: []hostguard.FenceReceipt{{Target: target, Bytes: mustMarshalStopReceipt(s), EvidenceAt: at}}}
inv := generationInventory{Installations: []hostguard.FenceView{view}, Launches: []hostbox.LaunchInventory{{Target: target, WritersClosed: true, Reservations: []hostbox.LaunchReservation{{Target: target, State: hostbox.UnitSettled, Group: hostbox.LaunchGroup{RelativePath: instancectl.ClaimUnitControlGroup(target.Host)}}}}}}
records := []release.GenerationReservation{{Binding: release.GenerationBinding{Target: generationOwner(target)}, Closed: true, Retirement: strings.Repeat("a", 64)}}
diff --git a/internal/host/rootmigration_evidence.go b/internal/host/rootmigration_evidence.go
index b27243cc6..3ba5c12e2 100644
--- a/internal/host/rootmigration_evidence.go
+++ b/internal/host/rootmigration_evidence.go
@@ -37,7 +37,7 @@ func readMigrationStop(ctx context.Context, store release.Store, directory hosta
if err != nil {
return StopResult{}, err
}
- wanted := StopReceipt{Host: target.Host, Incarnation: target.Incarnation, InstallationStamp: target.Stamp, WriterSession: target.Session, Box: target.Box, Enrollment: target.Enrollment, BootID: target.BootID, ControllerID: target.ControllerID, OperationID: target.Op, Region: target.Region, DirectoryRevision: in.DirectoryRevision, InventorySHA256: digestStop(in), LocalJournalSHA256: digestStop(journal)}
+ wanted := StopReceipt{Host: target.Host, Incarnation: target.Incarnation, InstallationStamp: target.Stamp, WriterSession: target.Session, Box: target.Box, Enrollment: target.Enrollment, BootID: target.BootID, ControllerID: target.ControllerID, OperationID: target.Op, Region: target.Region, Binding: in.DirectoryRevision, InventorySHA256: digestStop(in), LocalJournalSHA256: digestStop(journal)}
for _, key := range keys {
if !strings.HasPrefix(key, prefix) || !strings.HasSuffix(key, ".json") {
continue
@@ -57,7 +57,11 @@ func readMigrationStop(ctx context.Context, store release.Store, directory hosta
if json.Unmarshal(raw, &p) != nil || p.V != 1 || p.Kind != "stopped" || p.ID == "" || p.FenceID == "" || p.ClaimGen == 0 || p.ObservedBootID == "" || p.EvidenceAt.IsZero() || len(p.CgroupIdentities) == 0 || p.RequestLimitNS != int64(hostbox.RequestLimit) || key != prefix+p.ID+".json" || legacyJournalProofMatch(p) != legacyJournalProofMatch(wanted) || p.Phase != target.Phase || p.ObligationID != target.ObligationID {
continue
}
- target.FenceID, target.ClaimGen, target.ClaimETag = p.FenceID, p.ClaimGen, p.ClaimETag
+ numeral, ok := receiptRosterRevision(p.DirectoryRevision)
+ if !ok {
+ continue
+ }
+ target.FenceID, target.ClaimGen, target.ClaimETag, target.RosterRevision = p.FenceID, p.ClaimGen, p.ClaimETag, numeral
return StopResult{Target: target, Key: key, Digest: digestRawStop(raw), Bytes: raw, EvidenceAt: p.EvidenceAt}, nil
}
return StopResult{}, hostbox.ErrLegacyJournalProof
diff --git a/internal/host/rootmigration_historic_linux_test.go b/internal/host/rootmigration_historic_linux_test.go
index 58a1b84c9..6a1ab11d3 100644
--- a/internal/host/rootmigration_historic_linux_test.go
+++ b/internal/host/rootmigration_historic_linux_test.go
@@ -88,7 +88,7 @@ func migrationHistoricFixture(t *testing.T, store release.Store, r ClaimRuntimeR
if err := inventory.Close(); err != nil {
t.Fatal(err)
}
- receipt := StopReceipt{V: 1, ID: "historic-stop", Kind: "stopped", Host: target.Host, Incarnation: inc, InstallationStamp: 1, WriterSession: 9, Box: actor.Box, Enrollment: actor.Enrollment, Region: "ie", BootID: target.BootID, ObservedBootID: target.BootID, ControllerID: target.ControllerID, DirectoryRevision: "1", ClaimGen: 1, ClaimETag: ctag, FenceID: target.FenceID, EvidenceAt: at, RequestLimitNS: int64(hostbox.RequestLimit), InventorySHA256: digestStop(in), LocalJournalSHA256: digestStop(journal), CgroupIdentities: []string{"historic-session"}}
+ receipt := StopReceipt{V: 1, ID: "historic-stop", Kind: "stopped", Host: target.Host, Incarnation: inc, InstallationStamp: 1, WriterSession: 9, Box: actor.Box, Enrollment: actor.Enrollment, Region: "ie", BootID: target.BootID, ObservedBootID: target.BootID, ControllerID: target.ControllerID, DirectoryRevision: "1", Binding: "1", ClaimGen: 1, ClaimETag: ctag, FenceID: target.FenceID, EvidenceAt: at, RequestLimitNS: int64(hostbox.RequestLimit), InventorySHA256: digestStop(in), LocalJournalSHA256: digestStop(journal), CgroupIdentities: []string{"historic-session"}}
raw, _ = json.Marshal(receipt)
if err := hostevidence.Publish(ctx, store, owners.EvidenceKey, stopEvidenceKey(target.Host, "", actor.Box, receipt.ID), raw); err != nil {
t.Fatal(err)
diff --git a/internal/hostguard/fence.go b/internal/hostguard/fence.go
index 29ec84e76..8b00f6c15 100644
--- a/internal/hostguard/fence.go
+++ b/internal/hostguard/fence.go
@@ -35,6 +35,13 @@ type FenceTarget struct {
ControllerID string `json:"controller_id"`
ClaimETag string `json:"claim_etag"`
DirectoryRevision string `json:"directory_revision"`
+ // RosterRevision is the roster write counter the stop's requester read,
+ // persisted with the fence before any stop effect. It is the one source of
+ // a stop receipt's directory_revision numeral (roster binding N1); the
+ // installation's binding is DirectoryRevision. It is receipt data only:
+ // retry authority ignores it (sameAuthority) and the journal v1 tuple
+ // never hashes it.
+ RosterRevision uint64 `json:"roster_revision,omitempty"`
}
func (t FenceTarget) validate(host string) error {
@@ -51,6 +58,10 @@ func (t FenceTarget) sameAuthority(other FenceTarget) bool {
// A bookkeeping CAS must not replace the persisted fence or its evidence.
t.ClaimETag, other.ClaimETag = "", ""
t.ClaimGen, other.ClaimGen = 0, 0
+ // The receipt numeral is the roster write counter at the request, which
+ // unrelated roster writes move between retries of one stop. The persisted
+ // target keeps the original numeral; a retry never replaces it (B2).
+ t.RosterRevision, other.RosterRevision = 0, 0
return t == other
}
diff --git a/internal/hostguard/fence_test.go b/internal/hostguard/fence_test.go
index 5c032912e..edd57fe55 100644
--- a/internal/hostguard/fence_test.go
+++ b/internal/hostguard/fence_test.go
@@ -194,6 +194,7 @@ func hostguardCaptured(target FenceTarget) Captured {
func TestBeginFenceResumesAfterUnrelatedClaimCAS(t *testing.T) {
f, target, _ := fenceFixture(t)
+ target.RosterRevision = 9
if _, err := f.g.BeginFence(t.Context(), target); err != nil {
t.Fatal(err)
}
@@ -204,10 +205,24 @@ func TestBeginFenceResumesAfterUnrelatedClaimCAS(t *testing.T) {
fresh := target
fresh.ClaimETag = f.obs.ETag
fresh.FenceID = "retry"
+ // Roster binding B2: unrelated roster writes between the request and its
+ // retry move the receipt numeral but not the binding. Retry authority
+ // ignores the numeral, and both lookups return the persisted target with
+ // its ORIGINAL numeral.
+ fresh.RosterRevision = target.RosterRevision + 4
got, err := f.g.BeginFence(t.Context(), fresh)
- if err != nil || got != target {
+ if err != nil || got != target || got.RosterRevision != 9 {
t.Fatalf("resume=%+v %v", got, err)
}
+ existing, err := f.g.ExistingFence(t.Context(), fresh)
+ if err != nil || existing != target || existing.RosterRevision != 9 {
+ t.Fatalf("existing=%+v %v", existing, err)
+ }
+ // Exact stored-target comparisons stay exact: the retry's numeral names no
+ // persisted fence.
+ if err := f.g.ResumeFence(t.Context(), fresh); !errors.Is(err, ErrFenceTarget) {
+ t.Fatalf("resume with a changed numeral: %v", err)
+ }
at := time.Unix(1, 0).UTC()
if err := f.g.CompleteFence(t.Context(), got, []byte("original receipt"), at, func(context.Context, FenceTarget, []byte, time.Time) error { return nil }); err != nil {
t.Fatal(err)
@@ -216,15 +231,23 @@ func TestBeginFenceResumesAfterUnrelatedClaimCAS(t *testing.T) {
if err != nil || string(receipt.Bytes) != "original receipt" || receipt.Target != target {
t.Fatalf("receipt=%+v %v", receipt, err)
}
- for _, change := range []func(*FenceTarget){func(v *FenceTarget) { v.Session++ }, func(v *FenceTarget) { v.Op = "another" }, func(v *FenceTarget) { v.ControllerID = "another" }} {
+ if _, err := f.g.FenceReceiptFor(t.Context(), fresh); !errors.Is(err, ErrNoFenceReceipt) {
+ t.Fatalf("receipt for a changed numeral: %v", err)
+ }
+ for _, change := range []func(*FenceTarget){func(v *FenceTarget) { v.Session++ }, func(v *FenceTarget) { v.Op = "another" }, func(v *FenceTarget) { v.ControllerID = "another" }, func(v *FenceTarget) { v.DirectoryRevision = "another-binding" }} {
g, old, _ := fenceFixture(t)
+ old.RosterRevision = 9
if _, err := g.g.BeginFence(t.Context(), old); err != nil {
t.Fatal(err)
}
fresh := old
change(&fresh)
+ fresh.RosterRevision++
if _, err := g.g.BeginFence(t.Context(), fresh); err == nil {
t.Fatal("changed authority resumed")
}
+ if _, err := g.g.ExistingFence(t.Context(), fresh); !errors.Is(err, ErrFenceTarget) {
+ t.Fatalf("changed authority found: %v", err)
+ }
}
}