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

Consider adding common scenario/pattern based security configurations #13296

Open
Tracked by #13266
asaikali opened this issue Jun 8, 2023 · 1 comment
Open
Tracked by #13266
Labels
theme: partner-use-cases Use cases we identified with a partner (an established contributor) type: enhancement A general enhancement

Comments

@asaikali
Copy link

asaikali commented Jun 8, 2023

Spring security has a massive number of configuration options and it can be quite overwhelming to know which combination of security configurations to use. It would be nice to provide some out of the box common configuration settings that configure spring security with "reasonable" secure defaults for a specific use case. For example something like CommonSecurityConfigurations.restApi(); should turn on all recommend spring security configuration for securing a rest api without having to configure every setting. A brain storm of possible scenario / pattern based configuration settings:

  • configure security for a Rest API
  • configure security for a GraphQL API
  • configure security for a server side rendered web app

The key goal is to enable the developer to think in terms of higher level capabilities so that they can declare to spring security my app needs pattern x, y, and z and have spring security provide a configuration that is recommend for x,y,z. Ideally the scenarios can be composed together but I am ok if they can't be.

Related gh-13266

@asaikali asaikali added status: waiting-for-triage An issue we've not yet triaged type: enhancement A general enhancement labels Jun 8, 2023
@jgrandja jgrandja removed the status: waiting-for-triage An issue we've not yet triaged label Jun 9, 2023
@sjohnr sjohnr added the theme: partner-use-cases Use cases we identified with a partner (an established contributor) label Jul 6, 2023
@jzheaux
Copy link
Contributor

jzheaux commented Nov 27, 2023

I wonder how opinionated such pre-configurations can/should be. .restApi already presents the possibility of HTTP Basic vs Bearer, so which do we pick? And to what degree can we change that opinion as security recommendations change?

Also, either choice requires some authentication source like a UserDetailsService or JwtDecoder which somewhat undermines what I hear as the goal.

For example, the following already supplies all of Spring Security's reasonable defaults for a JWT-based REST API:

@Bean 
SecurityFilterChain restSecurity(HttpSecurity http) {
    return http.oauth2ResourceServer((oauth2) -> oauth2
        .jwt((jwt) -> jwt.jwkSetUri("https://jwks.example.org"))
        .build();
}

which is already minimal, as far as I can tell.

Perhaps we could provide a subset of the DSL for given scenarios, like so:

@Bean 
RestApiConfigurer restSecurity() {
    return (restApi) -> restApi
        .httpBasic(...)
        .oauth2ResourceServer(...);
}

In this way, the number of options is reduced (for example, .sessionManagement, .formLogin, .oauth2Login, and .saml2Login all might be removed). I'm not really a fan of the maintenance cost, though.

Alternatively, I think #13057 would go a long way to removing the kind of boilerplate this ticket seems to allude to. With #13057, parts of the DSL unrelated to my app's customizations wouldn't need to be known and re-specified by me, the developer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: partner-use-cases Use cases we identified with a partner (an established contributor) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants