rgoussu@goussu: ~/library/security/exercises
~/library/security/exercises cat personal-ca-and-mtls.md

Stand up your own CA + mTLS between two services

# Run a private certificate authority, issue leaf certs, and require both sides to present one — the PKI trust chain and machine identity built with your own hands.

Exercisesaved 2026-08-08source #tls#pki#certificates#mtls#security#exercise

Goal

Build a working private PKI and use it to secure service-to-service traffic with mutual TLS. You create a root and intermediate CA, issue short-lived leaf certificates, wire a client and a server that each verify the other's certificate against your CA, and prove that identity — not just encryption — is what a certificate carries. The result demystifies the chain of trust, hostname validation, and the mTLS foundation of zero-trust setups.

Subject: full brief & instructions

Practices

Milestones

  1. Root the trust. Create a root CA (offline key) and an intermediate CA it signs with smallstep/step-ca (or raw openssl). Inspect both with openssl x509 -text — read the basicConstraints, key usage, and validity windows.
  2. Issue a server leaf. Sign a leaf certificate with correct SANs, serve it from a TLS server, and connect with openssl s_client -connect host:443 -showcerts — confirm the full chain is served (the classic missing-intermediate bug is instructive to reproduce and fix).
  3. Add the client leaf and require it. Issue a client certificate, configure the server to require and verify client certs against your CA, and confirm a client with no cert (or a cert from a different CA) is rejected — this is mTLS.
  4. Prove identity is enforced. Have the server read the client cert's subject/SAN and authorize on it; show that swapping to an untrusted issuer breaks the connection at the handshake, not the application.
  5. Operate it. Issue short-lived (hours) leaf certs and script renewal; alert on expiry. Feel why short lifetimes force automation and bound the compromise window.

Stretch goals

  • Add a CRL or OCSP responder and revoke a leaf; observe soft-fail behavior.
  • Introduce a service mesh / SPIFFE SVID and compare its automatic rotation to your manual scripts.

Related