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.
2.0 KiB
2.0 KiB
keycloak namespace NetworkPolicy
2026-11-11 점검 전 keycloak namespace에는 Keycloak Operator가 만든 ingress 정책 하나뿐이었다.
Keycloak 파드와 Operator 파드의 egress는 막혀 있지 않았다. 다른 플랫폼 namespace처럼 기본 차단에
필요한 것만 연다.
| 정책 | 대상 | 허용 |
|---|---|---|
keycloak-default-deny |
모든 파드 | ingress·egress 기본 차단 |
keycloak-allow-dns |
모든 파드 | kube-dns 53 |
keycloak-allow-platform-postgres |
모든 파드(서버와 realm import Job) | platform-data Postgres 5432 |
keycloak-allow-cluster-peers |
Keycloak 파드 | 같은 Keycloak 파드 JGroups 7800·57800 |
keycloak-operator-allow-egress |
Operator | API 서버(10.43.0.1:443, 192.168.0.107:6443), Keycloak 8080·9000 |
- Keycloak 파드의 ingress는 계속 Keycloak CR
spec.networkPolicy로 Operator가 만드는keycloak-network-policy가 소유한다(Traefik 8080, 관리 9000, JGroups). - 바깥(인터넷)으로 나가는 길은 없다. 2026-11-12에 repo와 Keycloak CR에 SMTP·외부 IdP 설정이 없고, Keycloak 파드의 열린 TCP 연결이 Postgres뿐인 것을 확인했다. SMTP나 외부 IdP를 붙이면 여기에 egress를 더해야 한다(안 더하면 메일·외부 로그인만 조용히 실패한다).
- kubelet probe는 노드에서 오므로 막히지 않는다.
적용과 확인
bash scripts/validate/render-tenants-and-policies.sh
kubectl kustomize infrastructure/networking/keycloak | kubectl diff -f -
kubectl apply -k infrastructure/networking/keycloak
적용 뒤 확인(모두 통과해야 한다):
kubectl -n keycloak get pods
curl -fsS -o /dev/null -w '%{http_code}\n' https://id.learn.hyeonworks.com/realms/hyeonworks/.well-known/openid-configuration
kubectl -n keycloak logs deploy/keycloak-operator --since=5m | grep -i -E 'error|exception|timeout' || echo no-operator-errors
되돌리기: kubectl delete -k infrastructure/networking/keycloak(Operator 정책은 남는다).