natsauth

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: 7 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 natsauth is the auth group under osapi nats: osapi nats auth password create and operator create, which make the authentication of a NATS setup for osapi, with a credential for each osapi role (osapi-io/osapi#1420).

Index

Constants

This section is empty.

Variables

View Source
var Group = command.Register(command.Define(
	"auth",
	"Make the NATS authentication of osapi, a credential for each role",
	command.Under(command.ParentNATS),
	command.Uses[Deps](),
	command.SubDoc("password", "A user and a password for each osapi role"),
	command.SubDoc("nkey", "An nkey for each osapi role"),
	command.SubDoc(
		"operator",
		"An operator, an account and a credentials file for each osapi role",
	),
	command.Method[CreateInput, CreateOutput]("create").
		Sub("password").
		Short("Make a user and a random password for each osapi role").
		Long("It makes a user for each osapi role (setup, controller, agent and join), each\n"+
			"with a random password and the least permissions of its role. It writes\n"+
			"`osapi-nats.yaml`, the part of osapi.yaml with the users of the embedded\n"+
			"server and the auth of the controller and the agent, and `nats-server.conf`,\n"+
			"the authorization block of a NATS server that osapi does not run. Each file\n"+
			"is mode 0600, and no password is on the command line. `--print` also\n"+
			"prints the server's block.").
		Example("--out /etc/osapi/nats").
		Prints(samplePassword).
		Fails("no directory", CreateInput{}).
		Handle(Password),
	command.Method[CreateInput, CreateOutput]("create").
		Sub("operator").
		Short("Make an operator, an account, and a credentials file for each osapi role").
		Long("It makes an operator, its system account, and an account for osapi with\n"+
			"JetStream. It writes the server's resolver file (`resolver.conf`), a\n"+
			"credentials file for the setup, controller and agent roles, each with the\n"+
			"least permissions of its role, and `osapi-nats.yaml`, the part of osapi.yaml\n"+
			"that uses them. Each file is mode 0600.\n\n"+
			"The controller mints the users of a join with two scoped signing keys:\n"+
			"`agent-signing.nk`, whose template is the agent role's permissions, and\n"+
			"`join-signing.nk`, the join role's. Thus the controller cannot mint a user\n"+
			"with more than an agent or a join user has. Keep `operator.nk` and\n"+
			"`account.nk` offline: they sign the accounts and the static users.\n"+
			"`--print` also prints the resolver file.").
		Example("--out /etc/osapi/nats").
		Prints(sampleOperator).
		Fails("no directory", CreateInput{}).
		Handle(Operator),
	command.Method[UpdateInput, CreateOutput]("update").
		Sub("operator").
		Short("Sign the account and each role's credentials again, with the same keys").
		Long("It reads the keys that `operator create` wrote to the directory, and writes\n"+
			"`resolver.conf` and the credentials file of each osapi role again, with the\n"+
			"permissions that each role has in this version of osapi. Run it after an\n"+
			"upgrade that adds a permission to a role, such as the rotation of an agent's\n"+
			"keys. The account's JWT holds the agent's permissions as the template of its\n"+
			"scoped signing key, and each credentials file holds the permissions of its\n"+
			"role, so an upgrade does not change them. The keys stay, so each agent keeps\n"+
			"its user and no agent joins again. Restart the NATS server, which reads the\n"+
			"resolver file at its start, then the controller, for its new credentials.\n"+
			"It needs `operator.nk` and `account.nk`.").
		Example("--out /etc/osapi/nats").
		Prints(sampleOperator).
		Fails("no directory", UpdateInput{}).
		Handle(OperatorUpdate),
	command.Method[CreateInput, CreateOutput]("create").
		Sub("nkey").
		Short("Make an nkey for each osapi role").
		Long("It makes an nkey for the setup, controller and agent roles, and writes the\n"+
			"seed of each (`setup.nk`, `controller.nk`, `agent.nk`), `osapi-nats.yaml`, the\n"+
			"part of osapi.yaml with the nkeys of the embedded server and their roles\n"+
			"(`nkey_roles`), and `nats-server.conf`, the authorization block of a NATS\n"+
			"server that osapi does not run, with the least permissions of each role.\n"+
			"Each file is mode 0600. A join over NATS needs a password or a JWT for its\n"+
			"bootstrap user: use `password create` or `operator create` for it.\n"+
			"`--print` also prints the server's block.").
		Example("--out /etc/osapi/nats").
		Prints(sampleNKey).
		Fails("no directory", CreateInput{}).
		Handle(NKey),
))

Group is the auth group's definition.

Functions

This section is empty.

Types

type CreateInput

type CreateInput struct {
	Out   string `json:"out"   validate:"required"  doc:"The directory that the files go to. It is made, mode 0700, when it is not there"`
	Print bool   `json:"print" validate:"omitempty" doc:"Also print the server's part: its authorization block, or its resolver file"`
}

CreateInput is the input of a create.

type CreateOutput

type CreateOutput struct {
	Files  []Written `                  json:"files"`
	Server string    `                  json:"server,omitempty" label:"Server config"`
	// contains filtered or unexported fields
}

CreateOutput is what a create wrote. It never holds a secret, except Server with --print, which the operator asked for.

func NKey

func NKey(
	ctx context.Context,
	d Deps,
	in CreateInput,
) (CreateOutput, error)

NKey makes an nkey for each osapi role.

func Operator

func Operator(
	ctx context.Context,
	d Deps,
	in CreateInput,
) (CreateOutput, error)

Operator makes an operator, an account and a credentials file for each osapi role.

func OperatorUpdate

func OperatorUpdate(
	ctx context.Context,
	d Deps,
	in UpdateInput,
) (CreateOutput, error)

OperatorUpdate signs the account and the credentials of each osapi role again, with the keys that operator create made and the permissions that each role has now.

func Password

func Password(
	ctx context.Context,
	d Deps,
	in CreateInput,
) (CreateOutput, error)

Password makes a user and a password for each osapi role.

type Deps

type Deps struct {
	FS     avfs.VFS
	Config config.Config
	// Audit writes an entry to the audit log of the controller, or is nil.
	// It fails when NATS cannot be reached, such as before NATS starts.
	Audit func(ctx context.Context, e audit.Entry) error
}

Deps is what a create uses: the file system and the config, whose streams, buckets and namespace the permissions name.

type UpdateInput

type UpdateInput struct {
	Out   string `` /* 137-byte string literal not displayed */
	Print bool   `json:"print" validate:"omitempty" doc:"Also print the server's resolver file"`
}

UpdateInput is the input of an update.

type Written

type Written struct {
	Role string `json:"role"`
	Path string `json:"path"`
}

Written is a file that a create wrote.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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