carlos / platform Public

moves floor: root keeps its own copy; an emptied /data line fails closed

Hunt H2-M1. The system units picked carlos.prev whenever
/data/.moves/floor.min-release was empty or gone, and /data is writable
by anything running as the service account, a flat tenant included.
Now floor.json still present counts as armed, so an emptied line fails
the gate. Root also keeps /opt/carlos/moves-floor.min-release, the
highest floor judgePrev has seen, raised and never lowered. The units
require the verdict to name it, and every non-census root floor check
reads the higher of it and floor.json. Witnesses: hunt_H2_M1_test.go
(stubs now hand the gate verb to the real gate), movesfloor_rootcopy
tests and new rows in TestSystemUnitsSelectPrevByTheFloor.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 2e93e7def10db1354afebccb844b8f25825e788c parent d2d3de1
11 files changed, +386 −36
  • internal/host/execsandboxfloor_test.go +4 −3
  • internal/host/genfloor_test.go +1 −1
  • internal/host/host_test.go +38 −13
  • internal/host/hunt_H2_M1_test.go +120 −0
  • internal/host/movesfloor.go +86 −13
  • internal/host/movesfloor_rootcopy_test.go +106 −0
  • internal/host/proxyfeature_test.go +1 −1
  • internal/host/rootmovesfloor_source.go +2 −1
  • internal/host/units/carlos-system-recover.service +10 −2
  • internal/host/units/carlos-system-update.service +10 −2
  • internal/moves/floor.go +8 −0
