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 ¶
const Subject = "$SYS.REQ.USER.AUTH"
Subject is where a NATS server sends each authorization request.
Variables ¶
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 ¶
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.
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.