SSH Keys
The SSH key inventory answers who can log in to our machines, and is that
still what we want. The agent reads the authorized_keys files of every
account on a host, the SSH server's effective settings and the accounts that
can become root; the dashboard keeps what it finds, lets you say whose each key
is, tells you when a key nobody owns turns up, and removes a key from every
host it is on in one request.
Reading is all the agent does by default. Removing a key is a job (see Removing a key).
Where to find it
Security → SSH keys has three tabs over one search box:
| Tab | One row per | Answers |
|---|---|---|
| By key | key (fingerprint) | On how many hosts is this key, under which accounts, and whose is it? Keys without an owner come first. |
| By host | host that reported | How many keys does it have, how many without an owner, and what is wrong with its SSH access? |
| By owner | person | Everything this person can log in to. |
The search matches the fingerprint, comment, account name, host name and owner. The filters narrow to a customer and, on the first tab, to keys without an owner or weak keys. Four figures above the tabs count the different keys, the keys without an owner, the weak keys and the hosts with a serious finding.
Click a row for the detail: a key lists every host, account and file it is
installed under, with the options that restrict it (from=, command=); a
host shows its SSH server settings, the accounts in its administrative groups,
its passwordless sudo rules and each key; an owner shows all their keys and
all the places they are installed.
A key's owner is one record for the key wherever it is installed. Only someone who reaches every customer that has the key can assign or clear it.
The page follows the server live. A report from a host, a new owner or a finished removal appears without reloading, and a customer's hosts never show up for someone who may not see that customer.
What the agent reads
The agent collects this when it starts and then every 30 minutes, and sends it
to POST /api/agent/ssh-keys only when it changed, or once a day when it did
not. The body is the same signed, gzip-compressed envelope the
inventory uses. Nothing is configured: it runs on every agent, and
reads only.
| What | Linux and other Unix hosts | Windows |
|---|---|---|
| Keys | The AuthorizedKeysFile files of every account in /etc/passwd that has a home directory. The setting comes from sshd -T, so %h, %u and a custom path are honoured; the default is .ssh/authorized_keys and .ssh/authorized_keys2 | %ProgramData%\ssh\administrators_authorized_keys, which applies to every administrator, and .ssh\authorized_keys in each profile under %SystemDrive%\Users |
| SSH server settings | sshd -T for what is in effect, PermitRootLogin, PasswordAuthentication, PubkeyAuthentication, PermitEmptyPasswords, AuthorizedKeysFile, AuthorizedKeysCommand and Port. Without the rights to run it, /etc/ssh/sshd_config and its Include files are read instead, and the page says so; that reading ignores Match blocks | the same, from %ProgramData%\ssh\sshd_config when sshd.exe -T cannot be run |
| Accounts that can become root | the members of sudo, wheel and admin, including accounts that have the group as their primary group, which /etc/group does not list | the local Administrators group, found by its well-known identifier so the language of the installation does not matter |
| Sudo without a password | the NOPASSWD rules of /etc/sudoers and every file of /etc/sudoers.d. The files are parsed, never executed; aliases are reported by name and a line the parser does not understand is skipped | not applicable |
Per key the agent reports the SHA-256 fingerprint as ssh-keygen -l prints
it, the type, the length, the comment, the account and file it came from and
the options in front of the key. Lines that are not a key, including damaged
ones sshd would skip as well, are ignored.
A file the agent cannot read, usually because it does not run with enough rights, is reported as unreadable. The dashboard keeps the keys it last knew from that file instead of treating it as emptied.
Needs the agent to run with the rights to read every account's home
directory and to run sshd -T: root on Linux, an administrator account on
Windows. Run with less, it reports less, and an unreadable file says so.
Owners
A key is anonymous until somebody says whose it is. Assign owner on a key names either an account of this instance or, for someone who has none such as a contractor, a name. Owners are kept per fingerprint, so one assignment covers the key on every host and under every account, and a person who holds several keys has all of them on the By owner tab. Names are matched ignoring case.
A key that belongs to no person can be given to a customer instead, shown as
Customer: name. This is meant for keys such as the default key of a Proxmox
cluster (root@pve), which every node of the cluster holds: the dialog offers
the customers whose hosts carry the key, so nobody has to invent a name. A
customer-owned key counts as owned, and the By owner tab groups it under the
customer. Deleting the customer removes the ownership with its hosts.
Assigning and removing owners is for administrators and managers, within the customers they reach. A key that also sits on a host in somebody's private area can be changed by nobody else, an administrator included, and the names offered when you assign an owner are only those of keys on hosts you see. Deleting an account removes its ownership: its keys count as unowned again. Every change is in the audit log.
Keys in profiles
Every account can store its own public keys under Profile → Security → SSH
keys, and an administrator can do the same for any account from Settings →
Users → ⋯ → SSH keys. Paste one or several lines (the content of a
.pub file), optionally with a label; the dashboard computes the fingerprint
the agent reports for the same key. Accepted are ssh-ed25519, ecdsa-sha2-*,
ssh-rsa of at least 2048 bits and the security-key types
sk-ssh-ed25519@openssh.com and sk-ecdsa-sha2-nistp256@openssh.com. A private
key, a line with options in front (from=, command=) and a certificate are
refused, and so is the whole paste if any line is.
A stored key is the same thing as an assigned owner: the account owns the
fingerprint wherever it appears, so the key raises no ssh.key_unknown event
when it shows up on a host and is listed with the account on the By owner
tab. Nothing is raised retroactively and no event is created or removed when a
key is stored or removed.
- A fingerprint another account already owns is refused, naming that account.
- A fingerprint a name without an account owned (a contractor) is taken over by the account; the audit entry lists the name that was replaced.
- Assign owner on the SSH keys pages with an account puts the key into that account's profile too, marked Only fingerprint known because the public key itself was never entered. Changing or removing the owner there takes the key out of the profile that held it.
- Removing a key from a profile removes the ownership only if it still points at that account.
- Deleting an account removes its keys and ownerships.
Storing and removing are in the audit log as ssh_key.profile_add
(with the fingerprints, the label and any name taken over) and
ssh_key.profile_remove. The routes are in the API.
Expected host keys
Some keys belong to the machines and not to a person: the key every node of a
Proxmox cluster generates (root@<nodename>, kept in
/etc/pve/priv/authorized_keys and installed on every node), or the key a
backup server logs in with. Such a key will never have an owner, and it is not
an intruder. Mark as expected host key on a key says so:
| Reason | required, up to 300 characters; shown when you point at the badge, and kept in the audit log |
| Where | All hosts (administrators only; it never covers a host in a private customer), all hosts of a customer, or chosen hosts among those that carry the key |
Where the mark applies, the key raises no ssh.key_unknown event and no
ssh_key.unknown webhook when it appears, does not count as a key without an
owner (the figure on this page, the home page, the Keys without an owner
host finding and the compliance check), and shows a neutral Host key
badge in place of the red No owner. A key marked for only some of its hosts
keeps the red badge, because it is still unexplained on the others. A key can
have an owner and a mark at the same time; the owner is shown.
Remove host key mark takes it back: the key counts as unowned again, and is reported when it next appears. Marking and unmarking are for the same people as assigning owners (administrators and managers, within the customers they reach, and only for a key all of whose customers they reach), and each is in the audit log.
The dashboard recognises a probable Proxmox cluster key and says so in the key's
detail and in the dialog: its comment is root@<nodename> and it sits in
/etc/pve/priv/authorized_keys, or it is root's key on at least two hosts. It
is only a hint. Nothing is ever marked automatically.
A key nobody owns
The first report of a host is the baseline. Keys found then are listed and wait on the page to be given owners; they are not an incident.
After that, a key that appears on a host and has no owner raises a
critical event, ssh.key_unknown, naming the host, the account, the file and
the fingerprint, and sends the ssh_key.unknown webhook. The
default event rule Critical events mails it at once, as it does every
critical event (see Event Rules); a customer or host under an
open maintenance window is not notified, but the event is still recorded. A
key that already has an owner, wherever it was assigned, appears without a
sound, and so does one marked as an expected host key
for that host.
There is no separate alert to acknowledge: the event is the notification, and assigning an owner is how you settle it.
Findings
A host is marked when something about its SSH access is worth a look. A finding is serious (red) or a warning (amber):
| Finding | Severity | Meaning |
|---|---|---|
| Root may log in with a password | serious | PermitRootLogin yes |
| Empty passwords allowed | serious | PermitEmptyPasswords yes |
| Password logins on | warning | PasswordAuthentication yes |
| Key logins off | warning | PubkeyAuthentication no, which makes every key on the host inert |
| Sudo without a password | warning | a NOPASSWD rule exists |
| Sudo without a password for everything | warning | a NOPASSWD rule that covers ALL commands |
| Weak keys | warning | a DSA key, or an RSA key below 2048 bits, is installed |
| Keys without an owner | warning | at least one key on the host has no owner |
Weak keys are also marked on the key itself. Only serious findings count towards the Hosts with serious findings figure.
Removing a key
Remove from all hosts on a key, Remove all on an owner, and
Remove on a key of one host ask for the key to be taken out of the
authorized_keys files. In the key's dialog every row of the table also has
Remove from this host: it removes the key from that account's files on
that one host only and leaves every other host alone. A removal always
becomes a batch of ssh.key.remove jobs, one per host that holds one
of the keys. They wait for a second person's approval only where the
customer's four-eyes policy asks for it, as every other job does; otherwise
the hosts remove the keys as soon as they receive the jobs.
Requesting is one step. The dialog lists what is removed from which host and account and asks for the reason (required where the customer's policy asks for one); Request removal sends it. Nothing has to be started afterwards: where approval is needed, the jobs start by themselves the moment a second person approves them, and the dialog shows live whether the removal is waiting for approval, running, done or failed.
| Permission to request and approve | access.shell, at every customer the hosts belong to |
| Host setting | the action ssh-keys in the actions list of the host's configuration file; a host that does not list it rejects the job |
| Reason | required where the customer's policy asks for one, and kept in the audit log |
The hosts are chosen by the dashboard from what you can see when you ask. A host that is offline gets the job when it links again, up to the day the job is valid for.
On the host the agent:
- finds the files by the same rules as when it reads them,
- removes exactly the lines whose key has one of the fingerprints — comments, other keys and line endings stay as they were, and the file ends with a line break so a key appended later starts on a line of its own,
- copies the file next to itself as
authorized_keys.selvara-bak-<time>first, readable by its owner only, and - reads the file back to make sure the key is gone.
The job's output lists each file it changed and where its copy is. A host that does not hold the key succeeds without changing anything. The agent reports again at once, so the page shows the result within moments. The copies are not cleaned up; delete them when you no longer need them. To put a key back that was removed by mistake, see the next section.
Undoing a removal
A removal that changed files can be undone from the jobs. Open the removal's batch (the link in the dialog, or the batch of any of its jobs) and choose Restore keys to put back what every host took out, or choose Restore keys on the row of one host. The dialog says how many files on how many hosts are touched. This is useful when a key was removed from more places than it should have been, for example from a service account that still needs it.
A restore is a batch of ssh.key.restore jobs, one per host, with the
same permission (access.shell), the same customer policies (second person,
reason) and the same host setting (the action ssh-keys) as the removal. The
dashboard takes the fingerprints and the files with their copies from the
removal's own result; nothing is typed in. On the host the agent, for each
file:
- accepts only a file that it would also read for an account, and only a copy under the name the removal gave it, so the job cannot write anywhere else,
- appends the lines of the removed keys from the copy exactly as they were, options and comment included, unless the key is in the file again already,
- starts the first appended key on a line of its own if the file did not end with a line break,
- copies the file next to itself as
authorized_keys.selvara-bak-<time>before it changes it, and keeps its owner and mode, and - reads the file back to make sure the keys are there.
A copy that was deleted in the meantime is reported on its file and does not fail the job; the other files are still restored. Keys that were added or changed after the removal stay as they are. Restoring twice is harmless. Agents older than the release that introduced this job type refuse it as an unknown kind of job: update the agent first.
Server accounts
A server account is a login that Selvara knows about and can create, check and remove on Linux hosts. It is defined once as a template and then rolled out to as many hosts as you choose. Windows hosts are skipped with the reason windows. The tab Accounts on the SSH keys page lists the templates; each host's SSH tab lists the accounts that host reports.
Hosts need agent 3.3.5 or later and the action accounts in the actions list
of their configuration file, see Jobs. Distributing
keys to an existing account also needs ssh-keys. A host whose agent is older
does not report its accounts at all; the page says so ("agent too old") instead
of showing an empty list.
Templates
Only administrators create, change or delete a template. A template has:
| Setting | Meaning |
|---|---|
| Name | the login name: lower-case letters, digits, _ and -, up to 32 characters, starting with a letter or _ |
| Sudo | none (no sudo), password (sudo asks for the account's password) or nopasswd (sudo without a password). New templates default to nopasswd |
| Shell | the login shell of an account that is created; default /bin/bash. The shell of an existing account is never changed |
| Password | optional, and required for sudo password. Selvara stores only a SHA-512-crypt hash, computed when you save; the plain text is never kept or logged. Without a password the account has none and can only be reached with a key |
| Keys | the public keys that belong on the account: picked from the keys you can see or pasted |
| Key mode | add (default) makes sure at least these keys are present and leaves other keys alone; exact removes every other key from the account's authorized_keys |
| Linked user | optional. A Selvara account linked to the template; with all profile keys on, every public key stored in that person's profile counts as a key of the template |
A person linked to a template can set its password themselves under Profile > Security > Server accounts. Nobody can read a password back, and a template shows only whether one is set. The hash is part of the rollout job only until that job has ended; it is then removed from the job, and retrying the job uses the template's current password.
Under Administration > Users, Set up on servers… creates a template linked to the person with all of their profile keys and rolls it out; Remove from servers… preselects the hosts where the account exists. Disabling a person offers to lock their server account.
A key that belongs to a template counts as expected wherever it appears, like a key marked as an expected host key: rolling it out raises no "unknown key" event and does not count as a key without an owner.
Expecting an account
A template can be expected on hosts: choose Expect on... and pick the hosts the way you pick them for a script (customers, groups, single hosts). From then on every host the target reaches is checked against the template at each report. A host deviates when:
- the account is missing,
- the account is locked or expired,
- sudo is missing or differs (password versus no password),
- a key of the template is missing, or, in key mode
exact, a key is there that the template does not list.
The Deviations section on the Accounts tab lists them per host and account, and Fix deviations rolls the templates out again to exactly those hosts. Hosts that cannot be checked (Windows, no agent, agent too old) are not counted as deviating. The compliance check Expected accounts passes where every expectation on a host is met, fails on any deviation, and is unknown where nothing can be checked.
Rolling out
Roll out... on a template opens a dialog: choose the hosts, read the
preview, give a reason where the customer's policy asks for one, and send. The
preview shows per host what will happen or why the host is skipped: windows,
no agent, not managed, agent too old, not allowed (the host or customer
policy does not allow accounts or ssh-keys) or no permission. The dialog
then follows the jobs live, including approval where the customer requires a
second person. Nothing has to be started afterwards.
On the host the agent:
- creates the account with a home directory if it does not exist, with the password hash if the template has a password and otherwise without a password and not locked,
- takes over an account that already exists without changing its user id,
home or shell, except that it unlocks it and, only if the template has a
password, sets the password. It refuses names of system accounts (user id
below 1000, which includes
root), - writes the sudo rule to
/etc/sudoers.d/selvara-<name>after checking it withvisudo; ifvisudois missing or rejects the rule, the job fails and nothing is changed. For sudononeit removes that file, - adds the keys to
~/.ssh/authorized_keys(creating the directory and file with the right owner and mode), after copying the file next to itself asauthorized_keys.selvara-bak-<time>, and with key modeexactremoves all other keys. Rolling out twice changes nothing the second time.
An account that Selvara did not create is adopted this way, and it is shown as managed by Selvara afterwards.
Removing an account from hosts
Remove from hosts... has three modes, with the same preview, reason and live progress as rolling out:
| Mode | What happens |
|---|---|
| Lock (default) | the password is locked, the account is set to expired and its sudo rule is removed. The keys and the home directory stay, but nobody can log in |
| Keys only | the account's authorized_keys is emptied (after a backup copy); the account itself stays |
| Delete | the sudo rule is removed and the account is deleted. The home directory stays unless Delete home directory is ticked |
The agent refuses root, any account with a user id below 1000 and the account
the agent itself runs as. An account that does not exist counts as removed.
Remove the expectation first, or the next report shows the account as missing
again.
Distributing keys
Distribute keys... on a key (in the inventory or in a profile) puts it into
the authorized_keys of an existing account on the hosts you choose, in mode
add, with one preview and one batch like the others. The agent needs the full
public key line for this; keys that were reported by fingerprint only become
available once the host has reported again with agent 3.3.5.
Rolling out, removing and distributing need access.shell at the customer of
every host, the host settings described above, and the customer's reason and
second-person policies. Templates and expectations are changed by
administrators only.
What it records
| Action | Audit entry |
|---|---|
| Owner set or removed | ssh_key.assign_owner, ssh_key.clear_owner, with the fingerprint |
| Key stored in or removed from a profile | ssh_key.profile_add, ssh_key.profile_remove, on the account, with the fingerprints |
| Host key marked or unmarked | ssh_key.mark_system (with the reason and the scope), ssh_key.unmark_system |
| Removal requested | ssh_key.remove with the fingerprints, the number of hosts, the batch and the reason; then the usual job.submit, job.approve and job.finish entries per host |
| Restore requested | ssh_key.restore with the fingerprints, the number of hosts and files, the batch and the reason; then the usual job entries per host |
The database
| Table | Holds |
|---|---|
ssh_keys | one row per host, account and fingerprint: type, bits, comment, options, the public key, file, first_seen, last_seen |
ssh_key_owners | one row per fingerprint with its owner: an account (user_id) or a name (person_name) |
user_ssh_keys | the keys of an account's profile: fingerprint, type, bits, comment, the public key (empty where only the fingerprint is known), label, who added it and when; each has its ssh_key_owners row |
ssh_key_system_marks | one row per fingerprint marked as an expected host key: reason, scope (all, customer or systems), the customer or host ids, who and when |
ssh_key_state | one row per host: the hash of its last report, when it was collected, the SSH server settings, the privileged groups, the sudo rules, the unreadable files and the accounts (empty when the agent does not report them) |
server_accounts | one row per template: name, sudo mode, shell, the password hash (never the password), key mode, the linked user and whether all of their profile keys count |
server_account_keys | the keys of a template: fingerprint, public key, label, who added it and when |
server_account_expectations | the hosts a template is expected on, as a target like a script's |
The keys and the state go with the host when it is deleted; the owners and the marks belong to the fingerprint. A mark for one customer goes with the customer.
Limits
- Only what the agent can read is known. A key handed out by an
AuthorizedKeysCommand(LDAP, a vault) is not in any file; the setting is shown so you know it is in use. - A host reports its keys every 30 minutes, so a key added between two reports is noticed at the next one.
- The fingerprint is the identity. The same key line with different options or comments is one key.
- Certificate authorities are not inventoried here, only the keys in
authorized_keys.