Actuatorエンドポイントを保護する
機密性の高い運用エンドポイントを保護します
「Actuatorエンドポイントを保護する」はCoddyKit上の無料Spring Boot 4 Microservices & REST APIsレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはSpring Boot 4 Microservices & REST APIs学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Spring Boot 4 Microservices & REST APIsコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
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,threaddumpAdding 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 / sidecarProbes 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 statusHiding 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-authorizedDisable 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: falseDefense 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
EndpointRequestmatchers - Permit
health/infofor probes; require a role for the rest - Restrict
show-detailsand disableshutdown - Isolate via a separate management port
よくある質問
「Actuatorエンドポイントを保護する」レッスンは無料ですか?
はい。「Actuatorエンドポイントを保護する」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Spring Boot 4 Microservices & REST APIsコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Spring Boot 4 Microservices & REST APIsコースには全4レッスンが含まれています。
「Actuatorエンドポイントを保護する」で何を学びますか?
機密性の高い運用エンドポイントを保護します ブラウザで直接実行するハンズオンコードでSpring Boot 4 Microservices & REST APIsを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Spring Boot 4 Microservices & REST APIsを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのSpring Boot 4 Microservices & REST APIsは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「Actuatorエンドポイントを保護する」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このSpring Boot 4 Microservices & REST APIsレッスンでコードを書いて実行できますか?
はい。すべてのSpring Boot 4 Microservices & REST APIsレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- Actuatorエンドポイントを有効にする
- ヘルスインジケーター
- Micrometerでカスタムメトリクスを作る
- Actuatorエンドポイントを保護する