jwtkey

package
v1.6.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// JWTKeyBucketName is the NATS KV bucket for JWT signing key distribution
	JWTKeyBucketName = "neuwerk-jwt-key"
	// JWTKeyName is the key name for the JWT signing key in the KV bucket
	JWTKeyName = "signing-key"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager handles JWT signing key generation and distribution for multi-node clusters. It follows the same encryption pattern as CA key distribution:

  1. Leader generates JWT signing key during bootstrap
  2. Key is encrypted with bootstrap token (using HKDF + AES-GCM like CA keys)
  3. Encrypted key is stored in NATS KV bucket
  4. Followers retrieve and decrypt the key from NATS KV
  5. All nodes save the key to local disk for persistence across restarts

func NewManager

func NewManager(bootstrapToken token.SecureToken, jwtKeyPath string, logger logr.Logger) (*Manager, error)

NewManager creates a new JWT key distribution manager.

func (*Manager) GenerateAndDistribute

func (m *Manager) GenerateAndDistribute(ctx context.Context, js jetstream.JetStream) error

GenerateAndDistribute generates a JWT signing key and stores it in NATS KV. Called by the bootstrap leader before CA generation. The key is encrypted using the same pattern as CA keys (PKCS#8 with AES-256-GCM).

func (*Manager) LoadOrRetrieve

func (m *Manager) LoadOrRetrieve(ctx context.Context, js jetstream.JetStream) (*rsa.PrivateKey, error)

LoadOrRetrieve loads the JWT signing key from local disk if it exists, otherwise retrieves it from NATS KV (for restart scenarios). Returns the private key or error if neither disk nor KV contains the key.

func (*Manager) RetrieveAndSave

func (m *Manager) RetrieveAndSave(ctx context.Context, js jetstream.JetStream) error

RetrieveAndSave retrieves the JWT signing key from NATS KV and saves it to local disk. Called by bootstrap followers after CAs are received. Polls with backoff for up to 30 seconds (matches CA distribution timeout).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL