APISIX real_ip patch + Vector parse_apisix 정규식 업데이트 기록

- apisix.md: real_ip_from 0.0.0.0/0, real_ip_header X-Forwarded-For, access_log_format에 xff/xrip 추가. helm values 미반영, cm 직접 patch 패턴
- victorialogs.md: 진짜 IP 기반 LogsQL 예시, parse_apisix 정규식과 APISIX log format이 짝이라는 주의
This commit is contained in:
kappa
2026-04-08 21:02:02 +09:00
parent 5b595967eb
commit b5e22c2081
2 changed files with 42 additions and 5 deletions

View File

@@ -75,9 +75,34 @@ chaitin-waf 플러그인은 `plugin_attr`(config.yaml)이 아닌 **`plugin_metad
⚠️ **etcd 직접 등록 금지** (1분 이내 controller가 삭제). 모든 신규 객체는 CRD로 선언해야 함. ⚠️ **etcd 직접 등록 금지** (1분 이내 controller가 삭제). 모든 신규 객체는 CRD로 선언해야 함.
#### real_ip 설정 #### real_ip 설정 (2026-04-08 patch 반영)
helm values `apisix.nginx.http.realIpFrom` / `realIpHeader`로 관리. 차트 정상 반영됨. ⚠️ **helm values로는 반영 안 됨** — APISIX helm chart의 nginx.http.realIpFrom/realIpHeader 옵션이 K3s에 배포된 차트(2.13.0) 구조에서 `nginx_config.http`로 전달이 안 됨. 그래서 `cm/apisix` 직접 patch가 필요하고, helm upgrade 시 reset됨.
현재 적용 값 (cm/apisix `config.yaml`):
```yaml
nginx_config:
http:
real_ip_header: "X-Forwarded-For"
real_ip_from:
- 0.0.0.0/0 # BunnyCDN/OpenWrt/K3s 모든 hop 신뢰 (Tailnet+LAN+CDN 경유)
real_ip_recursive: "on"
access_log_format: '$remote_addr - $remote_user [$time_local] $http_host \"$request\" $status $body_bytes_sent $request_time \"$http_referer\" \"$http_user_agent\" $upstream_addr $upstream_status $upstream_response_time \"$upstream_scheme://$upstream_host$upstream_uri\" xff=\"$http_x_forwarded_for\" xrip=\"$http_x_real_ip\"'
```
→ access log의 첫 필드 `$remote_addr`이 X-Forwarded-For에서 추출한 진짜 클라이언트 IP가 됨. 끝에 `xff="..." xrip="..."` 디버그 필드 추가.
적용 절차:
```bash
kubectl get cm apisix -n apisix -o jsonpath='{.data.config\.yaml}' > /tmp/apisix-config.yaml
# /tmp/apisix-config.yaml 편집 (real_ip_*, access_log_format)
kubectl create cm apisix --from-file=config.yaml=/tmp/apisix-config.yaml -n apisix --dry-run=client -o yaml | kubectl apply -f -
kubectl rollout restart deploy/apisix -n apisix
```
⚠️ **Vector parse_apisix 정규식과 짝**: APISIX log format을 변경할 때마다 `vector` helm values의 parse_apisix 정규식도 같이 업데이트해야 [[victorialogs|VictoriaLogs]]에 구조화 필드가 정상 추출됨. 현재 정규식은 `xff/xrip` 필드를 optional 그룹으로 처리.
#### 이전 사유 (2026-03-25) #### 이전 사유 (2026-03-25)
- Ingress Controller 2.0 초기 시도에서 GatewayProxy 모드 + ApisixRoute CRD 연동 실패 (당시 helm values에 v1.x 형식의 `config.apisix.serviceName` 사용 → 차트 1.x 스키마와 불일치) - Ingress Controller 2.0 초기 시도에서 GatewayProxy 모드 + ApisixRoute CRD 연동 실패 (당시 helm values에 v1.x 형식의 `config.apisix.serviceName` 사용 → 차트 1.x 스키마와 불일치)

View File

@@ -138,13 +138,25 @@ program:apisix path:/apisix/admin/routes
# 느린 요청 (1초 이상) # 느린 요청 (1초 이상)
program:apisix request_time:>1.0 program:apisix request_time:>1.0
# 특정 IP # 특정 클라이언트 외부 IP (real_ip 적용 후 진짜 IP)
program:apisix remote_addr:10.42.2.240 program:apisix remote_addr:211.211.28.97
# 특정 호스트
program:apisix host:juiceshop.keepanker.cv
# 특정 호스트의 4xx/5xx
program:apisix host:juiceshop.keepanker.cv status:>=400
# 특정 노드 pod # 특정 노드 pod
program:apisix _stream:{kubernetes.pod_name="apisix-58847b6b7c-rdnw6"} program:apisix _stream:{kubernetes.pod_name="apisix-f5764d796-kdj2x"}
``` ```
> [!info] 진짜 IP 추적
> 2026-04-08 [[apisix#real_ip 설정 (2026-04-08 patch 반영)|APISIX real_ip patch]] 이후 `remote_addr`에 BunnyCDN edge가 전달한 진짜 외부 IP가 찍힘. `xff`/`xrip` 필드로 X-Forwarded-For/X-Real-IP 헤더 원본도 보존. 그 이전 로그는 K3s pod CIDR(10.42.x.x)만 찍혀 있음.
> [!warning] parse_apisix 정규식과 APISIX log format은 짝
> APISIX의 `access_log_format`을 바꾸면 vector helm values의 `parse_apisix` 정규식도 같이 업데이트해야 함. 안 그러면 매치 실패해서 `log_type=raw`로 떨어지고 구조화 필드(method/status/path 등) 추출이 안 됨.
UI에서 직접 쿼리하거나 HTTP API: UI에서 직접 쿼리하거나 HTTP API:
```bash ```bash