@@ -0,0 +1,106 @@
|
||||
# -------------------------------------------------------------------
|
||||
# 1. Deny-by-default : sans règle explicite plus bas, AUCUN trafic entrant
|
||||
# ni sortant n'est autorisé pour les pods de ce namespace. C'est ce qui
|
||||
# empêche par défaut toute communication vers un autre namespace de démo
|
||||
# et vers l'API Kubernetes.
|
||||
# -------------------------------------------------------------------
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: default-deny-all
|
||||
spec:
|
||||
podSelector: {}
|
||||
policyTypes:
|
||||
- Ingress
|
||||
- Egress
|
||||
|
||||
---
|
||||
# -------------------------------------------------------------------
|
||||
# 2. Trafic intra-démo : frontend <-> backend <-> postgresql/redis, dans
|
||||
# CE namespace uniquement (le podSelector du namespaceSelector par défaut
|
||||
# de Kubernetes limite déjà à ce namespace : pas de namespaceSelector ici
|
||||
# équivaut à "même namespace").
|
||||
# -------------------------------------------------------------------
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: allow-intra-namespace
|
||||
spec:
|
||||
podSelector: {}
|
||||
policyTypes:
|
||||
- Ingress
|
||||
- Egress
|
||||
ingress:
|
||||
- from:
|
||||
- podSelector: {}
|
||||
egress:
|
||||
- to:
|
||||
- podSelector: {}
|
||||
|
||||
---
|
||||
# -------------------------------------------------------------------
|
||||
# 3. Ingress externe autorisé : uniquement depuis le Traefik partagé
|
||||
# (aucune autre démo, aucun autre client, ne peut ouvrir de connexion
|
||||
# directe vers les pods de cette démo).
|
||||
# -------------------------------------------------------------------
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: allow-ingress-from-traefik
|
||||
spec:
|
||||
podSelector: {}
|
||||
policyTypes:
|
||||
- Ingress
|
||||
ingress:
|
||||
- from:
|
||||
- namespaceSelector:
|
||||
matchLabels:
|
||||
kubernetes.io/metadata.name: {{ .Values.traefikNamespace }}
|
||||
|
||||
---
|
||||
# -------------------------------------------------------------------
|
||||
# 4. DNS uniquement vers kube-system, port 53. C'est la SEULE ouverture vers
|
||||
# kube-system : aucun accès à autre chose dans ce namespace, et l'API
|
||||
# server (kubernetes.default.svc, namespace "default") n'est jamais
|
||||
# autorisé nulle part dans ce chart -> bloqué par le deny-by-default.
|
||||
# -------------------------------------------------------------------
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: allow-egress-dns
|
||||
spec:
|
||||
podSelector: {}
|
||||
policyTypes:
|
||||
- Egress
|
||||
egress:
|
||||
- to:
|
||||
- namespaceSelector:
|
||||
matchLabels:
|
||||
kubernetes.io/metadata.name: {{ .Values.kubeSystemNamespace }}
|
||||
ports:
|
||||
- protocol: UDP
|
||||
port: 53
|
||||
- protocol: TCP
|
||||
port: 53
|
||||
|
||||
---
|
||||
# -------------------------------------------------------------------
|
||||
# 5. Internet public sortant (webhooks Telegram/NowPayments, GPS TomTom...),
|
||||
# en excluant les plages privées : ça couvre par construction l'IP de
|
||||
# l'API server et celles des autres namespaces, sans avoir besoin de la
|
||||
# connaître explicitement.
|
||||
# -------------------------------------------------------------------
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: allow-egress-internet
|
||||
spec:
|
||||
podSelector: {}
|
||||
policyTypes:
|
||||
- Egress
|
||||
egress:
|
||||
- to:
|
||||
- ipBlock:
|
||||
cidr: 0.0.0.0/0
|
||||
except:
|
||||
{{- toYaml .Values.blockedEgressCIDRs | nindent 14 }}
|
||||
Reference in New Issue
Block a user