CodeBlanks Logo Icon CodeBlanks

mTLS

Learn mutual TLS with Istio.

mTLS

With mutual TLS (mTLS) both sides present their certificates: the traffic is encrypted and each service's identity (a SPIFFE identity derived from the ServiceAccount) is verified. Istio issues and rotates the certificates automatically. A PeerAuthentication determines whether mTLS is required:

apiVersion: security.istio.io/v1
kind: PeerAuthentication
metadata:
  name: varsayilan
  namespace: magaza
spec:
  mtls:
    mode: STRICT        # PERMISSIVE: accepts both plain and mTLS

During migration you start with PERMISSIVE; once all clients have joined the mesh, you switch to STRICT.

Authorization policy

Thanks to mTLS identities, an AuthorizationPolicy writes rules like "only the web service may GET api's /urunler path":

apiVersion: security.istio.io/v1
kind: AuthorizationPolicy
metadata:
  name: api-erisim
  namespace: magaza
spec:
  selector:
    matchLabels: {app: api}
  action: ALLOW
  rules:
    - from:
        - source:
            principals: ["cluster.local/ns/magaza/sa/web"]
      to:
        - operation:
            methods: ["GET"]
            paths: ["/urunler*"]

Practice Mandatory mTLS

Write a PeerAuthentication YAML: security.istio.io/v1; name varsayilan, namespace magaza; spec.mtls.mode: STRICT.

Starter code

terminal
# buraya yaz

Sample solution

terminal
apiVersion: security.istio.io/v1
kind: PeerAuthentication
metadata:
  name: varsayilan
  namespace: magaza
spec:
  mtls:
    mode: STRICT

Expected output

peerauthentication.security.istio.io/varsayilan created
$ kubectl exec -n default deneme -- curl -s -o /dev/null -w "%{http_code}" http://api.magaza:8000/
000

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 In STRICT mode, what happens if a pod outside the mesh (without a sidecar) sends a request to api?

  • A sidecar is added automatically
  • A warning is logged but it passes
  • The connection is refused Correct answer
  • Plain text is accepted

Explanation: STRICT only accepts mTLS connections.

2 Make mTLS required.

Question
spec:
  mtls:
    mode: ____
Answer
spec:
  mtls:
    mode: STRICT

Explanation: STRICT accepts only mTLS.

3 Match.

Term Meaning
mTLS Mutual identity and encryption
PERMISSIVE Migration mode
STRICT mTLS only
principals Service identity

All lessons in Expert