Skip to content

service tokens: 403 ROUTE_NOT_ALLOWLISTED for valid tokens; MCP lists only allowed tools - #185

Merged
teddashh merged 2 commits into
mainfrom
feat/service-token-route-403
Nov 21, 2026
Merged

teddashh merged 2 commits into
mainfrom
feat/service-token-route-403

Conversation

@teddashh

Copy link
Copy Markdown
Collaborator

What

The Hub now says which layer denied a service-token request, and the MCP lists only the tools a token can actually use.

  1. 403 instead of 401 for a valid token. A valid service token (scope, expiry, revocation and source CIDR all pass) that calls an eligible route not in its allowlist now gets 403 ROUTE_NOT_ALLOWLISTED. Before, it got a generic 401 UNAUTHENTICATED.
    • This denial no longer spends the serviceAttempts failed-attempt budget, because a valid credential is not a guessing attempt.
    • Unknown, revoked or expired tokens, CIDR mismatches and ineligible routes keep the generic 401.
    • In store.AuthenticateServiceToken, the allowlist check now runs after the source CIDR check and returns the new ErrServiceRouteNotAllowed.
  2. GET /v1/operator/service-tokens/self also returns allowlist. operatorclient.ServiceTokenSelf gained the field.
  3. clawctl-operator --token-file … mcp filters tools/list to the tools whose Hub routes are all in that allowlist.
    • The routes for each tool are declared in internal/operatoragent/routes.go.
    • If the self call fails, the list stays complete; the Hub still enforces either way.
    • Tailnet-identity mode (no token) is unchanged.

This came up for real: the operator-admin token's allowlist lacks POST /v1/operator/schedule-jobs/{id}/cancel. The MCP still offered schedule_job_cancel, and the call came back as "401 Authentication required".

Consistency guard

TestOperatorToolRoutesAreRegistered fails if:

  • a tool in Tools() declares no routes, or
  • a declared route is not registered in the Hub's operatorRoutePolicies.

So a new tool cannot be added without declaring its routes, and a renamed route cannot drift.

Tests

  • TestServiceTokenRouteNotAllowlisted:
    • 403 with the code, repeated five times without exhausting a burst-2 limiter, after which an allowed call still succeeds
    • a forged token gets 401
    • self returns the allowlist
  • TestToolsForFiltersByAllowlist: filtering, multi-route tools need every route, nil allowlist lists everything, and MCP tools/list uses it.
  • TestServiceTokenBoundary: the non-allowlisted case now expects 403. The CIDR mismatch case is still 401.

Deploy / rollback

  • No schema change.
  • This is a behaviour change only for valid tokens on routes outside their allowlist (401 → 403). Clients that treat any 4xx as failure are unaffected.
  • Rollback: redeploy the previous image (68ef582); nothing to undo.

… only allowed tools

A valid service token calling an eligible route outside its allowlist now
gets 403 ROUTE_NOT_ALLOWLISTED instead of a generic 401, and the denial no
longer spends the failed-attempt rate-limit budget. Bad, revoked, expired
or CIDR-mismatched tokens keep 401. GET service-tokens/self returns the
allowlist, and clawctl-operator mcp with --token-file filters tools/list to
tools whose declared Hub routes the token holds.
@teddashh
teddashh merged commit caff12a into main Nov 21, 2026
15 checks passed
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