networkpolicy.yaml 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # NetworkPolicy (task 46). Default-deny for the app pods.
  2. #
  3. # Selecting the pods below with BOTH policy types makes this a default-deny
  4. # for them in any CNI that enforces NetworkPolicy (Calico, Cilium, ...): only
  5. # the flows listed here are admitted, everything else is dropped. A CNI that
  6. # ignores NetworkPolicy does not apply this control; verify the cluster CNI.
  7. #
  8. # Egress:
  9. # - DNS only, to the `kube-system` namespace on port 53 (UDP + TCP). Adjust if
  10. # CoreDNS runs elsewhere; NodeLocal DNSCache also lives in `kube-system`, so
  11. # it is covered.
  12. # - Postgres (5432) and Redis (6379) anywhere else, with link-local
  13. # `169.254.0.0/16` excluded so the cloud metadata endpoint
  14. # (`169.254.169.254`) can never be reached. If Postgres/Redis run in-cluster,
  15. # tighten the port-scoped `ipBlock` to their namespace/pod selector.
  16. # - Everything else, including the Kubernetes API and arbitrary HTTPS
  17. # exfiltration, is denied. The app never calls the API and runs with
  18. # `automountServiceAccountToken: false`.
  19. #
  20. # Ingress: only the public TLS port (8080) and the plaintext health port
  21. # (8081) are reachable. NetworkPolicy cannot name a Service (the Service is
  22. # virtual, and traffic arrives from the L4 gateway or the kubelet), so the
  23. # source is unrestricted but the ports are not. The Service keeps publishing
  24. # 8080 only; 8081 must never be internet-facing.
  25. apiVersion: networking.k8s.io/v1
  26. kind: NetworkPolicy
  27. metadata:
  28. name: d-oauth-server
  29. namespace: d-oauth
  30. labels:
  31. app.kubernetes.io/name: d-oauth-server
  32. app.kubernetes.io/part-of: d-oauth
  33. spec:
  34. podSelector:
  35. matchLabels:
  36. app.kubernetes.io/name: d-oauth-server
  37. policyTypes:
  38. - Ingress
  39. - Egress
  40. ingress:
  41. - ports:
  42. - port: 8080
  43. protocol: TCP
  44. - port: 8081
  45. protocol: TCP
  46. egress:
  47. # DNS (kube-dns / CoreDNS in kube-system).
  48. - to:
  49. - namespaceSelector:
  50. matchLabels:
  51. kubernetes.io/metadata.name: kube-system
  52. ports:
  53. - port: 53
  54. protocol: UDP
  55. - port: 53
  56. protocol: TCP
  57. # Postgres + Redis ports only; link-local (metadata) excluded.
  58. - to:
  59. - ipBlock:
  60. cidr: 0.0.0.0/0
  61. except:
  62. - 169.254.0.0/16
  63. ports:
  64. - port: 5432
  65. protocol: TCP
  66. - port: 6379
  67. protocol: TCP