Skip to content

feat: migrate UI from Keycloak master realm to dedicated kagenti realm - #764

Merged
pdettori merged 7 commits into
rossoctl:mainfrom
mrsabath:feat/keycloak-kagenti-realm
Mar 4, 2026
Merged

pdettori merged 7 commits into
rossoctl:mainfrom
mrsabath:feat/keycloak-kagenti-realm

Conversation

@mrsabath

@mrsabath mrsabath commented Feb 25, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Migrates the Kagenti UI from Keycloak's built-in master realm to a dedicated kagenti realm
  • Adds guarded realm bootstrap logic to auth_secret.py — creates the kagenti realm and a default admin user during installation, controlled by AUTO_BOOTSTRAP_REALM (default: true, set false for prod)
  • Bootstrapped user includes email/name (required by Keycloak 26.x for profile completion) and is granted realm-admin role for Keycloak admin console access
  • Templatizes 5 hardcoded /realms/master references in Helm templates so all realm URLs derive from {{ .Values.keycloak.realm }}
  • Phase 1 of a multi-phase effort to align UI, AuthBridge demos, and CI onto a single shared Keycloak realm (resolves kagenti-extensions#147)

Files changed

File Change
charts/kagenti/values.yaml keycloak.realm: kagenti, add autoBootstrapRealm: true
charts/kagenti/templates/ui.yaml Templatize KEYCLOAK_CONSOLE_URL
charts/kagenti/templates/agent-namespaces.yaml Templatize 4x /realms/master
charts/kagenti/templates/ui-oauth-secret-job.yaml Pass AUTO_BOOTSTRAP_REALM env
kagenti/auth/ui-oauth-secret/auth_secret.py Realm + user bootstrap logic (with email/name, realm-admin role)
kagenti/backend/app/core/config.py Update fallback default
kagenti/ui-v2/src/pages/AdminPage.tsx Update fallback default

Design decisions

  • Toggle-controlled: AUTO_BOOTSTRAP_REALM=false disables all privileged Keycloak operations (realm/user creation) for production environments
  • Idempotent: Realm and user creation are guarded by existence checks; never resets existing user passwords; never modifies existing clients
  • Backward compatible: Users can override keycloak.realm: master in their values to keep the old behavior
  • Admin API unchanged: user_realm_name="master" stays in all auth scripts — Keycloak admin API always authenticates through master (Keycloak requirement)
  • Complete user profile: Bootstrapped user includes email, firstName, lastName, emailVerified (required by Keycloak 26.x) and realm-admin role (for admin console access)

Known limitations (Phase 1)

  • AuthBridge demos still use the demo realm. UI chat with AuthBridge-protected agents will work once demos are migrated to the kagenti realm (Phase 2 follow-up in kagenti-extensions)
  • Switching realm invalidates all existing sessions/tokens — users must re-login after upgrade

Test plan

Smoke test checklist

# 1. Realm exists
curl -s http://keycloak.localtest.me:8080/realms/kagenti | jq .realm
# Expected: "kagenti"

# 2. UI client exists in kagenti realm
ADMIN_TOKEN=$(curl -s http://keycloak.localtest.me:8080/realms/master/protocol/openid-connect/token \
  -d "grant_type=password" -d "client_id=admin-cli" \
  -d "username=admin" -d "password=admin" | jq -r .access_token)
curl -s -H "Authorization: Bearer $ADMIN_TOKEN" \
  "http://keycloak.localtest.me:8080/admin/realms/kagenti/clients" | jq '.[].clientId' | grep kagenti
# Expected: "kagenti"

# 3. Token issuer is /realms/kagenti
curl -s http://keycloak.localtest.me:8080/realms/kagenti/.well-known/openid-configuration | jq .issuer
# Expected: "http://keycloak.localtest.me:8080/realms/kagenti"

# 4. UI login succeeds
# Navigate to http://kagenti-ui.localtest.me:8080 and log in with admin/admin

# 5. Keycloak admin console accessible
# Navigate to http://keycloak.localtest.me:8080/admin/kagenti/console/ — no permission error

Acceptance criteria

  • Fresh install: UI login succeeds against kagenti realm
  • Admin page: Keycloak console link points to /admin/kagenti/console/
  • Keycloak admin console: No "You do not have permission" error for bootstrapped user
  • Idempotent: Re-running the OAuth secret job creates no duplicates
  • Bootstrap disabled: AUTO_BOOTSTRAP_REALM=false with missing realm shows clear error
  • Note: Chat with AuthBridge demos expected to fail until Phase 2

@pdettori pdettori 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.

Review Summary

This PR migrates the Kagenti UI from Keycloak's master realm to a dedicated kagenti realm. The Helm templatization of realm references is clean and the design is well thought out (idempotent, toggle-controlled, backward compatible).

However, the user bootstrap logic silently fails in CI, causing the admin user to not be created in the kagenti realm, which breaks UI login. The pre-commit hooks are also failing on the build job.

Areas reviewed: Python, Helm/K8s, Frontend (TSX)
Commits: 2 commits, all signed-off ✅
CI status: ❌ failing — Deploy & Test (user_not_found in kagenti realm), build 3.12 (pre-commit hooks)

CI Failure Analysis

Deploy & Test: UI E2E agent-chat.spec.ts times out because the Keycloak login fails. Keycloak logs show repeated:

type="LOGIN_ERROR", realmName="kagenti", clientId="kagenti", error="user_not_found", username="admin"

The kagenti realm and client were created, but the admin user was NOT created.

Build (3.12): Fails at "Run pre-commit hooks" step (3.11 was cancelled by matrix strategy).

@mrsabath
mrsabath force-pushed the feat/keycloak-kagenti-realm branch from af0b90f to e735cdf Compare February 27, 2026 04:36
@mrsabath
mrsabath force-pushed the feat/keycloak-kagenti-realm branch from f4a87b3 to bf7a84f Compare February 27, 2026 14:25
@pdettori

Copy link
Copy Markdown
Member

/run-e2e

@github-actions github-actions Bot added the safe-to-test Maintainer reviewed - safe to run E2E tests label Feb 27, 2026
@github-actions

Copy link
Copy Markdown

E2E HyperShift Tests Started

Triggered by: @pdettori
Commit: 27463d3ecc889d75d3c4291c1b3e9984a762986a
Workflow Run: View logs

Tests are running on OpenShift 4.20.11. This typically takes 30-45 minutes.


To re-run tests after new commits, comment /run-e2e again.

@github-actions

Copy link
Copy Markdown

E2E HyperShift Tests Failed

Commit: 27463d3ecc889d75d3c4291c1b3e9984a762986a
Result: Tests failed - please check the logs
Workflow Run: View logs


To re-run tests after fixing issues, comment /run-e2e again.

@github-actions github-actions Bot removed the safe-to-test Maintainer reviewed - safe to run E2E tests label Feb 27, 2026
@github-actions

Copy link
Copy Markdown

New Commits Detected

The safe-to-test label has been automatically removed because new commits were pushed.

New HEAD: fe5ea0b

For maintainers: Please review the new changes and comment /run-e2e to trigger E2E tests.

Security checklist

Before running E2E tests, verify the PR does NOT contain:

  • Changes to .github/workflows/ that bypass security
  • Changes to .github/scripts/ that could exfiltrate secrets
  • curl, wget, or nc commands to external URLs in scripts
  • Base64 encoding of environment variables
  • Printing secrets to logs (echo $SECRET)
  • Suspicious package installations

This is an automated security measure to prevent TOCTOU attacks

@mrsabath

Copy link
Copy Markdown
Member Author

/run-e2e

@github-actions github-actions Bot added the safe-to-test Maintainer reviewed - safe to run E2E tests label Feb 27, 2026
@github-actions

Copy link
Copy Markdown

E2E HyperShift Tests Started

Triggered by: @mrsabath
Commit: fe5ea0b37d360c41eac1874ba5dbdde492090155
Workflow Run: View logs

Tests are running on OpenShift 4.20.11. This typically takes 30-45 minutes.


To re-run tests after new commits, comment /run-e2e again.

@github-actions

Copy link
Copy Markdown

E2E HyperShift Tests Failed

Commit: fe5ea0b37d360c41eac1874ba5dbdde492090155
Result: Tests failed - please check the logs
Workflow Run: View logs


To re-run tests after fixing issues, comment /run-e2e again.

@mrsabath

Copy link
Copy Markdown
Member Author

/run-e2e

@github-actions

Copy link
Copy Markdown

E2E HyperShift Tests Started

Triggered by: @mrsabath
Commit: fe5ea0b37d360c41eac1874ba5dbdde492090155
Workflow Run: View logs

Tests are running on OpenShift 4.20.11. This typically takes 30-45 minutes.


To re-run tests after new commits, comment /run-e2e again.

@github-actions

Copy link
Copy Markdown

E2E HyperShift Tests Failed

Commit: fe5ea0b37d360c41eac1874ba5dbdde492090155
Result: Tests failed - please check the logs
Workflow Run: View logs


To re-run tests after fixing issues, comment /run-e2e again.

@github-actions github-actions Bot removed the safe-to-test Maintainer reviewed - safe to run E2E tests label Mar 3, 2026
@github-actions

github-actions Bot commented Mar 3, 2026

Copy link
Copy Markdown

New Commits Detected

The safe-to-test label has been automatically removed because new commits were pushed.

New HEAD: 597f69f

For maintainers: Please review the new changes and comment /run-e2e to trigger E2E tests.

Security checklist

Before running E2E tests, verify the PR does NOT contain:

  • Changes to .github/workflows/ that bypass security
  • Changes to .github/scripts/ that could exfiltrate secrets
  • curl, wget, or nc commands to external URLs in scripts
  • Base64 encoding of environment variables
  • Printing secrets to logs (echo $SECRET)
  • Suspicious package installations

This is an automated security measure to prevent TOCTOU attacks

@mrsabath

mrsabath commented Mar 4, 2026

Copy link
Copy Markdown
Member Author

/run-e2e

@github-actions github-actions Bot added the safe-to-test Maintainer reviewed - safe to run E2E tests label Mar 4, 2026
@github-actions

github-actions Bot commented Mar 4, 2026

Copy link
Copy Markdown

E2E HyperShift Tests Started

Triggered by: @mrsabath
Commit: 597f69f40d769c5baebe75f10019dd26a4aca964
Workflow Run: View logs

Tests are running on OpenShift 4.20.11. This typically takes 30-45 minutes.


To re-run tests after new commits, comment /run-e2e again.

@github-actions

github-actions Bot commented Mar 4, 2026

Copy link
Copy Markdown

E2E HyperShift Tests Failed

Commit: 597f69f40d769c5baebe75f10019dd26a4aca964
Result: Tests failed - please check the logs
Workflow Run: View logs


To re-run tests after fixing issues, comment /run-e2e again.

mrsabath added 2 commits March 3, 2026 20:57
Replace hardcoded `master` realm references with a configurable `kagenti`
realm for the Kagenti UI and platform components. This is Phase 1 of
aligning all components (UI, AuthBridge demos, CI) onto a single shared
Keycloak realm, which will resolve the UI chat 401 issue when AuthBridge
is enabled (kagenti-extensions#147).

Changes:
- values.yaml: change keycloak.realm from `master` to `kagenti`, add
  `autoBootstrapRealm` toggle
- ui.yaml: templatize KEYCLOAK_CONSOLE_URL (was hardcoded /admin/master/)
- agent-namespaces.yaml: templatize 4 hardcoded /realms/master references
- ui-oauth-secret-job.yaml: pass AUTO_BOOTSTRAP_REALM env var to job
- auth_secret.py: add guarded realm bootstrap (create realm + default
  user if AUTO_BOOTSTRAP_REALM=true and realm != master)
- config.py: update fallback realm default from `master` to `kagenti`
- AdminPage.tsx: update fallback realm for Keycloak console link

The realm bootstrap is idempotent (create-only-if-absent, never resets
existing user passwords) and can be disabled for production environments
by setting keycloak.autoBootstrapRealm=false in Helm values.

Note: AuthBridge demos still use the `demo` realm. UI chat with
AuthBridge-protected agents will work once demos are migrated to the
`kagenti` realm (Phase 2 follow-up).

Signed-off-by: Mariusz Sabath <[email protected]>
Made-with: Cursor
Newer Keycloak versions (26.x) require email and profile fields for
the user account to be considered "fully set up". Without these fields,
direct access grants fail with "Account is not fully set up" and the
browser login flow may prompt for profile completion.

Also grants the realm-admin client role (from realm-management) to the
bootstrapped user so they can access the Keycloak admin console for the
kagenti realm without a "You do not have permission" error.

Signed-off-by: Mariusz Sabath <[email protected]>
Made-with: Cursor
mrsabath added 5 commits March 3, 2026 20:57
The Kagenti backend maps the Keycloak 'admin' realm role to
kagenti-admin (inheriting kagenti-operator) via a temporary mapping.
Without this role in the kagenti realm, users get 403 "Required
role(s): kagenti-operator" when using the UI.

Create the 'admin' realm role and assign it to the bootstrapped user
alongside the existing realm-admin client role.

Part of: #767

Signed-off-by: Mariusz Sabath <[email protected]>
Signed-off-by: Mariusz Sabath <[email protected]>
Made-with: Cursor
Address CI failure where user creation silently failed (caught as
non-fatal warning), causing downstream user_not_found login errors
in the E2E tests.

Changes:
- Make user creation exception fatal (raise instead of warning)
- Add post-creation verification that the bootstrap user exists
- Remove redundant change_current_realm() call (constructor already
  sets realm_name)

Addresses review feedback from @pdettori on PR #764.

Signed-off-by: Mariusz Sabath <[email protected]>
Made-with: Cursor
Remove unused imports (Optional, Any) and reformat string
concatenations to satisfy ruff-format and ruff-check hooks.

Made-with: Cursor
Signed-off-by: Mariusz Sabath <[email protected]>
Made-with: Cursor
The CI E2E tests were failing because the ui-oauth-secret job uses a
pre-built quay.io image that lacks the kagenti realm bootstrap logic
added in this PR. The user_not_found error in the kagenti realm caused
all Playwright login tests to fail.

- Add CI script to build the ui-oauth-secret image from source, load
  it into Kind, and restart the job after the Ansible installer
- Add the build step to both e2e-kind-pr and e2e-kind workflows
- Change imagePullPolicy to configurable (default IfNotPresent) so
  Kind uses the locally-loaded image instead of pulling from registry

Signed-off-by: Mariusz Sabath <[email protected]>
Made-with: Cursor
Extend the build script to handle OpenShift by creating a BuildConfig
with binary source, building the image inside the cluster, and
overriding the Helm values to use the internal registry image.

Previously, HyperShift E2E tests used the pre-built quay.io image
which lacked PR changes (realm bootstrap, user creation), causing
login failures in the kagenti realm.

Also adds the build step to both e2e-hypershift-pr.yaml and
e2e-hypershift.yaml workflows, placed after Deploy Kagenti and
before Pre-flight checks.

Signed-off-by: Mariusz Sabath <[email protected]>
Made-with: Cursor
@mrsabath
mrsabath force-pushed the feat/keycloak-kagenti-realm branch from 597f69f to 37486bb Compare March 4, 2026 02:02
@github-actions github-actions Bot removed the safe-to-test Maintainer reviewed - safe to run E2E tests label Mar 4, 2026
@github-actions

github-actions Bot commented Mar 4, 2026

Copy link
Copy Markdown

New Commits Detected

The safe-to-test label has been automatically removed because new commits were pushed.

New HEAD: 37486bb

For maintainers: Please review the new changes and comment /run-e2e to trigger E2E tests.

Security checklist

Before running E2E tests, verify the PR does NOT contain:

  • Changes to .github/workflows/ that bypass security
  • Changes to .github/scripts/ that could exfiltrate secrets
  • curl, wget, or nc commands to external URLs in scripts
  • Base64 encoding of environment variables
  • Printing secrets to logs (echo $SECRET)
  • Suspicious package installations

This is an automated security measure to prevent TOCTOU attacks

@mrsabath

mrsabath commented Mar 4, 2026

Copy link
Copy Markdown
Member Author

/run-e2e

@github-actions github-actions Bot added the safe-to-test Maintainer reviewed - safe to run E2E tests label Mar 4, 2026
@github-actions

github-actions Bot commented Mar 4, 2026

Copy link
Copy Markdown

E2E HyperShift Tests Started

Triggered by: @mrsabath
Commit: 37486bb5db95b682acc18b1ea48c77988c1bce19
Workflow Run: View logs

Tests are running on OpenShift 4.20.11. This typically takes 30-45 minutes.


To re-run tests after new commits, comment /run-e2e again.

@github-actions

github-actions Bot commented Mar 4, 2026

Copy link
Copy Markdown

E2E HyperShift Tests Passed

Commit: 37486bb5db95b682acc18b1ea48c77988c1bce19
Result: All tests passed
Workflow Run: View logs

The safe-to-test label indicates this commit has been approved for E2E testing.


If you push new commits, the label will be removed and you'll need to comment /run-e2e again.

@pdettori pdettori 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

@pdettori
pdettori merged commit 3e1c46d into rossoctl:main Mar 4, 2026
16 checks passed
@esnible esnible mentioned this pull request Mar 4, 2026
1 task
pdettori added a commit that referenced this pull request Mar 4, 2026
The values.yaml pointed to a test image (quay.io/pdettori/ui-oauth-secret)
built before PR #764 added realm bootstrap logic. This caused UI login
failures on Kind installs because no admin user was created in the kagenti
realm.

Switch to ghcr.io/kagenti/kagenti/ui-oauth-secret, consistent with
agent-oauth-secret and other images.

Closes #833

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
mrsabath added a commit to mrsabath/agent-examples that referenced this pull request Mar 6, 2026
The Kagenti platform migrated from the Keycloak "demo" realm to
"kagenti" (rossoctl/rossoctl#764). Update the ISSUER and JWKS_URL in
.env.authbridge to match, so UI-based tool imports use the correct
realm for token validation.

Part of: rossoctl/rossoctl#767

Signed-off-by: Mariusz Sabath <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for Review! safe-to-test Maintainer reviewed - safe to run E2E tests

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

feat: go-processor should support multiple JWKS URLs for inbound validation

2 participants