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:- Publish Permissions - Control which subjects a user can publish messages to
- Subscribe Permissions - Control which subjects a user can subscribe to
- 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)
Deny Override
Deny rules always override allow rules: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.ordersin PROD is separate fromproduction.ordersin 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
- User subscribes to
requests.service - Request arrives with reply subject
_INBOX.abc123 - User granted temporary publish permission to
_INBOX.abc123 - 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:STANDARD- Regular NATS clientsWEBSOCKET- WebSocket clientsLEAFNODE- Leaf node connectionsMQTT- 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
- Check deny list first - if matched, reject
- If allow list empty, default permit
- If allow list exists, subject must match
Subscribe Check
- Check deny list first - if matched, reject
- If allow list empty, default permit
- If allow list exists, subject must match