Egress policy
An EgressPolicy lists the hosts outside the cluster that its pods can reach, and can add a header from a Secret to their HTTPS requests.
The egress proxy
EgressPolicy is a Kite kind, with no upstream equivalentWhen an EgressPolicy selects a pod, the node agent sends the pod’s traffic to hosts outside the cluster through a proxy on the node. The proxy allows only the hosts that the policy lists. A selected pod starts only after its node redirects the pod’s address to the proxy.
The policy does not affect traffic to other pods and to Services, which NetworkPolicy controls.
An inject rule adds a header from a Secret to the pod’s HTTPS requests to a
host, so code in the pod never has the token.
Limits
- The proxy uses HTTP/1.1 with the pod and with the host.
- SSH and database protocols cannot use an
injectrule. - A client that pins a certificate cannot use an
injectrule.
A client that cannot use an inject rule keeps using a mounted Secret.
Write a policy
apiVersion: kiteplane.dev/v1alpha1
kind: EgressPolicy
metadata:
name: ci
namespace: builds
spec:
podSelector:
matchLabels: { app: ci }
allowedHosts: ["github.com", "*.githubusercontent.com"]
inject:
- host: ci.example.com
path: /api/cache/
prefix: "Bearer "
secretKeyRef: { name: ci-tokens, key: cache }
- host: github.com
basicAuth: { username: x-access-token }
secretKeyRef: { name: ci-tokens, key: git }
Trust the egress CA
For an inject rule, the proxy ends the pod’s TLS with a certificate from the
cluster’s egress certificate authority (CA). It sets the header in place of
any header of that name that the pod sent. It then sends the request on over
TLS, and checks the host’s certificate against public roots.
So a pod with an inject rule must trust the egress CA:
-
Mount the CA in the pod spec. The cluster publishes it in the ClusterTrustBundle
kiteplane.dev:egress:cawhen a node first needs a certificate.volumes: - name: egress-ca projected: sources: - clusterTrustBundle: name: kiteplane.dev:egress:ca path: ca.crt -
Add the projected
ca.crtto the bundle your client reads, beside the public roots that a host without a rule needs.
Hosts
| Hosts and ports | Effect |
|---|---|
github.com | Ports 80 and 443 |
registry.example:5000 | Port 5000 only |
*.example.com | Every name under example.com, and not example.com itself |
* | Every host and port. Only TCP 80 and 443 go through the proxy, which needs the host’s name |
| Several policies | A pod that several policies select reaches the hosts of all of them |
| DNS | The node’s DNS server resolves cluster names and listed names, and returns REFUSED for others |
A host with an inject rule | Allowed whether allowedHosts lists it or not. ci.example.com:8443 applies to port 8443, and no port means 443 |
Inject rules
| Field | Rule |
|---|---|
path | Matches whole segments: /api/cache covers /api/cache/x, not /api/cachex. The longest match wins. No path covers every request to the host. |
header | Authorization unless the rule sets another |
prefix | Written before the Secret’s value, such as Bearer |
basicAuth | Sets Authorization: Basic from its username and the Secret’s value, and allows no header or prefix |
secretKeyRef | The Secret and key. Spaces and newlines at either end of the value are removed. Whoever writes the policy needs get on the Secret. |
Refusals and errors
| Case | Result |
|---|---|
Host is not the TLS connection’s server name | 421 |
A path with a . or .. segment | 400 |
| A WebSocket or another upgrade | The header goes on the upgrade request. After 101, bytes pass through unchanged. |
| A selected pod on the node’s network, or privileged outside gVisor or Kata | The node refuses to start it, because either one can change the node’s rules. |
| A node whose agent does not enforce EgressPolicy | The scheduler skips it: node(s) didn't enforce Pod's EgressPolicy. A pod already there waits. |
| A missing Secret or key, or no node certificate yet | The pod waits, and its status says what for. |
Next
- Networking: pod ranges, ports, Services and NetworkPolicy.
- Troubleshoot: steps for a pod that cannot reach another.