Configure mutual TLS (mTLS) for zero-trust service-to-service communication. Use when implementing zero-trust networking, certificate management, or securing internal service communication.
Add this skill
npx mdskills install sickn33/mtls-configurationComprehensive mTLS guide with strong templates for Istio, Linkerd, SPIRE, and debugging workflows
1---2name: mtls-configuration3description: Configure mutual TLS (mTLS) for zero-trust service-to-service communication. Use when implementing zero-trust networking, certificate management, or securing internal service communication.4---56# mTLS Configuration78Comprehensive guide to implementing mutual TLS for zero-trust service mesh communication.910## Do not use this skill when1112- The task is unrelated to mtls configuration13- You need a different domain or tool outside this scope1415## Instructions1617- Clarify goals, constraints, and required inputs.18- Apply relevant best practices and validate outcomes.19- Provide actionable steps and verification.20- If detailed examples are required, open `resources/implementation-playbook.md`.2122## Use this skill when2324- Implementing zero-trust networking25- Securing service-to-service communication26- Certificate rotation and management27- Debugging TLS handshake issues28- Compliance requirements (PCI-DSS, HIPAA)29- Multi-cluster secure communication3031## Core Concepts3233### 1. mTLS Flow3435```36┌─────────┐ ┌─────────┐37│ Service │ │ Service │38│ A │ │ B │39└────┬────┘ └────┬────┘40 │ │41┌────┴────┐ TLS Handshake ┌────┴────┐42│ Proxy │◄───────────────────────────►│ Proxy │43│(Sidecar)│ 1. ClientHello │(Sidecar)│44│ │ 2. ServerHello + Cert │ │45│ │ 3. Client Cert │ │46│ │ 4. Verify Both Certs │ │47│ │ 5. Encrypted Channel │ │48└─────────┘ └─────────┘49```5051### 2. Certificate Hierarchy5253```54Root CA (Self-signed, long-lived)55 │56 ├── Intermediate CA (Cluster-level)57 │ │58 │ ├── Workload Cert (Service A)59 │ └── Workload Cert (Service B)60 │61 └── Intermediate CA (Multi-cluster)62 │63 └── Cross-cluster certs64```6566## Templates6768### Template 1: Istio mTLS (Strict Mode)6970```yaml71# Enable strict mTLS mesh-wide72apiVersion: security.istio.io/v1beta173kind: PeerAuthentication74metadata:75 name: default76 namespace: istio-system77spec:78 mtls:79 mode: STRICT80---81# Namespace-level override (permissive for migration)82apiVersion: security.istio.io/v1beta183kind: PeerAuthentication84metadata:85 name: default86 namespace: legacy-namespace87spec:88 mtls:89 mode: PERMISSIVE90---91# Workload-specific policy92apiVersion: security.istio.io/v1beta193kind: PeerAuthentication94metadata:95 name: payment-service96 namespace: production97spec:98 selector:99 matchLabels:100 app: payment-service101 mtls:102 mode: STRICT103 portLevelMtls:104 8080:105 mode: STRICT106 9090:107 mode: DISABLE # Metrics port, no mTLS108```109110### Template 2: Istio Destination Rule for mTLS111112```yaml113apiVersion: networking.istio.io/v1beta1114kind: DestinationRule115metadata:116 name: default117 namespace: istio-system118spec:119 host: "*.local"120 trafficPolicy:121 tls:122 mode: ISTIO_MUTUAL123---124# TLS to external service125apiVersion: networking.istio.io/v1beta1126kind: DestinationRule127metadata:128 name: external-api129spec:130 host: api.external.com131 trafficPolicy:132 tls:133 mode: SIMPLE134 caCertificates: /etc/certs/external-ca.pem135---136# Mutual TLS to external service137apiVersion: networking.istio.io/v1beta1138kind: DestinationRule139metadata:140 name: partner-api141spec:142 host: api.partner.com143 trafficPolicy:144 tls:145 mode: MUTUAL146 clientCertificate: /etc/certs/client.pem147 privateKey: /etc/certs/client-key.pem148 caCertificates: /etc/certs/partner-ca.pem149```150151### Template 3: Cert-Manager with Istio152153```yaml154# Install cert-manager issuer for Istio155apiVersion: cert-manager.io/v1156kind: ClusterIssuer157metadata:158 name: istio-ca159spec:160 ca:161 secretName: istio-ca-secret162---163# Create Istio CA secret164apiVersion: v1165kind: Secret166metadata:167 name: istio-ca-secret168 namespace: cert-manager169type: kubernetes.io/tls170data:171 tls.crt: <base64-encoded-ca-cert>172 tls.key: <base64-encoded-ca-key>173---174# Certificate for workload175apiVersion: cert-manager.io/v1176kind: Certificate177metadata:178 name: my-service-cert179 namespace: my-namespace180spec:181 secretName: my-service-tls182 duration: 24h183 renewBefore: 8h184 issuerRef:185 name: istio-ca186 kind: ClusterIssuer187 commonName: my-service.my-namespace.svc.cluster.local188 dnsNames:189 - my-service190 - my-service.my-namespace191 - my-service.my-namespace.svc192 - my-service.my-namespace.svc.cluster.local193 usages:194 - server auth195 - client auth196```197198### Template 4: SPIFFE/SPIRE Integration199200```yaml201# SPIRE Server configuration202apiVersion: v1203kind: ConfigMap204metadata:205 name: spire-server206 namespace: spire207data:208 server.conf: |209 server {210 bind_address = "0.0.0.0"211 bind_port = "8081"212 trust_domain = "example.org"213 data_dir = "/run/spire/data"214 log_level = "INFO"215 ca_ttl = "168h"216 default_x509_svid_ttl = "1h"217 }218219 plugins {220 DataStore "sql" {221 plugin_data {222 database_type = "sqlite3"223 connection_string = "/run/spire/data/datastore.sqlite3"224 }225 }226227 NodeAttestor "k8s_psat" {228 plugin_data {229 clusters = {230 "demo-cluster" = {231 service_account_allow_list = ["spire:spire-agent"]232 }233 }234 }235 }236237 KeyManager "memory" {238 plugin_data {}239 }240241 UpstreamAuthority "disk" {242 plugin_data {243 key_file_path = "/run/spire/secrets/bootstrap.key"244 cert_file_path = "/run/spire/secrets/bootstrap.crt"245 }246 }247 }248---249# SPIRE Agent DaemonSet (abbreviated)250apiVersion: apps/v1251kind: DaemonSet252metadata:253 name: spire-agent254 namespace: spire255spec:256 selector:257 matchLabels:258 app: spire-agent259 template:260 spec:261 containers:262 - name: spire-agent263 image: ghcr.io/spiffe/spire-agent:1.8.0264 volumeMounts:265 - name: spire-agent-socket266 mountPath: /run/spire/sockets267 volumes:268 - name: spire-agent-socket269 hostPath:270 path: /run/spire/sockets271 type: DirectoryOrCreate272```273274### Template 5: Linkerd mTLS (Automatic)275276```yaml277# Linkerd enables mTLS automatically278# Verify with:279# linkerd viz edges deployment -n my-namespace280281# For external services without mTLS282apiVersion: policy.linkerd.io/v1beta1283kind: Server284metadata:285 name: external-api286 namespace: my-namespace287spec:288 podSelector:289 matchLabels:290 app: my-app291 port: external-api292 proxyProtocol: HTTP/1 # or TLS for passthrough293---294# Skip TLS for specific port295apiVersion: v1296kind: Service297metadata:298 name: my-service299 annotations:300 config.linkerd.io/skip-outbound-ports: "3306" # MySQL301```302303## Certificate Rotation304305```bash306# Istio - Check certificate expiry307istioctl proxy-config secret deploy/my-app -o json | \308 jq '.dynamicActiveSecrets[0].secret.tlsCertificate.certificateChain.inlineBytes' | \309 tr -d '"' | base64 -d | openssl x509 -text -noout310311# Force certificate rotation312kubectl rollout restart deployment/my-app313314# Check Linkerd identity315linkerd identity -n my-namespace316```317318## Debugging mTLS Issues319320```bash321# Istio - Check if mTLS is enabled322istioctl authn tls-check my-service.my-namespace.svc.cluster.local323324# Verify peer authentication325kubectl get peerauthentication --all-namespaces326327# Check destination rules328kubectl get destinationrule --all-namespaces329330# Debug TLS handshake331istioctl proxy-config log deploy/my-app --level debug332kubectl logs deploy/my-app -c istio-proxy | grep -i tls333334# Linkerd - Check mTLS status335linkerd viz edges deployment -n my-namespace336linkerd viz tap deploy/my-app --to deploy/my-backend337```338339## Best Practices340341### Do's342- **Start with PERMISSIVE** - Migrate gradually to STRICT343- **Monitor certificate expiry** - Set up alerts344- **Use short-lived certs** - 24h or less for workloads345- **Rotate CA periodically** - Plan for CA rotation346- **Log TLS errors** - For debugging and audit347348### Don'ts349- **Don't disable mTLS** - For convenience in production350- **Don't ignore cert expiry** - Automate rotation351- **Don't use self-signed certs** - Use proper CA hierarchy352- **Don't skip verification** - Verify the full chain353354## Resources355356- [Istio Security](https://istio.io/latest/docs/concepts/security/)357- [SPIFFE/SPIRE](https://spiffe.io/)358- [cert-manager](https://cert-manager.io/)359- [Zero Trust Architecture (NIST)](https://www.nist.gov/publications/zero-trust-architecture)360
Full transparency — inspect the skill content before installing.