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
- func Classify(msg string) string
- func LoadFailed(p paths.Paths) ([]string, error)
- func SaveFailed(p paths.Paths, refs []string) error
- type CheckReport
- type HostCheck
- type ManualStep
- type RotateReport
- type Rotator
- func (r *Rotator) Check(selector string) (CheckReport, error)
- func (r *Rotator) Results() []RunResult
- func (r *Rotator) Rollback(selector string) (RotateReport, error)
- func (r *Rotator) Rotate(selector string, allowUnverified bool, passphrase string) (RotateReport, error)
- func (r *Rotator) RotateEach(names []string, allowUnverified bool, pw string, out io.Writer, ...) ([]string, error)
- func (r *Rotator) Unattended(w io.Writer) *Rotator
- func (r *Rotator) Via(name string) string
- func (r *Rotator) WithManualStep(step ManualStep) *Rotator
- type RunResult
- type Summary
- func (s Summary) Counts() []SummaryCount
- func (s Summary) CountsUp() []SummaryCount
- func (s Summary) Failed() []string
- func (s Summary) Format() string
- func (s Summary) Needs() []SummaryNeed
- func (s Summary) Notes() []SummaryNote
- func (s Summary) Owners() int
- func (s Summary) Rerun() string
- func (s Summary) Root() string
- func (s Summary) Rows() []SummaryRow
- func (s Summary) Running() bool
- func (s Summary) Took() string
- func (s Summary) Totals() string
- func (s Summary) Untouched() string
- type SummaryCount
- type SummaryKey
- type SummaryNeed
- type SummaryNote
- type SummaryRow
- type TargetResult
Constants ¶
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.
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
Classify names why a step failed, from what it said, as a summary's Kind.
func LoadFailed ¶ added in v0.1.6
LoadFailed is the keys the last run left: what rotate --failed runs again.
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 ¶
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 (*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
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 ¶
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
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
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) Format ¶ added in v0.1.6
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) Rerun ¶ added in v0.1.6
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
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) Took ¶ added in v0.1.6
Took is how long the run took, to a tenth of a second; "" when unknown.
type SummaryCount ¶ added in v0.1.6
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
SummaryNeed is one thing left for you to do, and the keys it is for.
type SummaryNote ¶ added in v0.1.6
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.