Gitfed
bastien-mrq/gitfed / deploy / k8s / networkpolicy.yaml
# Egress hardening: gitfed only ever needs to reach the public internet (to
# fetch other instances' /.well-known/gitfed.json during federation) plus
# cluster DNS. This policy blocks outbound traffic to private / internal
# ranges, so even if the application-level anti-SSRF guard (see
# internal/federation/wellknown.go) were bypassed, a crafted federation target
# still couldn't reach cluster-internal or link-local (cloud-metadata)
# addresses. Ingress is left to the ingress controller / Service.
#
# NOTE: requires a CNI that enforces NetworkPolicy (Cilium, Calico, ...).
# k3s' default flannel does NOT enforce it — deploy a policy-capable CNI or
# treat this as documentation of intent.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: gitfed-egress
  namespace: gitfed
spec:
  podSelector:
    matchLabels:
      app: gitfed
  policyTypes: [Egress]
  egress:
    # Cluster DNS resolution.
    - to:
        - namespaceSelector: {}
      ports:
        - protocol: UDP
          port: 53
        - protocol: TCP
          port: 53
    # Public internet on 443 (federation well-known fetch), excluding all
    # private, loopback, link-local and CGNAT ranges.
    - to:
        - ipBlock:
            cidr: 0.0.0.0/0
            except:
              - 10.0.0.0/8
              - 172.16.0.0/12
              - 192.168.0.0/16
              - 169.254.0.0/16
              - 127.0.0.0/8
              - 100.64.0.0/10
      ports:
        - protocol: TCP
          port: 443