Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot Actuator - Cannot disable /info endpoint

I tried disabling all actuator endpoints for production environment in application.yml configuration file:

endpoints.enabled: false

It works for all endpoints except for /info. How can I turn off all endpoints for given environment?

UPDATE:

Project I am working on is also acting as Eureka client. In documentation for Spring Cloud Netflix in section Status Page and Health Indicator (http://cloud.spring.io/spring-cloud-netflix/spring-cloud-netflix.html) it says that "Eureka instance default to "/info" and "/health" respectively".

Is there any solution to disable those endpoints?

I was able to disable /health endpoint with endpoints.enabled: false, but not the /info endpoint.

like image 916
Saša Avatar asked Dec 21 '15 16:12

Saša


People also ask

How do I turn off spring boot actuator endpoints?

Spring Boot disable Endpoints<id>. enabled property. For example, you can declare the following property in your properties or yml file to enable the shutdown endpoint. To disable all the endpoints, you can set the management.

How do you turn on actuator endpoints in spring boot?

To enable Spring Boot actuator endpoints to your Spring Boot application, we need to add the Spring Boot Starter actuator dependency in our build configuration file. Maven users can add the below dependency in your pom. xml file. Gradle users can add the below dependency in your build.

Is spring boot actuator enabled by default?

In order to access the actuator endpoints using HTTP, we need to both enable and expose them. By default, all endpoints but /shutdown are enabled.

Can we override actuator in spring boot?

In case of the presence of duplicate endpoints the priority goes to the actuator endpoints since their mappings are created afterwards, there might be another way to force the creation of their mappings first so you can override the native endpoints at all times.


1 Answers

Finally I managed to solve my problem. I enabled only /info and /health endpoints in actuator. And to allow access to /info endpoint only to users with role ADMIN I needed to mix actuator management security and spring security configuration.

So my application.yml looks like this:

endpoints.enabled: false

endpoints:
    info.enabled: true
    health.enabled: true

management.security.role: ADMIN

And spring security configuration like this (where I needed to change order of ManagementSecurityConfig to have higher priority):

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfiguration {


    @Configuration
    protected static class AuthenticationSecurity extends GlobalAuthenticationConfigurerAdapter {

        @Autowired
        private AuthenticationProvider authenticationProvider;

        public AuthenticationSecurity() {
            super();
        }

        @Override
        public void init(AuthenticationManagerBuilder auth) throws Exception {
             auth.inMemoryAuthentication().withUser("admin").password("secret").roles("ADMIN");
        }
    }

    @Configuration
    @Order(Ordered.HIGHEST_PRECEDENCE + 2)
    public static class ManagementSecurityConfig extends WebSecurityConfigurerAdapter {


        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.csrf().disable()
                    .requestMatchers()
                    .antMatchers("/info/**")
                    .and()
                    .authorizeRequests()
                    .anyRequest().hasRole("ADMIN")
                    .and()
                    .httpBasic();
        }
    }

    @Configuration
    public static class ApiWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter {

        protected void configure(HttpSecurity http) throws Exception {
            // API security configuration
        }

    }
}
like image 63
Saša Avatar answered Nov 07 '22 04:11

Saša