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
Series 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.
kongctl v1.29.0+
This tutorial uses kongctl to manage Konnect resources programmatically. We recommend keeping kongctl up to date with the latest version (1.29.0).
- Install kongctl from developer.konghq.com/kongctl.
-
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.
-
Create a
MeshIdentityfor 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 EOFIn this example:
selector.dataplane: {}matches every proxy in the mesh.insecureAllowSelfSignedaccepts a CA the control plane generates itself, for testing purposes. In a real mesh, provide a CA underbundled.ca.trustDomainexplicitly keeps the SPIFFE IDs predictable. Left out, it’s generated based on the following template:{{ .Mesh }}.{{ .Zone }}.mesh.local.
-
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.conditionsshould reportProvider,MeshTrustCreatedandReadyas true, andstatus.trustDomainshows the domain issuance is pinned to. -
Check the
MeshTrustthe 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
-
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/counterThe request fails. Proxies now have identities, so
MeshTrafficPermissionapplies, and no permission exists yet, so thekvproxy rejects the call fromdemo-app. -
Send the same request from your host, outside the mesh:
curl -XPOST http://127.0.0.1:25050/api/counterThis request also fails. Inbounds are
Strictunless a MeshTLS policy says otherwise, so thedemo-appproxy 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
EOFInspect the applied policy
-
Check that the
MeshTrafficPermissionpolicy applies to thekvproxy:kongctl inspect mesh dataplane kv \ --control-plane-url "$KONG_MESH_CP" \ --control-plane-token "$KONG_MESH_ADMIN_TOKEN" -
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
-
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/counterThe response returns the incremented counter and the
local-demo-zonezone name. The application reachedkvover mTLS, and thekvproxy admitted it becausedemo-app’s SPIFFE ID is allowed.It can take a few seconds for the
MeshTrafficPermissionto be applied. If the request still fails, wait and try again. -
Send the same request from your host again:
curl -XPOST http://127.0.0.1:25050/api/counterIt still fails:
curlpresents no mesh identity, and the inbound isStrict. Traffic between the two workloads is encrypted and authorized, and traffic from outside the mesh isn’t admitted.
Cleanup
Remove the demo containers and network
Remove the demo containers:
docker rm --force kong-mesh-demo-app kong-mesh-demo-kv kong-mesh-demo-control-planeRemove the Docker network:
docker network rm kong-mesh-demoRemove the working directory:
rm -rf "$KONG_MESH_DEMO_DIR"