Skip to content
This repository was archived by the owner on Sep 9, 2026. It is now read-only.

NO-ISSUE: Enable Keycloak organizations - #464

Merged
openshift-merge-bot[bot] merged 1 commit into
osac-project:mainfrom
jhernand:enable_keycloak_organizations
Apr 29, 2026
Merged

openshift-merge-bot[bot] merged 1 commit into
osac-project:mainfrom
jhernand:enable_keycloak_organizations

Conversation

@jhernand

@jhernand jhernand commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Summary

This enables the Keycloak organizations feature and grants the
osac-controller service account the permissions it needs to manage
them.

The realm configuration is updated to set organizationsEnabled to
true, and the osac-controller service account is granted the
following roles from the realm-management client:

  • manage-realm - Manage the realm configuration, including organizations.
  • manage-users - Create, update and delete users.
  • view-realm - View the realm configuration.
  • view-users - View users.

The documentation and integration test tooling are updated accordingly.

Summary by CodeRabbit

  • Documentation

    • Updated Keycloak setup documentation across multiple deployment guides to reflect expanded service account authorization requirements for proper controller operation.
  • Configuration

    • Enabled Keycloak organizations functionality in the realm configuration.
    • Updated controller service account role mappings to include additional realm management and viewing permissions.

@openshift-ci-robot

Copy link
Copy Markdown

@jhernand: This pull request explicitly references no jira issue.

Details

In response to this:

Summary

This enables the Keycloak organizations feature and grants the
osac-controller service account the permissions it needs to manage
them.

The realm configuration is updated to set organizationsEnabled to
true, and the osac-controller service account role is changed from
manage-users to manage-realm so that the controller can create,
update and delete organizations. The documentation and integration test
tooling are updated accordingly.

This branch includes #463 and will need to be rebased once that is
merged.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci
openshift-ci Bot requested review from adriengentil and tzvatot April 28, 2026 18:56
@jhernand
jhernand requested review from CrystalChun and removed request for adriengentil and tzvatot April 28, 2026 18:57
@coderabbitai

coderabbitai Bot commented Apr 28, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b58317a4-bead-4ffb-ae87-aa33ad64834b

📥 Commits

Reviewing files that changed from the base of the PR and between 90c8c18 and e219099.

📒 Files selected for processing (5)
  • charts/README.md
  • charts/keycloak/README.md
  • charts/keycloak/files/realm.json
  • it/it_tool.go
  • manifests/README.md
✅ Files skipped from review due to trivial changes (2)
  • manifests/README.md
  • charts/README.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • charts/keycloak/files/realm.json
  • it/it_tool.go

Walkthrough

This PR updates Keycloak configuration to expand the role requirements for the osac-controller service account from a single realm-management: manage-users role to four roles: manage-realm, manage-users, view-realm, and view-users. The changes are reflected in documentation files, Keycloak realm configuration, and test integration code. Additionally, the realm configuration file enables Keycloak organizations functionality.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • fulfillment-service#463: Adds initial realm-management: manage-users role assignment for osac-controller, while this PR expands the role set to include manage-realm, view-realm, and view-users.
  • fulfillment-service#462: Modifies Keycloak service-account and client setup for osac-controller including realm.json and role assignments, sharing similar scope with this PR.

Suggested labels

lgtm

Suggested reviewers

  • CrystalChun
  • trewest
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'NO-ISSUE: Enable Keycloak organizations' is partially related to the changeset; it highlights enabling Keycloak organizations (realm.json change) but omits the primary documentation updates about the osac-controller service account role expansion.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
charts/keycloak/templates/_start.tpl (1)

87-107: Consider validating required credentials before writing the config.

If neither the URL contains credentials nor the user/password files exist, db_user and db_password will be empty. Keycloak will fail at runtime with potentially unclear database authentication errors.

🔧 Optional: Add validation for required credentials
+# Validate required credentials:
+if [[ -z "${db_user}" ]]; then
+  echo "Database user is not set (provide 'user' file or include in URL)"
+  exit 1
+fi
+if [[ -z "${db_password}" ]]; then
+  echo "Database password is not set (provide 'password' file or include in URL)"
+  exit 1
+fi
+
 # Write the Keycloak configuration file:
 conf_file="/opt/keycloak/conf/keycloak.conf"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@charts/keycloak/templates/_start.tpl` around lines 87 - 107, The startup
script writes keycloak.conf using db_url, db_user and db_password but does not
validate credentials; add a validation step before creating conf_file (check
db_url for embedded credentials or that db_user and db_password are non-empty /
the files providing them exist) and if missing emit a clear error and exit
non-zero instead of writing an incomplete config; modify the segment around
conf_file, db_url, db_user, db_password and the exec /opt/keycloak/bin/kc.sh
start --import-realm call to perform this check and fail-fast with a helpful
message.
it/it_tool.go (1)

942-947: Conditionally emit clientRoles only when role mappings exist.

In Keycloak's UserRepresentation model, clientRoles is defined as Map<String, List<String>> and should be omitted (not null) when empty. Line 946 always includes this field; provide it only when data.ClientRoles is non-empty.

Suggested patch
-		users = append(
-			users, map[string]any{
-				"username":               fmt.Sprintf("service-account-%s", data.ClientId),
-				"enabled":                true,
-				"serviceAccountClientId": data.ClientId,
-				"clientRoles":            data.ClientRoles,
-			},
-		)
+		user := map[string]any{
+			"username":               fmt.Sprintf("service-account-%s", data.ClientId),
+			"enabled":                true,
+			"serviceAccountClientId": data.ClientId,
+		}
+		if len(data.ClientRoles) > 0 {
+			user["clientRoles"] = data.ClientRoles
+		}
+		users = append(users, user)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@it/it_tool.go` around lines 942 - 947, The map literal passed into users
always includes "clientRoles" even when empty; change this to build the
attributes map first (e.g., attrs := map[string]any{ "username":
fmt.Sprintf("service-account-%s", data.ClientId), "enabled": true,
"serviceAccountClientId": data.ClientId }) and then only set
attrs["clientRoles"] = data.ClientRoles when data.ClientRoles is non-nil and has
length > 0 (len(data.ClientRoles) > 0). Finally pass attrs to users instead of
the inline literal so "clientRoles" is omitted when empty.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@charts/keycloak/templates/_start.tpl`:
- Around line 87-107: The startup script writes keycloak.conf using db_url,
db_user and db_password but does not validate credentials; add a validation step
before creating conf_file (check db_url for embedded credentials or that db_user
and db_password are non-empty / the files providing them exist) and if missing
emit a clear error and exit non-zero instead of writing an incomplete config;
modify the segment around conf_file, db_url, db_user, db_password and the exec
/opt/keycloak/bin/kc.sh start --import-realm call to perform this check and
fail-fast with a helpful message.

In `@it/it_tool.go`:
- Around line 942-947: The map literal passed into users always includes
"clientRoles" even when empty; change this to build the attributes map first
(e.g., attrs := map[string]any{ "username": fmt.Sprintf("service-account-%s",
data.ClientId), "enabled": true, "serviceAccountClientId": data.ClientId }) and
then only set attrs["clientRoles"] = data.ClientRoles when data.ClientRoles is
non-nil and has length > 0 (len(data.ClientRoles) > 0). Finally pass attrs to
users instead of the inline literal so "clientRoles" is omitted when empty.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ab64f358-7122-43ae-8b0e-41e2e2cd5e5b

📥 Commits

Reviewing files that changed from the base of the PR and between 61fa7a3 and 90c8c18.

📒 Files selected for processing (7)
  • charts/README.md
  • charts/keycloak/README.md
  • charts/keycloak/files/realm.json
  • charts/keycloak/templates/_start.tpl
  • charts/keycloak/templates/deployment.yaml
  • it/it_tool.go
  • manifests/README.md

Comment thread it/it_tool.go
This enables the Keycloak organizations feature in the realm
configuration and grants the `osac-controller` service account the
roles it needs to manage the realm, users and organizations. The
roles assigned from the `realm-management` client are:

- `manage-realm` - Manage the realm configuration, including
  organizations.
- `manage-users` - Create, update and delete users.
- `view-realm` - View the realm configuration.
- `view-users` - View users.

The documentation and integration test tooling are updated
accordingly.

Signed-off-by: Juan Hernandez <juan.hernandez@redhat.com>
@jhernand
jhernand force-pushed the enable_keycloak_organizations branch from 90c8c18 to e219099 Compare April 29, 2026 08:33

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

/lgtm

@openshift-ci

openshift-ci Bot commented Apr 29, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: CrystalChun, jhernand

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot
openshift-merge-bot Bot merged commit 850659c into osac-project:main Apr 29, 2026
12 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants