Spring Boot Actuator λŠ” Spring Boot Application 의 μƒνƒœλ₯Ό λͺ¨λ‹ˆν„°λ§ν•˜κ³  κ΄€λ¦¬ν•˜κΈ° μœ„ν•œ 도ꡬ이닀.

Actuator λ₯Ό μ‚¬μš©ν•˜κ²Œ 되면 νŠΉμ • endpoint 듀이 ν™œμ„±ν™”λœλ‹€. endpoint λ₯Ό ν™œμ„±ν™”ν•˜λŠ” 것을 expose ν•œλ‹€, 즉 λ…ΈμΆœμ‹œν‚¨λ‹€λΌκ³ λ„ ν‘œν˜„ν•œλ‹€. λͺ¨λ“  endpoint 에 λŒ€ν•œ λͺ©λ‘κ³Ό μ •λ³΄λŠ” Spring 곡식 λ¬Έμ„œ μ—μ„œ 확인가λŠ₯ν•˜λ‹€.

Accessing Endpoints

POM νŒŒμΌμ— dependency λ₯Ό μΆ”κ°€ν•¨μœΌλ‘œμ¨ Spring Boot Actuator λ₯Ό μ‚¬μš©ν•  수 있으며, κΈ°λ³Έμ μœΌλ‘œλŠ” /health endpoint 만 ν™œμ„±ν™”λ˜μ–΄ μžˆλ‹€. λ‹€λ₯Έ endpoint ν™œμ„±ν™”λ₯Ό μœ„ν•΄μ„œλŠ” application.properties νŒŒμΌμ— λ‹€μŒκ³Ό 같이 μΆ”κ°€ν•΄μ£Όμ–΄μ•Ό ν•œλ‹€.

λ§Œμ•½ /info endpoint λ₯Ό μΆ”κ°€ν•˜κ³ , ν•΄λ‹Ή endpoint 에 ν™˜κ²½λ³€μˆ˜ 정보λ₯Ό ν¬ν•¨ν•˜λ„λ‘ ν•˜κ³  μ‹ΆμœΌλ©΄ λ‹€μŒκ³Ό 같이 μΆ”κ°€ν•˜λ©΄ λœλ‹€. μ•„λ‹ˆλ©΄ wildcard λ₯Ό μ‚¬μš©ν•˜μ—¬ λͺ¨λ“  endpoint 듀을 expose ν•  μˆ˜λ„ μžˆλ‹€.

management.endpoints.web.exposure.include=health,info
management.info.env.enabled=true
 
# expose all endpoints
management.endpoints.web.exposure.include=*

κ·ΈλŸ¬λ‚˜ ν•΄λ‹Ή endpoint 듀을 public ν•˜κ²Œ λ³΄μ—¬μ£ΌλŠ” 것은 λ³΄μ•ˆ κ΄€μ μ—μ„œ μ˜¬λ°”λ₯΄λ‹€κ³ λŠ” ν•  수 μ—†κΈ° λ•Œλ¬Έμ—, νŠΉμ • κΆŒν•œμ„ κ°€μ§„ client 의 μš”μ²­μ—λ§Œ μ‘λ‹΅ν•˜λŠ” μ‹μœΌλ‘œ κ΅¬μ„±ν•˜κ±°λ‚˜ μ•„μ˜ˆ νŠΉμ • endpoint 에 λŒ€ν•˜μ—¬λŠ” λΉ„ν™œμ„±ν™”ν•˜λŠ” 것이 λ°”λžŒμ§ν•  것이닀.

μΆ”κ°€μ μœΌλ‘œ ν•΄λ‹Ή κΈ€ μ—μ„œ λΆ€ν•˜κ°€ μ‘΄μž¬ν•˜λŠ” Server System μ—μ„œ Acutator κ°€ Health Check λ₯Ό ν•˜λŠ” κ³Όμ •κ³Ό 이에 λŒ€ν•œ 이슈λ₯Ό 닀루고 μžˆμ–΄ 주기적으둜 μ‚΄νŽ΄λ³Ό ν•„μš”κ°€ μžˆλ‹€.

Accessing Endpoints - Test Result

/health, /info endpoint λ§Œμ„ μΆ”κ°€ν•œ 이후에 Application 을 μ‹€ν–‰ν•˜κ³  log λ₯Ό 확인해보면 μœ„μ™€ 같이 2 개의 endpoints κ°€ exposed λ˜μ—ˆλ‹€λŠ” 것을 확인할 수 μžˆλ‹€.

wildcard λ₯Ό μ΄μš©ν•˜μ—¬ λͺ¨λ“  endpoint λ₯Ό μΆ”κ°€ν–ˆμ„ κ²½μš°μ—λŠ” μœ„μ™€ 같이 14개의 endpoint 듀이 exposed 된 것을 λ³Ό 수 μžˆλ‹€.

Securing Endpoints

