Skip to content
Tutorials Center
My learning

Topics

Lesson 25 of 36 ยท Gateways and Ingress

Istio Egress Control: ServiceEntry, REGISTRY_ONLY and Egress Gateway

Control outbound traffic from your mesh: outboundTrafficPolicy modes, ServiceEntry for external APIs, routing through an egress gateway, and why egress control matters for security.

Most attention goes to traffic coming in, but traffic going out matters just as much. A compromised pod that can call any address on the internet can leak data or download malware. Istio lets you see, restrict and funnel outbound calls, so that only the destinations you approved are reachable and so that a single, well-known address represents your cluster to the outside world.

The product cannot run on this site: configuration is read-only and Python stand-ins model the policy decisions.

What happens by default

The sidecar's setting outboundTrafficPolicy.mode decides what to do with a call to a host that is not in the mesh registry:

  • ALLOW_ANY (default): the call passes through as plain TCP. You get a basic TCP metric under the name PassthroughCluster, but no HTTP routing, no retries and no HTTP telemetry.
  • REGISTRY_ONLY: only hosts known to the mesh are reachable; anything else is blocked and fails with a 502 or connection reset (the response flag is often UF or the cluster is BlackHoleCluster).
Terminal
istioctl install --set meshConfig.outboundTrafficPolicy.mode=REGISTRY_ONLY
kubectl get configmap istio -n istio-system -o jsonpath='{.data.mesh}' | grep -A1 outboundTrafficPolicy

REGISTRY_ONLY is the safer posture, and it is what makes allow-listing possible.

ServiceEntry: add an external service to the registry

A ServiceEntry tells Istio about a destination that does not live in Kubernetes. After you create one, the mesh treats it like a service: you get telemetry, and you can attach VirtualServices and DestinationRules to it (timeouts, retries, TLS settings).

YAML
apiVersion: networking.istio.io/v1
kind: ServiceEntry
metadata:
  name: payments-api
  namespace: shop
spec:
  hosts:
    - api.payments.example.com
  ports:
    - number: 443
      name: https
      protocol: TLS
  resolution: DNS
  location: MESH_EXTERNAL

The fields: hosts is the DNS name; ports gives protocol (use TLS when the app itself encrypts and the proxy should only match on SNI; use HTTP and a DestinationRule for origination, described next); resolution is DNS, STATIC (with endpoints) or NONE; location is MESH_EXTERNAL or MESH_INTERNAL (for VMs you manage).

TLS origination

Application code often prefers to call plain http://api.example.com and let the proxy upgrade the connection. This is TLS origination: the proxy opens the TLS connection. The benefit is full HTTP visibility and policy before encryption. Define the ServiceEntry with port 80 protocol HTTP and a targetPort: 443, then add a DestinationRule with trafficPolicy.tls.mode: SIMPLE.

YAML
apiVersion: networking.istio.io/v1
kind: DestinationRule
metadata:
  name: payments-tls
spec:
  host: api.payments.example.com
  trafficPolicy:
    portLevelSettings:
      - port:
          number: 80
        tls:
          mode: SIMPLE

Egress gateway: one controlled exit

An egress gateway is an Envoy deployment at the edge that outbound traffic is forced through. Reasons to use one:

  • A fixed set of nodes with known IP addresses, so partners can allow-list your source addresses.
  • Central audit logs and policy for every external call.
  • Defense in depth: combined with Kubernetes NetworkPolicy that only lets the gateway talk to the internet, a pod that bypasses its sidecar still cannot reach the outside.

The route has two legs: sidecar to egress gateway (inside the mesh, mTLS), then gateway to the external host.

flowchart LR
  A["app pod + sidecar"] -->|"mTLS"| EG["egress gateway"]
  EG -->|"HTTPS"| X["api.payments.example.com"]
  A -. "blocked by NetworkPolicy" .-> X

The dotted path is what you forbid with a NetworkPolicy so nothing can skip the gateway.

A sketch of the configuration: a Gateway on the egress gateway for the external host, a DestinationRule with a subset, and a VirtualService with two routes (mesh to gateway, gateway to the external host).

YAML
apiVersion: networking.istio.io/v1
kind: VirtualService
metadata:
  name: via-egress
spec:
  hosts: [api.payments.example.com]
  gateways: [mesh, istio-egressgateway]
  tls:
    - match:
        - gateways: [mesh]
          port: 443
          sniHosts: [api.payments.example.com]
      route:
        - destination: { host: istio-egressgateway.istio-system.svc.cluster.local, port: { number: 443 } }
    - match:
        - gateways: [istio-egressgateway]
          port: 443
          sniHosts: [api.payments.example.com]
      route:
        - destination: { host: api.payments.example.com, port: { number: 443 } }

Sidecars are not a security boundary by themselves: an application that avoids the proxy (for example, by running as the proxy's user id or using host networking) can bypass it. Pair egress control with NetworkPolicies or your cloud's firewall.

Try it: model the two policy modes

Python ALLOW_ANY versus REGISTRY_ONLY

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Try it: build an allow-list from observed calls

A useful migration path is to observe what workloads call under ALLOW_ANY, then generate ServiceEntries before switching to REGISTRY_ONLY.

Python Generate ServiceEntry stubs

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Review the output before applying it: observation shows what is called, not what is legitimate.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does REGISTRY_ONLY do?

    Only hosts known through services or ServiceEntries are reachable.
  2. 2. What is TLS origination?

    With origination the sidecar upgrades the outbound connection, giving HTTP-level visibility.
  3. 3. Why pair an egress gateway with a NetworkPolicy?

    Sidecars are not a hard security boundary; the network layer enforces that all egress passes the gateway.
  4. 4. Which resource adds an external API to the mesh registry?

    A ServiceEntry describes hosts, ports and resolution for services outside Kubernetes.

Summary

  • ALLOW_ANY passes unknown outbound traffic as plain TCP; REGISTRY_ONLY blocks it.
  • A ServiceEntry adds external hosts and unlocks telemetry and policies for them.
  • TLS origination lets the proxy encrypt outbound HTTP.
  • An egress gateway gives one audited exit with stable IPs; enforce it with NetworkPolicies.

Next: Istio and the Kubernetes Gateway API