nairavs
nairavs

Reputation: 509

Disable spring boot actuator "health-component" and "health-component-instance"

Hi I am using actuator in sprinb-boot 2, with the following properties

management.endpoints.enabled-by-default=false
management.endpoint.health.enabled=true

My aim is to disable all endpoints except health. By this configuration I disabled all except health and getting the following endpoints now "health", "health-component", "health-component-instance" . Is it possible to disable "health-component", "health-component-instance" as well ? And how ?

Upvotes: 4

Views: 7155

Answers (3)

AlexGera
AlexGera

Reputation: 783

For SpringBoot 2.1.3 you can use the following in you application.yml:

#ENDPOINTS:
management:
  endpoints:
    web:
      exposure:
        include:
        - 'health'
        - 'info'

It will make only two listed endpoints available from actuator.

Upvotes: 2

Ismail Raju
Ismail Raju

Reputation: 324

add in pom.xml

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>

Add a config class:

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .authorizeRequests()
                .antMatchers("/actuator/health/*").authenticated()
                .antMatchers("/**").permitAll();
    }
}

Upvotes: 1

Karol Dowbecki
Karol Dowbecki

Reputation: 44962

Health component endpoints were introduced in Spring Boot 2.2.0.M2 as an extension to already existing HealthEndpoint.

There is no configuration option to disable just /health-component and /health-component-instance, either the entire health endpoint is disabled or not.

Upvotes: 4

Related Questions