activator: kept-wake fence baseline opens no publisher
keptBaseline compared and reread the files manifest through hostfiles.OpenBaseline and Open, which the publication guard allows only to sealing continuations (TestEveryStagingOperationIsClassified). It now uses two read-only helpers, hostfiles.BaselineGen and ReadBaseline, which answer what the publisher's Gen and Baseline did, with the same refusals and requests. The wake's publisher still opens on the fence's write in stageKeptFiles.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 files changed,
+129
−9
internal/activator/hagenerations_test.go+31 −0internal/activator/hawake.go+8 −9internal/hostfiles/fence_test.go+38 −0internal/hostfiles/publisher.go+52 −0
diff --git a/internal/activator/hagenerations_test.go b/internal/activator/hagenerations_test.go| index af57265f0..e67d00926 100644 |
| --- a/internal/activator/hagenerations_test.go |
| +++ b/internal/activator/hagenerations_test.go |
| @@ -1104,3 +1104,34 @@ func TestHAWakeRetirementWithoutStoreTime(t *testing.T) { |
| } |
| s.stopForTest(e) |
| } |
| + |
| +// keptBaseline returns the kept manifest when its revision is the |
| +// marker's, with no request, and otherwise the manifest as it is now (one |
| +// GET), without opening a publisher (the publication guard's raw-secret |
| +// rule): what a publisher's Gen and Baseline would have answered. |
| +func TestKeptBaselineComparesAndRereadsWithoutAPublisher(t *testing.T) { |
| + s, e := haServiceEntry(t, "shop.example.com") |
| + writeFiles(t, s.b, s.rt, map[string]string{"a.txt": "app file"}) |
| + s.stopForTest(e) |
| + m := s.rewriteMarkerFormat(t, true) |
| + ctx := context.Background() |
| + manifest := hostfiles.ManifestKey(s.b.filesPrefix(s.rt.Host)) |
| + body, ok := s.fx.Object(manifest) |
| + if !ok { |
| + t.Fatal("no files manifest") |
| + } |
| + before := len(s.fx.Requests()) |
| + base, err := s.b.keptBaseline(ctx, s.rt, m.FilesGen) |
| + if err != nil || !base.Found || string(base.Body) != string(body) || len(s.fx.Requests()) != before { |
| + t.Fatalf("matching revision: %+v, %v, requests %v", base, err, s.fx.Requests()[before:]) |
| + } |
| + logs := captureLog(t) |
| + base, err = s.b.keptBaseline(ctx, s.rt, "9:not-the-marker") |
| + reqs := s.fx.Requests()[before:] |
| + if err != nil || !base.Found || string(base.Body) != string(body) || base.ETag == "" || len(reqs) != 1 || reqs[0] != "GET "+manifest { |
| + t.Fatalf("other revision: %+v, %v, requests %v", base, err, reqs) |
| + } |
| + if !strings.Contains(logs.String(), "the kept manifest is not the marker's") { |
| + t.Fatalf("log %q", logs.String()) |
| + } |
| +} |
diff --git a/internal/activator/hawake.go b/internal/activator/hawake.go| index cb753c124..5a4d2ae14 100644 |
| --- a/internal/activator/hawake.go |
| +++ b/internal/activator/hawake.go |
| @@ -898,20 +898,19 @@ func (b *ExecBackend) keptBaseline(ctx context.Context, rt registry.Route, gen s |
| prefix := b.filesPrefix(rt.Host) |
| base, err := readFilesBaseline(b.pathsFor(rt)) |
| if err == nil { |
| - var pub *hostfiles.Publisher |
| - if pub, err = hostfiles.OpenBaseline(b.FilesStore, prefix, base); err == nil { |
| - if pub.Gen() == gen { |
| + // Compared, never continued: the wake's own publisher opens on |
| + // the fence's result (stageKeptFiles), so no publisher is opened |
| + // here (the publication guard's raw-secret rule). |
| + var have string |
| + if have, err = hostfiles.BaselineGen(prefix, base); err == nil { |
| + if have == gen { |
| return base, nil |
| } |
| - err = fmt.Errorf("revision %s, the marker names %s", pub.Gen(), gen) |
| + err = fmt.Errorf("revision %s, the marker names %s", have, gen) |
| } |
| } |
| log.Printf("activator: %s: files: the kept manifest is not the marker's (%v); reading it again", rt.Host, err) |
| - pub, err := hostfiles.Open(ctx, b.FilesStore, prefix) |
| - if err != nil { |
| - return hostfiles.Baseline{}, err |
| - } |
| - return pub.Baseline(), nil |
| + return hostfiles.ReadBaseline(ctx, b.FilesStore, prefix) |
| } |
| // haLifetime is the host's lifetime ID for the keep decision: the one its |
diff --git a/internal/hostfiles/fence_test.go b/internal/hostfiles/fence_test.go| index 59385d248..2eb2b0631 100644 |
| --- a/internal/hostfiles/fence_test.go |
| +++ b/internal/hostfiles/fence_test.go |
| @@ -124,3 +124,41 @@ func TestFenceManifestStampsAndBlocksALateWrite(t *testing.T) { |
| } |
| }) |
| } |
| + |
| +// BaselineGen and ReadBaseline answer what a publisher would (Gen after |
| +// OpenBaseline; Baseline after Open) without opening one: the kept wake's |
| +// fence compares and reads its manifest with them (keptBaseline). |
| +func TestBaselineGenAndReadBaselineMatchAPublisher(t *testing.T) { |
| + ctx := context.Background() |
| + s := release.NewDirStore(t.TempDir()) |
| + none, err := ReadBaseline(ctx, s, pfx) |
| + if err != nil || none.Found { |
| + t.Fatalf("no manifest: %+v, %v", none, err) |
| + } |
| + if gen, err := BaselineGen(pfx, none); err != nil || gen != open(t, s).Gen() || gen != "0:" { |
| + t.Fatalf("no manifest gen %q, %v", gen, err) |
| + } |
| + p := open(t, s) |
| + stage(t, p, "a.txt", "one") |
| + if _, err := p.Commit(ctx); err != nil { |
| + t.Fatal(err) |
| + } |
| + read, err := ReadBaseline(ctx, s, pfx) |
| + if err != nil || !read.Found || read.ETag != p.Baseline().ETag || string(read.Body) != string(p.Baseline().Body) { |
| + t.Fatalf("read %+v, %v; publisher %+v", read, err, p.Baseline()) |
| + } |
| + gen, err := BaselineGen(pfx, read) |
| + if err != nil || gen != p.Gen() { |
| + t.Fatalf("gen %q, %v; publisher %q", gen, err, p.Gen()) |
| + } |
| + opened, err := OpenBaseline(s, pfx, read) |
| + if err != nil || opened.Gen() != gen { |
| + t.Fatalf("OpenBaseline gen %v, %v", opened, err) |
| + } |
| + if _, err := BaselineGen(pfx, Baseline{Found: true, Body: read.Body}); err == nil { |
| + t.Fatal("a found baseline with no token was accepted") |
| + } |
| + if _, err := BaselineGen(pfx, Baseline{Found: true, Body: []byte("{"), ETag: "x"}); err == nil { |
| + t.Fatal("bytes that do not decode were accepted") |
| + } |
| +} |
diff --git a/internal/hostfiles/publisher.go b/internal/hostfiles/publisher.go| index 92a489baf..e9215ba5e 100644 |
| --- a/internal/hostfiles/publisher.go |
| +++ b/internal/hostfiles/publisher.go |
| @@ -243,6 +243,58 @@ func (p *Publisher) Baseline() Baseline { |
| return Baseline{Found: true, Body: append([]byte(nil), p.committedBody...), ETag: p.etag} |
| } |
| +// BaselineGen is the revision a publisher opened on b would name |
| +// (OpenBaseline, then Gen), with no publisher: "<seq>:<sha256 of b's |
| +// exact bytes>", or "0:" for no manifest. It refuses what OpenBaseline |
| +// refuses: a bad prefix, a found baseline with no token, bytes that do |
| +// not decode, and a manifest past the path cap. It reads nothing, stages |
| +// nothing and opens nothing a caller could continue, so a raw secret |
| +// item in b is not its concern: a wake that continues from b opens its |
| +// own publisher. |
| +func BaselineGen(prefix string, b Baseline) (string, error) { |
| + if err := checkPrefix(prefix); err != nil { |
| + return "", err |
| + } |
| + if !b.Found { |
| + return "0:", nil |
| + } |
| + if b.ETag == "" { |
| + return "", fmt.Errorf("hostfiles: open %s at its read bytes: no token", prefix) |
| + } |
| + m, err := decode(prefix, b.Body) |
| + if err != nil { |
| + return "", err |
| + } |
| + if err := manifestWithinCap(m); err != nil { |
| + return "", fmt.Errorf("hostfiles: open %s: the manifest cannot be continued, an operator must replace it: %w", prefix, err) |
| + } |
| + return fmt.Sprintf("%d:%s", m.Seq, sum(b.Body)), nil |
| +} |
| + |
| +// ReadBaseline is the manifest at prefix as it is now (one GET), as Open |
| +// would take it and Baseline return it, with no publisher: Found false |
| +// when there is none. It refuses what Open refuses. Like BaselineGen it |
| +// is for a caller that only compares or fences the manifest. |
| +func ReadBaseline(ctx context.Context, s release.Store, prefix string) (Baseline, error) { |
| + if s == nil { |
| + return Baseline{}, errors.New("hostfiles: open: no store") |
| + } |
| + if err := checkPrefix(prefix); err != nil { |
| + return Baseline{}, err |
| + } |
| + m, raw, etag, found, err := loadRaw(ctx, s, prefix) |
| + if err != nil { |
| + return Baseline{}, err |
| + } |
| + if err := manifestWithinCap(m); err != nil { |
| + return Baseline{}, fmt.Errorf("hostfiles: open %s: the manifest cannot be continued, an operator must replace it: %w", prefix, err) |
| + } |
| + if !found { |
| + return Baseline{}, nil |
| + } |
| + return Baseline{Found: true, Body: append([]byte(nil), raw...), ETag: etag}, nil |
| +} |
| + |
| func sum(body []byte) string { |
| h := sha256.Sum256(body) |
| return hex.EncodeToString(h[:]) |