feat(validate): add a live drift check against the repository renders

The 2026-11-11 review found a pg_hba rule that existed only in the
cluster by rendering every root by hand and running kubectl diff.
Nothing does that regularly, so drift is found by accident.

live-drift-check.sh renders all live roots (Phase 1 and 2, admin
services, observability core, the Traefik trust overlay, the tenant,
PriorityClass and keycloak policy roots), strips Secrets and runs
kubectl diff, which is a server-side dry run. It prints one line per
drifted object, honours a dated accepted-drift list and can write
Prometheus textfile metrics for a later alert.

Risk: read-only. It consumes the render scripts' verified-output-dir
handoff and deletes those directories on exit; the README notes this
second consumer. Secret values are not compared.

Verification (desktop, before this series is applied): 17 drifted
objects, matching the review plus the new roots; exit 1; the textfile
holds platform_live_drift_objects 17.
This commit is contained in:
DongHyeonka
2026-11-12 00:29:18 +09:00
parent ebdf33f072
commit 3eafb7e1d8
3 changed files with 220 additions and 0 deletions
+37
View File
@@ -559,3 +559,40 @@ parser와 세 mode의 fixture 회귀는 live cluster에 연결하지 않고 다
```sh
bash scripts/validate/test-k3s-secret-encryption-status.sh
```
## 테넌트·우선순위·keycloak 정책 렌더 검사
`render-tenants-and-policies.sh`는 클러스터에 닿지 않고 세 빌드 루트를 렌더해 불변식을
확인한다.
- `services/tenants/techlog`: tech-log 테넌트의 플랫폼 쪽 객체 11개(목록이 정확히 같아야
한다), `hyeonworks-prod` PSA 라벨, techlog DatabaseRole 권한 플래그, 대시보드 이름
- `services/priority-classes`: `platform-critical`(0보다 크고 시스템 클래스보다 작다),
`platform-low`(0보다 작고 선점하지 않는다), 둘 다 global default가 아니다
- `infrastructure/networking/keycloak`: namespace 전체 기본 차단, egress 규칙마다 포트,
허용 CIDR은 API 서버 둘뿐
```sh
bash scripts/validate/render-tenants-and-policies.sh
```
## 라이브 drift 검사
`live-drift-check.sh`는 이 저장소의 라이브 빌드 루트를 모두 렌더하고(Phase 1·2, 관리 도구,
관측 core, Traefik trust overlay, 위 세 루트) Secret을 뺀 뒤 `kubectl diff`(서버 dry-run,
저장하지 않음)로 클러스터와 비교한다. 렌더에는 위 render 스크립트의 `--verified-output-dir`
출력을 읽기만 하는 용도로 쓴다(그 디렉터리는 스크립트가 끝날 때 지운다).
```sh
PLATFORM_HELM_BIN=/home/donghyeon/.local/bin/helm \
bash scripts/validate/live-drift-check.sh \
--accepted scripts/validate/live-drift-accepted.txt
```
- 종료 코드: 0 차이 없음, 1 차이 있음, 2 검사 자체 실패.
- `DRIFT <Kind> <ns>/<name> (+추가 -삭제) [입력 파일]`로 객체마다 한 줄을 쓴다.
`generation` 줄만 다른 것은 세지 않는다.
- `--accepted`: 알고 있는 차이를 기한과 이유를 달아 적는다. 기한이 지나면 다시 drift로 센다.
- `--textfile FILE`: `platform_live_drift_objects`, `platform_live_drift_check_success`,
`platform_live_drift_last_run_timestamp_seconds`를 Prometheus textfile 형식으로 쓴다.
- Secret 값의 차이는 보지 않는다.