Skip to main content

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:
Or via command line:

Full TLS with Client Verification

Or via command line:

Certificate Files

Certificate Formats

NATS accepts PEM-encoded certificates: server-cert.pem:
server-key.pem:

Generating Self-Signed Certificates

For development/testing:
Never use self-signed certificates in production. Obtain certificates from a trusted Certificate Authority.

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’s tls.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):
  1. X25519MLKEM768 - Post-quantum hybrid
  2. X25519 - Fast elliptic curve
  3. CurveP256
  4. CurveP384
  5. CurveP521
Custom curve preferences:
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

Supported values:
  • 1.0 (deprecated, not recommended)
  • 1.1 (deprecated, not recommended)
  • 1.2 (minimum recommended)
  • 1.3 (recommended)
Always use TLS 1.2 or higher. TLS 1.3 provides better performance and security.

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
“tls: bad certificate”
  • Server rejected client certificate
  • Solution: Ensure client cert is signed by trusted CA
“tls: handshake timeout”
  • TLS handshake taking too long
  • Solution: Increase tls.timeout value