carlos / platform Public

claim regional enrollment: stop pinning the roster revision

The agent's regional worker pinned the whole verified actor at Build,
including the roster-wide Revision. Every roster write bumps it, a
create's own actor hold among them, so VerifyRegional returned
ErrChanged on every pass after the first create until the agent
restarted (G10).

VerifyRegional now compares the fresh actor with the startup actor
field by field, ignoring only Revision. The protection the revision
gave against a quarantine since startup stays explicit: the production
roster adapter now carries the row's QuarantineRevision on the actor,
and that only grows, so a box quarantined and readmitted since startup
still never matches. Verify itself still refuses an ineligible,
quarantined, fenced or retired row.

claimBoundIdentity, the regional data store's check, still pins the
revision on purpose (TestMoveParksVerifiedIdentityAndRealEngine) and is
unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 7b8057206c2e0802d4af78c20a08d880e1093b38 parent 79db17b
4 files changed, +189 −2
  • internal/host/claim_regional_revision_test.go +170 −0
  • internal/host/claimassembly.go +14 −1
  • internal/host/claimproduction.go +1 −1
  • internal/hostbox/identity.go +4 −0
diff --git a/internal/host/claim_regional_revision_test.go b/internal/host/claim_regional_revision_test.go
new file mode 100644
index 000000000..9d63705d3
--- /dev/null
+++ b/internal/host/claim_regional_revision_test.go
@@ -0,0 +1,170 @@
+package host
+
+import (
+ "crypto/ed25519"
+ "encoding/json"
+ "errors"
+ "os"
+ "path/filepath"
+ "reflect"
+ "strings"
+ "testing"
+
+ "github.com/carlosframework/platform/internal/hostactors"
+ "github.com/carlosframework/platform/internal/hostbox"
+ "github.com/carlosframework/platform/internal/hostfloor"
+ "github.com/carlosframework/platform/internal/release"
+)
+
+// Every actor field but the roster-wide Revision is part of the enrollment
+// a built assembly is bound to. The reflection walk covers fields added later.
+func TestSameVerifiedActorIgnoresOnlyRevision(t *testing.T) {
+ base := hostbox.Actor{FleetHomeRegion: "ie", HomeRegion: "ie", ControlBucket: "deployment", Box: "box", Enrollment: strings.Repeat("a", 32), Revision: 7, Region: "ie", Bucket: "data", Namespace: "platform", Cloud: hostbox.CloudIdentity{Provider: "aws", Account: "111122223333", Region: "eu-west-1", InstanceID: "i-0abc"}, Eligible: true, QuarantineRevision: 2}
+ var walk func(v reflect.Value, path string)
+ walk = func(v reflect.Value, path string) {
+ for i := 0; i < v.NumField(); i++ {
+ f, name := v.Field(i), path+v.Type().Field(i).Name
+ if f.Kind() == reflect.Struct {
+ walk(f, name+".")
+ continue
+ }
+ changed := base
+ field := reflect.ValueOf(&changed).Elem().FieldByIndex(fieldIndex(reflect.TypeOf(base), name))
+ switch field.Kind() {
+ case reflect.String:
+ field.SetString(field.String() + "-changed")
+ case reflect.Uint64:
+ field.SetUint(field.Uint() + 1)
+ case reflect.Bool:
+ field.SetBool(!field.Bool())
+ default:
+ t.Fatalf("%s: unhandled kind %s", name, field.Kind())
+ }
+ if got, want := sameVerifiedActor(changed, base), name == "Revision"; got != want {
+ t.Errorf("%s changed: same = %v, want %v", name, got, want)
+ }
+ }
+ }
+ walk(reflect.ValueOf(base), "")
+}
+
+func fieldIndex(t reflect.Type, path string) []int {
+ var index []int
+ for _, name := range strings.Split(path, ".") {
+ f, _ := t.FieldByName(name)
+ index = append(index, f.Index...)
+ t = f.Type
+ }
+ return index
+}
+
+// The regional enrollment check runs on the production roster adapter: a
+// roster revision bump (a create's actor hold is one) passes, and a
+// quarantine and readmission since startup still refuses.
+func TestClaimRegionalEnrollmentSurvivesRosterRevision(t *testing.T) {
+ key := ed25519.NewKeyFromSeed(make([]byte, 32))
+ s := release.NewDirStore(t.TempDir())
+ bucket := "deployment"
+ if err := hostfloor.Publish(t.Context(), s, release.RootSigner(key), bucket, hostfloor.Floor{Min: 1, MinRelease: "v0.1.0"}); err != nil {
+ t.Fatal(err)
+ }
+ raw, _, _ := s.Get(t.Context(), hostfloor.Key)
+ auth, _, _ := s.Get(t.Context(), hostfloor.AuthKey)
+ dir := t.TempDir()
+ body, _ := json.Marshal(hostfloor.Policy{Schema: 1, DeploymentBucket: bucket, Mode: "enforced", Floor: raw, Authorization: auth})
+ if err := os.WriteFile(filepath.Join(dir, "policy.json"), body, 0600); err != nil {
+ t.Fatal(err)
+ }
+ identity := handoverRecoveryIdentity(t, hostbox.Actor{Box: "box", Enrollment: strings.Repeat("a", 32), Region: "ie", ControlBucket: bucket, Revision: 1})
+ row := hostactors.Box{BoxID: "box", Enrollment: strings.Repeat("a", 32), Namespace: identity.Namespace, Label: "box", Region: "ie", Pool: "default", Cloud: hostactors.Cloud{Provider: "aws", Account: identity.Account, Region: identity.AWSRegion, InstanceID: "i-0abc"}, EvidenceSHA256: strings.Repeat("c", 64), State: "active"}
+ roster := hostactors.Roster{V: 1, DeploymentBucket: bucket, Revision: 1, RequestLimitNS: int64(hostbox.RequestLimit), Publication: "published", FloorSHA256: hostfloor.Digest(raw), Boxes: map[string]hostactors.Box{"box": row}, Consoles: map[string]hostactors.Console{}, Holds: map[string]hostactors.Reservation{}, Activations: map[string]hostactors.Reservation{}}
+ write := func() {
+ t.Helper()
+ wire, err := release.SignRootEnvelope(release.RootSigner(key), roster)
+ if err != nil {
+ t.Fatal(err)
+ }
+ _, etag, _ := s.Get(t.Context(), hostactors.Key)
+ if _, err = s.Put(t.Context(), hostactors.Key, wire, etag); err != nil {
+ t.Fatal(err)
+ }
+ }
+ write()
+ identity.Roster = productionClaimRoster{Directory: hostactors.Directory{Store: s, PublicKey: key.Public().(ed25519.PublicKey), Bucket: bucket}, DataBucket: identity.Bucket, FloorDir: dir}
+ actor, err := identity.Verify(t.Context())
+ if err != nil {
+ t.Fatal(err)
+ }
+ e := claimRegionalEnrollment{identity: identity, actor: actor}
+ check := func(step string, want error) {
+ t.Helper()
+ if err := e.VerifyRegional(t.Context(), actor.Region, actor.Bucket, hostbox.RequestLimit); !errors.Is(err, want) && !(want == nil && err == nil) {
+ t.Fatalf("%s: VerifyRegional = %v, want %v", step, err, want)
+ }
+ }
+ check("startup", nil)
+
+ roster.Revision++
+ write()
+ check("roster revision bump", nil)
+
+ row.State, row.QuarantineRevision, row.LossIDs = "quarantined", 1, []string{"loss"}
+ roster.Boxes["box"], roster.Revision = row, roster.Revision+1
+ write()
+ check("quarantined", hostbox.ErrChanged)
+
+ row.State = "active"
+ roster.Boxes["box"], roster.Revision = row, roster.Revision+1
+ write()
+ check("readmitted since startup", hostbox.ErrChanged)
+}
+
+// Each enrollment field the roster carries still refuses when it changes
+// under a running assembly; only the revision bump passes.
+func TestClaimRegionalEnrollmentFieldChanges(t *testing.T) {
+ base := hostbox.Actor{Box: "box", Enrollment: "enrolled", Region: "region", FleetHomeRegion: "region", ControlBucket: "control", Revision: 1}
+ identity := handoverRecoveryIdentity(t, base)
+ actor, err := identity.Verify(t.Context())
+ if err != nil {
+ t.Fatal(err)
+ }
+ e := claimRegionalEnrollment{identity: identity, actor: actor}
+ for name, edit := range map[string]func(*hostbox.Actor){
+ "revision": func(a *hostbox.Actor) { a.Revision++ },
+ "eligible": func(a *hostbox.Actor) { a.Eligible = false },
+ "quarantined": func(a *hostbox.Actor) { a.Quarantined = true },
+ "quarantine revision": func(a *hostbox.Actor) { a.QuarantineRevision++ },
+ "box": func(a *hostbox.Actor) { a.Box = "other" },
+ "enrollment": func(a *hostbox.Actor) { a.Enrollment = "re-enrolled" },
+ "region": func(a *hostbox.Actor) { a.Region = "other" },
+ "bucket": func(a *hostbox.Actor) { a.Bucket = "other" },
+ "namespace": func(a *hostbox.Actor) { a.Namespace = "other" },
+ "control bucket": func(a *hostbox.Actor) { a.ControlBucket = "other" },
+ "fleet home region": func(a *hostbox.Actor) { a.FleetHomeRegion = "other" },
+ "cloud account": func(a *hostbox.Actor) { a.Cloud.Account = "444455556666" },
+ "cloud region": func(a *hostbox.Actor) { a.Cloud.Region = "eu-west-2" },
+ "cloud instance": func(a *hostbox.Actor) { a.Cloud.InstanceID = "i-0def" },
+ } {
+ t.Run(name, func(t *testing.T) {
+ changed := identity
+ row := actor
+ row.HomeRegion = ""
+ edit(&row)
+ changed.Roster = handoverRecoveryRoster{row}
+ e := e
+ e.identity = changed
+ err := e.VerifyRegional(t.Context(), actor.Region, actor.Bucket, hostbox.RequestLimit)
+ if name == "revision" {
+ if err != nil {
+ t.Fatalf("revision bump refused: %v", err)
+ }
+ return
+ }
+ // A new instance ID fails Verify's signed cloud evidence first,
+ // with that check's own error; every other change is ErrChanged.
+ if err == nil || (name != "cloud instance" && !errors.Is(err, hostbox.ErrChanged)) {
+ t.Fatalf("changed enrollment: %v, want ErrChanged", err)
+ }
+ })
+ }
+}
diff --git a/internal/host/claimassembly.go b/internal/host/claimassembly.go
index d54c9f48e..4b1984cca 100644
--- a/internal/host/claimassembly.go
+++ b/internal/host/claimassembly.go
@@ -286,12 +286,25 @@ func (e claimRegionalEnrollment) VerifyRegional(ctx context.Context, region, buc
if err != nil {
return err
}
- if a != e.actor || !park.SameRegion(a.HomeRegion, park.PlacementRegion(a.Region), region) || a.Bucket != bucket {
+ if !sameVerifiedActor(a, e.actor) || !park.SameRegion(a.HomeRegion, park.PlacementRegion(a.Region), region) || a.Bucket != bucket {
return hostbox.ErrChanged
}
return nil
}
+// sameVerifiedActor reports whether a freshly verified actor is still the
+// enrollment the regional worker was built for. Every field must match except the
+// roster-wide Revision, which every roster write bumps, a create's own actor
+// hold among them; pinning it stopped the regional worker at the first
+// create after each agent start. What the startup pin protected stays
+// explicit: Verify refuses an ineligible, quarantined, fenced or retired
+// row, and QuarantineRevision only grows, so a box quarantined and readmitted
+// since startup still never matches its startup actor.
+func sameVerifiedActor(current, expected hostbox.Actor) bool {
+ current.Revision, expected.Revision = 0, 0
+ return current == expected
+}
+
func productionClaimFactory(ctx context.Context) (ClaimProviders, error) {
entry, _ := ctx.Value(claimEntryKey{}).(claimEntry)
if entry.Store == nil {
diff --git a/internal/host/claimproduction.go b/internal/host/claimproduction.go
index c87c21f76..dad097aa3 100644
--- a/internal/host/claimproduction.go
+++ b/internal/host/claimproduction.go
@@ -393,7 +393,7 @@ func (p productionClaimRoster) Actor(ctx context.Context, box string) (hostbox.A
if local.Digest != remote.Digest || o.Roster.Publication != "published" || o.Roster.FloorSHA256 != remote.Digest {
return a, hostfloor.ErrFloor
}
- return hostbox.Actor{FleetHomeRegion: o.Roster.HomeRegion, ControlBucket: p.Directory.Bucket, Box: box, Enrollment: b.Enrollment, Revision: o.Roster.Revision, Region: b.Region, Bucket: p.DataBucket, Namespace: b.Namespace, Eligible: true, Cloud: hostbox.CloudIdentity{Provider: b.Cloud.Provider, Account: b.Cloud.Account, Region: b.Cloud.Region, InstanceID: b.Cloud.InstanceID}}, nil
+ return hostbox.Actor{FleetHomeRegion: o.Roster.HomeRegion, ControlBucket: p.Directory.Bucket, Box: box, Enrollment: b.Enrollment, Revision: o.Roster.Revision, Region: b.Region, Bucket: p.DataBucket, Namespace: b.Namespace, Eligible: true, QuarantineRevision: b.QuarantineRevision, Cloud: hostbox.CloudIdentity{Provider: b.Cloud.Provider, Account: b.Cloud.Account, Region: b.Cloud.Region, InstanceID: b.Cloud.InstanceID}}, nil
}
type productionClaimRegional struct {
diff --git a/internal/hostbox/identity.go b/internal/hostbox/identity.go
index 97f268ca5..8e60153ba 100644
--- a/internal/hostbox/identity.go
+++ b/internal/hostbox/identity.go
@@ -22,6 +22,10 @@ type Actor struct {
Cloud CloudIdentity
Eligible bool
Quarantined bool
+ // QuarantineRevision is the roster row's quarantine count. It only grows,
+ // so an actor verified after a quarantine and readmission never equals
+ // one verified before it, whatever else the roster revision does.
+ QuarantineRevision uint64
}
type CloudIdentity struct{ Provider, Account, Region, InstanceID string }
type Roster interface {