oficina / equipo Public

Sign-in: setup-token's home and /tmp in memory only

Astra round 2: the setup-token launch bound /home/runner and /tmp to
host scratch, so what the CLI writes during the exchange reached a disk
until cleanup. For the sign-in launch only, both are now bubblewrap
tmpfs (64 MiB each), gone with the namespace; other launches are
unchanged. The runner still takes the token only from the CLI's output.

The fake writes each code (and the token) into its home and /tmp; the
end-to-end test scans the runner's scratch, state, homes and config
while the CLI waits and after: red first, green now; binding to
scratch again turns it and the containment test red.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev edffce04f80903fa557235d6cadec9ffa73260e9 parent 178d564
6 files changed, +87 −15
  • docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md +16 −0
  • docs/superpowers/specs/2026-11-08-equipo-connections.md +8 −6
  • internal/fakeclaude/setuptoken.go +14 −2
  • internal/headless/signin_contained_test.go +10 −2
  • internal/headless/signin_test.go +23 −0
  • internal/runner/containment/mounts.go +16 −5

CI passed — run details

diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md
index 415f71f8..69c47ab8 100644
--- a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md
+++ b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md
@@ -6530,6 +6530,22 @@ and the connection browser tests (`-tags browser`).
| 2 descendants | `TestHeadlessClaudeSignIn` (the CLI leaves a child ignoring SIGHUP and exits; none survives before the new link), `TestHeadlessSignInContained` | start the CLI outside a namespace, killing its group only while it runs (the reviewed code) | red: 1 child outlived it |
| 3 crash recovery | `TestHeadlessSignInRunnerKilled` (SIGKILL to a runner process while setup-token waits; restart: runner_offline, home, record, scratch and every process of the namespace gone); `TestSignInRecoveryProvesNamespaceGone` | no recovery of a killed runner's namespaces; skip the proof before the home goes | red: record stayed; red: home removed unproven |
+### Review round 2 (Astra, approve after one fix)
+
+The setup-token launch's home and /tmp were binds to host scratch, so
+what the CLI writes during the exchange reached a disk until cleanup.
+For the sign-in only (other launches unchanged) both are now
+bubblewrap `--tmpfs` (`--size` 64 MiB, `--perms` 0700 and 1777): the
+namespace's memory. The fake now writes every code it is given, and the
+token after a right one, into `$HOME/.claude.json` and
+`$TMPDIR/claude-exchange.log`. `TestHeadlessClaudeSignIn` scans the
+runner's scratch root, state dir, homes and config while the CLI still
+waits after a wrong code, and again after healthy (the token file the
+one exception): red first (the code in
+`scratch/attempt-*/home/.claude.json`), green after.
+`TestHeadlessSignInContained` checks the probe's writes reach no host
+path. Mutation: bind both to scratch again: both red.
+
### To confirm on the first live use
What CLI 2.1.312 prints after a right code (the runner takes the first
diff --git a/docs/superpowers/specs/2026-11-08-equipo-connections.md b/docs/superpowers/specs/2026-11-08-equipo-connections.md
index fcfa5621..eda0f9ab 100644
--- a/docs/superpowers/specs/2026-11-08-equipo-connections.md
+++ b/docs/superpowers/specs/2026-11-08-equipo-connections.md
@@ -589,10 +589,12 @@ ignores it. A token row's Sign in again and the renewal line start
this sign-in, the paste offered second. The runner runs the unmodified
`claude setup-token` itself, on a pseudo-terminal, contained like every
provider launch (the `signin-v1` policy, `provider.BuildSignInPolicy`):
-its own bubblewrap namespace, recorded before anything forks, with the
-launch's scratch home its only writable home (the connection's
-dedicated home and the runner's state are not mounted; the runner
-writes the token into the home itself), no workspace or tool socket,
+its own bubblewrap namespace, recorded before anything forks, whose
+only writable places, its home and /tmp, are the namespace's own memory
+(tmpfs capped at 64 MiB each, gone with it; nothing the CLI writes
+during the exchange reaches a disk), the connection's dedicated home
+and the runner's state not mounted (the runner writes the token into
+the home itself, from the CLI's output), no workspace or tool socket,
`BROWSER` a program that opens nothing, and egress through the relay to
`platform.claude.com` and `api.anthropic.com` only. Those hosts were
read from the pinned CLI 2.1.312 statically: its production OAuth
@@ -634,8 +636,8 @@ static read says "OAuth error: ..." then Enter to retry, the same link
for a code it cannot read and a new sign-in for one the exchange
refuses, and the runner presses Enter once), that a typed code followed
by a separate carriage return is taken as entered, that the CLI honours
-the relay's proxy for the exchange, and what it writes into its scratch
-home (gone with the namespace either way).
+the relay's proxy for the exchange, and that what it writes fits the
+in-memory home.
**Sealing.** The app seals with libsodium `crypto_box_seal` over a
payload `{secret, runner_id, connection_id, provider, endpoint,
diff --git a/internal/fakeclaude/setuptoken.go b/internal/fakeclaude/setuptoken.go
index 8820b208..391782da 100644
--- a/internal/fakeclaude/setuptoken.go
+++ b/internal/fakeclaude/setuptoken.go
@@ -37,7 +37,10 @@ import (
// printed: a code from another run's link is wrong. The token it prints
// is Token(email). It refuses to run off a terminal (as Ink does), with
// a BROWSER that is not a no-op (it would open one), or with anything
-// in argv but setup-token. A code starting "orphan" makes it start a child that
+// in argv but setup-token. Every code it is given (and, after a right
+// one, the token) it writes into $HOME/.claude.json and
+// $TMPDIR/claude-exchange.log, as a CLI may during the exchange. A code
+// starting "orphan" makes it start a child that
// ignores a hangup and exit, leaving the child.
//
// Steering, from SetupSteerFile beside the binary (absent inside a
@@ -179,7 +182,16 @@ func setupToken(args []string, stdin io.Reader, stdout io.Writer) int {
}
mid, got, ok := strings.Cut(code, "#")
email, err := hex.DecodeString(strings.TrimPrefix(mid, "fakecode-"))
- if ok && got == state && strings.HasPrefix(mid, "fakecode-") && err == nil {
+ right := ok && got == state && strings.HasPrefix(mid, "fakecode-") && err == nil
+ // What a CLI may write during the exchange, the code and (once
+ // it has one) the token in it: its config and a scratch file.
+ kept := code
+ if right {
+ kept += "\n" + Token(string(email))
+ }
+ _ = os.WriteFile(filepath.Join(home(), ".claude.json"), []byte(kept), 0600)
+ _ = os.WriteFile(filepath.Join(os.TempDir(), "claude-exchange.log"), []byte(kept), 0600)
+ if right {
out("\r\n\x1b[32m✓\x1b[39m Long-lived authentication token created successfully!\r\n\r\nYour OAuth token (valid for 1 year):\r\n\r\n\x1b[33m" + Token(string(email)) + "\x1b[39m\r\n\r\nStore this token securely. You won't be able to see it again.\r\n\r\nUse this token by setting: export CLAUDE_CODE_OAUTH_TOKEN=<token>\r\n")
return 0
}
diff --git a/internal/headless/signin_contained_test.go b/internal/headless/signin_contained_test.go
index 1535c058..52d9c3f4 100644
--- a/internal/headless/signin_contained_test.go
+++ b/internal/headless/signin_contained_test.go
@@ -19,8 +19,9 @@ import (
// The sign-in's `claude setup-token` (the fake) in the real namespace,
// as the runner starts it (provider.BuildSignInPolicy, StartTerminal):
// on a terminal; another account's home and the runner's state are not
-// there to read; it writes to disk only in its own scratch home and
-// /tmp, not to the workspace, /etc or /usr; a CONNECT to a host off its list
+// there to read; it writes only to its home and /tmp, both its own
+// memory (nothing reaches the host), not to the workspace, /etc or
+// /usr; a CONNECT to a host off its list
// is refused by the egress proxy and counted. A child the CLI starts
// that ignores a hangup dies with the namespace when the CLI exits, and
// the namespace's scratch, where a code typed in could have been
@@ -111,6 +112,13 @@ func TestHeadlessSignInContained(t *testing.T) {
t.Errorf("write to %s is not %s", path, word)
}
}
+ // Those writes are the namespace's memory: nothing on the host.
+ _ = filepath.WalkDir(scratch, func(path string, d os.DirEntry, err error) error {
+ if err == nil && d.Name() == "w" {
+ t.Errorf("a write in the namespace reached the host: %s", path)
+ }
+ return nil
+ })
if !strings.Contains(screen, "probe connect example.net HTTP/1.1_403_Forbidden") {
t.Errorf("a host off the list was not refused: %q", screen)
}
diff --git a/internal/headless/signin_test.go b/internal/headless/signin_test.go
index d34a9abe..4c0deb77 100644
--- a/internal/headless/signin_test.go
+++ b/internal/headless/signin_test.go
@@ -116,6 +116,9 @@ func TestHeadlessClaudeSignIn(t *testing.T) {
v := cv.Connections[c.ID].Prompt
return v != nil && v.Attempt == 3 && v.WrongCode && v.URL != ""
})
+ // The CLI wrote the wrong code into its home and /tmp and is still
+ // waiting: both are its namespace's memory, nothing on the host.
+ onHost(t, r, wrong, "the code the CLI wrote")
p = *latest(s, c.ID)
u, _ = url.Parse(p.URL)
code := fakeclaude.SetupCode(email, u.Query().Get("state"))
@@ -134,6 +137,8 @@ func TestHeadlessClaudeSignIn(t *testing.T) {
err := inst.DB.Writer().QueryRow("SELECT count(*) FROM chat_usage WHERE role = 'check' AND connection = ? AND outcome = ?", got.LocalID, wire.OutcomeReplied).Scan(&n)
return err == nil && n == 1
})
+ onHost(t, r, code, "the code the CLI wrote")
+ onHost(t, r, fakeclaude.Token(email), "the token the CLI wrote")
home := filepath.Join(r.root, "accounts", got.LocalID)
token := fakeclaude.Token(email)
tokenFile := filepath.Join(home, provider.TokenFile)
@@ -295,3 +300,21 @@ func TestHeadlessSignInRunnerKilled(t *testing.T) {
t.Fatal("a child of the CLI survived")
}
}
+
+// onHost fails if secret is in any file in the runner's scratch, state,
+// homes or config, but the connection's token file (which is the token's
+// only place, written by the runner from the CLI's output).
+func onHost(t *testing.T, r *localRunner, secret, what string) {
+ t.Helper()
+ for _, dir := range []string{r.cfg.ScratchRoot, r.cfg.StateDir, filepath.Join(r.root, "accounts"), filepath.Dir(r.cfg.AccountBindingsPath)} {
+ _ = filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error {
+ if err != nil || !d.Type().IsRegular() || d.Name() == provider.TokenFile {
+ return nil
+ }
+ if raw, _ := os.ReadFile(path); bytes.Contains(raw, []byte(secret)) {
+ t.Fatalf("%s is on the host: %s", what, path)
+ }
+ return nil
+ })
+ }
+}
diff --git a/internal/runner/containment/mounts.go b/internal/runner/containment/mounts.go
index c846be3d..d10ba9cd 100644
--- a/internal/runner/containment/mounts.go
+++ b/internal/runner/containment/mounts.go
@@ -132,6 +132,10 @@ func (p *mounts) bind(source, target string, ro, tree bool) error {
p.files = append(p.files, f)
return nil
}
+
+// signInTmpfs caps each of a sign-in's in-memory home and /tmp.
+const signInTmpfs = 64 << 20
+
func (m *Manager) mountPlan(l provider.Launch, dir string) (_ *mounts, err error) {
p := &mounts{}
defer func() {
@@ -186,11 +190,18 @@ func (m *Manager) mountPlan(l provider.Launch, dir string) (_ *mounts, err error
return nil, errMount
}
}
- if err = p.bind(runtimeHome, "/home/runner", false, true); err != nil {
- return nil, err
- }
- if err = p.bind(filepath.Join(dir, "tmp"), "/tmp", false, true); err != nil {
- return nil, err
+ if signIn {
+ // A sign-in writes nothing to disk: its home and /tmp are the
+ // namespace's own memory, capped, gone with it. The runner takes
+ // the token from the CLI's output, never from a file here.
+ p.args = append(p.args, "--size", strconv.Itoa(signInTmpfs), "--perms", "0700", "--tmpfs", "/home/runner", "--size", strconv.Itoa(signInTmpfs), "--perms", "1777", "--tmpfs", "/tmp")
+ } else {
+ if err = p.bind(runtimeHome, "/home/runner", false, true); err != nil {
+ return nil, err
+ }
+ if err = p.bind(filepath.Join(dir, "tmp"), "/tmp", false, true); err != nil {
+ return nil, err
+ }
}
if err = p.bind(m.cfg.RunnerBinary, "/equipo-namespace", true, false); err != nil {
return nil, err