Skip to content

Harmonize Keycloak Client Configurations with Built-in IdP#589

Merged
micbar merged 5 commits intoopencloud-eu:mainfrom
michaelstingl:harmonize-keycloak-client-configs
Apr 7, 2025
Merged

Harmonize Keycloak Client Configurations with Built-in IdP#589
micbar merged 5 commits intoopencloud-eu:mainfrom
michaelstingl:harmonize-keycloak-client-configs

Conversation

@michaelstingl
Copy link
Copy Markdown
Contributor

@michaelstingl michaelstingl commented Apr 6, 2025

Description

This PR harmonizes the Keycloak client configurations with the built-in IdP client configurations to ensure a consistent authentication experience regardless of which identity provider is used.

Related Issue

Motivation and Context

When switching between the built-in IdP and Keycloak, users may experience authentication issues due to inconsistent client configurations. This PR ensures that client IDs, redirect URIs, domain names, and authentication methods are aligned between both systems.

Key changes:

  1. Standardized client IDs to match built-in IdP:

    • web (unchanged)
    • OpenCloudDesktop (was random ID)
    • OpenCloudAndroid (was random ID)
    • OpenCloudIOS (was random ID)
    • Cyberduck (simplified ID)
  2. Fixed domain names:

    • Changed mobile app URLs from opencloud.com to opencloud.eu
    • Replaced hardcoded domains with template variables
  3. Standardized redirect URIs:

    • Added specific callback paths for web client
    • Used consistent formats for desktop client
  4. Aligned authentication methods:

    • Set mobile and desktop clients as public clients (equivalent to native app type)

How Has This Been Tested?

  • Test environment: Local Docker Compose setup with Keycloak enabled
  • Test case 1: Login with web client using templated URLs
  • Test case 2: Verified client configuration in Keycloak admin console
  • Test case 3: Tested template variable replacement in docker-entrypoint-override.sh

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation added

Note on documentation: The Keycloak documentation file at /docs/docs/admin/30-configuration/30-keycloak.md exists in the separate docs repository as a draft. After this PR is merged, a separate PR should be created in the docs repository to update the documentation with the new client configuration details.

Detailed Analysis

1. Client ID Differences

Client Type Built-in IdP ID Keycloak ID
Web web web
Desktop OpenCloudDesktop xdXOt13JKxym1B1QcEncf2XDkLAexMBFwiT9j6EfhhHFJhs2KM9jbjTmf8JBXE69
Android OpenCloudAndroid e4rAsNUSIUs0lF4nbv9FmCeUkTlV9GdgTLDH1b5uie7syb90SzEVrbN7HIpmWJeD
iOS OpenCloudIOS mxd5OQDk6es5LzOzRvidJNfXLUZS2oN3oUFeXPP8LpPrhx3UroJFduGEYIBOxkY1

2. Domain Name Inconsistencies

Client Type Built-in IdP Domain Keycloak Domain
Web {{OC_URL}} (templated) https://cloud.opencloud.test (hardcoded) ❌
Android oc://android.opencloud.eu oc://android.opencloud.com
iOS oc://ios.opencloud.eu oc://ios.opencloud.com

3. Redirect URI Format Differences

Client Type Built-in IdP Format Keycloak Format
Web Template with specific paths Single wildcard path ❌
Desktop Fixed ports Wildcard ports ❌

4. Client Authentication Type

Client Type Built-in IdP Keycloak
Web Trusted: true publicClient: true (equivalent) ✅
Desktop ApplicationType: native Uses client secret ❌
Android ApplicationType: native Uses client secret ❌
iOS ApplicationType: native Uses client secret ❌

This change makes the Keycloak client configurations consistent with the built-in IdP:

1. Standardized client IDs to match built-in IdP:
   - web (unchanged)
   - OpenCloudDesktop (was random ID)
   - OpenCloudAndroid (was random ID)
   - OpenCloudIOS (was random ID)
   - Cyberduck (simplified ID)

2. Updated domain names to use .eu consistently:
   - Changed from opencloud.com to opencloud.eu for mobile apps
   - Changed from hardcoded domains to templated {{OC_URL}} values

3. Updated redirect URIs to match built-in IdP format:
   - Added specific callback paths for web client
   - Removed wildcarded ports for desktop client

4. Changed mobile/desktop clients to public clients (equivalent to native app type)

5. Enhanced docker-entrypoint-override.sh to handle {{OC_URL}} template variables

These changes ensure a consistent authentication experience regardless of
whether users are using the built-in IdP or Keycloak.
michaelstingl added a commit to michaelstingl/opencloud-eu-docs that referenced this pull request Apr 6, 2025
This adds detailed documentation for Keycloak integration with OpenCloud, including:
- Setup with Docker Compose
- OpenCloud configuration
- Client configuration details (matching built-in IdP)
- Advanced configuration (Backchannel Logout)
- Troubleshooting advice
- User and group management overview

Relates to opencloud-eu/opencloud#589
@micbar micbar added the Type:DevOps Related to CI/CD label Apr 6, 2025
@micbar
Copy link
Copy Markdown
Member

micbar commented Apr 6, 2025

@michaelstingl Thanks! I tested your changes - the clients are working fine! 👏

One issue is, that the deployment only imports the full realm, so we need to also change the client values in the realm itself.

@michaelstingl michaelstingl force-pushed the harmonize-keycloak-client-configs branch from f1c73ad to e487dfd Compare April 7, 2025 12:59
@michaelstingl
Copy link
Copy Markdown
Contributor Author

Thanks for the feedback! I've updated the opencloud-realm.dist.json file to synchronize all client IDs, redirect URIs, post-logout URIs, and other settings with the values in the individual client JSON files.

Since the realm configuration file is quite complex, please let me know if I missed anything else that needs to be aligned. This should ensure that when the realm is imported during deployment, all client configurations match exactly.

Update the realm configuration to match the client configuration JSON files:

1. Update client IDs to match client JSON files:
   - Changed 'xdXOt13JKxym1B1QcEncf2XDkLAexMBFwiT9j6EfhhHFJhs2KM9jbjTmf8JBXE69' to 'OpenCloudDesktop'
   - Changed 'e4rAsNUSIUs0lF4nbv9FmCeUkTlV9GdgTLDH1b5uie7syb90SzEVrbN7HIpmWJeD' to 'OpenCloudAndroid'
   - Changed 'mxd5OQDk6es5LzOzRvidJNfXLUZS2oN3oUFeXPP8LpPrhx3UroJFduGEYIBOxkY1' to 'OpenCloudIOS'

2. Fix additional client properties:
   - Fix client names: Use proper capitalization for all clients
   - Fix OAuth redirect URIs for Android and iOS to use .eu domain
   - Fix Desktop URIs by removing wildcard asterisks
   - Update post-logout redirect URIs to match client JSONs
   - Set publicClient flag to true for all mobile/desktop clients

These changes ensure that when the realm is imported during deployment,
the client configurations will match the client JSONs exactly.
@michaelstingl michaelstingl force-pushed the harmonize-keycloak-client-configs branch from e487dfd to 8bbd562 Compare April 7, 2025 13:21
Harmonize the web client configuration in the realm:
- Add 'OpenCloud Web App' client name
- Change URLs to use {{OC_URL}} template variables
- Update redirect URIs to use specific paths instead of wildcard
- Set backchannel logout URL to use templated URL

This completes the harmonization of all client configurations in the realm.
@michaelstingl
Copy link
Copy Markdown
Contributor Author

I noticed one more issue while testing and fixed it in another commit:

The web client configuration also needed harmonization. I updated it to:

  • Add the proper client name ("OpenCloud Web App")
  • Use {{OC_URL}} template variables instead of hardcoded URLs
  • Update redirect URIs to match exact paths instead of wildcard
  • Update backchannel logout URL to use the template

These changes should complete the harmonization of all clients in the realm configuration.

Copy link
Copy Markdown
Member

@micbar micbar left a comment

Choose a reason for hiding this comment

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

Working fine. I am not so happy with the new OC_URL placeholder.

# replace openCloud domain in keycloak realm import
mkdir /opt/keycloak/data/import
sed -e "s/cloud.opencloud.test/${OC_DOMAIN}/g" /opt/keycloak/data/import-dist/opencloud-realm.json > /opt/keycloak/data/import/opencloud-realm.json
sed -e "s/cloud.opencloud.test/${OC_DOMAIN}/g" \
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.

What is the gain of that change?
Before your change, it was already a valid config, because cloud.opencloud.test is used on all testing and developer machines.
${OC_DOMAIN} is not always populated if you do not run the entrypoint script.

So i would like to keep it like it was.

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.

Also the introduction of {{OC_URL}} makes updating the config harder. Before, we could just commit the export generated by keycloak (kc.sh export)

Reverted templating changes to match upstream conventions:

1. Removed template variable handling from docker-entrypoint-override.sh
   - Removed {{OC_URL}} replacement, keeping only domain replacement

This maintains compatibility with the upstream approach of using direct URLs
with domain substitution instead of template variables.
@michaelstingl
Copy link
Copy Markdown
Contributor Author

Thanks for the feedback about the template variables! I've reverted those changes to match the upstream conventions.

I initially added the {{OC_URL}} variables because I noticed they're used in the built-in IdP configuration (in services/idp/pkg/config/defaults/defaultconfig.go) and wanted to make the Keycloak configuration consistent with that pattern. However, I understand now that the Keycloak configuration should follow its own established convention with direct URLs and domain substitution.

I've:

  1. Changed web client URLs back to direct format (https://cloud.opencloud.test)
  2. Reverted docker-entrypoint-override.sh to only handle direct domain replacement

The important client ID harmonization and redirect URI updates remain in place. Let me know if there's anything else that should be adjusted!

Copy link
Copy Markdown
Member

@micbar micbar left a comment

Choose a reason for hiding this comment

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

Thank you! 🙏

@suse-coder
Copy link
Copy Markdown

There are still old references like e4rAsNUSIUs0lF4nbv9FmCeUkTlV9GdgTLDH1b5uie7syb90SzEVrbN7HIpmWJeD in the new /keycloak/opencloud-realm.dist.json

Updated the remaining references to old client IDs in the role mappings section:
- xdXOt13JKxym1B1QcEncf2XDkLAexMBFwiT9j6EfhhHFJhs2KM9jbjTmf8JBXE69 → OpenCloudDesktop
- e4rAsNUSIUs0lF4nbv9FmCeUkTlV9GdgTLDH1b5uie7syb90SzEVrbN7HIpmWJeD → OpenCloudAndroid
- mxd5OQDk6es5LzOzRvidJNfXLUZS2oN3oUFeXPP8LpPrhx3UroJFduGEYIBOxkY1 → OpenCloudIOS

This ensures all client ID references throughout the realm configuration are
consistent and use the simplified IDs.
@michaelstingl
Copy link
Copy Markdown
Contributor Author

Thanks @suse-coder for catching those remaining old client IDs! I've fixed all the references in the role mappings section of the configuration, replacing the long random IDs with the simplified client names.

This should complete the harmonization of client IDs throughout the entire realm configuration.

@micbar micbar merged commit d2d33e4 into opencloud-eu:main Apr 7, 2025
1 check passed
@michaelstingl michaelstingl deleted the harmonize-keycloak-client-configs branch April 7, 2025 16:48
michaelstingl added a commit to michaelstingl/opencloud-eu-docs that referenced this pull request Apr 9, 2025
This adds detailed documentation for Keycloak integration with OpenCloud, including:
- Setup with Docker Compose
- OpenCloud configuration
- Client configuration details (matching built-in IdP)
- Advanced configuration (Backchannel Logout)
- Troubleshooting advice
- User and group management overview

Relates to opencloud-eu/opencloud#589
micbar pushed a commit to opencloud-eu/docs that referenced this pull request Apr 9, 2025
* Add comprehensive Keycloak integration documentation

This adds detailed documentation for Keycloak integration with OpenCloud, including:
- Setup with Docker Compose
- OpenCloud configuration
- Client configuration details (matching built-in IdP)
- Advanced configuration (Backchannel Logout)
- Troubleshooting advice
- User and group management overview

Relates to opencloud-eu/opencloud#589

* Simplify docker-compose command and explain .env file auto-configuration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type:DevOps Related to CI/CD

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Harmonize Keycloak Client Configurations with Built-in IdP

4 participants