carlos / platform Public

Devbox identity and private targets (#486 A): plan

Six tasks: copy deck, identity adapter, front-door middleware, registrar
socket targets and allow lists, CLI and serve wiring, census.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev af57ab9653a7930720f77cff1ac01014db39861e parent 9f46fee
1 file changed, +158 −0
  • docs/superpowers/plans/2026-11-01-devbox-identity.md +158 −0

CI passed — run details

diff --git a/docs/superpowers/plans/2026-11-01-devbox-identity.md b/docs/superpowers/plans/2026-11-01-devbox-identity.md
new file mode 100644
index 000000000..aec0fc760
--- /dev/null
+++ b/docs/superpowers/plans/2026-11-01-devbox-identity.md
@@ -0,0 +1,158 @@
+# Devbox Identity and Private Targets (#486 A) Implementation Plan
+
+> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
+
+**Goal:** Devbox links tell the upstream who is looking: Tailscale login, personal devices only. A link can point at a private Unix socket, and `--allow` makes a link answer only named logins.
+
+**Architecture:** `edge.ServeDevbox` wraps the edge handler in a front-door middleware. The middleware:
+
+1. strips `Carlos-Visitor-*` headers;
+2. asks a `VisitorIdentity` adapter about the remote address;
+3. drops identity for shared machines;
+4. enforces the link's allow list, fetched through a lookup the registrar hands it in-process;
+5. sets the headers.
+
+The registrar gains socket targets, checked against the caller's uid in a sticky sockets directory the service creates, and per-link allow lists. The CLI makes the socket private and grants the service user access with a POSIX ACL.
+
+**Tech Stack:** Go, `golang.org/x/sys/unix`, plain HTTP over Unix sockets. No new modules.
+
+**Spec:** `docs/superpowers/specs/2026-11-01-devbox-identity-design.md`, approved by Paul 2026-11-01.
+
+## Global Constraints
+
+- Header names are exactly `Carlos-Visitor-Login`, `Carlos-Visitor-Name` and `Carlos-Visitor-Node`. The edge deletes them from every incoming request, whatever the case and whatever the link kind, WebSocket upgrades included.
+- Identity is never inferred. If the lookup fails, the visitor is anonymous. A request from the devbox's own listen IP, or from a node named in `CARLOS_DEVBOX_SHARED_NODES` (a comma list of node names), is anonymous too. An allow-listed link refuses anonymous visitors.
+- Whois cache: 60 s for an answer, 5 s for a failure. Lookups go over tailscaled's LocalAPI at `/var/run/tailscale/tailscaled.sock`, as plain HTTP over the Unix socket.
+- Allow matching is exact and case-insensitive on Login, with no globs. A refusal is HTTP 403 with the approved private-link page. It never echoes the list or the owner.
+- Sockets live directly in `/run/carlos-devbox/sockets/`, created by `serve` at start with mode 1733. The socket file is mode 0600 with an ACL entry for the service user: rw for the service uid only. The registrar requires the owner uid to equal the caller uid, a socket type, no symlink, and a successful connect.
+- Linux only for `--socket` and identity. On darwin, `--socket` is refused with deck copy and identity is off. Darwin must still build.
+- User-facing strings come only from approved copy deck rows: DBX-C94 onwards, appended to `docs/superpowers/plans/2026-10-30-devbox-mode-copy.md`. No em dashes.
+- **Verification budget** (Paul, 2026-10-31):
+ - mutation checks only on refusal and security paths, at most about 10 per task, each with targeted `-run`;
+ - run tests once with `-count=1`, plus one `-race`;
+ - locally, run only the touched packages; CI runs the full suite;
+ - smoke-test on docs-t1 as soon as a link works end to end.
+- Commit subjects under 80 characters; body after a blank line.
+
+## Review Focus
+
+1. **Spoofing:** a visitor sends `carlos-visitor-login: paulca@github`, in mixed case. The upstream never sees it. Test in Task 3.
+2. **A request from the devbox itself:** no identity, so an allow-listed link refuses it, even when the box owner's login is on the list. Test in Task 3.
+3. **tailscaled down or slow:** an allow-listed link answers 403 within the request deadline, and an open link serves anonymously. Test in Task 2 (adapter timeout) and Task 3 (refusal).
+4. **A socket owned by someone else, a symlink to one, or a path outside the sockets directory:** refused before anything is written. Test in Task 4.
+5. **Re-share changes the allow list** (a list to none, or none to a list): the edge applies the change on the next request, with no restart. Test in Task 3 and Task 4.
+
+---
+
+### Task 1: Copy deck (controller and Paul)
+
+Draft rows DBX-C94 onwards for:
+
+- the `--socket` help and the `--allow` help;
+- the refusals:
+ - socket outside the sockets directory;
+ - not a socket;
+ - not yours;
+ - the service can't connect;
+ - the ACL couldn't be set;
+ - `--socket` on macOS;
+ - a malformed login in `--allow`;
+- the 403 private-link page (title and one sentence);
+- `list` states: "private" and "tailnet";
+- the runbook: the sockets directory, and the identity rule for shared machines (`CARLOS_DEVBOX_SHARED_NODES`).
+
+Run copy review with Paul, apply his text verbatim, and bump the gate's inventory.
+
+### Task 2: The identity adapter
+
+**Files:**
+- Create `internal/edge/visitor.go`: the interface, the cache, and the shared-node rule helper.
+- Create `internal/tsidentity/whois.go`: the Tailscale adapter.
+- Tests: `internal/edge/visitor_test.go`, `internal/tsidentity/whois_test.go`.
+
+**Interfaces (produces):**
+
+```go
+// internal/edge
+type Visitor struct{ Login, Name, Node string }
+type VisitorIdentity interface {
+ Who(ctx context.Context, remote netip.AddrPort) (Visitor, bool, error)
+}
+func NewCachedIdentity(inner VisitorIdentity, now func() time.Time) VisitorIdentity // 60 s hit, 5 s miss
+// internal/tsidentity
+func New(socketPath string, timeout time.Duration) edge.VisitorIdentity // GET /localapi/v0/whois?addr=<ip:port>
+```
+
+The Tailscale adapter treats a tagged node, or an empty `UserProfile.LoginName`, as ok=false. Its timeout is 2 s (my call).
+
+- [ ] **Tests:**
+ - `TestWhoisParsesLoginNameNode`: a fake LocalAPI on a temp Unix socket returns the whois JSON, and the adapter maps `UserProfile.LoginName`, `UserProfile.DisplayName` and `Node.ComputedName`.
+ - `TestWhoisTaggedNodeIsAnonymous`.
+ - `TestWhoisTimeout`: a fake that never answers gives an error in about 2 s.
+ - `TestCachedIdentityTTLs`: a hit is reused for up to 60 s and refetched after. A miss is reused for up to 5 s.
+- [ ] **Implement, run, commit.** Before wiring it in, the builder checks once on docs-t1 that the `carlos-devbox` user can call whois. Run `sudo -u carlos-devbox` only if Paul agrees, or else as an unprivileged non-operator account. Record the result in the report. If whois is refused, STOP and report; the spec says the fallback must not need root.
+
+### Task 3: The front-door middleware
+
+**Files:**
+- Modify `internal/edge/devbox.go`: `DevboxConfig` gains `Identity VisitorIdentity`, `SharedNodes []string` and `AllowFor func(host string) []string`, and `srv.Handler` becomes `devboxFront(e, cfg)`.
+- Create `internal/edge/devboxfront.go`.
+- Test: `internal/edge/devboxfront_test.go`.
+
+**Interfaces:** `func devboxFront(next http.Handler, cfg DevboxConfig, selfIP netip.Addr) http.Handler`. `selfIP` comes from `ListenAddr`.
+
+- [ ] **Tests:**
+ - `TestFrontStripsVisitorHeaders`: Review Focus 1, with mixed case, and on an upgrade request too.
+ - `TestFrontSetsIdentity`.
+ - `TestFrontSelfIPIsAnonymous`: Review Focus 2.
+ - `TestFrontSharedNodeIsAnonymous`.
+ - `TestFrontAllowRefusesOthers`: the 403 body is the deck page and doesn't contain the allowed login.
+ - `TestFrontAllowRefusesAnonymous`: Review Focus 3, with an adapter error.
+ - `TestFrontOpenLinkServesAnonymous`.
+ - `TestFrontAllowListChangeTakesEffect`: Review Focus 5, a changed `AllowFor` result applies on the next request.
+- [ ] **Implement, run** `go test ./internal/edge -run 'TestFront|TestDevbox' -count=1`, **then commit.**
+
+### Task 4: Registrar: socket targets and allow lists
+
+**Files:**
+- Modify `internal/devbox/links.go`: `Link` gains `Socket string` (`json:"socket,omitempty"`) and `Allow []string` (`json:"allow,omitempty"`); `Kind` gains `"socket"`.
+- Modify `internal/devbox/registrar.go`: `POST /share/socket {name, path, allow}`; `allow` on `/share/live` and `/share/folder`; `func (r *Registrar) AllowFor(host string) []string`; `list` carries `private bool`.
+- Create `internal/devbox/socketcheck_linux.go` and `socketcheck_other.go`.
+- Test: `internal/devbox/registrar_socket_test.go`.
+
+The registry row for a socket link is `{Host, Kind: "service", Socket: path, App: name, Status: "ready"}`, written with `UpsertUnlessRootfs`. The checks run on an `O_PATH|O_NOFOLLOW` fd plus `fstat`: the parent is exactly `SocketsDir`, the file is a socket, and the owner uid equals the caller. A connect test with a 300 ms timeout comes last. New codes: `socket-path`, `not-a-socket`, `socket-not-yours`, `socket-unreachable` and `bad-allow`.
+
+- [ ] **Tests:**
+ - `TestShareSocketWritesSocketRoute`.
+ - `TestShareSocketRefusesOtherOwner`, `TestShareSocketRefusesSymlink` and `TestShareSocketRefusesOutsideDir`: Review Focus 4. Fake the owner uid through a seam where the test can't chown.
+ - `TestShareSocketUnreachable`.
+ - `TestAllowForReturnsList`; `TestReshareReplacesAllow`, for Review Focus 5.
+ - `TestBadAllowLogin`: an empty entry, whitespace, or more than 254 characters.
+ - `TestListMarksPrivate`.
+- [ ] **Implement, run** `TMPDIR=/tmp/g go test ./internal/devbox -count=1`, **then commit.**
+
+### Task 5: CLI, serve wiring, runbook
+
+**Files:**
+- Modify `devbox_cli.go`:
+ - `share` gains `--socket PATH` and `--allow LIST`;
+ - `list` gains the private/tailnet state;
+ - `serve` creates `SocketsDir` at mode 1733, builds `tsidentity.New` behind `NewCachedIdentity` and reads `CARLOS_DEVBOX_SHARED_NODES`, and passes `Identity`, `SharedNodes` and `AllowFor` into `DevboxConfig`.
+- Create `devbox_acl_linux.go`, `devbox_acl_other.go`, and the test `devbox_acl_linux_test.go`. `func grantServiceACL(path string, serviceUID uint32) error` sets mode 0600 and writes `system.posix_acl_access` (owner rw, named user serviceUID rw, mask rw, group none, other none) with `unix.Setxattr`. The service uid comes from looking up the user `carlos-devbox` (`CARLOS_DEVBOX_SERVICE_USER` overrides).
+- Modify `infra/devbox/README.md` with the deck's runbook rows.
+
+- [ ] **Tests:**
+ - `TestGrantServiceACLEncodes`: the xattr bytes round-trip through a decoder.
+ - `TestDevboxShareSocketCLI`: against the in-process registrar.
+ - `TestDevboxShareAllowFlag`.
+ - `TestDevboxSocketRefusedOnDarwin`: a GOOS seam.
+- [ ] **Implement, run** `TMPDIR=/tmp/g go test -run TestDevbox . -count=1` and the copy gate, **then commit.**
+- [ ] **Smoke on docs-t1** after a release, or with a dev build that Paul installs:
+ - a socket link served through the edge;
+ - another account can't connect to the socket;
+ - `--allow paulca@github` serves Paul's MacBook and refuses from docs-t1 itself;
+ - stopping tailscaled makes allow-listed links refuse.
+
+### Task 6: Census and docs
+
+Run `make census-card` and `make census-propose NAME=devbox-identity`, plus the 9B8 overlay if sites are rejected. The `carlos:devbox` skill update (`--socket`, `--allow`, identity headers) goes to the skills repo as a follow-up PR.