carlos / platform Public

fix: snapshot worker opens its files without openat2

codex agent, operated by paul@keymail.dev pushed by claude agent, operated by paul@keymail.dev 53940194d31b9c74c2af92d37f6db9d3aa206d08 parent b8ad2fa
9 files changed, +332 −15
  • docs/superpowers/notes/census-demo-snapshot-unit-check-claims.md +5 −0
  • docs/superpowers/notes/census-proposal-demo-snapshot-unit-check.md +13 −3
  • internal/democlaim/source_linux.go +33 −4
  • internal/democlaim/source_other.go +4 −3
  • internal/democlaim/source_worker_linux_test.go +166 −0
  • internal/democlaim/worker.go +1 −1
  • internal/instancectl/demo_snapshot_kernel_linux_test.go +96 −2
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −1
  • internal/provision/testdata/plan14-root-reads-demo-snapshot-unit-check.tsv +13 −1

CI passed — run details

Intent

Human

<paseo-system version="1" kind="agent-message" source-agent-id="39e7acfa-a56a-470b-8ef5-70de5c57a6f2" message-id="82c2c846-468c-4c94-897a-659253cfc30f" source-agent-title="agent /start demo program controller"> From 39e7acfa, FYI from the release agent&apos;s claimAvailable check (false, as expected). sophie and dennis are fully ready: seed + moved capabilities, protocol 2, floor v0.34.9, prev allowed v0.34.9. One extra line from demo box-1 for you to judge while you&apos;re in this code: its edges-file pass logs &quot;could not load box snapshots (fleetapi: list status/boxes/: unexpected status 404)&quot;. You said fleet boxes publish no edges file. Is this 404 harmless noise, or does anything on the claim path (moved delivery, readiness) need that list? Answer when the witness is done. If it&apos;s a fault, it joins the same branch. </paseo-system>

Attributed to this commit: 51.7 g CO₂e (6,537,700 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on demo-snapshot-unit-check, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.

diff --git a/docs/superpowers/notes/census-demo-snapshot-unit-check-claims.md b/docs/superpowers/notes/census-demo-snapshot-unit-check-claims.md
index c5820b517..85f4fce28 100644
--- a/docs/superpowers/notes/census-demo-snapshot-unit-check-claims.md
+++ b/docs/superpowers/notes/census-demo-snapshot-unit-check-claims.md
@@ -1 +1,6 @@
internal/instancectl/demo_snapshot_disk.go:demoSnapshotSupervisor.checkUnit Accept an omitted EnvironmentFiles property as empty, as emitted by systemd 257; continue requesting it and reject every non-empty value. All other property checks remain unchanged. No read added; the existing systemctl query requests the same properties.
+internal/democlaim/source_linux.go:OpenSource Retain the existing instancefs directory open and openat2 flags for root and agent callers; move the file syscall from Source.open into this constructor's opener. No fallback is added. Shared validation still rejects unsafe names, nonregular files, multiple links and oversized DB plus WAL.
+internal/democlaim/source_linux.go:OpenWorkerSource Open only the worker's private directory with open O_DIRECTORY|O_NOFOLLOW|O_CLOEXEC, then use the worker file opener and shared Source checks. The private command supplies /work; no root or agent caller switches to this constructor. New direct directory read replaces the worker's blocked openat2 path.
+internal/democlaim/source_linux.go:openWorkerFile Open a single component relative to the held private worker directory with openat O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOFOLLOW. Refuse empty, dot, dot-dot, slash, backslash and NUL names before the syscall. New direct file read is used only by OpenWorkerSource, including VerifyUnchanged.
+internal/democlaim/source_linux.go:Source.open Route the file open through the constructor-selected opener; retain identical Fstat, regular-file, nlink==1 and nonnegative-size checks. Root and agent still select openat2; the private worker selects openat. VerifyUnchanged uses this same seam with its existing inode, timestamps, size and link checks.
+internal/democlaim/worker.go:RunSnapshotWorkerIn Select OpenWorkerSource for fixed snapshot.db and optional snapshot.db-wal in private /work. Preserve root refusal, result-name reservation, timeout, VerifyUnchanged, checkpoint, integrity check, hashing and failed-result cleanup. No new path input or read is added here.
diff --git a/docs/superpowers/notes/census-proposal-demo-snapshot-unit-check.md b/docs/superpowers/notes/census-proposal-demo-snapshot-unit-check.md
index e2f496a7f..10e908894 100644
--- a/docs/superpowers/notes/census-proposal-demo-snapshot-unit-check.md
+++ b/docs/superpowers/notes/census-proposal-demo-snapshot-unit-check.md
@@ -1,19 +1,29 @@
# Census approval: demo-snapshot-unit-check
-Ruling `census-ruling-demo-snapshot-unit-check`. The independent reviewer approves or rejects every change below, 0 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26).
+Ruling `census-ruling-demo-snapshot-unit-check`. The independent reviewer approves or rejects every change below, 3 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26).
| unit | change | read sites | what changed |
|---|---|---|---|
+| `internal/democlaim/worker.go` `RunSnapshotWorkerIn` | body | unchanged (1) | Select OpenWorkerSource for fixed snapshot.db and optional snapshot.db-wal in private /work. Preserve root refusal, result-name reservation, timeout, VerifyUnchanged, checkpoint, integrity check, hashing and failed-result cleanup. No new path input or read is added here. |
| `internal/instancectl/demo_snapshot_disk.go` `demoSnapshotSupervisor.checkUnit` | body | unchanged (1) | Accept an omitted EnvironmentFiles property as empty, as emitted by systemd 257; continue requesting it and reject every non-empty value. All other property checks remain unchanged. No read added; the existing systemctl query requests the same properties. |
+| `internal/democlaim/source_linux.go` `Source.open` | sites | -file:Openat2 | Route the file open through the constructor-selected opener; retain identical Fstat, regular-file, nlink==1 and nonnegative-size checks. Root and agent still select openat2; the private worker selects openat. VerifyUnchanged uses this same seam with its existing inode, timestamps, size and link checks. |
-Envelopes re-pinned: `internal/instancectl`.
+Envelopes re-pinned: `internal/democlaim`, `internal/instancectl`.
Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner.
Recorded dispositions, which each change must still satisfy:
+- `internal/democlaim/worker.go` `RunSnapshotWorkerIn`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-agent-start-demo-3;basis=Open only fixed private helper files and write bounded snapshot metadata; caller-provided live source paths never reach SQLite as root. Census read-site delta: +file:OpenFile.
- `internal/instancectl/demo_snapshot_disk.go` `demoSnapshotSupervisor.checkUnit`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-agent-start-demo-3;basis=Inspect the effective fixed systemd snapshot unit and require its declared isolation, resource and execution settings. Census read-site delta: +data-literal.
+- `internal/democlaim/source_linux.go` `Source.open`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-agent-start-demo-3;basis=Open DB and WAL beneath the retained source directory with openat2 no-follow/beneath constraints and enforce regular-file bounds. Census read-site delta: +file:Fstat, +file:Openat2.
-Seal: `ebeaa693941f5592cd7bc3458effc2a333a8d12ba4f192a93d0aa32589048939` → `62613178975daa6640bb46d87f143bf5291e51921e350b6c731438a77daf61f7`.
+New dispositions, which census-propose wrote and the reviewer checks against the unit's reads and the diff:
+
+- new `internal/democlaim/source_linux.go:OpenSource`: reads +file:Openat2; written legacy, accepted-legacy, frozen
+- new `internal/democlaim/source_linux.go:OpenWorkerSource`: reads +file:Open; written legacy, accepted-legacy, frozen
+- new `internal/democlaim/source_linux.go:openWorkerFile`: reads +file:Openat; written legacy, accepted-legacy, frozen
+
+Seal: `ebeaa693941f5592cd7bc3458effc2a333a8d12ba4f192a93d0aa32589048939` → `1e83ce23d7d1306e3963f802fecf8c914a2624726255e3bc30382104e568adde`.
Overlay: `internal/provision/testdata/plan14-root-reads-demo-snapshot-unit-check.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/internal/democlaim/source_linux.go b/internal/democlaim/source_linux.go
index f35c41c40..73987b310 100644
--- a/internal/democlaim/source_linux.go
+++ b/internal/democlaim/source_linux.go
@@ -20,17 +20,46 @@ type Source struct {
dir *os.File
base string
dbStat, walStat unix.Stat_t
+ openFile func(int, string) (int, error)
}
-func OpenSource(dir, base string) (s *Source, err error) {
+func OpenSource(dir, base string) (*Source, error) {
+ return openSource(dir, base, func(dir string) (*os.File, error) {
+ return instancefs.OpenDirBeneath(dir, ".")
+ }, func(fd int, name string) (int, error) {
+ return unix.Openat2(fd, name, &unix.OpenHow{Flags: unix.O_RDONLY | unix.O_CLOEXEC | unix.O_NONBLOCK, Resolve: unix.RESOLVE_BENEATH | unix.RESOLVE_NO_SYMLINKS | unix.RESOLVE_NO_MAGICLINKS})
+ })
+}
+
+// OpenWorkerSource is only for fixed names in the worker's private /work.
+// DynamicUser's seccomp filter blocks openat2. A single component opened
+// with O_NOFOLLOW cannot escape the held directory or follow a symlink.
+func OpenWorkerSource(dir, base string) (*Source, error) {
+ return openSource(dir, base, func(dir string) (*os.File, error) {
+ fd, err := unix.Open(dir, unix.O_RDONLY|unix.O_DIRECTORY|unix.O_NOFOLLOW|unix.O_CLOEXEC, 0)
+ if err != nil {
+ return nil, err
+ }
+ return os.NewFile(uintptr(fd), dir), nil
+ }, openWorkerFile)
+}
+
+func openWorkerFile(fd int, name string) (int, error) {
+ if name == "" || name == "." || name == ".." || strings.ContainsAny(name, "/\\\x00") {
+ return -1, ErrSnapshot
+ }
+ return unix.Openat(fd, name, unix.O_RDONLY|unix.O_CLOEXEC|unix.O_NONBLOCK|unix.O_NOFOLLOW, 0)
+}
+
+func openSource(dir, base string, openDir func(string) (*os.File, error), openFile func(int, string) (int, error)) (s *Source, err error) {
if !filepath.IsAbs(dir) || base == "" || base == "." || base == ".." || strings.ContainsAny(base, "/\\\x00") {
return nil, ErrSnapshot
}
- d, err := instancefs.OpenDirBeneath(dir, ".")
+ d, err := openDir(dir)
if err != nil {
return nil, err
}
- s = &Source{dir: d, base: base}
+ s = &Source{dir: d, base: base, openFile: openFile}
defer func() {
if err != nil {
s.Close()
@@ -63,7 +92,7 @@ func OpenSource(dir, base string) (s *Source, err error) {
func (s *Source) open(name string) (*os.File, unix.Stat_t, error) {
var st unix.Stat_t
- fd, err := unix.Openat2(int(s.dir.Fd()), name, &unix.OpenHow{Flags: unix.O_RDONLY | unix.O_CLOEXEC | unix.O_NONBLOCK, Resolve: unix.RESOLVE_BENEATH | unix.RESOLVE_NO_SYMLINKS | unix.RESOLVE_NO_MAGICLINKS})
+ fd, err := s.openFile(int(s.dir.Fd()), name)
if err != nil {
return nil, st, err
}
diff --git a/internal/democlaim/source_other.go b/internal/democlaim/source_other.go
index a9ec1d708..d1086c883 100644
--- a/internal/democlaim/source_other.go
+++ b/internal/democlaim/source_other.go
@@ -12,6 +12,7 @@ type Source struct {
DBBytes, WALBytes int64
}
-func OpenSource(string, string) (*Source, error) { return nil, errors.ErrUnsupported }
-func (*Source) VerifyUnchanged() error { return errors.ErrUnsupported }
-func (*Source) Close() error { return nil }
+func OpenSource(string, string) (*Source, error) { return nil, errors.ErrUnsupported }
+func OpenWorkerSource(string, string) (*Source, error) { return nil, errors.ErrUnsupported }
+func (*Source) VerifyUnchanged() error { return errors.ErrUnsupported }
+func (*Source) Close() error { return nil }
diff --git a/internal/democlaim/source_worker_linux_test.go b/internal/democlaim/source_worker_linux_test.go
new file mode 100644
index 000000000..84516cfed
--- /dev/null
+++ b/internal/democlaim/source_worker_linux_test.go
@@ -0,0 +1,166 @@
+//go:build linux
+
+package democlaim
+
+import (
+ "bytes"
+ "go/ast"
+ "go/parser"
+ "go/token"
+ "io"
+ "os"
+ "path/filepath"
+ "testing"
+
+ "golang.org/x/sys/unix"
+)
+
+func TestOpenWorkerSource(t *testing.T) {
+ t.Run("dbAndWAL", func(t *testing.T) {
+ dir := walFixture(t)
+ s, err := OpenWorkerSource(dir, "source.db")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer s.Close()
+ for _, entry := range []struct {
+ file *os.File
+ size int64
+ name string
+ }{{s.DB, s.DBBytes, "source.db"}, {s.WAL, s.WALBytes, "source.db-wal"}} {
+ if entry.file == nil || entry.size <= 0 {
+ t.Fatalf("missing %s", entry.name)
+ }
+ got, err := io.ReadAll(entry.file)
+ if err != nil {
+ t.Fatal(err)
+ }
+ want, err := os.ReadFile(filepath.Join(dir, entry.name))
+ if err != nil || !bytes.Equal(got, want) || int64(len(got)) != entry.size {
+ t.Fatal("source bytes differ", entry.name, err)
+ }
+ }
+ if err = s.VerifyUnchanged(); err != nil {
+ t.Fatal(err)
+ }
+ if err = os.Truncate(filepath.Join(dir, "source.db-wal"), 0); err != nil {
+ t.Fatal(err)
+ }
+ if err = s.VerifyUnchanged(); err == nil {
+ t.Fatal("changed WAL accepted")
+ }
+ })
+ for _, suffix := range []string{"", "-wal"} {
+ for _, fault := range []string{"symlink", "hardlink", "fifo", "directory", "oversize"} {
+ t.Run("source.db"+suffix+"/"+fault, func(t *testing.T) {
+ dir := t.TempDir()
+ must := func(err error) {
+ t.Helper()
+ if err != nil {
+ t.Fatal(err)
+ }
+ }
+ base := filepath.Join(dir, "source.db")
+ must(os.WriteFile(base, []byte("db"), 0600))
+ path := base + suffix
+ if suffix == "" {
+ must(os.Remove(path))
+ }
+ switch fault {
+ case "symlink":
+ must(os.WriteFile(path+".target", []byte("db"), 0600))
+ must(os.Symlink(path+".target", path))
+ case "hardlink":
+ must(os.WriteFile(path+".target", []byte("db"), 0600))
+ must(os.Link(path+".target", path))
+ case "fifo":
+ must(unix.Mkfifo(path, 0600))
+ case "directory":
+ must(os.Mkdir(path, 0700))
+ case "oversize":
+ must(os.WriteFile(path, []byte("db"), 0600))
+ must(os.Truncate(path, MaxSnapshotBytes+1))
+ }
+ if s, err := OpenWorkerSource(dir, "source.db"); err == nil {
+ s.Close()
+ t.Fatal("unsafe source accepted")
+ }
+ })
+ }
+ }
+ for _, name := range []string{"", ".", "..", "nested/source.db", "../source.db"} {
+ t.Run("name/"+name, func(t *testing.T) {
+ if s, err := OpenWorkerSource(t.TempDir(), name); err != ErrSnapshot {
+ if s != nil {
+ s.Close()
+ }
+ t.Fatal("unsafe name accepted", err)
+ }
+ if fd, err := openWorkerFile(-1, name); err != ErrSnapshot {
+ if fd >= 0 {
+ unix.Close(fd)
+ }
+ t.Fatal("worker file seam did not reject name", err)
+ }
+ })
+ }
+ t.Run("directorySymlink", func(t *testing.T) {
+ link := filepath.Join(t.TempDir(), "link")
+ if err := os.Symlink(walFixture(t), link); err != nil {
+ t.Fatal(err)
+ }
+ if s, err := OpenWorkerSource(link, "source.db"); err == nil {
+ s.Close()
+ t.Fatal("directory symlink accepted")
+ }
+ })
+ t.Run("absentWAL", func(t *testing.T) {
+ dir := t.TempDir()
+ if err := os.WriteFile(filepath.Join(dir, "source.db"), []byte("db"), 0600); err != nil {
+ t.Fatal(err)
+ }
+ s, err := OpenWorkerSource(dir, "source.db")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer s.Close()
+ if s.WAL != nil || s.WALBytes != 0 {
+ t.Fatal("absent WAL reported present")
+ }
+ if err = s.VerifyUnchanged(); err != nil {
+ t.Fatal(err)
+ }
+ if err = os.WriteFile(filepath.Join(dir, "source.db-wal"), []byte("wal"), 0600); err != nil {
+ t.Fatal(err)
+ }
+ if err = s.VerifyUnchanged(); err == nil {
+ t.Fatal("new WAL accepted")
+ }
+ })
+}
+
+func TestWorkerSourceDoesNotUseOpenat2(t *testing.T) {
+ f, err := parser.ParseFile(token.NewFileSet(), "source_linux.go", nil, 0)
+ if err != nil {
+ t.Fatal(err)
+ }
+ for _, name := range []string{"OpenWorkerSource", "openWorkerFile"} {
+ found := false
+ for _, decl := range f.Decls {
+ fn, ok := decl.(*ast.FuncDecl)
+ if !ok || fn.Name.Name != name {
+ continue
+ }
+ found = true
+ ast.Inspect(fn.Body, func(n ast.Node) bool {
+ if id, ok := n.(*ast.Ident); ok && (id.Name == "Openat2" || id.Name == "instancefs" || id.Name == "OpenSource") {
+ t.Errorf("%s references %s; the worker sandbox blocks openat2", name, id.Name)
+ }
+ return true
+ })
+ }
+ if !found {
+ t.Fatalf("worker open function %s missing", name)
+ }
+ }
+}
diff --git a/internal/democlaim/worker.go b/internal/democlaim/worker.go
index 66d63709b..186e96415 100644
--- a/internal/democlaim/worker.go
+++ b/internal/democlaim/worker.go
@@ -38,7 +38,7 @@ func RunSnapshotWorkerIn(ctx context.Context, dir string) (err error) {
_ = os.Remove(filepath.Join(dir, "result.json"))
}
}()
- source, err := OpenSource(dir, "snapshot.db")
+ source, err := OpenWorkerSource(dir, "snapshot.db")
if err != nil {
return err
}
diff --git a/internal/instancectl/demo_snapshot_kernel_linux_test.go b/internal/instancectl/demo_snapshot_kernel_linux_test.go
index 5627268ba..811e89fc3 100644
--- a/internal/instancectl/demo_snapshot_kernel_linux_test.go
+++ b/internal/instancectl/demo_snapshot_kernel_linux_test.go
@@ -4,6 +4,7 @@ package instancectl
import (
"context"
+ "database/sql"
"encoding/json"
"errors"
"fmt"
@@ -30,6 +31,57 @@ type snapshotWitnessInput struct {
Socket string
}
+func TestDemoClaimSnapshotRealWorker(t *testing.T) {
+ if os.Getenv("CARLOS_SNAPSHOT_WITNESS_HELPER") != "1" {
+ t.Skip("private snapshot witness helper")
+ }
+ if err := democlaim.RunSnapshotWorker(t.Context()); err != nil {
+ t.Fatal(err)
+ }
+}
+
+func prepareSnapshotWorkerWAL(t *testing.T, work string) {
+ t.Helper()
+ path := filepath.Join(t.TempDir(), "source.db")
+ db, err := sql.Open("sqlite", path)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer db.Close()
+ db.SetMaxOpenConns(1)
+ for _, query := range []string{"PRAGMA journal_mode=WAL", "PRAGMA wal_autocheckpoint=0", "CREATE TABLE items(value TEXT)", "PRAGMA wal_checkpoint(TRUNCATE)", "INSERT INTO items VALUES ('committed in WAL')"} {
+ if _, err = db.ExecContext(t.Context(), query); err != nil {
+ t.Fatal(err)
+ }
+ }
+ // Copy before closing SQLite: its last connection checkpoints the source WAL.
+ for _, suffix := range []string{"", "-wal"} {
+ raw, err := os.ReadFile(path + suffix)
+ if err != nil || len(raw) == 0 {
+ t.Fatal("missing fixture bytes", suffix, err)
+ }
+ f, err := os.OpenFile(filepath.Join(work, "snapshot.db"+suffix), os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0600)
+ if err != nil {
+ t.Fatal(err)
+ }
+ _, writeErr := f.Write(raw)
+ err = errors.Join(writeErr, f.Chmod(0666), f.Sync(), f.Close())
+ if err != nil {
+ t.Fatal(err)
+ }
+ }
+ // Immutable mode ignores the WAL, proving that the copied DB lacks the row.
+ base, err := sql.Open("sqlite", "file:"+filepath.Join(work, "snapshot.db")+"?immutable=1")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer base.Close()
+ var count int
+ if err = base.QueryRowContext(t.Context(), "SELECT count(*) FROM items").Scan(&count); err != nil || count != 0 {
+ t.Fatal("fixture row is not WAL-only", count, err)
+ }
+}
+
// This hostile replacement for SQLite uses the already-built test binary.
// Only the gated witness installs it, under the shipped unit's restrictions.
func TestDemoClaimSnapshotHostileHelper(t *testing.T) {
@@ -193,7 +245,7 @@ func TestDemoClaimSnapshotRuntimeDevWitness(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- for _, mode := range []string{"isolation", "memory", "duration"} {
+ for _, mode := range []string{"realWorker", "isolation", "memory", "duration"} {
t.Run(mode, func(t *testing.T) {
id, e := demobuild.NewJobID()
if e != nil {
@@ -215,6 +267,11 @@ func TestDemoClaimSnapshotRuntimeDevWitness(t *testing.T) {
if e = p.prepareDisk(ctx, id); e != nil {
t.Fatal(e)
}
+ helper := "TestDemoClaimSnapshotHostileHelper"
+ if mode == "realWorker" {
+ helper = "TestDemoClaimSnapshotRealWorker"
+ prepareSnapshotWorkerWAL(t, filepath.Join(dir, "work"))
+ }
input := snapshotWitnessInput{Mode: mode}
for _, base := range []string{"/data", "/etc/carlos", "/var/lib"} {
path := filepath.Join(base, "snapshot-witness-"+id)
@@ -250,7 +307,7 @@ func TestDemoClaimSnapshotRuntimeDevWitness(t *testing.T) {
ctl(context.Background(), "daemon-reload")
}()
// An empty BindReadOnlyPaths= clears every bind mount, BindPaths too.
- text := "[Service]\nExecStart=\nExecStart=/snapshot-worker -test.run=^TestDemoClaimSnapshotHostileHelper$\nBindReadOnlyPaths=\nBindPaths=" + filepath.Join(dir, "work") + ":/work\nBindReadOnlyPaths=" + filepath.Join(fixture, "worker") + ":/snapshot-worker\nEnvironment=CARLOS_SNAPSHOT_WITNESS_HELPER=1\n"
+ text := "[Service]\nExecStart=\nExecStart=/snapshot-worker -test.run=^" + helper + "$\nBindReadOnlyPaths=\nBindPaths=" + filepath.Join(dir, "work") + ":/work\nBindReadOnlyPaths=" + filepath.Join(fixture, "worker") + ":/snapshot-worker\nEnvironment=CARLOS_SNAPSHOT_WITNESS_HELPER=1\n"
if e = os.WriteFile(filepath.Join(drop, "90-witness.conf"), []byte(text), 0644); e != nil {
t.Fatal(e)
}
@@ -264,6 +321,43 @@ func TestDemoClaimSnapshotRuntimeDevWitness(t *testing.T) {
oldAssert := p.assertUnit
p.assertUnit = func(context.Context, string) error { return nil }
defer func() { p.assertUnit = oldAssert }()
+ if mode == "realWorker" {
+ if e = p.run(ctx, id); e != nil {
+ t.Fatal("real worker failed", e)
+ }
+ // Match exportDemoSnapshot: reap before trusting the result files.
+ if e = p.stop(id); e != nil {
+ t.Fatal("real worker did not stop", e)
+ }
+ source, meta, e := p.result(ctx, id)
+ if e != nil {
+ t.Fatal("real worker result rejected", e)
+ }
+ if e = source.Close(); e != nil {
+ t.Fatal(e)
+ }
+ if meta.Bytes <= 0 || meta.SHA256 == "" {
+ t.Fatal("empty snapshot metadata", meta)
+ }
+ // Read the DB alone as root; the worker must have checkpointed the WAL.
+ db, e := sql.Open("sqlite", "file:"+filepath.Join(dir, "work/snapshot.db")+"?immutable=1")
+ if e != nil {
+ t.Fatal(e)
+ }
+ var value string
+ e = db.QueryRowContext(ctx, "SELECT value FROM items").Scan(&value)
+ e = errors.Join(e, db.Close())
+ if e != nil || value != "committed in WAL" {
+ t.Fatal("committed WAL row missing", value, e)
+ }
+ if e = p.cleanup(id); e != nil {
+ t.Fatal(e)
+ }
+ if _, e = os.Stat(dir); !os.IsNotExist(e) {
+ t.Fatal("scratch survived", e)
+ }
+ return
+ }
runCtx, stop := context.WithTimeout(ctx, democlaim.SnapshotWindow)
defer stop()
watcherDone := make(chan struct{})
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index 808106031..a47c8dbeb 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -108,4 +108,4 @@ plan14-root-reads-agent-start-demo-3.tsv ebeaa693941f5592cd7bc3458effc2a333a8d12
plan14-root-reads-lease-renew-after-pause.tsv ebeaa693941f5592cd7bc3458effc2a333a8d12ba4f192a93d0aa32589048939
plan14-root-reads-demo-api-claim-paths.tsv ebeaa693941f5592cd7bc3458effc2a333a8d12ba4f192a93d0aa32589048939
plan14-root-reads-demo-moved-capability.tsv ebeaa693941f5592cd7bc3458effc2a333a8d12ba4f192a93d0aa32589048939
-plan14-root-reads-demo-snapshot-unit-check.tsv 62613178975daa6640bb46d87f143bf5291e51921e350b6c731438a77daf61f7
+plan14-root-reads-demo-snapshot-unit-check.tsv 1e83ce23d7d1306e3963f802fecf8c914a2624726255e3bc30382104e568adde
diff --git a/internal/provision/testdata/plan14-root-reads-demo-snapshot-unit-check.tsv b/internal/provision/testdata/plan14-root-reads-demo-snapshot-unit-check.tsv
index 2d2acb175..921c08735 100644
--- a/internal/provision/testdata/plan14-root-reads-demo-snapshot-unit-check.tsv
+++ b/internal/provision/testdata/plan14-root-reads-demo-snapshot-unit-check.tsv
@@ -1,5 +1,17 @@
# Census overlay demo-snapshot-unit-check, written by census-propose (#369). census-ruling-demo-snapshot-unit-check, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-demo-snapshot-unit-check.md.
-# 1 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+# 2 body, 1 sites, 2 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+# 3 new dispositions: 0 reads re-frozen at their disposition with the claim, 3 new units frozen accepted-legacy, 0 quiet units retired while they read nothing, 0 other.
+@legacy c3ea54a8e526ae95620099433ac5c537d66e8d4eb04f98af9cf267042725c5ff internal/democlaim/worker.go RunSnapshotWorkerIn legacy accepted-legacy accepted-legacy;rev3=census-ruling-agent-start-demo-3;basis=Open only fixed private helper files and write bounded snapshot metadata; caller-provided live source paths never reach SQLite as root. Census read-site delta: +file:OpenFile.;rev3=census-ruling-demo-snapshot-unit-check;basis=Select OpenWorkerSource for fixed snapshot.db and optional snapshot.db-wal in private /work. Preserve root refusal, result-name reservation, timeout, VerifyUnchanged, checkpoint, integrity check, hashing and failed-result cleanup. No new path input or read is added here. file:OpenFile@415 a8c4558d93231e981f238d55569fd6246418b4046bef10d13afc4628932871ee
@legacy a9f4a77dc7d8520df2ca3bdad419a9036584fb6d321eb698be683b1a583d882d internal/instancectl/demo_snapshot_disk.go demoSnapshotSupervisor.checkUnit legacy accepted-legacy accepted-legacy;rev3=census-ruling-agent-start-demo-3;basis=Inspect the effective fixed systemd snapshot unit and require its declared isolation, resource and execution settings. Census read-site delta: +data-literal.;rev3=census-ruling-demo-snapshot-unit-check;basis=Accept an omitted EnvironmentFiles property as empty, as emitted by systemd 257; continue requesting it and reject every non-empty value. All other property checks remain unchanged. No read added; the existing systemctl query requests the same properties. data-literal@2502 45a6caa9bbf6c9c099a6510bc3b24f86fd991c327a088c921a8d93ad845e965e
+@legacy 26488921960addf575f00f610d4fb8cfbdc42d56738d9460f48b2f4c991deeb6 internal/democlaim/source_linux.go OpenSource legacy accepted-legacy accepted-legacy;rev3=census-ruling-demo-snapshot-unit-check;basis=Retain the existing instancefs directory open and openat2 flags for root and agent callers; move the file syscall from Source.open into this constructor's opener. No fallback is added. Shared validation still rejects unsafe names, nonregular files, multiple links and oversized DB plus WAL. file:Openat2@219 2b8aba2d2ff9a2052320e09c076ae722d7344b1bbddfd552ac3d35e96280ab7d
+@legacy f23cb704cd544f04910b4922ecebb9919eadfda64e27cb0e2718a99164228d3f internal/democlaim/source_linux.go OpenWorkerSource legacy accepted-legacy accepted-legacy;rev3=census-ruling-demo-snapshot-unit-check;basis=Open only the worker's private directory with open O_DIRECTORY|O_NOFOLLOW|O_CLOEXEC, then use the worker file opener and shared Source checks. The private command supplies /work; no root or agent caller switches to this constructor. New direct directory read replaces the worker's blocked openat2 path. file:Open@139 ef3b5ffd251d71ba3a3aa4ad1a4d0c771124bd4df39cbec96f03bbc5d4330c2d
+@legacy 3db7d78561424d3239eac16f31df2d7be45be4c0fa9a2193ce7b579c4dcb9758 internal/democlaim/source_linux.go openWorkerFile legacy accepted-legacy accepted-legacy;rev3=census-ruling-demo-snapshot-unit-check;basis=Open a single component relative to the held private worker directory with openat O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOFOLLOW. Refuse empty, dot, dot-dot, slash, backslash and NUL names before the syscall. New direct file read is used only by OpenWorkerSource, including VerifyUnchanged. file:Openat@180 584d2fddd1fa75eb35a41538f6121ca6bfaf849b0777736bcc04b5494d192cf6
+@legacy 3511d07846656f365bf46f07998e6ad6b3d513fbcd18c0ccb7d61e1a80efc06b internal/democlaim/source_linux.go Source.open legacy accepted-legacy accepted-legacy;rev3=census-ruling-agent-start-demo-3;basis=Open DB and WAL beneath the retained source directory with openat2 no-follow/beneath constraints and enforce regular-file bounds. Census read-site delta: +file:Fstat, +file:Openat2.;rev3=census-ruling-demo-snapshot-unit-check;basis=Route the file open through the constructor-selected opener; retain identical Fstat, regular-file, nlink==1 and nonnegative-size checks. Root and agent still select openat2; the private worker selects openat. VerifyUnchanged uses this same seam with its existing inode, timestamps, size and link checks. file:Fstat@186 63cb063611680dbced88283992e996102313e6a9fb138c29e9092946781e86ec
+internal/democlaim/worker.go RunSnapshotWorkerIn legacy accepted-legacy accepted-legacy;rev3=census-ruling-agent-start-demo-3;basis=Open only fixed private helper files and write bounded snapshot metadata; caller-provided live source paths never reach SQLite as root. Census read-site delta: +file:OpenFile.;rev3=census-ruling-demo-snapshot-unit-check;basis=Select OpenWorkerSource for fixed snapshot.db and optional snapshot.db-wal in private /work. Preserve root refusal, result-name reservation, timeout, VerifyUnchanged, checkpoint, integrity check, hashing and failed-result cleanup. No new path input or read is added here. file:OpenFile@415 a8c4558d93231e981f238d55569fd6246418b4046bef10d13afc4628932871ee
internal/instancectl/demo_snapshot_disk.go demoSnapshotSupervisor.checkUnit legacy accepted-legacy accepted-legacy;rev3=census-ruling-agent-start-demo-3;basis=Inspect the effective fixed systemd snapshot unit and require its declared isolation, resource and execution settings. Census read-site delta: +data-literal.;rev3=census-ruling-demo-snapshot-unit-check;basis=Accept an omitted EnvironmentFiles property as empty, as emitted by systemd 257; continue requesting it and reject every non-empty value. All other property checks remain unchanged. No read added; the existing systemctl query requests the same properties. data-literal@2502 45a6caa9bbf6c9c099a6510bc3b24f86fd991c327a088c921a8d93ad845e965e
+internal/democlaim/source_linux.go OpenSource legacy accepted-legacy accepted-legacy;rev3=census-ruling-demo-snapshot-unit-check;basis=Retain the existing instancefs directory open and openat2 flags for root and agent callers; move the file syscall from Source.open into this constructor's opener. No fallback is added. Shared validation still rejects unsafe names, nonregular files, multiple links and oversized DB plus WAL. file:Openat2@219 2b8aba2d2ff9a2052320e09c076ae722d7344b1bbddfd552ac3d35e96280ab7d
+internal/democlaim/source_linux.go OpenWorkerSource legacy accepted-legacy accepted-legacy;rev3=census-ruling-demo-snapshot-unit-check;basis=Open only the worker's private directory with open O_DIRECTORY|O_NOFOLLOW|O_CLOEXEC, then use the worker file opener and shared Source checks. The private command supplies /work; no root or agent caller switches to this constructor. New direct directory read replaces the worker's blocked openat2 path. file:Open@139 ef3b5ffd251d71ba3a3aa4ad1a4d0c771124bd4df39cbec96f03bbc5d4330c2d
+internal/democlaim/source_linux.go openWorkerFile legacy accepted-legacy accepted-legacy;rev3=census-ruling-demo-snapshot-unit-check;basis=Open a single component relative to the held private worker directory with openat O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOFOLLOW. Refuse empty, dot, dot-dot, slash, backslash and NUL names before the syscall. New direct file read is used only by OpenWorkerSource, including VerifyUnchanged. file:Openat@180 584d2fddd1fa75eb35a41538f6121ca6bfaf849b0777736bcc04b5494d192cf6
+internal/democlaim/source_linux.go Source.open legacy accepted-legacy accepted-legacy;rev3=census-ruling-agent-start-demo-3;basis=Open DB and WAL beneath the retained source directory with openat2 no-follow/beneath constraints and enforce regular-file bounds. Census read-site delta: +file:Fstat, +file:Openat2.;rev3=census-ruling-demo-snapshot-unit-check;basis=Route the file open through the constructor-selected opener; retain identical Fstat, regular-file, nlink==1 and nonnegative-size checks. Root and agent still select openat2; the private worker selects openat. VerifyUnchanged uses this same seam with its existing inode, timestamps, size and link checks. file:Fstat@186 63cb063611680dbced88283992e996102313e6a9fb138c29e9092946781e86ec
+@coverage internal/democlaim 803d33a415e0f4b765bfd1d8cbc8e2206b2d99d4bd4a0a4a04f6c86ca33c8e63
@coverage internal/instancectl 0a26ffced872e6261a077002c7fb869ed636a468e7335b57f363adc5115abf38