ctlkeys

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 17 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 ctlkeys is the key store of mashctl: the account signing seed and the per-zone scoped signing seeds, kept as 0600 files in a 0700 directory (ADR 0052). Seed text is never put in an error or a log line.

Index

Constants

View Source
const OperatorJWTFile = "operator.jwt"

OperatorJWTFile is the name, in the key directory, of the copy of the operator JWT that tells mashctl which keys the operator accepts as issuers of an account JWT.

Variables

View Source
var (
	// ErrNoZoneKey is wrapped by ZoneKey when the zone has no key file and create is false.
	ErrNoZoneKey = errors.New("mashctl: no signing key for zone")
	// ErrNoOperatorKey is returned by Operator when operator.nk is absent.
	ErrNoOperatorKey = errors.New("mashctl: no operator key (operator.nk): it exists only for a server `mashctl init --local` stood up")
	// ErrNoSystemKey is returned by System when system.nk is absent.
	ErrNoSystemKey = errors.New("mashctl: no system account key (system.nk): it exists only for a server `mashctl init --local` stood up")
	// ErrNoAccountKey is returned by Account when account.nk is absent.
	ErrNoAccountKey = errors.New("mashctl: no account signing key: run `mashctl init`")
)
View Source
var ErrDifferentKey = errors.New("mashctl: the key store already holds a different key")

ErrDifferentKey is wrapped by ImportOperator and ImportAccount when the store already holds another key.

View Source
var ErrDifferentOperatorJWT = errors.New("mashctl: the key directory already holds a different operator.jwt")

ErrDifferentOperatorJWT is wrapped by InstallOperatorJWT when the key directory already holds another operator JWT.

View Source
var ErrLocked = errors.New("another mashctl policy apply holds the key directory lock")

ErrLocked is the error of Lock when another holder keeps the lock past the wait.

Functions

func CheckParentDir

func CheckParentDir(d string) error

CheckParentDir refuses a directory that is not a real directory (a symlink is refused), is not owned by the effective uid, or is writable by other users (group-writable is allowed: under the usual user-private-group umask 002 a config directory is 0775 and the group is the owner alone): a place where a creds file may be created without another user being able to swap or replace it. A missing directory is an error wrapping fs.ErrNotExist.

func DirFor

func DirFor(cfg config.Config, env func(string) string) (string, error)

DirFor is the key directory: $MASH_KEYS_DIR when absolute (a relative one is an error), else <cfg.Dir>/keys.

func InstallFile

func InstallFile(path string, data []byte) (created bool, err error)

InstallFile writes data to path with the custody rules of the key files: a 0600 temp file in the same directory (O_EXCL), fsync, a hard link that cannot replace an existing file, a sync of the directory. An existing path is left untouched and reported with created false; the caller compares its content. The directory must exist.

func ParseAccountSeed

func ParseAccountSeed(path string) (nkeys.KeyPair, string, error)

ParseAccountSeed is ParseOperatorSeed for an account identity seed (account prefix).

func ParseOperatorSeed

func ParseOperatorSeed(path string) (nkeys.KeyPair, string, error)

ParseOperatorSeed reads the operator seed file at path (0600, a regular file, an operator-prefix seed) and returns the key pair and its public key. The seed is never put in an error.

func SetSyncDirHook

func SetSyncDirHook(h func(string) error) (restore func())

SetSyncDirHook replaces the directory sync that InstallFile and SyncDir use and returns the function that restores it. It exists so tests in other packages can inject a failure.

func SyncDir

func SyncDir(path string) error

SyncDir fsyncs the directory at path so a new or renamed entry in it survives power loss.

Types

type Authority

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

Authority is the key store rooted at one directory.

func Open

func Open(dir string) (*Authority, error)

Open opens the key store at dir. It creates nothing; a missing dir is an empty store.

func (*Authority) Account

func (a *Authority) Account() (nkeys.KeyPair, string, error)

Account returns the account signing key pair and its public key.

func (*Authority) Dir

func (a *Authority) Dir() string

Dir is the key directory.

func (*Authority) ImportAccount

func (a *Authority) ImportAccount(path string) (pub string, created bool, err error)

ImportAccount is ImportOperator for the account identity seed (account.nk).

func (*Authority) ImportOperator

func (a *Authority) ImportOperator(path string) (pub string, created bool, err error)

ImportOperator copies the operator seed file at path into the store as operator.nk (0600, no clobber, fsync). The same key already stored is not an error (created is false); a different one is ErrDifferentKey and nothing changes.

func (*Authority) InitAccount

func (a *Authority) InitAccount() (pub string, created bool, err error)

InitAccount creates the account signing key if absent. It never overwrites an existing seed.

func (*Authority) InitOperator

func (a *Authority) InitOperator() (pub string, created bool, err error)

InitOperator creates the operator key (operator.nk) if absent; used by `mashctl init --local`. It never overwrites.

func (*Authority) InitSystem

func (a *Authority) InitSystem() (pub string, created bool, err error)

InitSystem creates the system account's identity key (system.nk) if absent. It never overwrites.

func (*Authority) InstallOperatorJWT

func (a *Authority) InstallOperatorJWT(token string) (created bool, err error)

InstallOperatorJWT stores token as <keydir>/operator.jwt (0600, never replacing a file). With a file already in place, created is false and the error says so when its content differs. The token is not validated here.

func (*Authority) Lock

func (a *Authority) Lock(wait time.Duration) (unlock func(), err error)

Lock takes an exclusive advisory lock on <keydir>/apply.lock (0600), waiting up to wait for another holder, and returns the function that releases it. The lock covers appliers that share this key directory; it does nothing for copies of the keys on other hosts, and on platforms without flock it is a no-op.

func (*Authority) Operator

func (a *Authority) Operator() (nkeys.KeyPair, string, error)

Operator returns the operator key pair and its public key.

func (*Authority) OperatorJWT

func (a *Authority) OperatorJWT() (string, error)

OperatorJWT returns the operator JWT stored in the key directory, or "" when there is none.

func (*Authority) System

func (a *Authority) System() (nkeys.KeyPair, string, error)

System returns the system account's identity key pair and its public key.

func (*Authority) ZoneKey

func (a *Authority) ZoneKey(zone string, create bool) (nkeys.KeyPair, error)

ZoneKey returns zone's scoped signing key; with create it generates and writes one if absent. It never overwrites.

func (*Authority) ZonePublic

func (a *Authority) ZonePublic(zone string) (string, error)

ZonePublic is the public key of an existing zone key.

func (*Authority) Zones

func (a *Authority) Zones() ([]string, error)

Zones lists the zones that have a key file, sorted.

Jump to

Keyboard shortcuts

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