rotator

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 19 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 rotator does zero-downtime, staged, single-old-archive key rotation. rotate stages a replacement, deploys it to every target (the current key stays active), verifies, and only then commits (archive current under /old/, promote staged, revoke old). On any pre-commit failure the staged key is discarded and the active key is untouched. rollback is the symmetric reverse move of the single /old/ key.

Index

Constants

View Source
const (
	KindLogsIn        = "logs-in"
	KindAPI           = "api"
	KindManual        = "manual"
	KindUnreachable   = "unreachable"
	KindNeverDeployed = "never-deployed"
	KindRemoved       = "removed"
	KindNoKey         = "no-key"
	KindFailed        = "failed"
)

What a dry run can find at a host, and why a key cannot rotate.

View Source
const (
	ResultRotated     = "rotated"
	ResultReplaced    = "replaced"
	ResultNotRotated  = "not rotated"
	ResultWouldRotate = "would rotate"
	ResultWouldPause  = "would pause"
	ResultWouldFail   = "would fail"
	// ResultWaiting is a key the run has not reached yet.
	ResultWaiting = "waiting"
	// KindReplaced is a key a forced rotation replaced on this computer.
	KindReplaced = "replaced"
	// KindNotRemoved is a key left trusted where it could not be removed.
	KindNotRemoved = "not-removed"
	// KindUnverified is a key put in place that no login has proved yet.
	KindUnverified = "unverified"
	// KindTrusted is a host whose keys were already pinned.
	KindTrusted = "trusted"
	// KindNoHostKeys is a host that answered with no keys to pin.
	KindNoHostKeys = "no-host-keys"
)

The result words a summary uses: a rotation's, and a dry run's.

Variables

This section is empty.

Functions

func Classify added in v0.1.6

func Classify(msg string) string

Classify names why a step failed, from what it said, as a summary's Kind.

func LoadFailed added in v0.1.6

func LoadFailed(p paths.Paths) ([]string, error)

LoadFailed is the keys the last run left: what rotate --failed runs again.

func SaveFailed added in v0.1.6

func SaveFailed(p paths.Paths, refs []string) error

SaveFailed keeps the keys a run left, one per line, for rotate --failed; an empty list clears it.

Types

type CheckReport added in v0.1.6

type CheckReport struct {
	Key   string
	Hosts []HostCheck
	// Problem is set when the key cannot be rotated at all (no key file);
	// ProblemKind names it.
	Problem, ProblemKind string
}

CheckReport is a dry run of one key's rotation.

func (CheckReport) Format added in v0.1.6

func (c CheckReport) Format() string

Format is the dry run as lines: the key, then each host with what was found.

func (CheckReport) OK added in v0.1.6

func (c CheckReport) OK() bool

OK reports whether the rotation would go through without a failure.

type HostCheck added in v0.1.6

type HostCheck struct {
	Alias, Provider string
	// Manual is a target that takes the new key by hand: the rotation stops
	// there and asks you to paste it.
	Manual bool
	// OK is false when the rotation would fail here; Message says why.
	OK      bool
	Message string
	// Kind names what was found, for a summary: KindLogsIn, KindAPI,
	// KindManual, KindUnreachable, KindNeverDeployed or KindRemoved.
	Kind string
	// Via is how the new key would reach the host: ssh, a provider's API, or
	// a provider that takes it by hand.
	Via string
}

HostCheck is what a dry run found for one host a key is deployed to.

type ManualStep

type ManualStep func(alias, where, pubkey string) bool

ManualStep is asked, for each target whose provider can only take a pasted key (a web panel such as Ploi), to show the staged public key and where it goes, and to report whether it is now in place. The CLI sets one only when there is a terminal to ask at; without one, rotate behaves as it always has.

type RotateReport

type RotateReport struct {
	KeyName        string
	OldFingerprint string
	NewFingerprint string
	Committed      bool
	Message        string
	Targets        []TargetResult
	// Fallback names the software type minted when the hardware *-sk type had
	// no security key to answer; "" otherwise.
	Fallback string `json:",omitempty"`
}

RotateReport summarizes a rotate/rollback run.

func (RotateReport) Format

func (r RotateReport) Format() string

Format renders the rotation summary (mirrors RotateReport.format).

