0Pricing
Spring Boot 4 Microservices & REST APIs · درس

تأمين نقاط نهاية Actuator

احمِ نقاط النهاية التشغيلية الحساسة

تأمين نقاط نهاية Actuator درس مجاني في Spring Boot 4 Microservices & REST APIs على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في 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,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

الأسئلة الشائعة

هل درس «تأمين نقاط نهاية Actuator» مجاني؟

نعم — نص درس «تأمين نقاط نهاية Actuator» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Spring Boot 4 Microservices & REST APIs، انتقل إلى CoddyKit PRO. تتضمن دورة Spring Boot 4 Microservices & REST APIs 4 دروس في المجموع.

ماذا ستتعلم في «تأمين نقاط نهاية Actuator»؟

احمِ نقاط النهاية التشغيلية الحساسة تتمرن على Spring Boot 4 Microservices & REST APIs مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Spring Boot 4 Microservices & REST APIs؟

لا تُشترط خبرة سابقة. Spring Boot 4 Microservices & REST APIs على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.

كم من الوقت يستغرق درس «تأمين نقاط نهاية Actuator»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Spring Boot 4 Microservices & REST APIs هذا؟

نعم. كل درس في Spring Boot 4 Microservices & REST APIs يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. تفعيل نقاط نهاية Actuator
  2. مؤشرات الحالة
  3. مقاييس مخصصة باستخدام Micrometer
  4. تأمين نقاط نهاية Actuator
← العودة إلى Spring Boot 4 Microservices & REST APIs