Skip to content

EnableReactiveMethodSecurity docs/example for graphiql -> graphql (Same host/origin) #252

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

Closed
cforce opened this issue Jan 12, 2022 · 5 comments
Labels
in: security Issues related to security status: superseded Issue is superseded by another

Comments

@cforce
Copy link

cforce commented Jan 12, 2022

Can you please add a more detailed doc or even better ran example howto get webflux secured for "graphiql" and "graphql" http/ws via spring security oauth provider running . Also i tried to keep actuator endpoints open without authentication.
I think it's a common pattern and its not easy to get that working if not even not supported yet.

Below some (sadly non functional code) to explain a bit until where i get, but still without success.
This request is in terms of better docs by example if the feature is there, else wise to request a feauture that allows especially to secure /graphiql/** (or other configured path for graphiql) being accesed without auth and dedicated role.
Also the question is if the security header's /(jwt token) is preserved donwards when triggering graphql query/mutation/introspection from the the graphiql UI to the same domain graph ws endpoint.

@Configuration
@EnableWebFluxSecurity
@EnableReactiveMethodSecurity
@Profile("!keycloak")
public class SecurityConfig {
/*
    @Bean
    SecurityWebFilterChain springWebFilterChain(ServerHttpSecurity http) throws Exception {
        return http
                .csrf(spec -> spec.disable())
                .authorizeExchange(requests ->
                    requests.matchers(PathRequest.toStaticResources().atCommonLocations()).permitAll()
                            .matchers(EndpointRequest.to(InfoEndpoint.class, HealthEndpoint.class)).permitAll()
                            .matchers(EndpointRequest.to("graphiql")).hasRole(Roles.AdminRole)
                            .matchers(EndpointRequest.toAnyEndpoint()).hasRole(Roles.AdminRole)//.authenticated()
                            .matchers(EndpointRequest.to("graphql")).hasAnyRole(Roles.AdminRole,Roles.ReaderRole,Roles.WriterRole)
                            .pathMatchers("management/**").hasRole(Roles.AdminRole)
                )
                .httpBasic(withDefaults())
                .formLogin()
                .and().logout().logoutSuccessHandler(logoutSuccessHandler())
                .and().build();

    }

*/

@cforce cforce changed the title EnableReactiveMethodSecurity docs/example for graphiql -> graphql (Same host/origin) via role EnableReactiveMethodSecurity docs/example for graphiql -> graphql (Same host/origin) Jan 12, 2022
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 12, 2022
@rstoyanchev
Copy link
Contributor

For WebFlux security, you'll need to check the Spring Security reference docs. For GraphiQL, it should be no different than securing any URL path but in addition, related to introspection, there is also spring-projects/spring-boot#29248.

Generally, the Security section in the reference docs is short which reflects the fact that to secure a Spring GraphQL application is no different than securing a web application. Mainly, Spring GraphQL needs to ensure context propagates from WebFlux to the data fetching layer so that you can use Security annotations or access the authenticated principal in @SchemaMapping methods. This should work for HTTP and WebSocket.

I would suggest that you go incrementally. Ensure the WebFlux application is secured, perhaps testing with a WebFlux controller. Then start working with Spring GraphQL, and let us know if you run into specific issues, and we can also use the experience to improve the docs, but as I mentioned, a lot of it will be in the Spring Security reference. We'll only make additions in Spring GraphQL that are necessary or specific to GraphQL.

@rstoyanchev rstoyanchev added status: waiting-for-feedback We need additional information before we can continue in: security Issues related to security labels Jan 19, 2022
@cforce
Copy link
Author

cforce commented Jan 21, 2022

Yes, its definetly doable .- however extending the examples code base would help a lot, as it seems there is no other example i could find from the community.
Still on it, Springs security oauth + keyloack + EnableReactiveMethodSecurity - its giving me a hard time :-/

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jan 21, 2022
@cforce
Copy link
Author

cforce commented Jan 22, 2022

I still search for a valid example webflux/reactive how to inject/setup per test in @SpringBootTest a WebGraphQlTester which uses some dedicated oauth client.

@rstoyanchev
Copy link
Contributor

We'll consider this as part of #208.

@rstoyanchev rstoyanchev closed this as not planned Won't fix, can't repro, duplicate, stale Nov 3, 2022
@rstoyanchev rstoyanchev added status: superseded Issue is superseded by another and removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels Nov 3, 2022
@rstoyanchev
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: security Issues related to security status: superseded Issue is superseded by another
Projects
None yet
Development

No branches or pull requests

3 participants