Skip to content

feat(env): give each computer in a multi env a control token of its own - #825

Open
andrewpark-scaleai wants to merge 1 commit into
mainfrom
andrewpark/per-computer-control-tokens
Open

andrewpark-scaleai wants to merge 1 commit into
mainfrom
andrewpark/per-computer-control-tokens

Conversation

@andrewpark-scaleai

@andrewpark-scaleai andrewpark-scaleai commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Merge order for this group:

  1. Framework: feat(gateway): serve pgweb and db-mcp at /svc/ routes #821 and feat(gateway): open pgweb in a browser with a signed link #824 (merged), then feat(env): give each computer in a multi env a control token of its own #825 (any time).
  2. Consumers (internal PRs) pin a framework release that has 821 and 824, then merge and deploy.
  3. The gateway image with 821, 824 and 825 is promoted.
  4. refactor(env): reach pgweb and db-mcp only through the gateway's /svc routes #823 merges last, after every consumer is deployed on that release and envs on older gateways have expired. Merging it earlier breaks every caller that still uses the old console URLs.

Why

A multi env's computers shared the gateway's control token. This PR gives each computer a token of its own, so each credential opens only what it is for, and keeps the token out of the computer session's process environment.

What changed

  • Each computer mints its own control token at deploy.
  • The gateway gets them in CHILD_CONTROL_TOKENS and sends each computer's token on that computer's /svc routes.
  • The session holds only AGENTENV_CONTROL_TOKEN_SHA256, and the driver card advertises control_token: "sha256".
  • granted_headers picks the longest matching grant prefix.

Scope

  • Multi env computers and computers deployed alone.
  • CONTROL_TOKEN_CHILDREN stays in the gateway for computers an older agent-env booted. Delete it once no deploy sets it.

Blast Radius

  • New framework, older gateway image: steps still reach each computer through the record's per-computer grant.
  • Older framework, new gateway image: the gateway still honors CONTROL_TOKEN_CHILDREN.
  • Computer images composed before this change keep the plain token until recomposed. That token now belongs to the computer alone.
  • Each computer's token sits in child_envs[<name>].control_token of the multi env's record. A hub that strips the top-level token from reads should strip these too.

Verification

  • Unit trees tst/unit/env, tst/unit/providers, tst/unit/task, tst/unit/task_step, tst/unit/drivers and the protocol's tests pass, except environment-specific failures that also fail on the base branch.
  • multi_env_computers_test.py asserts each computer holds its own token.
  • A local Docker container check found no token in the session's process environments.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; the earlier CLI database-link issue remains non-blocking.

Fix All in CursorFindings

  1. P2 Printed database link needs authentication. ▶
Fix with agent prompt
### Issue 1
src/agent_env/cli/env/deploy.py:106-108
The CLI now prints the guarded `db_web_gateway_url` instead of the direct database URL. Opening this link in a browser returns 401 because the browser sends no control token. The CLI gives users neither an authenticated entry point nor instructions for supplying that header.

Provide a browser-friendly authenticated entry point, or print instructions for opening the UI through an authenticated local proxy. Keep the console protected.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Each computer now gets its own control token instead of sharing the gateway's.

  • Each computer gets a control token of its own.
  • Digest-ready drivers no longer need the control token in their process environment.
  • Calls to a computer use its grant instead of the gateway’s.

Diagram

sequenceDiagram
    participant F as Framework
    participant G as Gateway
    participant C as Computer
    F->>C: Boot with token digest
    F->>G: Configure each computer token
    F->>G: Call computer route with matching token
    G->>C: Forward computer token
    C->>C: Compare token hash with stored digest
    C-->>F: Return result through gateway
Loading

Reviews (6) · Last reviewed commit: "feat(env): give each computer in a multi..." · Reviewed by Greptile

Comment on lines +106 to +108
# The SQL consoles take the env's control token, as an Authorization: Bearer header.
if deployed_env.db_web_gateway_url:
click.echo("Env DB Web Url: " + click.style(deployed_env.db_web_gateway_url, fg="yellow"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Printed database link needs authentication. The CLI now prints the guarded db_web_gateway_url instead of the direct database URL. Opening this link in a browser returns 401 because the browser sends no control token. The CLI gives users neither an authenticated entry point nor instructions for supplying that header.

Provide a browser-friendly authenticated entry point, or print instructions for opening the UI through an authenticated local proxy. Keep the console protected.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agent_env/cli/env/deploy.py
Line: 106-108

Comment:
**Printed database link needs authentication.** The CLI now prints the guarded `db_web_gateway_url` instead of the direct database URL. Opening this link in a browser returns 401 because the browser sends no control token. The CLI gives users neither an authenticated entry point nor instructions for supplying that header.

Provide a browser-friendly authenticated entry point, or print instructions for opening the UI through an authenticated local proxy. Keep the console protected.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Cursor Fix in Claude Code Fix in Codex

Each computer mints its own control token at deploy. The gateway receives
them in CHILD_CONTROL_TOKENS and sends each computer's token on that
computer's /svc routes. A driver whose card advertises control_token
"sha256" boots with only the token's digest (AGENTENV_CONTROL_TOKEN_SHA256).
granted_headers picks the longest matching grant. CONTROL_TOKEN_CHILDREN stays
for computers an older agent-env booted.
@andrewpark-scaleai
andrewpark-scaleai force-pushed the andrewpark/per-computer-control-tokens branch from 3238617 to 2dac273 Compare November 20, 2026 23:15

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant