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로 선언해야 함.
#### 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)
- Ingress Controller 2.0 초기 시도에서 GatewayProxy 모드 + ApisixRoute CRD 연동 실패 (당시 helm values에 v1.x 형식의 `config.apisix.serviceName` 사용 → 차트 1.x 스키마와 불일치)