μœ„μ—μ„œ 봀듯이 λͺ¨λ“  endpoint λ₯Ό expose ν•˜λŠ” 것은 μ•ˆμ „ν•˜μ§€ μ•Šμ„ 수 μžˆλ‹€. λ¨Όμ € κ°„λ‹¨ν•˜κ²Œ νŠΉμ • endpoint λ₯Ό λΉ„ν™œμ„±ν™”ν•˜λŠ” 방법에 λŒ€ν•˜μ—¬ μ•Œμ•„λ³΄μž.

management.endpoints.web.exposure.exclude=health,info

μœ„μ™€ 같이 μž…λ ₯ν•΄μ€ŒμœΌλ‘œμ¨ κ°„λ‹¨ν•˜κ²Œ νŠΉμ • endpoints λ₯Ό λΉ„ν™œμ„±ν™”ν•  수 μžˆλ‹€. κ·ΈλŸ¬λ‚˜ ν•΄λ‹Ή 방법은 μ–΄λŠ λˆ„κ΅¬λ„ ν•΄λ‹Ή endpoint 에 μ ‘κ·Όν•  수 μ—†κ²Œ λœλ‹€.

이에 login 의 방법을 ν†΅ν•˜μ—¬ 검증을 거친 λ’€, ν•΄λ‹Ή μ‚¬μš©μžμ—κ²Œ νŠΉμ • endpoint 에 λŒ€ν•œ 접근을 ν—ˆμš©ν•˜κ²Œ ν•˜λŠ” 방법이 μžˆλ‹€. λ°”λ‘œ spring-boot-starter-security λ₯Ό μ΄μš©ν•˜λŠ” 것이닀.

/actuator/bean endpoint 에 λŒ€ν•œ 접근을 κ΄€λ¦¬ν•œλ‹€κ³  ν•΄λ³΄μž. Spring Security λ₯Ό μ‚¬μš©ν•˜κ²Œ 되면 Spring Security λŠ” ν•΄λ‹Ή endpoint 에 μ ‘κ·Όν•˜λŠ” μ‚¬μš©μžμ—κ²Œ login promt λ₯Ό λΆ€μ—¬ν•œλ‹€.

default user name 은 user 이고, default password λŠ” console logs μ—μ„œ 확인할 수 μžˆλ‹€. κ·ΈλŸ¬λ‚˜ 이듀은application.properties νŒŒμΌμ„ ν†΅ν•˜μ—¬ overriding ν•  수 있으며, DB λ₯Ό μ‚¬μš©ν•˜μ—¬ role 을 κΈ°μ€€μœΌλ‘œ ν•  μˆ˜λ„ 있고, 또 μ•”ν˜Έν™”λ₯Ό ν•˜μ—¬ μ‚¬μš©ν•  μˆ˜λ„ μžˆλ‹€.

Securing Endpoints - Test Result

μš°μ„  POM νŒŒμΌμ— spring-boot-starter-security λ₯Ό μΆ”κ°€ν•˜κ³  Application 을 μ‹€ν–‰ν•˜λ©΄ λ‹€μŒκ³Ό 같은 log λ₯Ό 확인할 수 μžˆλ‹€.

default password κ°€ λ‚˜μ˜¨ 것을 λ³Ό 수 있고, μ•„λž˜μ—λŠ” 개발 λ‹¨κ³„μ—μ„œλ§Œ ν•΄λ‹Ή password λ₯Ό μ‚¬μš©ν•˜κ³  publication λ‹¨κ³„μ—μ„œλŠ” update κ°€ ν•„μš”ν•˜λ‹€λŠ” λ©”μ„Έμ§€κ°€ μžˆλŠ” 것을 μ•Œ 수 μžˆλ‹€.

# Use wildcard to expose all endpoints  
management.endpoints.web.exposure.include=*  
management.info.env.enabled=true  
  
# Exclude individual endpoints with a comma-delimited list  
management.endpoints.web.exposure.exclude=health,info

μœ„ μƒν™©μ—μ„œ 각각 /beans 와 /health endpoint 에 μ ‘κ·Όν–ˆμ„ λ•Œμ˜ μ‹€μ œ server 응닡은 λ‹€μŒκ³Ό κ°™λ‹€.

μš°μ„  root endpoint λ₯Ό ν¬ν•¨ν•œ λͺ¨λ“  endpoint 에 Spring Security κ°€ 적용이 되기 λ•Œλ¬Έμ—, μœ„μ™€ 같이 /login endpoint 둜 κ°•μ œ redirection λ˜λŠ” 것을 λ³Ό 수 μžˆλ‹€. 기쑴의 endpoint 듀에 λŒ€ν•˜μ—¬λŠ” μ™Όμͺ½κ³Ό 같이 μ •μƒμ μœΌλ‘œ 접근이 κ°€λŠ₯ν•œ λͺ¨μŠ΅μ΄μ§€λ§Œ, exclude λ₯Ό ν†΅ν•˜μ—¬ μ œμ™Έλœ endpoint 에 μ ‘κ·Όν•  λ•Œμ—λŠ” 우츑과 같은 Whitelabel Error Page κ°€ λ³΄μ—¬μ§€λŠ” λͺ¨μŠ΅μ΄λ‹€.