diff --git a/internal/host/execsandboxfloor_test.go b/internal/host/execsandboxfloor_test.go
index c77813108..c8cc4f807 100644
--- a/internal/host/execsandboxfloor_test.go
+++ b/internal/host/execsandboxfloor_test.go
@@ -152,8 +152,9 @@ func TestExecSandboxRecoveryUnit(t *testing.T) {
// Preserve the old expression byte for byte except for the one gate
// and, after it, the PROXY protocol gate (TestRecoverUnitGatesPrev) and
// the storage generations floor gate
- // (TestRecoverUnitGatesPrevOnGenerations).
- original := `if [ -x /opt/carlos/system/guard/carlos ] && { [ -e /var/lib/carlos-claims/authority/exec/census.json ] || [ -L /var/lib/carlos-claims/authority/exec/census.json ] || [ -e /opt/carlos/system/guard/moves ] || [ -L /opt/carlos/system/guard/moves ]; }; then exec /opt/carlos/system/guard/carlos system guard-exec recover; fi; if [ -f /opt/carlos/system/router/journal.json ] && [ -x /opt/carlos/carlos.prev ] && [ ! -L /data/.moves/floor.min-release ] && { [ ! -e /data/.moves/floor.min-release ] || [ -f /data/.moves/floor.min-release ]; } && { ! [ -s /data/.moves/floor.min-release ] || /opt/carlos/carlos.prev system floor-allows-prev /data/.moves/floor.min-release /opt/carlos/carlos.prev.allowed; } && [ ! -L /data/.moves/seeds-floor.min-release ] && { [ ! -e /data/.moves/seeds-floor.min-release ] || [ -f /data/.moves/seeds-floor.min-release ]; } && { ! [ -s /data/.moves/seeds-floor.min-release ] || /opt/carlos/carlos.prev system floor-allows-prev /data/.moves/seeds-floor.min-release /opt/carlos/carlos.prev.seeds-allowed; }; then exec /opt/carlos/carlos.prev system apply --recover; fi; exec /opt/carlos/carlos system apply --recover`
+ // (TestRecoverUnitGatesPrevOnGenerations). The moves floor clause reads
+ // floor.json and root's own copy of the floor too (hunt H2-M1).
+ original := `if [ -x /opt/carlos/system/guard/carlos ] && { [ -e /var/lib/carlos-claims/authority/exec/census.json ] || [ -L /var/lib/carlos-claims/authority/exec/census.json ] || [ -e /opt/carlos/system/guard/moves ] || [ -L /opt/carlos/system/guard/moves ]; }; then exec /opt/carlos/system/guard/carlos system guard-exec recover; fi; if [ -f /opt/carlos/system/router/journal.json ] && [ -x /opt/carlos/carlos.prev ] && [ ! -L /data/.moves/floor.min-release ] && { [ ! -e /data/.moves/floor.min-release ] || [ -f /data/.moves/floor.min-release ]; } && { { ! [ -s /data/.moves/floor.min-release ] && ! [ -e /data/.moves/floor.json ] && ! [ -L /data/.moves/floor.json ]; } || /opt/carlos/carlos.prev system floor-allows-prev /data/.moves/floor.min-release /opt/carlos/carlos.prev.allowed; } && { ! [ -e /opt/carlos/moves-floor.min-release ] || /opt/carlos/carlos.prev system floor-allows-prev /opt/carlos/moves-floor.min-release /opt/carlos/carlos.prev.allowed; } && [ ! -L /data/.moves/seeds-floor.min-release ] && { [ ! -e /data/.moves/seeds-floor.min-release ] || [ -f /data/.moves/seeds-floor.min-release ]; } && { ! [ -s /data/.moves/seeds-floor.min-release ] || /opt/carlos/carlos.prev system floor-allows-prev /data/.moves/seeds-floor.min-release /opt/carlos/carlos.prev.seeds-allowed; }; then exec /opt/carlos/carlos.prev system apply --recover; fi; exec /opt/carlos/carlos system apply --recover`
if strings.Replace(strings.Replace(command, gate+proxyRecoveryGate+generationsRecoveryGate, gate, 1), gate, "", 1) != original {
t.Fatal("recovery changed outside gate")
}
@@ -169,7 +170,7 @@ func TestExecSandboxRecoveryUnit(t *testing.T) {
// Execute the real expression with only fixed box paths relocated.
cmd := strings.ReplaceAll(command, "/opt/carlos/carlos.prev", prev)
cmd = strings.ReplaceAll(cmd, "/opt/carlos/carlos", current)
- for _, p := range []string{"/opt/carlos/system/guard/carlos", "/var/lib/carlos-claims/authority/exec/census.json", "/opt/carlos/system/guard/moves", "/data/.moves/floor.min-release", "/data/.moves/seeds-floor.min-release"} {
+ for _, p := range []string{"/opt/carlos/system/guard/carlos", "/var/lib/carlos-claims/authority/exec/census.json", "/opt/carlos/system/guard/moves", "/data/.moves/floor.min-release", "/data/.moves/floor.json", "/opt/carlos/moves-floor.min-release", "/data/.moves/seeds-floor.min-release"} {
cmd = strings.ReplaceAll(cmd, p, filepath.Join(root, "absent", filepath.Base(p)))
}
journal := filepath.Join(root, "journal")
diff --git a/internal/host/genfloor_test.go b/internal/host/genfloor_test.go
index 40f10de77..7f1628ba4 100644
--- a/internal/host/genfloor_test.go
+++ b/internal/host/genfloor_test.go
@@ -466,7 +466,7 @@ func TestRecoverUnitGatesPrevOnGenerations(t *testing.T) {
os.WriteFile(prev, []byte("#!/bin/sh\ncase \"$1 $2\" in\n'system apply') echo prev > '"+receipt+"';;\n*) exit 0;;\nesac\n"), 0o755)
cmd := strings.ReplaceAll(command, "/opt/carlos/carlos.prev", prev)
cmd = strings.ReplaceAll(cmd, "/opt/carlos/carlos", current)
- for _, p := range []string{"/opt/carlos/system/guard/carlos", "/var/lib/carlos-claims/authority/exec/census.json", "/opt/carlos/system/guard/moves", "/data/.moves/floor.min-release", "/data/.moves/seeds-floor.min-release"} {
+ for _, p := range []string{"/opt/carlos/system/guard/carlos", "/var/lib/carlos-claims/authority/exec/census.json", "/opt/carlos/system/guard/moves", "/data/.moves/floor.min-release", "/data/.moves/floor.json", "/opt/carlos/moves-floor.min-release", "/data/.moves/seeds-floor.min-release"} {
cmd = strings.ReplaceAll(cmd, p, filepath.Join(root, "absent", filepath.Base(p)))
}
journal := filepath.Join(root, "journal")
diff --git a/internal/host/host_test.go b/internal/host/host_test.go
index 5b4b90dd3..575708ebb 100644
--- a/internal/host/host_test.go
+++ b/internal/host/host_test.go
@@ -1957,28 +1957,43 @@ func TestSystemUnitsSelectPrevByTheFloor(t *testing.T) {
want string
gate string // which binary ran the floor gate, "" for none
prevNoVerb bool // carlos.prev predates the gate and rejects its verb
+ json bool // the data dir's floor.json is there
+ rootCopy string // root's own copy of the floor, "" for none
}{
- {"no journal", false, "", "", "", false, "carlos", "", false},
- {"no floor", true, "", "", "", false, "carlos.prev", "", false},
- {"no floor, no prev", true, "", "", "", true, "carlos", "", false},
- {"floor and a verdict naming it", true, "v0.30.0\n", "v0.30.0\n", "", false, "carlos.prev", "carlos.prev", false},
- {"a verdict for an older floor", true, "v0.30.0\n", "v0.29.0\n", "", false, "carlos", "carlos.prev", false},
- {"floor and no verdict", true, "v0.30.0\n", "", "", false, "carlos", "carlos.prev", false},
- {"no journal, armed and allowed", false, "v0.30.0\n", "v0.30.0\n", "", false, "carlos", "", false},
- {"armed, no prev", true, "v0.30.0\n", "v0.30.0\n", "", true, "carlos", "", false},
+ {"no journal", false, "", "", "", false, "carlos", "", false, false, ""},
+ {"no floor", true, "", "", "", false, "carlos.prev", "", false, false, ""},
+ {"no floor, no prev", true, "", "", "", true, "carlos", "", false, false, ""},
+ {"floor and a verdict naming it", true, "v0.30.0\n", "v0.30.0\n", "", false, "carlos.prev", "carlos.prev", false, false, ""},
+ {"a verdict for an older floor", true, "v0.30.0\n", "v0.29.0\n", "", false, "carlos", "carlos.prev", false, false, ""},
+ {"floor and no verdict", true, "v0.30.0\n", "", "", false, "carlos", "carlos.prev", false, false, ""},
+ {"no journal, armed and allowed", false, "v0.30.0\n", "v0.30.0\n", "", false, "carlos", "", false, false, ""},
+ {"armed, no prev", true, "v0.30.0\n", "v0.30.0\n", "", true, "carlos", "", false, false, ""},
// The agent owns /data: anything but a regular file at the
// floor path is refused before the gate runs (#267), and the
// gate refuses one swapped in after that test (it never
// follows a symlink or opens a FIFO for a blocking read).
// [ -s ] is false for a dangling symlink and a FIFO, so
// without the shell's test both would read as "no floor".
- {"symlink floor with matching verdict", true, "v0.30.0\n", "v0.30.0\n", "symlink", false, "carlos", "", false},
- {"dangling symlink floor", true, "", "", "dangling", false, "carlos", "", false},
- {"directory floor", true, "", "", "directory", false, "carlos", "", false},
- {"fifo floor", true, "", "v0.30.0\n", "fifo", false, "carlos", "", false},
+ {"symlink floor with matching verdict", true, "v0.30.0\n", "v0.30.0\n", "symlink", false, "carlos", "", false, false, ""},
+ {"dangling symlink floor", true, "", "", "dangling", false, "carlos", "", false, false, ""},
+ {"directory floor", true, "", "", "directory", false, "carlos", "", false, false, ""},
+ {"fifo floor", true, "", "v0.30.0\n", "fifo", false, "carlos", "", false, false, ""},
// A carlos.prev older than the gate answers its verb with
// an unknown-verb exit: a mismatch, so carlos runs.
- {"a carlos.prev without the gate verb", true, "v0.30.0\n", "v0.30.0\n", "", false, "carlos", "carlos.prev", true},
+ {"a carlos.prev without the gate verb", true, "v0.30.0\n", "v0.30.0\n", "", false, "carlos", "carlos.prev", true, false, ""},
+ // Hunt H2-M1: the data dir is writable by anything running as
+ // the service account, a flat tenant among them. floor.json
+ // still there with the line emptied or removed is an armed
+ // floor whose line cannot be read: carlos runs.
+ {"floor.json there, line emptied", true, "", "v0.30.0\n", "empty", false, "carlos", "carlos.prev", false, true, ""},
+ {"floor.json there, line removed", true, "", "v0.30.0\n", "", false, "carlos", "carlos.prev", false, true, ""},
+ // Root's own copy of the floor, which only root writes: with
+ // both data dir files gone carlos.prev still runs only when
+ // its verdict names root's copy.
+ {"data dir floor gone, root copy named by the verdict", true, "", "v0.30.0\n", "", false, "carlos.prev", "carlos.prev", false, false, "v0.30.0\n"},
+ {"data dir floor gone, root copy, no verdict", true, "", "", "", false, "carlos", "carlos.prev", false, false, "v0.30.0\n"},
+ {"data dir floor lowered below root copy", true, "v0.29.0\n", "v0.29.0\n", "", false, "carlos", "carlos.prev\ncarlos.prev", false, true, "v0.30.0\n"},
+ {"data dir floor and root copy agree", true, "v0.30.0\n", "v0.30.0\n", "", false, "carlos.prev", "carlos.prev\ncarlos.prev", false, true, "v0.30.0\n"},
} {
t.Run(tc.name, func(t *testing.T) {
root := t.TempDir()
@@ -2030,6 +2045,10 @@ func TestSystemUnitsSelectPrevByTheFloor(t *testing.T) {
if out, err := exec.Command("mkfifo", floorPath).CombinedOutput(); err != nil {
t.Fatalf("mkfifo: %v: %s", err, out)
}
+ case "empty":
+ if err := os.WriteFile(floorPath, nil, 0o644); err != nil {
+ t.Fatal(err)
+ }
default:
if tc.floor != "" {
if err := os.WriteFile(floorPath, []byte(tc.floor), 0o644); err != nil {
@@ -2040,6 +2059,12 @@ func TestSystemUnitsSelectPrevByTheFloor(t *testing.T) {
if tc.verdict != "" {
os.WriteFile(filepath.Join(opt, moves.PrevAllowedFile), []byte(tc.verdict), 0o644)
}
+ if tc.json {
+ os.WriteFile(filepath.Join(data, moves.FloorFile), []byte(`{"min":1,"min_release":"v0.30.0"}`+"\n"), 0o644)
+ }
+ if tc.rootCopy != "" {
+ os.WriteFile(filepath.Join(opt, moves.RootFloorMinReleaseFile), []byte(tc.rootCopy), 0o644)
+ }
script := strings.ReplaceAll(body, "/data/", data+"/")
script = strings.ReplaceAll(script, "/opt/carlos/", opt+"/")
cmd := exec.Command("/bin/sh", "-c", script)
diff --git a/internal/host/hunt_H2_M1_test.go b/internal/host/hunt_H2_M1_test.go
new file mode 100644
index 000000000..eb28edb56
--- /dev/null
+++ b/internal/host/hunt_H2_M1_test.go
@@ -0,0 +1,120 @@
+package host
+
+import (
+ "os"
+ "os/exec"
+ "path/filepath"
+ "strings"
+ "testing"
+
+ "github.com/carlosframework/platform/internal/moves"
+)
+
+// Hunt H2-M1 (verifier: fable). The carlos-system-update.service ExecStart
+// shell selects carlos.prev when a router journal is open and the moves
+// floor line /data/.moves/floor.min-release is absent or empty: the
+// `! [ -s floor ]` arm short-circuits the floor-allows-prev gate. The floor
+// files live under /data/.moves, which openMovesDir chowns to the service
+// user (movesfloor_linux.go:65, :279) — the same uid (carlos) that any
+// flat-tier workload runs as — so a same-uid process can truncate them.
+//
+// This test drives the production ExecStart line verbatim (read from the
+// embedded unit) with a floor that was armed (floor.json names a release)
+// and whose floor.min-release line an owner then emptied, and asserts the
+// SECURE outcome: the current binary (carlos) runs, since its own Go floor
+// check is the backstop. On current code the empty line reads as "no floor"
+// and carlos.prev runs, so the test fails — confirming the lever.
+//
+// NOTE: this behaviour is the design-acknowledged moves-floor residual
+// (movesfloor.go: "What this is not: a defence against a compromised agent.
+// The agent owns /data and can remove the floor files there."). The same
+// shell outcome is already pinned, as intended, by host_test.go's "no
+// floor" case. The finding's novelty is only that the flat tier runs
+// UNTRUSTED code as that same uid — the #370 shared-/data root cause — not
+// a code defect in the shell.
+func TestHunt_H2_M1_EmptiedFloorLineForcesPrev(t *testing.T) {
+ line := systemUpdateExecStartLine(t)
+ body, ok := strings.CutPrefix(line, "ExecStart=/bin/sh -c '")
+ body2, ok2 := strings.CutSuffix(body, "'")
+ if !ok || !ok2 {
+ t.Fatalf("ExecStart is not one quoted sh -c body: %s", line)
+ }
+
+ root := t.TempDir()
+ opt, data := filepath.Join(root, "opt"), filepath.Join(root, "data")
+ ran := filepath.Join(root, "ran")
+ if err := os.MkdirAll(filepath.Join(opt, "system", "router"), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.MkdirAll(filepath.Join(data, ".moves"), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ // Minimal carlos / carlos.prev stubs that record which one ran. The
+ // floor gate verb is handed to the real Go gate (this test binary as
+ // TestFloorGateHelperProcess, as TestSystemUnitsSelectPrevByTheFloor
+ // does), so a shell that asks it gets the production answer rather
+ // than a stub's yes. (Setup adapted 2026-11-30: the original stubs
+ // answered every verb by recording a run, on the premise that the gate
+ // is never reached.)
+ self, err := os.Executable()
+ if err != nil {
+ t.Fatal(err)
+ }
+ for _, name := range []string{"carlos", "carlos.prev"} {
+ sh := "#!/bin/sh\n" +
+ "if [ \"$1\" = system ] && [ \"$2\" = floor-allows-prev ]; then\n" +
+ " shift 2\n" +
+ " exec " + self + " -test.run='^TestFloorGateHelperProcess$' -- \"$@\"\n" +
+ "fi\n" +
+ "echo " + name + " > " + ran + "\n"
+ if err := os.WriteFile(filepath.Join(opt, name), []byte(sh), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ }
+ // A router journal is open (a prior apply was cut off): the precondition
+ // for the prev branch.
+ if err := os.WriteFile(filepath.Join(opt, "system", "router", "journal.json"), []byte("{}"), 0o600); err != nil {
+ t.Fatal(err)
+ }
+ // The floor was armed — floor.json still names a release — but its
+ // one-line floor.min-release, which the units read, has been emptied by
+ // a same-uid process. (An unlink would be identical: `! -e` is true.)
+ if err := os.WriteFile(filepath.Join(data, ".moves", "floor.json"), []byte(`{"min":1,"min_release":"v0.30.0"}`), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(filepath.Join(data, moves.FloorMinReleaseFile), nil, 0o644); err != nil {
+ t.Fatal(err)
+ }
+
+ script := strings.ReplaceAll(body2, "/data/", data+"/")
+ script = strings.ReplaceAll(script, "/opt/carlos/", opt+"/")
+ cmd := exec.Command("/bin/sh", "-c", script)
+ cmd.Env = append(os.Environ(), floorGateHelperEnv+"=1")
+ if out, err := cmd.CombinedOutput(); err != nil {
+ t.Fatalf("%v: %s", err, out)
+ }
+ got, _ := os.ReadFile(ran)
+ if g := strings.TrimSpace(string(got)); g != "carlos" {
+ t.Errorf("with the floor armed but floor.min-release emptied, %s ran; want carlos (the current binary, whose own Go check backstops the floor). The empty line short-circuits the floor-allows-prev gate and selects carlos.prev", g)
+ }
+}
+
+// systemUpdateExecStartLine returns the single ExecStart= line from the
+// embedded carlos-system-update.service, the production unit.
+func systemUpdateExecStartLine(t *testing.T) string {
+ t.Helper()
+ b, err := unitsFS.ReadFile("units/carlos-system-update.service")
+ if err != nil {
+ t.Fatal(err)
+ }
+ var line string
+ for _, l := range strings.Split(string(b), "\n") {
+ if strings.HasPrefix(l, "ExecStart=") {
+ line = l
+ }
+ }
+ if line == "" {
+ t.Fatal("no ExecStart line in carlos-system-update.service")
+ }
+ return line
+}
diff --git a/internal/host/movesfloor.go b/internal/host/movesfloor.go
index 16cd63c57..929846368 100644
--- a/internal/host/movesfloor.go
+++ b/internal/host/movesfloor.go
@@ -44,6 +44,11 @@ import (
// was judged at or above, written only while no registry row is held by
// an operation (a .prev is a downgrade by definition). judgePrev is the
// one judge, run by root at every apply and every adopt pass.
+// - <optDir>/moves-floor.min-release, root's own copy of the highest floor
+// judgePrev has seen (hunt H2-M1), one line in the same bytes as
+// floor.min-release. judgePrev raises it from the floor it reads and
+// never lowers it; every root floor check outside a census reads the
+// higher of it and floor.json (effectiveLocalFloor).
//
// The two system units choose carlos.prev for a recovery only when the
// floor line is absent, or equal byte for byte to the verdict. The version
@@ -52,9 +57,13 @@ import (
// gate (movesfloorgate.go), which never follows a symlink or waits on a
// FIFO the agent planted.
//
-// What this is not: a defence against a compromised agent. The agent owns
-// /data and can remove the floor files there. The floor protects the
-// protocol against old builds and honest mistakes, which is what §11 asks.
+// What this is not: a defence against a compromised agent before root has
+// seen the floor. The agent owns /data and can remove the floor files
+// there, and so can a flat tenant, which runs as the agent's uid. Once root
+// has judged against a floor its own copy holds it: removing or lowering
+// the files in /data then neither lowers what root enforces nor lets the
+// units pick a carlos.prev below it. The floor protects the protocol
+// against old builds and honest mistakes, which is what §11 asks.
const movesFloorMaxBytes = 4 << 10
@@ -64,6 +73,61 @@ const movesFloorRefreshEvery = time.Hour
func prevVersionPath(optDir string) string { return filepath.Join(optDir, moves.PrevVersionFile) }
func prevAllowedPath(optDir string) string { return filepath.Join(optDir, moves.PrevAllowedFile) }
+func rootFloorCopyPath(optDir string) string {
+ return filepath.Join(optDir, moves.RootFloorMinReleaseFile)
+}
+
+// readRootFloorCopy reads root's own copy of the floor (moves-floor.min-release
+// in root's opt dir, which only root can change, so read by its path).
+// (nil, nil) means root has never judged against an armed floor. A copy
+// that is there but holds no release is an error: armed, value unknown.
+func readRootFloorCopy(optDir string) (*moves.Floor, error) {
+ f, err := os.Open(rootFloorCopyPath(optDir))
+ if errors.Is(err, os.ErrNotExist) {
+ return nil, nil
+ }
+ if err != nil {
+ return nil, err
+ }
+ defer f.Close()
+ line, _ := readLineFrom(f)
+ if !validFloorRelease(line) {
+ return nil, fmt.Errorf("%s: %q is not a release", f.Name(), line)
+ }
+ return &moves.Floor{Min: 1, MinRelease: line}, nil
+}
+
+// effectiveLocalFloor is the floor root enforces outside a census: the
+// higher of floor.json and root's own copy (hunt H2-M1). Either one that
+// cannot be read is an error, which every caller treats as armed and
+// unknown.
+func effectiveLocalFloor(optDir, dataDir string) (*moves.Floor, error) {
+ local, err := readLocalFloor(dataDir)
+ if err != nil {
+ return nil, err
+ }
+ own, err := readRootFloorCopy(optDir)
+ if err != nil {
+ return nil, err
+ }
+ return floorMaximum(local, own), nil
+}
+
+// raiseRootFloorCopy writes the effective floor to root's own copy when it
+// is higher than the copy, under the floor lock. Never lower: the copy is
+// what keeps the floor when /data's files are removed or lowered.
+func raiseRootFloorCopy(optDir, dataDir string) error {
+ return withFloorLock(dataDir, false, func(*movesDir) error {
+ floor, err := effectiveLocalFloor(optDir, dataDir)
+ if err != nil || floor == nil {
+ return err
+ }
+ if own, _ := readLine(rootFloorCopyPath(optDir)); own == floor.MinRelease {
+ return nil
+ }
+ return writeFileDurable(rootFloorCopyPath(optDir), []byte(floor.MinRelease+"\n"), 0o644)
+ })
+}
// validFloorRelease is a min_release the floor can be armed at: a release
// moves.ReleaseAtOrAbove can compare, so nothing that would fail closed on
@@ -176,8 +240,9 @@ func writeFloorFiles(d *movesDir, f moves.Floor) error {
// only rises on a box: a lower protocol minimum, or a min_release that is
// lower or does not compare, is refused. Lowering a floor is an operator's
// manual step, box by box: delete <DataDir>/.moves/floor.json and
-// floor.min-release (and publish the lower object), and the next apply or
-// refresh arms what is published.
+// floor.min-release, and root's own copy <optDir>/moves-floor.min-release
+// (and publish the lower object), and the next apply or refresh arms what
+// is published.
func floorRegression(local, remote *moves.Floor) error {
if remote.Min < local.Min {
return fmt.Errorf("the published floor's protocol minimum %d is below this box's %d; lowering a floor is done by hand on each box", remote.Min, local.Min)
@@ -325,9 +390,11 @@ type holdFreezer func(fn func(held []registry.Route) error) error
// judgePrev is the one judge of carlos.prev (moves spec §11): it writes the
// verdict when carlos.prev is at or above the armed floor and no registry
-// row is held by an operation, and removes it otherwise. With no floor
-// armed it touches neither the registry nor carlos.prev, and leaves no
-// verdict (the units do not read one then).
+// row is held by an operation, and removes it otherwise. The armed floor is
+// the higher of floor.json and root's own copy, and the copy is raised to
+// it first (hunt H2-M1). With no floor armed it touches neither the
+// registry nor carlos.prev, and leaves no verdict (the units do not read
+// one then).
func judgePrev(optDir, dataDir string, reg *registry.Registry) error {
return judgePrevWith(optDir, dataDir, func(fn func([]registry.Route) error) error {
if reg == nil {
@@ -354,11 +421,14 @@ func judgePrevWith(optDir, dataDir string, freeze holdFreezer, learn func() stri
}
return cause
}
+ if err := raiseRootFloorCopy(optDir, dataDir); err != nil {
+ return deny(fmt.Errorf("moves protocol floor: root's copy of the floor: %v", err))
+ }
if _, err := os.Stat(systemPrevPath(optDir)); err != nil {
return deny(nil)
}
if _, ok := readLine(prevVersionPath(optDir)); !ok && learn != nil {
- if f, _ := readLocalFloor(dataDir); f != nil {
+ if f, _ := effectiveLocalFloor(optDir, dataDir); f != nil {
if v := learn(); validSystemVersion(v) {
if err := writePrevVersion(optDir, v); err != nil {
return deny(err)
@@ -369,7 +439,7 @@ func judgePrevWith(optDir, dataDir string, freeze holdFreezer, learn func() stri
ran := false
err := withFloorLock(dataDir, false, func(*movesDir) error {
ran = true
- floor, err := readLocalFloor(dataDir)
+ floor, err := effectiveLocalFloor(optDir, dataDir)
if err != nil {
return deny(fmt.Errorf("moves protocol floor: the floor on this box cannot be read: %v", err))
}
@@ -466,10 +536,13 @@ func rootJudgeMovesPrevWithSource(reg *registry.Registry, source rootFloorIdenti
optDir, dd := release.OptDir(), dataDir()
if _, err := os.Stat(filepath.Join(dd, moves.FloorFile)); errors.Is(err, os.ErrNotExist) {
- // No floor armed: nothing to judge and no verdict to keep. The one
- // stat is all an unarmed box pays.
+ // No floor armed: nothing to judge and no verdict to keep. The
+ // stats are all an unarmed box pays. Root's own copy of the floor
+ // counts as armed (hunt H2-M1).
if _, err := os.Stat(prevAllowedPath(optDir)); errors.Is(err, os.ErrNotExist) {
- return nil
+ if _, err := os.Stat(rootFloorCopyPath(optDir)); errors.Is(err, os.ErrNotExist) {
+ return nil
+ }
}
}
return withPrevLock(optDir, func() error {
diff --git a/internal/host/movesfloor_rootcopy_test.go b/internal/host/movesfloor_rootcopy_test.go
new file mode 100644
index 000000000..548a976c3
--- /dev/null
+++ b/internal/host/movesfloor_rootcopy_test.go
@@ -0,0 +1,106 @@
+package host
+
+import (
+ "os"
+ "path/filepath"
+ "testing"
+
+ "github.com/carlosframework/platform/internal/moves"
+)
+
+// Hunt H2-M1: the floor files under /data can be rewritten or removed by
+// anything running as the service account, a flat tenant among them. Root
+// keeps its own copy of the highest floor it has judged against, in its
+// own opt dir, raised from what it reads and never lowered, and judges
+// carlos.prev against the higher of the two. Removing or lowering the data
+// dir's files therefore neither lowers the floor root enforces nor earns
+// carlos.prev a verdict below it.
+func TestJudgePrevKeepsARootCopyOfTheFloor(t *testing.T) {
+ opt, dd := t.TempDir(), t.TempDir()
+ os.WriteFile(systemPrevPath(opt), []byte("#!/bin/sh\n"), 0o755)
+ rootCopy := func() string {
+ b, _ := os.ReadFile(filepath.Join(opt, moves.RootFloorMinReleaseFile))
+ return string(b)
+ }
+ verdict := func() string {
+ b, _ := os.ReadFile(prevAllowedPath(opt))
+ return string(b)
+ }
+ judge := func(prev string) {
+ t.Helper()
+ if err := writePrevVersion(opt, prev); err != nil {
+ t.Fatal(err)
+ }
+ if err := judgePrevWith(opt, dd, noHolds, nil); err != nil {
+ t.Fatal(err)
+ }
+ }
+
+ armLocalFloor(t, dd, "v0.30.0")
+ judge("v0.30.0")
+ if rootCopy() != "v0.30.0\n" || verdict() != "v0.30.0\n" {
+ t.Fatalf("armed at v0.30.0: root copy %q, verdict %q", rootCopy(), verdict())
+ }
+
+ // Both data dir files removed: the root copy stands, and carlos.prev is
+ // still judged against it.
+ if err := os.RemoveAll(filepath.Join(dd, ".moves")); err != nil {
+ t.Fatal(err)
+ }
+ judge("v0.29.0")
+ if rootCopy() != "v0.30.0\n" {
+ t.Fatalf("data dir floor removed: root copy %q, want v0.30.0", rootCopy())
+ }
+ if v := verdict(); v != "" {
+ t.Fatalf("data dir floor removed: a carlos.prev below the root copy got the verdict %q", v)
+ }
+ judge("v0.30.0")
+ if v := verdict(); v != "v0.30.0\n" {
+ t.Fatalf("data dir floor removed: a carlos.prev at the root copy got %q, want v0.30.0", v)
+ }
+
+ // The data dir floor lowered: the root copy is not lowered with it.
+ armLocalFloor(t, dd, "v0.29.0")
+ judge("v0.29.0")
+ if rootCopy() != "v0.30.0\n" {
+ t.Fatalf("data dir floor lowered: root copy %q, want v0.30.0", rootCopy())
+ }
+ if v := verdict(); v != "" {
+ t.Fatalf("data dir floor lowered: a carlos.prev below the root copy got the verdict %q", v)
+ }
+
+ // A raised floor raises the root copy.
+ armLocalFloor(t, dd, "v0.31.0")
+ judge("v0.31.0")
+ if rootCopy() != "v0.31.0\n" || verdict() != "v0.31.0\n" {
+ t.Fatalf("raised to v0.31.0: root copy %q, verdict %q", rootCopy(), verdict())
+ }
+}
+
+// Every root floor check outside a census reads the floor through
+// readEffectiveMovesFloor: it answers the higher of the data dir's floor
+// and root's own copy, so the install, rollback and recovery checks hold
+// even when the data dir's files are gone or lowered.
+func TestRootReadsTheFloorAtLeastItsOwnCopy(t *testing.T) {
+ opt, dd := t.TempDir(), t.TempDir()
+ if err := writeFileDurable(filepath.Join(opt, moves.RootFloorMinReleaseFile), []byte("v0.30.0\n"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ for _, tc := range []struct{ local, want string }{
+ {"", "v0.30.0"},
+ {"v0.29.0", "v0.30.0"},
+ {"v0.31.0", "v0.31.0"},
+ } {
+ if tc.local != "" {
+ armLocalFloor(t, dd, tc.local)
+ }
+ f, err := readEffectiveMovesFloor(nil, opt, dd)
+ if err != nil || f == nil || f.MinRelease != tc.want {
+ t.Fatalf("data dir floor %q, root copy v0.30.0: effective %+v, %v; want %s", tc.local, f, err, tc.want)
+ }
+ }
+ // No root copy and no data dir floor: no floor, as before.
+ if f, err := readEffectiveMovesFloor(nil, t.TempDir(), t.TempDir()); err != nil || f != nil {
+ t.Fatalf("nothing armed: %+v, %v", f, err)
+ }
+}
diff --git a/internal/host/proxyfeature_test.go b/internal/host/proxyfeature_test.go
index 0863d1e83..4950781cb 100644
--- a/internal/host/proxyfeature_test.go
+++ b/internal/host/proxyfeature_test.go
@@ -497,7 +497,7 @@ func TestRecoverUnitGatesPrev(t *testing.T) {
os.WriteFile(prev, []byte("#!/bin/sh\ncase \"$1 $2\" in\n'system apply') echo prev > '"+receipt+"';;\n*) exit 0;;\nesac\n"), 0o755)
cmd := strings.ReplaceAll(command, "/opt/carlos/carlos.prev", prev)
cmd = strings.ReplaceAll(cmd, "/opt/carlos/carlos", current)
- for _, p := range []string{"/opt/carlos/system/guard/carlos", "/var/lib/carlos-claims/authority/exec/census.json", "/opt/carlos/system/guard/moves", "/data/.moves/floor.min-release", "/data/.moves/seeds-floor.min-release"} {
+ for _, p := range []string{"/opt/carlos/system/guard/carlos", "/var/lib/carlos-claims/authority/exec/census.json", "/opt/carlos/system/guard/moves", "/data/.moves/floor.min-release", "/data/.moves/floor.json", "/opt/carlos/moves-floor.min-release", "/data/.moves/seeds-floor.min-release"} {
cmd = strings.ReplaceAll(cmd, p, filepath.Join(root, "absent", filepath.Base(p)))
}
journal := filepath.Join(root, "journal")
diff --git a/internal/host/rootmovesfloor_source.go b/internal/host/rootmovesfloor_source.go
index 2f12845f0..e9aa5adf5 100644
--- a/internal/host/rootmovesfloor_source.go
+++ b/internal/host/rootmovesfloor_source.go
@@ -46,7 +46,8 @@ func readEffectiveMovesFloor(source rootFloorIdentitySource, opt, dd string) (*m
return nil, err
}
if !required {
- return readLocalFloor(dd)
+ // The higher of /data's floor.json and root's own copy (hunt H2-M1).
+ return effectiveLocalFloor(opt, dd)
}
return readRootProtocolBound(rootFloorDir(opt), id)
}
diff --git a/internal/host/units/carlos-system-recover.service b/internal/host/units/carlos-system-recover.service
index 4df8e5b6e..b4e0a208b 100644
--- a/internal/host/units/carlos-system-recover.service
+++ b/internal/host/units/carlos-system-recover.service
@@ -9,7 +9,8 @@
# When a journal is open and carlos.prev exists, the recovery runs from
# carlos.prev.
# The moves protocol floor (moves spec §11) narrows that choice: once a
-# floor is armed (/data/.moves/floor.min-release is there and not empty),
+# floor is armed (/data/.moves/floor.min-release is there and not empty,
+# or /data/.moves/floor.json is there at all),
# carlos.prev runs only when its verdict file (/opt/carlos/carlos.prev.allowed,
# written by root after comparing versions in Go) names that same floor,
# byte for byte. A floor path that is a symlink or anything but a regular
@@ -25,6 +26,13 @@
# before. The line carries no percent sign and no dollar sign, both of which
# systemd expands before the shell sees them.
#
+# /data is writable by anything that runs as the service account, a flat
+# tenant among them, so the files there cannot be the only word (hunt
+# H2-M1). Root keeps its own copy of the highest floor it has judged
+# carlos.prev against, /opt/carlos/moves-floor.min-release, raised and
+# never lowered (judgePrev). Once it is there, carlos.prev runs only when
+# the verdict names it too, whatever /data says.
+#
# The seeds floor (seeded-instances spec §3.3) adds the same test for its
# own files: once /data/.moves/seeds-floor.min-release is there and not
# empty, carlos.prev runs only when /opt/carlos/carlos.prev.seeds-allowed
@@ -54,7 +62,7 @@ Type=oneshot
# runs first.
TimeoutStartSec=13min
EnvironmentFile=-/etc/carlos/host.env
-ExecStart=/bin/sh -c 'if [ -x /opt/carlos/system/guard/carlos ] && { [ -e /var/lib/carlos-claims/authority/exec/census.json ] || [ -L /var/lib/carlos-claims/authority/exec/census.json ] || [ -e /opt/carlos/system/guard/moves ] || [ -L /opt/carlos/system/guard/moves ]; }; then exec /opt/carlos/system/guard/carlos system guard-exec recover; fi; if [ -f /opt/carlos/system/router/journal.json ] && [ -x /opt/carlos/carlos.prev ] && [ ! -L /data/.moves/floor.min-release ] && { [ ! -e /data/.moves/floor.min-release ] || [ -f /data/.moves/floor.min-release ]; } && { ! [ -s /data/.moves/floor.min-release ] || /opt/carlos/carlos.prev system floor-allows-prev /data/.moves/floor.min-release /opt/carlos/carlos.prev.allowed; } && [ ! -L /data/.moves/seeds-floor.min-release ] && { [ ! -e /data/.moves/seeds-floor.min-release ] || [ -f /data/.moves/seeds-floor.min-release ]; } && { ! [ -s /data/.moves/seeds-floor.min-release ] || /opt/carlos/carlos.prev system floor-allows-prev /data/.moves/seeds-floor.min-release /opt/carlos/carlos.prev.seeds-allowed; } && /opt/carlos/carlos system exec-sandbox-allows-prev /opt/carlos/carlos.prev && /opt/carlos/carlos system proxy-allows-prev /opt/carlos/carlos.prev && /opt/carlos/carlos system generations-allows-prev /opt/carlos/carlos.prev; then exec /opt/carlos/carlos.prev system apply --recover; fi; exec /opt/carlos/carlos system apply --recover'
+ExecStart=/bin/sh -c 'if [ -x /opt/carlos/system/guard/carlos ] && { [ -e /var/lib/carlos-claims/authority/exec/census.json ] || [ -L /var/lib/carlos-claims/authority/exec/census.json ] || [ -e /opt/carlos/system/guard/moves ] || [ -L /opt/carlos/system/guard/moves ]; }; then exec /opt/carlos/system/guard/carlos system guard-exec recover; fi; if [ -f /opt/carlos/system/router/journal.json ] && [ -x /opt/carlos/carlos.prev ] && [ ! -L /data/.moves/floor.min-release ] && { [ ! -e /data/.moves/floor.min-release ] || [ -f /data/.moves/floor.min-release ]; } && { { ! [ -s /data/.moves/floor.min-release ] && ! [ -e /data/.moves/floor.json ] && ! [ -L /data/.moves/floor.json ]; } || /opt/carlos/carlos.prev system floor-allows-prev /data/.moves/floor.min-release /opt/carlos/carlos.prev.allowed; } && { ! [ -e /opt/carlos/moves-floor.min-release ] || /opt/carlos/carlos.prev system floor-allows-prev /opt/carlos/moves-floor.min-release /opt/carlos/carlos.prev.allowed; } && [ ! -L /data/.moves/seeds-floor.min-release ] && { [ ! -e /data/.moves/seeds-floor.min-release ] || [ -f /data/.moves/seeds-floor.min-release ]; } && { ! [ -s /data/.moves/seeds-floor.min-release ] || /opt/carlos/carlos.prev system floor-allows-prev /data/.moves/seeds-floor.min-release /opt/carlos/carlos.prev.seeds-allowed; } && /opt/carlos/carlos system exec-sandbox-allows-prev /opt/carlos/carlos.prev && /opt/carlos/carlos system proxy-allows-prev /opt/carlos/carlos.prev && /opt/carlos/carlos system generations-allows-prev /opt/carlos/carlos.prev; then exec /opt/carlos/carlos.prev system apply --recover; fi; exec /opt/carlos/carlos system apply --recover'
ProtectHome=yes
PrivateTmp=yes
diff --git a/internal/host/units/carlos-system-update.service b/internal/host/units/carlos-system-update.service
index 9b402c493..7e215f47b 100644
--- a/internal/host/units/carlos-system-update.service
+++ b/internal/host/units/carlos-system-update.service
@@ -7,7 +7,8 @@
# from carlos.prev rather than from the candidate that did not work.
#
# The moves protocol floor (moves spec §11) narrows that choice: once a
-# floor is armed (/data/.moves/floor.min-release is there and not empty),
+# floor is armed (/data/.moves/floor.min-release is there and not empty,
+# or /data/.moves/floor.json is there at all),
# carlos.prev runs only when its verdict file (/opt/carlos/carlos.prev.allowed,
# written by root after comparing versions in Go) names that same floor,
# byte for byte. A floor path that is a symlink or anything but a regular
@@ -23,6 +24,13 @@
# before. The line carries no percent sign and no dollar sign, both of which
# systemd expands before the shell sees them.
#
+# /data is writable by anything that runs as the service account, a flat
+# tenant among them, so the files there cannot be the only word (hunt
+# H2-M1). Root keeps its own copy of the highest floor it has judged
+# carlos.prev against, /opt/carlos/moves-floor.min-release, raised and
+# never lowered (judgePrev). Once it is there, carlos.prev runs only when
+# the verdict names it too, whatever /data says.
+#
# The seeds floor (seeded-instances spec §3.3) adds the same test for its
# own files: once /data/.moves/seeds-floor.min-release is there and not
# empty, carlos.prev runs only when /opt/carlos/carlos.prev.seeds-allowed
@@ -47,7 +55,7 @@ OnFailure=carlos-system-recover.service
Type=oneshot
TimeoutStartSec=20min
EnvironmentFile=-/etc/carlos/host.env
-ExecStart=/bin/sh -c 'if [ -x /opt/carlos/system/guard/carlos ] && { [ -e /var/lib/carlos-claims/authority/exec/census.json ] || [ -L /var/lib/carlos-claims/authority/exec/census.json ] || [ -e /opt/carlos/system/guard/moves ] || [ -L /opt/carlos/system/guard/moves ]; }; then exec /opt/carlos/system/guard/carlos system guard-exec apply; fi; if [ -f /opt/carlos/system/router/journal.json ] && [ -x /opt/carlos/carlos.prev ] && [ ! -L /data/.moves/floor.min-release ] && { [ ! -e /data/.moves/floor.min-release ] || [ -f /data/.moves/floor.min-release ]; } && { ! [ -s /data/.moves/floor.min-release ] || /opt/carlos/carlos.prev system floor-allows-prev /data/.moves/floor.min-release /opt/carlos/carlos.prev.allowed; } && [ ! -L /data/.moves/seeds-floor.min-release ] && { [ ! -e /data/.moves/seeds-floor.min-release ] || [ -f /data/.moves/seeds-floor.min-release ]; } && { ! [ -s /data/.moves/seeds-floor.min-release ] || /opt/carlos/carlos.prev system floor-allows-prev /data/.moves/seeds-floor.min-release /opt/carlos/carlos.prev.seeds-allowed; }; then exec /opt/carlos/carlos.prev system apply; fi; exec /opt/carlos/carlos system apply'
+ExecStart=/bin/sh -c 'if [ -x /opt/carlos/system/guard/carlos ] && { [ -e /var/lib/carlos-claims/authority/exec/census.json ] || [ -L /var/lib/carlos-claims/authority/exec/census.json ] || [ -e /opt/carlos/system/guard/moves ] || [ -L /opt/carlos/system/guard/moves ]; }; then exec /opt/carlos/system/guard/carlos system guard-exec apply; fi; if [ -f /opt/carlos/system/router/journal.json ] && [ -x /opt/carlos/carlos.prev ] && [ ! -L /data/.moves/floor.min-release ] && { [ ! -e /data/.moves/floor.min-release ] || [ -f /data/.moves/floor.min-release ]; } && { { ! [ -s /data/.moves/floor.min-release ] && ! [ -e /data/.moves/floor.json ] && ! [ -L /data/.moves/floor.json ]; } || /opt/carlos/carlos.prev system floor-allows-prev /data/.moves/floor.min-release /opt/carlos/carlos.prev.allowed; } && { ! [ -e /opt/carlos/moves-floor.min-release ] || /opt/carlos/carlos.prev system floor-allows-prev /opt/carlos/moves-floor.min-release /opt/carlos/carlos.prev.allowed; } && [ ! -L /data/.moves/seeds-floor.min-release ] && { [ ! -e /data/.moves/seeds-floor.min-release ] || [ -f /data/.moves/seeds-floor.min-release ]; } && { ! [ -s /data/.moves/seeds-floor.min-release ] || /opt/carlos/carlos.prev system floor-allows-prev /data/.moves/seeds-floor.min-release /opt/carlos/carlos.prev.seeds-allowed; }; then exec /opt/carlos/carlos.prev system apply; fi; exec /opt/carlos/carlos system apply'
# --- hardening (the carlos-stage.service set) ---
ProtectHome=yes
diff --git a/internal/moves/floor.go b/internal/moves/floor.go
index d1cc9ea3c..7e541a332 100644
--- a/internal/moves/floor.go
+++ b/internal/moves/floor.go
@@ -55,6 +55,14 @@ const (
// bytes as FloorMinReleaseFile. Absent means carlos.prev may not run
// while a floor is armed.
PrevAllowedFile = "carlos.prev.allowed"
+ // RootFloorMinReleaseFile is root's own copy of the highest floor it
+ // has judged carlos.prev against, one line in the same bytes as
+ // FloorMinReleaseFile, beside carlos.prev in the opt dir
+ // (/opt/carlos/moves-floor.min-release). Anything running as the
+ // service account can rewrite or remove the data dir's files, a flat
+ // tenant among them (hunt H2-M1); only root writes this one, and only
+ // upward. Absent means root has never judged against an armed floor.
+ RootFloorMinReleaseFile = "moves-floor.min-release"
)
// Floor is the minimum protocol version, and the first release that speaks