Add Cloudmux-scoped session credential leases#72
Draft
lawrencecchen wants to merge 1 commit into
Draft
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ae7b593 to
3383948
Compare
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.
Summary
openai-codex-responses.Lease contract
POST /internal/v1/session-leasesrequires the configured Subrouter admin bearer token for network callers. Loopback remains available for local self-hosting.Request:
{ "organizationId": "organization-1", "workspaceId": "workspace-1", "conversationId": "conversation-1", "invocationId": "invocation-1", "agentSessionId": "agent-session-1", "agent": "pi", "provider": "codex", "model": "openai/gpt-5.4", "proxyBaseUrl": "http://subrouter:31415" }provider,model, andproxyBaseUrlare optional. Provider aliases are normalized, provider-prefixed models are normalized, and conflicting provider/model prefixes are rejected.Codex response shape:
{ "leaseId": "lease_<random>", "sessionKey": "agent-session-1", "expiresAt": "2026-07-11T12:15:00Z", "environment": { "CLOUDMUX_SUBROUTER_LEASE_TOKEN": "<three-segment SRLEASE capability>", "OPENAI_API_KEY": "<same capability>", "OPENAI_BASE_URL": "http://subrouter:31415/v1" }, "assignment": { "accountId": "<selected Subrouter account>", "provider": "codex", "authMode": "oauth", "model": "gpt-5.4", "reason": "subrouter_scheduler" }, "pi": { "provider": "cloudmux-subrouter", "api": "openai-codex-responses", "baseUrl": "http://subrouter:31415/backend-api", "apiKeyEnvironmentVariable": "CLOUDMUX_SUBROUTER_LEASE_TOKEN", "model": "gpt-5.4" } }Anthropic-compatible assignments return
ANTHROPIC_API_KEY,ANTHROPIC_AUTH_TOKEN, andANTHROPIC_BASE_URLinstead.DELETE /internal/v1/session-leases/<leaseId>is authenticated and idempotent.The capability is accepted as an OpenAI-compatible bearer token, an Anthropic-compatible
X-Api-Key, or an explicitX-Subrouter-Leaseheader.Security model
typ: "SRLEASE". The payload marker iscloudmux_session_lease: true.cloudmux-broker. The selected upstream account ID and provider credentials never appear in the token.atobdirectly. The random third segment uses base64url.Testing
go test ./...go vet ./...go test -race ./internal/proxy -run 'SessionLease|PresentedSessionLease' -count=1All checks pass. Behavior coverage includes admin authentication, OAuth and API-key proxy exchange, Pi-compatible claim decoding, credential and upstream-account non-disclosure, idempotent minting, random nonce/signature uniqueness, forged-signature rejection, ordinary provider JWT pass-through, endpoint/model restriction, revocation, and expiration.
Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.Summary by cubic
Add Cloudmux session credential leases to broker 15‑minute, invocation-scoped tokens that pin traffic to a selected account/provider/model without exposing provider credentials. Enables Pi to use
codexand Anthropic-compatible routes safely.New Features
/internal/v1/session-leasesmints a lease and returns env vars + Pi config; optionalprovider,model,proxyBaseUrl; normalizes aliases; idempotent per invocation scope./internal/v1/session-leases/{leaseId}revokes (idempotent); leases expire after 15 minutes and are cleared on restart.X-Api-Key, orX-Subrouter-Lease; swaps it for the selected account credential inside Subrouter, pinsaccount/provider/model, and restricts calls to the provider’s model endpoint.codexOpenAI-compatible/v1/*and Anthropic-compatible messages for Claude, Kimi, and ZAI.Migration
AdminToken, call POST to mint a lease, keep the returned env in memory, use the providedbaseUrland model, and send DELETE on cleanup.Written for commit ae7b593. Summary will update on new commits.