Introduce zero-trust security

TL;DR

Create a MeshIdentity so workloads get certificates, which makes traffic default to deny, then allow specific callers with a MeshTrafficPermission matching on their SPIFFE ID.

Prerequisites

This page is part of the Get started with Kong Mesh on Universal series.

Complete the previous page, Add the demo application before completing this page.

This tutorial uses kongctl to manage Konnect resources programmatically. We recommend keeping kongctl up to date with the latest version (1.29.0).

  1. Install kongctl from developer.konghq.com/kongctl.
  2. Verify the installation:

    kongctl version

Issue identities

A workload gets a certificate from a MeshIdentity. Without one, proxies have no identity, serve plaintext, and neither MeshTLS nor MeshTrafficPermission applies to them.

  1. Create a MeshIdentity for every proxy in the mesh:

    cat <<'EOF' | kongctl apply mesh -f - \
      --control-plane-url "$KONG_MESH_CP" \
      --control-plane-token "$KONG_MESH_ADMIN_TOKEN"
    type: MeshIdentity
    mesh: default
    name: demo-identity
    spec:
      selector:
        dataplane: {}
      spiffeID:
        trustDomain: default.mesh.local
      provider:
        type: Bundled
        bundled:
          autogenerate:
            enabled: true
          insecureAllowSelfSigned: true
          meshTrustCreation: Enabled
    EOF

    In this example:

    • selector.dataplane: {} matches every proxy in the mesh.
    • insecureAllowSelfSigned accepts a CA the control plane generates itself, for testing purposes. In a real mesh, provide a CA under bundled.ca.
    • trustDomain explicitly keeps the SPIFFE IDs predictable. Left out, it’s generated based on the following template: {{ .Mesh }}.{{ .Zone }}.mesh.local.
  2. Check that the identity initialized:

    kongctl get mesh meshidentities demo-identity -o yaml \
      --control-plane-url "$KONG_MESH_CP" \
      --control-plane-token "$KONG_MESH_ADMIN_TOKEN"

    status.conditions should report Provider, MeshTrustCreated and Ready as true, and status.trustDomain shows the domain issuance is pinned to.

  3. Check the MeshTrust the control plane created to publish the CA bundle:

    kongctl get mesh meshtrusts \
      --control-plane-url "$KONG_MESH_CP" \
      --control-plane-token "$KONG_MESH_ADMIN_TOKEN"

Confirm that traffic is denied

  1. Send a request from inside the demo application’s container, so the application calls the key/value store through its sidecar:

    docker exec kong-mesh-demo-app curl -s -XPOST http://127.0.0.1:5050/api/counter

    The request fails. Proxies now have identities, so MeshTrafficPermission applies, and no permission exists yet, so the kv proxy rejects the call from demo-app.

  2. Send the same request from your host, outside the mesh:

    curl -XPOST http://127.0.0.1:25050/api/counter

    This request also fails. Inbounds are Strict unless a MeshTLS policy says otherwise, so the demo-app proxy rejects plaintext from outside the mesh.

Allow the demo app to reach the key/value store

Create a MeshTrafficPermission that allows traffic from demo-app to kv:

cat <<'EOF' | kongctl apply mesh -f - \
  --control-plane-url "$KONG_MESH_CP" \
  --control-plane-token "$KONG_MESH_ADMIN_TOKEN"
type: MeshTrafficPermission
mesh: default
name: allow-demo-app-to-kv
spec:
  targetRef:
    kind: Dataplane
    labels:
      app: kv
  rules:
    - default:
        allow:
          - spiffeID:
              type: Exact
              value: spiffe://default.mesh.local/workload/demo-app
EOF

Inspect the applied policy

  1. Check that the MeshTrafficPermission policy applies to the kv proxy:

    kongctl inspect mesh dataplane kv \
      --control-plane-url "$KONG_MESH_CP" \
      --control-plane-token "$KONG_MESH_ADMIN_TOKEN"
  2. Check which proxies the policy matches:

    kongctl inspect mesh meshtrafficpermission allow-demo-app-to-kv \
      --control-plane-url "$KONG_MESH_CP" \
      --control-plane-token "$KONG_MESH_ADMIN_TOKEN"

To let traffic from outside the mesh reach the demo application, see Application ingress.

Validate

  1. Send the request from inside the demo application’s container again:

    docker exec kong-mesh-demo-app curl -s -XPOST http://127.0.0.1:5050/api/counter

    The response returns the incremented counter and the local-demo-zone zone name. The application reached kv over mTLS, and the kv proxy admitted it because demo-app’s SPIFFE ID is allowed.

    It can take a few seconds for the MeshTrafficPermission to be applied. If the request still fails, wait and try again.

  2. Send the same request from your host again:

    curl -XPOST http://127.0.0.1:25050/api/counter

    It still fails: curl presents no mesh identity, and the inbound is Strict. Traffic between the two workloads is encrypted and authorized, and traffic from outside the mesh isn’t admitted.

Cleanup

Remove the demo containers:

docker rm --force kong-mesh-demo-app kong-mesh-demo-kv kong-mesh-demo-control-plane

Remove the Docker network:

docker network rm kong-mesh-demo

Remove the working directory:

rm -rf "$KONG_MESH_DEMO_DIR"

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!