envoy-guide
Module 3 · Making It Useful·14 min·intermediate

TLS termination

Terminate HTTPS at Envoy with local certificates.

TLS in two directions

Envoy can encrypt traffic on either side of itself, and the two are configured independently:

  • DownstreamTlsContext — TLS from the client to Envoy. Lives on the listener's filter chain. This is what people usually mean by "TLS termination."
  • UpstreamTlsContext — TLS from Envoy to the backend. Lives on the cluster (transport_socket). Use this when your backends speak HTTPS or when you're doing mTLS in a service mesh.

You can mix them: HTTPS in front, plain HTTP to backends (very common at the edge), or HTTPS-everywhere with mTLS (typical inside a mesh).

Up vs Down — the most common Envoy bug

If you find yourself debugging certificate errors, the very first thing to check is whether you put the TLS config in the right place. Downstream = listener. Upstream = cluster. Reversing them is a daily occurrence.

Generate a local cert (the easy way)

The smoothest path on dev machines is mkcert, which installs a local CA trusted by your browser:

Shell
# install once
brew install mkcert nss     # macOS
# choco install mkcert       # Windows
# apt install mkcert         # Linux

mkcert -install
mkcert localhost 127.0.0.1
# produces: localhost+1.pem and localhost+1-key.pem

If mkcert isn't an option, plain openssl works too:

Shell
openssl req -x509 -newkey rsa:2048 -nodes -keyout server.key -out server.crt \
  -subj "/CN=localhost" -days 365

Self-signed: your browser will warn, but curl -k works.

The Envoy config

Take a working hello-world and add a transport_socket to the filter chain. Move the listener to port 8443 (or 443 if you have privileges).

YAML
  listeners:
  - name: https
    address:
      socket_address: { address: 0.0.0.0, port_value: 8443 }
    filter_chains:
    - filters:
      - name: envoy.filters.network.http_connection_manager
        typed_config:
          "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
          stat_prefix: ingress_https
          http_filters:
          - name: envoy.filters.http.router
            typed_config:
              "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
          route_config:
            virtual_hosts:
            - name: all
              domains: ["*"]
              routes:
              - match: { prefix: "/" }
                route: { cluster: backend }

      transport_socket:
        name: envoy.transport_sockets.tls
        typed_config:
          "@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.DownstreamTlsContext
          common_tls_context:
            tls_certificates:
            - certificate_chain: { filename: "/etc/envoy/certs/server.crt" }
              private_key:       { filename: "/etc/envoy/certs/server.key" }

Mount the certs alongside the config when you docker run:

Shell
docker run --rm -it \
  -p 8443:8443 -p 9901:9901 \
  -v "$PWD/envoy.yaml:/etc/envoy/envoy.yaml" \
  -v "$PWD/server.crt:/etc/envoy/certs/server.crt" \
  -v "$PWD/server.key:/etc/envoy/certs/server.key" \
  envoyproxy/envoy:v1.31-latest
Hands-on · HTTPS in 5 minutes
  1. Generate a cert with one of the methods above.
  2. Adapt your hello-world to the listener config above (port 8443, with the transport_socket).
  3. Run Envoy with the extra cert mounts.
  4. Test:
Shell
curl -kv https://localhost:8443/get

You should see TLS handshake lines and a 200 response. If you used mkcert, drop the -k — your local CA is trusted.

  1. Bonus: visit https://localhost:8443/clusters admin... no wait, that's port 9901 in plain HTTP. The admin interface stays unencrypted on localhost — this is normal, but reinforces "never expose 9901."
Modern TLS only, please

Envoy defaults to TLS 1.2+. To force 1.3 only, set tls_minimum_protocol_version: TLSv1_3 under common_tls_context.tls_params. There is no good reason to allow TLS 1.0 / 1.1 in 2026.

Real-world example · Public-facing edge gateway team
Problem
The platform team needs to terminate TLS for hundreds of public hostnames, each with its own cert (think: customer-branded subdomains). Restarting nginx for every cert change is unacceptable.
Envoy solution
One Envoy listener uses SNI: each filter_chain in the listener has a filter_chain_match on server_names and its own DownstreamTlsContext. A control plane (Envoy Gateway, Contour, etc.) generates the right filter chains as certs are issued, and pushes them in via xDS. No restart, no downtime, hundreds of certs per Envoy.

Up next

You've got TLS. Next we'll teach Envoy to not give up the moment a backend hiccups — timeouts, retries, and circuit breakers.

Quick check

You want Envoy to accept HTTPS from browsers and forward plain HTTP to your app. Which TLS context do you configure?

Practical task
Finish the quick check and tick off the task to unlock.
Quick checkTasks 0/3