Skip to content
Security model

Security model

Lemano holds SSH access to servers and a history of what is on them. This page says what it trusts, what it keeps and what it refuses. To report a vulnerability, see the security policy.

What you may be looking for:

Host keys

  • Every host key is pinned in Lemano’s own known_hosts file ($XDG_CONFIG_HOME/lemano/known_hosts, in OpenSSH’s format), for a target and for every jump host on the way to it, each under its own host:port.
  • An unknown key is refused unless you pass --accept-new-host-key. A changed key is always refused, and is replaced only by lemano target rekey, given the exact new fingerprint (with --jump for a jump host).
  • A target can name the key to expect, hostKey in its file, as a public key line or a fingerprint. The first connection then accepts only a key it names, before anything is read, and pins it; any other key is refused with both fingerprints, and so is a pinned key the setting does not name. Jump hosts and certificate authorities are not covered.
  • Your ssh configuration cannot weaken this. Lemano only asks the ssh client to print its settings, and never reads StrictHostKeyChecking, UserKnownHostsFile, GlobalKnownHostsFile, HostKeyAlias, UpdateHostKeys or VerifyHostKeyDNS: a setting meant for your interactive ssh sessions must not turn off the checks of an unattended tool, and an alias must not make one host’s key stand for another’s. A changed HostName that leads to a host with another key is refused like any changed key.
  • Recording Ansible runs (lemano ansible record) pins a host it has never seen the way your own ssh would: when your known_hosts files (those ssh -G names as UserKnownHostsFile and GlobalKnownHostsFile, hashed entries included) have the host, under its address or its HostName, their keys are copied into Lemano’s file first, each as an entry for that host alone (never the shared or wildcard entry it was found under), and the host must present one of them; otherwise its first key is pinned, because a playbook run cannot stop to ask, and its fingerprint is shown in the run’s output. The commands that read hosts on your request (lemano ansible discover, check, codify, export) refuse such a host (exit code 4, with its fingerprint) unless given --accept-new-host-key. This only ever adds keys for a host Lemano has none for, so it can make the check stricter than pinning on first sight, never weaker. HostKeyAlias is not followed. Once pinned, a different key is refused, whatever Ansible’s host_key_checking says.

Commands Lemano runs on your machine

Lemano runs two kinds of local command, both from configuration you control:

  • ssh -G, to read your ssh configuration (see Using your SSH config). It runs with your environment, standard input from /dev/null, no terminal and a 10-second limit. A Match exec block in your configuration runs its command then, as it would for ssh itself.
  • A proxy command, from your ssh configuration or from a target file’s spec.connector.proxyCommand. It runs through your shell with your rights. A target file with a proxyCommand runs that command on the machine of whoever runs lemano discover with it: review target files from others as you would review a script.

Lemano runs no other local command. Turn reading the ssh configuration off with --ssh-config none (or LEMANO_SSH_CONFIG=none), or per target with spec.connector.sshConfig: false; neither ssh -G nor a proxy command from your configuration runs then.

A proxy command is never logged, shown or written to the store: Lemano records only that a target is reached through one. Its errors carry its exit status and the start of its standard error, with control characters escaped, and never the command line. Values put into it (%h, %n, %p, %r) are refused when they hold characters a shell would interpret.

