Skip to content

Filtering organization groups when managing or processing groups#30590

Merged
pedroigor merged 1 commit into
keycloak:mainfrom
pedroigor:issue-30589
Jun 28, 2024
Merged

Filtering organization groups when managing or processing groups#30590
pedroigor merged 1 commit into
keycloak:mainfrom
pedroigor:issue-30589

Conversation

@pedroigor

@pedroigor pedroigor commented Jun 19, 2024

Copy link
Copy Markdown
Contributor
  • Adds a type to groups to filter organization groups from group queries. The reason for using a type is to avoid a nullable column and potentially impact database indexes and also eventually leverage groups for purposes other than realm and organization
  • Adds filtering to the user cache layer to filter organization groups when returning the groups the user is a member
  • Organization groups are no longer shown in the Group and User UIs and this improves the UX
  • Organization groups are no longer added to tokens when using a group mapper
  • Listing organizations will not automatically fetch their groups because the attributes are removed from the representation
  • Deleting a realm will remove organization and groups using a query rather than iterate over groups/orgs as before
  • Adding a database index on ORG_DOMAIN for the ORG_ID. Queries run a lot faster when listing organizations. For instance, from Execution Time: 129.512 ms to Execution Time: 0.084 ms in a database with 100k organizations each one with 10 domains.

@keycloak-github-bot

Copy link
Copy Markdown

Unreported flaky test detected

If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.organization.exportimport.OrganizationExportTest#testExport

Keycloak CI - Base IT (3)

java.lang.AssertionError: expected:<201> but was:<404>
	at org.junit.Assert.fail(Assert.java:89)
	at org.junit.Assert.failNotEquals(Assert.java:835)
	at org.junit.Assert.assertEquals(Assert.java:647)
	at org.junit.Assert.assertEquals(Assert.java:633)
...
jakarta.ws.rs.NotFoundException: HTTP 404 Not Found
	at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.handleErrorStatus(ClientInvocation.java:242)
	at org.jboss.resteasy.client.jaxrs.internal.proxy.extractors.DefaultEntityExtractorFactory$3.extractEntity(DefaultEntityExtractorFactory.java:41)
	at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invokeSync(ClientInvoker.java:136)
	at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:103)
...

Report flaky test

@keycloak-github-bot keycloak-github-bot 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.

Unreported flaky test detected, please review

@keycloak-github-bot

Copy link
Copy Markdown

Unreported flaky test detected

If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.broker.KcSamlBrokerTest#testPostBrokerLoginFlowWithOTP_bruteForceEnabled

Keycloak CI - FIPS IT (strict)

java.lang.AssertionError: expected:<Invalid authenticator code.> but was:<null>
	at org.junit.Assert.fail(Assert.java:89)
	at org.junit.Assert.failNotEquals(Assert.java:835)
	at org.junit.Assert.assertEquals(Assert.java:120)
	at org.junit.Assert.assertEquals(Assert.java:146)
...

Report flaky test

@keycloak-github-bot keycloak-github-bot 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.

Unreported flaky test detected, please review

@pedroigor pedroigor force-pushed the issue-30589 branch 7 times, most recently from f7d3eda to 385945d Compare June 25, 2024 18:52
@pedroigor pedroigor marked this pull request as ready for review June 25, 2024 18:54
@pedroigor pedroigor requested review from a team as code owners June 25, 2024 18:54

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

@pedroigor Thank you for preparing the PR. I have few comments/questions, please see below.

Overall it seems good. Conceptually I'm not convinced about the fact that a Group and an Organization would share the same ID in the database to simulate @OneToOne relationship without explicitly defining it in the entity. I believe it could bring several issues and overall it's not very good practice.

There are several points in general why I believe so:

  • Data integrity: it violates the entity uniqueness.
  • Lack of referential integrity: FK constrains, cascading operations
  • ORM Tooling Limitations like annotations, without them the ORM cannot manage relationships correctly
  • Personally I find it more error prone and less readable

I am not saying we suffer from any of those, but IMO it'd be safer to discuss this matter in broader team to get an agreement that Keycloak wants to go this route.

Comment thread model/jpa/src/main/resources/META-INF/jpa-changelog-26.0.0.xml Outdated
Comment thread model/jpa/src/main/resources/META-INF/jpa-changelog-26.0.0.xml Outdated
Comment thread model/jpa/src/main/java/org/keycloak/models/jpa/JpaRealmProvider.java Outdated
Comment thread server-spi/src/main/java/org/keycloak/models/GroupProvider.java Outdated
Comment thread server-spi/src/main/java/org/keycloak/models/GroupProvider.java Outdated
@pedroigor

Copy link
Copy Markdown
Contributor Author

There are several points in general why I believe so:

  • Data integrity: it violates the entity uniqueness.

There is no data integrity violation because IDs for organizations and groups are still unique.

  • Lack of referential integrity: FK constrains, cascading operations

We already lack FKs and cascading in other places. I'm not changing that now. Please, consider we have already discussed this with others in the team.

  • ORM Tooling Limitations like annotations, without them the ORM cannot manage relationships correctly

We already have places where we don't use relationships like OneToMany or ManyToOne and I think for performance reasons. The previous code, for instance, was just using a column even though we had a one-to-one behind-the-scenes but with different IDs.

  • Personally I find it more error prone and less readable

I guess you are used to the same approach in other places where we don't have relationships defined explicitly. And I think that is fine.

I am not saying we suffer from any of those, but IMO it'd be safer to discuss this matter in broader team to get an agreement that Keycloak wants to go this route.

If we don't suffer from any of those, why we are discussing it :)

@pedroigor

Copy link
Copy Markdown
Contributor Author

@pedroigor pedroigor force-pushed the issue-30589 branch 6 times, most recently from 6269657 to afe2410 Compare June 27, 2024 12:36
@vramik vramik requested review from vramik and removed request for vramik June 27, 2024 12:43

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

I am leaving the decision about the IDs up to you.

@pedroigor

Copy link
Copy Markdown
Contributor Author

@vramik The decision has been taken since I opened the PR :) Please, consider it as OK from my side.

@pedroigor

Copy link
Copy Markdown
Contributor Author

I've changed the PR to not share the same ID anymore as I found another issue when migrating (also had to update group attributes table).

Closes keycloak#30589

Signed-off-by: Pedro Igor <pigor.craveiro@gmail.com>

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

@pedroigor I didn't have a chance to look at the latest changes of the PR. but I believe it goes to the right direction, approving now to unblock merging.

@pedroigor

Copy link
Copy Markdown
Contributor Author

Added #30919 as a follow-up.

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

Approving based on @vramik's review.
Not merging it yet in case you want someone else to review it.

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

Approving. I did not review very deeply. Relying on the review by @vramik . But the ideas behind the PRs look good to me per our discussion with @pedroigor

@pedroigor

Copy link
Copy Markdown
Contributor Author

@mposolda @vramik Tks.

@pedroigor pedroigor merged commit cc2ccc8 into keycloak:main Jun 28, 2024
@pedroigor pedroigor deleted the issue-30589 branch June 28, 2024 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants