Skip to main content

Authorization Overview

NATS Server authorization controls what authenticated users can publish and subscribe to. Permissions are granted at the subject level, providing fine-grained access control.

Permissions System

The permission system operates on two dimensions:
  1. Publish Permissions - Control which subjects a user can publish messages to
  2. Subscribe Permissions - Control which subjects a user can subscribe to
Each permission dimension supports:
  • Allow rules - Explicitly permit access to subjects
  • Deny rules - Explicitly prohibit access to subjects (override allow rules)

Basic Permission Structure

Subject Permission Rules

Wildcards

NATS supports two wildcard types:
  • * - Matches a single token
  • > - Matches one or more tokens (must be last)
Examples:

Deny Override

Deny rules always override allow rules:
This user can publish to data.public but NOT data.sensitive.passwords.

User-Level Permissions

Username/Password Users

NKey Users

Account-Based Authorization

Accounts provide complete isolation between groups of users.

Multi-Account Configuration

Users in different accounts cannot communicate unless explicit account imports/exports are configured.

Account Isolation

Accounts provide:
  • Subject namespace isolation - production.orders in PROD is separate from production.orders in DEV
  • Resource isolation - Connection and subscription limits per account
  • Security boundaries - Complete separation between tenants

Response Permissions

Allow clients to respond to request-reply messages dynamically:

Response Permission Behavior

  1. User subscribes to requests.service
  2. Request arrives with reply subject _INBOX.abc123
  3. User granted temporary publish permission to _INBOX.abc123
  4. Permission expires after TTL or max messages reached

Default Response Limits

From source code (server/auth.go:256-261):

Permission Examples

Read-Only Consumer

Publisher-Only

Request-Reply Service

Admin User

Service-Specific Permissions

Connection Type Restrictions

Restrict users to specific connection types:
Supported connection types:
  • STANDARD - Regular NATS clients
  • WEBSOCKET - WebSocket clients
  • LEAFNODE - Leaf node connections
  • MQTT - MQTT clients

Route Permissions

Control what subjects can be imported/exported between servers in a cluster:

Account Imports and Exports

Accounts can selectively share subjects:

Export from Account

Import into Account

Permission Validation

From server/auth.go implementation:

Publish Check

  1. Check deny list first - if matched, reject
  2. If allow list empty, default permit
  3. If allow list exists, subject must match

Subscribe Check

  1. Check deny list first - if matched, reject
  2. If allow list empty, default permit
  3. If allow list exists, subject must match

Testing Permissions

Test permissions before deploying:

Best Practices

1. Principle of Least Privilege

Grant minimal required permissions:

2. Use Deny Rules for Exceptions

3. Organize by Account

Separate environments and tenants:

4. Enable Response Permissions

For request-reply patterns: