Close boot guard comment bypass and verify witness pointers in Go
Co-Authored-By: GPT-6 Astra <noreply@openai.com>
3 files changed,
+127
−5
internal/host/group_boot_staging_test.go+16 −5scripts/witness-pointer/main.go+57 −0scripts/witness-pointer/main_test.go+54 −0
diff --git a/internal/host/group_boot_staging_test.go b/internal/host/group_boot_staging_test.go| index ba5ab1154..138a23720 100644 |
| --- a/internal/host/group_boot_staging_test.go |
| +++ b/internal/host/group_boot_staging_test.go |
| @@ -69,7 +69,7 @@ func checkGroupBootStaging(s string) error { |
| lines := strings.Split(s, "\n") |
| execs := 0 |
| for i, line := range lines { |
| - if !strings.Contains(line, "bootstrap") || strings.Contains(line, "bootstrap.sha256") && !strings.Contains(line, "subprocess") { |
| + if !strings.Contains(line, "bootstrap") { |
| continue |
| } |
| prev := "" |
| @@ -87,7 +87,9 @@ func checkGroupBootStaging(s string) error { |
| if prev != "boot_verify.check()" { |
| return fmt.Errorf("line %d executes the bootstrap without the shared verification", i+1) |
| } |
| - case strings.Contains(line, "'get-object'") || strings.HasPrefix(line, "with open(work + 'bootstrap', 'rb')") || strings.HasPrefix(line, "os.chmod(work + 'bootstrap', 0o700)") || strings.HasPrefix(line, "write(work + 'bootstrap.sha256'") || 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 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/'"): |
| default: |
| return fmt.Errorf("line %d references the bootstrap outside the audited forms: %s", i+1, line) |
| } |
| @@ -137,9 +139,18 @@ func TestGroupBootStagingGuard(t *testing.T) { |
| "verify not adjacent": func(s string) string { |
| return strings.Replace(s, groupBootVerify+"\n"+install, groupBootVerify+"\nsysctl -p /dev/null\n"+install, 1) |
| }, |
| - "extra direct exec": func(s string) string { return s + groupBootStaging + "/bootstrap version\n" }, |
| - "extra shell wrapper": func(s string) string { return s + "sh " + groupBootStaging + "/bootstrap version\n" }, |
| - "extra python exec": func(s string) string { return s + "subprocess.run([work + 'bootstrap', 'x'])\n" }, |
| + "extra direct exec": func(s string) string { return s + groupBootStaging + "/bootstrap version\n" }, |
| + "extra shell wrapper": func(s string) string { return s + "sh " + groupBootStaging + "/bootstrap version\n" }, |
| + "extra python exec": func(s string) string { return s + "subprocess.run([work + 'bootstrap', 'x'])\n" }, |
| + "extra direct exec with digest comment": func(s string) string { |
| + return s + groupBootStaging + "/bootstrap version # bootstrap.sha256\n" |
| + }, |
| + "extra shell wrapper with digest comment": func(s string) string { |
| + return s + "sh " + groupBootStaging + "/bootstrap version # bootstrap.sha256\n" |
| + }, |
| + "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) }, |
| "python3 without -I": func(s string) string { |
| return strings.Replace(s, groupBootVerify+"\n"+hostenv, "python3 "+strings.TrimPrefix(groupBootVerify, "python3 -I ")+"\n"+hostenv, 1) |
diff --git a/scripts/witness-pointer/main.go b/scripts/witness-pointer/main.go| new file mode 100644 |
| index 000000000..7ce77d638 |
| --- /dev/null |
| +++ b/scripts/witness-pointer/main.go |
| @@ -0,0 +1,57 @@ |
| +package main |
| + |
| +import ( |
| + "context" |
| + "crypto/ed25519" |
| + "encoding/base64" |
| + "encoding/json" |
| + "fmt" |
| + "os" |
| + "strings" |
| + |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +type pointerStore struct { |
| + release.Store |
| + body []byte |
| +} |
| + |
| +func (s pointerStore) Get(_ context.Context, key string) ([]byte, string, error) { |
| + if key != release.SystemPointerKey("router", "stable") { |
| + return nil, "", fmt.Errorf("unexpected key %q", key) |
| + } |
| + return s.body, "local", nil |
| +} |
| + |
| +func verify(pointerPath, pubkeyPath string) (*release.SystemPointer, error) { |
| + body, err := os.ReadFile(pointerPath) |
| + if err != nil { |
| + return nil, err |
| + } |
| + key, err := os.ReadFile(pubkeyPath) |
| + if err != nil { |
| + return nil, err |
| + } |
| + pub, err := base64.StdEncoding.DecodeString(strings.TrimSpace(string(key))) |
| + if err != nil || len(pub) != ed25519.PublicKeySize { |
| + return nil, fmt.Errorf("invalid release public key") |
| + } |
| + p, _, err := release.GetSystemPointer(context.Background(), pointerStore{body: body}, ed25519.PublicKey(pub), "router", "stable") |
| + return p, err |
| +} |
| + |
| +func main() { |
| + if len(os.Args) != 3 { |
| + fmt.Fprintln(os.Stderr, "usage: witness-pointer POINTER PUBKEY") |
| + os.Exit(2) |
| + } |
| + p, err := verify(os.Args[1], os.Args[2]) |
| + if err == nil { |
| + err = json.NewEncoder(os.Stdout).Encode(p) |
| + } |
| + if err != nil { |
| + fmt.Fprintln(os.Stderr, err) |
| + os.Exit(1) |
| + } |
| +} |
diff --git a/scripts/witness-pointer/main_test.go b/scripts/witness-pointer/main_test.go| new file mode 100644 |
| index 000000000..663c9c709 |
| --- /dev/null |
| +++ b/scripts/witness-pointer/main_test.go |
| @@ -0,0 +1,54 @@ |
| +package main |
| + |
| +import ( |
| + "crypto/ed25519" |
| + "crypto/rand" |
| + "encoding/base64" |
| + "encoding/json" |
| + "os" |
| + "path/filepath" |
| + "testing" |
| +) |
| + |
| +func TestVerifyUsesReleasePointerValidation(t *testing.T) { |
| + pub, priv, err := ed25519.GenerateKey(rand.Reader) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + dir := t.TempDir() |
| + keyPath, pointerPath := filepath.Join(dir, "pub"), filepath.Join(dir, "pointer") |
| + if err := os.WriteFile(keyPath, []byte(base64.StdEncoding.EncodeToString(pub)+"\n"), 0600); err != nil { |
| + t.Fatal(err) |
| + } |
| + payload := `{"schema":1,"component":"router","channel":"stable","current":{"version":"v0.34.2","artifacts":{"linux-arm64":{"key":"bootstrap/router/v0.34.2/carlos-linux-arm64","sha256":"f837b3763457825d469c89cde80fb85fd45f50fd1872a8d53147d53fdebfdc01"}}},"spread":"0s","promoted_at":"2026-11-04T17:34:03Z"}` |
| + encoded := base64.StdEncoding.EncodeToString([]byte(payload)) |
| + sig := base64.StdEncoding.EncodeToString(ed25519.Sign(priv, []byte(encoded))) |
| + for _, tc := range []struct { |
| + name, body, signature string |
| + grant any |
| + ok bool |
| + }{ |
| + {"valid", encoded, sig, nil, true}, |
| + {"tampered payload", encoded + "A", sig, nil, false}, |
| + {"bad signature", encoded, "AA==", nil, false}, |
| + {"scoped signer", encoded, sig, map[string]string{"key": "x"}, false}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + wrapper := map[string]any{"payload": tc.body, "sig": tc.signature} |
| + if tc.grant != nil { |
| + wrapper["grant"] = tc.grant |
| + } |
| + raw, err := json.Marshal(wrapper) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := os.WriteFile(pointerPath, raw, 0600); err != nil { |
| + t.Fatal(err) |
| + } |
| + _, err = verify(pointerPath, keyPath) |
| + if (err == nil) != tc.ok { |
| + t.Fatalf("verify error = %v; want success %v", err, tc.ok) |
| + } |
| + }) |
| + } |
| +} |