type Rotator

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

Rotator rotates keys.

func New

New builds a Rotator.

func (*Rotator) Check added in v0.1.6

func (r *Rotator) Check(selector string) (CheckReport, error)

Check is a dry run of Rotate: it changes nothing, and tells for each host the key is used on whether the rotation would get through - the server answers and the current key still logs in, or the target takes the new key by hand - so a long rotation can be tested before it starts.

func (*Rotator) Results added in v0.1.6

func (r *Rotator) Results() []RunResult

Results is what the last RotateEach did with each key, for its summary.

func (*Rotator) Rollback

func (r *Rotator) Rollback(selector string) (RotateReport, error)

Rollback restores the single /old/ predecessor (plain reverse move), re-deploys it, and revokes the rotated-in key. Mirrors Rotator.rollback.

func (*Rotator) Rotate

func (r *Rotator) Rotate(selector string, allowUnverified bool, passphrase string) (RotateReport, error)

Rotate stages a fresh key, deploys+verifies it on every target, and commits only if all verified (or allowUnverified and all deployed). Mirrors Rotator.rotate.

func (*Rotator) RotateEach

func (r *Rotator) RotateEach(names []string, allowUnverified bool, pw string, out io.Writer,
	save, next func() error) ([]string, error)

RotateEach rotates the keys named, one after another, as `authama ssh rotate` does for a selection: a key that fails is reported and left as it was, and the rest go on. save runs after every committed key, so an interrupted batch keeps what it finished. next, when set, runs before each key, and an error from it stops the batch there: a web job's cancel. It returns the keys not rotated.

func (*Rotator) Unattended

func (r *Rotator) Unattended(w io.Writer) *Rotator

Unattended makes the rotation's deploys run with nobody to answer a prompt, writing their ssh output to w. The web UI rotates this way.

func (*Rotator) Via added in v0.1.6

func (r *Rotator) Via(name string) string

Via is how the key named reaches its hosts, for a summary of one key.

func (*Rotator) WithManualStep

func (r *Rotator) WithManualStep(step ManualStep) *Rotator

WithManualStep sets the manual step and returns the Rotator.

type RunResult added in v0.1.6

type RunResult struct {
	Ref    string
	Report *RotateReport
	Err    error
	Via    string
}

RunResult is one key's outcome in a batch rotation.

type Summary added in v0.1.6

type Summary struct {
	Check   bool
	Keys    []SummaryKey
	Elapsed time.Duration
	// Command is the command line the run was, as its first line shows it:
	// "authama ssh rotate --all".
	Command string
	// Verb is the tree's root, the command's own name: rotate (the default),
	// revoke, delete. RerunCommand and UntouchedText replace the rotation's
	// own re-run command and closing note, for another command's summary.
	Verb, RerunCommand, UntouchedText string
}

Summary is the outcome of a rotation, or of its dry run, for every key it covered: what each key's result was, grouped by owner and project, with each explanation printed once as a numbered note, what is left for you to do, and the command that runs the failed keys again.

func SummarizeCheck added in v0.1.6

func SummarizeCheck(reports []CheckReport, elapsed time.Duration) Summary

SummarizeCheck is a dry run's summary: each key's worst host decides its result.

func SummarizeRun added in v0.1.6

func SummarizeRun(results []RunResult, replaced []string, elapsed time.Duration) Summary

SummarizeRun is a rotation's summary. replaced names the keys a forced rotation then replaced on this computer.

func (Summary) Counts added in v0.1.6

func (s Summary) Counts() []SummaryCount

Counts are the counts of each result, worst first.

func (Summary) CountsUp added in v0.1.6

func (s Summary) CountsUp() []SummaryCount

CountsUp are the counts of each result, best first, as the Output card's badges show them.

func (Summary) Failed added in v0.1.6

func (s Summary) Failed() []string

Failed is the keys that did not go through.

func (Summary) Format added in v0.1.6

func (s Summary) Format() string

Format is the summary as aligned plain text, as `authama ssh rotate` prints it at the end of a run: the command, the result, the tree with its columns, the notes, what is left for you, and the counts with the command that runs the failed keys again.

func (Summary) Needs added in v0.1.6

func (s Summary) Needs() []SummaryNeed

