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
- Variables
- func CheckParentDir(d string) error
- func DirFor(cfg config.Config, env func(string) string) (string, error)
- func InstallFile(path string, data []byte) (created bool, err error)
- func ParseAccountSeed(path string) (nkeys.KeyPair, string, error)
- func ParseOperatorSeed(path string) (nkeys.KeyPair, string, error)
- func SetSyncDirHook(h func(string) error) (restore func())
- func SyncDir(path string) error
- type Authority
- func (a *Authority) Account() (nkeys.KeyPair, string, error)
- func (a *Authority) Dir() string
- func (a *Authority) ImportAccount(path string) (pub string, created bool, err error)
- func (a *Authority) ImportOperator(path string) (pub string, created bool, err error)
- func (a *Authority) InitAccount() (pub string, created bool, err error)
- func (a *Authority) InitOperator() (pub string, created bool, err error)
- func (a *Authority) InitSystem() (pub string, created bool, err error)
- func (a *Authority) InstallOperatorJWT(token string) (created bool, err error)
- func (a *Authority) Lock(wait time.Duration) (unlock func(), err error)
- func (a *Authority) Operator() (nkeys.KeyPair, string, error)
- func (a *Authority) OperatorJWT() (string, error)
- func (a *Authority) System() (nkeys.KeyPair, string, error)
- func (a *Authority) ZoneKey(zone string, create bool) (nkeys.KeyPair, error)
- func (a *Authority) ZonePublic(zone string) (string, error)
- func (a *Authority) Zones() ([]string, error)
Constants ¶
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 ¶
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`") )
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.
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.
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 ¶
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 ¶
DirFor is the key directory: $MASH_KEYS_DIR when absolute (a relative one is an error), else <cfg.Dir>/keys.
func InstallFile ¶
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 ¶
ParseAccountSeed is ParseOperatorSeed for an account identity seed (account prefix).
func ParseOperatorSeed ¶
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 ¶
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.
Types ¶
type Authority ¶
type Authority struct {
// contains filtered or unexported fields
}
Authority is the key store rooted at one directory.
func (*Authority) ImportAccount ¶
ImportAccount is ImportOperator for the account identity seed (account.nk).
func (*Authority) ImportOperator ¶
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 ¶
InitAccount creates the account signing key if absent. It never overwrites an existing seed.
func (*Authority) InitOperator ¶
InitOperator creates the operator key (operator.nk) if absent; used by `mashctl init --local`. It never overwrites.
func (*Authority) InitSystem ¶
InitSystem creates the system account's identity key (system.nk) if absent. It never overwrites.
func (*Authority) InstallOperatorJWT ¶
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 ¶
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) OperatorJWT ¶
OperatorJWT returns the operator JWT stored in the key directory, or "" when there is none.
func (*Authority) System ¶
System returns the system account's identity key pair and its public key.
func (*Authority) ZoneKey ¶
ZoneKey returns zone's scoped signing key; with create it generates and writes one if absent. It never overwrites.
func (*Authority) ZonePublic ¶
ZonePublic is the public key of an existing zone key.