Qaze Logo
Back to NATS Knowledge Base
Security

What are NATS Nkeys?

NATS Nkeys are a cryptographic system introduced by NATS to provide a secure and decentralized way to manage and verify identities within the NATS ecosystem. They are based on public-key cryptography and are designed to be lightweight and easy to use, while offering a strong security foundation for authentication and authorization.

Key Concepts

Public-Key Cryptography

Public-key cryptography is a system that uses pairs of keys: public keys, which can be shared openly, and private keys, which are kept secret. In the context of NATS Nkeys, the private key is used to create digital signatures, and the corresponding public key is used to verify those signatures.

Nkey Types

NATS Nkeys are categorized into different types based on their purposes:

  • Operator Nkeys: These are the top-level keys used to manage and define the entire NATS deployment, including accounts and users.
  • Account Nkeys: These are used to manage individual accounts within a NATS deployment. Accounts are a way to logically group users and subjects for better organizational control.
  • User Nkeys: These are associated with individual users within an account and are used for end-user authentication.

Generating Nkeys

Nkeys can be generated using the nkeys command-line tool provided by NATS. This tool can create keys for operators, accounts, and users. The generation process involves creating a new key pair (public and private keys) and securely storing the private key.

Secure Key Storage

It is crucial to store private keys securely to prevent unauthorized access. Private keys can be encrypted and stored in secure hardware modules, databases, or secure file storage systems.

Digital Signatures

Nkeys use digital signatures for authentication. When a user or system needs to authenticate, it generates a digital signature using its private key. This signature can then be verified by others using the corresponding public key. This ensures that the entity presenting the signature is indeed the holder of the private key, thereby authenticating its identity.

Authentication and Authorization

In a NATS deployment, the process of authenticating and authorizing users involves verifying their digital signatures against the public keys defined in their Nkeys. Operators and account managers can set up various policies and permissions based on these keys, providing fine-grained control over which users can access which resources.

Benefits of Using Nkeys

  • Security: The use of strong cryptographic methods ensures that identities are secure and hard to spoof.
  • Decentralization: Nkeys do not rely on a central authority for identity management. Each entity manages its own keys.
  • Portability: Nkeys are lightweight and can be easily transferred and integrated into different systems.
  • Scalability: The system is designed to scale efficiently, even as the size of the deployment grows.

Summary

NATS Nkeys provide a robust, secure, and efficient way to manage identities and control access within the NATS system. By leveraging public-key cryptography, Nkeys offer strong security guarantees while remaining simple and flexible to use. This makes them an excellent choice for modern distributed systems requiring secure and scalable identity management.