feat(tenants): declare tech-log platform objects and keycloak egress #4

Merged
donghyeon.kang merged 4 commits from donghyeon.kang/w6-tenant-and-policies AGit into main 2026-11-11 15:43:43 +00:00
Owner

무엇을, 왜

2026-11-11 k3s 성숙도 점검(docs/reviews/2026-11-11-k3s-maturity-review.md) 7절의 권하는 안 중 재시작이 없는 것을 넣는다. 총괄이 정한 8절 결정 2(tech-log 플랫폼 쪽 객체는 platform-core tenant로)에 따른다.

  1. services/tenants/techlog: kubectl apply로만 들어가 있던 tech-log의 플랫폼 쪽 객체 11개를 라이브 last-applied 그대로 선언한다. DB Role·Database, platform-data·object-storage·observability의 NetworkPolicy, Probe 둘, PrometheusRule, 대시보드, Namespace hyeonworks-prod. Namespace에는 PSA enforce=baseline·warn=restricted·audit=restricted를 붙인다.
  2. services/priority-classes: platform-critical(1000000)과 platform-low(-1000, 선점 안 함). 만들기만 하고 아직 아무 파드에도 붙이지 않는다.
  3. infrastructure/networking/keycloak: keycloak namespace 기본 차단 + egress 허용 목록(DNS, Postgres, JGroups, Operator → API 서버·Keycloak 관리 포트). Keycloak ingress는 그대로 Operator 정책이 소유한다.
  4. scripts/validate/render-tenants-and-policies.sh(정적 불변식)와 scripts/validate/live-drift-check.sh(모든 라이브 루트 렌더 → Secret 제외 → kubectl diff 서버 dry-run, 받아들인 차이 목록, textfile 지표).

