-
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
Always set OIDC tenant id and document how to access it in Hibernate and Mongo resolvers #44547
Always set OIDC tenant id and document how to access it in Hibernate and Mongo resolvers #44547
Conversation
michalvavrik
commented
Nov 16, 2024
- closes: Unable to read RoutingContext from CustomTenantResolver #44168
\cc @yrodiere in case you want to review, thanks |
🙈 The PR is closed and the preview is expired. |
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 |
This comment has been minimized.
This comment has been minimized.
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 |
So I have done whatever I understood from @sberyozkin comment. Sorry, but this may take few iterations. Also I don't have time to run all related tests locally as I have to go (run just few modules), so I'll just trigger CI and look at potential failures. |
f9640b8
to
d7d7e62
Compare
@yrodiere I have requested review from you because I don't have permissions to just dismiss your review. I don't think it makes sense for you to review ATM because this might take a while. Thanks that you looked before. |
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.
Commenting to finish the dismissing of my review :)
Agreed, it's more about OIDC than Hibernate ORM in the end, so I'm not much help here.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
d7d7e62
to
e8068a8
Compare
This comment has been minimized.
This comment has been minimized.
e8068a8
to
df602e0
Compare
Status for workflow
|
Status for workflow
|
Thanks @yrodiere |
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.
Thanks @michalvavrik