ssh

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: GPL-3.0, LGPL-3.0 Imports: 12 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 ssh handles SSH key injection and host key collection for node containers, and the export of the SSH client configuration.

Index

Constants

View Source
const (
	// ConfigFile is the ssh_config that a user's ssh includes.
	ConfigFile = "ssh_config"
	// KeyFile is the realm's private key, which ConfigFile names.
	KeyFile = "id_ed25519"
	// KnownHostsFile holds the nodes' host keys, which ConfigFile names.
	KnownHostsFile = "known_hosts"
)

The files of the SSH config export, in the directory that ExportConfig writes.

View Source
const HostKeyFile = "/etc/ssh/ssh_host_ed25519_key.pub"

HostKeyFile is where sshd keeps a node's ed25519 host public key, which the node generates on its first boot, in authorized_keys format with a comment: "ssh-ed25519 AAAA... root@host".

View Source
const InjectKeyScript = `mkdir -p /root/.ssh
printf '%s\n' "$1" >> ` + authorizedKeysPath + `
ssh-keyscan -t ed25519 localhost`

InjectKeyScript appends $1, a public key, to root's authorized_keys, creating the directory if needed, and prints the ed25519 host key that sshd serves, as ssh-keyscan reports it: "localhost ssh-ed25519 AAAA...". It has one command per line, for sh -e, which stops at the first that fails, and takes the key as an argument of the shell, not as part of its script. ssh-keyscan asks sshd, which must be running, for the key it serves; HostKey reads it from the output.

Variables

This section is empty.

Functions

func ExportConfig

func ExportConfig(ctx context.Context, client *docker.Client, fs afero.Fs, dir, realm string) error

ExportConfig exports the SSH configuration of realm to dir: it reads the private key and known_hosts from the realm's SSH relay container (mesh.RealmNames), in one docker exec, and writes id_ed25519, known_hosts and ssh_config to dir. Each file is written to a temporary file in dir and renamed into place, in the order of ExportFiles, so that a reader never sees a truncated file or Host blocks before their keys. When the relay container does not exist, the error satisfies docker.IsNotFound and dir is left as it is; RemoveExport then removes the export of a realm without clusters.

The sind CLI runs it after every command that changes the realm's clusters; pkg/cluster does not, so a library caller that keeps an export runs it itself.

func ExportFiles

func ExportFiles() []string

ExportFiles returns the files of the export, in the order ExportConfig replaces them: the key and the host keys before the ssh_config that names their hosts.

func GenerateSSHConfig

func GenerateSSHConfig(dir, realm string, hosts []string) string

GenerateSSHConfig returns the SSH config that lets the user's ssh reach the realm's nodes through its SSH relay container (mesh.RealmNames), with the private key and known_hosts in dir (KeyFile, KnownHostsFile). hosts are the nodes' DNS names; a name in it that is not a node's DNS name in the realm, <node>.<cluster>.<realm>.sind, is left out. For the default realm, it includes hostname canonicalization directives that enable short-name SSH access (e.g. "ssh controller").

func HostKey

func HostKey(stdout string) (string, error)

HostKey returns the ed25519 host public key in the output of InjectKeyScript, in "ssh-ed25519 AAAA..." format (without the hostname prefix). It skips ssh-keyscan's comment lines.

func HostKeyFromFile

func HostKeyFromFile(content string) (string, error)

HostKeyFromFile returns the key of HostKeyFile's content, in "ssh-ed25519 AAAA..." format, without the comment.

func RemoveExport

func RemoveExport(fs afero.Fs, dir string) error

RemoveExport removes the files of the export from dir, and dir itself if that leaves it empty. Files that do not exist are no error. It removes them in the reverse order of ExportFiles, ssh_config first, so that a reader never sees Host blocks whose key or host keys are gone.

Types

This section is empty.

Jump to

Keyboard shortcuts

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