0Pricing
Spring Boot 4 Microservices & REST APIs · Aula

Protegendo endpoints do Actuator

Proteja endpoints operacionais sensíveis.

Protegendo endpoints do Actuator é uma aula grátis de Spring Boot 4 Microservices & REST APIs no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Spring Boot 4 Microservices & REST APIs, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Spring Boot 4 Microservices & REST APIs inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

Why Actuator Needs Securing

Actuator endpoints can reveal environment variables, beans, mappings, and even heap dumps. Left open, they leak sensitive information and may allow dangerous operations like shutdown. They must be protected in production.

Minimize the Attack Surface First

Security starts with exposure. Expose only the endpoints operators truly need over HTTP, and exclude sensitive ones like env, beans, and heapdump.

management:
  endpoints:
    web:
      exposure:
        include: health,info,prometheus
        exclude: env,beans,heapdump,threaddump

Adding Spring Security

To authenticate access, add Spring Security. Once on the classpath, it secures the application — including Actuator endpoints — and you define the rules.

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

The EndpointRequest Matcher

Spring Boot provides EndpointRequest matchers so your security config can target Actuator endpoints precisely, without hardcoding the /actuator path.

import static org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest.*;
// EndpointRequest.toAnyEndpoint()
// EndpointRequest.to("health", "info")

Locking Down the Endpoints

A typical policy: allow health and info anonymously (for probes), but require an authenticated role for everything else.

@Bean
SecurityFilterChain actuatorSecurity(HttpSecurity http) throws Exception {
    http.securityMatcher(EndpointRequest.toAnyEndpoint())
        .authorizeHttpRequests(a -> a
            .requestMatchers(EndpointRequest.to("health", "info")).permitAll()
            .anyRequest().hasRole("ADMIN"))
        .httpBasic(Customizer.withDefaults());
    return http.build();
}

Role-Based Access

Restrict management endpoints to an operations role such as ADMIN. Combine with your existing user store — in-memory for demos, a real identity provider in production.

@Bean
UserDetailsService users(PasswordEncoder encoder) {
    UserDetails admin = User.withUsername("ops")
        .password(encoder.encode("change-me"))
        .roles("ADMIN").build();
    return new InMemoryUserDetailsManager(admin);
}

Isolating with a Management Port

Run Actuator on a separate port that is only reachable inside your network or cluster. Public traffic hits the app port; operators reach management through internal routing.

management:
  server:
    port: 8081
# expose 8081 only to the internal network / sidecar

Probes Without Credentials

Kubernetes probes call health/liveness and health/readiness without auth. Permit those specific paths while still protecting the rest of health details and other endpoints.

.requestMatchers(EndpointRequest.to("health")).permitAll()
// keep show-details restricted so anonymous probes see only status

Hiding Health Details

Even when health is public, do not leak component internals to anonymous callers. Set show-details to when-authorized so probes see only UP/DOWN.

management:
  endpoint:
    health:
      show-details: when-authorized

Disable Dangerous Endpoints

Some endpoints can change runtime state. Keep shutdown disabled, and avoid exposing heapdump or threaddump publicly, as they reveal memory contents and aid attackers.

management:
  endpoint:
    shutdown:
      enabled: false

Defense in Depth

No single control suffices. Combine measures:

  • Minimal exposure
  • Authentication and roles
  • Network isolation / separate port
  • Restricted health details

Quick Check

Test your understanding of securing Actuator.

Recap

Treat Actuator as a security perimeter.

  • Expose minimally; exclude env, beans, heapdump
  • Add Spring Security and use EndpointRequest matchers
  • Permit health/info for probes; require a role for the rest
  • Restrict show-details and disable shutdown
  • Isolate via a separate management port

Perguntas Frequentes

A aula “Protegendo endpoints do Actuator” é grátis?

Sim — o texto completo de “Protegendo endpoints do Actuator” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Spring Boot 4 Microservices & REST APIs, atualize para CoddyKit PRO. O curso de Spring Boot 4 Microservices & REST APIs inclui 4 aulas no total.

O que vou aprender em “Protegendo endpoints do Actuator”?

Proteja endpoints operacionais sensíveis. Você pratica Spring Boot 4 Microservices & REST APIs com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar Spring Boot 4 Microservices & REST APIs?

Nenhuma experiência prévia é necessária. Spring Boot 4 Microservices & REST APIs no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.

Quanto tempo leva a aula “Protegendo endpoints do Actuator”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de Spring Boot 4 Microservices & REST APIs?

Sim. Cada aula de Spring Boot 4 Microservices & REST APIs inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Habilitando endpoints do Actuator
  2. Indicadores de saúde
  3. Métricas personalizadas com Micrometer
  4. Protegendo endpoints do Actuator
← Voltar para Spring Boot 4 Microservices & REST APIs