티스토리 뷰

Spring boot actuator?

  • Spring Boot Actuator란 Spring Boot 기반의 애플리케이션을 손쉽게 모니터링 할수 있는 데이터를 제공해주는 라이브러리이다.
  • 웹의 상태 모니터링과 metric, traffic정보 그리고 database의 상태등을 알 수 있다. 
  • 이러한 모니터링 데이터를 직접 구현할 필요없이 간단한 설정으로 사용할 수 있다는 것이 큰 장점이다. (물론 설정은 나의몫....)

Configuration

JAVA8, Spring Boot 2.1.4.RELEASE, Gradle 기준

Gradle Depengency 추가

compile("org.springframework.boot:spring-boot-starter-actuator")

spring boot 2 부터는 기본으로 대부분의 정보를 노출하지 않는 것으로 되어 있기 때문에 해당 부분 변경

  • management.endpoints.web.exposure.include = "*" 로 설정하여 모든 정보를 노출시킴
    • 내부 서비스가 아닌 외부 접근이 가능하면 중요 정보를 노출시킬 수 있으므로 필히 보안적용을 해야합니다.
  • 기본 actuator endpont인 '/actuator'를 그대로 쓰면 유출 위험이 있으므로 management.endpoints.web.base-path를 이용하여 임의의 경로를 바꾸어준다.
  • health check시 사용하는 /health endpoint를 사용하기 위해 endpoint.health.show-details=always로 설정한다. (Document)
  • 만약 보안상 노출하고 싶지 않은 endpoint가 있다면 management.endpoints.web.exposure.exclude를 사용한다.
-- application.yml
management:
  endpoints:
    web:
      exposure:
        include: "*"
        #exclude: bean,dev
      base-path: '/secure/actuator'
 
  endpoint:
    health:
      show-details: always

Usage

  • 위에서 설정한 base-path로 접속하면 현재 actuator가 제공하는 endpoint들의 목록을 볼수있다.
    (각 endpoint 설명 - 4.3 Predefined Endpoints 참고)
  • 리스트의 URL를 클릭하여 각각의 리소스 데이터들을 확인 가능하다.

Spring Security

actuator의 정보들은 공개되면 안되므로 security로 막아놓는다.

Gradle Depengency 추가

compile 'org.springframework.boot:spring-boot-starter-security'

Security 설정 추가

@Configuration
@AllArgsConstructor
public class SecuritySecureConfig extends WebSecurityConfigurerAdapter {
 
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
            .antMatchers(UrlConstants.SECURE + "/**").authenticated()
            .anyRequest().permitAll()
            .and()
            .httpBasic()
            .and()
            .csrf().disable();
    }
     
}
spring:
  security:
    user:
      name: {{usrename}}
      password: {{password}}

 


출처

https://brunch.co.kr/@springboot/99
http://blog.naver.com/PostView.nhn?blogId=dg110&logNo=221363263124&categoryNo=0&parentCategoryNo=0&viewDate=&currentPage=1&postListTopCurrentPage=1&from=postView&userTopListOpen=true&userTopListCount=5&userTopListManageOpen=false&userTopListCurrentPage=1
https://www.baeldung.com/spring-boot-actuators
https://supawer0728.github.io/2018/05/12/spring-actuator/
https://jeong-pro.tistory.com/160

'프레임워크 > 스프링 & 스프링 부트' 카테고리의 다른 글

Spring STOMP  (0) 2023.03.22
Spring Boot Admin  (1) 2019.12.30
Spring Boot - ORM(Object-relational mapping)  (0) 2019.08.10
Spring Boot - MVC  (0) 2019.08.10
Spring Boot - @SpringBootApplication  (0) 2019.08.10
댓글