Credentials

  • Target files hold references to keys (agent, file:, env:, secret://), never keys.
  • Keys are read into memory when a connection opens and are never stored. Key files that others can read are refused.
  • A key with a passphrase is used only through your SSH agent: Lemano never prompts.
  • What Lemano keeps about a connection, shown by lemano target show, is the host, port, user, jump hosts, the paths of identity files and the agent socket: no key, no passphrase, no proxy command.

Passwords

Keys are recommended: a key never leaves your machine, while a password is sent to the server, which can then use it elsewhere if it is compromised. For servers that only take a password, a target file may name one, and the password sudo asks for, by reference (spec.connector.password, spec.connector.sudoPassword: env:, file:, secret://, ansible:// or prompt):

  • A target file never holds a password; the loader refuses one.
  • A password file that others can read is refused, as a key is.
  • The login password is offered after the keys, and only to a server whose host key is pinned: an unknown key is refused before anything is sent, and a changed key always.
  • The sudo password is used only where sudo -n is refused. It is written to sudo’s standard input, never to a command line or the remote environment, and only once sudo’s own prompt has appeared. A refused password is not tried again: a wrong guess is not repeated against the account’s lockout limit.
  • Passwords are held in memory only while needed, then overwritten. They never reach the store, a log, an error, the JSON output or a fixture; Lemano records only that a password was used and the kind of its reference.
  • prompt reads from the controlling terminal with echo off; without a terminal the command fails rather than read a password from a pipe.

Asking Ansible for a password

A password reference ansible://<host>?config=<file>&inventory=<source> has Lemano ask its credential helper lemano-ansible (a program installed beside lemano; see credential helpers), which runs ansible (the debug action, which runs on your machine and connects to no host) to print the password variables of that one host: both the login and the sudo password of a target in one run, before the connection starts. Ansible reads the configuration file the reference names (passed as ANSIBLE_CONFIG, and run from that file’s folder) and your vault settings, and decrypts or renders the values. When a host sets several password variables, Lemano uses the one Ansible uses. The value is printed encoded in base64 on one line, which Lemano decodes into memory that it overwrites after use. Nothing Ansible printed is kept or shown: an error says what is wrong in its own words (no vault password, a wrong one, a missing variable, Ansible not installed), with the host and the variable names, never a value.

Ansible has settings that copy what it evaluates somewhere: a log file (log_path), and callbacks that write results to a file, a database or a web service, or notify someone. They apply to any command that evaluates a password, including this one, so Lemano starts Ansible, for this and for the import, so that none of them sees the value:

  • ANSIBLE_LOG_PATH=/dev/null: no log file, also for ansible-inventory, which prints every variable as written;
  • ANSIBLE_LOAD_CALLBACK_PLUGINS=false: an ad-hoc command loads callbacks other than its screen output only when bin_ansible_callbacks is set, and that is turned off;
  • and, in case a version loads them anyway, ANSIBLE_CALLBACKS_ENABLED and its older name ANSIBLE_CALLBACK_WHITELIST list only the screen output’s own name, and ANSIBLE_CALLBACK_PLUGINS names no folder, so neither a callback that needs enabling nor one that does not can be found.

This holds when your ansible.cfg names a log file and callbacks that copy every result into files: the settings above keep them from seeing the value, though a plain run of Ansible with the same file would write them.

Naming a configuration file and an inventory in a target file makes Lemano run Ansible with them on your machine, and they can run code: a vault password script, a dynamic inventory, a lookup. Read a target file that holds such a reference as you read a script, as you do one with a proxyCommand.

The reference names a host, a configuration file and the inventory sources, never a value. A host name with a character that Ansible reads as part of a host pattern (:, ,, *, [, ! and the like) cannot be referenced, so that a password is never asked for through a pattern that reaches other hosts. The inventory is yours: Ansible runs the lookups and filters it contains, as any use of it does.

What sudo runs

A pass runs its scripts as sudo -n sh -s, the script on standard input. With a sudo password, the login shell first runs sudo -S -p <prompt> -v, which reads the password and records the authentication, then the same sudo -n sh -s. So one sudoers rule covers both:

# /etc/sudoers.d/lemano
# Without a password:
lemano ALL=(root) NOPASSWD: /bin/sh -s
# Or, with the sudo password:
lemano ALL=(root) /bin/sh -s

With a password, sudo must keep the authentication for the next command (its default; timestamp_timeout must not be 0). That authentication does not outlive the run: the same command removes it with sudo -K when it ends, whether the script succeeded, failed or was interrupted. Lemano never runs any other command through sudo.

The secret store

lemano secret set keeps passwords and private keys in the store, for target files to name as secret://<name>:

  • Each value is encrypted with AES-256-GCM under a fresh data key, itself encrypted with the store’s wrapping key, as the store’s other contents are. The secret’s name is authenticated with the value, so a value copied into another secret’s row fails to decrypt.
  • Nothing derived from a value is stored: no hash, no length. Secrets are in no generation, record, history, verification or hash chain.
  • The store’s keys are sealed by its key file (or passphrase). Whoever has the store and its key file can read the secrets; the store alone is not enough. Losing the key file loses the secrets, along with the rest of the store: back it up as you back up the store.
  • Values are read from the terminal or standard input, never from the command line, held in memory only while needed, then overwritten.

Secrets by pattern

Files that hold credentials by their nature (private keys, login files, cloud and container clients’ logins, command histories) are never read: their content is not fetched, stored or hashed, only their metadata is kept, and an export lists them to move or replace by hand. See files never read.

Other file content is stored encrypted, and leaves the store only through a diff, a history, a revert preview, lemano ansible check, codify and export. In all of them a file’s content is kept out, unless you ask for it with --show-secrets or --with-secrets, when the file is not readable by every user, when it is a file of sealed text (crontabs, sudo rules, fstab, sshd_config, authorized_keys), or when its name or content looks like it holds secrets, however readable it is. The output then says not shown: it looks like it holds secrets: <rule>; export and codify write the content as an undefined variable with a hint, or encrypted with Ansible Vault under --with-secrets.

The command of a cron entry follows the same rule in state pull: Lemano keeps its text in the store, encrypted under the store’s keys, and writes it when the file that holds it is readable by every user and the text does not look like it holds a secret. A user’s crontab is normally not readable by every user, so its commands are left out, with the reason. The same holds for the options of a mount in /etc/fstab.

The commands of a sudo rule, and the forced command and the environment settings of an authorized key, are what those files grant, and the files are rarely readable by every user. state pull writes their text, kept the same way, unless the text looks like it holds a secret, whoever can read the file: the command is then left out and the declaration says which one and why, never quoting it. The public key of an authorized key is not a secret: the store holds it as it is, with the fingerprint that names it.

A sudo command line that attributes a change (lemano diff) follows the text rule of a cron command: Lemano keeps its text in the store, encrypted under the store’s keys and tied to its keyed hash, and shows it as the server logged it unless it looks like it holds a secret, when the command is left out and the change is still attributed. The server’s log is not a file of sealed text, so its readability does not decide. The keyed hash is never shown. Lemano reads sudo’s and sshd’s messages from the journal only when the journal records that the program itself logged them (its process and executable, which the sender cannot choose), so a line another program writes under sudo’s name, as logger -t sudo does, is not taken for sudo’s; a message the journal could not trace to its program, because sudo had already exited, counts only for the user who sent it. The server’s own text logs (auth.log) are not read for this: they carry no such record, and a line in them cannot be told from a forged one.

The rules by name:

RuleFiles
environment file.env, .env.*
key or keystore file*.key, *.p12, *.pfx, *.jks, *.keystore
SSH private key fileid_rsa, id_dsa, id_ecdsa, id_ed25519 and their security-key forms, ssh_host_*_key
credentials file.netrc, .pgpass, .htpasswd, .git-credentials, any name holding credentials or secret
history file*_history, .history, .zhistory, .lesshst, .viminfo

The rules by content, run in memory on the decrypted content of text files:

RuleFinds
private keya PEM, OpenSSH or OpenPGP private key header, or a client key given inline in a Kubernetes client configuration (a .pem file holding only certificates is shown)
registry loginan npm registry login (_authToken, _auth, _password) or a container registry login ("auth", "identitytoken")
credential assignmenta key naming a password, passphrase, secret, token, API key, access key or private key, assigned a value with = or : (DB_PASSWORD=..., password: ..., export API_TOKEN="..."), also in a comment
credentials in a URLscheme://user:password@host
authorization headerAuthorization: (or Proxy-Authorization:) with a scheme and a value
AWS access key, GitHub token, GitLab token, Slack token, Stripe live key, Google API key, npm token, Anthropic API keythe provider’s documented token prefix and length

An assignment does not count when its value is empty, yes/no, true/false, a number 0 or 1, a placeholder in angle brackets, or a reference to a value held elsewhere (${VAR}, $VAR, {{ var }}), nor when the key only names something about the credential (password_file, password_maps, PASS_MAX_DAYS); passwd: alone is a name service database, not a password. The rules name what they found and never quote it. They find common secrets, not every secret; keep other files out with contentExcludePaths.

What verify proves

Each generation is stored as a canonical JSON document that names the SHA-256 hash of the generation before it and the hash of every object it lists. lemano verify walks a target’s generations from number 0 and recomputes them: the document’s own hash, the parent hash, the hash of each object record, and that every blob an object refers to is present (blobs are checked for presence, not decrypted). It reports the first generation where this fails.

So it finds a generation or object that was changed, damaged or removed from inside the history, because the generations after it name its hash. It does not detect:

  • the newest generations being removed, with nothing after them to name the hash;
  • a store rewritten from some generation onward, hashes included, by someone who can write the store file and recompute them, which needs only the file, since the hashes are not keyed.

The history is evidence of what happened, not protection against someone who controls the store. Keep a copy of the latest generation’s hash somewhere the store’s users cannot write (lemano history -o json shows each generation’s hash), and compare it after a verify.

On the servers

Nothing is installed on a server. The connector writes nothing to the server’s disk and reading changes nothing in its configuration: the scripts travel over the SSH session and only read. The one trace of a read is on Red Hat family servers, where counting pending updates with dnf -C as an ordinary account leaves dnf’s own cache folder in /var/tmp. A server is written to only when you run lemano revert, described below. The login account is a dedicated one (lemano by default) that escalates with sudo -n when allowed. Getting started shows how to create it, give it your key and write the one sudoers line it needs.

Between the package manager’s full checks (daily by default), a package file outside /etc is checked only when its size, times, inode, mode or owner changed since the previous pass. Its change time is set by the kernel, so an edit is seen even when its modification time is put back; an attacker with root who also sets the clock back is seen only by the next full check. Set spec.discovery.packageCheckInterval lower, or run lemano discover --full-package-check, where that matters.

What a revert writes

lemano revert is the only command that changes a server, and it changes only what you asked for:

  • the files you reverted (and, with --delete-added, the files it deleted);
  • the sysctl keys you reverted, in the running kernel (sysctl -w);
  • with --reload, a reload of the units you named;
  • for a trial, the folder /var/lib/lemano/trial/<id>/, a timer and, on a host with systemd, a unit that undoes the trial at boot, all described below.

Nothing else is written, and no package, service file or account is touched. A revert writes only once approved: by typing yes, by --expect-plan with the digest of the plan that was shown (the run builds its plan again from a fresh reading and writes only if it has that digest), or by --auto-approve, which accepts whatever plan the run builds. The write step is one script, sent on the SSH session like every other, and it runs through the same sudo command (sudo -n sh -s, or with the sudo password), so the single sudoers rule shown above covers it. On a target declared to run without root (privilege: user), only files the login account can write are reverted, and sysctl -w is refused.

How a file is written

For each file the step:

  1. makes a temporary file in the target’s own folder, named .lemano-<pid>-<n>.tmp, with a mode no wider than the final one, so that nobody who could not read the file can read it meanwhile, and writes the content to it;
  2. sets the owner and group, then the final mode, and flushes the file to disk;
  3. runs the validator when the file has one: sshd -t -f for the sshd configuration, visudo -c -f for sudoers files. A file the validator refuses, or whose validator is not installed, is not written, and the live file stays as it was. The validator’s own words are dropped, since they quote the configuration. It then checks that the temporary file has the SHA-256 of the content the engine sent, which travels with it: a content damaged on the way, or decoded wrongly, never replaces the file;
  4. checks that the live file still has the SHA-256 the preview was built from (or still does not exist), right before the rename, and refuses the file otherwise as changed since the preview. Nothing else stops the others;
  5. renames the temporary file over the live one, which is atomic, and flushes the folder. A file that did not exist is put in place with a hard link instead, which fails if the name appeared in the meantime;
  6. on a host that enforces SELinux, restores the label the policy gives the file (restorecon).

The temporary file is removed on every way out, including a dropped connection. A name with a dot is skipped by sudo’s sudoers.d, so a temporary file there is never read as a rule.

What is checked and what is not. The check in step 4 and the rename are two system calls: a process that replaces the file between them wins the race, which no shell can close. For a new file the hard link closes it. A symbolic link or a folder found at the path is never replaced.

Folders other users can change. A shell command cannot open a file without following a symbolic link, and a user who can change a folder can swap a file in it for a link at any moment, between any two commands. So Lemano never acts as root on a file inside a folder that an ordinary user can change, at any level from / down to the file. The users who can change a folder are its owner, unless root, and, when its group may write to it, every member of that group other than root: the accounts whose primary group it is and the group’s listed members. A group with no members adds no one: only programs installed by root with that group write there (the cron spool, written by the crontab program, is one), so root acts itself. Where one user alone can change the folders on the way, every command that opens the file, its temporary file or the trial’s copy of it runs as that user (with setpriv), and a swapped link reaches only what that user could already read or change. The same rule holds when discovery reads a file’s content or takes its hash. The write is refused, with a reason, when:

  • the file, or the owner the revert would give it, is another user’s;
  • folders on the way belong to different users;
  • the group of a folder, which may write to it, has more than one member;
  • a folder that every user may write to is not sticky (in a sticky one, such as /tmp, the owner of each entry counts too);
  • setpriv is not installed.

Discovery reads neither the content nor the hash of a file in such a folder; the file is listed with the reason.

Primary members of a group are found by listing the accounts (getent passwd). A directory service set up not to list all its accounts can hide some of them, and a folder its group may write to is then taken as changeable by fewer users than it is.

Access control lists, extended attributes and file capabilities of the replaced file are not carried over, and the SELinux step has been run only against a stand-in for restorecon: it has not yet been checked on a host that enforces SELinux.

The content of a file travels inside the script, encoded in base64, on standard input: never on a command line, where other users of the server could read it. The answers carry fixed texts only, never content, and the engine escapes control characters in whatever a host prints.

What a trial leaves on the host

A revert run as a trial (--trial, and by default for the files that control access: sshd’s configuration, sudoers, PAM, /etc/security, firewall rules, authorized_keys, /etc/passwd, /etc/shadow, /etc/group, /etc/gshadow, /etc/nsswitch.conf, /etc/hosts.allow and /etc/hosts.deny) can undo itself if the change cuts the access that Lemano would use to undo it. Before writing anything, the step leaves:

  • /var/lib/lemano/trial/<id>/, owned by root with mode 0700, holding a copy of the current version of every file the revert will touch, the previous live value of every sysctl key, and a small POSIX sh script that puts them back;
  • a transient timer that runs that script when the window ends: lemano-trial-<id>.timer and its service, made with systemd-run, or, on a host without systemd, an at job (which needs atd to be running). A host with neither refuses the trial before anything is written;
  • on a host with systemd, a unit that undoes the trial at boot, /etc/systemd/system/lemano-trial-boot-<id>.service (owned by root, mode 0644), enabled into sysinit.target with a link in /etc/systemd/system/sysinit.target.wants/. It runs the same undo script and only while the trial is pending. The transient timer does not survive a reboot; this unit does, so a machine that restarts before the trial is confirmed puts the old files back instead of booting into the new ones. A host that cannot write the unit refuses the trial before anything is written.

The copies are of files that may hold secrets, so the folder is readable by root only, exists only while the trial is pending, and is removed:

  • when you confirm (after Lemano has logged in again with a fresh connection and found the host reachable): the timer is stopped, the boot unit and its link are removed and the folder removed, leaving nothing. If the boot unit cannot be removed, the answer says so and the folder stays, so that the confirmation can be repeated;
  • when you answer anything but yes, or the fresh login fails: Lemano runs the script at once, through the fresh connection or, when there is none, through the connection that wrote (sshd keeps the sessions it already has), and the timer is stopped first;
  • when the write changed nothing (every file changed since the preview, for example): the trial is cancelled at once;
  • when the timer fires: the script restores the files with their owner, group and mode, deletes the files the revert created, puts the sysctl values back, checks the restored sshd configuration with sshd -t and the sudoers files with visudo -c, and only then reloads the units the revert reloaded (sshd is not reloaded if its check fails). It removes its boot unit first, so that it runs at most once, and its folder, itself included. If something could not be put back, the folder is kept and the problem is written to the journal;
  • when the machine restarts before the window ends: the boot unit runs the script with --boot before the SSH server, systemd-sysctl and the firewall loaders (ufw, nftables, firewalld, netfilter-persistent, iptables) start, so they read the restored files. The files are put back the same way. The script then reloads nothing, which would wait for a job on a unit ordered after it, and sets no sysctl key: the restored sysctl files are applied by the boot itself.

When the restored files decide where the SSH server listens, the undo restarts it the same way the write did (the service is stopped and its socket restarted when the socket is active), so the server is back where it was. sshd -t is run with the privilege separation directory present, which the server’s unit removes when it stops.

After the write step restarts the SSH server, the host checks that it listens on the port, and the address if it is an IP address, that the target connects to, provided it listened there before the restart. If not, the host undoes the trial at once, without waiting for a login that cannot happen; the timer stays as the last resort. A target reached through a jump host or a proxy command is not checked this way.

A trial timed with at (a host without systemd) has no boot unit: the job stays in at’s spool across a restart, and atd runs it when it starts, which can be after the SSH server has started with the new files.

The window is 5 minutes by default and can be 1 to 60. Confirming and the timer cannot both win: whichever takes the folder’s marker first decides, and a confirmation that arrives after the undo began is told so.