Documentation
¶
Overview ¶
Package change previews a change before it is made, and makes it only if what it would do has not moved since it was previewed.
A preview runs the change for real, against a private copy of the home: the config files, and from ~/.ssh only the files a snapshot may hold (config, known_hosts, public keys). It then diffs what the copy became against what is there now, so the preview is not a description of the change but the change itself, made somewhere harmless. No private key is ever copied.
Apply takes the lock, previews again under it, and runs the change on the real home only if the new preview hashes the same as the one the person confirmed. Anything that moved in between - a CLI command, another browser tab - is reported with the new preview instead of being overwritten. The lock is held only for that, never while a person reads.
Index ¶
- Variables
- func Apply(p paths.Paths, ch Change, hash string, retain int, source string) (Plan, Result, error)
- func ApplyManifestEdit(out io.Writer, p paths.Paths) error
- func BackupKeyFile(p paths.Paths) string
- func CheckAdopt(p paths.Paths, key, profile, alias, hv, user string) error
- func ReservationFor(forWhat, note, fingerprint string, now time.Time) manifest.ReservedKey
- func ResolveReserve(p paths.Paths, arg string) (name, fingerprint string, err error)
- func WarnDangling(out io.Writer, p paths.Paths, m *manifest.Manifest)
- type Change
- func AuditNotify() Change
- func BackupKey() Change
- func Bundle(keep int) Change
- func Clean(adopt bool) Change
- func ConfigRender() Change
- func DoctorFix() Change
- func ExportSelectionDelete(name string) Change
- func ExportSelectionSave(name string, sel selection.Selection) Change
- func FactoryReset(confirmed bool) Change
- func HistoryReset(confirmed bool) Change
- func HomeInit(confirmed bool) Change
- func HostAdd(profile, alias string, in HostInput) Change
- func HostApply(profile string, specs []editor.HostSpec, create bool, category string) Change
- func HostDelete(profile, alias string) Change
- func HostEdit(profile, alias string, in HostInput) Change
- func KeyAdd(profile, name, keyType, host string) Change
- func KeyDelete(ref manifest.KeyRef) Change
- func KeyLifetime(ref manifest.KeyRef, days int) Change
- func KeyRegenPub(real paths.Paths, sel keysvc.Selection) Change
- func KeyReserve(name, forWhat, note string) Change
- func KeyRoot(target, confirm string) Change
- func KeyUnreserve(name string) Change
- func Keygen(target string) Change
- func NamingKeyTemplate(profile, tpl string) Change
- func NamingSet(profile string, f NamingFields) Change
- func NotifyTest() Change
- func OwnerFingerprint(on bool) Change
- func OwnerForget(confirmed bool) Change
- func OwnerInit() Change
- func OwnerPINRemove(current string) Change
- func OwnerPINSet(current, next, confirm string) Change
- func OwnerReseal() Change
- func ProfileAdd(name, keyScope, keyName, keyComment string) Change
- func ProfileAddIn(name, keyScope, keyName, keyComment, category string) Change
- func ProfileCategory(name, category string) Change
- func ProfileCode(name, code string) Change
- func ProfileDelete(name string) Change
- func ProfileEdit(name string, keyScope, keyName *string) Change
- func ProfileKeyComment(name, comment string) Change
- func ProfilePurge(name string) Change
- func ProvidersExport() Change
- func Reconcile() Change
- func Repair(home func(paths.Paths) repair.Home) Change
- func SSHImport(real paths.Paths, source string, replace bool) Change
- func SettingsInit(force bool) Change
- func SettingsSet(key, value string) Change
- func SettingsUnset(key string) Change
- func SnapshotRestore(snapshotsDir, id string, retain int) Change
- func SnapshotsPrune(keep int) Change
- func TokenApply() Change
- func TokenConfigEdit(text string) Change
- func TokenDelete(target, host string) Change
- func TokenImport() Change
- func TokenInit(targets []string) Change
- func TokenSet(spec tokensvc.SetSpec, mode string, secret func() (string, error)) Change
- func VMAdd(profile, alias, hypervisor, vmName, user string) Change
- func VMAdoptKey(key, profile, alias, hv, vmName, user string) Change
- func VMDockerContext(alias string) Change
- func VMSchedule(install bool) Change
- func VMSync(repin bool) Change
- type FileDiff
- type HostInput
- type NamingFields
- type Plan
- type Result
Constants ¶
This section is empty.
Variables ¶
var ErrImportWouldReplace = errors.New("a non-empty manifest already exists - importing replaces it " +
"rather than merging; re-run with --force, which backs the current " +
"manifest and inventory up to <home>/.state/ first")
ErrImportWouldReplace is import refusing to replace a manifest that has profiles, which the CLI allows only with --force.
var ErrStale = fmt.Errorf("the change would now do something different from what you confirmed: %w", mutation.ErrDeclined)
ErrStale reports a confirmation made against a preview that no longer matches what the change would do.
var NewSyncer = func(p paths.Paths, cfg settings.VMConfig, opt vmsync.Options) *vmsync.Syncer { return vmsync.New(p, cfg, opt) }
NewSyncer builds the syncer the VM changes use; tests swap it.
Functions ¶
func Apply ¶
Apply makes ch on p if a fresh preview under the lock still hashes to hash. On ErrStale it returns that fresh preview, for the person to confirm again.
func ApplyManifestEdit ¶
ApplyManifestEdit re-renders ~/.ssh/config after a command changed the manifest, and reports what moved.
The rendered config is a pure function of the manifest, so every manifest edit makes the file on disk stale - which is exactly the drift `doctor` and `diff` exist to report. Leaving that to a later reconcile meant a successful edit ended with the tool complaining about a problem it had just created, and the user being told to run a second command to finish the first. So the rule is: a command that changes the manifest renders; a command that only touches key files (keygen, rotate) changes no manifest state and does not.
This is safe to run after any edit. Rendering replaces the managed block and preserves everything around it (renderer.ComposeRootConfig), so it never disturbs hand-written config, and it is idempotent - an edit that changes no Host block writes nothing and says nothing.
func BackupKeyFile ¶ added in v0.1.6
BackupKeyFile is where `settings backup-key` keeps the age identity it makes, owner-only: where paths.age_identity_file (AUTHAMA_AGE_IDENTITY_FILE) already points, when it does, so a restore finds the key it expects; otherwise in the config home.
func CheckAdopt ¶ added in v0.1.3
CheckAdopt validates an adoption against the home as it is now: a loose pair in ~/.ssh, a hypervisor authama knows that does not manage its own keys, a guest user it will embed, a per_service profile, a new alias.
func ReservationFor ¶ added in v0.1.6
func ReservationFor(forWhat, note, fingerprint string, now time.Time) manifest.ReservedKey
ReservationFor builds the reservation `key reserve` records.
func ResolveReserve ¶ added in v0.1.6
ResolveReserve turns `key reserve`'s argument - a bare name, ~/.ssh/<name>, an absolute path, or any of them with .pub - into the file name directly in ~/.ssh, and checks it is a loose keypair authama does not manage. It reads only the public half (for the fingerprint).
func WarnDangling ¶
WarnDangling reports the blocking dangling-key states inline, right after the command that could have caused one.
Only the blocking ones, and only after the command's own output: a key nothing will ever use is worth interrupting for, while an unminted key or a stale record is doctor's business. Failing to audit is silent - this is a courtesy on the end of a command that already succeeded, not a check in its own right.
Types ¶
type Change ¶
type Change struct {
Command string // "host add"
Args []string
Subjects []history.Subject
Run func(p paths.Paths, out io.Writer) error
// Mints marks a change that makes a new key. Its preview mints a
// throwaway key in the copy, which apply cannot reproduce, so public key
// blobs and fingerprints are left out of the hash: the confirmation
// binds to everything else the change writes, and to which keys it makes.
Mints bool
// NoSnapshot skips the ~/.ssh snapshot before the change, for one that
// manages the snapshots themselves and would otherwise prune its own.
NoSnapshot bool
// Effects lists what the change does outside the files a preview copies
// - snapshots it removes, modes it fixes - as lines for the preview to
// show. They are part of the hash, so they cannot change unseen either.
Effects func(p paths.Paths) ([]string, error)
// OnApply is the part of a change that a copy cannot hold - a Docker
// context, a desktop notification, an encrypted backup of private keys.
// It runs on apply only, under the lock, after the snapshot and before
// Run. A preview never runs it, so a change with OnApply must say what it
// does in Effects; Preview refuses one that does not.
OnApply func(p paths.Paths, out io.Writer) error
}
Change is one change a person can ask for. Run makes it against p, the way the CLI command does after its guard; it never takes the lock or snapshots, which Apply does around it.
func AuditNotify ¶
func AuditNotify() Change
AuditNotify is the --notify half of `authama ssh audit --notify`: the desktop alert for keys that need attention, if one is due. It is gated by the same daily or weekly cadence, so asking twice in a day sends one.
func BackupKey ¶ added in v0.1.6
func BackupKey() Change
BackupKey is `authama settings backup-key`: makes an age key for encrypted backups with age-keygen, keeps its identity owner-only in the config home, and sets backup.age_recipient and paths.age_identity_file to it. The key is made only on apply, never in a preview, so no page ever shows it.
func Bundle ¶
Bundle is `authama ssh bundle [--keep N]`: an age-encrypted backup of ~/.ssh and the config, written to the state home's dist/. It takes no snapshot, as the CLI's does not: it changes nothing a snapshot would hold.
func Clean ¶
Clean is `authama ssh clean --yes [--adopt]`: stale pins, stale inventory records and write residue. The residue is swept by the snapshot apply takes first, as the CLI's is.
func ConfigRender ¶
func ConfigRender() Change
ConfigRender is `authama ssh config render --yes`: migrate any legacy per-profile known_hosts into the single store, then write the config.
func DoctorFix ¶
func DoctorFix() Change
DoctorFix is the --fix half of `authama doctor --fix`: set every config-home and ~/.ssh path back to its canonical mode.
func ExportSelectionDelete ¶ added in v0.1.6
ExportSelectionDelete is `authama export selections delete <name> --from manifest`.
func ExportSelectionSave ¶ added in v0.1.6
ExportSelectionSave is `authama export selections save <name> --to manifest`: keep sel in the manifest's defaults.export.selections, so it travels with the manifest. This account's own store is not a change: the web saves there directly, as the CLI does.
func FactoryReset ¶ added in v0.1.6
FactoryReset is `authama reset --confirm reset`. confirmed is the word the form asks to be typed.
func HistoryReset ¶ added in v0.1.6
HistoryReset is `authama history reset --confirm history`: the history database and the audit log are moved aside, kept, and the next change starts a new history. confirmed is the word the form asks to be typed. It refuses while history.permanent is on.
func HomeInit ¶ added in v0.1.6
HomeInit is `authama init --force --backup`: the manifest, inventory and .env are written again with fresh defaults, after copying the old ones into the state home's .state/init-backup-<time>/. Profiles, hosts and token declarations go with the old manifest, so the form asks for the word "init" to be typed. ~/.ssh is not touched: keys and their files stay.
func HostAdd ¶
HostAdd is `authama ssh host add <profile> <alias> -H <hostname> -u <user> [-p] [--tag]...`.
func HostApply ¶
HostApply is `authama ssh host apply <profile> --host <spec>... --yes`, with --create-profile or --category for a profile that does not exist yet. Each spec is `<alias> <host>[:port] <user> [role]`.
func HostDelete ¶
HostDelete is `authama ssh host delete <profile> <alias> --yes`: the host, its block and its pins go; its key files stay.
func KeyAdd ¶
KeyAdd is `authama ssh key add <profile> <name> [--type] [--host]`: declare the key, mint it, and wire it to a host when one is named.
func KeyDelete ¶
KeyDelete is `authama ssh key delete <profile/key> --yes`: the declaration and the record go; the files stay.
func KeyLifetime ¶ added in v0.1.6
KeyLifetime is `authama ssh key lifetime <profile/key> <days> --yes`, or `--clear` for days 0: the key's lifetime and its expiry counted again.
func KeyRegenPub ¶ added in v0.1.6
KeyRegenPub is `authama ssh key regen-pub <selection> --yes`: each selected key's .pub rebuilt from the key it belongs to.
A preview's copy holds no private key, only an empty stand-in at its path, so a .pub derived there would be derived from nothing. Each private key is therefore read where it really is, under real, whichever home the change writes: deriving the public half reads the private key and copies nothing of it, which is what `ssh-keygen -y` does for the CLI. The preview and the apply then derive the same public keys, and the confirmation binds to them.
func KeyReserve ¶ added in v0.1.6
KeyReserve is `authama ssh key reserve <name> [--for X] [--note Y] --yes`: keep a loose ~/.ssh key on purpose. Only the manifest changes.
func KeyRoot ¶ added in v0.1.6
KeyRoot is `authama ssh key root <dir> --yes`: ~/.ssh/<dir>/ made the key root, and the whole tree of profile directories moved there in one rename.
It moves every key on disk, so it is made only when confirm repeats the new name exactly. A preview's copy holds a stand-in for each private key, so the preview lists every key it would move without holding one.
func KeyUnreserve ¶ added in v0.1.6
KeyUnreserve is `authama ssh key unreserve <name> --yes`: the key is loose again (doctor lists it); the file is not touched.
func Keygen ¶
Keygen is `authama ssh keygen <profile|alias> --no-pin --yes`, without --force: it mints the target's missing keys and leaves every existing one alone.
func NamingKeyTemplate ¶ added in v0.1.6
NamingKeyTemplate is `authama ssh naming key-template <tpl> [--profile <p>] --yes`: how new keys are named. Every existing host keeps its key name.
func NamingSet ¶ added in v0.1.6
func NamingSet(profile string, f NamingFields) Change
NamingSet is `authama ssh naming set [--profile <p>] <flags>`: the manifest's naming rules, or one profile's own. Every existing host keeps its key name.
func NotifyTest ¶
func NotifyTest() Change
NotifyTest is `authama ssh notify test`: one test desktop notification.
func OwnerFingerprint ¶ added in v0.1.6
OwnerFingerprint is `authama owner fingerprint on|off`.
func OwnerForget ¶ added in v0.1.6
OwnerForget is `authama owner forget --yes`. confirmed is the word the form asks to be typed, so the binding is not dropped by a stray click.
func OwnerPINRemove ¶ added in v0.1.6
OwnerPINRemove is `authama owner pin remove`.
func OwnerPINSet ¶ added in v0.1.6
OwnerPINSet is `authama owner pin set`: a new PIN, or a changed one when current is the PIN set now. It refuses a PIN that could not be reset if forgotten, and a PIN the policy refuses, at preview.
func OwnerReseal ¶ added in v0.1.6
func OwnerReseal() Change
OwnerReseal is `authama owner reseal --yes`: accept the files as they are.
func ProfileAdd ¶
ProfileAdd is `authama ssh profile add <name> [--key-scope] [--key-name] [--key-comment]`.
func ProfileAddIn ¶ added in v0.1.6
ProfileAddIn is ProfileAdd with --category: the profile is filed under profiles/<category>/ from the start. An empty category is ProfileAdd.
func ProfileCategory ¶
ProfileCategory is `authama ssh profile edit <name> --category <category>`: it moves the profile's key directory, private keys and all, and the inventory records follow. "" returns it to the flat layout.
func ProfileCode ¶ added in v0.1.6
ProfileCode is `authama ssh profile edit <name> --code <code>`: the code a profile's servers are named by ("" clears it). Every existing host keeps its key name; the config is rendered again, as the command does.
func ProfileDelete ¶
ProfileDelete is `authama ssh profile delete <name> --yes`: the manifest, the inventory records, the rendered blocks and the pins go; key files stay.
func ProfileEdit ¶
ProfileEdit is `authama ssh profile edit <name> [--key-scope] [--key-name]`. A nil field is left as it is.
func ProfileKeyComment ¶ added in v0.1.6
ProfileKeyComment is `authama ssh profile edit <name> --key-comment <template>`: the comment template for keys the profile mints from now on. An empty template inherits defaults.key_comment.
func ProfilePurge ¶
ProfilePurge is `authama ssh profile delete <name> --purge --yes`: everything ProfileDelete removes, and the profile's key files too. It never runs without the encrypted backup the CLI writes first; the web has no --no-key-backup.
func ProvidersExport ¶
func ProvidersExport() Change
ProvidersExport is `authama ssh providers --export`, without --force: write the shipped provider catalog into the home to customize, unless one is there.
func Reconcile ¶
func Reconcile() Change
Reconcile is `authama ssh reconcile --yes --no-pin`: mint every missing key, record keys already on disk, render the config, fix modes.
func Repair ¶ added in v0.1.6
Repair is `authama repair --yes`: every fix repair.Home.Check finds. The fixes reach the OS key store, file modes and a database, which a preview copy does not hold, so they run in OnApply; Effects lists them, and the confirmation is bound to that list.
func SSHImport ¶ added in v0.1.6
SSHImport is `authama ssh import <source> [--force] --yes`: the ssh config at source read into a new manifest and inventory, replacing them.
source is a path the caller chose, never one a person typed. Keys it names outside the managed tree are copied in; a preview's copy gets an empty file at each such path instead (importer.InPlaceOf), so no private key is copied to show it, and the preview still lists every key it would create.
func SettingsInit ¶ added in v0.1.6
SettingsInit is `authama settings init`: write a starter authama.json (the schema reference and version, every setting at its default) into the config home. Without force it refuses a file that is already there; with force the file already there is kept beside the new one, as authama.json.before-reset-<time>, so resetting the settings to their defaults loses nothing. It touches nothing in ~/.ssh, so it takes no snapshot, as the command takes none.
func SettingsSet ¶ added in v0.1.6
SettingsSet is `authama settings set <key> <value>`: one setting written into authama.json, every other kept. On apply the running process takes the new value at once, so a page that needed it (a job's backup check) passes without a restart; a variable already set in the environment still wins, as it does at start-up.
func SettingsUnset ¶ added in v0.1.6
SettingsUnset is `authama settings unset <key>`: the setting is taken out of authama.json and goes back to its default; this server follows at once, unless the environment sets it some other way.
func SnapshotRestore ¶
SnapshotRestore is `authama ssh snapshots restore <id> --yes`: put back the config, known_hosts and public keys a snapshot holds, after snapshotting ~/.ssh as it is now. snapshotsDir is the real home's: a preview restores from it into the copy, where it has no snapshot of its own to take, and apply restores into the home through the same function the CLI uses.
A snapshot written before private keys were left out is refused, as the snapshot page refuses to open one: restoring it would put plaintext private keys back on disk from an archive nobody can see into here.
func SnapshotsPrune ¶
SnapshotsPrune is `authama ssh snapshots prune --keep <n>`. It takes no snapshot of its own first, which would push one more out.
func TokenApply ¶
func TokenApply() Change
TokenApply is `authama token apply` with no terminal to ask: the token config is resolved from the server's environment and every tool's file is merged. A registry docker keeps in a credential store is handled as the config's _settings.docker_creds_store says, and refused when it says nothing.
func TokenConfigEdit ¶ added in v0.1.6
TokenConfigEdit replaces the config home's tokens.json with text, the web UI's editor: the text must parse and hold variable names only (tokens.CheckNamesOnly), so the editor can never be the way a secret lands in a file that is meant to be committed. The preview shows the file's diff. The CLI's equivalent is editing the file and running `token status`.
func TokenDelete ¶
TokenDelete is `authama token delete <target> <host>`.
func TokenImport ¶ added in v0.1.6
func TokenImport() Change
TokenImport is `authama token import` with no FILE: copy auth-token-manager's config, found where that tool looked, to the config home's tokens.json. The old file is left in place.
func TokenInit ¶ added in v0.1.6
TokenInit is `authama token init [--target …]` with no FILE: a starter token config at the config home's tokens.json, never over one that is there. It names environment variables, never secrets.
func TokenSet ¶ added in v0.1.6
TokenSet is `authama token set`: add one credential to its tool's file, or replace the one already there for that host. The secret is not part of the change - Effects and the command line never hold it - and comes from secret only when the change is made. mode settles a registry Docker keeps in a credential store as --creds-store-mode does; empty reads $AUTHAMA_DOCKER_CREDS_STORE, and refuses when that is unset too, since a page cannot ask.
func VMAdoptKey ¶ added in v0.1.3
VMAdoptKey is `authama ssh vm adopt-key <key> <profile> <alias> --hypervisor <hv> --vm <vm> --user <user> --yes`: add the VM host and copy the loose ~/.ssh/<key> pair into the profile under the key's own name. The copy holds the private key only as a placeholder, which the preview copies in its place; the original is never removed from the web.
func VMDockerContext ¶
VMDockerContext is `authama ssh vm docker-context <alias>`: create, or update, the Docker context ssh://<alias> for a VM host.
func VMSchedule ¶ added in v0.1.3
VMSchedule is `authama ssh vm sync --install-schedule --yes` (install) or `--remove-schedule --yes`: the daily `vm sync --quiet --yes` job.
func VMSync ¶ added in v0.1.3
VMSync is `authama ssh vm sync --yes [--repin]`.
The manifest half - removing the hosts of gone VMs, adding declared devboxes - runs in Run, against the copy, so the preview shows the exact manifest and config diff. The half outside the home - pins, the guest's authorized_keys, Docker contexts - is listed in Effects and made in OnApply: a hashed known_hosts line gets a fresh salt every time it is written, so a pin made in the copy could never hash the same twice. OnApply backs the manifest and inventory up first.
type FileDiff ¶
type FileDiff struct {
Path string
State string // added | removed | changed
Lines []history.DiffLine
// Checked is set when the file's new content was validated (JSON, see
// util/highlight.Check), and Problem holds what failed, if anything.
Checked bool
Problem string
}
FileDiff is one file the change touches. Path is relative to the home it belongs to, prefixed "~/.ssh/" or "config/" so the two trees read apart.
type HostInput ¶
HostInput is what a person can set on a host from the web. Pointer fields are left unchanged when nil, as an unset CLI flag is.
type NamingFields ¶ added in v0.1.6
NamingFields are the naming rules a NamingSet change sets. A nil field is left as it is, as an unset flag of `ssh naming set` is; an empty one goes back to inheriting.
func (NamingFields) Empty ¶ added in v0.1.6
func (f NamingFields) Empty() bool
Empty is true when the change would set nothing.
type Plan ¶
type Plan struct {
Command string
Args []string
Files []FileDiff
Effects []string
Hidden []string // files the copy holds no content for that the change removes or creates
Output string
Err string // the change would fail, with this message
Mints bool // the keys it shows are throwaway; apply mints new ones
// NoSnapshot is set when apply takes no snapshot of ~/.ssh first.
NoSnapshot bool
Hash string
}
Plan is a preview: what the change would write, what it would say, and a hash binding the two to the state they were computed from.