Secure the perimeter with MeshPassthrough

Uses: Kong Mesh
TL;DR

On a control plane that sets restrictOutbound to false, apply a MeshPassthrough policy to:

  1. Block unknown destinations with passthroughMode: None.
  2. Allow specific destinations with passthroughMode: Matched and appendMatch entries (for example, httpbin.konghq.com on port 80).
  3. Keep one record of the external destinations your workloads can reach, so you can audit them.

Prerequisites

This page is part of the Kong Mesh scenarios: the Kong Air journey series.

Complete the previous page, Send traffic between zones before completing this page.

The Kong Air mesh starts open: its control plane sets restrictOutbound to false, so a sidecar forwards traffic to any external destination. In this guide, close the perimeter with a MeshPassthrough policy, then update the same policy to allow only the external destinations that Kong Air needs.

To learn more about what this guide does, read the following reference pages:

Record the baseline

Confirm that check-in-api reaches an external destination before any policy exists. Pick a destination that your cluster can resolve and reach, so that you can tell a policy block from a DNS failure later:

kubectl exec -n kong-air-production deploy/check-in-api -- wget -q -T 5 -O- http://httpbin.konghq.com/ip

The command prints the IP address that httpbin.konghq.com saw:

{
  "origin": "203.0.113.25"
}

Close the perimeter

  1. Create a kong-air-perimeter policy with passthroughMode: None:

    kubectl apply -f - <<'EOF'
    apiVersion: kuma.io/v1alpha1
    kind: MeshPassthrough
    metadata:
      name: kong-air-perimeter
      namespace: kong-air-production
      labels:
        kuma.io/mesh: kong-air-mesh
    spec:
      targetRef:
        kind: Mesh
      default:
        passthroughMode: None
    EOF
  2. Call the same destination again:

    kubectl exec -n kong-air-production deploy/check-in-api -- wget -q -T 5 -O- http://httpbin.konghq.com/ip

    The command fails with a non-zero exit status and prints no response body. The Kong Air proxies in kong-air-production now reach only the destinations that the mesh knows about.

Allow selected destinations

Update kong-air-perimeter to passthroughMode: Matched, so only the destinations in appendMatch pass:

kubectl apply -f - <<'EOF'
apiVersion: kuma.io/v1alpha1
kind: MeshPassthrough
metadata:
  name: kong-air-perimeter
  namespace: kong-air-production
  labels:
    kuma.io/mesh: kong-air-mesh
spec:
  targetRef:
    kind: Mesh
  default:
    passthroughMode: Matched
    appendMatch:
      - type: Domain
        value: httpbin.konghq.com
        port: 80
        protocol: http
      - type: IP
        value: "203.0.113.10"
        port: 443
        protocol: tls
      - type: CIDR
        value: "198.51.100.0/24"
        port: 443
        protocol: tls
EOF

Validate

  1. Confirm that the policy blocks a destination outside the allowlist. Use a host that your cluster can resolve and reach, so that only the policy can cause a failure:

    kubectl exec -n kong-air-production deploy/check-in-api -- wget -q -T 5 -O- http://httpbin.org/ip

    The command fails with a non-zero exit status and prints no response body. The sidecar has no route for httpbin.org on port 80, so it answers with 503 Service Unavailable.

  2. Confirm that the httpbin.konghq.com entry allows traffic to that host on port 80:

    kubectl exec -n kong-air-production deploy/check-in-api -- wget -q -T 5 -O- http://httpbin.konghq.com/ip

    The command prints the IP address that httpbin.konghq.com saw:

    {
      "origin": "203.0.113.25"
    }
  3. Confirm that the port 80 entry doesn’t cover the same host on port 443:

    kubectl exec -n kong-air-production deploy/check-in-api -- wget -q -T 5 -O- https://httpbin.konghq.com/ip

    The command fails. If the workload needs HTTPS to this host, add a second appendMatch entry for port 443 with protocol: tls.

FAQs

It depends on the restrictOutbound setting of the control plane. Kong Mesh 3.0 defaults restrictOutbound to true, so a proxy that no MeshPassthrough policy selects drops that traffic. The Kong Air control plane sets restrictOutbound to false, so its proxies forward that traffic to any destination, through the Envoy “Original Destination” cluster. Prepare the mesh for production turns the setting on for Kong Air.

All lets traffic to every unknown destination pass, None lets none pass, and Matched lets only the destinations in appendMatch pass. A policy that leaves out passthroughMode uses Matched, so a policy without appendMatch entries blocks every unknown destination. For the full behavior of each mode, see MeshPassthrough modes.

appendMatch accepts Domain, IP, and CIDR entries. Each entry takes an optional port, and a protocol that defaults to tcp. A Domain entry can’t use tcp or mysql, so set its protocol. An exact domain always needs a port, because the sidecar resolves the domain itself and connects to that port. A wildcard domain needs a port with http, http2, or grpc.

A match combines a destination, a port, and a protocol, so an entry for a host on port 80 over HTTP doesn’t allow the same host on port 443. For the validation rules, see MeshPassthrough.

Create the MeshPassthrough policy in kong-mesh-system instead of kong-air-production. A policy in an application namespace reaches only the proxies in that namespace, and a policy in the system namespace reaches every proxy in the zone. For how the namespace sets a policy’s reach, see Policy scope.

Keep the Mesh-level MeshPassthrough policy as the baseline, and add a policy with a Dataplane selector for the workloads that need broader access. A Dataplane selector is more specific than Mesh, so the exception wins for the proxies it matches, and the baseline stays in place for every other proxy. See Policy precedence.

Use MeshPassthrough for the long tail of outbound calls to destinations that the mesh doesn’t model. The sidecar enforces it and connects to those destinations directly.

When a destination matters enough to name, model it as a MeshExternalService, as in Manage external services with MeshExternalService. MeshExternalService traffic goes through the zone egress, where a MeshTrafficPermission must allow each caller. For both paths, see Traffic paths.

No. MeshPassthrough applies only to sidecars that run with transparent proxying. The Kubernetes sidecar injector turns it on by default. For a proxy without it, the control plane skips the policy and records a warning.

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!