NATS gives every connecting service a cryptographic identity, so securing a NATS deployment is mostly a job of managing non-human identities well: who holds which seed, which account it belongs to, and which subjects it may touch. NATS is a messaging system used to connect microservices, edge devices and data pipelines. Its security model covers three things: encrypting connections with TLS, authenticating clients, and authorising what each client may publish or subscribe to. This guide walks through each layer from a platform and identity point of view, with the settings named as they appear in the NATS documentation.
The audience is platform engineers, SREs and security teams who run NATS servers or clusters, or who review how applications connect to them. If you are looking for guidance on consumer chat apps rather than server messaging infrastructure, see the Securing Messaging Apps Guide.
This is an independent guide from NHI Mgmt Group, based on the NATS project's public documentation as of November 2026. It is not sponsored or reviewed by the NATS project or its maintainers. Product features change, so confirm settings against the current NATS documentation.
Key takeaways
- NATS security has three layers: TLS for encryption, authentication for identity, and subject level authorisation for what each identity may do. Plan all three together.
- NKeys use Ed25519 public key signatures. The server stores only public keys and verifies a signed challenge, so it never sees a client's private key.
- An NKey seed (a string beginning with
S) is a private key. Treat every seed as a secret with an owner, a storage location and a rotation plan. - Decentralised JWT authentication creates a chain of trust: operators issue accounts, and accounts issue users. Protect operator and account signing keys as tier zero assets.
- Accounts isolate tenants and applications. The NATS documentation suggests thinking of one account as a messaging container for one application.
- Permissions are allow lists and deny lists on subjects. Wildcards such as
>and broad_INBOX.>subscriptions are the most common source of over privilege. - The TLS
insecureoption skips certificate verification on outgoing connections and is marked not recommended in the documentation. Keep it out of production.
Why NATS is a non-human identity problem
Almost every client of a NATS server is software: a microservice, a job runner, an IoT gateway, a leaf node in a remote site or another NATS server in a cluster. Each one needs a credential to connect, and each credential grants access to a slice of the subject space. That makes NATS a concentrated store of machine identities, and the usual non-human identity questions apply directly.
- Inventory: which users, NKeys and JWTs exist, and which workload uses each one?
- Ownership: who is accountable for each account and each signing key?
- Least privilege: does each identity hold only the publish and subscribe rights its job needs?
- Lifecycle: how are credentials issued, rotated and revoked when a service is retired or a seed leaks?
Messaging systems also carry sensitive payloads: orders, telemetry, commands to devices and events that drive automation. A client that can publish to a command subject can often change system behaviour, and a client that can subscribe broadly can read data that was never meant for it. Treat publish rights on control subjects with the same care as write access to a production database.
The three layers of NATS security
The NATS documentation describes three forms of security that the server provides: connections can be encrypted with TLS, client connections can require authentication, and clients can be authorised for the subjects they publish or subscribe to. Each layer covers a different risk.
| Layer | What it protects against | Main configuration |
|---|---|---|
| TLS | Eavesdropping and tampering on client, route and monitoring connections | The tls map: cert_file, key_file, ca_file, min_version, verify |
| Authentication | Unknown clients connecting to the server | Users with NKeys, decentralised JWT with an operator, or certificate mapping with verify_and_map |
| Authorisation | A known client reading or writing subjects outside its role | permissions with publish, subscribe, allow, deny and allow_responses; accounts with exports and imports |
A common mistake is to switch on one layer and assume the others follow. TLS on its own encrypts traffic but lets any client with network access connect. Authentication without subject permissions lets every authenticated service see every subject. Design all three before the first production client connects.
NKeys: public key identities for services
NKeys are the foundation of NATS identity. The documentation describes them as a public key signature system based on Ed25519. When a client connects, the server sends a random challenge, the client signs it with its private key, and the server checks the signature against the public key it has on record. Because the challenge is new for every connection request, the documentation states that this design is immune to playback attacks, and the server can verify identities without ever storing or seeing private keys.
The documentation positions NKeys as a replacement for token authentication, because a connecting client must prove that it controls the private key for the authorised public key. A shared token, by contrast, works for anyone who copies it.
Reading NKey prefixes
NKeys are generated with the nk tool, for example nk -gen user -pubout. The output has two lines:
- The first line starts with
Sfor seed. The second letter shows the role, soSUis a user seed. The documentation states that seeds are private keys and must be treated as secrets and guarded with care. - The second line starts with
Ufor user and is the public key, which can be shared safely.
The prefix rule is useful for security tooling. A secrets scanner or log filter can flag strings that look like NATS seeds, and a reviewer can tell at a glance whether a value in a configuration file is a public key (safe) or a seed (a leak).
Configuring NKey users
To use NKey authentication without JWTs, the server configuration lists users under authorization, each with an nkey property set to the user's public key. No password or token is needed, and permissions can be added per user. The client supplies its public key and a signing callback that loads the seed and signs the server's nonce.
The documentation's client example shows a seed held as a constant in code, with a comment saying the client loads the seed safely from a file or a constant. In production, prefer the file or a secrets manager. A seed embedded in application source ends up in version control, build logs and container images.
Decentralised JWT authentication and the chain of trust
With plain NKey or password users, every user must be listed in the server configuration, and an administrator must edit and reload that configuration for each change. Decentralised JWT authentication moves the description of accounts, users and permissions into signed JSON Web Tokens that are managed separately from the server. The documentation calls this a distributed configuration paradigm.
Operators, accounts and users
NATS defines three NKey roles: operators, accounts and users. They form a chain of trust. Operators issue accounts, accounts issue users, and servers are configured to trust specific operators. If an account was issued by a trusted operator, users of that account are trusted.
NATS restricts JWTs more tightly than many systems. The documentation states that NATS JWTs must always be digitally signed using Ed25519, that issuer and subject fields must be public NKeys, and that issuer and subject must match the roles expected for the claim. JWTs that are not signed with Ed25519 are rejected.
How a connection is checked
When a user connects, it presents a user JWT issued by its account and signs a server challenge with its private key. The server verifies the signature against the user's public key, retrieves the account JWT that issued the user, and checks that the user's issuer matches the account. Authorisation then comes from the account (its exports, imports and limits such as maximum connections) and from the user JWT, which can restrict the subjects the user may publish or subscribe to.
JWTs here are configuration, not sessions
An important detail from the documentation: in many systems a JWT is a session or a proof of authentication, but NATS JWTs are only configuration. They describe the public ID of the entity, the public ID of its issuer and its capabilities. Authentication is the signed nonce. This changes how you think about exposure:
- A leaked user JWT on its own does not let an attacker connect, because the attacker still needs the matching private key to sign the challenge.
- A leaked user seed is the real credential. In practice the two are often stored together in a single credentials file, so protect the file as a secret.
- A leaked account or operator signing key is far worse, because it lets the holder issue new identities that servers will trust.
For a wider view of token design, see the JWT Security Guide.
Managing the hierarchy with nsc
The documentation describes the nsc tool as the practical way to create NKeys and JWTs for operators, accounts and users and to synchronise them with the account resolvers built into the server. Once servers trust an operator, little server configuration changes as users come and go. The documentation also notes that an operator can issue account JWTs while a separate team issues user JWTs for its own account, and neither needs the other's private NKey.
That separation is valuable for least privilege. An application team can mint credentials for its own services without holding the operator key, and the platform team never needs to see application seeds. Write down who holds each operator and account key, where it lives, and who can approve its use.
Accounts and multi-tenancy
Accounts are the main isolation boundary in NATS. The documentation describes them as securely isolated communication contexts that allow multi-tenancy. Messages published by users in one account are not visible to users in another account unless the accounts explicitly export and import subjects.
The documentation also explains why accounts matter: with traditional authorisation, clients can publish and subscribe to anything unless configured otherwise, so administrators have to carve up the subject space carefully. Accounts avoid that by giving each group its own subject space. The documentation advises thinking of one account as a messaging container for one application, and states that more accounts with few clients is a better design than one large account.
Exports and imports
Accounts share data through exports and imports. A stream export shares messages an account publishes. A service export lets other accounts send requests that the exporting account fulfils. In the export configuration map, the accounts property lists which accounts may import. The documentation states that if accounts is not specified, the stream or service is public and any account can import it.
That default is the one to watch. Review every export and confirm that it names the importing accounts, unless sharing with every account on the system is genuinely intended. The documentation also notes that the word stream here refers to a flow of core NATS messages and should not be confused with a JetStream stream.
Subject permissions and least privilege
Within an account, or on a server using users without accounts, authorisation is set per user with a permissions map. The publish and subscribe properties take a subject, a list of subjects or a permission map with allow and deny lists. Where allow and deny overlap, the documentation states that deny wins.
Default permissions
The default_permissions entry applies to every user that has no permissions of its own. Set it deliberately. A restrictive default means a new user created without permissions gets very little; a broad default means every forgotten user is over privileged.
Wildcards and inboxes
The documentation's examples use > to match any subject for an admin role. That is appropriate for a small number of break glass identities, not for services. Request and reply patterns need care too. Replies typically go to subjects that start with _INBOX., and the documentation warns that any client allowed to subscribe to _INBOX.> can receive all responses published. It suggests that more sensitive installations add or narrow the inbox prefix, or use accounts to separate traffic.
Allow responses
For service responders, the allow_responses option grants temporary permission to publish to reply subjects. Enabling it implicitly denies publishing to other subjects, unless an explicit publish allow overrides that. The responses map takes max (the maximum number of response messages) and expires (how long the permission lasts). The documentation states that true is equivalent to { max: 1 } with no time limit, and that nsc offers --allow-pub-response and --response-ttl for the same controls. For a responder service, this is usually tighter than granting publish on a wide inbox pattern.
| Role | Suggested shape (NHI Mgmt Group recommendation) |
|---|---|
| Producer service | Publish to its own subjects only; no subscribe beyond what it needs |
| Consumer service | Subscribe to named subjects or queue groups; no publish except replies |
| Responder service | Subscribe to request subjects; allow_responses with a low max and an expires value |
| Requestor client | Publish to request subjects; subscribe to a narrowed inbox prefix |
| Administrator | > rights held by very few identities, with separate credentials and monitoring |
TLS for clients, clusters and leaf nodes
NATS uses TLS to encrypt client, route and monitoring connections. Configuration revolves around a tls map. The settings that matter most for security are:
cert_fileandkey_file: the server certificate and its private key. The key file is another machine secret to protect.ca_file: the certificate authority bundle. When it is not set, the server uses the system trust store.min_version: the minimum TLS version. The documented default is 1.2.verify: require and verify client certificates. The documentation notes this does not apply to monitoring.verify_and_map: require and verify client certificates and map certificate values to users for authentication.pinned_certs: a list of SHA256 public key fingerprints; connections presenting other certificates are closed.insecure: skip certificate verification on outgoing connections only. The documentation marks this not recommended.connection_rate_limit: caps new TLS client connections per second on the client listener. The default of 0 disables the limit.
TLS first handshake
By default the server sends an INFO protocol message in clear text when a TCP connection opens, before TLS begins. From NATS v2.10.4, setting handshake_first: true in the tls block makes the server expect a TLS handshake straight away. The documentation explains that values such as auto or a duration fall back to sending INFO after a delay so older clients can connect, and that administrators who want no data sent in plain text must use true. Only clients that support the option can connect when it is on.
Certificates between servers
Cluster and gateway connections always have verify enabled, according to the documentation. For clusters, certificates must carry both the server authentication and client authentication extended key usages, because either side may act as client. When clients discover servers through cluster advertisements, set the advertised names so they match the certificate subject alternative names, otherwise hostname verification fails.
Rotation
The documentation advises keeping both old and new root or intermediate certificates in ca_file during rotation, because servers in different places rarely rotate at exactly the same moment. Certificate file changes take effect after a configuration reload. Self signed certificates are for testing only; the documentation is explicit that they should not be used in production.
Behind a TLS terminating proxy
If a reverse proxy terminates TLS, the documentation describes an empty tls block with allow_non_tls: true. Use this only when the proxy to server path is on a trusted network segment, and record the exception, because that hop is unencrypted.
For background on certificates and handshakes, see the How TLS Works Guide.
Protecting seeds, signing keys and credentials files
Every strong control above depends on keeping private keys private. NHI Mgmt Group recommends treating NATS key material in tiers:
- Operator signing keys: the root of trust. Keep them offline or in a hardware backed store, limit who can use them, and log every use.
- Account signing keys: can mint users for that account. Hold them in a secrets manager owned by the account's team.
- User seeds and credentials files: one per workload, delivered at runtime from a secrets manager or a mounted secret, never baked into images or committed to repositories.
- TLS private keys: the
key_filefor servers and client certificates, with file permissions limited to the process that needs them.
Add NATS seed patterns to your secret scanning rules. Because the public half of an NKey is safe to share, logs and dashboards can show user public keys for traceability without exposing anything secret. When a service is retired, remove its user from the account rather than leaving it dormant, and when a seed is exposed, replace the user identity and remove the old one. For the difference between rotating and revoking, see Secret Rotation vs Revocation.
Common failure patterns
- Shared credentials across services: one user or token used by many workloads, so no single service can be revoked without breaking the rest.
- Seeds in source code: copying the documentation's example literally and embedding a seed as a constant in application code.
- Public exports by default: exports with no
accountslist, which the documentation says makes them importable by any account. - Everything in one account: a single large account with complex subject carving, instead of one account per application.
- Broad inbox subscriptions: granting
_INBOX.>to many clients, which lets each of them receive every response. - Admin wildcards for services:
>publish and subscribe rights given to application identities for convenience. - Insecure TLS in production:
insecureleft on after testing, or self signed certificates promoted to production. - Unowned signing keys: operator or account keys on an engineer's laptop with no record of who holds them.
Practitioner checklist
- Inventory every NATS user, NKey and JWT, and map each to a named workload and owner.
- Use NKeys or decentralised JWT authentication for services instead of shared passwords or tokens.
- Store operator and account signing keys in controlled, logged locations, separate from application credentials.
- Deliver user seeds and credentials files at runtime from a secrets manager; scan repositories and images for seed strings.
- Create one account per application and list importing accounts on every export.
- Set a restrictive
default_permissionsand give each user explicit publish and subscribe lists. - Narrow inbox prefixes and use
allow_responseswithmaxandexpiresfor responders. - Enable TLS on client, cluster, gateway and leaf node connections, keep
min_versionat 1.2 or higher, and never shipinsecure. - Consider
handshake_first: trueonce all clients support it, so no data is sent in plain text. - Plan certificate rotation with old and new CAs in
ca_file, and reload configuration after changes. - Remove users for retired services and replace identities whose seeds may have been exposed.
Standards and references
- NATS documentation: Securing NATS (NKeys, JWT, TLS, authorisation and accounts pages)
- NIST SP 800-53 Rev. 5: AC-6 Least Privilege, IA-5 Authenticator Management, SC-8 Transmission Confidentiality and Integrity
- NIST SP 800-52 Rev. 2, Guidelines for the Selection, Configuration, and Use of TLS Implementations
- NIST SP 800-207 Zero Trust Architecture
- MITRE ATT&CK T1552 Unsecured Credentials
- MITRE ATT&CK T1078 Valid Accounts
Related NHI Mgmt Group resources: Securing Messaging Apps Guide · JWT Security Guide · How TLS Works Guide · Secret Rotation vs Revocation