manifest

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 13 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 manifest is the authama manifest domain model. The manifest is the single source of truth; this package loads/validates it and exposes the per-host key resolution the renderer and reconciler depend on (per_service default, shared opt-in).

Index

Constants

View Source
const (
	GitModeProfile = "profile"
	GitModeSSH     = "ssh"
	GitModeHTTPS   = "https"
)

Git remote modes. A checkout's origin points at GitHub one of three ways: through a profile's own SSH alias (git@github-<profile>:owner/repo.git), through plain SSH to github.com (the key bound to the rendered `Host github.com`), or over HTTPS (the gh-app credential helper).

View Source
const (
	HypervisorParallels = "parallels"
	HypervisorVMPal     = "vmpal"
	HypervisorVMware    = "vmware"
	HypervisorUTM       = "utm"
	HypervisorLima      = "lima"
	HypervisorOrbStack  = "orbstack"
	HypervisorPodman    = "podman"
)

Hypervisors sshmgr can resolve a devbox's address through.

View Source
const (
	KeyStoreFile        = "file"
	KeyStoreOnePassword = "1password"
)

Key stores. The empty string is the file store, so it never has to be written; anything else must be named here, because a typo would otherwise silently fall back to looking for private keys on disk.

View Source
const DefaultKeyComment = "{profile}/{alias} {date}"

DefaultKeyComment is the comment sshmgr writes when neither the profile nor the defaults set key_comment: the one every release before key_comment wrote.

View Source
const ProxyCloudflared = "cloudflared"

ProxyCloudflared reaches a host through Cloudflare Access: ssh runs `cloudflared access ssh --hostname %h`, which opens the tunnel after a browser sign-in, so no SSH port has to be open to the internet.

Variables

View Source
var DefaultGlobalOptions = map[string]string{
	"AddKeysToAgent": "yes", "IgnoreUnknown": "UseKeychain", "UseKeychain": "yes",
	"IdentitiesOnly": "yes", "ServerAliveInterval": "60",
}

DefaultGlobalOptions are the canonical Host* defaults used by Starter.

GitModes lists the modes in the order they are documented.

Hypervisors lists the supported hypervisors.

View Source
var ProxyKinds = []string{ProxyCloudflared}

ProxyKinds are the proxies sshmgr can render. raw_options may not set a ProxyCommand (it would run any command ssh is given), so each supported proxy is a field sshmgr writes itself, as it does for VM hosts.

Functions

func CategoryConfigFile

func CategoryConfigFile(category string) string

CategoryConfigFile is the ~ form path the root config Includes for a category, matching how IdentityFile paths render.

func CategoryConfigRel

func CategoryConfigRel(category string) string

CategoryConfigRel is the forward-slash path, relative to ~/.ssh, of the file holding a category's Host blocks.

func GlobProfileTree

func GlobProfileTree(sshDir string, tail ...string) []string

GlobProfileTree matches the pattern tail inside every profile directory on disk, in both layouts: profiles/<profile>/<tail> and profiles/<category>/<profile>/<tail>. It needs no manifest, because the scans that use it (doctor, snapshots, keyaudit) also look for what the manifest has forgotten.

A two-level match whose middle segment is "old" or dot-prefixed is dropped: that is a flat profile's rotation archive or staging directory, not a categorized profile, and a flat-only glob never saw inside them either. The result is sorted.

func IsDangerousOption

func IsDangerousOption(key string) bool

IsDangerousOption reports whether an SSH option key can execute commands / pull in config (dropped on import, rejected by validation). Case-insensitive.

func KeyComment

func KeyComment(m *Manifest, ref KeyRef, alias, date string) string

KeyComment expands the profile's key_comment for one key. alias is the host the key serves (callers pass the key name for an unwired key) and date the mint day.

func KeyCommentTemplate

func KeyCommentTemplate(m *Manifest, profile string) string

