-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Document how to propagate OIDC tenant id from OIDC tenant resolver to Hibernate tenant resolver #44547
base: main
Are you sure you want to change the base?
Conversation
michalvavrik
commented
Nov 16, 2024
- closes: Unable to read RoutingContext from CustomTenantResolver #44168
\cc @yrodiere in case you want to review, thanks |
🎊 PR Preview 8df922d has been successfully built and deployed to https://quarkus-pr-main-44547-preview.surge.sh/version/main/guides/
|
This comment has been minimized.
This comment has been minimized.
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.
Michal, thanks, I'm pretty sure we have a note about it in one of the Quarkus Hibernate docs.
As far as setting tenant id is concerned, OIDC sets it itself when the session cookie exists, and @TenantID resolver sets it too.
We should probably have it set in DefaultTenantConfigResolver if it is not already set.
IMHO it will be better
I can see notes in Hibernate docs and Mongo docs, however CDI request context activation in auth should concern authentication. I am just completing here incomplete existing documentation. Are you sure you want to duplicate this inside Hibernate (and Mongo) about proactive authentication?
I don't mind, but then maybe drop the existing example? Please look a few lines above the text I am adding. Anyway that is really not a point of change here. Let me try to summarize what I try to document here, maybe I put it wrong into the words? I try to say:
In another words, whether you set it the tenant id in the |
@sberyozkin if you meant that I am putting this information into a wrong place or that I should duplicate it into Hibernate and Mongo guides, np, I am just not sure if I understood you, so I'll wait for a response. |
Sorry for the confusion @michalvavrik, indeed, what I thought was available in the Hibernate docs is indeed sitting just above the Hibernate TenantResolver example you added in this PR :-), where I show the custom OIDC resolver propagating tenant id via a routing context attribute. But what your PR highlights is that code example I added earlier is outdated, the OIDC multi-tenancy docs should not ask users to propagate OIDC tenant id like I did in that example, instead, Quarkus OIDC should do it itself by setting a |
@sberyozkin what I try to show is important for users if they want to get the OIDC tenant id inside of the Hibernate tenant resolver. Should I rewrite that and move this information to https://quarkus.io/guides/hibernate-orm#writing-the-application ? And maybe drop that original example with link to the Hibernate one? |
@michalvavrik I support this PR, it just depends on the outdated OIDC resolution example, which sets a custom |
np, I'll deal with it tomorrow. |
c15a950
to
f9640b8
Compare
@sberyozkin regarding the scheduler scenario (when there is no active CDI request context), I think it can be easily handled by changing |
Status for workflow
|
I'm sorry, I'm not sure why the scheduler scenario is introduced, I certainly did not raise it. The example with When I said we need to make sure tenant id is always set, I did not mean scheduled scenarios. I'm only not 100% sure Sorry for the confusion, IMHO we need to avoid referring to OidcSession |
@@ -1159,27 +1159,31 @@ From the implementation above, tenants are resolved from the request path so tha | |||
|
|||
[NOTE] | |||
==== | |||
If you also use xref:security-openid-connect-multitenancy.adoc[OIDC multitenancy] and both OIDC and Hibernate ORM tenant IDs are the same and must be extracted from the Vert.x `RoutingContext` then you can pass the tenant id from the OIDC Tenant Resolver to the Hibernate ORM Tenant Resolver as a `RoutingContext` attribute, for example: | |||
If you also use xref:security-openid-connect-multitenancy.adoc[OIDC multitenancy] and both OIDC and Hibernate ORM tenant IDs are the same, | |||
you can get the OIDC tenant id from the `OidcSession` CDI bean inside of the Hibernate ORM Tenant Resolver like in the example below: |
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.
It does not work with bearer access tokens
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.
I am probably missing something, I 'll wait for answer below before I will address this comment. Thanks
User tried to access
Do you say that quarkus/extensions/oidc/runtime/src/main/java/io/quarkus/oidc/runtime/OidcSessionImpl.java Line 33 in 1e7e874
It isn't, and I did double check. However it didn't make sense to me, there is |
Ok. |
Hi Michal, I was just thinking, so https://github.com/quarkusio/quarkus/blob/main/extensions/oidc/runtime/src/main/java/io/quarkus/oidc/runtime/OidcSessionImpl.java#L33 works, but it is a wrong concept on the bearer access token path so IMHO we should indeed avoid recommending it as a general tenant id check mechanism... I'll probably need to tighten its implementation to throw illegal access exception when some of its methods are called if no ID token is available... In any case sorry if I was not clear, if you'd like, I can look at your original PR update and tune it a bit as proposed to save you some time... |
I misunderstood |