carlos / platform Public

Fix cold placement fixture certificates and gate credentials

Seed each real edge certificate cache, copy independent fold files without hardlinks, and authenticate requests with gate cookies. Give fault injection ownership of its published control fixtures.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 3869cf4581fe2851d2c2513c1c6377e6a2bba442 parent e848535
2 files changed, +61 −14
  • internal/host/haplacement_root_linux_test.go +56 −4
  • internal/host/haplacement_scenarios_root_linux_test.go +5 −10
diff --git a/internal/host/haplacement_root_linux_test.go b/internal/host/haplacement_root_linux_test.go
index a54ee8611..aa01d7e67 100644
--- a/internal/host/haplacement_root_linux_test.go
+++ b/internal/host/haplacement_root_linux_test.go
@@ -34,6 +34,7 @@ import (
"testing"
"time"
+ "golang.org/x/crypto/acme/autocert"
"golang.org/x/sys/unix"
"github.com/carlosframework/platform/internal/activator"
@@ -236,6 +237,7 @@ func TestColdPlacementRootAgent(t *testing.T) {
}))
defer admin.Close()
lifecycleCheck(t, "admin address", os.WriteFile(filepath.Join(data, "cold-root-admin"), []byte(admin.URL), 0600))
+ coldRootSeedCertificates(t, store, autocert.DirCache(filepath.Join(data, "acme")))
edge.RunWithActivatorReady([]string{"--registry", filepath.Join(data, "registry.db"), "--https", os.Getenv("COLD_ROOT_HTTPS"), "--http", "127.0.0.1:0"}, svc, nil, func(e *edge.Edge) {
activeEdge = e
e.EnableUsage(meter)
@@ -304,7 +306,7 @@ func TestColdPlacementRootRunner(t *testing.T) {
f := newColdRootHarness(t, "normal")
model, client, ctl, ingress := f.model, f.client, f.ctl, f.ingress
- response, err := coldRootGET(client)
+ response, err := coldRootGET(t, client)
lifecycleCheck(t, "non-choice request", err)
body, err := io.ReadAll(response.Body)
response.Body.Close()
@@ -368,7 +370,7 @@ func TestColdPlacementRootRunner(t *testing.T) {
readyUntil := time.Now().Add(2 * time.Minute)
var recovered bool
for time.Now().Before(readyUntil) {
- response, e := coldRootGET(client)
+ response, e := coldRootGET(t, client)
if e == nil {
raw, _ := io.ReadAll(response.Body)
response.Body.Close()
@@ -440,6 +442,28 @@ func coldRootCertificate(t *testing.T, store release.Store, caFile string) {
lifecycleCheck(t, "sibling certificate publication", err)
}
+func TestColdPlacementFixtureCertificateCache(t *testing.T) {
+ store := release.NewDirStore(t.TempDir())
+ caFile := filepath.Join(t.TempDir(), "ca.pem")
+ coldRootCertificate(t, store, caFile)
+ cache := autocert.DirCache(t.TempDir())
+ coldRootSeedCertificates(t, store, cache)
+ trust, err := os.ReadFile(caFile)
+ lifecycleCheck(t, "fixture trust", err)
+ roots := x509.NewCertPool()
+ if !roots.AppendCertsFromPEM(trust) {
+ t.Fatal("invalid fixture trust")
+ }
+ for _, host := range []string{lifecycleHost, lifecycleSibling} {
+ raw, err := cache.Get(t.Context(), host)
+ lifecycleCheck(t, "seeded cache", err)
+ cert, err := tls.X509KeyPair(raw, raw)
+ lifecycleCheck(t, "seeded key pair", err)
+ _, err = cert.Leaf.Verify(x509.VerifyOptions{Roots: roots, DNSName: host})
+ lifecycleCheck(t, "trusted fixture identity", err)
+ }
+}
+
func coldRootReadStats(t *testing.T, data string) coldRootStats {
raw, err := os.ReadFile(filepath.Join(data, "cold-root-admin"))
lifecycleCheck(t, "stats address", err)
@@ -453,12 +477,34 @@ func coldRootReadStats(t *testing.T, data string) coldRootStats {
return stats
}
-func coldRootGET(client *http.Client) (*http.Response, error) {
+func coldRootSeedCertificates(t *testing.T, store release.Store, cache autocert.Cache) {
+ t.Helper()
+ for _, host := range []string{lifecycleHost, lifecycleSibling} {
+ raw, _, err := store.Get(t.Context(), "control/certs/"+host)
+ lifecycleCheck(t, "fixture certificate", err)
+ lifecycleCheck(t, "seed edge certificate cache", cache.Put(t.Context(), host, raw))
+ }
+}
+
+func coldRootAuthorize(t *testing.T, req *http.Request) {
+ t.Helper()
+ reg, err := registry.Open("/data/registry.db")
+ lifecycleCheck(t, "gate registry", err)
+ defer reg.Close()
+ route, err := reg.Get(req.URL.Hostname())
+ lifecycleCheck(t, "gate route", err)
+ if route == nil || route.Gate == "" {
+ t.Fatal("fixture route has no gate")
+ }
+ req.AddCookie(&http.Cookie{Name: gate.CookieName, Value: gate.Mint(route.Host, route.Gate, time.Now().Add(time.Hour))})
+}
+
+func coldRootGET(t *testing.T, client *http.Client) (*http.Response, error) {
req, err := http.NewRequest("GET", "https://"+lifecycleHost+"/", nil)
if err != nil {
return nil, err
}
- req.SetBasicAuth("", "cold-root-password")
+ coldRootAuthorize(t, req)
return client.Do(req)
}
@@ -735,6 +781,12 @@ func newColdRootHarness(t *testing.T, mode string) *coldRootHarness {
lifecycleCheck(t, "fixture daemon reload", err)
coldRootProbeFixtures(t, uid, gid)
coldRootPrepareView(t, store, mode)
+ lifecycleCheck(t, "fault publication owner", filepath.Walk(lifecycleHome+"/deployment/control", func(path string, _ os.FileInfo, err error) error {
+ if err != nil {
+ return err
+ }
+ return os.Chown(path, uid, gid)
+ }))
if mode == "switch-off" {
env["CARLOS_REGION_HA"] = "0"
}
diff --git a/internal/host/haplacement_scenarios_root_linux_test.go b/internal/host/haplacement_scenarios_root_linux_test.go
index b92e59a67..36dcc0879 100644
--- a/internal/host/haplacement_scenarios_root_linux_test.go
+++ b/internal/host/haplacement_scenarios_root_linux_test.go
@@ -126,8 +126,6 @@ func coldRootPrepareView(t *testing.T, store release.Store, mode string) {
}
func coldRootDivergentView(t *testing.T, root string) string {
dst := filepath.Join(root, "view")
- // Immutable release artifacts are hardlinked, not copied. Only edges files
- // are copied, so the two children can retain deliberately different folds.
src := lifecycleHome + "/deployment"
lifecycleCheck(t, "independent fold", filepath.Walk(src, func(p string, info os.FileInfo, err error) error {
if err != nil {
@@ -141,14 +139,11 @@ func coldRootDivergentView(t *testing.T, root string) string {
if info.IsDir() {
return os.MkdirAll(target, 0755)
}
- if strings.Contains(rel, "edges/") {
- raw, err := os.ReadFile(p)
- if err != nil {
- return err
- }
- return os.WriteFile(target, raw, 0644)
+ raw, err := os.ReadFile(p)
+ if err != nil {
+ return err
}
- return os.Link(p, target)
+ return os.WriteFile(target, raw, 0644)
}))
ds := release.NewDirStore(dst)
raw, etag, err := ds.Get(t.Context(), edgesFileKey("leo"))
@@ -171,7 +166,7 @@ func (f *coldRootHarness) request(ref, host string) (int, string, http.Header) {
}
req, err := http.NewRequest("GET", "https://"+host+"/", nil)
lifecycleCheck(f.t, "request", err)
- req.SetBasicAuth("", "cold-root-password")
+ coldRootAuthorize(f.t, req)
response, err := client.Do(req)
lifecycleCheck(f.t, "request "+ref, err)
defer response.Body.Close()