2025-04-08T19:56:24
This commit is contained in:
162
docs/actuator/03_config.md
Normal file
162
docs/actuator/03_config.md
Normal file
@@ -0,0 +1,162 @@
|
||||
좋아, 이어서 **3부. 보안과 커스터마이징**을 작성해볼게. 액추에이터를 실무에 적용할 때 꼭 필요한 보안 설정과 사용자 정의 방법을 중심으로 정리할게.
|
||||
|
||||
---
|
||||
|
||||
## **3부. 보안과 커스터마이징**
|
||||
|
||||
---
|
||||
|
||||
### **12장. 액추에이터 엔드포인트 보안**
|
||||
|
||||
#### 기본 설정
|
||||
Spring Security를 사용할 경우, 액추에이터 엔드포인트는 기본적으로 인증이 필요함.
|
||||
|
||||
#### `application.yml`에서 노출 대상 설정
|
||||
|
||||
```yaml
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: health, info, metrics
|
||||
```
|
||||
|
||||
#### WebSecurityConfigurer를 통한 제어
|
||||
|
||||
```java
|
||||
@Configuration
|
||||
public class ActuatorSecurityConfig {
|
||||
|
||||
@Bean
|
||||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
||||
http
|
||||
.authorizeHttpRequests(auth -> auth
|
||||
.requestMatchers("/actuator/health", "/actuator/info").permitAll()
|
||||
.requestMatchers("/actuator/**").hasRole("ADMIN")
|
||||
.anyRequest().authenticated()
|
||||
)
|
||||
.httpBasic();
|
||||
return http.build();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
> 인증 필요 시 기본 사용자 정보는 `application.yml`에서 설정
|
||||
|
||||
```yaml
|
||||
spring:
|
||||
security:
|
||||
user:
|
||||
name: admin
|
||||
password: admin123
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### **13장. 액추에이터 엔드포인트 커스터마이징**
|
||||
|
||||
#### 엔드포인트 비활성화
|
||||
|
||||
```yaml
|
||||
management:
|
||||
endpoint:
|
||||
metrics:
|
||||
enabled: false
|
||||
```
|
||||
|
||||
#### 엔드포인트 경로 변경
|
||||
|
||||
```yaml
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
base-path: /manage
|
||||
```
|
||||
|
||||
> 결과: `/manage/health`, `/manage/info` 등의 경로로 변경됨
|
||||
|
||||
#### 관리 포트를 분리
|
||||
|
||||
```yaml
|
||||
management:
|
||||
server:
|
||||
port: 8081
|
||||
```
|
||||
|
||||
> `/actuator`는 8081 포트에서만 노출됨. 일반 API는 기존 8080에서 제공됨
|
||||
|
||||
---
|
||||
|
||||
### **14장. 사용자 정의 엔드포인트 만들기**
|
||||
|
||||
#### 기본 구조
|
||||
|
||||
```java
|
||||
@Component
|
||||
@Endpoint(id = "customstatus")
|
||||
public class CustomStatusEndpoint {
|
||||
|
||||
@ReadOperation
|
||||
public Map<String, Object> customStatus() {
|
||||
return Map.of(
|
||||
"service", "My Service",
|
||||
"status", "Running",
|
||||
"timestamp", Instant.now()
|
||||
);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
> `GET /actuator/customstatus` 호출 시 결과 반환
|
||||
|
||||
```json
|
||||
{
|
||||
"service": "My Service",
|
||||
"status": "Running",
|
||||
"timestamp": "2025-04-07T10:00:00Z"
|
||||
}
|
||||
```
|
||||
|
||||
#### WriteOperation 예시 (POST)
|
||||
|
||||
```java
|
||||
@WriteOperation
|
||||
public String updateSomething(@Selector String id, @Nullable String value) {
|
||||
// 업데이트 처리
|
||||
return "Updated " + id + " to " + value;
|
||||
}
|
||||
```
|
||||
|
||||
> POST `/actuator/customstatus/myconfig?value=test` 등으로 호출 가능
|
||||
|
||||
---
|
||||
|
||||
### **15장. 상태 분류 및 외부 연동 대응**
|
||||
|
||||
#### Health 상태 분류 예시
|
||||
|
||||
```yaml
|
||||
management:
|
||||
health:
|
||||
status:
|
||||
http-mapping:
|
||||
DOWN: 503
|
||||
OUT_OF_SERVICE: 503
|
||||
UP: 200
|
||||
UNKNOWN: 200
|
||||
```
|
||||
|
||||
> Kubernetes, AWS 등 상태 확인을 위한 HTTP 상태 코드 제어 가능
|
||||
|
||||
---
|
||||
|
||||
### **요약**
|
||||
|
||||
- 액추에이터는 민감한 정보를 다루므로 보안 설정이 필수
|
||||
- 엔드포인트는 개별적으로 비활성화하거나 커스터마이징 가능
|
||||
- 사용자 정의 엔드포인트로 비즈니스 모니터링도 가능
|
||||
- 상태 값은 외부 환경(K8s 등)에 맞게 분류할 수 있음
|
||||
|
||||
---
|
||||
|
||||
다음은 **4부. 운영 환경 통합**으로 Prometheus, Grafana, Spring Boot Admin 같은 외부 시스템과의 통합 내용을 다루면 좋아. 계속 이어서 써줄까?
|
||||
Reference in New Issue
Block a user