Skip to content

bug: keycloak-admin-secret in agent namespaces uses stale credentials after RHBK operator upgrade #1337

Closed

Description

@rrbanda

Problem

After an upgrade, the keycloak-admin-secret in agent namespaces (team1, team2, etc.) may contain stale credentials (admin/admin) while the actual Keycloak admin is temp-admin with a randomly generated password. This causes the client-registration sidecar to fail with 401 errors when trying to register agents as OAuth clients in Keycloak.

Root cause

  • The Helm chart defaults keycloak.adminUsername: admin and keycloak.adminPassword: admin in charts/kagenti/values.yaml (lines 149-165)
  • The RHBK operator creates keycloak-initial-admin with temp-admin + random password (documented in .github/scripts/kagenti-operator/36-fix-keycloak-admin.sh)
  • The installer has logic to read keycloak-initial-admin and override the Helm values (main.yml lines 1918-1948), but this only works on a full installer run
  • Partial upgrades, manual helm upgrade, or GitOps deployments skip this credential sync
  • The keycloak-admin-secret is rendered by Helm with whatever values are in the release, creating a mismatch with the actual Keycloak admin credentials

Steps to reproduce

  1. Install Kagenti on OpenShift with RHBK operator managing Keycloak
  2. Perform a Helm upgrade without running the full Ansible installer (or with the credential override step failing silently)
  3. Deploy an agent -- the client-registration sidecar fails with 401 from Keycloak

Suggested fix

Option A (preferred): Change charts/kagenti/templates/agent-namespaces.yaml to NOT create keycloak-admin-secret with hardcoded values. Instead, use an init container or Job that reads keycloak-initial-admin from the Keycloak namespace at deploy time and syncs it to agent namespaces. The kagenti-agent-oauth-secret-job already has RBAC to read this secret -- extend it to also sync keycloak-admin-secret.

Option B: Make the installer's credential override step mandatory and fail-fast if it cannot read the source secret, rather than silently proceeding with defaults.

Option C: Remove hardcoded defaults from values.yaml entirely and require explicit credential configuration, failing early if not provided.

Workaround

Update the secret manually in each agent namespace:

KC_USER=$(oc get secret keycloak-initial-admin -n keycloak -o jsonpath='{.data.username}' | base64 -d)
KC_PASS=$(oc get secret keycloak-initial-admin -n keycloak -o jsonpath='{.data.password}' | base64 -d)

for ns in team1 team2; do
  oc create secret generic keycloak-admin-secret -n $ns \
    --from-literal=KEYCLOAK_ADMIN_USERNAME="$KC_USER" \
    --from-literal=KEYCLOAK_ADMIN_PASSWORD="$KC_PASS" \
    --dry-run=client -o yaml | oc apply -f -
done

Environment

  • Platform: OpenShift 4.20.14
  • Keycloak: RHBK operator-managed
  • Previous creds: admin/admin
  • Actual creds: temp-admin/<generated>

Activity

  1. moved this from New/ToDo to Backlog in Rossoctl Issue Prioritizationon Jul 6, 2026
  2. added a commit that references this issue on Jul 7, 2026
    b642c92
  3. added a commit that references this issue on Jul 9, 2026
    38747bf
  4. added this to the Release v0.7.0 milestone on Jul 13, 2026
  5. mrsabath commented on Jul 13, 2026

    @mrsabath
    Member

    Resolved — closing.

    The runtime bug (stale admin/admin in keycloak-admin-secret → 401 on client registration after an RHBK admin-password rotation/upgrade) is fixed in main. The chart no longer creates a hardcoded admin secret; instead credentials are read live at deploy time from the operator-managed keycloak-initial-admin — this is Option A from the report:

    • charts/kagenti/values.yaml defaults to keycloak.adminSecretName: keycloak-initial-admin (adminUsernameKey: username, adminPasswordKey: password).
    • charts/kagenti/templates/agent-oauth-secret-job.yaml reads that secret at deploy time (RBAC scoped to it) and provisions per-agent OAuth clients from the live credentials.
    • No hardcoded keycloak-admin-secret creation remains anywhere in the chart, so the credentials can't drift out of sync across upgrades.

    Remaining follow-up is docs/script cleanup only — removing the now-inaccurate keycloak-admin-secret section from docs/install.md and the orphaned --set keycloak.adminUsername/adminPassword flags (silently ignored — those chart values no longer exist) from scripts/ocp/setup-kagenti.sh. That's tracked in #2155 (approved) and can merge independently; it is not a blocker for this bug.

    Closing as fixed.

  6. added a commit that references this issue on Jul 15, 2026
    b3c717c
  7. moved this from In progress to Done in Rossoctl Issue Prioritizationon Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions