콘텐츠로 이동

2022 11 10

2022-11-10

Actuator 안전하게 사용하기

  • 참고: https://techblog.woowahan.com/9232/
  • Spring Actuator란
    • 스프링 부트의 백엔드 어플리케이션 모니터링 및 관리 측면에서 도움
    • HTTP 방식과 JMX 방식이 있으며, Health Check 용도의 actuator health endpoint
  • Actuator 보안 이슈
    • 조심해야할 정보
      • 비밀번호, API Key, Token 등 Credential
      • 서비스 도메인, IP 주소와 같은 정보
    • 불필요한 endpoint 활성화시켜 문제가 발생함!
  • /actuator/env 환경변수로 중요 정보를 저장해 둔 경우
    • Spring Actuator의 env 엔드포인트를 설정해뒀다면, 중요 정보가 노출 될 수 있음!
    • 불필요하다면 env 엔드포인트는 노출하지 말자!
  • /acutator/heapdump 로 중요 정보가 메모리에 있는 경우
    • 서비스가 점유 중인 heap 메모리를 덤프하여 그 데이터를 제공
    • 덤프된 메모리 값을 통해 중요 정보가 유출될 수 있음
  • /actuator/shutdown 으로 외부 사용자가 어플리케이션 끌 수도!
    • 서비스 가용성에 큰 문제 줄 수 있음
  • 안전하게 Actuator 사용하기
    1. 기본적으로 endpoint all disable => 필요한 것만 include
      • management.endpoints.enabled-by-default=false
      • management.endpoint.[필요한endpoint].enable=true
    2. shutdown은 무조건 disable
    3. JMX 형태로 Actuator 사용이 필요하지 않다면 disable
    4. Actuator는 서비스 운영에 사용되는 포트와 다른 포트 쓰는 것도 추천
      • 공격자를 막을 수 있음
      • management.server.port
    5. Actuator Default 경로보다는 경로를 변경하여 운영할 것
      • 기본 경로 대신 다른 경로를 설정해서 외부 공격자의 스캐닝을 벗어나자!
      • management.endpoints.web.base-path
    6. Actuator 접근은, 인증/인가 과정을 거칠 것
      protected void configure(HttpSecurity http) throws Exception {
          http
              .authorizeRequests()
              .antMatchers("/login", "/signup", "/user").permitAll()
              .antMatchers("/actuator/**").hasRole("ADMIN")
              .anyRequest().authenticated()
              .and()
              .logout()
              .logoutSuccessfulUrl("/login")
              .invalidateHttpSession(true);
      }
      
      # Actuator 보안 설정 샘플
      
      # 1. Endpoint all disable
      management.endpoints.enabled-by-default = false
      
      # 2. Enable specific endpoints
      management.endpoint.info.enabled = true
      management.endpoint.health.enabled = true
      
      # 3. Exclude all endpoint for JMX and Expose specific endpoints
      management.endpoints.jmx.exposure.exclude = *
      management.endpoints.web.exposure.include = info, health
      
      # 4. Use other port for Actuator
      management.server.port = [포트번호]
      
      # 5. Change Actuator Default path
      management.endpoints.web.base-path = [/변경된 경로]
      

배달의민족 마이크로서비스 여행기

- 참고: https://www.youtube.com/watch?v=BnS6343GTkY