carlos / platform Public

edge: Paul's cut after round 4, the route scan takes only loopback TCP console routes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 8d6e625c6aeeca2753732cf22bd712b7f0479ba0 parent 9ed2267
7 files changed, +67 −115
  • docs/superpowers/specs/2026-11-24-hub-console-address-from-install-design.md +4 −2
  • internal/edge/replicaconsole.go +21 −58
  • internal/edge/replicaconsole_peer_linux.go +0 −26
  • internal/edge/replicaconsole_peer_other.go +0 −9
  • internal/edge/replicaconsole_scan_rootrunner_linux_test.go +6 −6
  • internal/edge/replicaconsole_socket_linux_test.go +0 −14
  • internal/edge/replicaconsole_socket_test.go +36 −0

CI cancelled — superseded by a newer push — run details

CI log
=== gate ===
go: downloading go1.26.10 (linux/arm64)
go version go1.26.10 linux/arm64
opentofu: arm64, tofu 1.13.9, aws 6.73.0, archive 2.8.1
  tofu: downloading https://carlos-ci-mirror-640012953448.s3.eu-west-1.amazonaws.com/opentofu/tofu_1.13.9_linux_arm64.tar.gz
  tofu: downloaded, digest verified
  aws: downloading https://carlos-ci-mirror-640012953448.s3.eu-west-1.amazonaws.com/opentofu/terraform-provider-aws_6.73.0_linux_arm64.zip
  aws: downloaded, digest verified
  archive: downloading https://carlos-ci-mirror-640012953448.s3.eu-west-1.amazonaws.com/opentofu/terraform-provider-archive_2.8.1_linux_arm64.zip
  archive: downloaded, digest verified
  installed in /tmp/carlos-opentofu-vWK9QL
.amadan/test-gate.sh
go: downloading github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.68.0
go: downloading golang.org/x/sys v0.49.0
go: downloading github.com/benbjohnson/litestream v0.5.14
go: downloading github.com/aws/aws-sdk-go-v2/service/costexplorer v1.67.5
go: downloading github.com/aws/aws-sdk-go-v2/service/s3 v1.105.0
go: downloading github.com/superfly/ltx v0.5.1
go: downloading golang.org/x/net v0.62.0
go: downloading modernc.org/sqlite v1.55.0
go: downloading github.com/aws/aws-sdk-go-v2/config v1.32.6
go: downloading golang.org/x/crypto v0.58.0
go: downloading github.com/aws/aws-sdk-go-v2/service/sns v1.43.0
go: downloading github.com/aws/aws-sdk-go-v2/service/acm v1.45.0
go: downloading github.com/aws/aws-sdk-go-v2/service/ec2 v1.324.0
go: downloading github.com/aws/aws-sdk-go-v2/service/iam v1.58.2
go: downloading github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi v1.37.0
go: downloading github.com/aws/aws-sdk-go-v2/service/route53 v1.64.1
go: downloading github.com/pion/turn/v4 v4.1.4
go: downloading github.com/aws/aws-sdk-go-v2/service/sesv2 v1.66.6
go: downloading github.com/aws/aws-sdk-go-v2/service/ssm v1.74.0
go: downloading github.com/klauspost/compress v1.20.2
go: downloading github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.14
go: downloading github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.23
go: downloading github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.31
go: downloading github.com/wlynxg/anet v0.0.5
go: downloading github.com/pierrec/lz4/v4 v4.1.22
go: downloading golang.org/x/text v0.43.0
go: downloading github.com/pion/randutil v0.1.0
go: downloading github.com/prometheus/client_golang v1.17.0
go: downloading github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.20.18
go: downloading github.com/lmittmann/tint v1.1.3
go: downloading github.com/beorn7/perks v1.0.1
go: downloading github.com/cespare/xxhash/v2 v2.3.0
go: downloading github.com/prometheus/common v0.45.0
go: downloading github.com/prometheus/client_model v0.5.0
go: downloading github.com/prometheus/procfs v0.12.0
go: downloading google.golang.org/protobuf v1.36.10
go: downloading github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0
go: downloading golang.org/x/crypto/x509roots/fallback v0.0.0-20260209214922-2f26647a795e
go: downloading github.com/klauspost/compress v1.20.2
go: downloading modernc.org/sqlite v1.55.0
go: downloading github.com/aws/aws-sdk-go-v2/service/ecs v1.91.0
go: downloading github.com/pierrec/lz4/v4 v4.1.22
go: downloading modernc.org/libc v1.74.1
go: downloading modernc.org/libc v1.74.1
go: downloading github.com/dustin/go-humanize v1.0.1
go: downloading modernc.org/mathutil v1.7.1
go: downloading github.com/google/uuid v1.6.0

amadan: job cancelled — a newer push superseded it
diff --git a/docs/superpowers/specs/2026-11-24-hub-console-address-from-install-design.md b/docs/superpowers/specs/2026-11-24-hub-console-address-from-install-design.md
index 7bef95dd5..62a06c772 100644
--- a/docs/superpowers/specs/2026-11-24-hub-console-address-from-install-design.md
+++ b/docs/superpowers/specs/2026-11-24-hub-console-address-from-install-design.md
@@ -198,8 +198,9 @@ The order is **env > socket > the old route scan**:
uid before anything is written, on every call (cut 3, §15). A failed
dial (the console stopping between the check and the dial) is a 502 with
no request written, which the box reads as the console unreachable.
-3. Absent or failing the checks: today's route scan, which on the flagship
- answers 503 as it does now.
+3. Absent or failing the checks: today's route scan, restricted to
+ loopback TCP console routes (never a socket route, §15), which on the
+ flagship answers 503 as it does now.
The checks are one small file read and two `lstat`s per call, and need no
restart or watcher. The edge's sandbox allows it:
@@ -380,3 +381,4 @@ Round 2's P2s are applied in rev 3 (§15).
| Task 3 R2 | P1 systemd re-chowns a directory holding a foreign listener (same family as R1: socket identity) | Stopping rule 2. **Paul chose cut 3, 2026-11-24: check the peer.** One dial function, `dialConsoleFleet` (`internal/edge/replicaconsole.go`), proves with `SO_PEERCRED` that the listener's uid is root's recorded console uid before a byte is written; no connection reuse, so every call is proved; regression test with a foreign listener under a re-chowned directory (`replicaconsole_peer_rootrunner_linux_test.go`) |
| Task 3 R2 | P2-2 symlinked drop-in not repaired; P2-3 inactive-console directory check dropped; P2-4 numeric `User=` | Applied (`readConsoleFleetDropInAt`, `exclusive`, `consoleUnitUID`) |
| Task 3 R3 | P1-1 the kept route scan reaches the fleet socket around the peer check; P1-2 `SO_PEERCRED` is fixed at `listen()`, so a root console cannot be told from a listener that dropped privileges; P1-3 socket tests assume Linux | **Paul approved a fourth round, 2026-11-24, with these three fixes** (no fifth round): the route scan skips a socket route under `/run/carlos-console` and its socket dial refuses a listener bound there by the kernel's name for it (`newRouteScanSocketProxy`); root refuses `exclusive` for a console running as uid 0 (the flagship console runs as `carlos`); success tests Linux-only, refusal checks on other systems |
+| Task 3 R4 | P1 a relative-bound foreign listener reached through a symlink passes the route scan's name check (same family) | **Paul chose cut 1, 2026-11-24, after round 4:** for its last release the route scan accepts only loopback TCP console routes, never a socket route. The leaking path is removed, not fixed, so there is no fifth round |
diff --git a/internal/edge/replicaconsole.go b/internal/edge/replicaconsole.go
index 8d4a5e197..faf3d78d3 100644
--- a/internal/edge/replicaconsole.go
+++ b/internal/edge/replicaconsole.go
@@ -95,40 +95,6 @@ func newReplicaConsoleSocketProxy(socket string) http.Handler {
}, true)
}
-// inConsoleFleetDir reports whether path names consolefleet.Dir or
-// anything in it.
-func inConsoleFleetDir(path string) bool {
- p := filepath.Clean(path)
- return p == consolefleet.Dir || strings.HasPrefix(p, consolefleet.Dir+"/")
-}
-
-// newRouteScanSocketProxy is the route scan's proxy for a console route on
-// a unix socket. Its dial refuses a connection whose listener is bound in
-// consolefleet.Dir, whatever path reached it (a symlink, a hard link): the
-// kernel's name for the listening end (getpeername) is where the listener
-// bound, not the path dialled. So the route scan can never be a way to the
-// console's fleet socket around dialConsoleFleet's peer check. No
-// connection is kept for reuse; box calls are few.
-func newRouteScanSocketProxy(socket string) http.Handler {
- d := &net.Dialer{Timeout: 5 * time.Second}
- return replicaConsoleProxy("console", func(ctx context.Context, _, _ string) (net.Conn, error) {
- c, err := d.DialContext(ctx, "unix", socket)
- if err != nil {
- return nil, err
- }
- bound, err := unixPeerPath(c)
- if err != nil {
- c.Close()
- return nil, fmt.Errorf("route scan socket %s: reading the listener's name: %w", socket, err)
- }
- if inConsoleFleetDir(bound) {
- c.Close()
- return nil, fmt.Errorf("route scan socket %s reaches the console's fleet socket (%s); box calls go there only with the listener's user proved", socket, bound)
- }
- return c, nil
- }, true)
-}
-
// consoleFleetUIDKey carries, in a box call's context, the console user
// root recorded when the edge chose the socket for it.
type consoleFleetUIDKey struct{}
@@ -381,9 +347,9 @@ func (e *Edge) serveReplicaConsole(w http.ResponseWriter, r *http.Request) {
// 3. The route scan (to be deleted the release after the socket ships,
// Paul 2026-11-24): the one route for app console with unit
// console.service and no account (the platform console's shape), on a
-// loopback upstream or a socket, not an alias, regional, via a tunnel
-// or activator-owned, and its proxy (with its version header) is
-// reused.
+// loopback TCP upstream (never a socket route), not an alias,
+// regional, via a tunnel or activator-owned, and its proxy (with its
+// version header) is reused.
func (e *Edge) routeReplicaConsole(w http.ResponseWriter, r *http.Request) string {
if e.replicaConsole != nil {
e.replicaConsole.ServeHTTP(w, e.withForwardKey(r))
@@ -403,33 +369,30 @@ func (e *Edge) routeReplicaConsole(w http.ResponseWriter, r *http.Request) strin
if host != rt.Host || up.alias || up.regional != 0 || up.viaTunnel || rt.Account != "" || rt.App != "console" || rt.Unit != "console.service" || rt.ActivatorOwned() {
continue
}
- proxy := up.proxy
+ // Loopback TCP only, never a socket route (Paul's cut after task 3
+ // review round 4, 2026-11-24): a socket path from a route row can
+ // lead, by a symlink or a relative bind, to the console's fleet
+ // socket, which box calls reach only through dialConsoleFleet's
+ // proof of the listener's user. This scan goes the next release.
if rt.Socket != "" {
- // Never the console's fleet socket, by name or by what the
- // connection reaches (task 3 review R3 P1-1, Paul's round 4): a
- // box call goes there only through dialConsoleFleet's peer check.
- if inConsoleFleetDir(rt.Socket) {
- continue
- }
- proxy = newRouteScanSocketProxy(rt.Socket)
- } else {
- addrs := rt.AddrList()
- if len(addrs) == 0 {
- continue
- }
- local := true
- for _, addr := range addrs {
- local = local && isLocalUpstream(addr)
- }
- if !local {
- continue
- }
+ continue
+ }
+ addrs := rt.AddrList()
+ if len(addrs) == 0 {
+ continue
+ }
+ local := true
+ for _, addr := range addrs {
+ local = local && isLocalUpstream(addr)
+ }
+ if !local {
+ continue
}
if console != nil {
UnavailableHeader(w, "replica-console-ambiguous", 2)
return ReplicaConsoleSourceRouteScan
}
- console = proxy
+ console = up.proxy
}
if console == nil {
UnavailableHeader(w, "replica-console-missing", 2)
diff --git a/internal/edge/replicaconsole_peer_linux.go b/internal/edge/replicaconsole_peer_linux.go
index 971f550a9..05bd73dab 100644
--- a/internal/edge/replicaconsole_peer_linux.go
+++ b/internal/edge/replicaconsole_peer_linux.go
@@ -31,29 +31,3 @@ func unixPeerUID(c net.Conn) (int, error) {
}
return int(cred.Uid), nil
}
-
-// unixPeerPath is the name the listening end of a unix stream connection
-// bound to (getpeername), whatever path was dialled to reach it.
-func unixPeerPath(c net.Conn) (string, error) {
- uc, ok := c.(*net.UnixConn)
- if !ok {
- return "", errors.New("not a unix connection")
- }
- raw, err := uc.SyscallConn()
- if err != nil {
- return "", err
- }
- var sa unix.Sockaddr
- var saErr error
- if err := raw.Control(func(fd uintptr) { sa, saErr = unix.Getpeername(int(fd)) }); err != nil {
- return "", err
- }
- if saErr != nil {
- return "", saErr
- }
- u, ok := sa.(*unix.SockaddrUnix)
- if !ok {
- return "", errors.New("peer is not a unix address")
- }
- return u.Name, nil
-}
diff --git a/internal/edge/replicaconsole_peer_other.go b/internal/edge/replicaconsole_peer_other.go
index 12090e47a..978417537 100644
--- a/internal/edge/replicaconsole_peer_other.go
+++ b/internal/edge/replicaconsole_peer_other.go
@@ -12,12 +12,3 @@ import (
func unixPeerUID(net.Conn) (int, error) {
return 0, errors.New("listener credentials are not available on this platform")
}
-
-// unixPeerPath: the listener's own name, as the platform reports it.
-func unixPeerPath(c net.Conn) (string, error) {
- a := c.RemoteAddr()
- if a == nil {
- return "", errors.New("no peer address")
- }
- return a.String(), nil
-}
diff --git a/internal/edge/replicaconsole_scan_rootrunner_linux_test.go b/internal/edge/replicaconsole_scan_rootrunner_linux_test.go
index 16b8a29be..ea9088e92 100644
--- a/internal/edge/replicaconsole_scan_rootrunner_linux_test.go
+++ b/internal/edge/replicaconsole_scan_rootrunner_linux_test.go
@@ -16,12 +16,12 @@ import (
"github.com/carlosframework/platform/internal/registry"
)
-// TestRouteScanNeverReachesTheFleetSocket is task 3 review R3 P1-1: with
-// the socket not trusted (here root's record is not exclusive), an
-// accountless console route naming the fleet socket, directly or through
-// a symlink, must not reach it: the route scan skips the first and its
-// dial refuses the second by the listener's own name. Root only: it binds
-// in /run/carlos-console.
+// TestRouteScanNeverReachesTheFleetSocket is task 3 review R3 P1-1 and R4
+// P1: with the socket not trusted (here root's record is not exclusive),
+// an accountless console route naming the fleet socket, directly or
+// through a symlink, must not reach it. Paul's cut after round 4: the
+// route scan takes no socket route at all. Root only: it binds in
+// /run/carlos-console.
func TestRouteScanNeverReachesTheFleetSocket(t *testing.T) {
if os.Geteuid() != 0 {
t.Skip("needs root")
diff --git a/internal/edge/replicaconsole_socket_linux_test.go b/internal/edge/replicaconsole_socket_linux_test.go
index a3c1ddc55..e6e7da37c 100644
--- a/internal/edge/replicaconsole_socket_linux_test.go
+++ b/internal/edge/replicaconsole_socket_linux_test.go
@@ -151,17 +151,3 @@ func TestDialConsoleFleetRefusesAForeignListener(t *testing.T) {
}
c.Close()
}
-
-func TestInConsoleFleetDir(t *testing.T) {
- for path, want := range map[string]bool{
- "/run/carlos-console": true,
- "/run/carlos-console/fleet.sock": true,
- "/run/carlos-console/../carlos-console/x": true,
- "/run/carlos-consolex/fleet.sock": false,
- "/run/carlos/apps/console.test.sock": false,
- } {
- if got := inConsoleFleetDir(path); got != want {
- t.Errorf("%s: %v", path, got)
- }
- }
-}
diff --git a/internal/edge/replicaconsole_socket_test.go b/internal/edge/replicaconsole_socket_test.go
index 7d53f8c5f..165ae9c50 100644
--- a/internal/edge/replicaconsole_socket_test.go
+++ b/internal/edge/replicaconsole_socket_test.go
@@ -269,3 +269,39 @@ func newBoxCallRequest() *http.Request {
req.Header.Set("Authorization", "Bearer fleet-token")
return req
}
+
+// TestRouteScanTakesNoSocketRoute: the route scan's last release accepts
+// only loopback TCP console routes (Paul's cut after task 3 review round
+// 4, 2026-11-24): an accountless console.service route on a socket answers
+// replica-console-missing and its listener gets nothing.
+func TestRouteScanTakesNoSocketRoute(t *testing.T) {
+ dir, err := os.MkdirTemp("", "cfs")
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { os.RemoveAll(dir) })
+ sock := filepath.Join(dir, "console.sock")
+ ln, err := net.Listen("unix", sock)
+ if err != nil {
+ t.Fatal(err)
+ }
+ var hits atomic.Int32
+ srv := &http.Server{Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { hits.Add(1) })}
+ go func() { _ = srv.Serve(ln) }()
+ t.Cleanup(func() { _ = srv.Close() })
+ reg := openReg(t)
+ if err := reg.Upsert(registry.Route{Host: "console.test", App: "console", Unit: "console.service", Kind: "instance", Socket: sock, Status: "ready"}); err != nil {
+ t.Fatal(err)
+ }
+ e, err := New(reg, nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(e.probers.Stop)
+ e.withConsoleFleet(consoleFleetSource{record: func() (consolefleet.Record, error) { return consolefleet.Record{}, os.ErrNotExist }})
+ e.EnableTunnels(NewTunnelHub("tunnel.test", nil))
+ w := postBoxCall(t, e)
+ if w.Code != http.StatusServiceUnavailable || hits.Load() != 0 {
+ t.Fatalf("%d, socket route hits %d", w.Code, hits.Load())
+ }
+}