TLS Overview
NATS Server supports TLS (Transport Layer Security) to encrypt connections and authenticate clients using certificates. TLS is essential for production deployments.Basic TLS Configuration
Server TLS
Enable TLS for client connections:Full TLS with Client Verification
Certificate Files
Certificate Formats
NATS accepts PEM-encoded certificates: server-cert.pem:Generating Self-Signed Certificates
For development/testing:Client Certificate Verification
Mutual TLS (mTLS)
Require clients to present valid certificates:Certificate Mapping
Map certificate properties to user accounts:Certificate Pinning
Pin specific client certificates:Cipher Suites
NATS Server supports modern, secure cipher suites.Default Cipher Suites
From server/ciphersuites.go, NATS uses Go’stls.CipherSuites() which includes:
- TLS_AES_128_GCM_SHA256 (TLS 1.3)
- TLS_AES_256_GCM_SHA384 (TLS 1.3)
- TLS_CHACHA20_POLY1305_SHA256 (TLS 1.3)
- TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
- TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
- TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
- TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
- TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305
- TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305
Custom Cipher Suites
Curve Preferences
From server/ciphersuites.go:66-73, default curves (in order):- X25519MLKEM768 - Post-quantum hybrid
- X25519 - Fast elliptic curve
- CurveP256
- CurveP384
- CurveP521
NATS prioritizes post-quantum cryptography with X25519MLKEM768 by default.
FIPS Mode
When FIPS 140 mode is enabled (server/ciphersuites.go:56-65):- X25519 alone is excluded (not FIPS-approved)
- X25519MLKEM768 is included (FIPS-approved when combined with MLKEM768)
- Only FIPS-compliant cipher suites are available
TLS Versions
Minimum TLS Version
1.0(deprecated, not recommended)1.1(deprecated, not recommended)1.2(minimum recommended)1.3(recommended)
TLS Timeout
Configure TLS handshake timeout:TLS for Cluster Routes
Secure cluster communication:TLS for Gateway Connections
Secure super-cluster connections:TLS for Leaf Nodes
Secure leaf node connections:TLS for HTTP Monitoring
Secure monitoring endpoints:OCSP Stapling
Online Certificate Status Protocol for certificate validation:OCSP Peer Verification
Verify client certificates via OCSP:Certificate Rotation
Automatic Reload
NATS Server can reload certificates without restart:Certificate Expiration Monitoring
NATS Server exposes certificate expiration in monitoring endpoints:TLS Best Practices
1. Always Use TLS in Production
2. Use Strong Cipher Suites
Avoid weak ciphers:3. Enable Client Certificate Verification
For maximum security:4. Rotate Certificates Regularly
- Set certificate validity to 90 days or less
- Automate renewal (e.g., with Let’s Encrypt)
- Monitor expiration dates
5. Separate Certificates by Component
6. Protect Private Keys
7. Enable OCSP
Troubleshooting TLS
Test TLS Connection
Common Errors
“x509: certificate signed by unknown authority”- Client doesn’t trust server’s CA
- Solution: Provide correct CA file to client
- Server rejected client certificate
- Solution: Ensure client cert is signed by trusted CA
- TLS handshake taking too long
- Solution: Increase
tls.timeoutvalue