Skip to content

Restrict egress

List what an agent may reach. Everything else is dropped at the pod, DNS included.

spec:
egress:
fqdns:
- matchName: api.github.com
ports: [443]
- matchPattern: "*.githubusercontent.com"
endpoints:
- namespace: vault
selector:
matchLabels:
app.kubernetes.io/name: vault
ports: [8200]
cidrs:
- cidr: 10.20.0.0/16
ports: [5432]

If the policy sets models or mcp, egress to the gateway is added for you.

With Cilium

Leash writes a CiliumNetworkPolicy with toFQDNs rules, plus a DNS rule that only lets the pod look up the names you allowed. A lookup of anything else gets no answer.

Without Cilium

Standard NetworkPolicy can’t match domain names. Leash still applies endpoint and CIDR rules, leaves the fqdns rules out so they fail closed, and sets the Degraded condition naming what it couldn’t enforce.

Watch for leaks

Network policies add up: any other policy that selects the same pods and allows egress widens what they can reach. Leash checks the NetworkPolicies (and, with Cilium, CiliumNetworkPolicies) in the namespace, and reports EgressWidened on the AgentPolicy, naming them:

Terminal window
$ kubectl -n agents get agentpolicy claude-agent \
-o jsonpath='{.status.conditions[?(@.type=="EgressWidened")].message}'
NetworkPolicy/allow-all-egress also allow egress from these agents, so they can reach more than this policy allows, even while frozen

kubectl leash status shows it too.

DNS and ndots

With the default ndots:5, a lookup of api.github.com first tries in-cluster search domains, which Cilium’s DNS proxy refuses. Set ndots to 1 on agent pods:

spec:
dnsConfig:
options:
- name: ndots
value: "1"