-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Add quarkus-oidc-db-state-manager extension #13239
Comments
/cc @Sanne, @gsmet, @pedroigor |
Sounds reasonable for me, but I would keep this on hold until we have a real demand for becoming stateful. In Keycloak, for instance, we are planning to support reference tokens which should help with this. Also, people should always consider how much data they put into tokens. |
Hey @pedroigor Sure about the demand; but I've marked it as a good 1st issue, if someone finds it to be a useful feature for them then IMHO we should let them do it, we are not going ahead with the |
hey, I'm new to all of this . But I'm highly interested in contributing I'll be highly obliged if anyone would help me. Do I need to install quarkus or learn it? Or do I need to learn maven or graalvm? Please someone help. |
Hi @SumaiyaSafdar - please see #12522 (comment) where I gave you answer to similar question. Thanks. |
@sberyozkin I am interested in working on this extension. I would love to get started if no one else has started working on it yet. |
@gauravrmsc |
thanks @maxandersen I'm really obliged you replied. |
@sberyozkin |
@sberyozkin |
@gauravrmsc sorry, I've missed your questions. Yes, it has to be a new extension, in its I think you can copy and paste |
@gauravrmsc Hi - have you had a chance to look into it a bit further ? I'd like this extension added sooner or later - if you are busy with something else then it is np, just let me know |
@sberyozkin I want to work on this extension but this month I am a bit busy with my internship and university exams. Can I continue on this in Feb |
@gauravrmsc Sure - that sounds fine, good luck with the university work; let me know in Feb please - if you will have time to continue - this issue is not very urgent but we have some users which may benefit from it, so I'd prefer not to delay its resolution indefinitely. thanks |
@gauravrmsc - Hi, how are things - can you let me now please if you are intending to resume working on this issue ? Np if not - i can suggest a few other issues to look at which can take less time, etc |
@sberyozkin Hello, was navigating through good first issues label as I am interested in quarkus project and would like to contribute. |
@ahmadshabib Hi, missed it, yes, it would not be the best issue to start getting familiar with Quarkus, please pick up something else, I'm going to remove a good first issue label to avoid the confusions, thanks |
Hi @pedroigor @stuartwdouglas, I think this issue should be addressed somehow after a recent case of the Azure producing the code flow tokens with the size > 4096 and the authentication failing. So far the default token state manager has managed to save the day by having a single cookie combining 3 tokens split into into 3 cookies. However the case where it won't be able to handle a > 4096 case is not far away. Example in the Azure case, the bulk of it is the ID token, with the access token likely be a small binary token and trying to re-optimize ID token is not going go be a generic solution. It probably should be based on a cache though such as @cemnura would like to have look at this issue. thanks |
@sberyozkin are we looking for a caching mechanism like the following? Caching/Invalidating would be based on the tokenState? Lines 22 to 32 in dda8d67
|
@sberyozkin I gave it my best shot and tried to implement a caching mechanism. Please have a look here. Perhaps we can give the user the ability modify the caching properties such as
|
Hi @cemnura Thanks for starting so quickly. The current cache token manager is a copy of the default one - all of it has to go, So the config would read something like this:
I'd not be concerned about the max size here, as the authentication should always work and if the cache will restrict then some users won't be authenticated if the is size is max size. And the cache like Caffeine, Infinispan will take care of storing as many entries as needed. The expiry should probably be calculated the same way the Thanks |
Hi @sberyozkin I renamed the extension according to your comments. Would a configuration class like this be suitable? I believe I couldn't find where Thanks |
Hi @cemnura The config class like that one should do for now, I believe The session lifetime/max age calculated here: https://github.com/quarkusio/quarkus/blob/main/extensions/oidc/runtime/src/main/java/io/quarkus/oidc/runtime/CodeAuthenticationMechanism.java#L379 but the good news this value is already available as a routing context attribute, but may be add 30 secs to it. |
Hi @sberyozkin I changed the config class as you pointed out. Sounds like a good idea. Perhaps the The expiry after write should be a bit more (30 secs) then the max age. Therefore, the token state cache would die when the token reached its max age. Is the max age completely dependent on Also, how could I configure the |
Hi @cemnura
Why would the token cache would be gone ? It should be set individually for a specific token entry, not for the whole cache
It is a dynamic runtime value, it is calculated from the current ID token returned from Keycloak/etc
I think you'll need to use the Cache provider API directly :-) |
Hi @sberyozkin
Sorry, I meant as in cache entry would die for each specific token entry. Each entry would expire If so couldn't we just always have the cache expiry set to be
Yes it should be dynamic for sure depending on the time it was created. But will it always be the same duration? For example, the
Do you mean directly use the Thanks for your help 😃 |
Hi @cemnura
Makes sense, I thought I may have suggested something similar, but sorry if my comments were confusing
I'm not sure it will be the same duration, probably it will be in most cases except when multiple tenants are used where it might differ, but we should just take
Good point, indeed, Thanks |
Hey @cemnura Lets try to have some progress on this one :-), how is it going ? |
Sure thing. I'll get back to it today. :) |
Implemented a |
@cemnura Thanks, good plan IMHO. |
My conclusion is that there should be 2 extensions
/cc @sberyozkin |
I had a look into this, and it turns out that at the moment, Hibernate ORM and Hibernate Reactive can't coexist. It doesn't seem right to provide @sberyozkin I'd like to use cache after all. I can't understand arguments why it was previously ruled of as long as it is not in-memory cache. I won't look into this in next weeks, so please take your time to answer, but I'd like to see your POV. Thanks |
I presume argument against cache would be that the simplest apps probably don't have in place Redis / Infinispan. On the other hand, using cache would make this feature more usable for prod apps as it is faster and we don't have to take care of TTL. |
Hi @michalvavrik.
I agree.
Possibly but I'm not sure we want to start recommending a stateful approach in prod. IMHO, we can start with Does it sound reasonable to you, start with the simple |
Yep, this explanation makes sense to me. I'm glad to hear this, because I planned to go in the different direction. |
@michalvavrik Sounds good, let give users a simple option to keep the tokens in the local DB state and see what demand will be there to push it to the next level with Hibernate Reactive, Redis etc :-). I'm hoping each of such extensions would be very light-weight, say PanacheEntity |
Describe the extension
Quarkus OIDC
CodeAuthenticationMechanism
uses a defaultTokenStateManager
implementation which stores all the session content in a cookie, which, by default, will include 3 tokens: ID, access and refresh tokens. When all 3 of them are in a JWT format as is with Keycloak, the cookie value size may exceed4096
when JWTs have a lot of claims, at which point some browsers may drop it.Default
TokenStateManager
can be configured to create a cookie per each of these 3 tokens, thus, avoiding the size limitation problem, likely in most cases.However, a cookie per token solution is not ideal, and also, a general approach where JWT tokens are stored as cookies may become a weak point as far as the data privacy is concerned, since, a signed JWT token, if leaked, can be easily introspected (its payload is just a base64-url encoded JSON - hence a claim like
Address
might become visible).So, as discussed earlier with @pedroigor and @stuartwdouglas, the proposal is to ship a simple Hibernate based extension which will only implement
DbTokenStateManager
, store 3 tokens in a DB of choice, and return a DB pointer to OIDCCodeAuthenticationMechanism
thus allowing for a session cookie to only have a short encoded binary value:The DB-node synchronization would be out of scope - as it is a general concern for a multi-node Quarkus DB deployment.
Interested in this extension, please +1 via the emoji/reaction feature of GitHub (top right).
Also CC @Sanne
The text was updated successfully, but these errors were encountered: