Why You Should Stop Using NATS Default $G Account: Account Isolation & Security Design Explained
This article details the security risks of NATS default $G account, explains Account isolation boundaries, $SYS system account, Exports/Imports cross-account contracts, and Operator JWT security model, providing a five-step guide to designing a production-ready secure NATS account system.
Reading font

1. What Is the Default $G Account and Why Is It Unsafe?
In nats-server, G (Global Account) is the implicit default global account created when multi-account configuration is not enabled. If your config lacks an explicit accounts block or uses the legacy top-level authorization.users syntax, all connecting clients are placed into $G.
Running production workloads on $G introduces three major security and stability issues:
Flat Trust Within a Single Account : By default, NATS accounts have no internal defenses. A user without explicit permissions (and no account-level default_permissions ) can publish to any subject in the account and subscribe with > wildcard. Orders, payments, logs, and monitoring scripts all share $G , effectively eliminating lateral isolation.
JetStream and System Resources Lack Boundaries : In a single global space, any unrestricted user can access $JS.API.> management interfaces to create, modify, or delete Streams. A runaway service creating excessive Streams or exhausting connections directly impacts other services in the same account.
Implicit Exposure Traps During Config Evolution : Teams sometimes add system_account for monitoring or retain no_auth_user for legacy clients. If config boundaries aren't strict, unauthenticated connections or legacy users may fall back into the open default space, leaving a backdoor. Note that G is a reserved internal name; you cannot manually declare an account named G in the accounts block or the server will fail to start.
The diagram below contrasts the two deployment models: the red dashed box shows the implicit flat space under default $G where all services are exposed on the same plane; the blue solid box shows the explicit multi-account architecture where each business domain has independent boundaries and cross-domain communication requires explicit contracts.
Default $G shares all subjects; explicit multi-account system achieves hard isolation via independent boundaries and Exports/Imports contracts.
2. Core Concepts and Four Key Properties of NATS Account
To understand why NATS recommends Accounts for multi-tenant isolation, examine the four responsibilities an Account carries on the server side.
Logical Isolation of Subject Namespace
In NATS, Account is the fundamental isolation boundary; User is merely an access credential within an Account . Clients from two different Accounts connecting to the same NATS cluster have completely invisible subject spaces. Even if both ORDERS and ANALYTICS Accounts use the subject orders.created, messages sent and received on each side are isolated.
Independent JetStream Toggle and Resource Quotas
Once an explicit accounts block is introduced, JetStream becomes an opt-in per-account feature. You can precisely decide which Accounts may use persistent streams and set per-account quotas: maximum connections ( max_connections), maximum subscriptions, maximum message payload size, and JetStream storage and Stream count limits. This contains the blast radius of a misbehaving service to its own Account quota.
Special Accounts: $G vs $SYS
Besides custom business Accounts, NATS has two special system-level concepts:
$G (Default Global Account) : Implicit default domain for backward compatibility and quick single-node startup; production environments should replace it entirely via explicit configuration.
$SYS (System Account) : Specified via system_account in the config (typically named SYS ). It exclusively carries cluster-internal control-plane events, server heartbeats, client connect/disconnect audit ( SYS.SERVER.> ), monitoring queries, and dynamic Account resolution traffic. Placing ops and telemetry traffic in a dedicated $SYS Account ensures ordinary business accounts cannot inspect cluster topology or node state.
Cross-Account Communication: Exports and Imports
Isolation does not mean total siloing. When Accounts must exchange data, NATS provides strictly controlled Export and Import mechanisms supporting only two communication contracts:
Stream (Stream Export/Import) : One-way publish/subscribe (Pub/Sub). The exporting Account exposes a subject (wildcards allowed); the importing Account subscribes read-only to those events.
Service (Service Export/Import) : Two-way request/reply (Request-Reply). The importer sends requests to a locally mapped subject; the exporter's microservice processes and returns results. The response_type field declares response shape: default single returns one message per request; stream allows multiple streaming responses (e.g., chunked progress or continuous push).
To avoid subject naming conflicts across Accounts, the importer can use prefix or to fields in imports rules for local remapping (e.g., map ORDERS exported orders.shipped to local ext.orders). In stricter scenarios, the exporter can mark an Export as Private , requiring the importer to present an Activation Token signed by the exporter's private key to complete the binding.
3. From Static Config to Operator Mode: Three Account Management Models Compared
After clarifying Account capabilities, the next question is how to manage them. NATS supports a transition from static config files to a decentralized cryptographic trust chain. The comparison table below contrasts default $G, static accounts block, and Operator JWT mode across isolation, permissions, change management, and key governance.
NAS three account management modes compared: Operator JWT enables dynamic distribution and offline root key governance.
For small teams with fixed Account counts, a static accounts block in nats.conf suffices. But when Accounts and microservices change frequently, updating permissions requires syncing config across all NATS nodes and running reload, creating an operational bottleneck.
Enter NATS decentralized authentication mode (Operator Mode) . It replaces static user lists with Ed25519-based NKey keypairs and signed JWT s, building a three-level trust chain. The server only trusts the top-level Operator public key; at connection time the Account Resolver dynamically fetches Account policies and verifies signatures level by level.
Operator mode three-level cryptographic trust chain: server trusts only root public key, uses Nonce challenge and Resolver for dynamic auth.
Entities in this chain are distinguishable by prefix:
Operator ( O... / private key SO... ) : Root trust anchor for the entire NATS system, signs Account JWTs. In production, the Operator master private key is usually kept offline; daily operations use a rotatable Operator Signing Key for delegated signing.
Account ( A... / private key SA... ) : Represents an independent tenant or business domain. The Account JWT encodes subject rules, JetStream quotas, Exports/Imports contracts, and revocation lists.
User ( U... / private key SU... ) : Concrete client identity. User JWTs can be issued directly by the Account, but best practice uses a Scoped Signing Key — this binds permission templates like "read-only orders" or "write-only logs" to a specific Signing Key. If a Signing Key is compromised, you can precisely revoke the batch of Users it issued without touching the Account root key.
4. Designing a Secure NATS Account System: Five Steps
Combining the above mechanisms, a production-ready secure NATS Account architecture can be built in five steps.
Step 1: Explicitly Declare accounts and system_account , Retire $G
Regardless of cluster size, step one replaces implicit $G with explicit Account structure. In static config mode, at minimum separate the system management domain ( SYS) from business domains, and avoid open no_auth_user in production.
Below is a config example for understanding boundary separation (structural illustration only; production must add TLS certs and strong credentials — do not copy placeholder passwords directly):
listen: "0.0.0.0:4222"
# Explicitly designate system account for $SYS.* ops and monitoring traffic
system_account: "SYS"
accounts: {
SYS: {
users: [
{ user: "sys_monitor", password: "CHANGE_ME_SYS" }
]
},
ORDERS: {
jetstream: enabled
users: [
{ user: "order_writer", password: "CHANGE_ME_ORDER" }
]
},
ANALYTICS: {
# Enable JetStream on demand or keep disabled, fully isolated from ORDERS
users: [
{ user: "bi_reader", password: "CHANGE_ME_BI" }
]
}
}Step 2: Split Accounts by Trust Boundaries and Set Resource Quotas
Don't lump "a company" or "an environment" into a single Account. Split by security trust boundaries and fault isolation domains — typically by business domain (orders, payments, logging platform) or SaaS tenant.
For each business Account, explicitly limit connections, subscriptions, and JetStream disk/memory quotas to prevent a single rogue client from exhausting cluster file descriptors or disk space.
Step 3: Enforce Least Privilege Inside Accounts (Default Deny)
Accounts solve cross-Account isolation, but Users inside an Account still need permission constraints . Follow three practical rules:
Set default_permissions as a Safety Net : At Account level, configure conservative defaults (e.g., deny arbitrary publish/subscribe), then grant precise subjects to specific business Users or Scoped Signing Keys (e.g., only allow publishing orders.created ).
Use allow_responses Instead of Opening _INBOX.> : In Request-Reply, the server must reply to the requester's temporary _INBOX.* address. Don't grant publish.allow: ["_INBOX.>"] for convenience; enable allow_responses . When enabled, nats-server tracks the reply subject carried in each request and only permits responses to the currently valid reply channel.
Separate JetStream Control Plane from Data Plane : Regular business producers only need publish rights on business subjects; they should not hold $JS.API.STREAM.CREATE.> or delete permissions. Stream and Consumer changes should be performed by dedicated deployment/ops accounts or IaC pipelines.
Step 4: Cross-Account Sharing via Explicit Contracts and Private Activation
When ANALYTICS needs to consume ORDERS events or call a cross-team microservice, don't merge them into one Account. Instead, establish minimal contracts via Exports/Imports:
Export only the exact required subjects or controlled sub-prefixes; never export the Account root wildcard >.
On the import side, always add a prefix or remap to a new local subject (e.g., ext.orders.*) to instantly distinguish local vs. external messages.
For sensitive data or cross-team APIs, mark Export as Private and authorize via time-limited Activation Token bound to the specific importing Account public key; revoke or remove promptly when collaboration ends or expires.
Step 5: Production-Grade Key Governance and Transport Hardening
For long-lived multi-team clusters, adopt nsc or the newer nats auth toolchain to migrate to Operator JWT mode, and enforce three key governance rules:
Offline Root Keys : Operator master Seed ( SO... ) and Account master Seeds ( SA... ) kept offline; daily signing done via intermediate Signing Keys.
Short TTL and Revocation : Set reasonable expiry on User JWTs, combine with automated credential rotation; on detecting anomalous clients, update the Account JWT's revocation list (Revocation) to immediately evict affected credentials without server restart.
Understand Account Security Boundaries : Accounts and JWTs provide logical multi-tenant isolation, identity authentication, and subject-level authorization . They do not replace TLS/mTLS transport encryption , nor network-layer firewalls and security groups. Public or cross-datacenter links must enable TLS to prevent JWT or payload sniffing/tampering in transit.
5. When to Stay with Static Config vs. When to Adopt Operator Mode
Security architecture isn't better when more complex; choosing Account management requires weighing operational cost:
Suitable for Static accounts Block : Stable internal system count (e.g., 3–5 core service domains), low change frequency, config fully managed by GitOps or Ansible with rolling reload acceptable. This approach avoids learning NKey, Signing Key, and Account Resolver concepts, and troubleshooting is more straightforward.
Worth Adopting Operator JWT Mode : Multi-team self-service NATS onboarding, need to dynamically provision isolated spaces for external partners or SaaS tenants, require periodic key rotation without server restarts. Although initial investment in learning nsc / nats auth and configuring a distributed Account Resolver (e.g., built-in NATS KV Full Resolver) is needed, the payoff is zero-restart dynamic permission governance.
Replacing default $G with explicit Account boundaries, then tightening intra-Account default allow-all to least privilege based on allow_responses and precise subjects, already eliminates the vast majority of lateral privilege escalation risks in NATS deployments. On that foundation, evolve to Operator JWT based on your team's change velocity — that's the safest adoption path.
For questions about attribution, corrections or content rights, please contactand we will review it promptly.