Skip to content
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

OIDC: Encapsulate static/dynamic tenants maps in TenantConfigBean #43007

Closed
wants to merge 1 commit into from

Conversation

snazy
Copy link
Contributor

@snazy snazy commented Sep 4, 2024

Lets TenantConfigBean be the sole "owner" of the static/dynamic tenants maps, adds/changes accessor methods for tenants. Also introduces a functional interface to create tenants.

No functional change, only moving code around.

Also some minor code cleanups (reducing the amount of warnings in IntelliJ).

@quarkus-bot quarkus-bot bot added the area/oidc label Sep 4, 2024
Copy link

quarkus-bot bot commented Sep 4, 2024

Thanks for your pull request!

Your pull request does not follow our editorial rules. Could you have a look?

  • description should not be empty, describe your intent or provide links to the issues this PR is fixing (using Fixes #NNNNN) or changelogs

This message is automatically generated by a bot.

This comment has been minimized.

Copy link

github-actions bot commented Sep 4, 2024

🎊 PR Preview 47db797 has been successfully built and deployed to https://quarkus-pr-main-43007-preview.surge.sh/version/main/guides/

  • Images of blog posts older than 3 months are not available.
  • Newsletters older than 3 months are not available.

@sberyozkin
Copy link
Member

@snazy Thanks, can you fix the formatting please, I'll have a look tomorrow once I finish another PR

@snazy snazy force-pushed the oidc-refactor-for-context-limit branch from 0a6ab3c to 3178a45 Compare September 4, 2024 19:09
@snazy
Copy link
Contributor Author

snazy commented Sep 4, 2024

@snazy Thanks, can you fix the formatting please, I'll have a look tomorrow once I finish another PR

Sure, fixed

This comment has been minimized.

This comment has been minimized.

@sberyozkin
Copy link
Member

@snazy Thanks, it all looks good, refactoring makes sense and makes things a bit clearer. Michal, myself, added minor comments, but something did not work out during the initial refactoring, tests are impacted

@snazy snazy force-pushed the oidc-refactor-for-context-limit branch from 3178a45 to 6654e34 Compare September 5, 2024 12:56
@snazy
Copy link
Contributor Author

snazy commented Sep 5, 2024

The issue that's fixed now is that TenantConfigContexts for static tenants with a null provider were "leaked", causing the NPEs. Also updated the code to make things a bit clearer/leaner.

This comment has been minimized.

This comment has been minimized.

@snazy
Copy link
Contributor Author

snazy commented Sep 5, 2024

Um - let me look into those new test failures

@snazy snazy force-pushed the oidc-refactor-for-context-limit branch from 6654e34 to d0419b4 Compare September 5, 2024 15:31
@snazy
Copy link
Contributor Author

snazy commented Sep 5, 2024

Hm - the tests in those projects don't fail locally

This comment has been minimized.

This comment has been minimized.

@michalvavrik
Copy link
Member

Hm - the tests in those projects don't fail locally

Did you declare you have Linux containers available locally with -Dtest-containers -Dstart-containers appended to your mvn clean ....?

@snazy
Copy link
Contributor Author

snazy commented Sep 5, 2024

Hm - the tests in those projects don't fail locally

Did you declare you have Linux containers available locally with -Dtest-containers -Dstart-containers appended to your mvn clean ....?

Yup - just found those params in the GH workflow

@sberyozkin
Copy link
Member

sberyozkin commented Sep 5, 2024

@snazy One thing I know is that even a single line update can have an impact there, a lot is going on with the tenant resolution, and this is why, having a bit of clean up and adding extra clarity would not be bad at all. It will help going forward, thanks for working on this PR.
But I wonder, would it make sense to do a series of really small PRs for us to have a better control of these changes ?
For example:

  • PR1: get static tenants created at the first request time recorded in the static map
  • PR2: Consolidate the code which is really belonging to the tenant bean in that bean

@snazy
Copy link
Contributor Author

snazy commented Sep 5, 2024

Yea - something is quite broken with this change. Let me start from scratch.

@snazy snazy marked this pull request as draft September 5, 2024 17:21
@sberyozkin
Copy link
Member

sberyozkin commented Sep 5, 2024

Thanks @snazy, yeah, I think the introduction of the functional interface is nice, and making sure static tenants are only recorded in the static map, is worth a dedicated PR of its own, so if you are OK with it, please do it first, and then complete the preparation with the 2nd PR focusing on the rest of your refactoring here

@snazy
Copy link
Contributor Author

snazy commented Sep 7, 2024

Marked as a draft PR for now.

@snazy
Copy link
Contributor Author

snazy commented Sep 7, 2024

Ah! I found out why the PR fails in the CodeFlowTest: I've changed the order of the dynamic/static tenant checks in i.q.oidc.runtime.DefaultTenantConfigResolver#resolveConfig, which broke the tests. Which means, the refactoring was broken in the sense that static tenants still leaked into the dynamic map. Anyway - not a problem, as I'm going to change this PR.

@snazy snazy force-pushed the oidc-refactor-for-context-limit branch from d0419b4 to 3764850 Compare September 7, 2024 09:47
@snazy snazy changed the title OIDC: Refactoring as a preparation to introduce a limit for dynamic tenants OIDC: Encapsulate static/dynamic tenants maps in TenantConfigBean Sep 7, 2024
@snazy snazy marked this pull request as ready for review September 7, 2024 09:47
@snazy
Copy link
Contributor Author

snazy commented Sep 7, 2024

Updated the PR entirely, focusing on moving the tenants-maps into the TenantConfigBean and not let these maps escape.

@snazy
Copy link
Contributor Author

snazy commented Sep 7, 2024

Note: OidcClientRegistrationTest.testRegisteredClientDynamicTenant in integration-tests/oidc-client-registration/ fails on main as well.

Opened #43106

This comment has been minimized.

This comment has been minimized.

public Map<String, TenantConfigContext> getStaticTenantsConfig() {
return staticTenantsConfig;
public Uni<TenantConfigContext> createTenantContext(OidcTenantConfig oidcConfig, boolean dynamicTenant) {
if (oidcConfig.logout.backchannel.path.isPresent()) {
Copy link
Member

Choose a reason for hiding this comment

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

dynamicTenant is not checked yet

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Static tenants still escape into the dynamicTenants map in this PR.
I've opened #43110 to let static tenants not escape - tests should pass on 43110 now - the actual change wasn't that big - could actually sneak it back into this PR. WDYT?

if (tenantContext != null) {
// Dynamic map may contain the static contexts initialized on demand,
if (tenantConfigBean.getStaticTenantsConfig().containsKey(tenantId)) {
if (tenantConfigBean.getStaticTenant(tenantId) != null) {
Copy link
Member

Choose a reason for hiding this comment

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

Please remove the comment above since it is no longer relevant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#43110 removes it (the comment's still valid for this PR)

this.staticTenantsConfig = staticTenantsConfig;
this.dynamicTenantsConfig = dynamicTenantsConfig;
TenantContextFactory tenantContextFactory) {
this.staticTenantsConfig = new ConcurrentHashMap<>(staticTenantsConfig);
Copy link
Member

Choose a reason for hiding this comment

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

It is not clear to me why it is now a concurrent map, given the dynamicTenant in the function below is not checked

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#43110 should make it clear

Lets `TenantConfigBean` be the sole "owner" of the static/dynamic tenants maps, adds/changes accessor methods for tenants. Also introduces a functional interface to create tenants.

No functional change, only moving code around.

Also some minor code cleanups (reducing the amount of warnings in IntelliJ).
@snazy snazy force-pushed the oidc-refactor-for-context-limit branch from 3764850 to 6b670ad Compare September 8, 2024 12:29
Copy link

quarkus-bot bot commented Sep 8, 2024

Status for workflow Quarkus Documentation CI

This is the status report for running Quarkus Documentation CI on commit 6b670ad.

✅ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

Warning

There are other workflow runs running, you probably need to wait for their status before merging.

@sberyozkin
Copy link
Member

Hi @snazy Can you please pickup the latest updates and rework this PR next week or so, to have access to the dynamic (and static) map encapsulated inside TenantConfigBean, and replacing an explicit Function reference with an interface;

Now that the static tenant does not leak into the dynamic map anymore after a fix from @michalvavrik, the PR should become much simpler,

Let me now please if you won't have much time, thanks.

@snazy
Copy link
Contributor Author

snazy commented Sep 30, 2024

Closed in favor of #43590

@snazy snazy closed this Sep 30, 2024
@quarkus-bot quarkus-bot bot added the triage/invalid This doesn't seem right label Sep 30, 2024
@snazy snazy deleted the oidc-refactor-for-context-limit branch September 30, 2024 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/oidc triage/invalid This doesn't seem right
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants