devbox mode (#474): ServeDevbox refuses extra wildcard parents
Devbox certificates come only from CARLOS_WILDCARD_DOMAINS, so ServeDevbox now refuses PLATFORM_APPS_DOMAIN and CARLOS_STEERING_ZONE_ID: each adds a parent the devbox's DNS credential cannot publish. The end-to-end test binds 127.0.0.1:0 and learns the address through serveDevbox's bound hook instead of reusing a closed port. A comment notes the renewal loop outlives ServeDevbox because the process exits after it returns.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
internal/edge/devbox.go+25 −4internal/edge/devbox_test.go+37 −9
Intent
<task-notification> <task-id>ac566491bcc233331</task-id> <tool-use-id>toolu_01MpjViUxZkfKMRVCVuhJpiN</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/9b370a04-693c-4bda-b2eb-9a4b08f7626d/tasks/ac566491bcc233331.output</output-file> <status>completed</status> <summary>Agent "Implement Task 3: ServeDevbox front door" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>Status: DONE. Not pushed. Commit: 3a8a59f6 "devbox mode (#474): ServeDevbox, the wildcard-only front door". It adds internal/edge/devbox.go and devbox_test.go. Tests: `go test ./internal/edge -run 'TestDevbox'` passes all 6 tests (the brief's 4, plus an end-to-end serve-and-drain and a bind-failure test), after a compile-failure RED. `TestWildcard`, gofmt, vet and the darwin and windows builds are all clean. R4: the fake DNS saw 0 `present` calls and the counting CA saw 0 requests. Swapping in an autocert manager as a check made the test fail (4 CA requests and a new account key). Concerns: 1. The wildcard renewal loop has no stop, as in Run, so it keeps running after ServeDevbox returns. The later task that composes servers may need a stop added in wildcard.go. 2. If `PLATFORM_APPS_DOMAIN` or `CARLOS_STEERING_ZONE_ID` is set next to `CARLOS_WILDCARD_DOMAINS`, the manager adds parents the devbox's DNS credential can't publish. That means hourly failed order attempts: they cost the new-order allowance, not the failed-validation one. ServeDevbox doesn't refuse this yet, and refusing it would be a one-line check. 3. The end-to-end test reuses a free port after closing it, which could rarely flake. Report: /home/paulca/amadan.net/carlos/platform/.claude/worktrees/devbox-mode/.superpowers/sdd/2026-10-30-devbox-mode/task-3-report.md</result> <usage><subagent_tokens>116170</subagent_tokens><tool_uses>29</tool_uses><duration_ms>356392</duration_ms></usage> </task-notification>
Attributed to this commit: 8.46 g CO₂e (1,050,323 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on design-devbox-mode, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/internal/edge/devbox.go b/internal/edge/devbox.go| index ddac66f02..3d76badc1 100644 |
| --- a/internal/edge/devbox.go |
| +++ b/internal/edge/devbox.go |
| @@ -26,6 +26,7 @@ import ( |
| "net/http" |
| "net/netip" |
| "os" |
| + "strings" |
| "time" |
| "github.com/carlosframework/platform/internal/registry" |
| @@ -47,6 +48,13 @@ type DevboxConfig struct { |
| // refusal and bind failure is returned, never fatal: a caller may run this |
| // beside another server in one process. |
| func ServeDevbox(ctx context.Context, cfg DevboxConfig) error { |
| + return serveDevbox(ctx, cfg, nil) |
| +} |
| + |
| +// serveDevbox is ServeDevbox with a hook that is handed the bound address |
| +// once the listener exists, so a test can listen on port 0 and dial what it |
| +// got instead of reusing a port it closed. nil in production. |
| +func serveDevbox(ctx context.Context, cfg DevboxConfig, bound func(net.Addr)) error { |
| // The address first, before anything is built: a devbox is reachable |
| // only on its tailnet address, and an empty or wildcard host would put |
| // every route on the office LAN too. |
| @@ -64,12 +72,20 @@ func ServeDevbox(ctx context.Context, cfg DevboxConfig) error { |
| if cfg.SpoolRoot == "" { |
| return errors.New("edge: devbox: no spool root") |
| } |
| - // The devbox's parent is a configured one. An apps domain alone would |
| - // make newWildcardFromEnv build a manager whose parents come only from |
| - // routes, which is not the one wildcard a devbox is set up for. |
| + // Devbox certificates come only from CARLOS_WILDCARD_DOMAINS. The two |
| + // other variables newWildcardFromEnv turns into parents are refused, not |
| + // ignored: an apps domain derives a parent per account from routes, and a |
| + // steering zone adds the apps domain itself. The devbox's DNS credential |
| + // can publish neither challenge, so each would be an order attempt that |
| + // fails at present, every hour. |
| if len(splitDomains(os.Getenv("CARLOS_WILDCARD_DOMAINS"))) == 0 { |
| return errors.New("edge: devbox: CARLOS_WILDCARD_DOMAINS is unset; the wildcard is the only certificate devbox mode serves") |
| } |
| + for _, name := range []string{"PLATFORM_APPS_DOMAIN", "CARLOS_STEERING_ZONE_ID"} { |
| + if strings.TrimSpace(os.Getenv(name)) != "" { |
| + return fmt.Errorf("edge: devbox: %s is set; devbox certificates come only from CARLOS_WILDCARD_DOMAINS, so unset it", name) |
| + } |
| + } |
| e, err := newDevboxEdge(cfg) |
| if err != nil { |
| @@ -96,12 +112,17 @@ func ServeDevbox(ctx context.Context, cfg DevboxConfig) error { |
| if err != nil { |
| return err |
| } |
| + if bound != nil { |
| + bound(ln.Addr()) |
| + } |
| stop := make(chan struct{}) |
| defer close(stop) |
| e.OnReload(w.refresh) |
| w.refresh() |
| - go w.run() // process-lifetime, as in Run: run has no stop |
| + // run has no stop and outlives this function; that is fine because the |
| + // process exits once ServeDevbox returns. |
| + go w.run() |
| go e.Watch(stop) |
| // ReadHeaderTimeout for the same slow-header reason as Run's servers, |
diff --git a/internal/edge/devbox_test.go b/internal/edge/devbox_test.go| index 059e8007e..60867d404 100644 |
| --- a/internal/edge/devbox_test.go |
| +++ b/internal/edge/devbox_test.go |
| @@ -205,18 +205,20 @@ func TestDevboxServesTheWildcardAndDrains(t *testing.T) { |
| t.Fatal(err) |
| } |
| - probe, err := net.Listen("tcp", "127.0.0.1:0") |
| - if err != nil { |
| - t.Fatal(err) |
| - } |
| - addr := probe.Addr().String() |
| - probe.Close() |
| - |
| ctx, cancel := context.WithCancel(context.Background()) |
| defer cancel() |
| - cfg := DevboxConfig{Registry: openReg(t), ListenAddr: addr, CertDir: certDir, SpoolRoot: t.TempDir()} |
| + cfg := DevboxConfig{Registry: openReg(t), ListenAddr: "127.0.0.1:0", CertDir: certDir, SpoolRoot: t.TempDir()} |
| + boundAddr := make(chan string, 1) |
| done := make(chan error, 1) |
| - go func() { done <- ServeDevbox(ctx, cfg) }() |
| + go func() { done <- serveDevbox(ctx, cfg, func(a net.Addr) { boundAddr <- a.String() }) }() |
| + var addr string |
| + select { |
| + case addr = <-boundAddr: |
| + case err := <-done: |
| + t.Fatalf("ServeDevbox returned before binding: %v", err) |
| + case <-time.After(10 * time.Second): |
| + t.Fatal("ServeDevbox never bound its listener") |
| + } |
| roots := x509.NewCertPool() |
| roots.AddCert(cert.Leaf) |
| @@ -270,6 +272,32 @@ func TestDevboxServesTheWildcardAndDrains(t *testing.T) { |
| } |
| } |
| +// Devbox certificates come only from CARLOS_WILDCARD_DOMAINS: either |
| +// variable that would add another parent is refused, even alongside it. |
| +func TestDevboxRefusesExtraParents(t *testing.T) { |
| + ca, requests := countingCA(t) |
| + reg := openReg(t) |
| + for _, name := range []string{"PLATFORM_APPS_DOMAIN", "CARLOS_STEERING_ZONE_ID"} { |
| + t.Run(name, func(t *testing.T) { |
| + devboxEnv(t, ca.URL) |
| + t.Setenv(name, "example.org") |
| + cfg := DevboxConfig{Registry: reg, ListenAddr: "127.0.0.1:0", CertDir: t.TempDir(), SpoolRoot: t.TempDir()} |
| + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| + defer cancel() |
| + err := ServeDevbox(ctx, cfg) |
| + if err == nil || ctx.Err() != nil { |
| + t.Fatalf("ServeDevbox with %s set = %v (ctx %v), want an immediate refusal", name, err, ctx.Err()) |
| + } |
| + if !strings.Contains(err.Error(), name) { |
| + t.Fatalf("ServeDevbox with %s set = %v, want the variable named", name, err) |
| + } |
| + }) |
| + } |
| + if n := requests.Load(); n != 0 { |
| + t.Fatalf("the CA saw %d request(s), want 0", n) |
| + } |
| +} |
| + |
| // A bind failure is an error for the caller, never a log.Fatal: a later task |
| // runs ServeDevbox beside another server in one process. |
| func TestDevboxBindFailureIsAnError(t *testing.T) { |