Skip to content

Bug fix: Use correct Keycloak url and role used by ui admin - #679

Merged
mrsabath merged 2 commits into
rossoctl:mainfrom
pdettori:fix-keycloak
Feb 13, 2026
Merged

mrsabath merged 2 commits into
rossoctl:mainfrom
pdettori:fix-keycloak

Conversation

@pdettori

Copy link
Copy Markdown
Member

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-ui and follow printed instructions to run helm command.

Fixes #678

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_url to use an in-cluster Keycloak endpoint for server-to-server calls (e.g., JWKS fetch).
  • Update JWT validation to map Keycloak’s admin realm role to kagenti-admin, and return 503 when Keycloak is unreachable during token validation.
  • Helm: inject KEYCLOAK_URL into 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.

Comment thread kagenti/backend/app/core/auth.py Resolved
Comment thread kagenti/backend/app/core/auth.py Resolved
Comment thread charts/kagenti/values.yaml Resolved
Comment thread kagenti/backend/app/core/config.py Resolved
Comment thread kagenti/backend/app/core/auth.py Resolved
@pdettori

Copy link
Copy Markdown
Member Author

Comments addressed in latest push

  1. Reverted mlflowOAuthSecret.image change — restored quay.io/ladas/mlflow-oauth-secret with the TODO comment. This belongs in a separate PR.
  2. Updated admin role mapping comment — replaced the generic comment with a TODO that explicitly marks this as temporary, references issue feat(auth): add RBAC role constants and hierarchy support #647 ("Protect Backend API" epic), and states it
    should be replaced with proper Keycloak role provisioning.
  3. Fixed duplicate logging (bonus, from another Copilot comment) — removed the try/catch logging in load_keys() since validate_token already logs the error. This avoids duplicate error
    lines per failure.

Copilot AI review requested due to automatic review settings February 13, 2026 11:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copilot AI Feb 13, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
except (httpx.HTTPError, ConnectionError) as e:
except httpx.HTTPError as e:

Copilot uses AI. Check for mistakes.
detail="Token key error",
)
except (httpx.HTTPError, ConnectionError) as e:
logger.error(f"Failed to connect to Keycloak for token validation: {e}")

Copilot AI Feb 13, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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}"
)

Copilot uses AI. Check for mistakes.

@mrsabath mrsabath left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@mrsabath
mrsabath merged commit 6572af3 into rossoctl:main Feb 13, 2026
21 checks passed
@pdettori
pdettori deleted the fix-keycloak branch February 13, 2026 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

🐛 kagenti ui is broken

3 participants