Managing JWT Security
If you are using the JWT model of authentication to secure your NATS infrastructure or implementing an Auth callout service, you can administer authentication and authorization without having to change the servers' configuration files.
You can use the nsc
CLI tool to manage identities. Identities take the form of nkeys. Nkeys are a public-key signature system based on Ed25519 for the NATS ecosystem. The nkey identities are associated with NATS configuration in the form of a JSON Web Token (JWT). The JWT is digitally signed by the private key of an issuer forming a chain of trust. The nsc tool creates and manages these identities and allows you to deploy them to a JWT account server, which in turn makes the configurations available to nats-servers.
You can also use nk
CLI tool and library to manage keys.
Creating, updating and managing JWTs programmatically
You can create, update and delete accounts and users programmatically using the following libraries:
Java: see NKey.java and JwtUtils.java
Integrating with your existing authentication/authorization system
You can integrate NATS with your existing authentication/authorization system or create your own custom authentication using the Auth callout.
Examples
See NATS by Example under "Authentication and Authorization" for JWT and Auth callout server implementation examples.
User JWTs
Account JWTs
Golang example from https://natsbyexample.com/examples/auth/nkeys-jwts/go
Notes
You can see the key (and any signing keys) of your operator using nsc list keys --show-seeds
, you should use a 'signing key' to create the account JWTs (as singing keys can be revoked/rotated easily)
To delete accounts use the "$SYS.REQ.CLAIMS.DELETE"
(see reference) and make sure to enable JWT deletion in your nats-server resolver (config allow_delete: true
in the resolver
stanza of the server configuration).
The system is just like any other account, the only difference is that it is listed as system account in the operator's JWT (and the server config).
Last updated