Needs is what is left for you to do, worst first, each with the keys it is for, grouped as the tree groups them.

func (Summary) Notes added in v0.1.6

func (s Summary) Notes() []SummaryNote

Notes are the explanations, each once, numbered in the order the run met them.

func (Summary) Owners added in v0.1.6

func (s Summary) Owners() int

Owners is how many profiles the summary covers.

func (Summary) Rerun added in v0.1.6

func (s Summary) Rerun() string

Rerun is the command that runs the failed keys again, or "": rotate --failed reads the keys the last run left.

func (Summary) Root added in v0.1.6

func (s Summary) Root() string

Root is the tree's first line: the command's own name, rotate unless Verb says otherwise.

func (Summary) Rows added in v0.1.6

func (s Summary) Rows() []SummaryRow

Rows is the summary's tree, line by line, under one continuous trunk: the root, each owner, its project groups and its keys.

func (Summary) Running added in v0.1.6

func (s Summary) Running() bool

Running reports whether a key is not finished yet.

func (Summary) Took added in v0.1.6

func (s Summary) Took() string

Took is how long the run took, to a tenth of a second; "" when unknown.

func (Summary) Totals added in v0.1.6

func (s Summary) Totals() string

Totals are the counts of each result, worst first: "3 would fail · 3 would pause · 3 would rotate".

func (Summary) Untouched added in v0.1.6

func (s Summary) Untouched() string

Untouched says what became of the keys that did not go through.

type SummaryCount added in v0.1.6

type SummaryCount struct {
	Word     string
	N        int
	Severity int
}

SummaryCount is how many keys had one result.

type SummaryKey added in v0.1.6

type SummaryKey struct {
	// Ref is profile/key.
	Ref string
	// Result is one of the Result words; Severity orders them, worst first:
	// 2 failed, 1 needs you, 0 went through.
	Result   string
	Severity int
	// Via is how the new key reaches its hosts (ssh, github api, ploi).
	Via string
	// Kind names why, as HostCheck.Kind does; Note is the long explanation,
	// printed once under Notes however many keys share it.
	Kind, Note string
	// Key is what the KEY column shows, when not the key's own name: the key
	// a host row is for, a host's address, a fingerprint.
	Key string
	// Pending is a key the run has not finished yet: Result is ResultWaiting,
	// or what the run is doing to it now (testing, rotating, revoking).
	Pending bool
}

SummaryKey is one key's line in a summary.

func Pending added in v0.1.6

func Pending(names []string, now string) []SummaryKey

Pending is the keys a run has yet to finish, for a summary drawn while it runs: the first is under way (Result is now, "testing" say), the rest wait.

type SummaryNeed added in v0.1.6

type SummaryNeed struct {
	Mark, Action string
	Severity     int
	Note         int
	Keys         string
}

SummaryNeed is one thing left for you to do, and the keys it is for.

type SummaryNote added in v0.1.6

type SummaryNote struct {
	N        int
	Text     string
	Severity int
}

SummaryNote is one explanation, numbered, with the severity of the worst key it explains.

type SummaryRow added in v0.1.6

type SummaryRow struct {
	// Branch is the tree drawn before the label (├─, │, └─). Root is the
	// tree's first line, the command's own name.
	Branch, Label string
	Root          bool
	// Env is a project group's environment, drawn after its name: simbi · prd.
	Env    string
	Group  bool
	Counts string
	// Mark is ✓, ! or × for a key.
	Mark, Key, Via, Result, Reason string
	Severity                       int
	// Note numbers the key's explanation under Notes; 0 for none.
	Note int
	// Pending is a key not finished yet: waiting, or under way.
	Pending bool
	// Gap puts a line before the row that holds only the trunk (Trunk):
	// between owners.
	Gap   bool
	Trunk string
}

SummaryRow is one line of a summary's tree: an owner or a project group (Group, with its Counts), or a key.

type TargetResult

type TargetResult struct {
	Alias    string
	Provider string
	Deployed bool
	Verified bool
	Revoked  bool
	// ManageURL is where a manual (web-panel) target's keys are managed; set when the deploy was a
	// paste, so a committed report can say where the old key still has to be removed by hand.
	ManageURL string
}

TargetResult is one target's rotation outcome.

Jump to

Keyboard shortcuts

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