sshconfig¶
Package sshconfig manages the local SSH configuration for codespace connections. It writes per-codespace config files into \~/.ssh/cosmonaut/ and ensures the main \~/.ssh/config includes them.
Index¶
- Constants
- func EnsureConfigIncludesGenerated(mainConfigPath string) error
- func EnsureIncludeLine(configText string) string
- func NeedsHostStarScoping(mainConfigPath string) bool
- func ParsePrimaryHostAlias(sshConfig string) (string, error)
- func ReadExistingAlias(includeDir, codespaceName string) (string, bool)
- func RefreshAllManagedExtras(includeDir string) (int, error)
- func RefreshManagedExtras(path string) (bool, error)
- func ScopeHostStarBlocks(mainConfigPath string) (bool, error)
- func WriteCodespaceConfig(includeDir, codespaceName, content string) error
- type SSHPaths
- func ResolvePaths() SSHPaths
- func (p SSHPaths) CodespaceConfigPath(codespaceName string) string
Constants¶
HostStarScopedLine is the form a bare `Host *` is rewritten to when the user accepts the scoping fix. The negation patterns prevent the catch-all block from contributing IdentityFile / IdentityAgent / etc. to codespace hosts (gh emits both `cs-*` and `cs.*` aliases).
MainConfigBackupSuffix is appended to the main ssh config path for the one-shot backup written before ScopeHostStarBlocks first modifies it.
func EnsureConfigIncludesGenerated¶
EnsureConfigIncludesGenerated ensures the main SSH config includes the generated configs.
func EnsureIncludeLine¶
EnsureIncludeLine ensures the SSH include line is at the top of the config. It removes any existing copy and prepends it.
func NeedsHostStarScoping¶
NeedsHostStarScoping reports whether mainConfigPath contains any bare `Host *` lines that should be narrowed so the catch-all block doesn't apply to codespace hosts. Returns false on read errors or missing file (the GUI banner shouldn't pester users without an actionable fix).
func ParsePrimaryHostAlias¶
ParsePrimaryHostAlias extracts the first concrete Host entry from SSH config text.
func ReadExistingAlias¶
ReadExistingAlias reads the SSH alias from an existing codespace config file. Returns the alias and true if the file exists and contains a valid Host entry, or empty string and false otherwise.
func RefreshAllManagedExtras¶
RefreshAllManagedExtras walks includeDir and refreshes the managed block in every *.conf file. Returns the number of files updated. Safe to call on every applet startup: idempotent and cheap.
func RefreshManagedExtras¶
RefreshManagedExtras rewrites the managed block in path to the current version. Returns true if the file was changed. No-op if already current or if the file doesn't exist.
func ScopeHostStarBlocks¶
ScopeHostStarBlocks rewrites bare `Host *` lines in mainConfigPath to `Host * !cs-* !cs.*` so codespace hosts skip catch-all auth rules (e.g. an IdentityFile pointing at a YubiKey-resident SK key that blocks ssh when the device isn't plugged in). Idempotent.
Writes a one-shot backup to mainConfigPath+MainConfigBackupSuffix before the first modification, so the user can recover the original if the rewrite breaks something else for them. Subsequent runs leave the existing backup untouched.
func WriteCodespaceConfig¶
WriteCodespaceConfig writes the SSH config for a codespace, replacing any prior cosmonaut-managed tail with the current one.
type SSHPaths¶
SSHPaths holds the resolved SSH directory paths.
func ResolvePaths¶
ResolvePaths returns the SSH paths for the current platform.
func (SSHPaths) CodespaceConfigPath¶
CodespaceConfigPath returns the path for a codespace-specific SSH config.
Generated by gomarkdoc