Egress to named destinations: stop the data exfil path

Egress to named destinations: stop the data exfil path

Ingress rules decide who can reach a pod. Egress rules decide where a pod can send - and that's the direction that matters once a workload is compromised, because exfiltration and command-and-control are outbound. Here we default-deny the frontend's egress and allow exactly two destinations, neither of them a hard-coded IP: an approved external network and an in-cluster Service.

What you'll learn

The policy

apiVersion: projectcalico.org/v3
kind: GlobalNetworkPolicy
metadata:
  name: frontend-egress-allowlist
spec:
  selector: env == 'prod' && app == 'frontend'
  types:
    - Egress
  egress:
    - action: Allow
      destination:
        selector: scope == 'approved-egress'
    - action: Allow
      protocol: TCP
      destination:
        services:
          name: backend-svc
          namespace: prod

What to observe

Allowed

Denied

The trap is a bare nets: rule with a wide CIDR (or worse, 0.0.0.0/0). It "works" today and quietly permits exfiltration to anywhere in that range. Name a labelled set instead: the allowlist becomes explicit, auditable, and editable in one place.

Recap

Egress allowlisting - to a labelled CIDR set and to Services - is how you decide where data may leave to, the control that bites during a breach. We've now secured the apps from every angle. Next we protect the layer underneath them: the cluster infrastructure, so a popped pod can't reach the control plane.