Skip to main content

Authentication Overview

NATS Server supports multiple authentication mechanisms to verify client identities. You can choose the method that best fits your security requirements and infrastructure.

Authentication Methods

NATS provides four primary authentication methods:
  1. Token-based authentication - Simple shared secret
  2. Username/password authentication - Traditional credentials
  3. NKeys authentication - Cryptographic public-key authentication
  4. JWT-based authentication - Decentralized authentication with claims

Token-Based Authentication

The simplest authentication method using a shared secret token.

Server Configuration

Or via command line:

Client Connection

Token authentication is suitable for development but should not be used in production. Prefer NKeys or JWT authentication.

Username/Password Authentication

Traditional username and password credentials.

Single User

Or via command line:

Multiple Users

Password Hashing with BCrypt

Never store plaintext passwords. Use bcrypt hashing:
The server warns if plaintext passwords are detected in the configuration.

Connection Deadlines

Expire user credentials after a specific time:

NKeys Authentication

Cryptographic authentication using Ed25519 public-key signatures. This is the recommended authentication method.

How NKeys Work

  1. Server generates a random nonce
  2. Client signs the nonce with its private NKey
  3. Server verifies the signature using the public NKey
  4. No passwords transmitted over the network

Generating NKeys

Output:
Store the private key securely. Never commit it to version control.

Server Configuration

Single NKey User

Multiple NKey Users

With Account Assignment

Client Configuration

Clients use a credentials file containing the NKey: user.creds:
Connect using credentials:

JWT-Based Authentication

JWT (JSON Web Token) authentication enables decentralized auth with signed claims. This is the most sophisticated authentication method.

Operator Mode

Operator mode uses a hierarchical trust model:

Server Configuration

Account JWT Example

Account JWTs define account-level claims:

User JWT Example

User JWTs define user-level claims and permissions:

Dynamic Updates

JWT authentication supports dynamic updates without server restarts:
  1. Update account or user JWT in the resolver
  2. Server automatically picks up changes
  3. Active connections continue with old credentials
  4. New connections use updated credentials

Account Signing Keys

Accounts can delegate user signing to scoped keys:

Authentication Callouts

Authentication can be delegated to an external service via the callout mechanism.

Server Configuration

Callout Flow

  1. Client connects to server
  2. Server publishes authentication request to $SYS.REQ.USER.AUTH
  3. Auth service validates credentials
  4. Auth service responds with signed User JWT
  5. Server grants access based on JWT claims

Encrypted Callouts

Callout requests and responses can be encrypted:

TLS Certificate Mapping

Map TLS certificate properties to users:

Authentication Timeouts

Clients must authenticate within the timeout:
Or via command line: