-
-
Notifications
You must be signed in to change notification settings - Fork 15
Migrate syncer user to cryptomatorhub-system client #336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThe changes introduce a new Java class, Suggested reviewers
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
backend/src/main/java/org/cryptomator/hub/KeycloakProducer.java(1 hunks)backend/src/main/java/org/cryptomator/hub/KeycloakRemoteUserProvider.java(5 hunks)backend/src/main/java/org/cryptomator/hub/api/VersionResource.java(1 hunks)backend/src/main/resources/application.properties(1 hunks)backend/src/main/resources/dev-realm.json(2 hunks)backend/src/test/java/org/cryptomator/hub/KeycloakRemoteUserProviderTest.java(3 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
backend/src/main/java/org/cryptomator/hub/KeycloakProducer.java (1)
backend/src/main/java/org/cryptomator/hub/KeycloakRemoteUserProvider.java (1)
ApplicationScoped(21-128)
🔇 Additional comments (15)
backend/src/test/java/org/cryptomator/hub/KeycloakRemoteUserProviderTest.java (3)
66-66: Tests updated to align with syncer client migration.The test now correctly reflects the removal of the syncer user from the user list, aligning with the migration from a syncer user to a service account client pattern.
89-89: Tests consistently updated to remove syncer user.Test case properly updated to maintain consistency with the first test case, ensuring the syncer user is no longer included in the test data.
152-152: Group membership tests correctly updated.Group membership test data has been properly updated to reflect the removal of the syncer user, consistent with the architectural changes in the PR.
backend/src/main/java/org/cryptomator/hub/api/VersionResource.java (2)
21-21: Dependency updated to use direct Keycloak injection.Clean replacement of the SyncerConfig dependency with a directly injected Keycloak instance, simplifying the class dependencies.
28-29: Simplified Keycloak version retrieval.The code has been refactored to directly use the injected Keycloak instance, removing the need for try-with-resources and simplifying the method implementation.
backend/src/main/java/org/cryptomator/hub/KeycloakProducer.java (4)
1-12: Well-structured new producer class for Keycloak.Clean implementation of a producer class using CDI for managing Keycloak instances. The class is properly scoped as ApplicationScoped, which is appropriate for this use case.
14-24: Properly configured injection of client credential properties.Configuration properties are correctly set up to inject the client ID, client secret, URL, and realm from application properties, supporting the migration to client credentials authentication.
26-36: Effective implementation of Keycloak instance production.The producer method correctly builds and configures a Keycloak instance using the KeycloakBuilder with proper client credentials configuration. The method is appropriately annotated with @produces and @ApplicationScoped.
38-40: Proper resource cleanup with @Disposes.Excellent implementation of resource cleanup with the @Disposes method to ensure the Keycloak instance is properly closed when it's no longer needed, preventing resource leaks.
backend/src/main/resources/application.properties (2)
41-42: Client credentials properly configured for development environment.Configuration has been properly updated to use the new client ID "cryptomatorhub-syncer" and client secret "top-secret" for the development environment.
Ensure the client secret "top-secret" is replaced with a secure value in production. This appears to be a development placeholder.
44-45: Test environment configuration consistent with development.Test environment configuration correctly mirrors the development settings for client ID and secret, maintaining consistency across environments.
backend/src/main/resources/dev-realm.json (1)
127-127: Migration to service account is a good security improvementConverting the syncer from a regular user to a service account with client credentials flow is a significant security improvement. This follows OAuth best practices for service-to-service authentication and aligns with the existing pattern used for the CLI client.
Also applies to: 232-241
backend/src/main/java/org/cryptomator/hub/KeycloakRemoteUserProvider.java (3)
28-31: Improve dependency management with direct Keycloak injectionThe direct injection of Keycloak and use of ConfigProperty for the realm name improves the code structure by:
- Leveraging dependency injection rather than manual creation
- Making the code more testable
- Centralizing Keycloak instance management
This change aligns well with dependency injection best practices.
35-35: Code is now simpler and more maintainableThe simplified method calls using the injected Keycloak instance and realm name make the code more concise and easier to maintain.
Also applies to: 85-85
44-44:Details
✅ Verification successful
Removal of user filtering is consistent with service account approach
The removal of code that filtered out the "syncer" user is appropriate now that it's a service account. This simplifies the code and represents the architectural change correctly.
However, verify that any code that processes these user lists doesn't have assumptions about syncers being filtered out.
Also applies to: 126-126
🏁 Script executed:
#!/bin/bash # Check if there are other parts of the codebase that might expect syncers to be filtered echo "Searching for references to syncer filtering in the codebase..." rg -i "synceruser|syncerconfig|filtersync|syncerfilter" --type javaLength of output: 426
Syncer filtering removal verified – no downstream assumptions detected
The removal of the user filtering logic for the "syncer" account is consistent with the new service account approach. Our search only revealed references to
SyncerConfigin a test (KeycloakRemoteUserProviderTest.java) and inSyncerConfig.java, with no additional filtering logic. There don’t appear to be any downstream assumptions about syncers being filtered out in the production code.
- Production Code: The removal at lines 44 and 126 in
KeycloakRemoteUserProvider.javaaligns with the updated architectural strategy.- Test Code: Although the test file instantiates a
SyncerConfig, it doesn’t enforce any syncer filtering behavior.- Overall Impact: No further modifications are required, but remain cautious if other parts modify or depend on the syncer configuration.
|
In-depth review will take a while, but what comes to mind immediately is the fact that the client will no longer "just sync" but be in charge of everything that hub needs to do in keycloak. Hence I would drop the name "syncer" for good. |
|
You are right, I wanted to keep the diff as small as possible and also what the admin needs to do, but as we are doing a partial import we can also introduce a new composite role and ask the admin to remove the syncer role...will think of a better name. |
|
How about just "hub"? After all this is the piece of software that is communicating with kc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (4)
backend/src/main/java/org/cryptomator/hub/KeycloakProducer.java (2)
17-18: Consider securing the client secretWhile the implementation is correct, consider adding additional safeguards for the client secret such as validating it's not empty at runtime.
@ConfigProperty(name = "hub.keycloak.client-secret") String clientSecret; + public void validateConfig() { + if (clientSecret == null || clientSecret.trim().isEmpty()) { + throw new IllegalStateException("hub.keycloak.client-secret must be configured"); + } + }
38-40: Add exception handling to disposeKeycloak methodThe
close()method might throw an exception. Consider adding try-catch to ensure proper resource cleanup.public void disposeKeycloak(@Disposes Keycloak keycloak) { - keycloak.close(); + try { + keycloak.close(); + } catch (Exception e) { + // Log the exception but don't rethrow to ensure cleanup continues + System.err.println("Error closing Keycloak client: " + e.getMessage()); + } }backend/src/main/resources/application.properties (2)
41-42: Use more descriptive client_id valueAccording to the PR objectives, the client ID should be "cryptomatorhub-syncer" to be more descriptive about its purpose. Consider updating the value to match the PR objectives.
-%dev.hub.keycloak.client-id=hub +%dev.hub.keycloak.client-id=cryptomatorhub-syncer
42-42: Use placeholder for client secret in development configWhile "top-secret" works for local development, consider using a placeholder that clearly indicates this should be replaced in production.
-%dev.hub.keycloak.client-secret=top-secret +%dev.hub.keycloak.client-secret=change-me-in-production
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
backend/src/main/java/org/cryptomator/hub/KeycloakProducer.java(1 hunks)backend/src/main/java/org/cryptomator/hub/SyncerConfig.java(0 hunks)backend/src/main/resources/application.properties(1 hunks)backend/src/main/resources/dev-realm.json(2 hunks)backend/src/test/java/org/cryptomator/hub/KeycloakRemoteUserProviderTest.java(3 hunks)
💤 Files with no reviewable changes (1)
- backend/src/main/java/org/cryptomator/hub/SyncerConfig.java
🚧 Files skipped from review as they are similar to previous changes (2)
- backend/src/main/resources/dev-realm.json
- backend/src/test/java/org/cryptomator/hub/KeycloakRemoteUserProviderTest.java
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Run Tests
🔇 Additional comments (2)
backend/src/main/java/org/cryptomator/hub/KeycloakProducer.java (1)
11-40: Well-designed Keycloak producer classThis class implements the client credentials flow for Keycloak authentication, which aligns with the PR objective of migrating from syncer user to client-based authentication. The implementation follows CDI best practices with proper
@Producesand@Disposesannotations.backend/src/main/resources/application.properties (1)
41-44:Details
❓ Verification inconclusive
Client credentials configuration added correctly
The configuration properties have been updated to use client ID and client secret instead of username/password, which matches the PR objectives. The development values are suitable for testing purposes.
Run the following script to confirm that the removed syncer-username and syncer-password properties are no longer used:
🏁 Script executed:
#!/bin/bash # Search for any remaining references to removed configuration properties echo "Checking for any remaining references to syncer-username and syncer-password" rg "syncer-username|syncer-password" --type javaLength of output: 213
Configuration Update Verified – Manual Verification Requested
The client credentials configuration now properly uses the client ID and client secret as intended by the PR. The shell script targeting Java files did not return any references to the removed
syncer-usernameandsyncer-passwordproperties. However, because the search was limited to Java files and produced no output (beyond the header), please manually verify that these removed properties are not referenced elsewhere in the codebase (for example, in configuration files such as properties or YAML).
- Confirm that a global search (without file-type restrictions) yields no instances of
syncer-usernameorsyncer-password.
For future changes where we use this client to create users/groups but also partial import realm for changes like in this PR, this is required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
backend/src/main/java/org/cryptomator/hub/KeycloakProducer.java(1 hunks)backend/src/main/resources/application.properties(1 hunks)backend/src/main/resources/dev-realm.json(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- backend/src/main/resources/dev-realm.json
🧰 Additional context used
🧬 Code Definitions (1)
backend/src/main/java/org/cryptomator/hub/KeycloakProducer.java (1)
backend/src/main/java/org/cryptomator/hub/KeycloakRemoteUserProvider.java (1)
ApplicationScoped(21-128)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Run Tests
🔇 Additional comments (4)
backend/src/main/java/org/cryptomator/hub/KeycloakProducer.java (4)
1-12: New class design follows CDI best practicesThis newly added
KeycloakProducerclass is well-structured with the appropriate@ApplicationScopedannotation, making it a singleton within the application context. This follows CDI best practices for centralized resource management.
14-24: Configuration properties correctly definedThe configuration properties are properly defined with descriptive names, and they align with the changes in the application.properties file. The naming convention clearly indicates their purpose, with "system-client-id" and "system-client-secret" replacing the previous syncer username/password approach.
26-36: Secure Keycloak instance creation with client credentialsThe
produceKeycloak()method correctly uses the builder pattern to create a Keycloak instance. The switch toCLIENT_CREDENTIALSgrant type is a more secure approach than the previous username/password authentication, as it follows OAuth 2.0 best practices for service-to-service authentication.
38-40: Proper resource cleanupThe
disposeKeycloak()method correctly uses the@Disposesannotation to ensure the Keycloak instance is properly closed when it's no longer needed, preventing resource leaks.
overheadhunter
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now that KC supports longer attributes (at least for users - not for groups), we may include base64-encoded images.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
♻️ Duplicate comments (1)
backend/src/main/resources/dev-realm.json (1)
225-234:⚠️ Potential issueUpdate the Client Secret for "cryptomatorhub-system"
The new client configuration uses a hardcoded secret value
"top-secret", which is insecure even for development environments and may unintentionally serve as a template for production. It is recommended to replace this with a secure, environment-specific placeholder (for example,"${GENERATED_SECRET}") or to ensure that a secure secret is injected via configuration.Proposed diff:
- "secret": "top-secret", + "secret": "${GENERATED_SECRET}",
🧹 Nitpick comments (1)
backend/src/main/resources/dev-realm.json (1)
111-121: Review the Service Account User "system" Setup and PrivilegesThe new "system" user configuration is set up to operate as a service account using the
"serviceAccountClientId"field, which is correctly linked to the new client. The inline base64-encoded SVG for thepictureattribute is a good way to avoid external dependencies and potential XSS risks. Please verify that omitting fields like"firstName"and"lastName"is intentional for a service account. Additionally, ensure that granting the"realm-admin"role via"clientRoles"aligns with your intended security model since it confers broad privileges.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
backend/src/main/resources/dev-realm.json(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Run Tests
Update Flow for existing deployments:
In Keycloak
secretinpartial-realm-import.jsonto a secure valuepartial-realm-import.jsonrealmsynceruser andsyncerroleIn the deployment
HUB_KEYCLOAK_SYNCER_USERNAME,HUB_KEYCLOAK_SYNCER_PASSWORDandHUB_KEYCLOAK_SYNCER_CLIENT_IDHUB_KEYCLOAK_SYSTEM_CLIENT_IDwith valuecryptomatorhub-systemHUB_KEYCLOAK_SYSTEM_CLIENT_SECRETwith thesecretvalue of yourpartial-realm-import.json