-
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
Provide default OIDC static tenant resolver #32864
Provide default OIDC static tenant resolver #32864
Conversation
🙈 The PR is closed and the preview is expired. |
✔️ 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. |
Is it normal to use the last URL segement to select a provider? And if so I am guessing this is just for the web-app case for the login URL? Not for URLs once you have the token? |
@stuartwdouglas Hi,
I'd say so, I think Quarkus Renarde does it for example (CC @FroMage ). It is either the path segment (typical I think), or, I guess, a query parameter. So this PR offers a last fallback checking the path segment, only when custom tenants are present and no custom resolver is available, so it is not really interfering with anything.
If we continue with the This is exactly how I'd write a custom But, if we have the Bearer token coming in, well, I can't see how else but use the path segment as a hint. I think in general, more than one social provider support is more interesting for the |
For bearer tokens, one might also use a dynamic tenant resolver and parse the token to check which provider should verify it (instead of expecting a provider name in the path), but this default fallback won't interfere in that case |
I would suggest being very careful about using session cookies for tenant resolution, or - at least - informing the users/developers/customers about potential CORS problems with such a setup. My reasoning is as follows:
My 2 cents: Use only a resource path segment to supply the tenant id. Having tried some other options, the resource path strategy is the only one which really works in a scalable and reusable way with a minimum of fuzz. |
@lennartj Thanks for the feedback,
It does not really work after the authentication has taken place for non-SPA/non-bearer token setup., when you access Quarkus directly from the browser. Application URI space can not be all partitioned and documented to have See Quarkus Renarde in action please. Or try a multi-tenant setup with Apart from that, tenant identifier in the path segment only works for SPA/CLI clients sending bearer tokens to Quarkus. In such cases, indeed CORS considerations should be considered - but the session cookie is not part of these considerations - it is not available there at all. In any case as far as this PR is concerned, this is just a fallback (which I verified not only with the tests but also with the browser), when no custom resolvers are available |
@lennartj I should've asked though, did you already try |
if (pathSegments.length > 0) { | ||
String lastPathSegment = pathSegments[pathSegments.length - 1]; | ||
if (tenantConfigBean.getStaticTenantsConfig().containsKey(lastPathSegment)) { | ||
return lastPathSegment; |
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.
This implementation looks correct. Unlike the code example we give in the docs ;)
See https://github.com/quarkusio/quarkus/pull/32864/files#diff-95192f8049e4b0a3a326ebbd353c3428b121c1088f3aff807a0a8dee3d58a264L303
Fixes #32834.
This PR will help with a more straightforward static tenant resolution, for example, given a typical configuration like:
or
now, instead of having to write a custom
TenantResolver
CDI bean doing the boilerplate code checking the last path segment which serves as a tenant id, and checking, in case ofweb-app
,RoutingContext
attribute, the users will just have it working immediately.The last variation above is tested in
integration-tests/keycloak-authorization
, where the testTenantResolver
doing the boilerplate code has been removed (I just needed to tweak the tenant configuration a bit to have the last path segment matching the tenant key).This default resolution will only be activated if no custom
TenantResolver
is available.This will also work well in a demo.
Also CC @FroMage (in case Steph does a similar boilerplate code in Renarde)