Network Security & TLS
Secure the wire: TLS certificates and the handshake, forward secrecy, trust chains, DNS hardening and network segmentation. Understand how encryption actually protects data in transit — and where it does not.
What is this?
Network security protects data in transit and limits who can reach what. TLS (Transport Layer Security) is the encryption protocol behind HTTPS, providing confidentiality, integrity and authentication of the server. It relies on a chain of trust from certificate authorities (CAs) down to leaf certificates for your hostname.
Why do you need it?
- Data in transit is the one place every service is exposed — anyone on the wire or at the load balancer can sniff plaintext.
- TLS authenticates the server, preventing man-in-the-middle impersonation of your hostname.
- Forward secrecy means even a stolen private key cannot decrypt past traffic.
- DNS is the backbone of modern infrastructure; cache poisoning or hijacked resolution is a total compromise.
- Segmentation and least-access networking limit lateral movement when one service is breached.
Mental model
A sealed, tamper-evident envelope
A TLS session
The envelope hides the contents (encryption), proves the seal was not broken (integrity), and is addressed to a verified recipient (authentication). Forward secrecy means the envelope is destroyed after delivery.
How it works
- The client and server negotiate a TLS version and cipher suite during the handshake.
- The server presents its certificate chain; the client validates each signature up to a trusted root CA.
- Ephemeral key exchange (ECDHE) creates session keys that are destroyed after the session — forward secrecy.
- All application data is encrypted under the session keys with message authentication codes for integrity.
- Certificate expiry, hostname mismatch and untrusted roots cause validation failures that clients reject.
A TLS 1.3 handshake at a glance.
Key commands
curl -vI https://example.com 2>&1 | grep -i 'SSL connection'Show which TLS version and cipher were negotiated.
openssl s_client -connect example.com:443 -servername example.comRun a raw TLS handshake and print the certificate chain and verification code.
curl --tls-max 1.2 -sI https://example.comForce the client to cap the TLS version to detect server compatibility.
dig example.com +shortResolve a hostname to its A records quickly.
curl --cert-status -sI https://example.comRequest OCSP stapling status for real-time revocation information.
Examples
Probe a TLS endpoint by hand
curl -v https://example.com 2>&1 | grep -iE "SSL connection|subject:|issuer:"openssl s_client -connect example.com:443 -servername example.com < /dev/null 2>/dev/null | grep -E "subject=|issuer=|Verify return code"dig example.com +shortnslookup example.comcurl shows the negotiated TLS version and the certificate's subject and issuer. openssl s_client performs a raw handshake and reports the verification code. dig and nslookup confirm the DNS records the connection will use.
In production
- All traffic is HTTPS with TLS 1.2+ (ideally 1.3) and HSTS enforced at the load balancer.
- Certificates are issued by Let's Encrypt or a private PKI and renewed automatically well before expiry.
- mTLS secures service-to-service calls inside the mesh, with per-workload certificates rotated on a schedule.
- DNS is monitored for anomalies and protected against cache poisoning; resolvers and zones are hardened.
- Network segmentation (VPCs, security groups, service meshes) enforces least-access between tiers.
Best practices
- Enforce a minimum TLS version (1.2) and prefer modern ciphers; disable deprecated suites.
- Pin leaf certificates via public-key pinning or TLS-ALPN, never hardcode short-lived CAs.
- Use OCSP stapling or short-lived certificates instead of blocking on revocation checks.
- Keep private keys on hardware or KMS-backed storage and rotate them on a schedule.
- Apply DNSSEC, restrict recursive resolvers, and separate public from private zones.
Common mistakes
- Shipping services with self-signed certificates that browsers and clients reject.
- Allowing TLS 1.0/1.1 or weak ciphers for legacy clients, exposing traffic to downgrade attacks.
- Ignoring certificate expiry until the outage — automation should watch every cert.
- Storing private keys in the repo or image next to the public certificate.
- Treating the load balancer TLS termination as enough while internal links stay plaintext.
Common issues
Self-signed certificate in certificate chainThe server presents a leaf not signed by any trusted root
Install the CA-signed certificate chain, or add the private CA to the client trust store.
Hostname does not match the certificateThe certificate's SANs do not include the requested hostname
Issue a certificate covering the exact hostname, or point the client at the correct name.
SSL connection refused / TLS version not supportedThe client offers only an older protocol the server rejects
Upgrade the client to TLS 1.2+, or temporarily enable an allowed legacy profile for migration.
Debugging tips
- Use openssl s_client to see the exact handshake failure reason (untrusted root, expired, hostname mismatch).
- Compare the Subject Alternative Names against the URL you requested — mismatch is the classic TLS error.
- Check the server's TLS configuration with a TLS checker against your public endpoints.
- Verify DNS first with dig: a wrong A/AAAA record produces a certificate mismatch that is not a TLS bug.
Interview checkpoint
Hands-on lab
- Resolve a host and confirm DNS records
- Inspect the negotiated TLS version and cipher
- Read certificate subject, issuer and chain
- Observe validation failures with bad certificates
TLS Handshake Deep Dive
30 min · advanced
Quick quiz
What does the client validate when it receives the server's certificate chain?
Forward secrecy protects past sessions even if the server's private key is later stolen.
Which TLS version mandates ephemeral key exchange for every session?
Cheat sheet
openssl s_client -connect host:443Raw handshake + chaincurl -vI https://hostNegotiated version and ciphercurl --tls-max 1.2 -sICap the TLS versiondig host +shortResolve DNS recordsTLS 1.2 minimumReject older protocolsHSTSForce HTTPS for clientsmTLSMutual authentication between servicesDNSSECAuthenticate DNS responses