natscallout

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package natscallout is osapi's NATS auth callout service. A NATS server with an auth_callout block sends each new connection to it, and it decides who the connection is: a host with a join token, or an admitted agent with its NATS user key. It answers with a user JWT that has the permissions of that role, signed with the issuer key that the server's block names.

Index

Constants

View Source
const Subject = "$SYS.REQ.USER.AUTH"

Subject is where a NATS server sends each authorization request.

Variables

View Source
var ErrRefused = errors.New("refused")

ErrRefused is a connection that the callout does not admit.

Functions

func VerifyNkey

func VerifyNkey(
	req *jwt.AuthorizationRequest,
) error

VerifyNkey is nil when the connection of req holds the seed of its nkey: the server's nonce, signed with that key. The server does not check it, because the callout decides the connection.

Types

type Decide

type Decide func(ctx context.Context, req *jwt.AuthorizationRequest) (Decision, error)

Decide is who the connection of req is, or an error that refuses it. Its error message goes back to the server, so it must hold no secret.

type Decision

type Decision struct {
	// Name is the user's name in the server, such as agent:<machine ID>.
	Name string
	// Permissions are the subjects of its role.
	Permissions bus.Permissions
	// Expires is when the server closes the connection, or zero for never.
	Expires time.Time
}

Decision is who a connection is: its name, and what it may do until it expires.

type Service

type Service struct {
	// Issuer is the account key that the server's auth_callout names as its
	// issuer. It signs each answer and each user JWT.
	Issuer nkeys.KeyPair
	// Account is the account that a user joins, such as OSAPI.
	Account string
	// Decide decides each connection.
	Decide Decide
	Logger *slog.Logger
}

Service answers the authorization requests of a NATS server.

func (Service) Reply

func (s Service) Reply(
	ctx context.Context,
	data []byte,
) ([]byte, error)

Reply is the answer to the authorization request in data: a signed response with a user JWT, or with the reason of a refusal.

func (Service) Serve

func (s Service) Serve(
	ctx context.Context,
	subscribe Subscribe,
) error

Serve answers each authorization request until ctx ends. subscribe must be of a connection of one of the server's auth_users, which the callout does not decide.

type Subscribe

type Subscribe func(subject string, handler nats.MsgHandler) (*nats.Subscription, error)

Subscribe subscribes a handler to a subject: the Subscribe of a NATS connection.

Jump to

Keyboard shortcuts

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