Progressively rolling in strict mTLS

The MeshTLS policy allows you to gradually migrate services to mutual TLS without dropping a packet.

Prerequisites

  • Completed quickstart to set up a zone control plane with demo application.

Basic setup

In order to be able to fully utilize MeshTLS policy you need to enable Mutual TLS (mTLS), and you can do it with builtin CA backend by executing:

  1. echo "apiVersion: kuma.io/v1alpha1
  2. kind: Mesh
  3. metadata:
  4. name: default
  5. spec:
  6. mtls:
  7. enabledBackend: ca-1
  8. backends:
  9. - name: ca-1
  10. type: builtin" | kubectl apply -f -

To make sure that traffic works in our examples let’s configure MeshTrafficPermission to allow all traffic:

  1. echo "apiVersion: kuma.io/v1alpha1
  2. kind: MeshTrafficPermission
  3. metadata:
  4. namespace: kuma-system
  5. name: mtp
  6. spec:
  7. targetRef:
  8. kind: Mesh
  9. from:
  10. - targetRef:
  11. kind: Mesh
  12. default:
  13. action: Allow" | kubectl apply -f -

Gradually bring another service into the mesh

Start a second demo app

First we start a new demo setup in another namespace called kuma-demo-migration. The below command installs the demo one more time in another namespace:

  1. curl -s https://raw.githubusercontent.com/kumahq/kuma-counter-demo/master/demo.yaml |
  2. sed "s#kuma.io/sidecar-injection: enabled#kuma.io/sidecar-injection: disabled#" |
  3. sed "s#name: kuma-demo#name: kuma-demo-migration#" |
  4. sed "s#redis.kuma-demo.svc.cluster.local#redis.kuma-demo-migration.svc.cluster.local#" |
  5. sed "s#namespace: kuma-demo#namespace: kuma-demo-migration#" | kubectl apply -f -

Below diagram shows which applications are inside the mesh and which are not. Purple links indicate that the communication is encrypted, gray ones are plaintext.

  1. ---
  2. title: service graph of the second demo app
  3. ---
  4. flowchart LR
  5. subgraph meshed
  6. subgraph kuma-demo
  7. direction LR
  8. demo-app(demo-app :5000)
  9. redis(redis :6379)
  10. demo-app --> redis
  11. end
  12. end
  13. subgraph non-meshed
  14. subgraph kuma-demo-migration
  15. direction LR
  16. redis2(redis :6379)
  17. demo-app2(demo-app :5000)
  18. demo-app2 --> redis2
  19. end
  20. end
  21. linkStyle 0 stroke:#d25585, stroke-width:2px;
  22. linkStyle 1 stroke:#555a5d, stroke-width:2px;

Enable port forwarding for both demo-apps

  1. kubectl port-forward svc/demo-app -n kuma-demo 5001:5000
  2. kubectl port-forward svc/demo-app -n kuma-demo-migration 5002:5000

Open up both apps’ GUI and turn on auto incrementing.

Enable permissive mode on redis

We begin with preparing redis to start in permissive mode when deployed inside the mesh. To enable permissive mode we define this MeshTLS policy:

  1. apiVersion: kuma.io/v1alpha1
  2. kind: MeshTLS
  3. metadata:
  4. name: redis
  5. namespace: kuma-demo-migration
  6. labels:
  7. kuma.io/mesh: default
  8. spec:
  9. targetRef:
  10. kind: MeshSubset
  11. tags:
  12. app: redis
  13. from:
  14. - targetRef:
  15. kind: Mesh
  16. default:
  17. mode: Permissive

Migrate redis to mesh

Then we bring redis into the mesh by adding kuma.io/sidecar-injection=true label:

  1. kubectl patch deployment redis -n kuma-demo-migration \
  2. --type='json' \
  3. -p='[{"op": "add", "path": "/spec/template/metadata/labels/kuma.io~1sidecar-injection", "value": "enabled"}]'

After this redis will be receiving plaintext traffic from non-meshed client. You can go to the Kuma GUI, check the Stats tab for the redis Dataplane in the kuma-demo-migration namespace, and you should see this metric increment :

Data Plane Proxies Stats metric for cluster.localhost_6379.upstream_cx_total

  1. cluster.localhost_6379.upstream_cx_total

The below diagram shows that the second redis was moved to be inside the mesh:

  1. ---
  2. title: service graph when redis is inside the mesh
  3. ---
  4. flowchart LR
  5. subgraph meshed
  6. subgraph kuma-demo
  7. direction LR
  8. demo-app(demo-app :5000)
  9. redis(redis :6379)
  10. demo-app --> redis
  11. end
  12. subgraph kuma-demo-migration
  13. direction LR
  14. redis2(redis :6379)
  15. end
  16. end
  17. subgraph non-meshed
  18. subgraph kuma-demo-migration
  19. direction LR
  20. demo-app2(demo-app :5000)
  21. demo-app2 --> redis2
  22. end
  23. end
  24. linkStyle 0 stroke:#d25585, stroke-width:2px;
  25. linkStyle 1 stroke:#555a5d, stroke-width:2px;

Migrate client to mesh

Next we do the same to the client so the traffic is encrypted:

  1. kubectl patch deployment demo-app -n kuma-demo-migration \
  2. --type='json' \
  3. -p='[{"op": "add", "path": "/spec/template/metadata/labels/kuma.io~1sidecar-injection", "value": "enabled"}]'

After this is done, you’ll have to re-enable the port-forward, and then you can go to the Kuma GUI, check the Stats tab for the redis Dataplane in the kuma-demo-migration namespace, and you should see this metric increment:

Data Plane Proxies Stats metric for inbound_POD_IP_6379.rbac.allowed

  1. inbound_POD_IP_6379.rbac.allowed

The below diagram shows that all services are now in the mesh:

  1. ---
  2. title: service graph when both client and redis are inside the mesh
  3. ---
  4. flowchart LR
  5. subgraph meshed
  6. subgraph kuma-demo
  7. direction LR
  8. demo-app(demo-app :5000)
  9. redis(redis :6379)
  10. demo-app --> redis
  11. end
  12. subgraph kuma-demo-migration
  13. direction LR
  14. demo-app2(demo-app :5000)
  15. redis2(redis :6379)
  16. demo-app2 --> redis2
  17. end
  18. end
  19. linkStyle 0,1 stroke:#d25585, stroke-width:2px;

Set strict mode on redis

Finally, to set strict mode you can either edit the policy or remove it (the default is taken from Mesh object which is STRICT).

Things to remember when migrating to strict TLS

If only encrypted traffic is sent to the destination, the difference between cluster.localhost_6379.upstream_cx_total and inbound_10_42_0_13_6379.rbac.allowed will not change after setting the workload to Strict mode.

  1. kubectl delete meshtlses.kuma.io -n kuma-demo-migration redis

Next steps

With a couple of easy steps we were able to gradually bring a service into the mesh without dropping a packet and encrypting the traffic whenever it’s possible.

Read more about MeshTLS policy.