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

Provide a fluent API to set up Quarkus Security #16728

Open
sberyozkin opened this issue Apr 22, 2021 · 11 comments
Open

Provide a fluent API to set up Quarkus Security #16728

sberyozkin opened this issue Apr 22, 2021 · 11 comments
Assignees
Labels
area/security kind/enhancement New feature or request

Comments

@sberyozkin
Copy link
Member

sberyozkin commented Apr 22, 2021

Description

Hantsy Bai has linked to the following Spring Security example:

@Configuration
public class SecurityConfig {

    @Bean
    SecurityFilterChain springWebFilterChain(HttpSecurity http) throws Exception {
        return http
                .httpBasic(AbstractHttpConfigurer::disable)
                .csrf(AbstractHttpConfigurer::disable)
                .sessionManagement(c -> c.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
                .authorizeRequests(c -> c
                        .antMatchers("/", "/info").permitAll()
                        .antMatchers(HttpMethod.GET, "/posts/**").permitAll()//.hasAuthority("SCOPE_read:posts")
                        .antMatchers(HttpMethod.POST, "/posts/**").hasAuthority("SCOPE_write:posts")
                        .antMatchers(HttpMethod.PUT, "/posts/**").hasAuthority("SCOPE_write:posts")
                        .antMatchers(HttpMethod.DELETE, "/posts/**").hasAuthority("SCOPE_delete:posts")
                        .anyRequest().authenticated()
                )
                .oauth2ResourceServer(OAuth2ResourceServerConfigurer::jwt)
                .cors().and().build();
    }

While we can do it with combining HttpAuthenticationMechanism/IdentityProvider and configuration, supporting something similar to the above in Quarkus can be of interest

Also CC @stuartwdouglas

@hantsy
Copy link
Contributor

hantsy commented Apr 22, 2021

Found in the old PicketLink docucmentation, https://docs.jboss.org/picketlink/2/latest/reference/html-single/, there are some work like this.

public class HttpSecurityConfiguration {
​
​    public void configureHttpSecurity(@Observes SecurityConfigurationEvent event) {
​        SecurityConfigurationBuilder builder = event.getBuilder();
​
​        builder
​            .http()
​                .forPath("/*.jsf")
​                    .authenticateWith()
​                        .form()
​                            .loginPage("/login.jsf")
​                            .errorPage("/loginFailed.jsf")
​                .forPath("/admin/*")
​                    .authorizeWith()
​                        .role("Administrator");
​    }
​}

@sberyozkin
Copy link
Member Author

@michalvavrik This one would have a very good impact, so among all the issues you may want to choose from, that would be most interesting IMHO.
It should be done in phases IMHO, first we do it nice and easy to set anything related to the built-in authentication: basic, form, mtls, proactive/on/off, path-based HTTP policies, etc. It is a large enough phase though.
Then I reckon we should add oidc, jwt, ets specific builders - which can be used individually or as part of this common builder API via typed options, instead of form(), something like auth(Auth.OIDC) which would be recognized if quarkus-oidc is on the class path, etc...
But yes, it can be a fairly time consuming/long term issue, but it can be done in parts for sure...

@michalvavrik
Copy link
Member

michalvavrik commented Nov 11, 2022

Sure, thank you for suggestion and nice description.

@michalvavrik michalvavrik self-assigned this Dec 21, 2022
michalvavrik added a commit to michalvavrik/quarkus that referenced this issue Mar 14, 2023
michalvavrik added a commit to michalvavrik/quarkus that referenced this issue Mar 14, 2023
michalvavrik added a commit to michalvavrik/quarkus that referenced this issue Mar 16, 2023
@geoand
Copy link
Contributor

geoand commented Jul 25, 2023

Is this still relevant?

@hantsy
Copy link
Contributor

hantsy commented Jul 25, 2023

Is there a programmatic config instead of the annotations?

@michalvavrik
Copy link
Member

Is this still relevant?

More importantly, it is next to impossible. It either requires:

  • to move a lot of stuff to runtime (and I mean a lot!),
  • or to basically provide users with some kind of builder that will be implementation of SmallRye Config source at build time
  • or some other trick with config as config interceptor that will do pretty much some as config source

Is there a programmatic config instead of the annotations?

Yeah, but it really doesn't go down with intention to do as much as possible at build time. The reason why I didn't move on this is that any implementation will not provide you will level of programmatic config that Spring and other FWs because you won't be able to inject stuff and only with difficulty access existing config properties (you need to avoid circular reference).

Anyway, this is on my list.

@hantsy
Copy link
Contributor

hantsy commented Jul 25, 2023

For security annotations, the reason I dislike it is it will affect my APIs testing when applying them on Rest API methods.

In Spring, I can ignore the security config when focusing on API development and testing.

And Quarkus security annotation is not flexible for applying a fine-grained security rule on URIs, in some of my past projects, simple role/group/permission can not satisfy the security requirements.

In spring security it is easy to control security on a URI path via custom codes to decide if it is authorized.

.antMatchers(HttpMethod.DELETE, "/posts/**").access(AuthencationContext, xxx -> a callback)

@hantsy
Copy link
Contributor

hantsy commented Jul 25, 2023

Or provides an article to describe how to apply the fine-grained security control using the existing features provided in Quarkus 3.x.

@hantsy
Copy link
Contributor

hantsy commented Aug 6, 2023

Check the current security docs, the security control is still based on annotations, and provide limited extension points.

@michalvavrik michalvavrik removed their assignment Aug 6, 2023
@michalvavrik
Copy link
Member

I hear you @hantsy. I have other issues with higher priority on my list, therefore I removed myself from this issue until they are done. Maybe someone else will pick it up. Thanks.

@michalvavrik
Copy link
Member

I believe now that most of the quarkus.http.auth is runtime configuration, we certainly can implement all examples given here in the comments / issue description. I won't look in the next 2 months, but I wanted to let you all know that situation has changed there is reasonable way to do this. I'm also happy to give a hand to anyone who will give this issue try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/security kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants