carlos / platform Public

Validate group boot sysctl directory and exact bootstrap lines

Add /etc/sysctl.d to the existing directory walker and reject substring-based
bootstrap guard bypasses. Refresh the census proposal for the template byte change.
Co-Authored-By: GPT-6 Astra <noreply@openai.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev cde9cf7e994dfd8343aa8d2c7ac6a765065155d6 parent e8c9cd0
5 files changed, +76 −13
  • docs/superpowers/notes/census-proposal-region-ha-p3b1-f4.md +2 −2
  • infra/modules/region-host/group-init.sh.tftpl +1 −1
  • internal/host/group_boot_staging_test.go +69 −6
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −1
  • internal/provision/testdata/plan14-root-reads-region-ha-p3b1-f4.tsv +3 −3
diff --git a/docs/superpowers/notes/census-proposal-region-ha-p3b1-f4.md b/docs/superpowers/notes/census-proposal-region-ha-p3b1-f4.md
index 9249e77bc..4ed86f0fd 100644
--- a/docs/superpowers/notes/census-proposal-region-ha-p3b1-f4.md
+++ b/docs/superpowers/notes/census-proposal-region-ha-p3b1-f4.md
@@ -4,7 +4,7 @@ Ruling `census-ruling-region-ha-p3b1-f4`. The independent reviewer approves or r
| unit | change | read sites | what changed |
|---|---|---|---|
-| `infra/modules/region-host/group-init.sh.tftpl` `external` | body | unchanged (1) | Move bootstrap and chrony staging to root:root 0700 /var/lib/carlos-group-boot through the existing O_NOFOLLOW walker; refuse unsafe preexisting directory. Bootstrap 0700; retain initial hash verification and rehash against a root-only captured SSM digest immediately before all three execs; named noexec refusal. Root reads only its own helper/hash and verified binary; no tenant/app/agent writable input or authority added. Final removal preserved. |
+| `infra/modules/region-host/group-init.sh.tftpl` `external` | body | unchanged (1) | Move bootstrap and chrony staging to root:root 0700 /var/lib/carlos-group-boot through the existing O_NOFOLLOW walker; refuse unsafe preexisting directory. Bootstrap 0700; retain initial hash verification and rehash against a root-only captured SSM digest immediately before all three execs; named noexec refusal. Root reads only its own helper/hash and verified binary; no tenant/app/agent writable input or authority added. Final removal preserved. Round 5 adds /etc/sysctl.d to the same root-owned, non-writable, O_NOFOLLOW directory walker before its existing exclusive sysctl file write; missing directory is created, unsafe ancestors refuse. All other template bytes unchanged in round 5. |
Envelopes re-pinned: `infra/modules/region-host`.
@@ -14,6 +14,6 @@ Recorded dispositions, which each change must still satisfy:
- `infra/modules/region-host/group-init.sh.tftpl` `external`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-region-ha-p3b;basis=New root user-data boot: operator Terraform/SSM supply scoped bootstrap object version/hash, queue, reader inventory and ingress; hash-verified bootstrap verifies signed IMDS identity. Root exclusively writes /etc/carlos/group.json, group-identity.json, region-config.json and group-ingress.json with current kernel boot ID; public address comes from protected IMDSv2, not signed document or headers. Install IMDS denial, chrony, dormant hairpin fence and protected drop-ins before bootstrap/install/start. No agent receipt is read by root; restart authority is separate maintenance permit. F1: operator-seeded SSM boot/bootstrap-object requires floor=absent-expected or required beside key/version/known_readers/deployment_aws_region; root copies it into group.json before config_digest. Missing or invalid floor refuses before bootstrap fetch; Terraform only names this SSM key and does not write the object. Agent and instance-control gain AF_NETLINK in their address-family allowlists, with no CAP_NET_ADMIN grant.
-Seal: `86aa1e39a21072d17678411a4047983a756494b84a25f7719c0cdf4a61cd1b85` → `2cac838a0f7c71af13f551e33df67a471c71a95745b46e26cf9bcefb46d02a0d`.
+Seal: `86aa1e39a21072d17678411a4047983a756494b84a25f7719c0cdf4a61cd1b85` → `6747141e803bcfe7a7482c9d14ed2c8880deee8623f55691bbdf91d5d5411dbf`.
Overlay: `internal/provision/testdata/plan14-root-reads-region-ha-p3b1-f4.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/infra/modules/region-host/group-init.sh.tftpl b/infra/modules/region-host/group-init.sh.tftpl
index 935208a50..90826ea0a 100644
--- a/infra/modules/region-host/group-init.sh.tftpl
+++ b/infra/modules/region-host/group-init.sh.tftpl
@@ -20,7 +20,7 @@ export DEBIAN_FRONTEND=noninteractive AWS_MAX_ATTEMPTS=1 AWS_RETRY_MODE=standard
python3 - <<'PY'
import os, stat
WORK = '/var/lib/carlos-group-boot'
-for path in ['/etc/apt/apt.conf.d', '/etc/needrestart/conf.d', '/etc/carlos', '/etc/chrony/conf.d', '/etc/systemd/system/carlos-edge.service.d', WORK]:
+for path in ['/etc/apt/apt.conf.d', '/etc/needrestart/conf.d', '/etc/carlos', '/etc/chrony/conf.d', '/etc/systemd/system/carlos-edge.service.d', '/etc/sysctl.d', WORK]:
fd = os.open('/', os.O_RDONLY | os.O_DIRECTORY)
try:
parts = path.strip('/').split('/')
diff --git a/internal/host/group_boot_staging_test.go b/internal/host/group_boot_staging_test.go
index 138a23720..a3ddc7e17 100644
--- a/internal/host/group_boot_staging_test.go
+++ b/internal/host/group_boot_staging_test.go
@@ -42,6 +42,25 @@ func between(t *testing.T, s, start, end string) string {
var groupBootTmpfs = regexp.MustCompile(`(^|[^A-Za-z0-9_./-])(/run|/tmp|/dev|/var/tmp|/var/run|/var/lock)(/|$|[^A-Za-z0-9_.-])`)
+// groupBootBootstrapLines are the only non-executing lines that may mention the
+// bootstrap. Each must match a template line exactly, whole.
+var groupBootBootstrapLines = map[string]bool{
+ `# Every execution of the bootstrap is preceded by this check of the staging`: true,
+ `# directory, the noexec flag and the bootstrap bytes against the SSM digest.`: true,
+ ` raise SystemExit('group_boot_bootstrap')`: true,
+ ` with regular(work + '/bootstrap.sha256', 0o600, owner) as f:`: true,
+ ` with regular(work + '/bootstrap', 0o700, owner) as f:`: true,
+ `# fetch verified bootstrap`: true,
+ `# Operator-seeded boot/bootstrap-object has exactly key, version, known_readers,`: true,
+ `if not obj['key'].startswith('bootstrap/' + E['CARLOS_DEPLOYMENT'] + '/' + E['CARLOS_REGION'] + '/') or not obj['version'] or obj['version'] == 'null':`: true,
+ `aws('s3api', 'get-object', '--bucket', E['CARLOS_DEPLOYMENT_BUCKET'], '--key', obj['key'], '--version-id', obj['version'], work + 'bootstrap', region=obj['deployment_aws_region'])`: true,
+ `with open(work + 'bootstrap', 'rb') as f:`: true,
+ `os.chmod(work + 'bootstrap', 0o700)`: true,
+ `write(work + 'bootstrap.sha256', sha.encode(), 0o600)`: true,
+ `# The verified bootstrap revalidates the signed identity and this boot's`: true,
+ `# bootstrap and install channel`: true,
+}
+
// checkGroupBootStaging inspects the paths the script stages, writes and
// executes. Every bootstrap execution must be the line right after the shared
// verification, and nothing may stage or run from a tmpfs default.
@@ -77,19 +96,18 @@ func checkGroupBootStaging(s string) error {
prev = lines[i-1]
}
switch {
- case strings.HasPrefix(line, groupBootStaging+"/bootstrap "):
+ case line == groupBootStaging+"/bootstrap instance-control --group-hairpin-install" || line == groupBootStaging+`/bootstrap system host-env write --group --deployment "$CARLOS_DEPLOYMENT" --region "$CARLOS_REGION" --aws-region "$AWS_REGION" --install`:
execs++
if prev != groupBootVerify {
return fmt.Errorf("line %d executes the bootstrap without the shared verification", i+1)
}
- case strings.HasPrefix(line, "subprocess.check_call([work + 'bootstrap'"):
+ case line == "subprocess.check_call([work + 'bootstrap', 'instance-control', '--group-hairpin-verify-identity'], timeout=10)":
execs++
if prev != "boot_verify.check()" {
return fmt.Errorf("line %d executes the bootstrap without the shared verification", i+1)
}
- case strings.TrimSpace(line) == "with regular(work + '/bootstrap.sha256', 0o600, owner) as f:" || line == "write(work + 'bootstrap.sha256', sha.encode(), 0o600)":
- // The checksum data lines: they read or write the digest and run nothing.
- case strings.Contains(line, "'get-object'") || strings.HasPrefix(line, "with open(work + 'bootstrap', 'rb')") || strings.HasPrefix(line, "os.chmod(work + 'bootstrap', 0o700)") || strings.Contains(line, "bootstrap-object") || strings.Contains(line, "bootstrap-sha256") || strings.Contains(line, "BOOTSTRAP_") || strings.HasPrefix(line, "#") || strings.HasPrefix(line, "# ") || strings.Contains(line, "verified bootstrap") || strings.Contains(line, "regular(work + '/bootstrap") || strings.Contains(line, "raise SystemExit('group_boot_bootstrap')") || strings.HasPrefix(line, "if not obj['key'].startswith('bootstrap/'"):
+ case groupBootBootstrapLines[line]:
+ // Audited data, check and comment lines: they run nothing.
default:
return fmt.Errorf("line %d references the bootstrap outside the audited forms: %s", i+1, line)
}
@@ -151,7 +169,17 @@ func TestGroupBootStagingGuard(t *testing.T) {
"unverified exec with digest comment": func(s string) string {
return strings.Replace(s, groupBootVerify+"\n"+install, install+" # bootstrap.sha256", 1)
},
- "verify is not helper": func(s string) string { return strings.Replace(s, groupBootVerify+"\n"+install, "true\n"+install, 1) },
+ "install with verified comment": func(s string) string { return strings.Replace(s, install, install+" # verified bootstrap", 1) },
+ "install with BOOTSTRAP_": func(s string) string { return strings.Replace(s, install, install+" BOOTSTRAP_X", 1) },
+ "install with bootstrap-object": func(s string) string { return strings.Replace(s, install, install+" bootstrap-object", 1) },
+ "install with get-object": func(s string) string { return strings.Replace(s, install, install+" 'get-object'", 1) },
+ "hostenv with get-object": func(s string) string { return strings.Replace(s, hostenv, hostenv+" 'get-object'", 1) },
+ "python exec with comment": func(s string) string {
+ return strings.Replace(s, "timeout=10)\n", "timeout=10) # verified bootstrap\n", 1)
+ },
+ "extra sh bootstrap argument": func(s string) string { return s + "sh " + groupBootStaging + "/bootstrap version\n" },
+ "unknown comment": func(s string) string { return s + "# verified bootstrap\n" },
+ "verify is not helper": func(s string) string { return strings.Replace(s, groupBootVerify+"\n"+install, "true\n"+install, 1) },
"python3 without -I": func(s string) string {
return strings.Replace(s, groupBootVerify+"\n"+hostenv, "python3 "+strings.TrimPrefix(groupBootVerify, "python3 -I ")+"\n"+hostenv, 1)
},
@@ -270,6 +298,41 @@ func TestGroupBootWalker(t *testing.T) {
}
})
}
+ t.Run("sysctl.d absent is created", func(t *testing.T) {
+ root := t.TempDir()
+ mkdirMode(t, filepath.Join(root, "var"), 0o755)
+ mkdirMode(t, filepath.Join(root, "var", "lib"), 0o755)
+ if out, err := runPython(t, t.TempDir(), walkerSource(t, root)); err != nil {
+ t.Fatalf("refused: %v %s", err, out)
+ }
+ info, err := os.Lstat(filepath.Join(root, "etc", "sysctl.d"))
+ if err != nil || !info.IsDir() || info.Mode().Perm() != 0o755 {
+ t.Fatalf("sysctl.d not created 0755: %v %v", info, err)
+ }
+ })
+ for name, setup := range map[string]func(t *testing.T, dir string){
+ "sysctl.d group writable": func(t *testing.T, dir string) { mkdirMode(t, dir, 0o775) },
+ "sysctl.d world writable": func(t *testing.T, dir string) { mkdirMode(t, dir, 0o757) },
+ "sysctl.d symlink": func(t *testing.T, dir string) {
+ target := filepath.Join(filepath.Dir(filepath.Dir(dir)), "elsewhere")
+ mkdirMode(t, target, 0o755)
+ if err := os.Symlink(target, dir); err != nil {
+ t.Fatal(err)
+ }
+ },
+ } {
+ t.Run(name, func(t *testing.T) {
+ root := t.TempDir()
+ mkdirMode(t, filepath.Join(root, "var"), 0o755)
+ mkdirMode(t, filepath.Join(root, "var", "lib"), 0o755)
+ mkdirMode(t, filepath.Join(root, "etc"), 0o755)
+ setup(t, filepath.Join(root, "etc", "sysctl.d"))
+ out, err := runPython(t, t.TempDir(), walkerSource(t, root))
+ if err == nil || !strings.Contains(out, "group_boot_directory") && !strings.Contains(out, "Too many levels") && !strings.Contains(out, "Not a directory") {
+ t.Fatalf("accepted: %v %s", err, out)
+ }
+ })
+ }
t.Run("wrong group", func(t *testing.T) {
root := t.TempDir()
mkdirMode(t, filepath.Join(root, "var"), 0o755)
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index 6d9627e9d..481343791 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -88,4 +88,4 @@ plan14-root-reads-region-ha-p3b.tsv face84b4c688cd3c179b0a34ced4d3521e71de8e63cb
plan14-root-reads-stateless-coordinator-oneboxfleet.tsv face84b4c688cd3c179b0a34ced4d3521e71de8e63cbd45f21c27972c5b1a921
plan14-root-reads-region-ha-group-rtb.tsv 526d434888d043a8b09d8fe196f6324782d6ca20d759b080f99daa528adf6a32
plan14-root-reads-region-ha-p3b1-fixes.tsv 86aa1e39a21072d17678411a4047983a756494b84a25f7719c0cdf4a61cd1b85
-plan14-root-reads-region-ha-p3b1-f4.tsv 2cac838a0f7c71af13f551e33df67a471c71a95745b46e26cf9bcefb46d02a0d
+plan14-root-reads-region-ha-p3b1-f4.tsv 6747141e803bcfe7a7482c9d14ed2c8880deee8623f55691bbdf91d5d5411dbf
diff --git a/internal/provision/testdata/plan14-root-reads-region-ha-p3b1-f4.tsv b/internal/provision/testdata/plan14-root-reads-region-ha-p3b1-f4.tsv
index b894664c8..736b3ecd5 100644
--- a/internal/provision/testdata/plan14-root-reads-region-ha-p3b1-f4.tsv
+++ b/internal/provision/testdata/plan14-root-reads-region-ha-p3b1-f4.tsv
@@ -1,5 +1,5 @@
# Census overlay region-ha-p3b1-f4, written by census-propose (#369). census-ruling-region-ha-p3b1-f4, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-region-ha-p3b1-f4.md.
# 1 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
-@legacy d5a8d1383df545942daa6e4bfe44cee51aa162a144a8c1d3de6f518a9907e02d infra/modules/region-host/group-init.sh.tftpl external legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-p3b;basis=New root user-data boot: operator Terraform/SSM supply scoped bootstrap object version/hash, queue, reader inventory and ingress; hash-verified bootstrap verifies signed IMDS identity. Root exclusively writes /etc/carlos/group.json, group-identity.json, region-config.json and group-ingress.json with current kernel boot ID; public address comes from protected IMDSv2, not signed document or headers. Install IMDS denial, chrony, dormant hairpin fence and protected drop-ins before bootstrap/install/start. No agent receipt is read by root; restart authority is separate maintenance permit. F1: operator-seeded SSM boot/bootstrap-object requires floor=absent-expected or required beside key/version/known_readers/deployment_aws_region; root copies it into group.json before config_digest. Missing or invalid floor refuses before bootstrap fetch; Terraform only names this SSM key and does not write the object. Agent and instance-control gain AF_NETLINK in their address-family allowlists, with no CAP_NET_ADMIN grant.;rev3=census-ruling-region-ha-p3b1-f4;basis=Move bootstrap and chrony staging to root:root 0700 /var/lib/carlos-group-boot through the existing O_NOFOLLOW walker; refuse unsafe preexisting directory. Bootstrap 0700; retain initial hash verification and rehash against a root-only captured SSM digest immediately before all three execs; named noexec refusal. Root reads only its own helper/hash and verified binary; no tenant/app/agent writable input or authority added. Final removal preserved. file:external@0 3caa0b1165ea720b77b282da0f2a370a16bccd1dba9b0ba8761b09fc63e178ab
-infra/modules/region-host/group-init.sh.tftpl external legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-p3b;basis=New root user-data boot: operator Terraform/SSM supply scoped bootstrap object version/hash, queue, reader inventory and ingress; hash-verified bootstrap verifies signed IMDS identity. Root exclusively writes /etc/carlos/group.json, group-identity.json, region-config.json and group-ingress.json with current kernel boot ID; public address comes from protected IMDSv2, not signed document or headers. Install IMDS denial, chrony, dormant hairpin fence and protected drop-ins before bootstrap/install/start. No agent receipt is read by root; restart authority is separate maintenance permit. F1: operator-seeded SSM boot/bootstrap-object requires floor=absent-expected or required beside key/version/known_readers/deployment_aws_region; root copies it into group.json before config_digest. Missing or invalid floor refuses before bootstrap fetch; Terraform only names this SSM key and does not write the object. Agent and instance-control gain AF_NETLINK in their address-family allowlists, with no CAP_NET_ADMIN grant.;rev3=census-ruling-region-ha-p3b1-f4;basis=Move bootstrap and chrony staging to root:root 0700 /var/lib/carlos-group-boot through the existing O_NOFOLLOW walker; refuse unsafe preexisting directory. Bootstrap 0700; retain initial hash verification and rehash against a root-only captured SSM digest immediately before all three execs; named noexec refusal. Root reads only its own helper/hash and verified binary; no tenant/app/agent writable input or authority added. Final removal preserved. file:external@0 3caa0b1165ea720b77b282da0f2a370a16bccd1dba9b0ba8761b09fc63e178ab
-@coverage infra/modules/region-host 906e1139a9a5e62d61ecbf8e0dc7c48a0453b4fab17f0dcfec8ef49d1a9c8b70
+@legacy 3424be63316e3d85cf37de4550c8e3ce7b8e236970a3bd5d1a99c3e332d5045a infra/modules/region-host/group-init.sh.tftpl external legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-p3b;basis=New root user-data boot: operator Terraform/SSM supply scoped bootstrap object version/hash, queue, reader inventory and ingress; hash-verified bootstrap verifies signed IMDS identity. Root exclusively writes /etc/carlos/group.json, group-identity.json, region-config.json and group-ingress.json with current kernel boot ID; public address comes from protected IMDSv2, not signed document or headers. Install IMDS denial, chrony, dormant hairpin fence and protected drop-ins before bootstrap/install/start. No agent receipt is read by root; restart authority is separate maintenance permit. F1: operator-seeded SSM boot/bootstrap-object requires floor=absent-expected or required beside key/version/known_readers/deployment_aws_region; root copies it into group.json before config_digest. Missing or invalid floor refuses before bootstrap fetch; Terraform only names this SSM key and does not write the object. Agent and instance-control gain AF_NETLINK in their address-family allowlists, with no CAP_NET_ADMIN grant.;rev3=census-ruling-region-ha-p3b1-f4;basis=Move bootstrap and chrony staging to root:root 0700 /var/lib/carlos-group-boot through the existing O_NOFOLLOW walker; refuse unsafe preexisting directory. Bootstrap 0700; retain initial hash verification and rehash against a root-only captured SSM digest immediately before all three execs; named noexec refusal. Root reads only its own helper/hash and verified binary; no tenant/app/agent writable input or authority added. Final removal preserved. Round 5 adds /etc/sysctl.d to the same root-owned, non-writable, O_NOFOLLOW directory walker before its existing exclusive sysctl file write; missing directory is created, unsafe ancestors refuse. All other template bytes unchanged in round 5. file:external@0 0ae418d250d74909847959a71097a8a523ad157c479401d2d71d2212cbaa14f4
+infra/modules/region-host/group-init.sh.tftpl external legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-p3b;basis=New root user-data boot: operator Terraform/SSM supply scoped bootstrap object version/hash, queue, reader inventory and ingress; hash-verified bootstrap verifies signed IMDS identity. Root exclusively writes /etc/carlos/group.json, group-identity.json, region-config.json and group-ingress.json with current kernel boot ID; public address comes from protected IMDSv2, not signed document or headers. Install IMDS denial, chrony, dormant hairpin fence and protected drop-ins before bootstrap/install/start. No agent receipt is read by root; restart authority is separate maintenance permit. F1: operator-seeded SSM boot/bootstrap-object requires floor=absent-expected or required beside key/version/known_readers/deployment_aws_region; root copies it into group.json before config_digest. Missing or invalid floor refuses before bootstrap fetch; Terraform only names this SSM key and does not write the object. Agent and instance-control gain AF_NETLINK in their address-family allowlists, with no CAP_NET_ADMIN grant.;rev3=census-ruling-region-ha-p3b1-f4;basis=Move bootstrap and chrony staging to root:root 0700 /var/lib/carlos-group-boot through the existing O_NOFOLLOW walker; refuse unsafe preexisting directory. Bootstrap 0700; retain initial hash verification and rehash against a root-only captured SSM digest immediately before all three execs; named noexec refusal. Root reads only its own helper/hash and verified binary; no tenant/app/agent writable input or authority added. Final removal preserved. Round 5 adds /etc/sysctl.d to the same root-owned, non-writable, O_NOFOLLOW directory walker before its existing exclusive sysctl file write; missing directory is created, unsafe ancestors refuse. All other template bytes unchanged in round 5. file:external@0 0ae418d250d74909847959a71097a8a523ad157c479401d2d71d2212cbaa14f4
+@coverage infra/modules/region-host 1644713517d7b1044eefc2d4c4ce2c33394a83e088ee8bcb86b08c019f5b37ff