고른 방법과 버린 대안

  • tenant 객체는 새로 쓰지 않고 라이브 last-applied를 옮겼다. 그래서 적용해도 Namespace 라벨 말고는 바뀌는 것이 없다.
  • PSA enforce=restricted는 버렸다. 서버 dry-run에서 tech-log 파드 셋이 모두 위반한다. baseline은 위반 0이다. tech-log securityContext(w1, tech-log deploy/)가 고쳐지면 올린다.
  • Keycloak egress에 공개 443을 열지 않았다. repo와 Keycloak CR에 SMTP·외부 IdP 설정이 없고, keycloak-0의 열린 TCP 연결은 Postgres뿐이었다(2026-11-12). 나중에 붙이면 egress를 더해야 한다고 README에 적었다.
  • PriorityClass를 이 PR에서 붙이지 않았다. 붙이면 파드가 재시작되므로 k3s 재시작 창(다음 PR)에 한다.
  • drift 검사는 호스트에서 사람이 돌리는 스크립트로 두었다. 클러스터 안 CronJob으로 돌리면 모든 namespace에 patch 권한(서버 dry-run에 필요)이 있어야 해서 버렸다. 주기 실행과 경보는 node-exporter textfile 수집기가 필요해 w1과 정한 뒤 다음 PR에서 한다.
  • 파일 소유: w1 범위(services/platform-postgres/**, postgres-backup, host README·docker·systemd, core-rules, alerting, node-exporter)는 건드리지 않았다. pg_hba는 w1이 넣는다.

위험과 영향

  • tenant: 라이브와 같은 내용이라 적용 위험이 없다. 바뀌는 것은 hyeonworks-prod 라벨 넷뿐이고, enforce=baseline은 지금 파드를 내보내지 않는다(새 파드만 검사).
  • keycloak 정책: 빠진 의존이 있으면 모든 서비스의 로그인이 깨진다. 병합 뒤 내가 적용하고 README의 확인(OIDC discovery 200, keycloak-0에서 Postgres 새 TCP 연결 성공·인터넷 연결 실패, Operator 로그 오류 없음)을 돌린다. 하나라도 실패하면 kubectl delete -k infrastructure/networking/keycloak로 바로 되돌린다.
  • PriorityClass: 만들기만 해서 파드 변화 없음.
  • drift 검사: 읽기만 한다(서버 dry-run). render 스크립트의 --verified-output-dir 출력을 읽기 전용으로 쓰는 두 번째 소비자라는 점을 scripts/validate/README.md에 적었다.

검증

desktop, Kustomize 5.8.1, Helm 3.19.4. 로그: 공유 노트 k3s-w6-pr-a-verify.log.

$ bash scripts/validate/render-tenants-and-policies.sh
tech-log tenant: 11 objects; PriorityClasses: 2; keycloak NetworkPolicies: 5
TENANTS AND POLICIES STATIC RENDER PASS                                    (exit 0)

$ kubectl kustomize services/tenants/techlog | kubectl diff -f -          # 서버 dry-run
v1.Namespace..hyeonworks-prod 만 다름(+PSA 라벨)

$ kubectl label --dry-run=server --overwrite ns hyeonworks-prod pod-security.kubernetes.io/enforce=baseline
namespace/hyeonworks-prod labeled (server dry run)                         (경고 없음)

$ bash scripts/validate/live-drift-check.sh --accepted scripts/validate/live-drift-accepted.txt
SUMMARY drift=9 accepted=8                                                 (exit 1)
  • 남은 drift 9개는 PR #3의 Traefik resources(1)와 이 PR의 새 객체(8: Namespace 라벨, PriorityClass 2, keycloak 정책 5)다. 둘을 적용하면 0이 된다.
  • 받아들인 차이 8개(기한 2026-11-30): pg_hba(w1), DatabaseRole 기본값 필드 표기 2, Keycloak Operator build-timestamp 라벨 3, prometheus-operator·kube-state-metrics 이미지 문자열 2. 뒤의 다섯은 적용하면 파드가 재시작되므로 재시작 창에 푼다.
  • render-phase1.sh 통과(이 PR은 그 루트를 바꾸지 않음).

리뷰어가 볼 곳

  • infrastructure/networking/keycloak/network-policies.yaml: 허용 목록이 너무 좁지 않은지.
  • services/tenants/techlog/namespace.yaml: PSA 라벨.
  • scripts/validate/live-drift-check.sh: diff 헤더 파싱과 종료 코드.

관련

  • docs/reviews/2026-11-11-k3s-maturity-review.md 4.3·7.2·7.5·7.7절, 8절 결정 2
  • 공유 노트 k3s-maturity-review.md 2단계
## 무엇을, 왜 2026-11-11 k3s 성숙도 점검(`docs/reviews/2026-11-11-k3s-maturity-review.md`) 7절의 권하는 안 중 **재시작이 없는 것**을 넣는다. 총괄이 정한 8절 결정 2(tech-log 플랫폼 쪽 객체는 platform-core tenant로)에 따른다. 1. `services/tenants/techlog`: `kubectl apply`로만 들어가 있던 tech-log의 플랫폼 쪽 객체 11개를 라이브 `last-applied` 그대로 선언한다. DB Role·Database, platform-data·object-storage·observability의 NetworkPolicy, Probe 둘, PrometheusRule, 대시보드, Namespace `hyeonworks-prod`. Namespace에는 PSA `enforce=baseline`·`warn=restricted`·`audit=restricted`를 붙인다. 2. `services/priority-classes`: `platform-critical`(1000000)과 `platform-low`(-1000, 선점 안 함). 만들기만 하고 아직 아무 파드에도 붙이지 않는다. 3. `infrastructure/networking/keycloak`: keycloak namespace 기본 차단 + egress 허용 목록(DNS, Postgres, JGroups, Operator → API 서버·Keycloak 관리 포트). Keycloak ingress는 그대로 Operator 정책이 소유한다. 4. `scripts/validate/render-tenants-and-policies.sh`(정적 불변식)와 `scripts/validate/live-drift-check.sh`(모든 라이브 루트 렌더 → Secret 제외 → `kubectl diff` 서버 dry-run, 받아들인 차이 목록, textfile 지표). ## 고른 방법과 버린 대안 - tenant 객체는 새로 쓰지 않고 라이브 `last-applied`를 옮겼다. 그래서 적용해도 Namespace 라벨 말고는 바뀌는 것이 없다. - PSA `enforce=restricted`는 버렸다. 서버 dry-run에서 tech-log 파드 셋이 모두 위반한다. `baseline`은 위반 0이다. tech-log securityContext(w1, tech-log `deploy/`)가 고쳐지면 올린다. - Keycloak egress에 공개 443을 열지 않았다. repo와 Keycloak CR에 SMTP·외부 IdP 설정이 없고, keycloak-0의 열린 TCP 연결은 Postgres뿐이었다(2026-11-12). 나중에 붙이면 egress를 더해야 한다고 README에 적었다. - PriorityClass를 이 PR에서 붙이지 않았다. 붙이면 파드가 재시작되므로 k3s 재시작 창(다음 PR)에 한다. - drift 검사는 호스트에서 사람이 돌리는 스크립트로 두었다. 클러스터 안 CronJob으로 돌리면 모든 namespace에 patch 권한(서버 dry-run에 필요)이 있어야 해서 버렸다. 주기 실행과 경보는 node-exporter textfile 수집기가 필요해 w1과 정한 뒤 다음 PR에서 한다. - 파일 소유: w1 범위(`services/platform-postgres/**`, postgres-backup, host README·docker·systemd, core-rules, alerting, node-exporter)는 건드리지 않았다. pg_hba는 w1이 넣는다. ## 위험과 영향 - tenant: 라이브와 같은 내용이라 적용 위험이 없다. 바뀌는 것은 `hyeonworks-prod` 라벨 넷뿐이고, `enforce=baseline`은 지금 파드를 내보내지 않는다(새 파드만 검사). - keycloak 정책: 빠진 의존이 있으면 모든 서비스의 로그인이 깨진다. 병합 뒤 내가 적용하고 README의 확인(OIDC discovery 200, keycloak-0에서 Postgres 새 TCP 연결 성공·인터넷 연결 실패, Operator 로그 오류 없음)을 돌린다. 하나라도 실패하면 `kubectl delete -k infrastructure/networking/keycloak`로 바로 되돌린다. - PriorityClass: 만들기만 해서 파드 변화 없음. - drift 검사: 읽기만 한다(서버 dry-run). render 스크립트의 `--verified-output-dir` 출력을 읽기 전용으로 쓰는 두 번째 소비자라는 점을 `scripts/validate/README.md`에 적었다. ## 검증 desktop, Kustomize 5.8.1, Helm 3.19.4. 로그: 공유 노트 `k3s-w6-pr-a-verify.log`. ```text $ bash scripts/validate/render-tenants-and-policies.sh tech-log tenant: 11 objects; PriorityClasses: 2; keycloak NetworkPolicies: 5 TENANTS AND POLICIES STATIC RENDER PASS (exit 0) $ kubectl kustomize services/tenants/techlog | kubectl diff -f - # 서버 dry-run v1.Namespace..hyeonworks-prod 만 다름(+PSA 라벨) $ kubectl label --dry-run=server --overwrite ns hyeonworks-prod pod-security.kubernetes.io/enforce=baseline namespace/hyeonworks-prod labeled (server dry run) (경고 없음) $ bash scripts/validate/live-drift-check.sh --accepted scripts/validate/live-drift-accepted.txt SUMMARY drift=9 accepted=8 (exit 1) ``` - 남은 drift 9개는 PR #3의 Traefik resources(1)와 이 PR의 새 객체(8: Namespace 라벨, PriorityClass 2, keycloak 정책 5)다. 둘을 적용하면 0이 된다. - 받아들인 차이 8개(기한 2026-11-30): pg_hba(w1), DatabaseRole 기본값 필드 표기 2, Keycloak Operator build-timestamp 라벨 3, prometheus-operator·kube-state-metrics 이미지 문자열 2. 뒤의 다섯은 적용하면 파드가 재시작되므로 재시작 창에 푼다. - `render-phase1.sh` 통과(이 PR은 그 루트를 바꾸지 않음). ## 리뷰어가 볼 곳 - `infrastructure/networking/keycloak/network-policies.yaml`: 허용 목록이 너무 좁지 않은지. - `services/tenants/techlog/namespace.yaml`: PSA 라벨. - `scripts/validate/live-drift-check.sh`: diff 헤더 파싱과 종료 코드. ## 관련 - `docs/reviews/2026-11-11-k3s-maturity-review.md` 4.3·7.2·7.5·7.7절, 8절 결정 2 - 공유 노트 `k3s-maturity-review.md` 2단계
donghyeon.kang added 4 commits 2026-11-11 15:31:49 +00:00
Every platform pod runs at priority 0. During the 2026-11-09 disk
eviction the tech-log production pods were ranked with Grafana and
kube-state-metrics. The kubelet ranks evictions by usage over requests
and then by priority, so without classes the database and the
production app have no head start.

Add two classes and attach nothing yet: platform-critical (1000000,
may preempt) for platform-postgres, Gitea, Keycloak and tech-log, and
platform-low (-1000, never preempts) for Grafana, pgAdmin, Loki and
Tempo. Neither is the global default, so no pod changes silently.

Risk: creating the classes changes no pod. Attaching them restarts the
pods, so that is left for the k3s restart window.

Verification: render-tenants-and-policies.sh (added later in this
series) checks the values, the preemption policy and globalDefault.
The keycloak namespace only has the ingress policy the Keycloak
Operator creates. Neither the Keycloak pod nor the Operator pod has any
egress restriction, unlike every other platform namespace.

Add a namespace-wide default deny and allow only what is used: DNS,
platform-postgres 5432 (server and realm-import jobs), JGroups between
Keycloak pods, and for the Operator the API server and the Keycloak
management ports. Keycloak ingress stays owned by the Operator policy.

Rejected: allowing public 443 like Gitea does. Neither the repository
nor the Keycloak CR configures SMTP or an external identity provider,
and the only open TCP connections from keycloak-0 on 2026-11-12 were to
PostgreSQL. Adding SMTP or an IdP later needs a new egress rule; the
README says so.

Risk: a missed dependency would break logins for every service. The
README lists the post-apply checks (OIDC discovery, a new TCP
connection to Postgres from keycloak-0, Operator logs) and the one-line
rollback.

Verification: render and kubectl diff only add the five policies.
The tech-log tenant needs objects inside platform namespaces: its
database and role, ingress to Postgres and AIStor, blackbox probes,
alert rules, a dashboard and two observability NetworkPolicies. They
were only ever applied with kubectl and no repository holds them, so a
deleted object cannot be recreated and a platform re-apply can drop
tech-log access without anyone noticing.

Declare them in services/tenants/techlog, copied from each object's
last-applied configuration. The dashboard follows the repository's
dashboard pattern (JSON file + configMapGenerator, same name, same
labels). The hyeonworks-prod Namespace moves here as the tenant
boundary and gets PSA enforce=baseline, warn/audit=restricted.

Rejected: enforce=restricted now. A server dry-run shows all three
tech-log pods would violate it; baseline has zero violations.

Risk: the render matches the live objects exactly except the added PSA
labels. The pg_hba rules and the Secret stay out of this root (Cluster
owner and Git policy).

Verification (desktop):
- render-tenants-and-policies.sh passes.
- kubectl diff of the render shows only the Namespace PSA labels.
- kubectl label --dry-run=server enforce=baseline: no warnings.
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.
donghyeon.kang merged commit b484110b6b into main 2026-11-11 15:43:43 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: donghyeon.kang/platform-core#4