gvisor demos: establish guest and host hardening contract
Add the guest launch mode, trusted memory limit, descriptor-owned exit records, and real-systemd measurement fixtures. Apply ruling R-T2: pin and verify the five-file runtime set for both Linux architectures. Privileged acceptance remains BLOCKED. Runner invocations 20261108T214542-26d2f0 and 20261108T214840-b6f8c8 verify the complete set but the sandbox exits before guest startup. The four-run Task 2 budget is exhausted. No hardening directive was weakened; the hardening set and production gVisor templates remain unpinned and unfinished. Local package tests, common build/vet/cross-build gates, and all four post-refresh census checks pass. The census is proposed, not reviewed. The task-2 report records evidence, limits, and remaining work.
Co-Authored-By: Astra (gpt-6-astra) via codex
15 files changed,
+1,693
−41
docs/superpowers/notes/census-proposal-gvisor-demos.md+4 −3internal/execsandbox/lock.go+72 −11internal/execsandbox/lock_test.go+77 −5internal/execsandbox/runsc.lock.json+50 −6internal/host/gvisor_fixture_rootrunner_linux_test.go+604 −0internal/host/gvisor_hardening_rootrunner_linux_test.go+470 −0internal/instanceexec/exec.go+14 −4internal/instanceexec/exit.go+27 −5internal/instanceexec/probe.go+9 −1internal/instanceexec/sandbox.go+51 −0internal/instanceexec/sandbox_linux.go+67 −0internal/instanceexec/sandbox_linux_test.go+215 −0internal/instanceexec/sandbox_other.go+24 −0internal/provision/testdata/plan14-root-reads-chain.tsv+1 −1internal/provision/testdata/plan14-root-reads-gvisor-demos.tsv+8 −5
CI failed — run details
Intent
diff --git a/docs/superpowers/notes/census-proposal-gvisor-demos.md b/docs/superpowers/notes/census-proposal-gvisor-demos.md| index cbe0309ad..2063a3d5d 100644 |
| --- a/docs/superpowers/notes/census-proposal-gvisor-demos.md |
| +++ b/docs/superpowers/notes/census-proposal-gvisor-demos.md |
| @@ -1,6 +1,6 @@ |
| # Census approval: gvisor-demos |
| -Ruling `census-ruling-gvisor-demos`. 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). |
| +Ruling `census-ruling-gvisor-demos`. The independent reviewer approves or rejects every change below, 4 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26). |
| | unit | change | read sites | what changed | |
| |---|---|---|---| |
| @@ -17,7 +17,7 @@ Ruling `census-ruling-gvisor-demos`. The independent reviewer approves or reject |
| | `internal/instancectl/server.go` `runWithClaim` | body | unchanged (4) | Require fixed sandbox settings from shared Configure; retain claim handler and legacy-route refusals; preserve egress asserter and revokes for invalid settings and gate only native restart dispatch. Native probe/build/start admission remains refused. Existing root reads unchanged. | |
| | `internal/instancectl/server.go` `type Server` | body | unchanged (1) | Add fixed configured and effective sandbox modes, configuration error and runtime readiness callback. No new path or read. | |
| -Envelopes re-pinned: `internal/execsandbox`, `internal/host`, `internal/host/units`, `internal/instancectl`. |
| +Envelopes re-pinned: `internal/execsandbox`, `internal/host`, `internal/host/units`, `internal/instancectl`, `internal/instanceexec`. |
| 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. |
| @@ -41,7 +41,8 @@ New dispositions, which census-propose wrote and the reviewer checks against the |
| - new `internal/execsandbox/runsc.lock.json:external`: reads +file:external; written legacy, accepted-legacy, frozen |
| - new `internal/host/execsandbox.go:sandboxExecGate`: reads +whole:Route ×2; written legacy, accepted-legacy, frozen |
| - new `internal/host/execsandbox.go:sandboxRouteGate`: reads +registry:Runtime, +whole:Route ×2; written legacy, accepted-legacy, frozen |
| +- new `internal/instanceexec/sandbox_linux.go:gvisorProbeChecks`: reads +data-literal, +file:ReadFile; written legacy, accepted-legacy, frozen |
| -Seal: `b970bb28c5a633d2572a1da549030e9258cfdabb6322ddffdd0ebf41b56c464c` → `39d38b6f517d92fcace7950644b0fc3455d03f5e055fd3c08a7f9ffcb06652dd`. |
| +Seal: `b970bb28c5a633d2572a1da549030e9258cfdabb6322ddffdd0ebf41b56c464c` → `fe0ca981cae7d649de4d5b30aec791b44914ed5770eb374dc91e7b7242406744`. |
| Overlay: `internal/provision/testdata/plan14-root-reads-gvisor-demos.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/internal/execsandbox/lock.go b/internal/execsandbox/lock.go| index 494f0a63b..4f6f8ceff 100644 |
| --- a/internal/execsandbox/lock.go |
| +++ b/internal/execsandbox/lock.go |
| @@ -2,7 +2,9 @@ package execsandbox |
| import ( |
| "bytes" |
| + "crypto/sha256" |
| _ "embed" |
| + "encoding/hex" |
| "encoding/json" |
| "fmt" |
| "io" |
| @@ -19,9 +21,39 @@ type RunscLock struct { |
| } |
| type RunscPin struct { |
| - TarballURL string `json:"tarball_url"` |
| - TarballSHA512 string `json:"tarball_sha512"` |
| - SHA256 string `json:"sha256"` |
| + TarballURL string `json:"tarball_url"` |
| + TarballSHA512 string `json:"tarball_sha512"` |
| + SHA256 string `json:"sha256"` |
| + Files []RunscFile `json:"files"` |
| +} |
| + |
| +type RunscFile struct { |
| + Path string `json:"path"` |
| + SHA256 string `json:"sha256"` |
| +} |
| + |
| +var runscMembers = [...]struct{ path, asset string }{ |
| + {"gvisor-bin/gvisor-proc-umounter", "gvisor-proc-umounter"}, |
| + {"gvisor-bin/gvisor-sentry-prewarmer", "gvisor-sentry-prewarmer"}, |
| + {"gvisor-bin/gvisor_sentry", "gvisor-sentry"}, |
| + {"gvisor-bin/runsc-fd-parking", "runsc-fd-parking"}, |
| + {"runsc", "runsc"}, |
| +} |
| + |
| +// SetID binds every executable to the canonical path-sorted manifest. |
| +// An incomplete, unsorted or inconsistent pin has no usable identity. |
| +func (p RunscPin) SetID() string { |
| + if len(p.Files) != len(runscMembers) || !lowerHex(p.SHA256, 64) { |
| + return "" |
| + } |
| + h := sha256.New() |
| + for i, f := range p.Files { |
| + if f.Path != runscMembers[i].path || !lowerHex(f.SHA256, 64) || f.Path == "runsc" && f.SHA256 != p.SHA256 { |
| + return "" |
| + } |
| + fmt.Fprintf(h, "%s %s\n", f.SHA256, f.Path) |
| + } |
| + return hex.EncodeToString(h.Sum(nil)) |
| } |
| var releaseName = regexp.MustCompile(`^release-[0-9]{8}\.[0-9]+$`) |
| @@ -43,7 +75,7 @@ func parseRunscLock(raw []byte) (RunscLock, error) { |
| for platform, arch := range map[string]string{"linux-arm64": "aarch64", "linux-amd64": "x86_64"} { |
| pin, ok := lock.Platforms[platform] |
| want := "https://storage.googleapis.com/gvisor/releases/release/" + strings.TrimPrefix(lock.Release, "release-") + "/" + arch + "/gvisor.tar.zstd" |
| - if !ok || pin.TarballURL != want || !lowerHex(pin.TarballSHA512, 128) || !lowerHex(pin.SHA256, 64) { |
| + if !ok || pin.TarballURL != want || !lowerHex(pin.TarballSHA512, 128) || pin.SetID() == "" { |
| return fail() |
| } |
| } |
| @@ -60,13 +92,27 @@ func uniqueJSON(d *json.Decoder, depth int) error { |
| if !ok { |
| return nil |
| } |
| - if delim != '{' || depth > 2 { |
| + if depth == 3 { |
| + if delim != '[' { |
| + return ErrRunsc |
| + } |
| + for d.More() { |
| + if err := uniqueJSON(d, depth+1); err != nil { |
| + return err |
| + } |
| + } |
| + _, err := d.Token() |
| + return err |
| + } |
| + if delim != '{' || depth > 4 { |
| return ErrRunsc |
| } |
| allowed := []map[string]bool{ |
| {"release": true, "platforms": true}, |
| {"linux-arm64": true, "linux-amd64": true}, |
| - {"tarball_url": true, "tarball_sha512": true, "sha256": true}, |
| + {"tarball_url": true, "tarball_sha512": true, "sha256": true, "files": true}, |
| + nil, |
| + {"path": true, "sha256": true}, |
| }[depth] |
| seen := map[string]bool{} |
| for d.More() { |
| @@ -114,15 +160,30 @@ func RunscFor(platform string) (RunscPin, error) { |
| } |
| func RunscPath(pin RunscPin) string { |
| - if !lowerHex(pin.SHA256, 64) { |
| + dir := RunscDir(pin) |
| + if dir == "" { |
| return "" |
| } |
| - return "/opt/carlos/runsc/" + pin.SHA256 + "/runsc" |
| + return dir + "/runsc" |
| } |
| -func RunscObjectKey(platform string, pin RunscPin) string { |
| - if (platform != "linux-arm64" && platform != "linux-amd64") || !lowerHex(pin.SHA256, 64) { |
| +func RunscDir(pin RunscPin) string { |
| + id := pin.SetID() |
| + if id == "" { |
| return "" |
| } |
| - return "bootstrap/router/runsc-" + pin.SHA256 + "/runsc-" + platform |
| + return "/opt/carlos/runsc/" + id |
| +} |
| + |
| +func RunscObjectKey(platform string, pin RunscPin, member string) string { |
| + id := pin.SetID() |
| + if (platform != "linux-arm64" && platform != "linux-amd64") || id == "" { |
| + return "" |
| + } |
| + for _, f := range runscMembers { |
| + if member == f.path { |
| + return "bootstrap/router/runsc-" + id + "/" + f.asset + "-" + platform |
| + } |
| + } |
| + return "" |
| } |
diff --git a/internal/execsandbox/lock_test.go b/internal/execsandbox/lock_test.go| index 37e427dcd..77d8b304d 100644 |
| --- a/internal/execsandbox/lock_test.go |
| +++ b/internal/execsandbox/lock_test.go |
| @@ -2,14 +2,24 @@ package execsandbox |
| import ( |
| "encoding/json" |
| + "reflect" |
| "strings" |
| "testing" |
| ) |
| func TestRunscLock(t *testing.T) { |
| const digest = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| - if got := RunscObjectKey("linux-arm64", RunscPin{SHA256: digest}); got != "bootstrap/router/runsc-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef/runsc-linux-arm64" { |
| - t.Fatalf("rev 5.1 object key: %s", got) |
| + wantPaths := []string{"gvisor-bin/gvisor-proc-umounter", "gvisor-bin/gvisor-sentry-prewarmer", "gvisor-bin/gvisor_sentry", "gvisor-bin/runsc-fd-parking", "runsc"} |
| + synthetic := RunscPin{SHA256: digest} |
| + for _, path := range wantPaths { |
| + synthetic.Files = append(synthetic.Files, RunscFile{Path: path, SHA256: digest}) |
| + } |
| + const stableID = "6a1af9dfd38731b99f8ca28f91b1df1ee0ed0fef7486c26d6f649fa4ab95aec3" |
| + if synthetic.SetID() != stableID { |
| + t.Fatalf("canonical set ID = %s", synthetic.SetID()) |
| + } |
| + if got := RunscObjectKey("linux-arm64", synthetic, "runsc"); got != "bootstrap/router/runsc-"+stableID+"/runsc-linux-arm64" { |
| + t.Fatalf("rev 5.2 object key: %s", got) |
| } |
| lock, err := LoadRunscLock() |
| if err != nil { |
| @@ -23,11 +33,32 @@ func TestRunscLock(t *testing.T) { |
| if err != nil { |
| t.Fatal(err) |
| } |
| - if RunscPath(pin) != "/opt/carlos/runsc/"+pin.SHA256+"/runsc" { |
| + wantID := map[string]string{ |
| + "linux-amd64": "b9f99c21c8c4eab387ca926cc073d93a7f4be25a76e0d4cc60947d9f87722437", |
| + "linux-arm64": "ef62daddb0405a6f30c3a23aea89d4c9b1f2dfe38a6bf59f8e8caad76bf1ff00", |
| + }[platform] |
| + if pin.SetID() != wantID { |
| + t.Fatalf("%s set ID: %s", platform, pin.SetID()) |
| + } |
| + var paths []string |
| + for _, file := range pin.Files { |
| + paths = append(paths, file.Path) |
| + } |
| + if !reflect.DeepEqual(paths, wantPaths) { |
| + t.Fatalf("members: %v", paths) |
| + } |
| + if RunscDir(pin) != "/opt/carlos/runsc/"+pin.SetID() || RunscPath(pin) != RunscDir(pin)+"/runsc" { |
| t.Fatal("runtime path") |
| } |
| - if RunscObjectKey(platform, pin) != "bootstrap/router/runsc-"+pin.SHA256+"/runsc-"+platform { |
| - t.Fatal("object key") |
| + for member, asset := range map[string]string{"runsc": "runsc", "gvisor-bin/gvisor_sentry": "gvisor-sentry", "gvisor-bin/runsc-fd-parking": "runsc-fd-parking", "gvisor-bin/gvisor-proc-umounter": "gvisor-proc-umounter", "gvisor-bin/gvisor-sentry-prewarmer": "gvisor-sentry-prewarmer"} { |
| + if RunscObjectKey(platform, pin, member) != "bootstrap/router/runsc-"+pin.SetID()+"/"+asset+"-"+platform { |
| + t.Fatalf("object key for %s", member) |
| + } |
| + } |
| + for _, member := range []string{"", "../runsc", "/runsc", "gvisor-bin/checkpointgofer", "gvisor-bin/runsc-metric-server", "containerd-shim-runsc-v1"} { |
| + if RunscObjectKey(platform, pin, member) != "" { |
| + t.Fatalf("unexpected member %s", member) |
| + } |
| } |
| } |
| if _, err := RunscFor("darwin-arm64"); err == nil { |
| @@ -54,6 +85,47 @@ func TestRunscLock(t *testing.T) { |
| "uppercase digest": strings.Replace(base, lock.Platforms["linux-arm64"].SHA256, strings.ToUpper(lock.Platforms["linux-arm64"].SHA256), 1), |
| "short archive digest": strings.Replace(base, lock.Platforms["linux-arm64"].TarballSHA512, "abc", 1), |
| "wrong architecture": strings.Replace(base, "/aarch64/", "/x86_64/", 1), |
| + "member key alias": strings.Replace(base, `"path":`, `"Path":`, 1), |
| + "duplicate member key": strings.Replace(base, `"path":`, `"path":"runsc","path":`, 1), |
| + "unknown member key": strings.Replace(base, `"path":`, `"extra":0,"path":`, 1), |
| + "files object": strings.Replace(base, `"files":[`, `"files":{`, 1), |
| + } |
| + for name, mutate := range map[string]func(*RunscPin){ |
| + "missing member": func(p *RunscPin) { p.Files = p.Files[:4] }, |
| + "null files": func(p *RunscPin) { p.Files = nil }, |
| + "extra member": func(p *RunscPin) { p.Files = append(p.Files, RunscFile{Path: "unexpected", SHA256: digest}) }, |
| + "duplicate member": func(p *RunscPin) { p.Files[0] = p.Files[1] }, |
| + "unsorted": func(p *RunscPin) { p.Files[0], p.Files[1] = p.Files[1], p.Files[0] }, |
| + "excluded member": func(p *RunscPin) { p.Files[0].Path = "gvisor-bin/checkpointgofer" }, |
| + "traversal member": func(p *RunscPin) { p.Files[0].Path = "../runsc" }, |
| + "member hash": func(p *RunscPin) { p.Files[0].SHA256 = "abc" }, |
| + "uppercase member hash": func(p *RunscPin) { p.Files[0].SHA256 = strings.ToUpper(p.Files[0].SHA256) }, |
| + "runsc hash mismatch": func(p *RunscPin) { p.SHA256 = digest }, |
| + } { |
| + var changed RunscLock |
| + if err := json.Unmarshal(raw, &changed); err != nil { |
| + t.Fatal(err) |
| + } |
| + p := changed.Platforms["linux-arm64"] |
| + mutate(&p) |
| + changed.Platforms["linux-arm64"] = p |
| + b, err := json.Marshal(changed) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + cases[name] = string(b) |
| + if p.SetID() != "" || RunscDir(p) != "" || RunscPath(p) != "" || RunscObjectKey("linux-arm64", p, "runsc") != "" { |
| + t.Errorf("invalid pin produces a runtime identity: %s", name) |
| + } |
| + } |
| + if RunscObjectKey("darwin-arm64", synthetic, "runsc") != "" { |
| + t.Fatal("unsupported object platform") |
| + } |
| + changed := synthetic |
| + changed.Files = append([]RunscFile(nil), synthetic.Files...) |
| + changed.Files[0].SHA256 = strings.Repeat("a", 64) |
| + if changed.SetID() == stableID || changed.SetID() == "" || synthetic.SetID() != stableID { |
| + t.Fatal("helper bytes must change set ID without changing original") |
| } |
| delete(lock.Platforms, "linux-arm64") |
| missing, _ := json.Marshal(lock) |
diff --git a/internal/execsandbox/runsc.lock.json b/internal/execsandbox/runsc.lock.json| index 749a17c03..8abe820a1 100644 |
| --- a/internal/execsandbox/runsc.lock.json |
| +++ b/internal/execsandbox/runsc.lock.json |
| @@ -1,15 +1,59 @@ |
| { |
| + "release": "release-20261102.0", |
| "platforms": { |
| "linux-amd64": { |
| - "sha256": "c5a5a7ba1209b605d08874fdd4429035f95afcb2d482bc95ed3fb13d31a25098", |
| + "tarball_url": "https://storage.googleapis.com/gvisor/releases/release/20261102.0/x86_64/gvisor.tar.zstd", |
| "tarball_sha512": "3c400f72be459b57b99b1c4f69be96bcd67eef3caf2078e595fc98e688b6b9a3af7802646b3dde7da8a9aba96d34f86be303e0430c7868ab2d13becdd403c0c1", |
| - "tarball_url": "https://storage.googleapis.com/gvisor/releases/release/20261102.0/x86_64/gvisor.tar.zstd" |
| + "sha256": "c5a5a7ba1209b605d08874fdd4429035f95afcb2d482bc95ed3fb13d31a25098", |
| + "files": [ |
| + { |
| + "path": "gvisor-bin/gvisor-proc-umounter", |
| + "sha256": "b3bbbaef5ddc62084e5febd19d3acca14f3d42b2a25d8552fb40def699467019" |
| + }, |
| + { |
| + "path": "gvisor-bin/gvisor-sentry-prewarmer", |
| + "sha256": "046e3ec1de3aa7b7ec7ce53b4f0d1e08db15987847606a8e361133d5c5bd3d73" |
| + }, |
| + { |
| + "path": "gvisor-bin/gvisor_sentry", |
| + "sha256": "6dfd3af65e664663f332d0e4b9fb82452496e34ebc6cb568ae49f5b1ac9d8166" |
| + }, |
| + { |
| + "path": "gvisor-bin/runsc-fd-parking", |
| + "sha256": "03af90d07ea466c10ecc3e3ba839b2a59540959dd3286aea3886917cba850c11" |
| + }, |
| + { |
| + "path": "runsc", |
| + "sha256": "c5a5a7ba1209b605d08874fdd4429035f95afcb2d482bc95ed3fb13d31a25098" |
| + } |
| + ] |
| }, |
| "linux-arm64": { |
| - "sha256": "cbca2f059fdbfd3563d7d7c10b4d77d534aaaa1f524ddb47d76b36285acc6499", |
| + "tarball_url": "https://storage.googleapis.com/gvisor/releases/release/20261102.0/aarch64/gvisor.tar.zstd", |
| "tarball_sha512": "e829ca32eef36f4e960460a6dcb094d7945ab507e9bfe0275f09467ab9bfeb846528fddfd42349ad64bb4f5b02148e1065c06e573feb8f6a8b3f47efa30a7d2e", |
| - "tarball_url": "https://storage.googleapis.com/gvisor/releases/release/20261102.0/aarch64/gvisor.tar.zstd" |
| + "sha256": "cbca2f059fdbfd3563d7d7c10b4d77d534aaaa1f524ddb47d76b36285acc6499", |
| + "files": [ |
| + { |
| + "path": "gvisor-bin/gvisor-proc-umounter", |
| + "sha256": "8ddecb8894b332be68e84faa073c073bbf1d6f046974d411fc02db03a73fde90" |
| + }, |
| + { |
| + "path": "gvisor-bin/gvisor-sentry-prewarmer", |
| + "sha256": "6916df96d23f2248b6566f4c9033d636f5d867c0ac8e497ea52147b30e5b920b" |
| + }, |
| + { |
| + "path": "gvisor-bin/gvisor_sentry", |
| + "sha256": "c394ae17b4a1ccf9d07085f17de9c11bc3de3958410e620f5f8138f6887e424e" |
| + }, |
| + { |
| + "path": "gvisor-bin/runsc-fd-parking", |
| + "sha256": "e41db2da554154f282f2829a664a2c4234c163b9da74fc9b4388126223c7090c" |
| + }, |
| + { |
| + "path": "runsc", |
| + "sha256": "cbca2f059fdbfd3563d7d7c10b4d77d534aaaa1f524ddb47d76b36285acc6499" |
| + } |
| + ] |
| } |
| - }, |
| - "release": "release-20261102.0" |
| + } |
| } |
diff --git a/internal/host/gvisor_fixture_rootrunner_linux_test.go b/internal/host/gvisor_fixture_rootrunner_linux_test.go| new file mode 100644 |
| index 000000000..2c65cf808 |
| --- /dev/null |
| +++ b/internal/host/gvisor_fixture_rootrunner_linux_test.go |
| @@ -0,0 +1,604 @@ |
| +//go:build linux && rootrunner |
| + |
| +package host |
| + |
| +import ( |
| + "archive/tar" |
| + "bytes" |
| + "context" |
| + "crypto/sha256" |
| + "crypto/sha512" |
| + "encoding/hex" |
| + "encoding/json" |
| + "errors" |
| + "fmt" |
| + "io" |
| + "net" |
| + "net/http" |
| + "os" |
| + "os/exec" |
| + "os/signal" |
| + "os/user" |
| + "path/filepath" |
| + "runtime" |
| + "strconv" |
| + "strings" |
| + "syscall" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/execsandbox" |
| + "github.com/carlosframework/platform/internal/instancectl" |
| + "github.com/carlosframework/platform/internal/instanceexec" |
| + "github.com/carlosframework/platform/internal/instancefs" |
| + "github.com/klauspost/compress/zstd" |
| + "golang.org/x/sys/unix" |
| +) |
| + |
| +const gvisorFixtureHost = "gvisor.example.com" |
| +const gvisorFixtureRootfs = "/var/lib/carlos/oci-rootfs" |
| + |
| +// This test binary is the transferred platform trampoline AND fixture app. |
| +// No local carlos executable or production bundle constructor is required. |
| +func init() { |
| + if len(os.Args) < 2 { |
| + return |
| + } |
| + switch os.Args[1] { |
| + case "instance-exec": |
| + instanceexec.RunExec(os.Args[2:]) |
| + os.Exit(0) |
| + case "instance-exit": |
| + instanceexec.RunExit(os.Args[2:]) |
| + os.Exit(0) |
| + case "instance-probe": |
| + instanceexec.RunProbe(os.Args[2:]) |
| + os.Exit(0) |
| + case "gvisor-test-app": |
| + if err := gvisorGuestApp(); err != nil { |
| + fmt.Fprintln(os.Stderr, err) |
| + os.Exit(72) |
| + } |
| + os.Exit(0) |
| + case "gvisor-test-child": |
| + os.Exit(0) |
| + case "gvisor-test-compiler": |
| + if err := gvisorCompilerApp(); err != nil { |
| + fmt.Fprintln(os.Stderr, err) |
| + os.Exit(73) |
| + } |
| + os.Exit(0) |
| + } |
| +} |
| + |
| +type gvisorGuestEvidence struct { |
| + UID, GID, PID, PPID int |
| + Status string |
| + MemoryLimit string |
| + Limits unix.Rlimit |
| + Permitted, LeafRefused, ParentRefused, EscapeRefused bool |
| +} |
| + |
| +func gvisorGuestEvidenceNow(dir string) (gvisorGuestEvidence, error) { |
| + e := gvisorGuestEvidence{UID: os.Getuid(), GID: os.Getgid(), PID: os.Getpid(), PPID: os.Getppid(), MemoryLimit: os.Getenv("GOMEMLIMIT")} |
| + status, err := os.ReadFile("/proc/self/status") |
| + if err != nil { |
| + return e, err |
| + } |
| + e.Status = string(status) |
| + if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &e.Limits); err != nil { |
| + return e, err |
| + } |
| + f, err := instancefs.OpenBeneath(dir, "allowed", os.O_CREATE|os.O_EXCL|os.O_RDWR, 0600) |
| + if err != nil { |
| + return e, fmt.Errorf("permitted openat2: %w", err) |
| + } |
| + _, err = f.Write([]byte("own bytes")) |
| + f.Close() |
| + if err != nil { |
| + return e, err |
| + } |
| + b, err := instancefs.ReadBeneath(dir, "allowed") |
| + e.Permitted = err == nil && string(b) == "own bytes" |
| + if err := os.Symlink("allowed", filepath.Join(dir, "leaf")); err != nil { |
| + return e, err |
| + } |
| + _, err = instancefs.ReadBeneath(dir, "leaf") |
| + e.LeafRefused = errors.Is(err, instancefs.ErrSymlink) |
| + if err := os.Symlink(dir, filepath.Join(dir, "parent")); err != nil { |
| + return e, err |
| + } |
| + _, err = instancefs.ReadBeneath(filepath.Join(dir, "parent"), "allowed") |
| + e.ParentRefused = errors.Is(err, instancefs.ErrSymlink) |
| + _, err = instancefs.ReadBeneath(dir, "../allowed") |
| + e.EscapeRefused = errors.Is(err, instancefs.ErrEscapes) |
| + return e, nil |
| +} |
| + |
| +func gvisorGuestApp() error { |
| + // Every guest wait has its own deadline, including a lost host connection. |
| + timer := time.AfterFunc(25*time.Second, func() { os.Exit(74) }) |
| + defer timer.Stop() |
| + e, err := gvisorGuestEvidenceNow("/data/instances/" + gvisorFixtureHost) |
| + if err != nil { |
| + return err |
| + } |
| + sigs := make(chan os.Signal, 1) |
| + signal.Notify(sigs, syscall.SIGTERM) |
| + defer signal.Stop(sigs) |
| + l, err := net.ListenUnix("unix", &net.UnixAddr{Name: "/run/carlos/instances/" + gvisorFixtureHost + "/app.sock", Net: "unix"}) |
| + if err != nil { |
| + return err |
| + } |
| + defer l.Close() |
| + l.SetDeadline(time.Now().Add(15 * time.Second)) |
| + conn, err := l.AcceptUnix() |
| + if err != nil { |
| + return err |
| + } |
| + conn.SetDeadline(time.Now().Add(3 * time.Second)) |
| + err = json.NewEncoder(conn).Encode(e) |
| + conn.Close() |
| + if err != nil { |
| + return err |
| + } |
| + select { |
| + case <-sigs: |
| + return nil |
| + case <-time.After(15 * time.Second): |
| + return errors.New("guest stop timeout") |
| + } |
| +} |
| + |
| +func gvisorCompilerApp() error { |
| + // A compiler-shaped witness: read source, fork/exec a child, map executable |
| + // memory, and write an output. Task 9 supplies the real offline Go toolchain. |
| + b, err := os.ReadFile("/work/src/input") |
| + if err != nil { |
| + return err |
| + } |
| + if string(b) != "fixture source" { |
| + return errors.New("unexpected source") |
| + } |
| + if err := os.WriteFile("/work/src/forbidden", nil, 0600); !errors.Is(err, syscall.EROFS) { |
| + return fmt.Errorf("source write: %v", err) |
| + } |
| + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| + defer cancel() |
| + if err := exec.CommandContext(ctx, "/opt/carlos/app", "gvisor-test-child").Run(); err != nil { |
| + return err |
| + } |
| + mem, err := unix.Mmap(-1, 0, 4096, unix.PROT_READ|unix.PROT_WRITE|unix.PROT_EXEC, unix.MAP_PRIVATE|unix.MAP_ANON) |
| + if err != nil { |
| + return err |
| + } |
| + if err := unix.Munmap(mem); err != nil { |
| + return err |
| + } |
| + e, err := gvisorGuestEvidenceNow("/work/out") |
| + if err != nil { |
| + return err |
| + } |
| + raw, err := json.Marshal(e) |
| + if err != nil { |
| + return err |
| + } |
| + fmt.Fprintln(os.Stderr, "compiler-shaped diagnostics") |
| + return os.WriteFile("/work/out/evidence.json", raw, 0600) |
| +} |
| + |
| +type gvisorFixture struct { |
| + t *testing.T |
| + uid, gid int |
| + runtime string |
| + rootStat unix.Stat_t |
| + nofile unix.Rlimit |
| + serial int |
| +} |
| + |
| +func gvisorCommand(timeout time.Duration, name string, args ...string) (string, error) { |
| + ctx, cancel := context.WithTimeout(context.Background(), timeout) |
| + defer cancel() |
| + cmd := exec.CommandContext(ctx, name, args...) |
| + cmd.WaitDelay = 2 * time.Second |
| + b, err := cmd.CombinedOutput() |
| + return string(b), err |
| +} |
| + |
| +func newGVisorFixture(t *testing.T) *gvisorFixture { |
| + t.Helper() |
| + if os.Geteuid() != 0 { |
| + t.Fatal("root is required") |
| + } |
| + if b, err := os.ReadFile("/proc/1/comm"); err != nil || strings.TrimSpace(string(b)) != "systemd" { |
| + t.Fatalf("systemd PID 1 required: %q %v", b, err) |
| + } |
| + if _, err := os.Stat("/sys/fs/cgroup/cgroup.controllers"); err != nil { |
| + t.Fatalf("cgroup v2 required: %v", err) |
| + } |
| + f := &gvisorFixture{t: t} |
| + slice, err := gvisorCommand(5*time.Second, "systemctl", "show", "carlos-gvisor-fixture.slice", "--property=ActiveState", "--property=ControlGroup", "--property=FragmentPath") |
| + sliceProperties := gvisorProperties(slice) |
| + if err != nil || sliceProperties["ActiveState"] != "inactive" || sliceProperties["ControlGroup"] != "" || sliceProperties["FragmentPath"] != "" { |
| + t.Fatalf("fixture slice already exists: %s %v", slice, err) |
| + } |
| + t.Cleanup(func() { |
| + if out, err := gvisorCommand(10*time.Second, "systemctl", "stop", "carlos-gvisor-fixture.slice"); err != nil { |
| + t.Errorf("slice cleanup: %s %v", out, err) |
| + } |
| + }) |
| + // Refuse production paths before creating anything. Cleanup owns only roots |
| + // successfully created here, and never removes a pre-existing path. |
| + roots := []string{"/opt/carlos", "/var/lib/carlos", "/run/carlos-control", "/run/carlos-runsc", "/run/carlos", "/data"} |
| + for _, p := range roots { |
| + if _, err := os.Lstat(p); !errors.Is(err, os.ErrNotExist) { |
| + t.Fatalf("fixture refuses existing path %s: %v", p, err) |
| + } |
| + } |
| + if _, err := user.Lookup("carlos"); err == nil { |
| + t.Fatal("fixture refuses existing carlos user") |
| + } else { |
| + var missing user.UnknownUserError |
| + if !errors.As(err, &missing) { |
| + t.Fatal(err) |
| + } |
| + } |
| + if _, err := user.LookupGroup("carlos"); err == nil { |
| + t.Fatal("fixture refuses existing carlos group") |
| + } else { |
| + var missing user.UnknownGroupError |
| + if !errors.As(err, &missing) { |
| + t.Fatal(err) |
| + } |
| + } |
| + for _, p := range roots { |
| + if err := os.Mkdir(p, 0755); err != nil { |
| + t.Fatal(err) |
| + } |
| + p := p |
| + t.Cleanup(func() { |
| + if err := os.RemoveAll(p); err != nil { |
| + t.Errorf("remove owned %s: %v", p, err) |
| + } |
| + }) |
| + } |
| + if out, err := gvisorCommand(10*time.Second, "groupadd", "--system", "carlos"); err != nil { |
| + t.Fatalf("groupadd: %s %v", out, err) |
| + } |
| + t.Cleanup(func() { |
| + if _, err := user.LookupGroup("carlos"); err != nil { |
| + var missing user.UnknownGroupError |
| + if errors.As(err, &missing) { |
| + return // userdel may remove the private group itself. |
| + } |
| + t.Errorf("group cleanup lookup: %v", err) |
| + return |
| + } |
| + if out, err := gvisorCommand(10*time.Second, "groupdel", "carlos"); err != nil { |
| + t.Errorf("group cleanup: %s %v", out, err) |
| + } |
| + }) |
| + if out, err := gvisorCommand(10*time.Second, "useradd", "--system", "--gid", "carlos", "--no-create-home", "--home-dir", "/nonexistent", "--shell", "/usr/sbin/nologin", "carlos"); err != nil { |
| + t.Fatalf("useradd: %s %v", out, err) |
| + } |
| + t.Cleanup(func() { |
| + if out, err := gvisorCommand(10*time.Second, "userdel", "carlos"); err != nil { |
| + t.Errorf("user cleanup: %s %v", out, err) |
| + } |
| + }) |
| + u, err := user.Lookup("carlos") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + f.uid, err = strconv.Atoi(u.Uid) |
| + if err != nil || f.uid == 0 { |
| + t.Fatal("invalid uid", u) |
| + } |
| + f.gid, err = strconv.Atoi(u.Gid) |
| + if err != nil || f.gid == 0 { |
| + t.Fatal("invalid gid", u) |
| + } |
| + for _, p := range []string{gvisorFixtureRootfs, "/run/carlos-control/oci", "/opt/carlos/live", "/data/instances/" + gvisorFixtureHost, "/run/carlos/instances/" + gvisorFixtureHost, "/data/instances/_probe", "/run/carlos/instances/_probe", "/var/lib/carlos/work/src", "/var/lib/carlos/work/out", "/var/lib/carlos/work/tmp", "/var/lib/carlos/work/home", "/var/lib/carlos/work/cache"} { |
| + if err := os.MkdirAll(p, 0755); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + for _, p := range []string{"/data/instances/" + gvisorFixtureHost, "/run/carlos/instances/" + gvisorFixtureHost, "/data/instances/_probe", "/run/carlos/instances/_probe", "/var/lib/carlos/work/out", "/var/lib/carlos/work/tmp", "/var/lib/carlos/work/home", "/var/lib/carlos/work/cache"} { |
| + if err := os.Chown(p, f.uid, f.gid); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := os.Chmod(p, 0700); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + if err := os.Chmod("/run/carlos-control", 0700); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := os.Chmod("/run/carlos-runsc", 0700); err != nil { |
| + t.Fatal(err) |
| + } |
| + self, err := os.Executable() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + in, err := os.Open(self) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + defer in.Close() |
| + out, err := os.OpenFile("/opt/carlos/carlos", os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0755) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + _, err = io.Copy(out, in) |
| + cerr := out.Close() |
| + if err != nil || cerr != nil { |
| + t.Fatal(err, cerr) |
| + } |
| + if err := os.Link("/opt/carlos/carlos", "/opt/carlos/app"); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := os.Symlink("../app", "/opt/carlos/live/"+gvisorFixtureHost); err != nil { |
| + t.Fatal(err) |
| + } |
| + f.writeJSON("/data/instances/"+gvisorFixtureHost+"/launch.run.json", instancectl.Launch{Schema: instancectl.LaunchSchema, Host: gvisorFixtureHost, Argv: []string{instanceexec.LiveDir + "/" + gvisorFixtureHost, "gvisor-test-app"}, Env: []string{"GOMEMLIMIT=1", "GOMEMLIMIT=off"}}, 0600) |
| + if err := os.Chown("/data/instances/"+gvisorFixtureHost+"/launch.run.json", f.uid, f.gid); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := os.WriteFile("/var/lib/carlos/work/src/input", []byte("fixture source"), 0444); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := unix.Stat(gvisorFixtureRootfs, &f.rootStat); err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(f.assertRootfs) |
| + f.runtime = f.fetchRunsc() |
| + help, err := gvisorCommand(10*time.Second, f.runtime, "flags") |
| + if err != nil { |
| + t.Fatalf("runsc flags: %s %v", help, err) |
| + } |
| + if !strings.Contains(help, `(default "systrap")`) { |
| + t.Fatalf("locked runsc does not default to systrap: %s", help) |
| + } |
| + t.Log("locked runsc default platform: systrap") |
| + // Native templates omit LimitNOFILE: these are systemd's inherited defaults. |
| + defaults, err := gvisorCommand(10*time.Second, "systemctl", "show", "--property=DefaultLimitNOFILE", "--property=DefaultLimitNOFILESoft") |
| + if err != nil { |
| + t.Fatal(defaults, err) |
| + } |
| + vals := gvisorProperties(defaults) |
| + f.nofile.Cur, err = strconv.ParseUint(vals["DefaultLimitNOFILESoft"], 10, 64) |
| + if err != nil { |
| + t.Fatal(defaults, err) |
| + } |
| + f.nofile.Max, err = strconv.ParseUint(vals["DefaultLimitNOFILE"], 10, 64) |
| + if err != nil { |
| + t.Fatal(defaults, err) |
| + } |
| + t.Logf("native inherited RLIMIT_NOFILE soft=%d hard=%d", f.nofile.Cur, f.nofile.Max) |
| + return f |
| +} |
| + |
| +func (f *gvisorFixture) writeJSON(path string, v any, mode os.FileMode) { |
| + f.t.Helper() |
| + b, err := json.MarshalIndent(v, "", " ") |
| + if err != nil { |
| + f.t.Fatal(err) |
| + } |
| + h, err := os.OpenFile(path, os.O_CREATE|os.O_EXCL|os.O_WRONLY, mode) |
| + if err != nil { |
| + f.t.Fatal(err) |
| + } |
| + _, err = h.Write(b) |
| + cerr := h.Close() |
| + if err != nil || cerr != nil { |
| + f.t.Fatal(err, cerr) |
| + } |
| +} |
| + |
| +func (f *gvisorFixture) assertRootfs() { |
| + f.t.Helper() |
| + entries, err := os.ReadDir(gvisorFixtureRootfs) |
| + if err != nil || len(entries) != 0 { |
| + f.t.Errorf("rootfs changed: %v %v", entries, err) |
| + } |
| + var st unix.Stat_t |
| + if err := unix.Stat(gvisorFixtureRootfs, &st); err != nil { |
| + f.t.Error(err) |
| + return |
| + } |
| + if st.Uid != 0 || st.Gid != 0 || st.Mode&0777 != 0755 || st.Ino != f.rootStat.Ino || st.Dev != f.rootStat.Dev || st.Mtim != f.rootStat.Mtim || st.Ctim != f.rootStat.Ctim { |
| + f.t.Errorf("rootfs identity changed: before=%+v after=%+v", f.rootStat, st) |
| + } |
| +} |
| + |
| +func (f *gvisorFixture) fetchRunsc() string { |
| + t := f.t |
| + t.Helper() |
| + pin, err := execsandbox.RunscFor("linux-" + runtime.GOARCH) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + // The sole external test network exception is this pinned HTTPS archive. |
| + // Disable redirects and hash the compressed archive before decoding it. |
| + ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) |
| + defer cancel() |
| + req, err := http.NewRequestWithContext(ctx, "GET", pin.TarballURL, nil) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + client := &http.Client{Timeout: 60 * time.Second, CheckRedirect: func(*http.Request, []*http.Request) error { return errors.New("redirect refused") }} |
| + resp, err := client.Do(req) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + defer resp.Body.Close() |
| + if resp.StatusCode != 200 { |
| + t.Fatal(resp.Status) |
| + } |
| + raw, err := io.ReadAll(io.LimitReader(resp.Body, (128<<20)+1)) |
| + if err != nil || len(raw) > 128<<20 { |
| + t.Fatal("archive bounds", err) |
| + } |
| + sum := sha512.Sum512(raw) |
| + if hex.EncodeToString(sum[:]) != pin.TarballSHA512 { |
| + t.Fatal("archive SHA512 mismatch") |
| + } |
| + z, err := zstd.NewReader(bytes.NewReader(raw), zstd.WithDecoderMaxMemory(256<<20)) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + defer z.Close() |
| + tr := tar.NewReader(io.LimitReader(z, 512<<20)) |
| + wanted := map[string]string{} |
| + for _, member := range pin.Files { |
| + wanted[member.Path] = member.SHA256 |
| + } |
| + binaries := map[string][]byte{} |
| + for { |
| + h, err := tr.Next() |
| + if err == io.EOF { |
| + break |
| + } |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + want, ok := wanted[h.Name] |
| + if !ok { |
| + continue |
| + } |
| + if _, duplicate := binaries[h.Name]; duplicate || h.Typeflag != tar.TypeReg || h.Size <= 0 || h.Size > 96<<20 { |
| + t.Fatalf("invalid runtime member %s", h.Name) |
| + } |
| + binary, err := io.ReadAll(io.LimitReader(tr, (96<<20)+1)) |
| + if err != nil || int64(len(binary)) != h.Size { |
| + t.Fatal("runtime member length", err) |
| + } |
| + sha := sha256.Sum256(binary) |
| + if hex.EncodeToString(sha[:]) != want { |
| + t.Fatalf("runtime member SHA256 mismatch: %s", h.Name) |
| + } |
| + binaries[h.Name] = binary |
| + } |
| + if len(binaries) != len(pin.Files) { |
| + t.Fatal("runtime member missing") |
| + } |
| + setDir := execsandbox.RunscDir(pin) |
| + if err := os.Mkdir("/opt/carlos/runsc", 0755); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := os.Mkdir(setDir, 0755); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := os.Mkdir(filepath.Join(setDir, "gvisor-bin"), 0755); err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, member := range pin.Files { |
| + path := filepath.Join(setDir, member.Path) |
| + h, err := os.OpenFile(path, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0755) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + _, err = h.Write(binaries[member.Path]) |
| + cerr := h.Close() |
| + if err != nil || cerr != nil { |
| + t.Fatal(err, cerr) |
| + } |
| + var st unix.Stat_t |
| + if err := unix.Lstat(path, &st); err != nil { |
| + t.Fatal(err) |
| + } |
| + if st.Uid != 0 || st.Gid != 0 || st.Mode != unix.S_IFREG|0755 || st.Nlink != 1 { |
| + t.Fatalf("invalid installed member metadata: %s %+v", member.Path, st) |
| + } |
| + t.Logf("verified runtime member %s SHA256=%s", member.Path, member.SHA256) |
| + } |
| + for _, path := range []string{"/opt", "/opt/carlos", "/opt/carlos/runsc", setDir, filepath.Join(setDir, "gvisor-bin")} { |
| + var st unix.Stat_t |
| + if err := unix.Lstat(path, &st); err != nil { |
| + t.Fatal(err) |
| + } |
| + if st.Uid != 0 || st.Gid != 0 || st.Mode != unix.S_IFDIR|0755 { |
| + t.Fatalf("invalid runtime directory metadata: %s %+v", path, st) |
| + } |
| + } |
| + t.Logf("verified pinned runtime linux-%s SetID=%s", runtime.GOARCH, pin.SetID()) |
| + return execsandbox.RunscPath(pin) |
| +} |
| + |
| +func gvisorProperties(raw string) map[string]string { |
| + out := map[string]string{} |
| + for _, line := range strings.Split(raw, "\n") { |
| + k, v, ok := strings.Cut(line, "=") |
| + if ok { |
| + out[k] = v |
| + } |
| + } |
| + return out |
| +} |
| + |
| +func (f *gvisorFixture) bundle(kind, id string) string { |
| + t := f.t |
| + t.Helper() |
| + iid := gvisorFixtureHost |
| + args := []string{"/opt/carlos/carlos", "instance-exec", "--sandbox=gvisor", "run", iid} |
| + env := []string{"GOMEMLIMIT=241591905"} |
| + cwd := "/data/instances/" + iid |
| + if kind == "probe" { |
| + iid = "_probe" |
| + cwd = "/data/instances/_probe" |
| + args = []string{"/opt/carlos/carlos", "instance-probe", "--sandbox=gvisor"} |
| + } |
| + if kind == "build" { |
| + args = []string{"/opt/carlos/app", "gvisor-test-compiler"} |
| + cwd = "/work/src" |
| + env = []string{"GOMEMLIMIT=966367638"} |
| + } |
| + mount := func(dst, typ, src string, opts ...string) map[string]any { |
| + return map[string]any{"destination": dst, "type": typ, "source": src, "options": opts} |
| + } |
| + mounts := []map[string]any{ |
| + mount("/proc", "proc", "proc", "nosuid", "noexec", "nodev"), |
| + mount("/dev", "tmpfs", "tmpfs", "nosuid", "strictatime", "mode=755", "size=65536k"), |
| + mount("/dev/pts", "devpts", "devpts", "nosuid", "noexec", "newinstance", "ptmxmode=0666", "mode=0620"), |
| + mount("/dev/shm", "tmpfs", "shm", "nosuid", "noexec", "nodev", "mode=1777", "size=65536k"), |
| + mount("/tmp", "tmpfs", "tmpfs", "nosuid", "nodev", "mode=1777"), |
| + mount("/opt/carlos/carlos", "bind", "/opt/carlos/carlos", "bind", "ro"), |
| + mount("/opt/carlos/app", "bind", "/opt/carlos/app", "bind", "ro"), |
| + mount("/opt/carlos/live", "bind", "/opt/carlos/live", "bind", "ro"), |
| + } |
| + if kind == "build" { |
| + for _, dir := range []string{"src", "out", "tmp", "home", "cache"} { |
| + mode := "rw" |
| + if dir == "src" { |
| + mode = "ro" |
| + } |
| + mounts = append(mounts, mount("/work/"+dir, "bind", "/var/lib/carlos/work/"+dir, "bind", mode, "nosuid", "nodev")) |
| + } |
| + } else { |
| + for _, root := range []string{"/data/instances/", "/run/carlos/instances/"} { |
| + mounts = append(mounts, mount(root+iid, "bind", root+iid, "bind", "rw", "nosuid", "nodev")) |
| + } |
| + } |
| + caps := map[string]any{} |
| + for _, k := range []string{"bounding", "effective", "inheritable", "permitted", "ambient"} { |
| + caps[k] = []string{} |
| + } |
| + ns := []map[string]string{} |
| + for _, typ := range []string{"pid", "ipc", "uts", "mount", "network"} { |
| + ns = append(ns, map[string]string{"type": typ}) |
| + } |
| + rlimits := []map[string]any{{"type": "RLIMIT_NOFILE", "soft": f.nofile.Cur, "hard": f.nofile.Max}} |
| + user := map[string]any{"uid": f.uid, "gid": f.gid, "additionalGids": []int{}} |
| + if kind == "build" { |
| + user["umask"] = 63 |
| + rlimits = append(rlimits, map[string]any{"type": "RLIMIT_FSIZE", "soft": 33554432, "hard": 33554432}) |
| + } |
| + config := map[string]any{"ociVersion": "1.0.2", "root": map[string]any{"path": gvisorFixtureRootfs, "readonly": true}, "process": map[string]any{"terminal": false, "user": user, "args": args, "env": env, "cwd": cwd, "capabilities": caps, "noNewPrivileges": true, "rlimits": rlimits}, "mounts": mounts, "linux": map[string]any{"namespaces": ns}} |
| + path := execsandbox.BundleDir(id) |
| + if err := os.Mkdir(path, 0700); err != nil { |
| + t.Fatal(err) |
| + } |
| + f.writeJSON(filepath.Join(path, "config.json"), config, 0600) |
| + return path |
| +} |
diff --git a/internal/host/gvisor_hardening_rootrunner_linux_test.go b/internal/host/gvisor_hardening_rootrunner_linux_test.go| new file mode 100644 |
| index 000000000..aeca1b18a |
| --- /dev/null |
| +++ b/internal/host/gvisor_hardening_rootrunner_linux_test.go |
| @@ -0,0 +1,470 @@ |
| +//go:build linux && rootrunner |
| + |
| +package host |
| + |
| +import ( |
| + "encoding/json" |
| + "errors" |
| + "fmt" |
| + "net" |
| + "os" |
| + "path/filepath" |
| + "strconv" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/instancectl" |
| + "golang.org/x/sys/unix" |
| +) |
| + |
| +// Measurement candidates only. Promote to execsandbox's pinned contract and |
| +// embedded templates only after the real trampoline passes on the root runner. |
| +const gvisorCandidateHardening = `ProtectSystem=strict |
| +ProtectHome=yes |
| +PrivateTmp=yes |
| +ProtectKernelTunables=yes |
| +ProtectKernelModules=yes |
| +ProtectKernelLogs=yes |
| +ProtectClock=yes |
| +ProtectHostname=yes |
| +ProtectControlGroups=yes |
| +LockPersonality=yes |
| +RestrictRealtime=yes |
| +SystemCallArchitectures=native |
| +` |
| + |
| +func TestRootGVisorHardening(t *testing.T) { |
| + f := newGVisorFixture(t) |
| + for _, kind := range []string{"run", "probe", "build"} { |
| + if !t.Run(kind, func(t *testing.T) { |
| + caseFixture := *f |
| + f := &caseFixture |
| + f.t = t |
| + unit := f.start(kind) |
| + f.checkHardening(unit) |
| + f.exercise(kind, unit) |
| + f.stop(unit) |
| + f.assertRootfs() |
| + }) { |
| + t.Fatal("candidate hardening/guest contract refused; no property removed") |
| + } |
| + } |
| +} |
| + |
| +func TestRootGVisorTrampoline(t *testing.T) { |
| + f := newGVisorFixture(t) |
| + unit := f.start("run") |
| + f.checkHardening(unit) |
| + f.exercise("run", unit) |
| + f.stop(unit) |
| + f.assertRootfs() |
| +} |
| + |
| +func (f *gvisorFixture) start(kind string) string { |
| + t := f.t |
| + t.Helper() |
| + f.serial++ |
| + id := fmt.Sprintf("fixture-%s-%d", kind, f.serial) |
| + bundle := f.bundle(kind, id) |
| + unit := "carlos-gvisor-" + id + ".service" |
| + path := "/run/systemd/system/" + unit |
| + load, err := gvisorCommand(5*time.Second, "systemctl", "show", unit, "--property=LoadState", "--value") |
| + if err != nil || strings.TrimSpace(load) != "not-found" { |
| + t.Fatalf("fixture unit already loaded: %s %v", load, err) |
| + } |
| + skeleton := gvisorRunSkeleton |
| + if kind == "probe" { |
| + skeleton = gvisorProbeSkeleton |
| + } |
| + if kind == "build" { |
| + skeleton = gvisorBuildSkeleton |
| + } |
| + var lines []string |
| + for _, line := range strings.Split(skeleton, "\n") { |
| + if strings.HasPrefix(line, "BindsTo=") || strings.HasPrefix(line, "Requires=") || strings.HasPrefix(line, "After=") { |
| + continue |
| + } |
| + if strings.HasPrefix(line, "Slice=") { |
| + line = "Slice=carlos-gvisor-fixture.slice" |
| + } |
| + line = strings.ReplaceAll(line, "%I", gvisorFixtureHost) |
| + line = strings.ReplaceAll(line, "%i", gvisorFixtureHost) |
| + if strings.HasPrefix(line, "StandardOutput=") && kind == "run" { |
| + line = "StandardOutput=journal" |
| + } |
| + lines = append(lines, line) |
| + } |
| + // The fixture substitutes only deployment dependencies, slice and log sink. |
| + // All candidate hardening, limits and the runsc recipe stay as specified. |
| + body := strings.Join(lines, "\n") + "\n" + gvisorCandidateHardening + "\nExecStartPre=-" + f.runtime + " --root=/run/carlos-runsc delete -force " + id + "\nExecStart=" + f.runtime + " --root=/run/carlos-runsc --ignore-cgroups --network=none --host-uds=create run --bundle " + bundle + " " + id + "\n" |
| + if kind == "run" { |
| + body += "ExecStopPost=/opt/carlos/carlos instance-exit --sandbox=gvisor run " + gvisorFixtureHost + "\n" |
| + } |
| + body += "ExecStopPost=-" + f.runtime + " --root=/run/carlos-runsc delete -force " + id + "\n" |
| + if kind == "build" { |
| + body += "ReadWritePaths=/var/lib/carlos/work/out /var/lib/carlos/work/tmp /var/lib/carlos/work/home /var/lib/carlos/work/cache\nStandardOutput=truncate:/var/lib/carlos/work/diagnostics\nStandardError=inherit\n" |
| + } |
| + h, err := os.OpenFile(path, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0644) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + _, err = h.WriteString(body) |
| + cerr := h.Close() |
| + if err != nil || cerr != nil { |
| + t.Fatal(err, cerr) |
| + } |
| + t.Cleanup(func() { |
| + if t.Failed() { |
| + f.diagnostics(unit) |
| + } |
| + if out, err := gvisorCommand(30*time.Second, "systemctl", "stop", unit); err != nil { |
| + t.Errorf("cleanup stop: %s %v", out, err) |
| + } |
| + if err := os.Remove(path); err != nil { |
| + t.Error(err) |
| + } |
| + if out, err := gvisorCommand(10*time.Second, "systemctl", "daemon-reload"); err != nil { |
| + t.Errorf("reload cleanup: %s %v", out, err) |
| + } |
| + gvisorCommand(5*time.Second, "systemctl", "reset-failed", unit) |
| + }) |
| + if out, err := gvisorCommand(10*time.Second, "systemctl", "daemon-reload"); err != nil { |
| + t.Fatalf("reload: %s %v", out, err) |
| + } |
| + if out, err := gvisorCommand(30*time.Second, "systemctl", "start", unit); err != nil { |
| + f.diagnostics(unit) |
| + t.Fatalf("start %s: %s %v", kind, out, err) |
| + } |
| + return unit |
| +} |
| + |
| +func (f *gvisorFixture) checkHardening(unit string) { |
| + t := f.t |
| + t.Helper() |
| + args := []string{"show", unit, "--property=LimitNOFILE", "--property=LimitNOFILESoft"} |
| + for name := range gvisorProperties(gvisorCandidateHardening) { |
| + args = append(args, "--property="+name) |
| + } |
| + out, err := gvisorCommand(5*time.Second, "systemctl", args...) |
| + if err != nil { |
| + t.Fatal(out, err) |
| + } |
| + t.Logf("effective %s:\n%s", unit, out) |
| + props := gvisorProperties(out) |
| + for name, want := range gvisorProperties(gvisorCandidateHardening) { |
| + got := props[name] |
| + // systemctl exposes these bool settings as yes/no; there is no generic |
| + // truthiness conversion that could hide a weaker setting. |
| + if got != want { |
| + t.Errorf("%s=%q, candidate=%q", name, got, want) |
| + } |
| + } |
| + if props["LimitNOFILE"] != strconv.FormatUint(f.nofile.Max, 10) || props["LimitNOFILESoft"] != strconv.FormatUint(f.nofile.Cur, 10) { |
| + t.Fatalf("native NOFILE defaults differ: %s", out) |
| + } |
| +} |
| + |
| +func (f *gvisorFixture) diagnostics(unit string) { |
| + f.t.Helper() |
| + out, _ := gvisorCommand(5*time.Second, "systemctl", "show", unit, "--property=ActiveState", "--property=SubState", "--property=Result", "--property=ExecMainStatus", "--property=InvocationID") |
| + f.t.Log(out) |
| + out, _ = gvisorCommand(5*time.Second, "journalctl", "-u", unit, "--no-pager", "-n", "35") |
| + f.t.Log(out) |
| + out, _ = gvisorCommand(5*time.Second, "journalctl", "-k", "--no-pager", "-n", "60") |
| + f.t.Logf("kernel diagnostics:\n%s", out) |
| + out, _ = gvisorCommand(5*time.Second, "journalctl", "-t", "systemd-coredump", "--no-pager", "-n", "20") |
| + f.t.Logf("coredump diagnostics:\n%s", out) |
| +} |
| + |
| +func (f *gvisorFixture) exercise(kind, unit string) { |
| + t := f.t |
| + t.Helper() |
| + switch kind { |
| + case "run": |
| + path := "/run/carlos/instances/" + gvisorFixtureHost + "/app.sock" |
| + deadline := time.Now().Add(12 * time.Second) |
| + var conn net.Conn |
| + var err error |
| + for time.Now().Before(deadline) { |
| + conn, err = net.DialTimeout("unix", path, 200*time.Millisecond) |
| + if err == nil { |
| + break |
| + } |
| + state, _ := gvisorCommand(2*time.Second, "systemctl", "show", unit, "--property=ActiveState", "--value") |
| + if strings.TrimSpace(state) != "active" && strings.TrimSpace(state) != "activating" { |
| + f.diagnostics(unit) |
| + t.Fatalf("real trampoline refused before host socket: %v", err) |
| + } |
| + time.Sleep(50 * time.Millisecond) |
| + } |
| + if err != nil { |
| + f.diagnostics(unit) |
| + t.Fatal(err) |
| + } |
| + defer conn.Close() |
| + conn.SetDeadline(time.Now().Add(3 * time.Second)) |
| + var e gvisorGuestEvidence |
| + if err := json.NewDecoder(conn).Decode(&e); err != nil { |
| + t.Fatal(err) |
| + } |
| + f.checkGuest(e, true, "241591905") |
| + case "probe": |
| + f.waitFinished(unit, false) |
| + raw, err := os.ReadFile("/run/carlos-control/gvisor-probe.out") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + var report instancectl.ProbeReport |
| + if err := json.Unmarshal(raw, &report); err != nil { |
| + t.Fatalf("probe output %q: %v", raw, err) |
| + } |
| + found := map[string]bool{} |
| + for _, line := range report.Lines { |
| + found[line.Check] = true |
| + if line.Check == "gvisor-readiness" { |
| + continue |
| + } |
| + if line.Verdict != "ok" { |
| + t.Errorf("probe %s: %s %s", line.Check, line.Verdict, line.Detail) |
| + } |
| + } |
| + for _, name := range []string{"guest-nonroot", "CapEff", "CapBnd", "NoNewPrivs", "openat2"} { |
| + if !found[name] { |
| + t.Errorf("missing probe check %s", name) |
| + } |
| + } |
| + if report.Ready { |
| + t.Error("measurement probe claimed complete readiness") |
| + } |
| + case "build": |
| + f.waitFinished(unit, true) |
| + raw, err := os.ReadFile("/var/lib/carlos/work/out/evidence.json") |
| + if err != nil { |
| + f.diagnostics(unit) |
| + t.Fatal(err) |
| + } |
| + var e gvisorGuestEvidence |
| + if err := json.Unmarshal(raw, &e); err != nil { |
| + t.Fatal(err) |
| + } |
| + f.checkGuest(e, false, "966367638") |
| + diagnostics, err := os.ReadFile("/var/lib/carlos/work/diagnostics") |
| + if err != nil || !strings.Contains(string(diagnostics), "compiler-shaped diagnostics") { |
| + t.Fatalf("compiler diagnostics: %q %v", diagnostics, err) |
| + } |
| + } |
| +} |
| + |
| +func (f *gvisorFixture) checkGuest(e gvisorGuestEvidence, child bool, limit string) { |
| + t := f.t |
| + t.Helper() |
| + t.Logf("guest evidence: %+v", e) |
| + if e.UID != f.uid || e.GID != f.gid { |
| + t.Errorf("guest identity %d:%d, want carlos %d:%d", e.UID, e.GID, f.uid, f.gid) |
| + } |
| + if child && (e.PPID != 1 || e.PID == 1) { |
| + t.Errorf("trampoline did not supervise guest: pid=%d ppid=%d", e.PID, e.PPID) |
| + } |
| + if e.MemoryLimit != limit { |
| + t.Errorf("GOMEMLIMIT=%q want %s", e.MemoryLimit, limit) |
| + } |
| + props := map[string]string{} |
| + for _, line := range strings.Split(e.Status, "\n") { |
| + k, v, _ := strings.Cut(line, ":") |
| + props[k] = strings.TrimSpace(v) |
| + } |
| + for _, name := range []string{"CapInh", "CapPrm", "CapEff", "CapBnd", "CapAmb"} { |
| + if props[name] != "0000000000000000" { |
| + t.Errorf("guest %s=%q", name, props[name]) |
| + } |
| + } |
| + if props["NoNewPrivs"] != "1" { |
| + t.Errorf("guest NoNewPrivs=%q", props["NoNewPrivs"]) |
| + } |
| + if e.Limits != f.nofile { |
| + t.Errorf("guest NOFILE=%+v native=%+v", e.Limits, f.nofile) |
| + } |
| + if !e.Permitted || !e.LeafRefused || !e.ParentRefused || !e.EscapeRefused { |
| + t.Error("guest openat2 contract failed") |
| + } |
| +} |
| + |
| +func (f *gvisorFixture) waitFinished(unit string, remain bool) { |
| + t := f.t |
| + t.Helper() |
| + deadline := time.Now().Add(15 * time.Second) |
| + for time.Now().Before(deadline) { |
| + out, err := gvisorCommand(3*time.Second, "systemctl", "show", unit, "--property=ActiveState", "--property=SubState", "--property=ExecMainStatus", "--property=Result") |
| + if err != nil { |
| + t.Fatal(out, err) |
| + } |
| + p := gvisorProperties(out) |
| + if p["ActiveState"] == "failed" { |
| + f.diagnostics(unit) |
| + t.Fatalf("guest refused: %s", out) |
| + } |
| + if p["ActiveState"] == "inactive" || remain && p["SubState"] == "exited" { |
| + if p["ExecMainStatus"] != "0" || p["Result"] != "success" { |
| + t.Fatal(out) |
| + } |
| + return |
| + } |
| + time.Sleep(50 * time.Millisecond) |
| + } |
| + f.diagnostics(unit) |
| + t.Fatal("bounded guest completion timed out") |
| +} |
| + |
| +func (f *gvisorFixture) stop(unit string) { |
| + t := f.t |
| + t.Helper() |
| + before, err := gvisorCommand(5*time.Second, "systemctl", "show", unit, "--property=InvocationID", "--property=ControlGroup") |
| + if err != nil { |
| + t.Fatal(before, err) |
| + } |
| + p := gvisorProperties(before) |
| + if out, err := gvisorCommand(30*time.Second, "systemctl", "stop", unit); err != nil { |
| + t.Fatalf("stop: %s %v", out, err) |
| + } |
| + f.waitFinished(unit, false) |
| + if cg := p["ControlGroup"]; cg != "" { |
| + err := filepath.WalkDir(filepath.Join("/sys/fs/cgroup", cg), func(path string, d os.DirEntry, err error) error { |
| + if errors.Is(err, os.ErrNotExist) { |
| + return nil |
| + } |
| + if err != nil { |
| + return err |
| + } |
| + if d.Name() == "cgroup.procs" { |
| + b, err := os.ReadFile(path) |
| + if err != nil { |
| + return err |
| + } |
| + if len(strings.TrimSpace(string(b))) != 0 { |
| + return fmt.Errorf("nonempty cgroup %s: %s", path, b) |
| + } |
| + } |
| + return nil |
| + }) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + if strings.Contains(unit, "fixture-run-") { |
| + path := "/run/carlos/instances/" + gvisorFixtureHost + "/" + instancectl.ExitRecordName(instancectl.RoleRun, p["InvocationID"]) |
| + raw, err := os.ReadFile(path) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + var rec instancectl.ExitRecord |
| + if err := json.Unmarshal(raw, &rec); err != nil { |
| + t.Fatal(err) |
| + } |
| + if rec.Invocation != p["InvocationID"] || rec.Result != "success" || rec.Status != "0" { |
| + t.Fatalf("exit hook record: %s", raw) |
| + } |
| + var st unix.Stat_t |
| + if err := unix.Stat(path, &st); err != nil { |
| + t.Fatal(err) |
| + } |
| + if st.Uid != uint32(f.uid) || st.Gid != uint32(f.gid) || st.Mode&0777 != 0600 { |
| + t.Fatalf("exit owner/mode: %+v", st) |
| + } |
| + var keys map[string]any |
| + json.Unmarshal(raw, &keys) |
| + if _, ok := keys["kind"]; ok { |
| + t.Fatal("exit record gained kind") |
| + } |
| + } |
| +} |
| + |
| +const gvisorRunSkeleton = `[Unit] |
| +Description=carlos gVisor demo instance %I |
| +BindsTo=carlos-edge.service |
| +Requires=data-instances.mount run-carlos-instances.mount run-carlos-logs.mount |
| +After=carlos-edge.service data-instances.mount run-carlos-instances.mount run-carlos-logs.mount |
| +[Service] |
| +Type=exec |
| +User=root |
| +Group=root |
| +Slice=carlos-instances-%i.slice |
| +ExecStart= |
| +Restart=no |
| +KillMode=mixed |
| +TimeoutStopSec=20 |
| +SuccessExitStatus=129 130 141 143 |
| +StandardOutput=file:/run/carlos/logs/%I.run.sock |
| +StandardError=inherit |
| +RuntimeDirectory=carlos-runsc |
| +RuntimeDirectoryMode=0700 |
| +RuntimeDirectoryPreserve=yes |
| +ReadWritePaths=/run/carlos-runsc /data/instances/%I /run/carlos/instances/%I |
| +TasksMax=320 |
| +OOMScoreAdjust=500 |
| +OOMPolicy=kill |
| +` |
| + |
| +const gvisorProbeSkeleton = `[Unit] |
| +Description=carlos gVisor instance probe |
| +Requires=data-instances.mount run-carlos-instances.mount |
| +After=data-instances.mount run-carlos-instances.mount |
| +[Service] |
| +Type=exec |
| +User=root |
| +Group=root |
| +Slice=carlos-instances.slice |
| +ExecStart= |
| +Restart=no |
| +KillMode=mixed |
| +RuntimeMaxSec=30 |
| +TimeoutStopSec=20 |
| +StandardOutput=truncate:/run/carlos-control/gvisor-probe.out |
| +StandardError=journal |
| +RuntimeDirectory=carlos-runsc |
| +RuntimeDirectoryMode=0700 |
| +RuntimeDirectoryPreserve=yes |
| +ReadWritePaths=/run/carlos-runsc /data/instances/_probe /run/carlos/instances/_probe |
| +MemoryMax=301989888 |
| +MemoryHigh=271790892 |
| +MemorySwapMax=301989888 |
| +TasksMax=320 |
| +CPUQuota=50% |
| +CPUWeight=50 |
| +IOWeight=50 |
| +OOMPolicy=kill |
| +` |
| + |
| +const gvisorBuildSkeleton = `[Unit] |
| +Description=carlos gVisor offline demo build |
| +BindsTo=carlos-instance-control.service |
| +After=carlos-instance-control.service |
| +[Service] |
| +Type=exec |
| +RemainAfterExit=yes |
| +User=root |
| +Group=root |
| +Slice=carlos-demo-builds.slice |
| +ExecStart= |
| +Restart=no |
| +KillMode=control-group |
| +RuntimeMaxSec=180 |
| +TimeoutStopSec=5 |
| +SendSIGKILL=yes |
| +OOMPolicy=kill |
| +MemoryMax=1107296256 |
| +MemoryHigh=996566625 |
| +MemorySwapMax=0 |
| +TasksMax=192 |
| +CPUQuota=50% |
| +CPUWeight=10 |
| +LimitFSIZE=33554432 |
| +UMask=0077 |
| +StandardInput=null |
| +StandardOutput=null |
| +StandardError=null |
| +RuntimeDirectory=carlos-runsc |
| +RuntimeDirectoryMode=0700 |
| +RuntimeDirectoryPreserve=yes |
| +ReadWritePaths=/run/carlos-runsc |
| +` |
diff --git a/internal/instanceexec/exec.go b/internal/instanceexec/exec.go| index 93a5071a0..d08388a9a 100644 |
| --- a/internal/instanceexec/exec.go |
| +++ b/internal/instanceexec/exec.go |
| @@ -17,6 +17,7 @@ import ( |
| "strings" |
| "github.com/carlosframework/platform/internal/cliflag" |
| + "github.com/carlosframework/platform/internal/execsandbox" |
| "github.com/carlosframework/platform/internal/instancectl" |
| "github.com/carlosframework/platform/internal/instancefs" |
| "github.com/carlosframework/platform/internal/provision" |
| @@ -63,10 +64,11 @@ var errUsage = errors.New("usage") |
| // execCommand is instance-exec's command line. |
| type execCommand struct { |
| - role instancectl.Role |
| - inst string |
| - rootfs bool // --rootfs: a rootfs template, the two-file launch |
| - claim string // --claim-reservation: the binary run's claim launch |
| + sandbox execsandbox.Effective |
| + role instancectl.Role |
| + inst string |
| + rootfs bool // --rootfs: a rootfs template, the two-file launch |
| + claim string // --claim-reservation: the binary run's claim launch |
| } |
| // launcher is the command line's launch. The tenant is scoped (#178, see |
| @@ -77,6 +79,8 @@ type execCommand struct { |
| // claim launch for anything but a binary run. |
| func (c execCommand) launcher() func(argv0 string, argv, env []string) error { |
| switch { |
| + case c.sandbox == execsandbox.EffectiveGVisor: |
| + return gvisorLauncher(gvisorInit, os.Getenv) |
| case c.role == instancectl.RoleTTY: |
| return ttyLaunch |
| case c.claim != "": |
| @@ -94,6 +98,7 @@ func parseExecArgs(args []string) (execCommand, error) { |
| fs.Usage = cliflag.Usage(fs, "usage: carlos instance-exec [--rootfs] <run|seed|sidecar|cmd|worker|tty> <instance-id>") |
| claim := fs.String("claim-reservation", "", "root launch reservation") |
| rootfs := fs.Bool("rootfs", false, "rootfs launch: root's launch file names the command") |
| + sandbox := fs.String("sandbox", "", "guest sandbox mode") |
| _ = fs.Parse(args) |
| if fs.NArg() != 2 { |
| fs.Usage() |
| @@ -107,6 +112,11 @@ func parseExecArgs(args []string) (execCommand, error) { |
| return execCommand{}, fmt.Errorf("instance-exec: role %q is not run, seed, sidecar or cmd (worker needs --rootfs)", fs.Arg(0)) |
| } |
| c := execCommand{role: role, inst: fs.Arg(1), rootfs: *rootfs, claim: *claim} |
| + var err error |
| + c.sandbox, err = guestSandbox(*sandbox, c.rootfs, c.claim, c.role, c.inst) |
| + if err != nil { |
| + return execCommand{}, fmt.Errorf("instance-exec: %w", err) |
| + } |
| if c.claim != "" { |
| if c.rootfs || c.claim != instancectl.ClaimExecSnapshot || role != instancectl.RoleRun || strings.Contains(c.inst, ":") { |
| return execCommand{}, errors.New("instance-exec: claim boundary refused") |
diff --git a/internal/instanceexec/exit.go b/internal/instanceexec/exit.go| index daf19e57b..83ef3b4c3 100644 |
| --- a/internal/instanceexec/exit.go |
| +++ b/internal/instanceexec/exit.go |
| @@ -12,6 +12,7 @@ import ( |
| "time" |
| "github.com/carlosframework/platform/internal/cliflag" |
| + "github.com/carlosframework/platform/internal/execsandbox" |
| "github.com/carlosframework/platform/internal/instancectl" |
| "github.com/carlosframework/platform/internal/instancefs" |
| "github.com/carlosframework/platform/internal/provision" |
| @@ -38,16 +39,22 @@ func RunExit(args []string) { |
| log.Print(err) |
| return |
| } |
| - if err := writeExitRecord(c.runDir, c.role, c.inst, os.Getenv, time.Now()); err != nil { |
| + if c.sandbox == execsandbox.EffectiveGVisor { |
| + err = writeGVisorExitRecord(c, os.Getenv, time.Now()) |
| + } else { |
| + err = writeExitRecord(c.runDir, c.role, c.inst, os.Getenv, time.Now()) |
| + } |
| + if err != nil { |
| log.Printf("instance-exit: %v", err) |
| } |
| } |
| // exitCommand is instance-exit's command line. |
| type exitCommand struct { |
| - role instancectl.Role |
| - inst string |
| - runDir string |
| + sandbox execsandbox.Effective |
| + role instancectl.Role |
| + inst string |
| + runDir string |
| } |
| // parseExitArgs is RunExit's flag and role parsing; its refusals carry |
| @@ -57,6 +64,7 @@ func parseExitArgs(args []string) (exitCommand, error) { |
| fs := flag.NewFlagSet("instance-exit", flag.ExitOnError) |
| runDir := fs.String("run-dir", provision.SocketDir, "run directory holding instances/<id>") |
| rootfs := fs.Bool("rootfs", false, "the unit is a rootfs template") |
| + sandbox := fs.String("sandbox", "", "guest sandbox mode") |
| fs.Usage = cliflag.Usage(fs, "usage: carlos instance-exit [--rootfs] <run|seed|sidecar|cmd|worker|tty> <instance-id>") |
| _ = fs.Parse(args) |
| if fs.NArg() != 2 { |
| @@ -70,13 +78,21 @@ func parseExitArgs(args []string) (exitCommand, error) { |
| case role == instancectl.RoleWorker && !*rootfs: |
| return exitCommand{}, fmt.Errorf("instance-exit: role %q is not run, seed, sidecar or cmd (worker needs --rootfs)", fs.Arg(0)) |
| } |
| - return exitCommand{role: role, inst: fs.Arg(1), runDir: *runDir}, nil |
| + mode, err := guestSandbox(*sandbox, *rootfs, "", role, fs.Arg(1)) |
| + if err != nil { |
| + return exitCommand{}, fmt.Errorf("instance-exit: %w", err) |
| + } |
| + return exitCommand{sandbox: mode, role: role, inst: fs.Arg(1), runDir: *runDir}, nil |
| } |
| // writeExitRecord writes exit.<role>.<invocation>.json with O_EXCL into |
| // <runDir>/instances/<iid>. A missing invocation id is a no-op (the |
| // variables are systemd's to provide); a malformed one is an error. |
| func writeExitRecord(runDir string, role instancectl.Role, inst string, env func(string) string, now time.Time) error { |
| + return writeExitRecordAs(runDir, role, inst, env, now, nil) |
| +} |
| + |
| +func writeExitRecordAs(runDir string, role instancectl.Role, inst string, env func(string) string, now time.Time, own func(*os.File) error) error { |
| inv := env("INVOCATION_ID") |
| if inv == "" { |
| return nil |
| @@ -112,6 +128,12 @@ func writeExitRecord(runDir string, role instancectl.Role, inst string, env func |
| } |
| return err |
| } |
| + if own != nil { |
| + if err := own(f); err != nil { |
| + f.Close() |
| + return err |
| + } |
| + } |
| if _, err := f.Write(raw); err != nil { |
| f.Close() |
| return err |
diff --git a/internal/instanceexec/probe.go b/internal/instanceexec/probe.go| index 7e6644b6e..4938dccdc 100644 |
| --- a/internal/instanceexec/probe.go |
| +++ b/internal/instanceexec/probe.go |
| @@ -117,9 +117,17 @@ func RunProbe(args []string) { |
| fs := flag.NewFlagSet("instance-probe", flag.ExitOnError) |
| fs.Usage = cliflag.Usage(fs, "usage: carlos instance-probe [--rootfs]") |
| rootfs := fs.Bool("rootfs", false, "the rootfs probe's checks, from inside the probe image (carlos-instance-rootfs-probe.service)") |
| + sandbox := fs.String("sandbox", "", "guest sandbox mode") |
| _ = fs.Parse(args) |
| var r instancectl.ProbeReport |
| - if *rootfs { |
| + if *sandbox != "" { |
| + _, err := guestSandbox(*sandbox, *rootfs, "", instancectl.RoleRun, "probe") |
| + if err != nil { |
| + r.Lines = []instancectl.VerdictLine{{Check: "sandbox", Verdict: "fail", Detail: err.Error()}} |
| + } else { |
| + r = gvisorProbeChecks() |
| + } |
| + } else if *rootfs { |
| r = runRootfsChecks(productionRootfsProbeEnv()) |
| } else { |
| r = runChecks(productionProbeEnv()) |
diff --git a/internal/instanceexec/sandbox.go b/internal/instanceexec/sandbox.go| new file mode 100644 |
| index 000000000..410aee4e9 |
| --- /dev/null |
| +++ b/internal/instanceexec/sandbox.go |
| @@ -0,0 +1,51 @@ |
| +package instanceexec |
| + |
| +import ( |
| + "errors" |
| + "strings" |
| + |
| + "github.com/carlosframework/platform/internal/execsandbox" |
| + "github.com/carlosframework/platform/internal/instancectl" |
| +) |
| + |
| +func guestSandbox(mode string, rootfs bool, claim string, role instancectl.Role, inst string) (execsandbox.Effective, error) { |
| + if mode == "" { |
| + return execsandbox.EffectiveSystemd, nil |
| + } |
| + if mode != "gvisor" { |
| + return "", execsandbox.ErrConfig |
| + } |
| + if rootfs { |
| + return "", execsandbox.ErrRootfs |
| + } |
| + if claim != "" { |
| + return "", execsandbox.ErrClaims |
| + } |
| + // Reuse the existing instance-name validation without admitting a generation. |
| + if role != instancectl.RoleRun || strings.Contains(inst, ":") { |
| + return "", execsandbox.ErrRole |
| + } |
| + if _, _, ok := instancectl.ParseGenInstance(inst + ":1"); !ok { |
| + return "", execsandbox.ErrRole |
| + } |
| + return execsandbox.EffectiveGVisor, nil |
| +} |
| + |
| +func gvisorLauncher(init func(string, []string, []string) error, getenv func(string) string) func(string, []string, []string) error { |
| + // Capture before execLaunch opens tenant-written JSON. No launch value can |
| + // supply or replace this root-selected trampoline setting. |
| + limit := getenv("GOMEMLIMIT") |
| + return func(argv0 string, argv, env []string) error { |
| + if limit != "241591905" { |
| + return errors.New("instance-exec: invalid root-supplied GOMEMLIMIT") |
| + } |
| + out := make([]string, 0, len(env)+1) |
| + for _, kv := range env { |
| + if !strings.HasPrefix(kv, "GOMEMLIMIT=") { |
| + out = append(out, kv) |
| + } |
| + } |
| + out = append(out, "GOMEMLIMIT="+limit) |
| + return init(argv0, argv, out) |
| + } |
| +} |
diff --git a/internal/instanceexec/sandbox_linux.go b/internal/instanceexec/sandbox_linux.go| new file mode 100644 |
| index 000000000..5e30f81e0 |
| --- /dev/null |
| +++ b/internal/instanceexec/sandbox_linux.go |
| @@ -0,0 +1,67 @@ |
| +//go:build linux |
| + |
| +package instanceexec |
| + |
| +import ( |
| + "fmt" |
| + "os" |
| + "os/user" |
| + "strconv" |
| + "strings" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/instancectl" |
| + "github.com/carlosframework/platform/internal/instancefs" |
| + "golang.org/x/sys/unix" |
| +) |
| + |
| +func gvisorInit(argv0 string, argv, env []string) error { |
| + // gVisor supplies a private abstract namespace; the supervisor stays intact. |
| + return runInit(argv0, argv, env, func() error { return nil }) |
| +} |
| + |
| +func writeExitRecordOwned(runDir string, role instancectl.Role, inst string, env func(string) string, now time.Time, uid, gid int) error { |
| + if uid < 0 || gid < 0 { |
| + return fmt.Errorf("instance-exit: invalid record owner") |
| + } |
| + return writeExitRecordAs(runDir, role, inst, env, now, func(f *os.File) error { |
| + return unix.Fchown(int(f.Fd()), uid, gid) |
| + }) |
| +} |
| + |
| +func writeGVisorExitRecord(c exitCommand, env func(string) string, now time.Time) error { |
| + if os.Geteuid() != 0 { |
| + return fmt.Errorf("instance-exit: gVisor host hook requires root") |
| + } |
| + u, err := user.Lookup("carlos") |
| + if err != nil { |
| + return err |
| + } |
| + uid, uerr := strconv.Atoi(u.Uid) |
| + gid, gerr := strconv.Atoi(u.Gid) |
| + if uerr != nil || gerr != nil || uid <= 0 || gid <= 0 { |
| + return fmt.Errorf("instance-exit: invalid carlos identity") |
| + } |
| + return writeExitRecordOwned(c.runDir, c.role, c.inst, env, now, uid, gid) |
| +} |
| + |
| +func gvisorProbeChecks() instancectl.ProbeReport { |
| + v := &verdicts{} |
| + v.pass("guest-nonroot", fmt.Sprintf("uid=%d gid=%d", os.Getuid(), os.Getgid()), os.Getuid() > 0 && os.Getgid() > 0) |
| + status, err := os.ReadFile("/proc/self/status") |
| + values := map[string]string{} |
| + for _, line := range strings.Split(string(status), "\n") { |
| + key, value, _ := strings.Cut(line, ":") |
| + values[key] = strings.TrimSpace(value) |
| + } |
| + for _, field := range []string{"CapInh", "CapPrm", "CapEff", "CapBnd", "CapAmb"} { |
| + v.pass(field, values[field], err == nil && values[field] == "0000000000000000") |
| + } |
| + v.pass("NoNewPrivs", values["NoNewPrivs"], err == nil && values["NoNewPrivs"] == "1") |
| + err = instancefs.SelfCheck("/data/instances/_probe") |
| + v.pass("openat2", fmt.Sprint(err), err == nil) |
| + // Task 6 supplies the root challenges and full network/runtime proof. |
| + // This early measurement must not advertise readiness to production. |
| + v.add("gvisor-readiness", "fail", "gVisor readiness proof is incomplete") |
| + return v.report() |
| +} |
diff --git a/internal/instanceexec/sandbox_linux_test.go b/internal/instanceexec/sandbox_linux_test.go| new file mode 100644 |
| index 000000000..839535a44 |
| --- /dev/null |
| +++ b/internal/instanceexec/sandbox_linux_test.go |
| @@ -0,0 +1,215 @@ |
| +//go:build linux |
| + |
| +package instanceexec |
| + |
| +import ( |
| + "bytes" |
| + "encoding/json" |
| + "errors" |
| + "os" |
| + "path/filepath" |
| + "reflect" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/execsandbox" |
| + "github.com/carlosframework/platform/internal/instancectl" |
| + "github.com/carlosframework/platform/internal/instancefs" |
| + "golang.org/x/sys/unix" |
| +) |
| + |
| +func TestGVisorLaunchValidation(t *testing.T) { |
| + const host = "gvisor.example.com" |
| + for _, flags := range [][]string{ |
| + {"--rootfs"}, {"--claim-reservation=" + instancectl.ClaimExecSnapshot}, |
| + } { |
| + args := append([]string{"--sandbox=gvisor"}, flags...) |
| + if _, err := parseExecArgs(append(args, "run", host)); err == nil { |
| + t.Fatalf("accepted %v", args) |
| + } |
| + } |
| + for _, role := range []string{"seed", "sidecar", "cmd", "tty", "worker"} { |
| + if _, err := parseExecArgs([]string{"--sandbox=gvisor", role, host}); err == nil { |
| + t.Errorf("accepted role %s", role) |
| + } |
| + } |
| + for _, inst := range []string{host + ":1", "../escape", "", "/absolute"} { |
| + if _, err := parseExecArgs([]string{"--sandbox=gvisor", "run", inst}); err == nil { |
| + t.Errorf("accepted instance %q", inst) |
| + } |
| + } |
| + for _, mode := range []string{"auto", "systemd", "bogus"} { |
| + if _, err := parseExecArgs([]string{"--sandbox=" + mode, "run", host}); err == nil { |
| + t.Errorf("accepted explicit mode %q", mode) |
| + } |
| + } |
| + c, err := parseExecArgs([]string{"--sandbox=gvisor", "run", host}) |
| + if err != nil || c.sandbox != execsandbox.EffectiveGVisor { |
| + t.Fatalf("gvisor parse: %+v %v", c, err) |
| + } |
| + native, err := parseExecArgs([]string{"run", host}) |
| + if err != nil || native.sandbox != execsandbox.EffectiveSystemd || reflect.ValueOf(native.launcher()).Pointer() != reflect.ValueOf(scopedInit).Pointer() { |
| + t.Fatalf("native launcher changed: %+v %v", native, err) |
| + } |
| + t.Setenv("GOMEMLIMIT", "241591905") |
| + for _, tc := range []struct { |
| + name string |
| + change func(*instancectl.Launch) |
| + }{ |
| + {"schema", func(l *instancectl.Launch) { l.Schema++ }}, |
| + {"host", func(l *instancectl.Launch) { l.Host = "not a host" }}, |
| + {"binding", func(l *instancectl.Launch) { l.Host = "other.example.com" }}, |
| + {"empty argv", func(l *instancectl.Launch) { l.Argv = nil }}, |
| + {"outside executable", func(l *instancectl.Launch) { l.Argv[0] = "/bin/sh" }}, |
| + {"other executable", func(l *instancectl.Launch) { l.Argv[0] = LiveDir + "/other.example.com" }}, |
| + {"traversal", func(l *instancectl.Launch) { l.Argv[0] = LiveDir + "/../live/" + host }}, |
| + {"environment", func(l *instancectl.Launch) { l.Env = []string{"invalid"} }}, |
| + {"valid", func(l *instancectl.Launch) {}}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + data := t.TempDir() |
| + l := instancectl.Launch{Schema: instancectl.LaunchSchema, Host: host, Argv: []string{LiveDir + "/" + host}} |
| + tc.change(&l) |
| + writeLaunch(t, filepath.Join(data, "instances", host), instancectl.RoleRun, l) |
| + var got captured |
| + err := execLaunch(data, c.role, c.inst, gvisorLauncher(got.exec, os.Getenv)) |
| + if tc.name == "valid" { |
| + if err != nil || got.calls != 1 { |
| + t.Fatalf("valid launch: %v %+v", err, got) |
| + } |
| + } else if err == nil || got.calls != 0 { |
| + t.Fatalf("unsafe launch: %v %+v", err, got) |
| + } |
| + }) |
| + } |
| + for _, component := range []string{"leaf", "parent"} { |
| + t.Run("symlink "+component, func(t *testing.T) { |
| + data := t.TempDir() |
| + dir := filepath.Join(data, "instances", host) |
| + writeLaunch(t, dir, instancectl.RoleRun, instancectl.Launch{Schema: 1, Host: host, Argv: []string{LiveDir + "/" + host}}) |
| + path := filepath.Join(dir, "launch.run.json") |
| + if component == "parent" { |
| + path = filepath.Join(data, "instances") |
| + } |
| + if err := os.Rename(path, path+"-real"); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := os.Symlink(path+"-real", path); err != nil { |
| + t.Fatal(err) |
| + } |
| + var got captured |
| + err := execLaunch(data, c.role, c.inst, gvisorLauncher(got.exec, os.Getenv)) |
| + if !errors.Is(err, instancefs.ErrSymlink) || got.calls != 0 { |
| + t.Fatalf("symlink: %v %+v", err, got) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +func TestGVisorGuestMemoryLimit(t *testing.T) { |
| + const host = "gvisor.example.com" |
| + t.Setenv("GOMEMLIMIT", "241591905") |
| + var got captured |
| + launch := gvisorLauncher(got.exec, os.Getenv) |
| + // The trusted value must already be captured when launch JSON is read. |
| + t.Setenv("GOMEMLIMIT", "1") |
| + data := t.TempDir() |
| + writeLaunch(t, filepath.Join(data, "instances", host), instancectl.RoleRun, instancectl.Launch{ |
| + Schema: 1, Host: host, Argv: []string{LiveDir + "/" + host}, |
| + Env: []string{"GOMEMLIMIT=1", "KEEP=yes", "GOMEMLIMIT=off", "GOMEMLIMIT=999999999999"}, |
| + }) |
| + if err := execLaunch(data, instancectl.RoleRun, host, launch); err != nil { |
| + t.Fatal(err) |
| + } |
| + if !reflect.DeepEqual(got.env, []string{"KEEP=yes", "GOMEMLIMIT=241591905"}) { |
| + t.Fatalf("env = %v", got.env) |
| + } |
| + for _, bad := range []string{"", "off", "0", "241591905\x00"} { |
| + var got captured |
| + if err := gvisorLauncher(got.exec, func(string) string { return bad })("app", nil, []string{"GOMEMLIMIT=241591905"}); err == nil || got.calls != 0 { |
| + t.Errorf("invalid trusted limit %q: %v, calls=%d", bad, err, got.calls) |
| + } |
| + } |
| +} |
| + |
| +func TestGVisorExitRecordOwned(t *testing.T) { |
| + const host = "gvisor.example.com" |
| + const inv = "deadbeefdeadbeefdeadbeefdeadbeef" |
| + env := envOf(map[string]string{"INVOCATION_ID": inv, "SERVICE_RESULT": "exit-code", "EXIT_CODE": "exited", "EXIT_STATUS": "3"}) |
| + now := time.Date(2026, 11, 8, 12, 0, 0, 0, time.UTC) |
| + makeRun := func() string { |
| + run := t.TempDir() |
| + if err := os.MkdirAll(filepath.Join(run, "instances", host), 0o700); err != nil { |
| + t.Fatal(err) |
| + } |
| + return run |
| + } |
| + run, native := makeRun(), makeRun() |
| + // Ordinary tests use their current identity; the root runner checks carlos. |
| + if err := writeExitRecordOwned(run, instancectl.RoleRun, host, env, now, os.Getuid(), os.Getgid()); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := writeExitRecord(native, instancectl.RoleRun, host, env, now); err != nil { |
| + t.Fatal(err) |
| + } |
| + name := filepath.Join("instances", host, instancectl.ExitRecordName(instancectl.RoleRun, inv)) |
| + path := filepath.Join(run, name) |
| + b, err := os.ReadFile(path) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + n, err := os.ReadFile(filepath.Join(native, name)) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if !bytes.Equal(b, n) { |
| + t.Fatalf("record changed:\n%s\n%s", b, n) |
| + } |
| + var fields map[string]any |
| + if err := json.Unmarshal(b, &fields); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, ok := fields["kind"]; ok { |
| + t.Fatal("kind added") |
| + } |
| + var st unix.Stat_t |
| + if err := unix.Stat(path, &st); err != nil { |
| + t.Fatal(err) |
| + } |
| + if st.Uid != uint32(os.Getuid()) || st.Gid != uint32(os.Getgid()) || st.Mode&0o777 != 0o600 { |
| + t.Fatalf("stat: %+v", st) |
| + } |
| + if err := writeExitRecordOwned(run, instancectl.RoleRun, host, env, now, os.Getuid(), os.Getgid()); err == nil { |
| + t.Fatal("overwrote record") |
| + } |
| + for _, component := range []string{"leaf", "parent"} { |
| + run := makeRun() |
| + link := filepath.Join(run, name) |
| + if component == "parent" { |
| + link = filepath.Join(run, "instances", host) |
| + if err := os.Remove(link); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + if err := os.Symlink(filepath.Join(native, name), link); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := writeExitRecordOwned(run, instancectl.RoleRun, host, env, now, os.Getuid(), os.Getgid()); err == nil { |
| + t.Fatalf("followed %s symlink", component) |
| + } |
| + } |
| + for _, args := range [][]string{{"--sandbox=gvisor", "--rootfs", "run", host}, {"--sandbox=gvisor", "seed", host}, {"--sandbox=gvisor", "run", host + ":1"}} { |
| + if _, err := parseExitArgs(args); err == nil { |
| + t.Errorf("exit accepted %v", args) |
| + } |
| + } |
| + // Parse/write failures remain advisory: RunExit must return to its caller. |
| + t.Setenv("INVOCATION_ID", "bad") |
| + RunExit([]string{"--sandbox=gvisor", "--run-dir=" + run, "run", host}) |
| + RunExit([]string{"--sandbox=gvisor", "seed", host}) |
| + after, err := os.ReadFile(path) |
| + if err != nil || !strings.EqualFold(string(after), string(b)) { |
| + t.Fatalf("changed original: %v", err) |
| + } |
| +} |
diff --git a/internal/instanceexec/sandbox_other.go b/internal/instanceexec/sandbox_other.go| new file mode 100644 |
| index 000000000..a84f36e83 |
| --- /dev/null |
| +++ b/internal/instanceexec/sandbox_other.go |
| @@ -0,0 +1,24 @@ |
| +//go:build !linux |
| + |
| +package instanceexec |
| + |
| +import ( |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/execsandbox" |
| + "github.com/carlosframework/platform/internal/instancectl" |
| +) |
| + |
| +func gvisorInit(string, []string, []string) error { return execsandbox.ErrUnsupported } |
| + |
| +func writeExitRecordOwned(string, instancectl.Role, string, func(string) string, time.Time, int, int) error { |
| + return execsandbox.ErrUnsupported |
| +} |
| + |
| +func writeGVisorExitRecord(exitCommand, func(string) string, time.Time) error { |
| + return execsandbox.ErrUnsupported |
| +} |
| + |
| +func gvisorProbeChecks() instancectl.ProbeReport { |
| + return instancectl.ProbeReport{Lines: []instancectl.VerdictLine{{Check: "sandbox", Verdict: "fail", Detail: execsandbox.ErrUnsupported.Error()}}} |
| +} |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index 20fe4fc4c..a8ce2bca2 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -128,4 +128,4 @@ plan14-root-reads-fix-activator-backoff-flake.tsv feba66806ddfcbdfaf369d72413bb1 |
| plan14-root-reads-region-ha-dr5.tsv f19eb78c1da1475cbf8e11a3d6c394d828aa1c8f88ae24469fe8d473581b934b |
| plan14-root-reads-instance-syscall-filter.tsv b970bb28c5a633d2572a1da549030e9258cfdabb6322ddffdd0ebf41b56c464c |
| plan14-root-reads-instance-restore-658-cli.tsv b970bb28c5a633d2572a1da549030e9258cfdabb6322ddffdd0ebf41b56c464c |
| -plan14-root-reads-gvisor-demos.tsv 39d38b6f517d92fcace7950644b0fc3455d03f5e055fd3c08a7f9ffcb06652dd |
| +plan14-root-reads-gvisor-demos.tsv fe0ca981cae7d649de4d5b30aec791b44914ed5770eb374dc91e7b7242406744 |
diff --git a/internal/provision/testdata/plan14-root-reads-gvisor-demos.tsv b/internal/provision/testdata/plan14-root-reads-gvisor-demos.tsv| index 2f72046a7..0444dc92d 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-gvisor-demos.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-gvisor-demos.tsv |
| @@ -1,6 +1,6 @@ |
| # Census overlay gvisor-demos, written by census-propose (#369). census-ruling-gvisor-demos, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-gvisor-demos.md. |
| -# 12 body, 0 sites, 4 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. |
| +# 12 body, 0 sites, 5 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +# 4 new dispositions: 0 reads re-frozen at their disposition with the claim, 4 new units frozen accepted-legacy, 0 quiet units retired while they read nothing, 0 other. |
| @legacy 53142bae4c3f2ad8444ecd148a1e5389cf059e60e80b0366056a6f7dce33997b internal/host/bootstrap.go bootstrapWithGroup legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-p3b;basis=Move bootstrapWith body here, retaining host.env, embedded unit reads and tmpfiles execution. Group live caller holds root mutation guard; skip automatic update/recovery units, preserve Restart=no/nftables drop-in and masks, and write separate root-owned /run/carlos-group-maintenance tmpfiles rule outside service ownership walk. No agent receipt read.;rev3=census-ruling-gvisor-demos;basis=Use the distinct claim/demo rendering marker, with historic state-directory recognition, for the 6b-N2 keep-installed decision; ordinary units are repaired on malformed host.env. Existing reads unchanged. file:Command@11946,file:ReadFile@564,file:ReadFile@7000 3cb60d7cb52e0e04a5ed690938acd5376f38e8275bf92624610f05bd3f6b41ab |
| @legacy 30cbb184502cda61320987fa438776a839eee01c610185e050779ae82eeed822 internal/host/systemapply.go systemApplier.installUnits legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-agent-start-demo-1;basis=Renders the staged build slice against live root host configuration; preserves it when settings cannot be parsed.;rev3=census-ruling-region-ha-p3b;basis=Require group apply/rollback permit, preserve root Restart=no/nftables drop-in and masks, and skip automatic update/recovery units. Existing staged unit and host.env reads remain; new indirect marker/permit reads are protected and agent receipts are excluded.;rev3=census-ruling-gvisor-demos;basis=Use claim/demo rendering evidence instead of the now-common EnvironmentFile line to preserve installed control on settings errors. Ordinary control stays flag-off and does not gain automatic restarts. Existing reads unchanged. file:ReadDir@1409,file:ReadFile@2000,file:ReadFile@5035,file:ReadFile@960,file:Stat@2658,file:Stat@3951 957f210b9c50169a414cc99ddf5ddae35a804e7c2ff734fe755e85bf3388087a |
| @legacy 16c52a77d87551d9536e381991f55ea95e527b1d647d5d58ff2f1797c0e1b971 internal/host/systemunits.go ensureSystemUnitsWithGuard legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-p3b;basis=Move unit-repair body here with existing lock/unit/host.env reads; under lock require operator repair permit on groups before writes and each systemctl effect, preserve root masks/drop-in and omit automatic update/recovery units. New indirect protected marker/permit reads, never agent receipt; fixed repair unchanged.;rev3=census-ruling-gvisor-demos;basis=Use claim/demo rendering evidence for repair/restart selection and 6b-N2 preservation. Ordinary environment loading does not classify a box as claims-enabled. Existing reads unchanged. file:OpenFile@293,file:ReadFile@4702,file:ReadFile@4835,file:ReadFile@6239,file:Stat@4611 123236f110db2d69dc2f425944485e52ba12fede7be07d07f7db0d08987f4f61 |
| @@ -8,9 +8,10 @@ |
| @legacy 05b7a387b7ff2a6a99259dde4f508f308afaf7cfff9a08c2ddc648169578c082 internal/instancectl/rootfs.go Server.runRootfsProbe legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-2;identity=instance control (/opt/carlos/carlos instance-control, carlos-instance-control.service, root);basis=root-input (J2,J4, as Server.RunProbe): new (rootfs Plan 2 Task 7): builds the probe image once per service start, hashes it (fileSHA256), lays out the _probe rootfs exe layout and its box-addrs, starts carlos-instance-rootfs-probe.service and ReadFiles its report from /run/carlos-control/rootfs-probe.out, which PID 1 writes from the probe's stdout; the probe runs the platform binary from root's own probe image, no tenant code; the report only decides readiness, and without an ok root-image line it is never ready, whatever it says;rev3=census-ruling-agent-start-demo-1;basis=Reads DemoBox and refuses before preparing or launching a rootfs probe; ordinary probe behavior unchanged.;rev3=census-ruling-gvisor-demos;basis=Refuse sandbox configuration or readiness errors before preparing or starting the native rootfs probe. Existing image read unchanged. file:ReadFile@2005 6ad27d7fe661eba457ea01736b8c482e27fd3d1a64ed80e8afefa8ffe4e9f386 |
| @legacy 7129928a96c588d2dcaf6e93b8c5e5f6977f2519ccb60f1af361f7b1c57602ee internal/instancectl/server.go Server.RunProbe legacy accepted-legacy accepted-legacy;rev3=J2,J4;basis=root-input;rev3=census-ruling-rootfs-apps-2;basis=after the resolver allow it applies the box-address deny (denyLocalAddrs: set-property IPAddressDeny on carlos-instances.slice from localPrefixes, which reads /proc/net/fib_trie and /proc/net/if_inet6 as LocalAddrs already did), writes the probe's box-addrs under its own exe layout (writeFileExcl, a decision row), and after the binary probe runs the rootfs probe (runRootfsProbe, a decision row); its own direct read, probe.out, is unchanged;rev3=census-ruling-region-ha-p3b;basis=Take shared root hairpin lease for the entire probe so deny refresh and hairpin mutation cannot race it. Indirect reads validate root boot snapshot, root state/fence and interface inventory; existing probe.out direct read remains and lock/config errors fail readiness.;rev3=census-ruling-gvisor-demos;basis=Refuse sandbox configuration or readiness errors before fixture reads and native probe dispatch. Existing probe read unchanged. file:ReadFile@2608 2a0e32e04c6e0c5f25021c62f760f72429fa5e91d7597fcc4b09b7fdf5790b34 |
| @legacy bc7cd834024c83776bd9b64133f191a03588dd973960954fd6a6ce853023ad69 internal/instancectl/server.go type Server legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=Re-digested at the pre-land merge: the body includes main's own change under census ruling 292, with no further change from this branch. Census ruling 292 reclassified this declaration accepted-legacy (J2,J4) for root's per-host ordering of legacy run starts against stops; this ruling kept the row as main classed it. Its own addition is the cmd start's poll and wait bounds and its per-host lock map: field declarations only;rev3=census-ruling-rootfs-apps-2;basis=new fields: HostRuntime, ProbeImage, ProbeImageFile, RootfsProbeOut, DenyEvery, the deny's lastDeny and denyMu, the rootfs probe's report and lock, the jit reload counters and imageDigests; genStarting counts binary generation starts per unit; rootfsLocksMu and rootfsLocks, one lock entry per rootfs unit name being started or removed right now, held by a start from its layout through systemctl start and its own cleanup and by a removal from its proof through the raw removal, a removal refusing while it is taken, a waiting start giving up when its request ends, an entry dropped with its last holder or waiter (fixes E6, L2, L3); rootfsProvenHook, a test hook run between the proof and the raw removal; field declarations only; no read added;rev3=census-ruling-instance-egress-sizes-328-329;basis=#328 plan 2 and #329 plan 3 Task 5: the declaration gains sliceLocks (one mutex per host slice, taken by /size and /parent) and Egress (the asserter every start path calls), and its comment names the egress allow (plan 3's ControlDropInDir field was deleted in ef38e13b, the P1 EROFS fix); the same one site, the Statfs field, offset moved; no read added.;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 6: comments only: the one-shot pacing fields cover /cmd and /tty, and cmdLocks is now keyed by (role, host) (oneShotKey, PF-7) so a session's start never waits behind a command's; field declarations unchanged; the same one site, no read added;rev3=census-ruling-agent-start-demo-1;basis=Adds fixed demo configuration, registry views, derived runtime root, synchronization and purge guard.;rev3=census-ruling-region-ha-p3b;basis=Add hairpinActive boolean alongside lastDeny under existing deny synchronization. Field declaration only; existing Statfs selector unchanged, no new read or externally supplied authority.;rev3=census-ruling-region-ha-p3b2-rolls;basis=adds one field holding the current hairpin exit watcher, guarded by the root hairpin flock; no new read;rev3=census-ruling-agent-start-demo-3;basis=Retain the snapshot supervisor in instance-control state; no new request-selected path. Census read-site delta: unchanged (1).;rev3=census-ruling-gvisor-demos;basis=Add fixed configured and effective sandbox modes, configuration error and runtime readiness callback. No new path or read. file:Statfs@4123 4f7b68950f5e49b21ed52a7d58e416d90f2e062e4e3c01e44468a2bd87494b98 |
| -@legacy 24a87a48463d7f66b86dbce845c4b4616816cf16181852c6b635bb8fba874c7f internal/execsandbox/runsc.lock.json external legacy accepted-legacy accepted-legacy;rev3=census-ruling-gvisor-demos;basis=Embed verified release-20261102.0 runsc archive and binary digests for both Linux platforms; URLs are immutable upstream HTTPS sources. No external runtime read. file:external@0 ee02ee9a4290bae7bf2a33fd60d1bf07484c75efd5d481c2af50523a374375e8 |
| +@legacy 39b3f98c010e512816b6964fd4de98193a850564e68021119a888e6a97f7befa internal/execsandbox/runsc.lock.json external legacy accepted-legacy accepted-legacy;rev3=census-ruling-gvisor-demos;basis=Extend the embedded release-20261102.0 pin to exactly the five R-T2 executable members on each Linux platform. Archive SHA512 was verified before extracting the named regular members; freeze each SHA256. Top-level SHA256 still equals runsc. No external runtime read. file:external@0 3a24ba581a95bc8fd8283984b5501f0002daff003e2d8fe90571e150ba15b617 |
| @legacy ee7a88073c08baf804220709c6e2d7778d7d277054f413be0443d2ac431643ef internal/host/execsandbox.go sandboxExecGate legacy accepted-legacy accepted-legacy;rev3=census-ruling-gvisor-demos;basis=Read the existing registry route through injected lookup only for gVisor; require the same route admission before BeforeExec. No new path; lookup is the existing registry handle. whole:Route@493,whole:Route@587 e66292565a6718b38622cfbd0747888356fb66fca161d782399067a0db23a1f5 |
| @legacy 8d2537e489c6d9c5782c1548a3cdabe421f20a9d4eae4b71d008d089c071a43c internal/host/execsandbox.go sandboxRouteGate legacy accepted-legacy accepted-legacy;rev3=census-ruling-gvisor-demos;basis=Read existing route layout, demo marker and runtime to refuse unsupported or direct gVisor launches before the next config gate. No new path; layout inputs are the backend's existing ones. registry:Runtime@700,whole:Route@432,whole:Route@802 6d3b45864d6e551a523e37dbec39f6d7befd414d02ce6751531ac312c7ec1d67 |
| +@legacy 3c1078f0c5d2242857e988d8047b8036e7c09c603443508ddb2520232da88e4a internal/instanceexec/sandbox_linux.go gvisorProbeChecks legacy accepted-legacy accepted-legacy;rev3=census-ruling-gvisor-demos;basis=Preliminary guest-only probe reads the fixed /proc/self/status to check empty capability sets and NoNewPrivs, and SelfCheck opens the fixed own /data/instances/_probe directory with unchanged safe-open flags. Runs as the guest carlos identity; reports readiness incomplete until the later root challenges exist. No tenant-selected host path or root authority is added. data-literal@696,file:ReadFile@202 825a550d5d62da0d0b322c480fa2a4a1027de35f04ac274b5f5c7eb1bbc072a2 |
| internal/host/agent.go runAgent authority B,C,D,F rev3=census-ruling-self-serve-moves-1;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): builds the box's lifetime judge once (newBoxJudge, nil with host claims on) and hands it to the seed placement, the moves and runs workers and every loop it starts; read sites unchanged, offsets moved; B,C,D,F authority retained; self-serve moves 1 Task 8: derives the box's lifetimes switch from the judge once (lifetimes := boxJudge != nil) and hands it to the edges file loop; read sites unchanged, offsets moved;rev3=census-ruling-plans-4d-lapse;basis=arms two more plans hooks from the same snapshot: e.SetPlanDisabledFor(planDisabledFor) beside SetPlanGovernedFor, and svc.SetDisabledFor(planDisabledRoute) beside SetMaxRunFor (plans 4d); the reads live in those units (plans-4d-units decision); read sites unchanged, offsets moved;rev3=census-ruling-rootfs-apps-2;basis=main's body as of the merge of origin/main 9b81d97b (with main's plan rate ceiling, edge request records, regional box names, self-serve moves plan 1, plans 4d-1 lapse and its other later changes under main's own census rulings) plus the rootfs placement wiring in the activator start: an agentRootfs built from eb.NestedOK, CARLOS_DEPLOYMENT_SINGLE_TENANT, CARLOS_POOLS, the claim flag, swapArming's answer, the control client's /ready/rootfs and, on a fleet box whose identity resolved, fleetOwnerCheck over the deploy store main already opens for the fleet label (fleetStore), then arm and armedRootfs.Store; this body reads nothing new itself; the closures it wires read later, at a rootfs wake and each status tick: GET /ready/rootfs over the control socket, NestedOK's checks, and release.FleetOwnerKey for the judged row's own account and this box's fleet from the deploy store;rev3=census-ruling-instance-egress-sizes-328-329;basis=#328 plan 2 Tasks 7 and 11, #329 plan 3 Task 7 and plan 1 Task 7's policy cache: the control client is built once and handed to eb.Control, to the status tick (egressStatus) and to a new egressNudgeLoop goroutine; armSizeSource(svc, "/sys/fs/cgroup") after the activator Service; armPolicyCache() after armChangeIndex; statusLoop takes egressStatus. The reads are those units' own (decision rows); this body reads nothing new: the same five sites, offsets moved, in the agent; B,C,D,F authority retained.;rev3=census-ruling-remote-instance-metrics;basis=builds the metrics loop's owners closure (metricsOwners over the agent's registry, the activator and cgm.Leftover) when an activator exists and hands it to metricsLoop; reads nothing new itself;rev3=census-ruling-edge-asset-cache-3;basis=adds file:Statfs. runAgent keeps its authority (B,C,D,F). The new site is assetcache.Statfs, an exported assetcache.FS interface value (var Statfs FS = statfsFS{}), not a function value and not a call in runAgent: the ready hook passes it to armEdgeAssetCache as the store's filesystem, and armEdgeAssetCache calls its Space method on the configured data directory (dataDir(): $CARLOS_DATA_DIR, else /data), which calls unix.Statfs there (statfsFS.Space, accepted legacy at census-ruling-edge-asset-cache-2). No request-supplied pathname reaches it.;rev3=census-ruling-remote-metrics-nested;basis=main's body (merged origin/main acfa4f80, under main's own census rulings) plus: snapshots the nested layout (snapshotNestedUnits over /sys/fs/cgroup/carlos.slice/carlos-instances.slice) once at start, before the activator, and hands the metrics loop a unitSources struct (stamped units, routeHostNames, that root and the snapshot); reads nothing new itself;rev3=census-ruling-region-ha-p1a;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): wires region HA P1a into the activator: cfg.Record = haRecordFacts(openDeployStore, boxJudge) (the box's lifetime judge this body already builds with newBoxJudge, nil with host claims on; CI fix) and cfg.Self = lease.CurrentSelf; eb.Lifetimes (the process's lifetime index), eb.Registry, eb.StartupSwept (seedSweptAtStart.Load), eb.FilesStore from newProductionFilesStore (now lease.NewFilesStore, rootaws-loaded, a log line on failure) and lease.SetObligationDir(<data>/.ha-owed) (logged on failure; HA acquires then refuse); this body reads nothing new itself, the same five sites; the reads are those units' own (haRecordFacts and lease's SetObligationDir are new rows on this card); merge of origin/main d7ae1d76: main's own later changes to this body are kept as main has them, under main's rulings (census-ruling-remote-instance-metrics: the metricsOwners closure for metricsLoop; census-ruling-edge-asset-cache-3: the +file:Statfs site, assetcache.Statfs handed to the asset ready hook); this branch's change is the same as above;rev3=census-ruling-region-ha-p1b1;basis=region HA P1b-1: builds one termfence.Confirmer (Self from lease.CurrentSelf at each call, EC2 DescribeInstances method only, client from rootaws.LoadDefaultConfig with retries off, built lazily on first use) and sets eb.OwnerTerminated; this body reads nothing new itself, the same six sites;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Task 7: the startup Sweep literal hands its answer to startupSwept, which logs as before and, only on a clean sweep, marks rootfs admission swept (MarkRootfsSwept); same Sweep call, no read added;rev3=census-ruling-managed-fleets-1b;basis=managed fleets 1b (controller ruling after branch review R1, and Paul's R2 ruling): sets svc.Fleet = fleetWakeFor(os.Getenv, identity, identErr, fleetStore) from the identity it already resolves once and the deployment store the fleet loops already opened, and logs an ERROR naming the identity error when the box is on a fleet with an invalid identity. fleetWakeFor reads CARLOS_REGION and CARLOS_FLEET from the same environment. Read sites unchanged (6). Agent, not root; a platform box is unchanged.;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 12: one call more beside armRunsPass, armInteractivePass(svc, reg, rolloutSink, boxJudge), in the same activator Configure hook, handing it the same box judge; fix round 1 (Astra P2, shutdown): after svc.Shutdown(ctx), shutdownInteractive(ctx) ends and joins every interactive session under the same shutdown budget; the worker's own reads are its units' (interactive.go); this body reads nothing new, the same six sites; merge of origin/main 6f1f6ca6: main's svc.Fleet = fleetWakeFor(...) and its invalid-identity ERROR line are kept as main has them (census-ruling-managed-fleets-1b); this branch's change is the same as above; read sites unchanged (6);rev3=census-ruling-fix-set-aside-exdev;basis=set-aside EXDEV fix: one field more on the agent ExecBackend literal, RawInstanceDir: layout.RawInstanceDir (a pure path join: <dataDir>/.instances/<InstanceID(host)>), so the start rule set-aside moves a copy out through the raw directory instead of through the nosymfollow bind; this body reads nothing new, the same six sites;rev3=census-ruling-durability-3a-escrow;basis=durability 3a Task 3: one more assignment beside eb.FilesStore: eb.EscrowKey = haEscrowKey(os.Getenv("CARLOS_SECRETS_KEY")), the agent's own environment parsed by appconfig.ParsePrivateKey as the moves pass parses it (unset or unparseable: a log line and nil, and HA publication refuses on the box). No path is opened or read, no read site added; the same six sites, offsets moved; B,C,D,F authority retained. Durability 3a Task 4: one more goroutine beside configSyncLoop: go escrowLoop(agentCtx, reg, svc), the escrow sweep every 30 s over the same registry and Service. This body reads nothing new itself; the same six sites, offsets moved; B,C,D,F authority retained. Durability 3a Task 5: one more call beside eb.EscrowKey: wireRawSecretPages(eb, PageOperator, metricsBoxLabel(os.Getenv, readMachineID())), which sets eb.OnRawSecret to page an operator (alerting.Page through PageOperator, LevelIncident) on its own goroutine with a 20 s timeout; metricsBoxLabel and readMachineID are the reads this body already makes for the moves refusal log; no new read site; the same six sites, offsets moved; B,C,D,F authority retained. Merge of origin/main 90c4d3aa: main's own later changes to this body are kept as main has them, under main's rulings; this branch's change is the same as above. Merge of origin/main 00bf5b8c (fleet set-aside EXDEV fix): main's change to this body is kept as main has it, under its own census ruling; this branch's change is unchanged.;rev3=census-ruling-probe-burst-limit;basis=two more sink wirings beside setAnalyticsSink: setProtectionSink(e.SetProtectionRecordOnly) and setAssetOwnersSource(e.AssetOwners), function values the telemetry pass calls; this body reads nothing new, the same six sites; authority B,C,D,F retained; no new root read or write kind;rev3=census-ruling-region-ha-p1b3a;basis=Arm HA placement exactly once on the existing Service before activatorStart and edges publication, wiring AwakeApps and the PageOperator callback; existing six read sites unchanged, no new root authority.;rev3=census-ruling-stateless-replicas-1;basis=Final review I3: start the concrete coordinator's renewal worker with agent setup; existing closeReplicaCoordinator shutdown cancels and joins it before release. No new read sites or credentials. Merge origin/main c59715e7: retain main's armHAPlacement(svc, PageOperator) wiring beside the existing activator setup; stateless coordinator and shutdown wiring remain. Same read sites; no new root read or credential.;rev3=census-ruling-edge-held-streams;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): in the edge-ready callback, calls act.SetHeldWakeHook(e.HeldWake) when act is non-nil (installing the non-blocking wake callback) and stores e.HeldStreamsForStatus in heldStreamsSource. Wiring of in-memory callbacks only; no read added.;rev3=census-ruling-region-ha-p1b3b-t;basis=Wire Service.SetDutyView to the live edge DutySnapshot in the ready callback. No new read; no new loop or cloud operation. B2 wires the registry as the persistent DutyStore before service startup; no new cloud or filesystem path. B3b: arm one journal-backed termination consumer before service startup using agentCtx and the shared confirmer; expose edge tick and join at edge shutdown. No new direct read sites.;rev3=census-ruling-agent-start-demo-1;basis=Passes the existing registry, data store and hibernation prefix into the demo worker, and the existing instance-control client into the demo before-exec hook. No alternate data store or polling loop. Merge resolution against origin/main 9bd45488 retains main's HA departure controller, lifecycle and duty wiring alongside the demo data store and worker; no read site added by the resolution.;rev3=census-ruling-region-ha-p3a;basis=P3a Task 3: install closed fixed admission before every launch source, bind activator/backend and edge, wire the real termination Started lifecycle and role reader after the change index; close before cancellation/child shutdown. No new external reads or cloud authority. Fix R1: move bind/lifecycle/edge-option wiring into wireAgentAdmission and worker listing into runWorkerBootPassAfterAdmission. Worker boot waits for admission before listing then uses unchanged bounded wakes and per-host serialization; whole Route read moves to the helper. No new storage, cloud, or root execution authority. Preserve merged main's agent wiring and census basis; the branch removes one whole Route use by moving worker iteration to the helper, with no added read kind.;rev3=census-ruling-stateless-replicas-2;basis=Slice 3b: arms a fleet-only worker using the existing registry, activator, backend and authenticated console transport. Owned worker stops and joins at shutdown. No new bucket reader. merge of origin/main 9b8b2c50: retain HA duty/departure lifecycle, wake-slot and existing agent wiring alongside the replica placement worker; no new read introduced by resolution. merge of origin/main 6be08467: Retain main demo configuration, admission, build and expiry wiring alongside the replica worker; merge-only body change, no additional read. merge of origin/main 7920cccf: Retain main box-role/group admission wiring and boot publication beside the owned replica worker and shutdown; main moves the boot registry List into runWorkerBootPassAfterAdmission, removing its inline whole Route site. No new read introduced by conflict resolution.;rev3=census-ruling-stateless-replicas-3;basis=Task 1 fix round 1 M3: retain the private snapshot source and cancel/join ownership, but use the replica-health-specific retry loop. It logs its first failure only and retains the existing exponential backoff capped at 30 seconds; unsupported builds return nil. Existing five direct read sites unchanged; no new credentials, bucket reader or app lifecycle action. Fix round 1 Q20: publish Edge.ReplicaSnapshots as a separate in-memory status source, leaving the tenant-visible Upstreams source unchanged. No new external reader or authority.;rev3=census-ruling-region-ha-p3b;basis=Load root-written group marker/configuration, configure signed boot binding and agent receipt completer, wire cancellable admission into departure work and expose cached GroupReaderSnapshot. New indirect boot reads use protected root files; agent-owned receipt controls duplicate initial completion only, never root restart permission. Same five direct sites. Merge 45cebde4 retains the replica health socket lifecycle and setReplicaSource beside GroupReaderSnapshot; no extra read beyond main.;rev3=census-ruling-agent-start-demo-2;basis=agent.go:309-329 opens demo-traffic.db beside the operator-configured registry when a demo domain exists, closes it at shutdown and wires drain-before-purge; :1010-1019 shares the worker and write gate; :1164-1177 installs the fleet identity and closed-until-worker serving callback. One added whole Route pass; the new indirect filesystem/SQL reads are claimed in openDemoTraffic and worker/store units. No request chooses the database pathname.;rev3=census-ruling-region-ha-p1b3b-s;basis=Wire the service duty view to authoritative cached sidecar manifest placement in LifetimeIndex and the edge sidecar projection; missing policy denies duty. Existing instance duty wiring remains.;rev3=census-ruling-region-ha-g2-t3;basis=T3a: wire eb.Page = PageOperator beside OwnerTerminated before departures arm, so suspect-holder pages work if departure setup fails; no new read; existing nine sites and authority unchanged; pages through the existing sink. T3b: publish the same backend through an atomic pointer for the metrics observer, and clear it on return; no new external read or authority.;rev3=census-ruling-agent-start-demo-3;basis=Wire the claim activator and root snapshot client into the demo worker; pass moved readiness to status reporting. Census read-site delta: unchanged (9).;rev3=census-ruling-region-ha-g2-fixes;basis=Wire local pool evidence, live withdrawal activator, startup ingress scan and alias publication, and edge lookup; no new direct sites; new indirect record/claim reads use existing store/judge paths described in ingress helpers.;rev3=census-ruling-region-ha-g2r-fixes;basis=W3: starts the existing record-view backstop loop with a departure-inventory listener (non-blocking, coalesced signal) even without an armed RecordView; it requests the existing full pass (backstopFullDue) there. Same nine read sites; no new read or authority.;rev3=census-ruling-region-ha-graceful-terminate-t2;basis=Derive one signal-time deadline with a 90-second budget; cap departure stop and startup/seed/service shutdown joins by it. No read added.;rev3=census-ruling-static-sweep-periodic;basis=in the edge-ready callback, publishes e.LargestStaticTree in staticTreeSource for the disk alert line (diskAlertFrac in the metrics loop); in-memory wiring only, no read added; read sites unchanged (9);rev3=census-ruling-gvisor-demos;basis=Capture sandbox resolution and refusal once; log errors once; gate route admission and BeforeExec before process launch. No new root read. file:Exec@19431,file:Open@1837,file:Statfs@50774,registry:App@12933,registry:Host@46810,whole:Route@12925,whole:Route@45968,whole:Route@46933,whole:Route@46995 c618605dd17ada0fb0b53b3c4d2176fd737c4f44b38a25298fbc1c48bae9fa0e |
| internal/host/bootstrap.go bootstrapWithGroup legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-p3b;basis=Move bootstrapWith body here, retaining host.env, embedded unit reads and tmpfiles execution. Group live caller holds root mutation guard; skip automatic update/recovery units, preserve Restart=no/nftables drop-in and masks, and write separate root-owned /run/carlos-group-maintenance tmpfiles rule outside service ownership walk. No agent receipt read.;rev3=census-ruling-gvisor-demos;basis=Use the distinct claim/demo rendering marker, with historic state-directory recognition, for the 6b-N2 keep-installed decision; ordinary units are repaired on malformed host.env. Existing reads unchanged. file:Command@11946,file:ReadFile@564,file:ReadFile@7000 3cb60d7cb52e0e04a5ed690938acd5376f38e8275bf92624610f05bd3f6b41ab |
| internal/host/claimstop_run.go RunInstanceControl authority C,D,G rev3=PROPOSED-p3;run=24;identity=root claim/adopt/update controller uid 0;basis=production root startup builds authenticated execution and launch handlers then uses activateClaimRoot for recovery, the registered census launch verifier and lifecycle start;rev3=census-ruling-rootfs-apps-2;basis=the claims-off path serves through instancectl.RunWithRegistryView with HostRuntime: instanceRegistryHostRuntime beside the same instanceRegistryHostApp(nil); the new read is instanceRegistryHostRuntime's own (a decision row in rootfs-apps-2-new); no read added in this body;rev3=census-ruling-instance-egress-sizes-328-329;basis=#328 plan 2 Tasks 4 and 6: the claims-off branch hands RunWithRegistryView the pre-claim egress asserter (newEgressAsserter over registryEgressSource and registryEgressHosts, which read the agent-written registry read-only, beside the instanceRegistryHostApp read it already had); the claims branch builds its runtime resources in instanceControlClaimResources, adding the claims asserter (claimsEgressSource writes no allow; the registry is read only to name slices), and serves through runClaimControl, which passes RunWithClaim the same handler, held-release route and host lookup plus that asserter. No read site in the unit, none added.;rev3=census-ruling-agent-start-demo-1;basis=Wires demo registry views and existing root release/adoption guard into instance control.;rev3=census-ruling-region-ha-p3b;basis=Add root hairpin identity verification, dormant install and reset CLI entries with bounded contexts. Indirect inputs are root-owned marker/identity/ingress/state and kernel/systemd process evidence; no request-controlled addresses or executable path. Existing control-service path remains.;rev3=census-ruling-gvisor-demos;basis=Resolve sandbox once through shared Configure; select claim protocol independently of sandbox refusal and retain claim stop/recovery, activation and host-fence pass. Relax demo-plus-claims fatal only for ErrClaims. Keep egress asserter and install its restart-only refusal before claim recovery. No new root read. 8defd30b08522508edaf87978bf7e7a70ff48fc0aef71a63a702231f387f0efb |
| @@ -23,10 +24,12 @@ internal/instancectl/rootfs.go Server.runRootfsProbe legacy accepted-legacy acce |
| internal/instancectl/server.go Server.RunProbe legacy accepted-legacy accepted-legacy;rev3=J2,J4;basis=root-input;rev3=census-ruling-rootfs-apps-2;basis=after the resolver allow it applies the box-address deny (denyLocalAddrs: set-property IPAddressDeny on carlos-instances.slice from localPrefixes, which reads /proc/net/fib_trie and /proc/net/if_inet6 as LocalAddrs already did), writes the probe's box-addrs under its own exe layout (writeFileExcl, a decision row), and after the binary probe runs the rootfs probe (runRootfsProbe, a decision row); its own direct read, probe.out, is unchanged;rev3=census-ruling-region-ha-p3b;basis=Take shared root hairpin lease for the entire probe so deny refresh and hairpin mutation cannot race it. Indirect reads validate root boot snapshot, root state/fence and interface inventory; existing probe.out direct read remains and lock/config errors fail readiness.;rev3=census-ruling-gvisor-demos;basis=Refuse sandbox configuration or readiness errors before fixture reads and native probe dispatch. Existing probe read unchanged. file:ReadFile@2608 2a0e32e04c6e0c5f25021c62f760f72429fa5e91d7597fcc4b09b7fdf5790b34 |
| internal/instancectl/server.go runWithClaim authority C,D,G Claim instance controller adds held-release RPC dispatch within existing launch/participation execution boundary.;rev3=census-ruling-rootfs-apps-2;basis=takes a RegistryView (HostApp and HostRuntime) for the bare hostApp, and the production Server literal gains HostRuntime, ProbeImage: BuildProbeImage, ProbeImageFile: ProbeImagePath, RootfsProbeOut under /run/carlos-control and DenyEvery: 10s; this body reads nothing new itself; the readers it wires (instanceRegistryHostRuntime, BuildProbeImage, the rootfs probe's output) are decision rows;rev3=census-ruling-instance-egress-sizes-328-329;basis=#328 plan 2 Task 4 and #329 plan 3 Task 5: takes the egress asserter as a parameter, sets it on the production Server literal (Egress) and starts its 30 s Loop beside probeLoop and diskLoop; the literal also names the fixture check ProbeFixturesOK (renamed in plan 2 Task 14). It sets no control drop-in directory: plan 3's ControlDropInDir default (/run/systemd/system.control) was deleted with removeGenControlDropIn in ef38e13b (the P1 EROFS fix), so instance control names systemd's control directory only to read it (TrustedDropinReader). The same four sites (the two exec.CommandContext closures, statfsBytes, the data literal), offsets moved; no read added.;rev3=census-ruling-agent-start-demo-1;basis=Wires root-owned demo config and existing fixed paths into the service.;rev3=census-ruling-region-ha-p3b;basis=Resume root-owned hairpin state before probes/control service work; verify current systemd agent identity and kernel fence/addresses, restore pidfd watch or revoke stale state. Same direct exec/statfs/data sites; indirect inputs are protected root snapshot/state and kernel evidence, never receipt data.;rev3=census-ruling-agent-start-demo-3;basis=Construct the demo snapshot supervisor for configured demo boxes; startup cleanup gates builder readiness. Census read-site delta: unchanged (4).;rev3=census-ruling-gvisor-demos;basis=Require fixed sandbox settings from shared Configure; retain claim handler and legacy-route refusals; preserve egress asserter and revokes for invalid settings and gate only native restart dispatch. Native probe/build/start admission remains refused. Existing root reads unchanged. data-literal@2255,file:CommandContext@1008,file:CommandContext@1186,file:Statfs@2276 5a007c635397921c0c08353e644bc95c90b4a3834742a983c848b6ec3845838d |
| internal/instancectl/server.go type Server legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=Re-digested at the pre-land merge: the body includes main's own change under census ruling 292, with no further change from this branch. Census ruling 292 reclassified this declaration accepted-legacy (J2,J4) for root's per-host ordering of legacy run starts against stops; this ruling kept the row as main classed it. Its own addition is the cmd start's poll and wait bounds and its per-host lock map: field declarations only;rev3=census-ruling-rootfs-apps-2;basis=new fields: HostRuntime, ProbeImage, ProbeImageFile, RootfsProbeOut, DenyEvery, the deny's lastDeny and denyMu, the rootfs probe's report and lock, the jit reload counters and imageDigests; genStarting counts binary generation starts per unit; rootfsLocksMu and rootfsLocks, one lock entry per rootfs unit name being started or removed right now, held by a start from its layout through systemctl start and its own cleanup and by a removal from its proof through the raw removal, a removal refusing while it is taken, a waiting start giving up when its request ends, an entry dropped with its last holder or waiter (fixes E6, L2, L3); rootfsProvenHook, a test hook run between the proof and the raw removal; field declarations only; no read added;rev3=census-ruling-instance-egress-sizes-328-329;basis=#328 plan 2 and #329 plan 3 Task 5: the declaration gains sliceLocks (one mutex per host slice, taken by /size and /parent) and Egress (the asserter every start path calls), and its comment names the egress allow (plan 3's ControlDropInDir field was deleted in ef38e13b, the P1 EROFS fix); the same one site, the Statfs field, offset moved; no read added.;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 6: comments only: the one-shot pacing fields cover /cmd and /tty, and cmdLocks is now keyed by (role, host) (oneShotKey, PF-7) so a session's start never waits behind a command's; field declarations unchanged; the same one site, no read added;rev3=census-ruling-agent-start-demo-1;basis=Adds fixed demo configuration, registry views, derived runtime root, synchronization and purge guard.;rev3=census-ruling-region-ha-p3b;basis=Add hairpinActive boolean alongside lastDeny under existing deny synchronization. Field declaration only; existing Statfs selector unchanged, no new read or externally supplied authority.;rev3=census-ruling-region-ha-p3b2-rolls;basis=adds one field holding the current hairpin exit watcher, guarded by the root hairpin flock; no new read;rev3=census-ruling-agent-start-demo-3;basis=Retain the snapshot supervisor in instance-control state; no new request-selected path. Census read-site delta: unchanged (1).;rev3=census-ruling-gvisor-demos;basis=Add fixed configured and effective sandbox modes, configuration error and runtime readiness callback. No new path or read. file:Statfs@4123 4f7b68950f5e49b21ed52a7d58e416d90f2e062e4e3c01e44468a2bd87494b98 |
| -internal/execsandbox/runsc.lock.json external legacy accepted-legacy accepted-legacy;rev3=census-ruling-gvisor-demos;basis=Embed verified release-20261102.0 runsc archive and binary digests for both Linux platforms; URLs are immutable upstream HTTPS sources. No external runtime read. file:external@0 ee02ee9a4290bae7bf2a33fd60d1bf07484c75efd5d481c2af50523a374375e8 |
| +internal/execsandbox/runsc.lock.json external legacy accepted-legacy accepted-legacy;rev3=census-ruling-gvisor-demos;basis=Extend the embedded release-20261102.0 pin to exactly the five R-T2 executable members on each Linux platform. Archive SHA512 was verified before extracting the named regular members; freeze each SHA256. Top-level SHA256 still equals runsc. No external runtime read. file:external@0 3a24ba581a95bc8fd8283984b5501f0002daff003e2d8fe90571e150ba15b617 |
| internal/host/execsandbox.go sandboxExecGate legacy accepted-legacy accepted-legacy;rev3=census-ruling-gvisor-demos;basis=Read the existing registry route through injected lookup only for gVisor; require the same route admission before BeforeExec. No new path; lookup is the existing registry handle. whole:Route@493,whole:Route@587 e66292565a6718b38622cfbd0747888356fb66fca161d782399067a0db23a1f5 |
| internal/host/execsandbox.go sandboxRouteGate legacy accepted-legacy accepted-legacy;rev3=census-ruling-gvisor-demos;basis=Read existing route layout, demo marker and runtime to refuse unsupported or direct gVisor launches before the next config gate. No new path; layout inputs are the backend's existing ones. registry:Runtime@700,whole:Route@432,whole:Route@802 6d3b45864d6e551a523e37dbec39f6d7befd414d02ce6751531ac312c7ec1d67 |
| -@coverage internal/execsandbox a82f0d29e785761294636ba166ef77182c9b54223678313d3a5f1e12152f6b73 |
| +internal/instanceexec/sandbox_linux.go gvisorProbeChecks legacy accepted-legacy accepted-legacy;rev3=census-ruling-gvisor-demos;basis=Preliminary guest-only probe reads the fixed /proc/self/status to check empty capability sets and NoNewPrivs, and SelfCheck opens the fixed own /data/instances/_probe directory with unchanged safe-open flags. Runs as the guest carlos identity; reports readiness incomplete until the later root challenges exist. No tenant-selected host path or root authority is added. data-literal@696,file:ReadFile@202 825a550d5d62da0d0b322c480fa2a4a1027de35f04ac274b5f5c7eb1bbc072a2 |
| +@coverage internal/execsandbox c3a67170cb13dda0369dd20029d2bc0be845843d2d84843dae270fe828013c01 |
| @coverage internal/host 6c84353dc2f5a136936c4872f2a69454d0f0578fc49583879fe8fa06854e87ae |
| @coverage internal/host/units bd5e78f37a4c2e876e5d5eb906e0bee0987eff2b8c61fb0fe130b09bdd4f0540 |
| @coverage internal/instancectl a943ca98500fd1e41282a8cb1421428f53df5e6a5ec2a347d542b107df03a6c8 |
| +@coverage internal/instanceexec 92f855820c777b54d5ef9261dfb861d5cb59a228edd1030be30782d6b0282ae2 |