Documentation
¶
Overview ¶
Package renderer renders the managed SSH config, ported from one template pair. One renderer backs config render, config check, and reconcile so they cannot disagree.
Index ¶
- Constants
- Variables
- func ClientFormatNames() []string
- func CloudflaredProxyCommand() string
- func ComposeRootConfig(existing, managed string) string
- func IsManagedEndLine(s string) bool
- func IsManagedFile(content string) bool
- func IsManagedHeaderLine(s string) bool
- func ProxyBinary(value string) string
- func ProxyCommandFor(alias string) string
- func RenderAll(m *manifest.Manifest, emitUseKeychain bool) (map[string]string, error)
- func RenderCategoryConfig(m *manifest.Manifest, category string) (string, error)
- func RenderFlatConfig(m *manifest.Manifest, p ExportPaths, emitUseKeychain bool) (string, error)
- func RenderFlatConfigOf(m *manifest.Manifest, p ExportPaths, emitUseKeychain bool, aliases []string) (string, error)
- func RenderHostBlockFor(m *manifest.Manifest, profile string, host manifest.Host) (string, error)
- func RenderRootConfig(m *manifest.Manifest, emitUseKeychain bool) (string, error)
- type ClientExport
- type ClientFile
- type ClientFormat
- type ClientHost
- type ExportPaths
- type RenderHost
- type Source
- type TermiusExport
- type TermiusKey
- type TermiusOptions
Constants ¶
const ( // ManagedHeader and ManagedEnd delimit the block authama owns in // ~/.ssh/config: everything between them is rewritten on each render, and // everything outside them is the user's and is preserved. They are the only // markers authama writes. ManagedHeader = "# Managed by authama - do not edit (run: authama ssh config render)" ManagedEnd = "# End of authama-managed block - content outside it is preserved" // RootConfig is the top-level config file's relative path under ~/.ssh. // Every uncategorized profile's Host blocks live inline here. A profile // with a category renders into profiles/<category>/config instead, which // the root config Includes - one file per category, never one per profile. RootConfig = "config" )
const ControlDir = "authama-cm"
ControlDir is the directory under ~/.ssh that holds the shared-connection sockets of VM hosts (vm.multiplex). `config render` and `vm proxy` create it owner-only; ssh refuses to make a master in a directory that is missing.
const ControlPersist = "10m"
ControlPersist is how long a VM host's shared connection outlives its last session.
const FlatHeader = "# authama flat export - every host inline, absolute paths, no Include.\n" +
"# Generated from the manifest by `authama ssh config export --flat`; ssh does not read this file\n" +
"# unless you point it here. Edit the manifest, not this copy, and export again.\n"
FlatHeader opens a flat export. It is deliberately not the managed header: authama owns the files it renders under ~/.ssh, and a copy of an export carrying that header would be treated as one of them.
Variables ¶
var ClientFormats = func() map[string]ClientFormat { out := map[string]ClientFormat{} for n, c := range encode.Clients { out[n] = ClientFormat{Name: c.Name, Client: c.Client, ViaSSH: c.ViaSSH, render: c.Render} } return out }()
ClientFormats are the exports, by name: encode.Clients, whose writers they call.
var CloudflaredPath = defaultCloudflaredPath
CloudflaredPath returns the cloudflared binary a Cloudflare Access host's ProxyCommand runs. A variable so tests pin it.
var GenericCSVColumns = encode.GenericCSVColumns
GenericCSVColumns are the generic export's columns (encode.GenericCSVColumns).
var Multiplex = defaultMultiplex
Multiplex reports whether VM hosts share one SSH connection (vm.multiplex, on unless set false). Off on Windows, whose OpenSSH has no ControlMaster. A variable so tests pin it.
var SelfPath = defaultSelfPath
SelfPath returns the authama binary a VM host's ProxyCommand runs. A variable so tests pin it.
var TermiusColumns = encode.TermiusColumns
TermiusColumns is the header of Termius's CSV import template (encode.TermiusColumns, where it is written).
Functions ¶
func ClientFormatNames ¶ added in v0.1.6
func ClientFormatNames() []string
ClientFormatNames are the export names, sorted.
func CloudflaredProxyCommand ¶
func CloudflaredProxyCommand() string
CloudflaredProxyCommand is the ProxyCommand for a Cloudflare Access host: cloudflared opens the Access tunnel to %h (the HostName, which ssh substitutes) after the browser sign-in Access asks for. Quoted like the VM ProxyCommand; a path ssh cannot quote falls back to the bare name.
func ComposeRootConfig ¶
ComposeRootConfig returns the full ~/.ssh/config with the managed block in place, preserving foreign content above and below it (e.g. an OrbStack Include). Old/legacy markers are recognized so the block is re-owned, not duplicated. An empty existing returns the managed block as-is.
func IsManagedEndLine ¶
func IsManagedFile ¶
IsManagedFile reports whether content opens with the managed header (or the pre-rename one) - i.e. whether authama wrote it.
func IsManagedHeaderLine ¶
IsManagedHeaderLine and IsManagedEndLine report whether a trimmed line opens or closes the managed block, under the current markers or an older release's.
func ProxyBinary ¶
ProxyBinary extracts the binary path from a ProxyCommand value authama rendered - a VM host's authama or a Cloudflare Access host's cloudflared - and "" for any other value. doctor uses it to find a recorded path that no longer exists, or a cloudflared that was never installed.
A VM host's ProxyCommand is `"<authama>" ssh vm proxy <alias>`; releases up to 2026-11-07 rendered `"<authama>" vm proxy <alias>`, and a config not yet re-rendered still holds that, so both are read.
func ProxyCommandFor ¶
ProxyCommandFor is the ProxyCommand a VM host renders: authama asks the hypervisor for the VM's current address on each connection.
The path is double-quoted literally, not with Go's %q: ssh does not unescape, so %q would double every backslash in a Windows path. A path containing a double quote cannot be quoted for ssh at all and falls back to the bare command name, resolved through PATH.
func RenderAll ¶
RenderAll renders every managed file: {relative path -> content} - the root config, plus profiles/<category>/config for each category in use.
func RenderCategoryConfig ¶
RenderCategoryConfig renders profiles/<category>/config: the Host blocks of every profile in that category, in manifest (file) order. It carries the managed header so authama can tell a file it wrote from one a user wrote there by hand, and no Host * block - the root config's applies to every host, wherever its block lives.
func RenderFlatConfig ¶
RenderFlatConfig renders the whole managed config as one self-contained file, for tools that read a single ssh_config and do not follow Include or Match (Termius's importer is one). Every profile's hosts are inline in manifest order, whatever their category, followed by the git ssh-mode block and Host * last, exactly as the split render orders them. Every ~ path is made absolute, so the file means the same wherever it is copied.
It is an export, never written over a file `config render` owns.
func RenderFlatConfigOf ¶ added in v0.1.6
func RenderFlatConfigOf(m *manifest.Manifest, p ExportPaths, emitUseKeychain bool, aliases []string) (string, error)
RenderFlatConfigOf is RenderFlatConfig of only the hosts named: each one's block exactly as the whole export writes it, under its profile's banner, in manifest order. The git ssh-mode block comes with the git profile's github.com host, and Host * always closes the file. An alias the manifest does not have is an error.
func RenderHostBlockFor ¶
RenderHostBlockFor renders the Host block one manifest host produces - byte for byte what RenderRootConfig emits for it. `authama ssh show` uses it to answer "what does this alias actually do" from the manifest, without asking the user to find the block in a file that now holds every profile's hosts at once.
func RenderRootConfig ¶
RenderRootConfig renders the entire managed block: one Include per category in use, then every uncategorized profile's hosts inline under a banner (in manifest/file order), then the global Host * block last.
Host * must stay last. OpenSSH takes the first value it obtains for a given keyword, so a global block placed above the per-host blocks would silently override their more specific directives. The category Includes therefore sit at the top of the block, where each included file expands in place ahead of Host *.
The Includes open with `Match all`. An Include that follows a Host or Match line is conditional on it, and the managed block is composed under whatever foreign content the user keeps above it - a hand-written Host block there would otherwise scope every category to that one host and leave the rest unconfigured, with no error. `Match all` resets the condition to every host. It is emitted only when there is a category to include, so a manifest with none renders byte-identical to before.
Types ¶
type ClientExport ¶ added in v0.1.6
type ClientExport = encode.ClientExport
ClientExport is a rendered export: the files, the hosts left out with the reason for each, and notes the user needs to finish the import.
func RenderClientExport ¶ added in v0.1.6
func RenderClientExport(m *manifest.Manifest, p ExportPaths, format string, opts TermiusOptions) (*ClientExport, error)
RenderClientExport renders the manifest's hosts for one SSH client. The hosts are chosen as for Termius (see RenderTermiusCSV): git hosts only with IncludeGit, never a --skip alias, and, for a format that does not go through ssh, never a host reached through a ProxyCommand.
type ClientFile ¶ added in v0.1.6
type ClientFile = encode.ClientFile
ClientFile is one file an export writes: its name and its bytes.
type ClientFormat ¶ added in v0.1.6
type ClientFormat struct {
Name, Client string
// ViaSSH formats launch `ssh <alias>`, so OpenSSH reads the managed config
// and a ProxyCommand or VM host works as it does at the terminal; the
// others hand the client a host, port, user and key and keep only hosts
// the client can reach on its own.
ViaSSH bool
// contains filtered or unexported fields
}
ClientFormat is one SSH client's import format.
type ClientHost ¶ added in v0.1.6
ClientHost is one host as an SSH client's import sees it. It is encode.Host: the writers moved to util/encode, where the export pipeline uses them too.
type ExportPaths ¶
ExportPaths is what an export needs to turn the ~ form paths the managed config uses into absolute ones: the SSH directory ~/.ssh stands for, and the home directory any other ~/ path is relative to. They differ under --ssh-dir, which is why the home is not derived from the SSH directory.
func ExportPathsFor ¶
func ExportPathsFor(sshDir string) ExportPaths
ExportPathsFor is the ExportPaths for sshDir: the user's home, or the SSH directory's parent when there is no home to read.
type RenderHost ¶
type RenderHost struct {
Alias string
Hostname string
User string
Port int
IdentityFile string
// IdentityAgent is the agent socket for a key kept in 1Password, "" for a
// key on disk. Rendered quoted: the macOS socket path contains a space.
IdentityAgent string
KnownHosts string
RawOptions manifest.OrderedOptions
// ProxyCommand is set by authama for a VM host (never from raw_options, which may not hold one).
ProxyCommand string
// ControlPath, when set, makes the host share one connection: the block
// gains ControlMaster/ControlPath/ControlPersist (a VM host, vm.multiplex).
// A value raw_options sets for one of them wins.
ControlPath string
}
RenderHost is the flat view a host block needs to render.
type Source ¶ added in v0.1.6
type Source struct {
M *manifest.Manifest
P ExportPaths
EmitUseKeychain bool
}
Source is the manifest as the export pipeline's host formats read it (encode.HostSource): the hosts a selection kept, as a client sees them, or their managed ssh_config.
func (Source) ClientHosts ¶ added in v0.1.6
func (s Source) ClientHosts(aliases []string, client string, viaSSH, includeGit bool) ([]encode.Host, []string, error)
ClientHosts are the hosts named, in the order named, chosen as RenderClientExport chooses them: a host behind a ProxyCommand only for a client that runs ssh, a git host only with includeGit.
func (Source) ManifestOrder ¶ added in v0.1.6
ManifestOrder is aliases in manifest order, as the client exports list hosts; an alias the manifest does not have keeps its place at the end.
type TermiusExport ¶
type TermiusExport struct {
CSV string
Keys []TermiusKey
Skipped []string
}
TermiusExport is a rendered Termius import: the CSV, the keys to attach, and the hosts left out with the reason for each.
func RenderTermiusCSV ¶
func RenderTermiusCSV(m *manifest.Manifest, p ExportPaths, opts TermiusOptions) (*TermiusExport, error)
RenderTermiusCSV renders the manifest's hosts as a Termius CSV import, one row per host Termius can reach: group = profile, label = alias, tags = the host's tags. Two kinds are left out and reported:
- VM hosts, which are reached only through authama's ProxyCommand, which Termius ignores (its docs say so), so a row would be a dead host;
- git hosts (user git, or a github or gitlab provider), which are not shells, unless IncludeGit is set;
- any alias named in Skip.
No password is ever written: the column is part of the template and stays empty.
type TermiusKey ¶
type TermiusKey struct {
Label string // the host's alias, its Termius label
KeyFile string // absolute path of the key ssh would use
Agent string // non-empty when the key lives in 1Password, not on disk
}
TermiusKey is one key the user attaches in Termius by hand: the CSV carries no keys, and Termius imports them into its own keychain, not by path.
type TermiusOptions ¶
type TermiusOptions struct {
IncludeGit bool // also export git hosts
Skip []string // aliases to leave out
}
TermiusOptions narrows a Termius export.