Token paste end to end; the enrolled person can add a first connection
The runner refused a connect for a person with no binding yet, so the first connection could never be added from the app; the person the runner is enrolled for is now always one of its owners. A headless test pastes a token through the API, sealed to the published key, and checks the turn, the expiry, the sign-out and that the token is nowhere on the instance. The spec records the token's residual risk and live checks.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 files changed,
+113
−2
docs/superpowers/specs/2026-11-08-equipo-connections.md+17 −0internal/headless/token_test.go+85 −0internal/runner/thin/movein.go+9 −0internal/runner/thin/run.go+2 −2
CI failed — run details
diff --git a/docs/superpowers/specs/2026-11-08-equipo-connections.md b/docs/superpowers/specs/2026-11-08-equipo-connections.md| index 2fda02ce..c2dfda29 100644 |
| --- a/docs/superpowers/specs/2026-11-08-equipo-connections.md |
| +++ b/docs/superpowers/specs/2026-11-08-equipo-connections.md |
| @@ -530,6 +530,23 @@ and the apps check both its fingerprint against the one approved at |
| enrolment and the seal key against its birational map, refusing on a |
| mismatch. |
| +**A pasted Claude token on the runner, as built.** The token lives only |
| +in `.oauth-token` (0600) in the connection's own home, outside every |
| +model-readable path, and reaches each Claude launch as |
| +`CLAUDE_CODE_OAUTH_TOKEN` through bubblewrap's `--args` pipe, never in |
| +argv; the CLI runs with `CLAUDE_CODE_SUBPROCESS_ENV_SCRUB=1` so the |
| +model's Bash does not inherit it. Residual risk, accepted and labelled: |
| +inside the namespace the model's tools run as the same user as the CLI, |
| +so a tool could read `/proc/<claude pid>/environ`; neither a `hidepid` |
| +proc mount (same user) nor making the unmodified CLI undumpable closes |
| +that. The containment's egress reaches only the provider's hosts, so the |
| +token can go nowhere but where it already works, and a leaked token is |
| +revoked by running `claude setup-token` again and signing the old |
| +connection out. To check on the first live paste: `claude auth status |
| +--json` reports `loggedIn: true` with only the variable set; the CLI |
| +writes no `.credentials.json` into the home; and the variable is absent |
| +from the model's Bash environment. |
| + |
| **Sealing.** The app seals with libsodium `crypto_box_seal` over a |
| payload `{secret, runner_id, connection_id, provider, endpoint, |
| attempt, expires_at}`, where `endpoint` is the full origin, scheme, |
diff --git a/internal/headless/token_test.go b/internal/headless/token_test.go| index 3f3f0cde..ee4642b3 100644 |
| --- a/internal/headless/token_test.go |
| +++ b/internal/headless/token_test.go |
| @@ -128,3 +128,88 @@ func TestHeadlessTokenConnection(t *testing.T) { |
| t.Fatal("the token is on the task page") |
| } |
| } |
| + |
| +// T2, end to end: the person adds Claude by token through the API as the |
| +// page does. The box is sealed to the seal key the instance publishes for |
| +// the runner, the runner opens it, the CLI's status probe passes, the row |
| +// is healthy with the token's expiry, and the next turn runs on it with |
| +// the token in CLAUDE_CODE_OAUTH_TOKEN. The token is nowhere on the |
| +// instance: its database file and WAL, its logs, its API and pages. |
| +func TestHeadlessTokenPasteEndToEnd(t *testing.T) { |
| + env, inst, r := localEnv(t) |
| + _, key, _ := ed25519.GenerateKey(rand.Reader) |
| + if err := runnerproto.JournalCredentials(filepath.Join(r.cfg.StateDir, "machine-key.json"), base64.RawURLEncoding.EncodeToString(key)); err != nil { |
| + t.Fatal(err) |
| + } |
| + r.only(t) |
| + r.start(t) |
| + s := open(t, env) |
| + s.keep() |
| + c, err := env.Client.Connect(s.ctx, wire.Connect{Provider: wire.ProviderClaude, Kind: wire.KindToken}) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + s.wait(t, "token card", time.Minute, func(cv *thintest.Conversation) bool { |
| + v := cv.Connections[c.ID] |
| + return v.Prompt != nil && v.Prompt.Kind == wire.PromptToken |
| + }) |
| + snap, err := env.Client.Snapshot(s.ctx) |
| + if err != nil || snap.Runner.SealKey == "" { |
| + t.Fatalf("no seal key published: %v", err) |
| + } |
| + token := fakeclaude.Token("paste@example.com") |
| + sealed, err := sealbox.Seal(snap.Runner.SealKey, wire.SealedPayload{Secret: token, RunnerID: snap.Runner.ID, ConnectionID: c.ID, Provider: wire.ProviderClaude, Endpoint: wire.EndpointAnthropic, Attempt: 1, ExpiresAt: time.Now().Add(wire.SealedTTL).UTC().Truncate(time.Second)}) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err = env.Client.Secret(s.ctx, c.ID, sealed); err != nil { |
| + v, _ := env.Client.Connection(s.ctx, c.ID) |
| + t.Fatalf("%v: connection %+v", err, v) |
| + } |
| + var got wire.Connection |
| + s.wait(t, "token healthy", time.Minute, func(cv *thintest.Conversation) bool { |
| + got = cv.Connections[c.ID] |
| + return got.State == wire.ConnHealthy |
| + }) |
| + if got.ExpiresAt == nil || time.Until(*got.ExpiresAt) < 360*24*time.Hour || got.LocalID == "" { |
| + t.Fatalf("healthy token connection %+v", got) |
| + } |
| + // The same box again is refused by the instance or answered with |
| + // nothing by the runner: the connection stays as it is. |
| + _, _ = env.Client.Secret(s.ctx, c.ID, sealed) |
| + sent := s.send(t, "Hello on the pasted token.") |
| + m := replyOf(t, s, sent.Turn.ID) |
| + if !strings.Contains(m.Text, "(signed in by token)") || s.conv.Turns[sent.Turn.ID].Connection != got.LocalID { |
| + t.Fatalf("turn on the pasted token: %q", m.Text) |
| + } |
| + // Nothing on the instance holds the token: the database file and its |
| + // WAL as bytes, the logs, the API and the page. |
| + for _, f := range []string{inst.Path, inst.Path + "-wal"} { |
| + raw, err := os.ReadFile(f) |
| + if err != nil && !os.IsNotExist(err) { |
| + t.Fatal(err) |
| + } |
| + if strings.Contains(string(raw), token) { |
| + t.Fatalf("the token is in %s", filepath.Base(f)) |
| + } |
| + } |
| + if strings.Contains(inst.Logs(), token) { |
| + t.Fatal("the token is in the instance's logs") |
| + } |
| + if page := inst.Get(t, "/conversation/connections"); strings.Contains(page, token) || !strings.Contains(page, "Token expires") { |
| + t.Fatal("the token is on the page, or its expiry is not") |
| + } |
| + list, _ := env.Client.Connections(s.ctx) |
| + raw, _ := json.Marshal(list) |
| + if strings.Contains(string(raw), token) { |
| + t.Fatal("the token is in the API") |
| + } |
| + // Signed out: the home and the token file go. |
| + if _, err = env.Client.SignOut(s.ctx, c.ID); err != nil { |
| + t.Fatal(err) |
| + } |
| + s.wait(t, "signed out", time.Minute, func(cv *thintest.Conversation) bool { return cv.Connections[c.ID].State == wire.ConnSignedOut }) |
| + if _, err := os.Stat(filepath.Join(r.root, "accounts", got.LocalID)); !os.IsNotExist(err) { |
| + t.Fatalf("the token's home stayed: %v", err) |
| + } |
| +} |
diff --git a/internal/runner/thin/movein.go b/internal/runner/thin/movein.go| index 6c17ca13..14c304ae 100644 |
| --- a/internal/runner/thin/movein.go |
| +++ b/internal/runner/thin/movein.go |
| @@ -55,6 +55,15 @@ func coordinatorPersons(c runner.Config) func() []string { |
| } |
| } |
| +// withPerson adds the person the runner is enrolled for: before their |
| +// first connection they have no binding, and adding one must work. |
| +func withPerson(persons []string, person string) []string { |
| + if person != "" && !slices.Contains(persons, person) { |
| + persons = append(persons, person) |
| + } |
| + return persons |
| +} |
| + |
| // Check sends what each person's desk needs, at most once per change |
| // (and again after moveInRetry if nothing came of it). |
| func (s *settler) Check(ctx context.Context) { |
diff --git a/internal/runner/thin/run.go b/internal/runner/thin/run.go| index b57dee16..0dc026a5 100644 |
| --- a/internal/runner/thin/run.go |
| +++ b/internal/runner/thin/run.go |
| @@ -186,7 +186,7 @@ func Run(ctx context.Context, c runner.Config, o Options) error { |
| if o.AccountsRoot == "" { |
| o.AccountsRoot = DefaultAccountsRoot() |
| } |
| - connector := &Connector{Runner: c, State: state, Conns: conns, Root: o.AccountsRoot, Owners: coordinatorPersons(c)(), Notify: link.Notify, Logger: o.Logger, Limit: o.ConnectLimit, RunnerID: creds.Bearer.RunnerID} |
| + connector := &Connector{Runner: c, State: state, Conns: conns, Root: o.AccountsRoot, Owners: withPerson(coordinatorPersons(c)(), creds.Bearer.Person), Notify: link.Notify, Logger: o.Logger, Limit: o.ConnectLimit, RunnerID: creds.Bearer.RunnerID} |
| // The seal key: the X25519 form of the enrolment key the owner |
| // approved; secrets for token connections are sealed to it. |
| sealKey := "" |
| @@ -259,7 +259,7 @@ func Run(ctx context.Context, c runner.Config, o Options) error { |
| if err = engine.Start(ctx); err != nil { |
| return err |
| } |
| - engineer := &Engineer{O: o.Claude, Codex: o.Codex, Clones: clones, Forge: fg, Authorize: link.Confirm, AuthorizeStep: link.ConfirmStep, ConfirmPublication: link.ConfirmPublication, Owners: coordinatorPersons(c)(), MaxStep: o.MaxStep, Note: o.StepNote, Healthy: conns.Usable, Conns: conns, Delta: link.Delta, Activity: link.Activity, StepActivity: link.StepActivity, Retention: o.KeptRetention, Host: c.MachineLabel} |
| + engineer := &Engineer{O: o.Claude, Codex: o.Codex, Clones: clones, Forge: fg, Authorize: link.Confirm, AuthorizeStep: link.ConfirmStep, ConfirmPublication: link.ConfirmPublication, Owners: withPerson(coordinatorPersons(c)(), creds.Bearer.Person), MaxStep: o.MaxStep, Note: o.StepNote, Healthy: conns.Usable, Conns: conns, Delta: link.Delta, Activity: link.Activity, StepActivity: link.StepActivity, Retention: o.KeptRetention, Host: c.MachineLabel} |
| link.Forget = engineer.RemoveKept |
| merges := &MergeWatch{State: state, Clones: clones, Git: c.GitPath, Notify: link.Notify, Logger: o.Logger, Every: o.MergeEvery} |
| if merges.Every <= 0 { |