carlos / platform Public

release: pointer identity is the exact signed object; fences stamp later

Astra round 2 (P2-3, P1-1 partly): a pointer's identity is the sha256 of
the wrapper it was verified from, set at the parse sites, so two signed
payloads that decode alike are two pointers. A cancellation fence takes
its publication's After stamp, strictly after the pointer it restores,
and is derived deterministically so retries write the same bytes. An app
floor with no identity admits nothing at its own stamp.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev e58b0d6ab8432f4a7b298abfef251f9e9246b062 parent 4bb2d6f
6 files changed, +249 −37
  • internal/release/golden_test.go +2 −0
  • internal/release/hunt_rc_r2_test.go +157 −0
  • internal/release/release.go +6 −0
  • internal/release/systempointer.go +16 −13
  • internal/release/systempublication.go +39 −13
  • internal/release/watermark.go +29 −11
diff --git a/internal/release/golden_test.go b/internal/release/golden_test.go
index 8b41ffcc8..639b92954 100644
--- a/internal/release/golden_test.go
+++ b/internal/release/golden_test.go
@@ -72,6 +72,8 @@ func TestGoldenRootSignedWrapperStillVerifies(t *testing.T) {
Actor: "owner@example.test",
At: time.Date(2026, 7, 30, 11, 4, 17, 0, time.UTC),
}},
+ // Its identity is the exact wrapper it was read from.
+ identity: signedIdentity([]byte(goldenRootSignedWrapper)),
}
if !reflect.DeepEqual(p, want) {
t.Fatalf("golden pointer decoded as\n%+v\nwant\n%+v", p, want)
diff --git a/internal/release/hunt_rc_r2_test.go b/internal/release/hunt_rc_r2_test.go
new file mode 100644
index 000000000..ddf3d9a6f
--- /dev/null
+++ b/internal/release/hunt_rc_r2_test.go
@@ -0,0 +1,157 @@
+package release
+
+import (
+ "bytes"
+ "context"
+ "encoding/json"
+ "errors"
+ "os"
+ "path/filepath"
+ "testing"
+ "time"
+)
+
+// Fix round 2 of the release chain (Astra round 2). The floors admit, at
+// their own stamp, only the exact pointer they recorded.
+
+// P2-3: a pointer's identity is the exact signed object it was read from.
+// Two signed payloads that decode to the same struct (one carries a signed
+// field this build does not know) are two pointers, not one; re-marshalling
+// the decoded struct named them the same.
+func TestPointerIdentityIsTheExactSignedObject(t *testing.T) {
+ priv, pub := testKeys(t)
+ sg := RootSigner(priv)
+ at := time.Date(2026, 11, 1, 9, 0, 0, 0, time.UTC)
+ base := map[string]any{"schema": 1, "account": "bab", "app": "km", "channel": "stable", "version": "v2", "promoted_at": at}
+ sign := func(extra map[string]any) []byte {
+ t.Helper()
+ m := map[string]any{}
+ for k, v := range base {
+ m[k] = v
+ }
+ for k, v := range extra {
+ m[k] = v
+ }
+ payload, err := json.Marshal(m)
+ if err != nil {
+ t.Fatal(err)
+ }
+ wire, err := signRootPayload(sg, payload)
+ if err != nil {
+ t.Fatal(err)
+ }
+ return wire
+ }
+ plain, extra := sign(nil), sign(map[string]any{"note": "a signed field this build ignores"})
+ a, err := verifyPointer(pub, plain, "bab", "km", "stable")
+ if err != nil {
+ t.Fatal(err)
+ }
+ again, err := verifyPointer(pub, plain, "bab", "km", "stable")
+ if err != nil {
+ t.Fatal(err)
+ }
+ b, err := verifyPointer(pub, extra, "bab", "km", "stable")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if PointerIdentity(a) != PointerIdentity(again) {
+ t.Fatal("two reads of one signed pointer have different identities")
+ }
+ if PointerIdentity(a) == PointerIdentity(b) {
+ t.Fatal("two different signed pointers share an identity")
+ }
+ // The floor holds that line: with a recorded, the other is a replay.
+ r := NewDigestRatchet(t.TempDir(), nil, false)
+ if err := r.Admit("bab", a); err != nil {
+ t.Fatal(err)
+ }
+ if err := NewDigestRatchet(r.own, nil, false).Admit("bab", b); !errors.Is(err, ErrPointerReplayed) {
+ t.Fatalf("the other signed pointer at the floor's stamp: %v, want ErrPointerReplayed", err)
+ }
+ if err := NewDigestRatchet(r.own, nil, false).Admit("bab", again); err != nil {
+ t.Fatalf("the recorded pointer read again: %v", err)
+ }
+}
+
+// P1-1 (partly): a floor on disk with no identity at its stamp admits
+// nothing there. It cannot tell the pointer it followed from a saved one
+// signed in the same second, so only a strictly later stamp is news.
+func TestWatermarkWithNoIdentityAdmitsNothingAtItsStamp(t *testing.T) {
+ s := NewDirStore(t.TempDir())
+ ctx := context.Background()
+ priv, pub := testKeys(t)
+ shipRelease(t, s, "bab", "shop", "v1", adoptPlatform, []byte("v1"))
+ if err := Promote(ctx, s, priv, "bab", "shop", "stable", "v1"); err != nil {
+ t.Fatal(err)
+ }
+ p, err := Channel(ctx, s, pub, "bab", "shop", "stable")
+ if err != nil {
+ t.Fatal(err)
+ }
+ dir := t.TempDir()
+ path := watermarkPath(dir, "bab", "shop", "stable")
+ if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ body, _ := json.Marshal(map[string]any{"promoted_at": p.PromotedAt, "version": p.Version})
+ if err := os.WriteFile(path, body, 0o644); err != nil {
+ t.Fatal(err)
+ }
+ if err := NewDigestRatchet(dir, nil, false).Admit("bab", p); !errors.Is(err, ErrPointerReplayed) {
+ t.Fatalf("a pointer at an identity-less floor's stamp: %v, want ErrPointerReplayed", err)
+ }
+}
+
+// P2-3: a cancellation fence is a new head with a stamp strictly after the
+// pointer it restores, so a box that followed that pointer admits the fence
+// as news and nothing at the old stamp but the old pointer itself. Every
+// retry of the cancellation writes exactly the same bytes.
+func TestCancelSystemPublicationFenceIsStampedAfterWhatItRestores(t *testing.T) {
+ ctx := context.Background()
+ priv, pub := testKeys(t)
+ sg := RootSigner(priv)
+ s := NewDirStore(t.TempDir())
+ rel := func(v string) SystemRelease {
+ return SystemRelease{Version: v, Artifacts: map[string]SystemArtifact{
+ "linux-arm64": {Key: SystemArtifactKey(v, "linux-arm64"), SHA256: "aa" + string(bytes.Repeat([]byte("0"), 62))}}}
+ }
+ if _, err := PromoteSystem(ctx, s, sg, SystemComponentRouter, "stable", rel("v1"), SystemPromoteOptions{}); err != nil {
+ t.Fatal(err)
+ }
+ before, _, err := GetSystemPointer(ctx, s, pub, SystemComponentRouter, "stable")
+ if err != nil {
+ t.Fatal(err)
+ }
+ pub2, err := PrepareSystemPromotion(ctx, s, sg, SystemComponentRouter, "stable", rel("v2"), SystemPromoteOptions{}, "act-1")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := CancelSystemPublication(ctx, s, sg, pub2); err != nil {
+ t.Fatal(err)
+ }
+ key := SystemPointerKey(SystemComponentRouter, "stable")
+ first, _, err := s.Get(ctx, key)
+ if err != nil {
+ t.Fatal(err)
+ }
+ fence, _, err := GetSystemPointer(ctx, s, pub, SystemComponentRouter, "stable")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if fence.CancellationID != "act-1" || fence.Current.Version != "v1" {
+ t.Fatalf("fence = %+v", fence)
+ }
+ if !fence.PromotedAt.After(before.PromotedAt) {
+ t.Fatalf("fence stamped %s, not after the pointer it restores (%s)", fence.PromotedAt, before.PromotedAt)
+ }
+ if SystemPointerIdentity(fence) == SystemPointerIdentity(before) {
+ t.Fatal("the fence and the pointer it restores share an identity")
+ }
+ if err := CancelSystemPublication(ctx, s, sg, pub2); err != nil {
+ t.Fatalf("retry of the cancellation: %v", err)
+ }
+ if again, _, _ := s.Get(ctx, key); !bytes.Equal(again, first) {
+ t.Fatal("a retry of the cancellation wrote different bytes")
+ }
+}
diff --git a/internal/release/release.go b/internal/release/release.go
index 6c2749f0f..41d386894 100644
--- a/internal/release/release.go
+++ b/internal/release/release.go
@@ -250,6 +250,11 @@ type ChannelPointer struct {
// starts clean. ADDITIVE: old pointers have no key; old binaries drop the
// field and keep baking, the safe direction.
FastTrack bool `json:"fast_track,omitempty"`
+
+ // identity is the sha256 of the exact signed wrapper this pointer was
+ // verified from (signedIdentity), set by the one parse site and nowhere
+ // else: PointerIdentity. A pointer built in memory has none.
+ identity string
}
// Promotion is one entry in a channel pointer's audit trail. It rides inside
@@ -677,6 +682,7 @@ func verifyPointerBinding(pub ed25519.PublicKey, wrapper []byte, wantAcct, wantA
return nil, fmt.Errorf("channel pointer %s/%s: %w", p.App, p.Channel, err)
}
}
+ p.identity = signedIdentity(wrapper)
return &p, nil
}
diff --git a/internal/release/systempointer.go b/internal/release/systempointer.go
index 086b30a47..c3b5ab8f9 100644
--- a/internal/release/systempointer.go
+++ b/internal/release/systempointer.go
@@ -3,9 +3,7 @@ package release
import (
"context"
"crypto/ed25519"
- "crypto/sha256"
"encoding/base64"
- "encoding/hex"
"encoding/json"
"errors"
"fmt"
@@ -56,6 +54,11 @@ type SystemPointer struct {
// later write. omitempty keeps a pointer without it byte-identical to
// one written before the field existed.
AllowBelowFleetForwardFloor bool `json:"allow_below_fleet_forward_floor,omitempty"`
+
+ // identity is the sha256 of the exact signed wrapper this pointer was
+ // verified from, set by parseSystemPointer and nowhere else:
+ // SystemPointerIdentity. A pointer built in memory has none.
+ identity string
}
// SystemRelease is everything a box needs to install one version. It travels
@@ -252,6 +255,7 @@ func parseSystemPointer(pub ed25519.PublicKey, wrapper []byte, wantComponent, wa
if err := validateSystemPointer(&p, wantComponent, wantChannel); err != nil {
return nil, err
}
+ p.identity = signedIdentity(wrapper)
return &p, nil
}
@@ -412,16 +416,15 @@ func PrepareSystemRollback(ctx context.Context, s Store, sg Signer, component, c
return SystemPublication{Component: component, Channel: channel, ID: id, ExpectedETag: etag, Before: body, After: wrapper}, nil
}
-// SystemPointerIdentity names one signed system pointer by its content: the
-// sha256 of the verified payload re-marshalled, the cancellation mark left
-// out. Two reads of the same signed pointer have the same identity, and so
-// does a cancellation fence (CancelSystemPublication), which re-signs the
-// pointer it fences with every field and its stamp kept: the box has
-// already followed exactly that release. Two different pointers do not.
+// SystemPointerIdentity names one signed system pointer by its exact signed
+// representation, as PointerIdentity does a channel pointer: the sha256 of
+// the wrapper bytes it was verified from, every signed field included, the
+// cancellation mark among them. A cancellation fence is its own pointer,
+// with its own later stamp (CancelSystemPublication). A pointer built in
+// memory is named by its content, marked unsigned (unsignedIdentity).
func SystemPointerIdentity(p *SystemPointer) string {
- q := *p
- q.CancellationID = ""
- raw, _ := json.Marshal(&q)
- sum := sha256.Sum256(raw)
- return hex.EncodeToString(sum[:])
+ if p.identity != "" {
+ return p.identity
+ }
+ return unsignedIdentity(p)
}
diff --git a/internal/release/systempublication.go b/internal/release/systempublication.go
index 82d816365..d09480417 100644
--- a/internal/release/systempublication.go
+++ b/internal/release/systempublication.go
@@ -50,23 +50,13 @@ func PublishSystemPublication(ctx context.Context, s Store, pub ed25519.PublicKe
// CancelSystemPublication competes with publication on its original pointer
// ETag. The fence must be durable before the actor reservation is removed.
+// The fence is derived from the publication alone (systemFence), so every
+// retry writes exactly the same bytes.
func CancelSystemPublication(ctx context.Context, s Store, sg Signer, p SystemPublication) error {
if p.ID == "" {
return ErrBadSystemPointer
}
- if _, err := p.Verify(sg.verifyPub()); err != nil {
- return err
- }
- before := &SystemPointer{Schema: 1, Component: p.Component, Channel: p.Channel}
- if len(p.Before) != 0 {
- var err error
- before, err = verifySystemPointer(sg.verifyPub(), p.Before, p.Component, p.Channel)
- if err != nil {
- return err
- }
- }
- before.CancellationID = p.ID
- fence, err := SignRootEnvelope(sg, before)
+ fence, err := systemFence(sg, p)
if err != nil {
return err
}
@@ -91,3 +81,39 @@ func CancelSystemPublication(ctx context.Context, s Store, sg Signer, p SystemPu
}
return err
}
+
+// systemFence is the pointer a cancellation of p writes back in place of
+// After: Before, marked with the activation id. Over a real pointer the
+// fence is a new head like any other (Astra round 2, P2-3): a box's floor
+// admits only a strictly later stamp, or the exact pointer it admitted, so
+// a fence carrying Before's own stamp would be a second pointer at that
+// stamp. It takes After's stamp, which the preparer put strictly after
+// Before's (waitPastPromotedAt); After and the fence both replace Before
+// under its ETag, so at most one of them is ever a head. The stamp comes
+// from the kept After rather than the clock, and the signature is
+// deterministic, so a retry signs the same bytes and recognises its own
+// committed write. A publication prepared before preparers waited may have
+// After at Before's stamp; its fence keeps that stamp, as it did then, and
+// a box that admitted Before refuses it and stays on Before, the release it
+// names. A fence over no pointer names no release and reads as no pointer
+// (GetSystemPointer).
+func systemFence(sg Signer, p SystemPublication) ([]byte, error) {
+ after, err := p.Verify(sg.verifyPub())
+ if err != nil {
+ return nil, err
+ }
+ if len(p.Before) == 0 {
+ return SignRootEnvelope(sg, &SystemPointer{Schema: 1, Component: p.Component, Channel: p.Channel, CancellationID: p.ID})
+ }
+ before, err := verifySystemPointer(sg.verifyPub(), p.Before, p.Component, p.Channel)
+ if err != nil {
+ return nil, err
+ }
+ fence := *before
+ fence.identity = ""
+ fence.CancellationID = p.ID
+ if after.PromotedAt.After(before.PromotedAt) {
+ fence.PromotedAt = after.PromotedAt
+ }
+ return SignRootEnvelope(sg, &fence)
+}
diff --git a/internal/release/watermark.go b/internal/release/watermark.go
index 82c498b6e..8342cdcbf 100644
--- a/internal/release/watermark.go
+++ b/internal/release/watermark.go
@@ -34,23 +34,41 @@ type watermark struct {
durable bool
}
-// PointerIdentity names one signed channel pointer by its content: the
-// sha256 of the verified payload re-marshalled. Two reads of the same signed
-// pointer have the same identity; two different pointers, the same stamp or
-// not, do not.
+// PointerIdentity names one signed channel pointer by its exact signed
+// representation: the sha256 of the wrapper bytes it was verified from,
+// payload, signature and grant as they were read, unknown signed fields
+// included (signedIdentity). Two reads of the same object have the same
+// identity; two different signed objects, the same stamp and content or
+// not, do not. Every pointer a floor sees in production comes through a
+// parse site; one built in memory (a test of the ratchet) is named by its
+// content under a prefix no signed identity has (unsignedIdentity).
func PointerIdentity(p *ChannelPointer) string {
+ if p.identity != "" {
+ return p.identity
+ }
+ return unsignedIdentity(p)
+}
+
+// signedIdentity is the identity of one verified signed wrapper.
+func signedIdentity(wrapper []byte) string {
+ sum := sha256.Sum256(wrapper)
+ return hex.EncodeToString(sum[:])
+}
+
+// unsignedIdentity names a pointer that was never verified by its content,
+// marked so it can never equal the identity of a signed one.
+func unsignedIdentity(p any) string {
raw, _ := json.Marshal(p)
sum := sha256.Sum256(raw)
- return hex.EncodeToString(sum[:])
+ return "unsigned:" + hex.EncodeToString(sum[:])
}
-// is reports whether p is the pointer this floor records. A floor written
-// without an identity (none was ever released) falls back to the version.
+// is reports whether p is exactly the pointer this floor records. A floor
+// with no identity is never that pointer: at the
+// floor's own stamp only the recorded pointer passes, and with nothing
+// recorded nothing does (Astra round 2, P1-1).
func (wm watermark) is(p *ChannelPointer) bool {
- if wm.ID == "" {
- return p.Version == wm.Version
- }
- return PointerIdentity(p) == wm.ID
+ return wm.ID != "" && PointerIdentity(p) == wm.ID
}
// watermarkPath is a channel's floor: <dir>/<acct>/<app>/<channel>.watermark,