pkikey

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: 20 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 pkikey is the key group under osapi pki: osapi pki key list, get, create and rotate, which read, make and rotate the keys of osapi on this host.

Index

Constants

View Source
const (
	// KindSigning is a key that signs, such as the controller's.
	KindSigning = "signing"
	// KindEncryption is a key that encrypts, such as the JetStream store's.
	KindEncryption = "encryption"
)

The kinds of key.

View Source
const (
	// StateOK is a key that osapi read.
	StateOK = "ok"
	// StateNotMade is a key whose file is not there, as on a host where its
	// component has not started.
	StateNotMade = "not made"
	// StateOff is the JetStream key when the config sets no key_file: the
	// store is not encrypted.
	StateOff = "off"
)

The states of a key.

Variables

View Source
var (
	ErrNoKey    = errors.New("no key with this name: list shows each")
	ErrNotMade  = errors.New("not made")
	ErrExists   = errors.New("the key exists")
	ErrNoRotate = errors.New("osapi does not rotate this key")
)

Errors of the key commands.

View Source
var Group = command.Register(command.Define(
	"key", "List, make and rotate the keys of osapi on this host",
	command.Under(command.ParentPKI),
	command.Uses[Deps](),
	command.Method[ListInput, ListOutput]("list").
		Short("List the keys, with their state, algorithm and fingerprint or ID").
		Long("Run this on the host. It reads each key of osapi that the config names:\n"+
			"the controller's Ed25519 signing key in controller.pki.key_dir, the agent's\n"+
			"Ed25519 signing key and P-256 encryption key in agent.pki.key_dir, the key\n"+
			"of the JetStream store in nats.server.jetstream.key_file, and the key of each\n"+
			"vault of type nats. A public key shows its fingerprint, and a secret key\n"+
			"shows its ID: never the key. A component that has not started on this host\n"+
			"made no key: its state is not made.").
		Example("").
		Prints(sampleList).
		Handle(List),
	command.Method[GetInput, Key]("get").
		Short("Show one key in full; the agent's key has the command that admits this machine").
		Long("It reads one key, as list does. The agent's signing key also has the\n"+
			"command that admits this machine, with its machine ID and the fingerprint\n"+
			"that covers the agent's two keys. A key that is not on this host is an\n"+
			"error that names osapi pki key create.").
		Example("--name agent").
		Prints(sampleAgent).
		Fails("no name", GetInput{}).
		Fails("a name of more than 64 characters", GetInput{Name: strings.Repeat("a", 65)}).
		Handle(Get),
	command.Method[CreateInput, Key]("create").
		Short("Make a key that is not on this host").
		Long("It makes the key with the name, with mode 0600: the signing key of the\n"+
			"controller, the two keys of the agent, a random key for the JetStream\n"+
			"store, or a random AES-256 key for a vault. It refuses a key that is there,\n"+
			"because a new key in its place is a rotation: a JetStream store and the\n"+
			"values of a vault do not decrypt with it, and an admission does not match\n"+
			"it. The controller and the agent make their keys at their first start, so\n"+
			"run this to make a key before then, such as the JetStream key before NATS\n"+
			"starts. Keep a copy of a JetStream or a vault key apart from the backup of\n"+
			"what it encrypts.").
		Example("--name jetstream").
		Prints(sampleJetStream).
		Fails("no name", CreateInput{}).
		Fails("a name of more than 64 characters", CreateInput{Name: strings.Repeat("a", 65)}).
		Handle(Create),
	command.Method[RotateInput, RotateOutput]("rotate").
		Short("Rotate the agent's keys, the controller's key or the key of a vault").
		Long("For the agent, it makes two new keys beside the old ones and sends them to\n"+
			"the controller over NATS, as the agent connects, signed with the old\n"+
			"signing key and the new one. The controller takes them in place of the\n"+
			"admitted keys, with no new admission, and keeps the old signing key valid\n"+
			"for controller.pki.rotation_grace_period. Then it moves the new keys in\n"+
			"place, and a running agent reads them at its next heartbeat. A refusal\n"+
			"removes the new keys. When the controller does not answer, the new keys\n"+
			"stay, and a second rotation sends them again.\n\n"+
			"For a vault of type nats, it adds a new key to its key_file, encrypts each\n"+
			"value of the vault again with it, then drops the old key. It connects to\n"+
			"NATS as the controller does. A running controller reads the new key at its\n"+
			"next call. A rotation that stops leaves the old key in the file, and a\n"+
			"second rotation completes it.\n\n"+
			"For the controller, on the controller's host, it makes the next key beside\n"+
			"the current one, and writes a record that the current key signs to the\n"+
			"state bucket. Each agent takes the next key at its next heartbeat. The\n"+
			"controller switches to it when each admitted agent has it, or when\n"+
			"controller.pki.rotation_grace_period ends, with no new admission.\n"+
			"osapi client pki key rotate does the same from any host, through the API.\n\n"+
			"It refuses the JetStream key, with what to do instead: a new JetStream key\n"+
			"makes the store unreadable.").
		Example("--name vault:default").
		Prints(sampleRotate).
		Check("pki key get", "--name vault:default",
			"state", "ok", "key_id", "{out.key.key_id}", "keys", "{out.key.keys}").
		Fails("no name", RotateInput{}).
		Fails("a name of more than 64 characters", RotateInput{Name: strings.Repeat("a", 65)}).
		Handle(Rotate),
))

