Using your SSH config
If ssh web-07 already works from your machine, a target file can be as
short as this:
apiVersion: lemano.dev/v1alpha1
kind: Target
metadata:
name: web-07
spec:
connector:
type: ssh
host: web-07Lemano asks your OpenSSH client for the settings it would use for
web-07 and connects with them: the real host name behind the alias, the
port, the user, the identity files, the jump hosts and the proxy command.
Lemano still makes the connection itself, and still checks every host key
against its own known_hosts file.
How the settings are read
For each target, Lemano runs
ssh -G [-F FILE] [-l USER] [-p PORT] [-J JUMPS] -- HOSTwhich prints the configuration after every Host, Match and Include
block has been applied, exactly as ssh HOST would apply them, including
Match final and a HostName that changes which later blocks match.
Nothing parses your configuration files but ssh itself.
ssh -G also prints OpenSSH’s own defaults: your local user name, port
22, the default identity files. Those are not settings you chose, so
Lemano tells them apart by asking a second time with -F none (no
configuration file at all) and keeping only what differs.
A User equal to your local user name looks the same in both answers, so
Lemano asks ssh once more, through a temporary configuration file that is
readable by you only and removed at once, to tell a User you set from
the default. If it cannot be told, Lemano says so and keeps its own
default. Match exec commands run once for each of these questions.
Which value wins
- A setting the target file states. It is passed to
ssh -Gon the command line, soMatchblocks see it, as withssh -o. - A setting your ssh configuration sets.
- Lemano’s default: port 22, the user
lemano, the keys of your SSH agent.
The default user of a target stays lemano, a dedicated account, even
though ssh itself would fall back to your local user name: Lemano never
logs in to a target with your own account unless something says so. A
jump host’s default user is your local user name, as for ssh.
lemano target show NAME shows the settings in effect for the last
discover and where each came from:
connection: user deploy (ssh config), host 10.0.4.17 (ssh config), port 22 (default)
through jump hosts: ops@bastion.example.com:22 (ssh config)
identity files: /home/me/.ssh/id_work (ssh config)
ssh config: readlemano discover -o json and lemano target show NAME -o json give the
same in connection.
The settings Lemano uses
| ssh_config keyword | Used for |
|---|---|
HostName | the host connected to; its key is pinned under this name |
Port, User | when the target file leaves them out |
IdentityFile | keys to offer, in order, after the target file’s credential; when none is configured, OpenSSH’s default files (~/.ssh/id_rsa, id_ecdsa, id_ed25519 and the others this ssh lists) |
IdentitiesOnly | offer only the agent keys that match an IdentityFile |
IdentityAgent | the agent socket (none turns the agent off) |
ProxyJump | jump hosts, each resolved with its own settings |
ProxyCommand | a local command that carries the connection |
ConnectTimeout | shortens the target’s connect timeout, never lengthens it |
Every other keyword is ignored. These are never honoured, whatever your
configuration says, because Lemano pins host keys itself:
StrictHostKeyChecking, UserKnownHostsFile, GlobalKnownHostsFile,
HostKeyAlias, UpdateHostKeys, VerifyHostKeyDNS. CertificateFile
is not used yet: SSH certificates are not supported.
Keys
Lemano offers keys in the order ssh tries them:
- the target file’s own
credential, when it states one; - the agent’s keys that match an
IdentityFile, in file order; - the agent’s other keys, unless
IdentitiesOnly yes; - the
IdentityFilekeys the agent does not hold.
With no IdentityFile in your configuration, the files are OpenSSH’s
default ones, in the order your ssh lists them; those that do not exist
are skipped without a word.
The agent is the one IdentityAgent names, or SSH_AUTH_SOCK. An
IdentityFile may name a public key, to pick that key in the agent. A
key with a passphrase is used only through the agent: Lemano never asks
for a passphrase. If a server refuses every key, the error lists what was
offered and what was left out and why, for example
/home/me/.ssh/id_old (passphrase-protected and not in the SSH agent).
Jump hosts
Host bastion
HostName bastion.example.com
User ops
Host web-*
ProxyJump bastionA chain of any length works (ProxyJump ops@gw1,gw2:2200): each hop is
resolved with its own Host blocks, as ssh resolves it, and reached
through the one before. A jump host is offered the agent’s keys, its own
IdentityFile keys, then the target file’s credential.
Every jump host’s key is pinned in Lemano’s known_hosts under its own
host:port. An unknown jump host key is refused unless you pass
--accept-new-host-key; the error names the jump host. A changed jump host
key is always refused. After checking the new key, pin it with
lemano target rekey web-07 --jump bastion.example.com:22 --fingerprint SHA256:...ProxyJump none turns jump hosts off.
Proxy commands
Host db-*
ProxyCommand ssh -W %h:%p ops@bastion.example.comThe command runs on your machine through your shell, as ssh runs it, with
%h, %n, %p, %r and %% replaced. Its standard input and output
carry the SSH connection; Lemano still checks the host key of the server
at the other end, pinned under the HostName. The command is killed when
the pass ends. If it fails, the error gives its exit status and the start
of what it wrote to standard error, never the command itself.
A command in a proxy chain runs with your rights, like any line of your ssh configuration: see Security model.
Choosing the configuration file
By default ssh -G reads the files ssh reads: ~/.ssh/config and the
system-wide file. To read another file instead (and not the system-wide
one), or none:
lemano --ssh-config ./lab_ssh_config discover -f targets/
lemano --ssh-config none discover -f targets/ # use the target files only
LEMANO_SSH_CONFIG=none lemano discover -f targets/For one target, spec.connector.sshConfig: false uses its own file’s
settings only.
Without OpenSSH
When no ssh client is on PATH, or it cannot print its configuration,
targets are reached with their own files’ settings, and discover says
once that your ssh configuration was not read and why. target show shows
it for each target as ssh config: not read: ....
If ssh -G itself fails, for example on a syntax error in your
configuration, or does not answer within 10 seconds (a Match exec
command that hangs), the target is not connected: guessing its settings
could reach another host. The error gives ssh’s exit status and message.