-
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
Select OIDC tenant using annotations #23086
Select OIDC tenant using annotations #23086
Conversation
@j-be Thanks for opening this PR. Re the precedence, while it is probably more precise in principle to check the annotations first, I don't think we should be concerned about a situation where The same is the case with the dynamic vs static - the dynamic resolver is checked first - but may be we could've flipped it around - but we've never had any issues. FYI, the reason both We can flip it the moment it proves to be a limitation for some real world cases, but right now, even this minor update is sensitive as it took me awhile to tune it around various cases. So I propose to take it 1 step at a time. Can you please:
thanks |
@sberyozkin Alright, will do. But the way you proposed on how to test it doesn't work afaict. As there is I could just copy the stuff I need from |
@j-be Not sure it is worth creating a new integration tests module.
But that is fine, |
@j-be Oh I see, then lets update the PR to check |
By the way, while |
Fair enough, I changed the implementation in a dedicated commit - will squash only when I'm done for better observability. Yet, the test you chose seems to be one of the few which does not actually care which tenant is actually active. Even if I patch @ApplicationScoped
public class CustomTenantResolver implements TenantResolver {
@Override
public String resolve(RoutingContext context) {
return null;
}
}
I'm not 100% sure what all of this is doing, but it seems that - no matter what - the OIDC provider is always http://localhost:8180/auth/realms/quarkus2/ (i.e. the fake Keycloak provided by I'll try and find another place where to put my test. |
@j-be The test does care it just that the default and this tenant are identical, which is a test weakness but it is not meant to be. So lets fix it and update it as proposed. In Keycloak test resource you can create another realm and update the tenant config accordingly to make sure the default config is not picked up |
What would help if you'd instead open an issue and provide more details. Just stating this fact and suggesting to test this PR elsewhere is not the right approach IMHO |
@sberyozkin I wasn't sure if it is a weakness in the test, or if I'm missing something and that very test doesn't really care. Anyway, will open a dedicated issue for that. I already thought of creating a second realm in |
@j-be I think you got me confused. In the test I've described what is tested is that no discovery is performed as well. When you return null it is the default config which enables the discovery is loaded - which does not refute the test. The weakness in the test is that there is no guarantee it was this tenant id which was loaded. So lets not worry about it for now, I'll take care of tightening it up later on, unless you prefer to tighten it alongside this PR, I don't mind |
@j-be No, the realms are created from the test factory using the API. (Ignore it please - I forgot this test uses Wiremock...) But I see creating realms won't guarantee in the test itself that again that tenant was loaded. What I do in a few other tests is that I echo back the tenant id - so perhaps |
@sberyozkin what I am saying is, that as far as I can tell within the module I never meant to say it is an issue for the test as it is right now, nor did I mean to imply that the test is not doing what it is supposed to. I'm still not sure what exactly is going on with the realms in that very test. I can see As for replying the tenant: that should work. This time reading |
@j-be Sorry, I think you are right that me suggesting to test the PR as I proposed would not really confirm this PR is effective. I think what we need to test is that a correct tenant-id is picked up, we can simplify, there are tests around testing individual tenant configurations, this PR is not about it. So how about a slightly different plan:
Does it work for you ? I have to sign off now, thanks for your time and enjoy the weekend :-) |
@sberyozkin Will try that when I find the time - need to leave now, too. Wish you a nice weekend, too. |
@sberyozkin I can't seem to be able to reproduce the behavior I saw in Dev mode using a unit test. During the tests the I created a new module on my branch ( I'll need to dig further trying to find out what is going on here. I'll report back as soon as I found out what is going on. |
@j-be Sure, if keeping a separate module will help you focus on this problem better then it is fine; but in the end IMHO the test should be added to one of the existing test modules - it just feels the minor update with this PR does not warrant the introduction of a new integration tests module. Thanks |
206f4be
to
885b3bc
Compare
@sberyozkin I finally found some time to further analyze this. You are right, this hinges on For completeness:
I updated the documentation to reflect this. Due to the importance of the fact I chose to put it in a I also completed my integration-tests and moved them to If something is missing: let me know 😃 |
This workflow status is outdated as a new workflow run has been triggered. Failing Jobs - Building 885b3bc
Failures⚙️ Initial JDK 11 Build #- Failing: integration-tests/oidc-wiremock
📦 integration-tests/oidc-wiremock✖ |
885b3bc
to
c6e16a2
Compare
@sberyozkin My pleasure. Sorry for the import ordering - not sure how that slipped by. |
@j-be Thanks, no problems re the build failure, I'm causing too many build failures myself (even though every time I thought I checked everything :-) ) |
@FroMage By the way, besides |
Sorry I'm late, but I don't understand why we document an API that might be useful, instead of providing that API. I'd have made it |
@FroMage That was one of my proposals - see #22974. From what I saw that would have been a major change though, as it seems there is no way to easily evaluate annotation values - at least I wasn't able to find any. Hence, my approach uses one annotation per tenant, which is not the nicest, but it works quite well and with very little code changes. I agree that this doesn't scale very well with the number of tenants, but for a handful of tenants it is imho. fine. And it avoids having to copy (or refactor) the code handling e.g. If there is interest I'd be happy to have a go at that. |
Fixes #22974.
This PR contains a small code change, as well as documentation for selecting OIDC providers based on annotations, rather than using
TenantResolver
.It is currently implemented as suggested by @sberyozkin.
I'd like to propose exposing and using
DefaultTenantConfigResolver.CURRENT_STATIC_TENANT_ID
directly. This would reduce the necessary code change, like:This would also flip precedence, i.e. in the current implementation
TenantResolver
takes precedence, while by usingDefaultTenantConfigResolver.CURRENT_STATIC_TENANT_ID
directly the annotations would, which imho. would be the preferred behavior, as annotations on the code are more specific than a globally registered bean.EDIT: UnitTests/IntegrationTests are still missing. I'm happy to provide some after the above was decided.