carlos / platform Public

Complete cold-placement runner environment and control transport

Set the guard fixture region and contain command exits in a private test child. Route the independent peer through the real edge process for controller authentication, and run it from the installed image with the normal edge bind capability.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 1cace98c682b6a40b65cb5e64c48cc84f5675c5e parent d995270
2 files changed, +79 −8
  • internal/host/haplacement_root_linux_test.go +75 −6
  • internal/host/haplacement_scenarios_root_linux_test.go +4 −2
diff --git a/internal/host/haplacement_root_linux_test.go b/internal/host/haplacement_root_linux_test.go
index 03e8f1a65..dfa681a7c 100644
--- a/internal/host/haplacement_root_linux_test.go
+++ b/internal/host/haplacement_root_linux_test.go
@@ -34,6 +34,8 @@ import (
"testing"
"time"
+ "golang.org/x/sys/unix"
+
"github.com/carlosframework/platform/internal/activator"
"github.com/carlosframework/platform/internal/analytics"
"github.com/carlosframework/platform/internal/boxid"
@@ -102,6 +104,16 @@ type coldRootAnalytics struct{ n atomic.Int64 }
func (a *coldRootAnalytics) Observe(analytics.Obs) { a.n.Add(1) }
+// A private Go-test payload keeps guard-arm's log.Fatal confined to this
+// fixture child, so a setup error cannot prevent the other witnesses running.
+func TestColdPlacementRootGuardArm(t *testing.T) {
+ if os.Getenv("COLD_ROOT_GUARD_ARM") != "1" {
+ t.Skip("private guard-arm payload")
+ }
+ version.Build = "v2.0.0"
+ RunSystemGuardArm([]string{"--policy", "/etc/carlos/policy.json", "--identity", "/etc/carlos/identity.json", "--enrollment", "/etc/carlos/enrollment.json"})
+}
+
func TestColdPlacementRootAgent(t *testing.T) {
ref := os.Getenv("COLD_ROOT_BOX")
if ref == "" {
@@ -135,7 +147,7 @@ func TestColdPlacementRootAgent(t *testing.T) {
lifecycleCheck(t, "obligation store", lease.SetObligationDir(filepath.Join(data, "obligations")))
files, err := newProductionFilesStore(t.Context(), cfg.Bucket, cfg.Region)
lifecycleCheck(t, "files store", err)
- ctl := instancectl.NewClient(controlsock.Path)
+ ctl := coldRootControlClient(t, ref)
manager := cgroup.SetupRetaining(t.Logf)
eb := &activator.ExecBackend{Cfg: cfg, Registry: reg, DataDir: "/data", OptDir: "/opt/carlos", FilesStore: files, EscrowKey: haEscrowKey(os.Getenv("CARLOS_SECRETS_KEY")), Control: ctl, Cgroups: manager}
if os.Getenv("COLD_ROOT_NO_PROOF") != "1" {
@@ -232,6 +244,54 @@ func TestColdPlacementRootAgent(t *testing.T) {
}, edge.WithBoxLabel(ref))
}
+// Logical boxes have independent agent processes but share this runner's
+// kernel and production instance-control unit. Its SO_PEERCRED gate accepts
+// only carlos-edge.service's MainPID. Relay Sophie's control transport through
+// that process, without replacing any readiness, sweep, launch or stop logic.
+func coldRootControlClient(t *testing.T, ref string) *instancectl.Client {
+ t.Helper()
+ const relay = "/run/carlos/cold-root-control.sock"
+ client := instancectl.NewClient(controlsock.Path)
+ if ref == "sophie" {
+ client.Dial = func(ctx context.Context, _ string) (net.Conn, error) {
+ return (&net.Dialer{}).DialContext(ctx, "unix", relay)
+ }
+ return client
+ }
+ if err := os.Remove(relay); err != nil && !os.IsNotExist(err) {
+ lifecycleCheck(t, "remove stale control relay", err)
+ }
+ listener, err := net.Listen("unix", relay)
+ lifecycleCheck(t, "control relay", err)
+ t.Cleanup(func() { listener.Close() })
+ go func() {
+ for {
+ incoming, err := listener.Accept()
+ if err != nil {
+ return
+ }
+ go func() {
+ defer incoming.Close()
+ upstream, err := net.DialTimeout("unix", controlsock.Path, 5*time.Second)
+ if err != nil {
+ return
+ }
+ defer upstream.Close()
+ done := make(chan struct{})
+ go func() {
+ io.Copy(upstream, incoming)
+ upstream.(*net.UnixConn).CloseWrite()
+ close(done)
+ }()
+ io.Copy(incoming, upstream)
+ incoming.Close()
+ <-done
+ }()
+ }
+ }()
+ return client
+}
+
func TestColdPlacementSealedWake(t *testing.T) { coldRootSealedWake(t) }
func TestColdPlacementCompetingViews(t *testing.T) { coldRootCompetingViews(t) }
func TestColdPlacementExpiredOwnerRecovery(t *testing.T) { coldRootExpiredOwner(t) }
@@ -424,8 +484,8 @@ func coldRootArmGuard(t *testing.T, store release.Store, key ed25519.PrivateKey,
for name, raw := range map[string][]byte{"policy": policy, "identity": identity, "enrollment": enrollment} {
lifecycleCheck(t, "guard input", os.WriteFile("/etc/carlos/"+name+".json", raw, 0600))
}
- // Execute the production entry point in this isolated runner process;
- // no CLI child inherits the operator's credentials or working directory.
+ // Execute the production entry point in a private Go-test child with an
+ // explicit environment and scratch working directory, as for the agents.
t.Run("guard-arm", func(t *testing.T) {
t.Setenv("CARLOS_DEPLOYMENT_BUCKET", actor.ControlBucket)
t.Setenv("CARLOS_S3_ENDPOINT", activationS3Fixture(t, store))
@@ -443,7 +503,14 @@ func coldRootArmGuard(t *testing.T, store release.Store, key ed25519.PrivateKey,
lifecycleCheck(t, "guard executor bytes", err)
lifecycleCheck(t, "guard executor identity "+path, hostfloor.CheckImage(disk.PublicKey, verified, identity, version.Build, runtime.GOOS+"-"+runtime.GOARCH, hostfloor.Digest(raw)))
}
- RunSystemGuardArm([]string{"--policy", "/etc/carlos/policy.json", "--identity", "/etc/carlos/identity.json", "--enrollment", "/etc/carlos/enrollment.json"})
+ cmd := exec.Command(os.Args[0], "-test.run=^TestColdPlacementRootGuardArm$", "-test.v", "-test.timeout=1m")
+ cmd.Dir = lifecycleHome
+ cmd.Env = []string{"COLD_ROOT_GUARD_ARM=1"}
+ for _, name := range []string{"PATH", "TMPDIR", "CARLOS_DATA_DIR", "CARLOS_OPT_DIR", "CARLOS_DEPLOYMENT_BUCKET", "CARLOS_RELEASE_PUBKEY", "CARLOS_S3_ENDPOINT", "AWS_REGION", "AWS_DEFAULT_REGION", "AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_EC2_METADATA_DISABLED", "AWS_CONFIG_FILE", "AWS_SHARED_CREDENTIALS_FILE"} {
+ cmd.Env = append(cmd.Env, name+"="+os.Getenv(name))
+ }
+ out, err := cmd.CombinedOutput()
+ lifecycleCheck(t, "real guard-arm: "+string(out), err)
})
raw, err := os.ReadFile("/etc/systemd/system/carlos-edge.service.d/90-host-floor.conf")
lifecycleCheck(t, "armed edge dependency", err)
@@ -511,6 +578,8 @@ func newColdRootHarness(t *testing.T, mode string) *coldRootHarness {
lifecycleEnvironment(t, server.URL)
t.Setenv("CARLOS_HOST_CLAIM", "")
t.Setenv("CARLOS_REGION_HA", "true")
+ t.Setenv("AWS_REGION", "eu-west-1")
+ t.Setenv("AWS_DEFAULT_REGION", "eu-west-1")
key := ed25519.NewKeyFromSeed(bytes.Repeat([]byte{1}, ed25519.SeedSize))
store := release.NewDirStore(lifecycleHome + "/deployment")
identity := handoverRecoveryIdentity(t, hostbox.Actor{Box: "box", Enrollment: strings.Repeat("a", 32), Revision: 1, Binding: "1", Region: "ie", FleetHomeRegion: "ie", ControlBucket: "deployment"})
@@ -701,9 +770,9 @@ func newColdRootHarness(t *testing.T, mode string) *coldRootHarness {
return os.Chown(p, uid, gid)
}))
addr := "127.0.0.2:443"
- cmd := exec.Command(binary, "-test.run=^TestColdPlacementRootAgent$", "-test.v", "-test.timeout=15m")
+ cmd := exec.Command("/opt/carlos/carlos", "-test.run=^TestColdPlacementRootAgent$", "-test.v", "-test.timeout=15m")
cmd.Dir = ingress
- cmd.SysProcAttr = &syscall.SysProcAttr{Credential: &syscall.Credential{Uid: uint32(uid), Gid: uint32(gid)}}
+ cmd.SysProcAttr = &syscall.SysProcAttr{Credential: &syscall.Credential{Uid: uint32(uid), Gid: uint32(gid)}, AmbientCaps: []uintptr{unix.CAP_NET_BIND_SERVICE}}
for name, value := range env {
switch name {
case "COLD_ROOT_DATA_ENDPOINT":
diff --git a/internal/host/haplacement_scenarios_root_linux_test.go b/internal/host/haplacement_scenarios_root_linux_test.go
index 2dd5816b3..b92e59a67 100644
--- a/internal/host/haplacement_scenarios_root_linux_test.go
+++ b/internal/host/haplacement_scenarios_root_linux_test.go
@@ -27,6 +27,8 @@ import (
"time"
"unsafe"
+ "golang.org/x/sys/unix"
+
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/aws/aws-sdk-go-v2/service/ec2/types"
@@ -673,10 +675,10 @@ func (f *coldRootHarness) restartSophie() {
}
// A fresh OS process, with an independent lease identity and cache. The
// root control sweep is real; callers restart only after stopping writers.
- cmd := exec.Command(os.Args[0], "-test.run=^TestColdPlacementRootAgent$", "-test.v", "-test.timeout=15m")
+ cmd := exec.Command("/opt/carlos/carlos", "-test.run=^TestColdPlacementRootAgent$", "-test.v", "-test.timeout=15m")
cmd.Dir = f.ingress
uid, gid := generationRunnerRegistryUser(f.t)
- cmd.SysProcAttr = &syscall.SysProcAttr{Credential: &syscall.Credential{Uid: uint32(uid), Gid: uint32(gid)}}
+ cmd.SysProcAttr = &syscall.SysProcAttr{Credential: &syscall.Credential{Uid: uint32(uid), Gid: uint32(gid)}, AmbientCaps: []uintptr{unix.CAP_NET_BIND_SERVICE}}
for name, value := range f.env {
switch name {
case "COLD_ROOT_DATA_ENDPOINT":