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

Optimize OIDC tenant id resolution #39492

Merged
merged 1 commit into from
Mar 20, 2024

Conversation

sberyozkin
Copy link
Member

Fixes #39417

This requires some tests and actually setting the extra attribute during the annotation processing :-)

@sberyozkin sberyozkin force-pushed the optimize_oidc_tenant_resolution branch 2 times, most recently from 6b35def to 39960a9 Compare March 20, 2024 13:58
@sberyozkin sberyozkin force-pushed the optimize_oidc_tenant_resolution branch from 39960a9 to 0a58003 Compare March 20, 2024 14:10
@sberyozkin
Copy link
Member Author

@michalvavrik I've updated tests now to verify that the tenant config resolver is called only during the first request or when the session cookie resolves the tenant with the resolver choosing to let this tenant id stay (this is what I wanted to retain, to let the resolvers block the possibly bogus tenant ids on some paths), as well as added log messages which can help tracing how exactly the tenant id has been set.

@sberyozkin sberyozkin marked this pull request as ready for review March 20, 2024 14:10
@quarkus-bot
Copy link

quarkus-bot bot commented Mar 20, 2024

Status for workflow Quarkus CI

This is the status report for running Quarkus CI on commit 0a58003.

✅ 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.

You can consult the Develocity build scans.

@sberyozkin
Copy link
Member Author

sberyozkin commented Mar 20, 2024

Proposing a backport to 3.8 if possible since otherwise custom TenantConfigResolver is forced to keep all OidcTenantConfig in some cache (for ex, memory) if it was loaded from the db and other external sources, if it wants to avoid reloading them on every request

Copy link
Member

@michalvavrik michalvavrik left a comment

Choose a reason for hiding this comment

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

looks very good

@sberyozkin
Copy link
Member Author

Thanks @michalvavrik.
Hi @gastaldi Can you please have a look and approve if it also looks fine to you ? It should be ready to go since @michalvavrik approved.

The PR is primarily about avoiding calling custom OIDC TenantConfigResolver and TenantResolver tenant resolvers if the tenant id is already known to be set by the @Tenant annotation. It also ensures that if the tenant id has already been deduced from the OIDC session cookie, all the available OIDC resolvers, including TenantConfigResolver and TenantResolver but also the path based resolvers get a chance to overwrite that tenant id if needed. And also adds logs to make it easy to trace where the tenant id was set up.

@gastaldi gastaldi merged commit 5a0e0d7 into quarkusio:main Mar 20, 2024
35 of 36 checks passed
@quarkus-bot quarkus-bot bot added this to the 3.10 - main milestone Mar 20, 2024
@sberyozkin sberyozkin deleted the optimize_oidc_tenant_resolution branch March 20, 2024 18:32
@sberyozkin
Copy link
Member Author

Thanks @gastaldi

@sberyozkin
Copy link
Member Author

@gsmet Hi, I proposed backports, but I've just noticed a related quickstart failure, I'll have a look and re-add the backport suggestions once I figure out what is wrong with that test

@sberyozkin
Copy link
Member Author

sberyozkin commented Mar 30, 2024

@michalvavrik @gastaldi I'm removing the release breaking change, because using a shared session cookie path for more than one OIDC web-app application makes no practical sense at all, I don't think anyone would allow it. The failing test in the quickstarts was passing due to some luck before because currently, the session cookie split into chunks leads to the wrong tenant calculation - in fact that multi-tenancy demo does not work even with 3.9 if you access it from the browser. This PR has exposed that problem.
I have the PR sorting out that coming soon.
I'll add a backport to 3.9 back but will keep 3.8 off the list for now

@@ -166,7 +180,11 @@ private TenantConfigContext getStaticTenantContext(RoutingContext context) {
}

private String resolveStaticTenantId(RoutingContext context) {
String tenantId;
String tenantId = context.get(OidcUtils.TENANT_ID_ATTRIBUTE);
if (isTenantSetByAnnotation(context, tenantId)) {
Copy link
Member

Choose a reason for hiding this comment

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

@sberyozkin you changed the order of resolvers. Annotation-based should be behind tenantResolver according to the https://quarkus.io/version/main/guides/security-openid-connect-multitenancy#static-tenant-resolution. I remember this change was discussed, but effectively documented order is different now?

I am asking because I did some tweaks to this code and need to know if this order should be kept now. I think it's fine, we just should change docs. Your call.

Copy link
Member Author

Choose a reason for hiding this comment

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

@michalvavrik Sure, somewhere, as part of discussing this issue, I suggested the annotation based resolution check should be made before asking the custom resolvers to do the work, I'll tweak the docs

Copy link
Member

Choose a reason for hiding this comment

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

Thank you, I wasn't sure.

Copy link
Member Author

Choose a reason for hiding this comment

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

As otherwise it would defeat the purpose of using those annotations :-)

@gsmet
Copy link
Member

gsmet commented Apr 2, 2024

This doesn't apply cleanly so I will skip backporting.

@sberyozkin
Copy link
Member Author

@gsmet OK, I'll have a look if it can work for 3.9.3

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.

OIDC TenantConfigResolver and TenantResolver are called even if the tenant id is already resolved
4 participants