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

@EnableReactiveMethodSecurity causes eager bean instantiation, breaking observations #12819

Closed
braunsonm opened this issue Mar 2, 2023 · 2 comments
Assignees
Labels
status: duplicate A duplicate of another issue type: bug A general bug

Comments

@braunsonm
Copy link
Contributor

braunsonm commented Mar 2, 2023

Describe the bug
Scratched my head at this one for awhile. We have some reactive applications and upon upgrading to Spring Boot 3.0.3, we noticed that the ObservationRegistry had zero handlers registered to it. This is because of some kind of early creation of the ObservationRegistry bean that is caused by the @EnableReactiveMethodSecurity.

I'm not sure what causes this problem in spring security, but in Spring Boot this would happen if something causes the ObservationRegistry bean to be created BEFORE the ObservationRegistryPostProcessor found here: https://github.com/spring-projects/spring-boot/blob/main/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/ObservationAutoConfiguration.java#L61-L70

This post processor is responsible for registering all the observation handlers. When you have an ObservationRegistry without handlers, it effectively becomes a NOOP registry causing all kinds of problems (including 500s in the spring cloud gateway).

To Reproduce

  • Go to start.spring.io
  • Create a project with: webflux, actuator, spring-security, and prometheus
  • Add a configuration class with @EnableReactiveMethodSecurity
  • For debugging purposes, add a controller which uses the ObservationRegistry, you can then set a breakpoint on the endpoint so you can inspect the ObservationRegistry bean. You will see it has zero handlers registered.
  • Remove the @EnableReactiveMethodSecurity notice that the handlers are added correctly.

Expected behavior
The @EnableReactiveMethodSecurity should not interfere with the ObservationRegistry

Sample

TestConfiguration.java

package com.example.demo;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableReactiveMethodSecurity;

@Configuration
@EnableReactiveMethodSecurity
public class TestConfiguration {
}

TestController.java

package com.example.demo;

import io.micrometer.observation.ObservationRegistry;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

@RestController
public class TestController {

    public ObservationRegistry observationRegistry;
    public TestController(ObservationRegistry observationRegistry) {
        this.observationRegistry = observationRegistry;
    }

    @GetMapping("/hey")
    Mono<String> myEndpoint() {
        return Mono.just("hey"); // SET YOUR BREAKPOINT HERE
    }
}

pom.xml

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-webflux</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-security</artifactId>
		</dependency>
		<dependency>
			<groupId>io.micrometer</groupId>
			<artifactId>micrometer-tracing-bridge-brave</artifactId>
		</dependency>

		<dependency>
			<groupId>io.micrometer</groupId>
			<artifactId>micrometer-registry-prometheus</artifactId>
			<scope>runtime</scope>
		</dependency>
@braunsonm braunsonm added status: waiting-for-triage An issue we've not yet triaged type: bug A general bug labels Mar 2, 2023
@braunsonm
Copy link
Contributor Author

braunsonm commented Mar 2, 2023

It seems this is the same problem as: #12815

@marcusdacoregio
Copy link
Contributor

This seems to be a duplicate of #12780.

Can you use Spring Security 6.0.3-SNAPSHOT and check if it fixes the problem?

I'll close this as a duplicate but feel free to continue the discussion if your scenario is different.

@marcusdacoregio marcusdacoregio added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 2, 2023
@marcusdacoregio marcusdacoregio self-assigned this Mar 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants