Fix CodeRouter trusted tenant exchange

Merged
LA
3mo ago
+65-5

Moves the trusted hosted-tenant exchange request into the API route so the deployed function always sends the scoped capabilities and dedicated control credential. This fixes production CLI login failures caused by a stale bundled hosted client omitting the control header.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Summary by cubic

Moves the trusted hosted-tenant exchange into API routes and switches the CLI to a semantic endpoint. Always forwards scoped capabilities and the stack control token header to fix login failures from stale clients.

  • Bug Fixes
    • Added POST /api/subrouter/tenant-exchange that posts to /_subrouter/auth/stack with Authorization, x-subrouter-stack-control-token, capability flags, and team info; uses no-store caching, propagates upstream errors, and returns parsed tenant JSON.
    • Updated CLI config to set exchangeUrl to /api/subrouter/tenant-exchange and cache-control to no-store on the config response.
    • Read hosted credentials via validated env (SUBROUTER_HOSTED_URL, SUBROUTER_STACK_TENANT_DELETE_TOKEN); return 503 if missing.

Summary by CodeRabbit

  • New Features

    • Added tenant-aware subrouter exchange support for CLI integrations.
    • Tenant capabilities and identity are securely forwarded during exchanges.
    • Added permission checks and validation for required service configuration.
  • Bug Fixes

    • Updated CLI configuration to use the tenant-specific exchange endpoint.
    • Improved propagation of upstream errors and unexpected failures.
    • Exchange responses are now uncached to ensure current configuration is used.