Skip to content

feat(gateway): take the control token on the older /svc REST state routes - #822

Merged
earakely-scale merged 4 commits into
mainfrom
andrewpark/legacy-rest-routes-take-token
Nov 24, 2026
Merged

earakely-scale merged 4 commits into
mainfrom
andrewpark/legacy-rest-routes-take-token

Conversation

@andrewpark-scaleai

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

Copy link
Copy Markdown
Contributor

Merge order for this pair:

  1. fix(env): send the control token to the REST routes behind the gateway #820 (callers send the token) merges first, any time.
  2. The internal caller PRs merge and deploy.
  3. feat(gateway): take the control token on the older /svc REST state routes #822 (the gateway requires the token) merges last. Merging it earlier makes every caller that doesn't send the token get a 401.

DO NOT MERGE until the scaleapi and synthetic-pipelines caller PRs are merged and deployed. Once this ships in a gateway image, a caller of these routes that does not send the control token gets a 401.

Why

The gateway's data plane routes take the control token. This PR applies the same rule to the older REST state routes behind /svc/<key>/, so every state-changing or state-reading route behind the gateway uses one auth scheme.

What changed

  • LEGACY_STATE_ROUTES in gateway/constants.py lists the older state routes: /api/reset, /api/add, /api/bridge/apply, /export-state, /export-snapshot, /snapshot-dirty, /reset-memory, /validate-rows, /api/_state, /api/_reset and /api/debug/seed.
  • token_paths adds them to every /svc/<key>/ route. Matching reuses reaches, so paths are normalized before the check.
  • A site's /website/<site>/ route serves none of these routes. The harness reaches sites through /svc/<site>/.
  • A gateway booted without a token behaves as before.
  • The verifier that run_bundle_built_envs_test.py embeds sends the run's grant to /export-state.

Rollout

Verification

  • tst/unit/env/gateway/control_token_test.py: 354 passed. tst/unit/env/gateway: 1356 passed. ruff check is clean.
  • Integration tests on local Docker through a token-booted gateway pass.

RetriggerView in GreptileConfidence Score: 5/5

The code appears safe to merge once the required caller deployments are complete.

Summary

The gateway now requires its control token for the listed legacy state routes behind /svc. With a token configured, website HTTP and WebSocket routes refuse those paths.

  • Legacy state calls behind /svc/<key>/ now need the control token.
  • /website/ routes now block legacy state paths on tokened gateways.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Request for a legacy state route] --> B{Gateway has a token?}
  B -->|No| C[Existing behavior]
  B -->|Yes| D{Route}
  D -->|/svc| E{Correct token?}
  E -->|Yes| F[Forward to backing service]
  E -->|No| G[401]
  D -->|/website| H[404 before forwarding]
Loading

Reviews (9) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile

@andrewpark-scaleai
andrewpark-scaleai marked this pull request as ready for review November 20, 2026 16:53
@andrewpark-scaleai
andrewpark-scaleai requested a review from a team as a November 20, 2026 16:53
@andrewpark-scaleai
andrewpark-scaleai force-pushed the andrewpark/legacy-rest-callers-send-token branch from 58f18f0 to f3ff3b3 Compare November 20, 2026 17:14
@andrewpark-scaleai
andrewpark-scaleai force-pushed the andrewpark/legacy-rest-routes-take-token branch from ab1fd64 to c614945 Compare November 20, 2026 17:30
Comment thread src/agent_env/env/gateway/gateway.py Resolved
Ubuntu added 3 commits November 20, 2026 22:53
The legacy REST helpers (reset_via_rest, add_via_rest, export_state, reset)
take headers and default to the run's grant. Legacy loads, resets, state reads
and streamed snapshots send the deployment's token. A grant covers a URL only
when it resolves under the grant's address, by whole path segments. A legacy
reset refused with 401 or 403 raises instead of falling back to the MCP tool.
…utes

LEGACY_STATE_ROUTES lists the older state routes a backing server serves
beside its data plane. On a gateway with a control token, every /svc/<key>/
route takes the token for each of them, after path normalization. A site's
/website route serves none of them. A gateway booted without a token behaves
as before.
A site at http://host/base receives ../base/x as /base/x, which is /x under its base. The route's path check now
reads the path the site receives against the site's own address, decoded, with the base path taken off, so it
matches the same paths the site's card names.
@andrewpark-scaleai
andrewpark-scaleai force-pushed the andrewpark/legacy-rest-routes-take-token branch from c614945 to 475e53d Compare November 20, 2026 23:04
@earakely-scale

Copy link
Copy Markdown
Collaborator

🤖 Automated Claude routine — Env Pod PR Context Review. This is a bot, not Edgar Arakelyan; not a human review.

Context from outside this diff, in case it hasn't crossed paths yet: #776 (open since Nov 18, still open) changes the same two halves as this stack, and neither PR references the other.

Two places the two route contracts disagree, both checkable from the diffs:

  1. Route set. fix(security): Older REST data routes behind the gateway proxy (/api/reset, /export-state, /export-snapshot) take no control token #776's list has 6 entries; this PR's LEGACY_STATE_ROUTES has 11, adding /api/add, /api/bridge/apply, /api/_state, /api/_reset, /api/debug/seed (asserted by set(LEGACY) == set(LEGACY_STATE_ROUTES) in control_token_test.py).
  2. Which keys are gated. fix(security): Older REST data routes behind the gateway proxy (/api/reset, /export-state, /export-snapshot) take no control token #776 guards only MCP keys — *(LEGACY_DATA_PATHS if key.startswith("mcp-") and key not in website_urls else ()) — and its control_token_test.py moves ("POST", "/svc/shop/api/reset") into PROXIED_OPEN. This PR guards every /svc/<key>/ including a site's, and refuses the same paths under /website/<site>/ (SITE_LEGACY_STATE_ROUTES). So the two land on opposite answers for a site's older REST routes.

Also worth noting for sequencing: this PR's description pins the gateway half to merge last, after the caller rollout, or untokened callers get 401. #776 carries both halves in one PR with no such guard, so if it merges first the gateway half ships ahead of that rollout.

No action implied — just surfacing that these are competing implementations so the pod can pick one before either lands.


Generated by Claude Code

Base automatically changed from andrewpark/legacy-rest-callers-send-token to main November 24, 2026 16:56
# Conflicts:
#	src/agent_env/env/legacy_protocol.py
#	src/agent_env/task_step/task_steps/snapshot_env.py
#	tst/unit/env/test_env.py
@earakely-scale
earakely-scale merged commit 1170219 into main Nov 24, 2026
59 of 63 checks passed
@earakely-scale
earakely-scale deleted the andrewpark/legacy-rest-routes-take-token branch November 24, 2026 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants