KiteGitHub
Quickstart

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 equivalent
A selected pod's TCP traffic on ports 80 and 443, and on each port a policy lists, goes to a proxy in kite-agent, which reads the TLS server name or the HTTP Host header. A host in allowedHosts gets a connection by name. A host with an inject rule gets the request with a header from a Secret. Any other host gets 403, or its TLS connection is closed. UDP and ports that no policy lists are dropped at the node. Selected podin an EgressPolicyTCP 80, 443and listed portsNode agent proxyreads the host name:TLS server name or HostHost in allowedHostsconnects to it by name,on the port the pod asked forHost with an inject ruleends TLS, adds the header froma Secret, sends it on over TLSAny other host or port403 to an HTTP request,or the TLS connection closesUDP, and ports that no policy listsdropped at the node, before the proxy
Fig. 1 The proxy decides by the host that the pod names. It connects to a listed host by name, and skips an address that only the node can reach: loopback, the node's own addresses, link-local such as the cloud's metadata service, multicast and broadcast. It also skips the cluster's own addresses, its pods and its Services, which NetworkPolicy governs. A host with no other address gets no connection.

When 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 inject rule.
  • A client that pins a certificate cannot use an inject rule.

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:

  1. Mount the CA in the pod spec. The cluster publishes it in the ClusterTrustBundle kiteplane.dev:egress:ca when a node first needs a certificate.

    volumes:
      - name: egress-ca
        projected:
          sources:
            - clusterTrustBundle:
                name: kiteplane.dev:egress:ca
                path: ca.crt
  2. Add the projected ca.crt to the bundle your client reads, beside the public roots that a host without a rule needs.

Hosts

Hosts and portsEffect
github.comPorts 80 and 443
registry.example:5000Port 5000 only
*.example.comEvery 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 policiesA pod that several policies select reaches the hosts of all of them
DNSThe node’s DNS server resolves cluster names and listed names, and returns REFUSED for others
A host with an inject ruleAllowed whether allowedHosts lists it or not. ci.example.com:8443 applies to port 8443, and no port means 443

Inject rules

FieldRule
pathMatches whole segments: /api/cache covers /api/cache/x, not /api/cachex. The longest match wins. No path covers every request to the host.
headerAuthorization unless the rule sets another
prefixWritten before the Secret’s value, such as Bearer
basicAuthSets Authorization: Basic from its username and the Secret’s value, and allows no header or prefix
secretKeyRefThe 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

CaseResult
Host is not the TLS connection’s server name421
A path with a . or .. segment400
A WebSocket or another upgradeThe 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 KataThe node refuses to start it, because either one can change the node’s rules.
A node whose agent does not enforce EgressPolicyThe 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 yetThe 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.