KeyCommentTemplate resolves the key_comment template for a profile: the profile's own, else the defaults', else DefaultKeyComment. It and KeyComment are functions, not Manifest methods, to keep that type from regrowing into a facade (cmd/sshmgr's layering test caps its method count).

func ManagedHostOption

func ManagedHostOption(key string) (useInstead string, ok bool)

ManagedHostOption reports whether a raw_options key duplicates a line the renderer writes for every host, and what to set instead. Case-insensitive, as ssh reads keywords.

func ProfileForOwner

func ProfileForOwner(m *Manifest, owner string) (string, error)

ProfileForOwner picks the profile a GitHub owner uses: Orgs, then Profile, then the only profile with a GitHub host. It fails rather than guess between several.

func RawOptionOverlaps

func RawOptionOverlaps(m *Manifest) []string

RawOptionOverlaps lists, as "profile/alias: ..." lines in manifest order, each raw_options key that duplicates a managed line. The renderer emits only the managed value (bar a raw Port at the default port), so these keys read as if they applied when they do not.

func UsesOnePassword

func UsesOnePassword(m *Manifest) bool

UsesOnePassword reports whether any profile keeps its keys in 1Password. A function rather than a method: Manifest carries a method ceiling (see TestNoTypeHasBecomeTheFacadeAgain), and this needs nothing private.

func ValidateHost

func ValidateHost(profile string, h Host) error

ValidateHost reports whether one host of the named profile would pass the manifest's validation, so a caller assembling hosts (import) can leave out the one that fails rather than the whole batch.

Types

type Defaults

type Defaults struct {
	KeyType         string         `json:"key_type"`
	KeyScope        string         `json:"key_scope"`
	RotateAfterDays int            `json:"rotate_after_days"`
	WarnBeforeDays  []int          `json:"warn_before_days"`
	ExpiryCheck     ExpiryCheck    `json:"expiry_check"`
	GlobalOptions   OrderedOptions `json:"global_options"`
	// OnePasswordAgent overrides the 1Password SSH agent socket a profile with
	// key_store "1password" renders as its IdentityAgent. Empty = the
	// platform's standard path (see OnePasswordAgentSocket).
	OnePasswordAgent string `json:"onepassword_agent,omitempty"`
	// KeyComment is the ssh-keygen -C template every profile inherits; empty
	// means DefaultKeyComment.
	KeyComment string `json:"key_comment,omitempty"`
	// Git configures `sshmgr git` and the rendered `Host github.com` block.
	Git *GitDefaults `json:"git,omitempty"`
}

Defaults are manifest-wide defaults.

func (Defaults) MarshalJSON

func (d Defaults) MarshalJSON() ([]byte, error)

MarshalJSON emits warn_before_days as [] when empty (not null) and global_options as {} via OrderedOptions, in declaration order.

func (Defaults) OnePasswordAgentSocket

func (d Defaults) OnePasswordAgentSocket() string

OnePasswordAgentSocket is the IdentityAgent a 1Password profile renders: the defaults override when set, else the platform's standard socket (checked against 1password.dev/ssh/get-started, 2026-10-19). "" on Windows, where Microsoft OpenSSH talks to one fixed pipe and per-host agents do not apply.

func (*Defaults) UnmarshalJSON

func (d *Defaults) UnmarshalJSON(b []byte) error

type ExpiryCheck

type ExpiryCheck struct {
	Enabled       bool `json:"enabled"`
	DebounceHours int  `json:"debounce_hours"`
	DesktopNotify bool `json:"desktop_notify"`
}

ExpiryCheck is the notifier policy.

func (*ExpiryCheck) UnmarshalJSON

func (e *ExpiryCheck) UnmarshalJSON(b []byte) error

type GitDefaults

type GitDefaults struct {
	// Mode is the default remote mode; empty means profile.
	Mode string `json:"mode,omitempty"`
	// Profile is the default identity: its GitHub key is bound to `Host github.com`
	// (ssh mode), and it is used for an owner Orgs does not list.
	Profile string `json:"profile,omitempty"`
	// Orgs maps a GitHub owner to the profile whose key it uses.
	Orgs map[string]string `json:"orgs,omitempty"`
}

GitDefaults configures `sshmgr git`. Absent, the mode is profile and no `Host github.com` block is rendered, so a manifest without it renders as before.

func (*GitDefaults) EffectiveMode

func (g *GitDefaults) EffectiveMode() string

EffectiveMode is Mode, or profile when unset.

type Host

type Host struct {
	Alias       string         `json:"alias"`
	Hostname    string         `json:"hostname"`
	User        string         `json:"user"`
	Port        int            `json:"port"`
	Provider    *string        `json:"provider,omitempty"`
	TokenEnv    *string        `json:"token_env,omitempty"`
	KeyName     *string        `json:"key_name,omitempty"`
	Tags        []string       `json:"tags,omitempty"`
	RequiresVPN bool           `json:"requires_vpn"`
	VPNName     *string        `json:"vpn_name,omitempty"`
	VPNURL      *string        `json:"vpn_url,omitempty"`
	RawOptions  OrderedOptions `json:"raw_options,omitempty"`
	// VM marks a local VM whose address the hypervisor supplies at connect time.
	VM *VMSpec `json:"vm,omitempty"`
	// Proxy routes connections through a proxy command, e.g. Cloudflare Access.
	Proxy *ProxySpec `json:"proxy,omitempty"`
}

Host is a single SSH host entry.

func GitHubHostOf

func GitHubHostOf(m *Manifest, profile string) (Host, bool)

GitHubHostOf returns the profile's GitHub host: the first one whose hostname is github.com. A profile with none has no profile-mode alias.

func VMHost

func VMHost(m *Manifest, alias string) (Host, error)

VMHost finds the host alias in m, which must have a vm spec.

func (Host) MarshalJSON

func (h Host) MarshalJSON() ([]byte, error)

MarshalJSON emits every field in declaration order (null for unset pointers, [] for no tags), matching the files v1 and v2 wrote. raw_options serializes {} when empty via OrderedOptions.

func (*Host) UnmarshalJSON

func (h *Host) UnmarshalJSON(b []byte) error

type KeyRef

type KeyRef struct {
	Profile string
	KeyName string
}

KeyRef names one key: the profile that owns it plus the file name inside that profile's directory. Key names are unique per profile, not globally - a person working under two orgs uses the same file name in both profile directories.

func (KeyRef) String

func (r KeyRef) String() string

String renders the composite "profile/key" selector form.

type KeySpec

type KeySpec struct {
	Name string `json:"name"`
	// Unset (rather than defaulted-on-load) so re-saving a manifest does not
	// bake today's defaults into every key, freezing them against a later
	// change to defaults.key_type / defaults.rotate_after_days.
	Type            *string `json:"type,omitempty"`
	RotateAfterDays *int    `json:"rotate_after_days,omitempty"`
}

KeySpec declares a key as a first-class member of its profile, independent of any host that uses it. Type and rotate_after_days are optional and inherit the manifest defaults when unset (see KeyTypeFor / RotateAfterDaysFor).

Declaring is optional in both directions: a host whose key_name names a key absent from the list still implicitly declares it, so every pre-`keys` manifest loads and renders unchanged. The list exists so a profile can own a key no host references yet - a second identity for the same org, or a key minted ahead of the host it will serve - which previously could not be expressed at all, since a key existed only as a property of a host.

func (*KeySpec) UnmarshalJSON

func (k *KeySpec) UnmarshalJSON(b []byte) error

type Manifest

type Manifest struct {
	Version  int                `json:"version"`
	Defaults Defaults           `json:"defaults"`
	Profiles map[string]Profile `json:"profiles"`
	// contains filtered or unexported fields
}

Manifest is the whole manifest.

func Load

func Load(path string) (*Manifest, error)

Load reads and validates a manifest from path.

func Starter

func Starter(emitUseKeychain bool) *Manifest

Starter returns a minimal valid manifest for `sshmgr init` - defaults and no profiles. Off macOS, the UseKeychain option is dropped. Mirrors Manifest.starter.

func (*Manifest) Categories

func (m *Manifest) Categories() []string

Categories returns the distinct categories in use, in first-seen manifest (file) order, so the root config Includes them in a stable order.

func (*Manifest) DeleteProfile

func (m *Manifest) DeleteProfile(name string)

DeleteProfile removes a profile and its order entry.

func (*Manifest) HostsForKey

func (m *Manifest) HostsForKey(ref KeyRef) ([]Host, error)

HostsForKey returns the hosts that use one key, scoped to its own profile.

func (*Manifest) IdentityFile

func (m *Manifest) IdentityFile(profileName, keyName string) string

IdentityFile is the rendered ~ form path for a key (always forward slashes). It names the private key. For a 1Password profile the private key is never on disk, so the renderer points ssh at its .pub instead; inventory records and every other caller keep this one, so a key has the same identity in both stores.

func (*Manifest) IterResolved

func (m *Manifest) IterResolved() ([]ResolvedKey, error)

IterResolved returns every host with its resolved key, in manifest (file) order - the order v1 resolved them in. Order is observable in order-preserving consumers like doctor's unpinned-host list; the rendered config is order-independent (the root config uses Include).

func (*Manifest) KeyPath

func (m *Manifest) KeyPath(sshDir string, ref KeyRef) string

KeyPath is the absolute path to a key's private half under sshDir.

func (*Manifest) KeyRefs

func (m *Manifest) KeyRefs() ([]KeyRef, error)

KeyRefs lists every distinct key in the manifest - the union of the keys each profile declares and the keys its hosts resolve to - deduplicated per profile so that hosts sharing one key yield a single ref. Refs are grouped by profile in manifest (file) order; within a profile, host-derived keys come first in host order, then any declared key no host uses.

The union is what makes a declared key real: it has no Host block, so walking IterResolved alone (which iterates hosts) leaves it invisible to reconcile, validate, doctor, list and expiry - present in the manifest, never minted, never checked.

func (*Manifest) KeySpecFor

func (m *Manifest) KeySpecFor(ref KeyRef) (KeySpec, bool)

KeySpecFor returns the profile's declaration for one key, if it has one. A key that only exists because a host names it has no spec and inherits every default.

func (*Manifest) KeyTypeFor

func (m *Manifest) KeyTypeFor(ref KeyRef) string

KeyTypeFor resolves the algorithm to mint a key with: the declared type when the profile declares one, else the manifest default.

func (*Manifest) KnownHostsFile

func (m *Manifest) KnownHostsFile() string

KnownHostsFile is the single, user-wide host-key trust store path. Every rendered host block points at this same file: splitting it per profile gave up cross-profile duplicate detection for no isolation ssh itself enforces (any profile's ssh invocation can read any other profile's known_hosts), so there is exactly one store, tagged and reference-counted per line instead of separated by directory.

func (Manifest) MarshalJSON

func (m Manifest) MarshalJSON() ([]byte, error)

MarshalJSON emits {version, defaults, profiles} with profiles in manifest (file) order - a Go map would otherwise marshal its keys sorted. Compact output; Save re-indents it to two spaces, the indentation those files used.

func (*Manifest) NonEmptyProfiles

func (m *Manifest) NonEmptyProfiles() []string

NonEmptyProfiles lists profiles that have at least one host, in manifest (file) order - the order v1 listed non-empty profiles in.

func (*Manifest) ProfileDir

func (m *Manifest) ProfileDir(sshDir, profileName string) string

ProfileDir is ProfileRel as an absolute path under sshDir.

func (*Manifest) ProfileNames

func (m *Manifest) ProfileNames() []string

ProfileNames returns profile names in manifest (file) order. Falls back to name order for a programmatically built manifest with no captured order.

func (*Manifest) ProfileRel

func (m *Manifest) ProfileRel(profileName string) string

ProfileRel is a profile's key directory relative to ~/.ssh, in forward-slash form: profiles/<category>/<profile> when the profile has a category, else profiles/<profile>. An undeclared profile resolves to the flat form, which is where every key lived before categories existed.

This is the one place the layout is decided. Every path to a key, its .pub, or its old/ directory goes through ProfileRel or ProfileDir; a hand-built filepath.Join(sshDir, "profiles", profile) is the defect a categorized profile exposes, because it silently points one directory too high.

func (*Manifest) ResolveKeySelector

func (m *Manifest) ResolveKeySelector(selector string) (KeyRef, error)

ResolveKeySelector turns a user-supplied key selector into a single KeyRef. It accepts the composite "profile/key" form, or a bare key name when exactly one profile uses it. A bare name matched by several profiles is an error listing the candidates, because the caller would otherwise operate on one profile's files while touching another's hosts.

func (*Manifest) ResolvedKeyName

func (m *Manifest) ResolvedKeyName(profileName string, host Host) (string, error)

ResolvedKeyName resolves a host's key name (per_service derives it; shared uses the profile key_name).

func (*Manifest) RotateAfterDaysFor

func (m *Manifest) RotateAfterDaysFor(ref KeyRef) int

RotateAfterDaysFor resolves a key's rotation interval the same way.

func (*Manifest) Save

func (m *Manifest) Save(path string) error

Save writes the manifest as indented JSON, atomically.

Via a temp file and a rename, not os.WriteFile: WriteFile truncates the target first, so a crash or a full disk mid-write leaves a truncated manifest - and the manifest is the only description of every profile, host and key, with nothing to rebuild it from. It also keeps whatever mode the file already had, while this re-asserts 0600 on every write.

func (*Manifest) SetProfile

func (m *Manifest) SetProfile(name string, p Profile)

SetProfile adds or replaces a profile, preserving file order (a new profile is appended, as v1 did).

func (*Manifest) UnmarshalJSON

func (m *Manifest) UnmarshalJSON(b []byte) error

func (*Manifest) Validate

func (m *Manifest) Validate() error

Validate re-runs the manifest validators (so a bad edit can't be persisted).

type OrderedOptions

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

OrderedOptions is an SSH-option map that preserves JSON key order (the renderer emits options in that order) and stringifies values the way v1 did.

func NewOrderedOptions

func NewOrderedOptions(pairs [][2]string) OrderedOptions

NewOrderedOptions builds an OrderedOptions from ordered key/value pairs (later duplicates overwrite the value but keep the first position).

func (OrderedOptions) Get

func (o OrderedOptions) Get(k string) string

func (OrderedOptions) Keys

func (o OrderedOptions) Keys() []string

func (OrderedOptions) Len

func (o OrderedOptions) Len() int

Len, Keys, and Get expose the options in order.

func (OrderedOptions) MarshalJSON

func (o OrderedOptions) MarshalJSON() ([]byte, error)

MarshalJSON emits the options in their preserved order.

func (*OrderedOptions) UnmarshalJSON

func (o *OrderedOptions) UnmarshalJSON(b []byte) error

type Profile

type Profile struct {
	Category string  `json:"category,omitempty"`
	KeyStore string  `json:"key_store,omitempty"`
	OPVault  string  `json:"op_vault,omitempty"`
	KeyScope string  `json:"key_scope"`
	KeyName  *string `json:"key_name,omitempty"`
	// KeyComment is the ssh-keygen -C template for keys minted in this
	// profile; empty inherits defaults.key_comment (see KeyCommentTemplate).
	KeyComment string    `json:"key_comment,omitempty"`
	Keys       []KeySpec `json:"keys,omitempty"`
	Hosts      []Host    `json:"hosts"`
}

Profile groups hosts that share an identity, plus the keys it owns.

Category optionally files the profile under a grouping directory - profiles/<category>/<profile>/ instead of profiles/<profile>/ - and moves its Host blocks out of the root config into profiles/<category>/config, which the root config Includes. Empty keeps the flat layout and inline rendering, so a manifest written before categories existed behaves exactly as it did.

KeyStore says where the profile's private keys live: "file" (the default, written as an omitted field) keeps them under ~/.ssh; "1password" keeps them as SSH Key items in OPVault, with only the public half on disk.

func (Profile) InOnePassword

func (p Profile) InOnePassword() bool

InOnePassword reports whether the profile keeps its private keys in 1Password.

func (Profile) MarshalJSON

func (p Profile) MarshalJSON() ([]byte, error)

MarshalJSON emits key_scope, key_name (null when unset), and hosts ([] when none) in declaration order, matching those files. category and keys are emitted only when set: both are v2 additions with no counterpart there, and omitting them keeps a manifest that uses neither - i.e. every manifest written before these fields existed - byte-identical across a load/save cycle.

func (*Profile) UnmarshalJSON

func (p *Profile) UnmarshalJSON(b []byte) error

type ProxySpec

type ProxySpec struct {
	Kind string `json:"kind"`
}

ProxySpec routes a host's connections through a proxy command.

type ResolvedKey

type ResolvedKey struct {
	Profile      string
	Host         Host
	KeyName      string
	IdentityFile string
}

ResolvedKey pairs a host with its resolved key name + IdentityFile path.

type VMSpec

type VMSpec struct {
	Hypervisor string `json:"hypervisor"`
	Name       string `json:"name"`
}

VMSpec marks a host as a local VM: its address comes from the hypervisor at connect time (`sshmgr vm proxy`), because a VM's IP changes and a static HostName goes stale.

Jump to

Keyboard shortcuts

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