Repository navigation
Bug fix: Use correct Keycloak url and role used by ui admin - #679
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses the Keycloak authentication regression reported in #678 by distinguishing between browser-facing and in-cluster Keycloak URLs for backend token validation, and by restoring admin access when using Keycloak’s default admin role.
Changes:
- Add
Settings.keycloak_internal_urlto use an in-cluster Keycloak endpoint for server-to-server calls (e.g., JWKS fetch). - Update JWT validation to map Keycloak’s
adminrealm role tokagenti-admin, and return 503 when Keycloak is unreachable during token validation. - Helm: inject
KEYCLOAK_URLinto the backend deployment; update the MLflow OAuth secret image reference.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| kagenti/backend/app/core/config.py | Introduces a separate internal Keycloak URL property to support in-cluster server-to-server auth flows. |
| kagenti/backend/app/core/auth.py | Switches JWKS fetching to internal URL; adds admin-role mapping and Keycloak connectivity error handling. |
| charts/kagenti/values.yaml | Updates the configured MLflow OAuth secret image repository. |
| charts/kagenti/templates/ui.yaml | Sets KEYCLOAK_URL env var for the backend pod from Helm values. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Comments addressed in latest push
|
Signed-off-by: Paolo Dettori <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
73854c2 to
4b28f70
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| status_code=status.HTTP_401_UNAUTHORIZED, | ||
| detail="Token key error", | ||
| ) | ||
| except (httpx.HTTPError, ConnectionError) as e: |
There was a problem hiding this comment.
The exception type ConnectionError is a Python built-in that may not catch httpx connection errors. Consider using httpx.ConnectError or httpx.TransportError instead, which are the specific exceptions raised by httpx for connection failures. Alternatively, since httpx.HTTPError is already caught and is the base class for all httpx exceptions, ConnectionError may be redundant unless you specifically need to catch non-httpx connection errors.
| except (httpx.HTTPError, ConnectionError) as e: | |
| except httpx.HTTPError as e: |
| detail="Token key error", | ||
| ) | ||
| except (httpx.HTTPError, ConnectionError) as e: | ||
| logger.error(f"Failed to connect to Keycloak for token validation: {e}") |
There was a problem hiding this comment.
The error message "Failed to connect to Keycloak for token validation" is misleading because this exception handler catches all httpx errors, not just connection errors. These could include HTTP status errors (4xx, 5xx), timeouts, or malformed responses. Consider a more generic message like "Failed to communicate with Keycloak authentication service" or separate the handling to provide more specific error messages for different failure modes.
| logger.error(f"Failed to connect to Keycloak for token validation: {e}") | |
| logger.error( | |
| f"Failed to communicate with Keycloak authentication service during token validation: {e}" | |
| ) |
Summary
Fixes regression issues introduced by previous PR on keycloak URL usage - in-cluster vs. off-cluster and update UI for new role used in backend API.
Related issue(s)
(Optional) Testing Instructions
install kagenti as usual, then do
make build-load-uiand follow printed instructions to run helm command.Fixes #678