Group is the key group's definition.

Functions

This section is empty.

Types

type CreateInput

type CreateInput struct {
	Name string `json:"name" validate:"required,max=64" doc:"The name of the key, as list shows it, such as jetstream or vault:default."`
}

CreateInput names the key to make.

type Deps

type Deps struct {
	FS          avfs.VFS
	Config      config.Config
	Identity    func() (*identity.Identity, error)
	Dial        func(ctx context.Context) (natsvault.KV, func(), error)
	RotateAgent func(ctx context.Context) (string, error)
	LookupEnv   func(key string) (string, bool)
	Audit       func(ctx context.Context, e audit.Entry) error
}

Deps is what the key commands use: the file system, the config that names each key, the identity of this machine for the admission of its agent, what connects to NATS for a rotation of a vault key, what rotates the agent's keys with the controller, how an environment variable is read for a vault with key_env, and the record of a change in the audit log, or nil.

type GetInput

type GetInput struct {
	Name string `` /* 138-byte string literal not displayed */
}

GetInput names a key.

type Key

type Key struct {
	Name        string `json:"name"`
	Kind        string `json:"kind"                  doc:"signing or encryption."`
	Component   string `json:"component"             doc:"The component that uses the key: controller, agent, nats or vault."`
	State       string `` /* 169-byte string literal not displayed */
	File        string `` /* 179-byte string literal not displayed */
	Algorithm   string `json:"algorithm"             doc:"Ed25519, ECDH P-256 or AES-256-GCM."`
	Fingerprint string `` /* 179-byte string literal not displayed */
	PublicKey   string `` /* 198-byte string literal not displayed */
	KeyID       string `` /* 194-byte string literal not displayed */
	Keys        int    `` /* 179-byte string literal not displayed */
	Admit       string `` /* 196-byte string literal not displayed */
}

Key is a key of osapi on this host as list and get show it. It never holds a secret: a public key shows its fingerprint, and a secret key its ID, the first 16 hex digits of its SHA-256.

func Create

func Create(
	ctx context.Context,
	d Deps,
	in CreateInput,
) (Key, error)

Create makes the key with the name. It refuses a key that is there: a new key in its place is a rotation, and only a vault key rotates.

func Get

func Get(
	_ context.Context,
	d Deps,
	in GetInput,
) (Key, error)

Get is one key in full. The agent's signing key has the command that admits this machine.

func Keys

func Keys(
	d Deps,
) []Key

Keys is each key of osapi on this host. A key that cannot be read is in the list too, with its state.

type ListInput

type ListInput struct{}

ListInput is the input of list, which has none.

type ListOutput

type ListOutput struct {
	Items []Key `json:"items"`
}

ListOutput is each key.

func List

func List(
	_ context.Context,
	d Deps,
	_ ListInput,
) (ListOutput, error)

List is each key of osapi on this host, with its state.

type RotateInput

type RotateInput struct {
	Name string `` /* 140-byte string literal not displayed */
}

RotateInput names the key to rotate.

type RotateOutput

type RotateOutput struct {
	Key    Key    `                json:"key"`
	Values int    `                json:"values,omitempty"`
	Next   string `` /* 145-byte string literal not displayed */
	// contains filtered or unexported fields
}

RotateOutput is the key after a rotation, and, for a vault, how many values the new key encrypted again.

func Rotate

func Rotate(
	ctx context.Context,
	d Deps,
	in RotateInput,
) (RotateOutput, error)

Rotate makes a new key in place of the one with the name. The agent's two keys go to the controller, which takes them in place of the admitted ones. A vault gets a new key, each value of the vault is encrypted again with it, and the old key is dropped. Any other key is refused, with what to do instead.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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