Repository navigation
Conversation
Add support for validating per-user RS256 JWTs forwarded by a trusted gateway. When enabled, cidx verifies the RS256 signature against the gateway's JWKS endpoint and JIT-provisions the user via the existing OIDC path, so cidx enforces its own per-user access control. Components: - GatewayJwtValidator: RS256 signature + iss/aud/exp verification with JWKS rate-limiting to prevent refetch amplification attacks - GatewayIdentityAuthenticator: bridges the validator and OIDCManager; offloads the synchronous JWKS fetch to a worker thread via anyio.to_thread.run_sync so it never blocks the event loop - gateway_auth_wiring: fail-safe factory with isolated identity-link store (gateway_oauth.db, separate from interactive SSO's oauth.db) - TrustedGatewayConfig: dataclass with defaults (disabled by default) - Priority 1.5 dispatch in dependencies.py between MCP credentials and OAuth/JWT, with session pre-elevation and TOTP documentation Security hardening vs. the base implementation: - JWKS fetch runs in worker thread (was blocking the event loop) - JWKS refetch rate-limited (forged kids cannot amplify requests) - Pre-elevation scope documented for TOTP audit trail
This was referenced Nov 5, 2026
added 3 commits
November 6, 2026 16:22
- Replace the global _last_jwks_error with a per-kid cooldown dict so a forged token with an unknown kid cannot block legitimate tokens whose kid is already cached - Require an explicit kid header; tokens without one are rejected without touching the cooldown - Add timeout=5 to PyJWKClient so a hanging JWKS endpoint cannot exhaust the anyio thread limiter - Reject non-https jwks_uri at construction time
Remove the automatic full-scope elevation window for gateway bearers. The gateway token is not proof of a second factor (unlike OAuth tokens cidx issued after its own MFA flow), so gateway users step up through the TOTP elevate tool like JWT-bearer users. Also set elevation_username so the elevation decorator can bind the window to this user.
- Pass oauth_backend through build_gateway_authenticator to OIDCManager so multi-replica deployments use cluster storage instead of per-pod SQLite - Add allow_email_auto_link=False (default) to TrustedGatewayConfig; when disabled, gateway identity resolution never sees the email claim and cannot auto-link to existing local accounts - Extract _normalize_group_mappings() and call it from both OIDCProviderConfig and TrustedGatewayConfig.__post_init__
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
Adds trusted gateway authentication: when cidx is fronted by a gateway, per-user RS256 JWTs forwarded by the gateway are validated against the gateway JWKS and JIT-provisioned via the existing OIDC path. This lets cidx enforce its own per-user access control (groups / repo_group_access) for gateway-proxied users.
New files
gateway_jwt_validator.py— RS256 signature verification against gateway JWKS, with rate-limited refetchesgateway_identity_authenticator.py— bridges validator + OIDCManager; async JWKS fetch via worker threadgateway_auth_wiring.py— fail-safe factory with isolated identity-link storeModified files
config_manager.py— addsTrustedGatewayConfigdataclass (disabled by default)dependencies.py— adds Priority 1.5 dispatch between MCP credentials and OAuth/JWTSecurity hardening
gateway_oauth.db) so subjects from different trust domains cannot collideTest plan
test_gateway_jwt_validator.py— valid token, issuer routing, alg-confusion, wrong audience, expired, missing sub, custom claimstest_gateway_identity_authenticator.py— claim mapping, empty groups, invalid token, failed provisioningtest_gateway_auth_wiring.py— enabled/disabled/None/misconfigured, isolated store assertiontest_gateway_mcp_dispatch.py— gateway token provisioned, invalid 401, non-gateway fallthrough, no authenticator noopReview findings addressed:
db_pathat this headfix: add db_path parameterfix: per-kid JWKS cooldownfix: remove gateway pre-elevationfix: remove gateway pre-elevationfix: wire oauth_backendfix: wire oauth_backendfix: remove gateway pre-elevationfix: per-kid JWKS cooldownfix: per-kid JWKS cooldownfix: remove gateway pre-elevationfix: wire oauth_backendMerge order: PR #2128 (only its OIDCManager
db_pathchange, already cherry-picked here) → this PR → PR #2133 (lifespan wiring). PR #2128 should drop its divergent copies of the 3 gateway modules.