Mengamankan Endpoint Actuator
Lindungi endpoint operasional yang sensitif.
Mengamankan Endpoint Actuator adalah pelajaran Spring Boot 4 Microservices & REST APIs gratis di CoddyKit. Ini adalah pelajaran 4 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar Spring Boot 4 Microservices & REST APIs, dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus Spring Boot 4 Microservices & REST APIs mencakup 4 pelajaran total.
Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.
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
Belajar Java dengan tutor AI — gratis
Tulis dan jalankan kode asli di browser kamu, dapatkan bantuan instan dari tutor AI 24/7, dan lanjutkan di mana kamu tinggalkan di web atau aplikasi.
- Kursus
- 24
- Pelajaran
- 93
Pertanyaan yang Sering Diajukan
Apakah pelajaran “Mengamankan Endpoint Actuator” gratis?
Ya — teks lengkap “Mengamankan Endpoint Actuator” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus Spring Boot 4 Microservices & REST APIs, upgrade ke CoddyKit PRO. Kursus Spring Boot 4 Microservices & REST APIs mencakup 4 pelajaran total.
Apa yang akan aku pelajari di “Mengamankan Endpoint Actuator”?
Lindungi endpoint operasional yang sensitif. Kamu berlatih Spring Boot 4 Microservices & REST APIs dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.
Apakah aku perlu pengalaman untuk memulai Spring Boot 4 Microservices & REST APIs?
Tidak diperlukan pengalaman sebelumnya. Spring Boot 4 Microservices & REST APIs di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 4 dari 4.
Berapa lama pelajaran “Mengamankan Endpoint Actuator” memakan waktu?
Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.
Bisakah aku menulis dan menjalankan kode dalam pelajaran Spring Boot 4 Microservices & REST APIs ini?
Ya. Setiap pelajaran Spring Boot 4 Microservices & REST APIs menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.
Semua pelajaran dalam kursus ini
- Mengaktifkan Endpoint Actuator
- Indikator Kesehatan
- Metrik Kustom dengan Micrometer
- Mengamankan Endpoint Actuator