Repository navigation
feat(gateway): role authentication through a roles/v1 extension - #874
Open
earakely-scale wants to merge 2 commits into
Open
earakely-scale wants to merge 2 commits into
earakely-scale wants to merge 2 commits into
Conversation
A caller could act as any role by naming it in the AgentEnv-Role header. The gateway now resolves each request's role once and refuses a role that was declared with token auth unless the caller presents a member's agent token (or the env control token). - roles/v1 (control-token only, advertised only on a gateway with a control token): POST/GET/DELETE /roles and POST/DELETE /roles/members, fixed paths with the role in the JSON body. The store keeps token digests only. - Resolution on every HTTP and WebSocket request; refusals (403) only on role-acting routes: the MCP path (rechecked on every tool call), /step, /svc/*, /website/* and /browser/*. Role names match case-insensitively. - Startup roles from GATEWAY_ROLES; computer token digests from COMPUTER_TOKEN_DIGESTS, with AgentEnv-Computer honoured only alongside that computer's token when the variable is present. - Identity headers are stripped before anything is proxied, and every trajectory event that names a role records how it was established (role_auth). - No token or digest reaches logs, errors, state or trajectories. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…t_token An MCP session keeps the role, source and agent token digest its initialize resolved to. A session opened on an open role with a token that was not yet a member kept source "header", so once the role was protected and the token added, its tool calls passed the membership check but still recorded role_auth "header". Each tools/call now derives the source from how it is authorized at that call (Roles.source_now) and binds it for the call: agent_token while the token is a member, header once the membership it was established by has ended on an open role, and the control and computer tokens unchanged. Only the digest is consulted; no token is stored. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Today a caller can act as any role on an env gateway by naming it in the
AgentEnv-Roleheader: on/step, the MCP endpoint,/svc,/websiteand/browser. So a client that can reach the gateway can read and write as another persona.This adds role authentication to the gateway. A role declared with token auth answers only to a member's agent token (sent as
AgentEnv-Agent-Token) or the env control token. Undeclared roles and roles declared withnoneauth work exactly as today, so nothing changes until someone declares a token role.This is the gateway half. Deploy-side support (minting agent tokens, declaring roles and adding members) comes in follow-up framework PRs.
Behaviour
POST /roles {role, auth: {type: none|token}},GET /roles,DELETE /roles {role}.POST /roles/members {role, agent_token}returns{member_id, auth};DELETE /roles/members {role, member_id}.GET /rolesreturns member ids, never a token or digest.default.default.brooke@…can't be reached asBROOKE@….{ok: false, error: "refused: …"}): only on routes that act as a role./step,/svc/*,/website/*(WebSocket included) and/browser/*./state, the card,/trajectory,/changes,/clock/*,/triggers/*,/notifications/*,/user_chat/*,/tools/*and/rolesnever take a role.GATEWAY_ROLESis a JSON list of{role, auth: {type}}. These come back after a restart; runtime members don't.COMPUTER_TOKEN_DIGESTS(name=sha256hex,…) at startup. When the variable is present, even empty,AgentEnv-Computercounts only with a matchingAgentEnv-Computer-Token(compared withhmac.compare_digest). Without it, an unauthenticated computer header is honoured only while the driver's role is open.AgentEnv-Agent-Token,AgentEnv-ComputerandAgentEnv-Computer-Tokenare stripped before anything is proxied./svcand/websiteget the resolved role stamped.role_auth:agent_token,control_token,computer_token,headerordefault./changesactors carry it too.Notes for reviewers
role_authis not added inside theprovokingdict oftrigger_firedevents. That would change the triggers wire shape that existing tests and consumers pin. The provoking call's owntool_call/http_requestevent already records it./svc/<SQL console>is not a role-acting route.How it was tested
pytest tst/unit/ packages/agentenv-protocol/tests/ -n auto.computer_exec_testsystem commands andtest_disk_recipe's Windows install).ruff checkis clean, andcheck_plugin_api.py --base origin/mainreports no break.tst/integration/env/gateway/gateway_role_auth_test.py: 2 passed. A persona made token-auth refuses a header switch (in any case), a member token plays it, an open role still works, and an MCP client with a member token lists and calls tools.tst/integration/computer/computer_triggers_test.py::test_a_computers_browser_requests_take_the_role_driving_it_now: 1 passed.🤖 Generated with Claude Code


Confidence Score: 5/5
The PR appears safe to merge; the previous recording issue is fixed and no new blocking issue was found.Summary
Adds gateway role authentication through
roles/v1, with token membership checks and authentication details in recorded events.Diagram
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Incoming request] --> B[Resolve role and credentials] B --> C{Role-acting route?} C -->|No| E[Serve route] C -->|Yes| D{Role allowed?} D -->|No| F[Refuse request] D -->|Yes| E E --> G[MCP tool call] G --> H[Recheck current membership] H --> I[Refresh recorded authentication source] I --> J[Run tool with temporary caller]Reviews (2) · Last reviewed commit: "fix(gateway): a session whose token join..." · Reviewed by Greptile