journal-migrate: the quiesce scan skips the migration's own children
journal-migrate holds the registry through a child it runs as the service user (openServiceRegistry), and the quiesce scan refused any service-uid process, so the migration refused itself every time with a misleading typed-journal error (platform-d8's harness at G7). scanQuiesceProcs skips the migration's direct children and names any other service-user process it refuses; procParent reads the ppid from /proc stat. Census rows added under the same ruling.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+100
−9
internal/host/claimjournal_migration_linux.go+51 −8internal/host/claimjournal_quiesce_linux_test.go+44 −0internal/provision/testdata/plan14-root-reads-claim-rootaws-sentinel.tsv+5 −1
CI passed — run details
diff --git a/internal/host/claimjournal_migration_linux.go b/internal/host/claimjournal_migration_linux.go| index f2d8e3ee1..c6c6979a8 100644 |
| --- a/internal/host/claimjournal_migration_linux.go |
| +++ b/internal/host/claimjournal_migration_linux.go |
| @@ -300,25 +300,68 @@ func quiesceLegacyClaimJournals(ctx context.Context) (func(), error) { |
| release() |
| return nil, err |
| } |
| - entries, err := os.ReadDir("/proc") |
| - if err != nil { |
| + if err = scanQuiesceProcs("/proc", uid, os.Getpid()); err != nil { |
| release() |
| return nil, err |
| } |
| + return release, nil |
| +} |
| + |
| +// scanQuiesceProcs refuses while any process runs as the service uid, except |
| +// this migration's own direct children: journal-migrate holds the registry |
| +// through a child it runs as the service user (openServiceRegistry), and |
| +// counting that child would make the migration refuse itself every time. The |
| +// refusal names the process it found. |
| +func scanQuiesceProcs(procDir string, uid, self int) error { |
| + entries, err := os.ReadDir(procDir) |
| + if err != nil { |
| + return err |
| + } |
| for _, entry := range entries { |
| - if _, err := strconv.Atoi(entry.Name()); err != nil { |
| + pid, err := strconv.Atoi(entry.Name()) |
| + if err != nil { |
| continue |
| } |
| var st unix.Stat_t |
| - if err = unix.Stat("/proc/"+entry.Name(), &st); errors.Is(err, unix.ENOENT) { |
| + if err = unix.Stat(filepath.Join(procDir, entry.Name()), &st); errors.Is(err, unix.ENOENT) { |
| continue |
| } |
| - if err != nil || int(st.Uid) == uid { |
| - release() |
| - return nil, errors.Join(err, hostbox.ErrTypedJournal) |
| + if err != nil { |
| + return errors.Join(err, hostbox.ErrTypedJournal) |
| + } |
| + if int(st.Uid) != uid { |
| + continue |
| } |
| + ppid, perr := procParent(filepath.Join(procDir, entry.Name(), "stat")) |
| + if errors.Is(perr, os.ErrNotExist) { |
| + continue |
| + } |
| + if perr == nil && ppid == self { |
| + continue |
| + } |
| + return errors.Join(errors.New("service-user process "+strconv.Itoa(pid)+" is still running"), perr, hostbox.ErrTypedJournal) |
| } |
| - return release, nil |
| + return nil |
| +} |
| + |
| +// procParent reads the parent pid from a /proc/<pid>/stat file. The command |
| +// name is parenthesised and may contain spaces, so the fields after the last |
| +// ')' are read: state, then ppid. |
| +func procParent(statPath string) (int, error) { |
| + raw, err := os.ReadFile(statPath) |
| + if err != nil { |
| + return 0, err |
| + } |
| + s := string(raw) |
| + i := strings.LastIndexByte(s, ')') |
| + if i < 0 { |
| + return 0, errors.New("malformed " + statPath) |
| + } |
| + fields := strings.Fields(s[i+1:]) |
| + if len(fields) < 2 { |
| + return 0, errors.New("malformed " + statPath) |
| + } |
| + return strconv.Atoi(fields[1]) |
| } |
| func recoverLegacyClaimEdgeMask(ctx context.Context) error { |
diff --git a/internal/host/claimjournal_quiesce_linux_test.go b/internal/host/claimjournal_quiesce_linux_test.go| new file mode 100644 |
| index 000000000..b5f57a35b |
| --- /dev/null |
| +++ b/internal/host/claimjournal_quiesce_linux_test.go |
| @@ -0,0 +1,44 @@ |
| +//go:build linux |
| + |
| +package host |
| + |
| +import ( |
| + "errors" |
| + "os" |
| + "path/filepath" |
| + "strconv" |
| + "strings" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/hostbox" |
| +) |
| + |
| +// journal-migrate holds the registry through a child it runs as the service |
| +// user. The quiesce scan must not count that child (or any other direct |
| +// child of the migration) as a running service process, or the migration |
| +// refuses itself every time; any other service-user process still refuses. |
| +func TestQuiesceScanSkipsOwnChildren(t *testing.T) { |
| + uid := os.Getuid() |
| + self := 4242 |
| + proc := t.TempDir() |
| + mk := func(pid, ppid int) { |
| + dir := filepath.Join(proc, strconv.Itoa(pid)) |
| + if err := os.Mkdir(dir, 0o755); err != nil { |
| + t.Fatal(err) |
| + } |
| + // /proc/<pid>/stat: "pid (comm) state ppid ..." |
| + stat := strconv.Itoa(pid) + " (carlos x) S " + strconv.Itoa(ppid) + " 1 1 0\n" |
| + if err := os.WriteFile(filepath.Join(dir, "stat"), []byte(stat), 0o644); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + mk(5000, self) // the registry child |
| + if err := scanQuiesceProcs(proc, uid, self); err != nil { |
| + t.Fatalf("own child refused: %v", err) |
| + } |
| + mk(5001, 1) // any other service-user process |
| + err := scanQuiesceProcs(proc, uid, self) |
| + if !errors.Is(err, hostbox.ErrTypedJournal) || !strings.Contains(err.Error(), "5001") { |
| + t.Fatalf("foreign process not refused by pid: %v", err) |
| + } |
| +} |
diff --git a/internal/provision/testdata/plan14-root-reads-claim-rootaws-sentinel.tsv b/internal/provision/testdata/plan14-root-reads-claim-rootaws-sentinel.tsv| index e2be63b40..eec98a3c7 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-claim-rootaws-sentinel.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-claim-rootaws-sentinel.tsv |
| @@ -1,9 +1,13 @@ |
| # Census overlay claim-rootaws-sentinel (a scrubbed root parent's own disabled shared-file sentinels are not an override in a root child, so the child's scrub stays silent; found by platform-d8's deployment harness at G4: a guard-armed box refused every router update because the candidate's version printed the ALERT into the guarded updater's combined output), loaded LAST, after claim-empty-cohort-fix2. RULED (platform-1e, 2026-10-20): accepted. Envelope only: ScrubEnvironment has no classified root-read unit; no row changes and the seal stands. |
| @coverage internal/rootaws ad641674b84d17a9f6a7b1acb4cf88b68cc2a882812a28c8f622d4fd9616b470 |
| # Also (CI fix, same ruling): hostInstallationPaths names the raw instance directory through layout.RawInstanceDir, a new exported accessor beside layout's rawInstanceDir, so the raw-directory guard holds; internal/host and internal/layout envelopes re-pinned here, and hostInstallationPaths's 9B8 digest re-pinned at its class (key-site, lit:instances). |
| -@coverage internal/host 7d6b2153dc1775c1221b0aabe191343d1c5db2e82e7f84b561d0dc3664ade971 |
| @coverage internal/layout cbb195397ab6f0018704e745b30e57df56d49289de87a1132d2f7ba426cf006b |
| # Also (harness G4, parent side, same ruling): hostfloor's guarded run returns the image's stdout only through runImage (new), so stderr progress or an alert cannot corrupt the version or plan an updater parses; Disk.Run's exec site moved into runImage at its class, and Disk.Run's row is retired. |
| @coverage internal/hostfloor ba748a60d9bd7a55d2d3c4a2fe17fc619c23aa2e813a88b164dff47e04a41a1f |
| @remove internal/hostfloor/image_linux.go Disk.Run |
| internal/hostfloor/image_linux.go runImage authority F,J4 rev3=census-ruling-claim-rootaws-sentinel;identity=root (the system updater and root's apply through hostfloor.Disk.Run on a guard-armed box);basis=root-input: the exec of the verified, protected image Disk.Run opened and checked, moved unchanged from Disk.Run; stdout is returned and stderr kept only for the error file:CommandContext@89 fbf4a73db9e71f8deefa8d56ece729f489f84689d064e2475f5551a823d6fa59 |
| +# Also (harness G7, same ruling): journal-migrate's quiesce scan moved into scanQuiesceProcs (new), which skips the migration's own direct children (its service-user registry child) and names any other service-user process it refuses; procParent (new) reads a /proc stat's ppid. Classes carried from quiesceLegacyClaimJournals. |
| +@coverage internal/host 514745d2c20f8a38953bdfc8d22cb5f8d4001681baeacdc73f313ed9dbfa3c86 |
| +internal/host/claimjournal_migration_linux.go quiesceLegacyClaimJournals authority C,G,J4 root-input;kept=C,G;scope=protected-decision-only;rev3=census-ruling-claim-rootaws-sentinel;basis=the /proc scan moved into scanQuiesceProcs; masks and stops as before file:ReadFile@226,file:ReadFile@327 cbf95218a0314ac8cc50f8957e3e5d142e2bc7f8c76aac0fd9a36eac5e37f013 |
| +internal/host/claimjournal_migration_linux.go scanQuiesceProcs authority C,G,J4 root-input;kept=C,G;scope=protected-decision-only;rev3=census-ruling-claim-rootaws-sentinel;identity=carlos system journal-migrate, offline operator CLI, uid 0;basis=lists /proc and stats each pid; refuses any service-uid process except the migration's own direct children (ppid from procParent); fails closed on an unreadable stat file:ReadDir@78,file:Stat@271 10a651585d64dc7138549bdc586d6a1597c6df77afba5be3db180488d9fca16e |
| +internal/host/claimjournal_migration_linux.go procParent authority C,G,J4 root-input;kept=C,G;scope=protected-decision-only;rev3=census-ruling-claim-rootaws-sentinel;identity=the same, uid 0;basis=reads one /proc/<pid>/stat and parses the ppid after the last ')'; a malformed file is an error the scan refuses on file:ReadFile@61 ad2c1fc49ec52ca978aeef9b33c015fd125b37df56586778bbf477af4720f130 |