Manage workload identity and mTLS

Uses: Kong Mesh
TL;DR

Inspect the identity in your first zone, then extend it to a second zone:

  1. Check that the MeshIdentity initialized, and inspect the MeshTrust that its Bundled provider generated.
  2. Create the same MeshIdentity on the second zone, which generates its own CA and trust domain.
  3. Copy each zone’s generated MeshTrust into the other zone, then confirm that each proxy’s trust bundle includes both trust domains.

Prerequisites

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

Complete the previous page, Connect a second zone before completing this page.

A request between two Kong Air services succeeds only when all of the following are true:

  • The caller presents a certificate with a Secure Production Identity Framework for Everyone (SPIFFE) ID, issued by MeshIdentity.
  • The receiver trusts the issuing certificate authority (CA) through a MeshTrust.
  • A MeshTrafficPermission allows the caller.

Kong Air now runs a second zone, zone2, so all three must also hold across zones.

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

Inspect the identity created in zone1

You created kong-air-identity on the zone1 control plane, in the kong-mesh-system namespace. The kong-air-identity selector covers every data plane proxy in kong-air-mesh, including application sidecars and mesh-scoped zone proxies.

  1. Check that kong-air-identity initialized. MeshIdentity reports three conditions, and all three must be True:

    kubectl get meshidentity kong-air-identity -n kong-mesh-system \
      -o jsonpath='{range .status.conditions[*]}{.type}={.status}{"\n"}{end}'

    You should get the following result:

    Provider=True
    MeshTrustCreated=True
    Ready=True

    Each condition reports one part of the setup:

    • Provider: The CA is usable.
    • MeshTrustCreated: The provider published a MeshTrust.
    • Ready: The identity can issue certificates.
  2. Inspect the MeshTrust that the Bundled provider created. Because kong-air-identity sets meshTrustCreation: Enabled, the control plane creates a MeshTrust with the same name:

    kubectl get meshtrust kong-air-identity -n kong-mesh-system \
      -o jsonpath='{.spec.trustDomain}{"\n"}{.spec.caBundles[0].type}{"\n"}'

    You should get the following result:

    kong-air-mesh.zone1.mesh.local
    Pem
  3. Confirm which MeshIdentity issued each workload’s certificate:

    kubectl get dataplaneinsights -n kong-air-production \
      -o custom-columns='NAME:.metadata.name,ISSUER:.status.mTLS.issuedBackend,EXPIRES:.status.mTLS.certificateExpirationTime'

    Each ISSUER value contains kong-air-identity. An ISSUER of <none> means that the data plane proxy has no workload identity, for example because no MeshIdentity selector matches it.

Apply the identity in the second zone

Create the same kong-air-identity on the zone2 control plane. You can only create a MeshIdentity in the system namespace. In zone2, the default trust domain resolves to kong-air-mesh.zone2.mesh.local:

kubectl --context "$ZONE2_CONTEXT" apply -f - <<'EOF'
apiVersion: kuma.io/v1alpha1
kind: MeshIdentity
metadata:
  name: kong-air-identity
  namespace: kong-mesh-system
  labels:
    kuma.io/mesh: kong-air-mesh
spec:
  selector:
    dataplane:
      matchLabels:
        kuma.io/mesh: kong-air-mesh
  provider:
    type: Bundled
    bundled:
      insecureAllowSelfSigned: true
      autogenerate:
        enabled: true
      meshTrustCreation: Enabled
  spiffeID:
    path: /ns/{{ .Namespace }}/sa/{{ .ServiceAccount }}
EOF

For production, we recommend a managed CA or SPIRE instead of self-signed autogenerated CAs, because you control the CA lifecycle. See Providers. This guide uses autogenerated CAs so you can see and test the trust relationship.

Copy zone1 trust into zone2

A MeshTrust spec holds only a trustDomain and a list of caBundles, so the copy never includes the CA private key. Create a MeshTrust named kong-air-mesh-trust-of-zone1 in zone2, with the two fields read from the zone1 MeshTrust:

kubectl --context "$ZONE2_CONTEXT" apply -f - <<EOF
apiVersion: kuma.io/v1alpha1
kind: MeshTrust
metadata:
  name: kong-air-mesh-trust-of-zone1
  namespace: kong-mesh-system
  labels:
    kuma.io/mesh: kong-air-mesh
spec:
  trustDomain: $(kubectl --context "$ZONE1_CONTEXT" get meshtrust kong-air-identity -n kong-mesh-system -o jsonpath='{.spec.trustDomain}')
  caBundles: $(kubectl --context "$ZONE1_CONTEXT" get meshtrust kong-air-identity -n kong-mesh-system -o jsonpath='{.spec.caBundles}')
EOF

Copy zone2 trust into zone1

Create a MeshTrust named kong-air-mesh-trust-of-zone2 in zone1, with the two fields read from the zone2 MeshTrust:

kubectl --context "$ZONE1_CONTEXT" apply -f - <<EOF
apiVersion: kuma.io/v1alpha1
kind: MeshTrust
metadata:
  name: kong-air-mesh-trust-of-zone2
  namespace: kong-mesh-system
  labels:
    kuma.io/mesh: kong-air-mesh
spec:
  trustDomain: $(kubectl --context "$ZONE2_CONTEXT" get meshtrust kong-air-identity -n kong-mesh-system -o jsonpath='{.spec.trustDomain}')
  caBundles: $(kubectl --context "$ZONE2_CONTEXT" get meshtrust kong-air-identity -n kong-mesh-system -o jsonpath='{.spec.caBundles}')
EOF

With three or more zones, every zone needs one MeshTrust for each other zone whose certificates it accepts. We recommend that you automate these copies.

Validate

  1. Confirm that each zone has its own generated MeshTrust and the copy from the other zone:

    kubectl --context "$ZONE1_CONTEXT" get meshtrust -n kong-mesh-system
    kubectl --context "$ZONE2_CONTEXT" get meshtrust -n kong-mesh-system
  2. Confirm that each copied MeshTrust holds the other zone’s trust domain:

    kubectl --context "$ZONE1_CONTEXT" get meshtrust kong-air-mesh-trust-of-zone2 \
      -n kong-mesh-system -o jsonpath='{.spec.trustDomain}{"\n"}'
    kubectl --context "$ZONE2_CONTEXT" get meshtrust kong-air-mesh-trust-of-zone1 \
      -n kong-mesh-system -o jsonpath='{.spec.trustDomain}{"\n"}'

    You should get the following result:

    kong-air-mesh.zone2.mesh.local
    kong-air-mesh.zone1.mesh.local
  3. Confirm that the zone control plane includes the copied MeshTrust in the trust bundle of each proxy. The supportedBackends field of each DataplaneInsight lists every MeshTrust in the mesh that the zone control plane knows:

    kubectl --context "$ZONE1_CONTEXT" get dataplaneinsights -n kong-air-production \
      -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.mTLS.supportedBackends}{"\n"}{end}'

    Every line contains two kri_mtrust_ entries: one for the local identity and one for the copy from the other zone:

    check-in-api-654c44bbdb-n55x8	["kri_mtrust_kong-air-mesh_zone1_kong-mesh-system_kong-air-identity_","kri_mtrust_kong-air-mesh_zone1_kong-mesh-system_kong-air-mesh-trust-of-zone2_"]

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!