Skip to content
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

Multi-tenancy support for OAuth2 #5351

Closed
jzheaux opened this issue May 15, 2018 · 8 comments
Closed

Multi-tenancy support for OAuth2 #5351

jzheaux opened this issue May 15, 2018 · 8 comments
Labels
in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) type: enhancement A general enhancement
Milestone

Comments

@jzheaux
Copy link
Contributor

jzheaux commented May 15, 2018

Summary

Today, it isn't clear how to best configure Spring Security to support a multi-tenant OAuth2 client.

Here is an example of one approach out in the wild:

https://github.com/thomasdarimont/spring-boot-2-keycloak-oauth-example/blob/feature/mulit-tenancy/src/main/java/demo/SpringBoot2App.java#L127

Though whether JwtDecoder is the ideal place and how tenants might possibly be treated in a more first-class way is yet to be seen. Opening this issue to get the conversation started.

@jzheaux jzheaux added New Feature in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) labels May 15, 2018
@jzheaux jzheaux added this to the 5.1.0.M2 milestone May 15, 2018
@bertramn
Copy link

We indeed had the requirement to run a single resource server that can validate JWTs issued by multiple issuers. We had to implement our own given the Spring one does not support this and Keycloak adapters only support Keycloak specific issuers.

We had 2 main use cases for multi tenancy:

  1. validate all inbound JWT with an Issuer whitelist

This use case requires the IssuerResolver to lookup (and cache) issuer metadata JWKS certs.

  1. validate inbound JWT based on a pre-configured list of issuers

This use case requires a pre-configured IssuerResolver which is configured with the issuer (iss) name it supports and then either the metadata url or the public cert, where the later does not really work well if your issuer performs key rotation.

Another interesting aspect we ran into was that if we just want to run a API based resource server (ie. Spring Boot micro service) there will be a lot of unnecessary moving parts in the Spring Security configuration. We ended up implementing 3 components (AccessDeniedHandler, AuthenticationFailureHandler and AuthenticationEntryPoint), everything else is surplus and massively overcomplicates things.

@jgrandja
Copy link
Contributor

Related #5385

@jgrandja jgrandja modified the milestones: 5.1.0.M2, 5.1.0.RC1 Jul 25, 2018
@metacubed
Copy link

In a multi-tenant configuration, each tenant would likely come with its own set of allowed issuers. A tenant-specific request would trust only a subset of the issuers configured for the resource server.

We would need to introduce a selection mechanism to pick the allowed issuer(s) for a request. This IssuerListSelector could have custom implementations that are specific to the resource server.

For example, the keycloak-auth project uses the request.getServerName() to decide which decoder implementation to use. Other request attributes could also be used, such as the request sub-domain, a header, etc.

@canayozel
Copy link

canayozel commented Oct 4, 2019

@jzheaux since this is released with spring security 5.2.0 is there any documentation or example to follow ? (Not only for resource server but oauth2 clients included)

@jzheaux
Copy link
Contributor Author

jzheaux commented Oct 16, 2019

@canayozel Multi-tenancy support for clients is had through multiple client registrations: https://docs.spring.io/spring-security/site/docs/current/reference/htmlsingle/#oauth2login-custom-provider-properties

For resource server, we have a sample, but are still on the hook for adding documentation.

@bertramn
Copy link

bertramn commented Dec 7, 2019

Hmm not too sure how the multi tenant example is of use to anyone wanting to run a Resource Server that can validate JWTs from different issuers. It just flip-flops the AuthenticationManager back and forth between paths. And I thought we finally could replace our custom implementation.

@jzheaux
Copy link
Contributor Author

jzheaux commented Dec 17, 2019

@bertramn, you are right that 5.2.x doesn't support any specific multi-tenancy model for resource servers. AuthenticationManagerResolver gives applications a place to address their multi-tenancy use case, be it whatever it may. In 5.2.x, there is just the interface and DSL hook.

#7724 demonstrates one way Spring Security might be able to support your use case for JWTs and multiple issuers - feel free to comment over there how well that implementation simplifies your customizations.

@20fps
Copy link

20fps commented Mar 16, 2020

Thanks a lot for this video https://www.youtube.com/watch?v=ke13w8nab-k
It answered all of my questions on multi-tenancy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

7 participants