Skip to main content

Overview

TLS (Transport Layer Security) options enable encrypted connections between NATS clients and servers, ensuring secure communication and optional client authentication through certificates.

Command Line Flags

boolean
default:"false"
Enable TLS without client certificate verification.
string
Path to server certificate file (PEM format).
string
Path to server private key file (PEM format).
boolean
default:"false"
Enable TLS and verify client certificates.
string
Path to certificate authority (CA) file for verifying client certificates.

Configuration File Options

Basic TLS Configuration

string
required
Path to server certificate file.
string
required
Path to server private key file.
string
Path to certificate authority file for client verification.

Client Verification

boolean
default:"false"
Verify client certificates. Requires ca_file.
boolean
default:"false"
Verify client certificates and map certificate fields to user authentication.
boolean
default:"false"
Skip certificate verification (for testing only).
Never use in production! This disables security.

Cipher and Protocol Configuration

array
List of allowed cipher suites. Restricts which encryption algorithms can be used.
array
Elliptic curves for ECDHE cipher suites.
string
default:"1.2"
Minimum TLS protocol version. Options: 1.0, 1.1, 1.2, 1.3

Performance and Timeout

float
default:"2.0"
TLS handshake timeout in seconds.
integer
TLS handshake rate limit in bytes per second.
boolean
default:"false"
Perform TLS handshake before sending INFO protocol.
duration
Fallback timeout when handshake_first is enabled.

Certificate Pinning

array
SHA256 fingerprints of pinned certificates.

Configuration Examples

Basic TLS Server

TLS with Client Verification

Mutual TLS (mTLS) with Certificate Mapping

High Security Configuration

Cluster with TLS

Multiple Certificates

Generating Test Certificates

For development and testing:

Available Cipher Suites

Modern recommended cipher suites:
  • 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_ECDSA_WITH_AES_128_GCM_SHA256
  • TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
  • TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
  • TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
  • TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305
  • TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305

Monitoring TLS Connections

Check TLS connection status via monitoring:
Look for tls_version and tls_cipher_suite fields in connection details.

Best Practices

  1. Protocol Version: Use TLS 1.2 or higher (preferably 1.3)
  2. Strong Ciphers: Configure modern cipher suites, avoid weak algorithms
  3. Certificate Management: Use proper PKI and rotate certificates regularly
  4. Client Verification: Enable verify or verify_and_map in production
  5. Certificate Expiry: Monitor certificate expiration dates
  6. Private Keys: Protect private keys with appropriate file permissions (0600)
  7. CA Trust: Use properly signed certificates from trusted CAs in production
  8. Separate Certificates: Use different certificates for client and cluster connections
  9. Timeout Tuning: Adjust timeout based on network conditions
  10. Testing: Always test TLS configuration before deploying to production

Certificate Mapping

When using verify_and_map: true, NATS maps certificate fields to users:
Client certificate with CN=alice will be authenticated as user alice.

Troubleshooting

Certificate Errors

Common Issues

  • Certificate expired: Check expiration with openssl x509 -enddate
  • Hostname mismatch: Ensure certificate CN/SAN matches server hostname
  • CA not trusted: Verify ca_file contains the correct CA certificate
  • Permission denied: Check file permissions on certificate and key files
  • Handshake timeout: Increase timeout value

Server Options

Core server configuration

Cluster Options

Secure cluster with TLS

JetStream Options

Secure JetStream with TLS