sign ssh certificates on demand from ssh itself, warn before setup, say what to do when a host key changes
This commit is contained in:
parent
fc29fc89c0
commit
3d7541c0af
1 changed files with 521 additions and 67 deletions
|
|
@ -81,11 +81,16 @@ and attaches it to the agent's cert-auth role `hive-agent-<name>` as a second
|
|||
- the key is `/run/hive-agent-ssh-cert/key` (directory `0700`, files `0400`,
|
||||
`UMask=0377`), generated when absent; the certificate is
|
||||
`key-cert.pub` beside it;
|
||||
- each run logs in to the store with the cert identity `hive-agent-bao-identity`
|
||||
keeps, signs `key.pub` through the role, checks the answer parses as a
|
||||
certificate and renames it into place. A `403` from the signing call is the
|
||||
switch being off: the unit prints one line and exits 0, and the next tick asks
|
||||
again. Any other failure fails the unit, which retries;
|
||||
- the unit's script is also the **helper** `ssh` runs: one text, two entries. Each
|
||||
run logs in afresh to the store with the cert identity
|
||||
`hive-agent-bao-identity` keeps, signs `key.pub` through the role, checks the
|
||||
answer parses as a certificate and renames it into place. A `403` from the
|
||||
signing call is the switch being off: the unit prints one line and exits 0,
|
||||
and the next tick asks again. Any other failure fails the unit, which retries.
|
||||
One run at a time (`flock` on the directory), the unit's or an `ssh`'s;
|
||||
- the unit copies the store's CA out of its credentials into
|
||||
`server-ca.pem` beside the key, so that an `ssh` run, which has no
|
||||
credentials directory, can reach the store;
|
||||
- the timer fires 20 minutes after each run, a third of the 60-minute lifetime,
|
||||
from the same file as the role's TTL;
|
||||
- the system `/etc/ssh/ssh_config` has one `Host *` block: `IdentityFile` and
|
||||
|
|
@ -94,7 +99,16 @@ and attaches it to the agent's cert-auth role `hive-agent-<name>` as a second
|
|||
`UserKnownHostsFile /agents/<name>/state/ssh_known_hosts`. The host binds the
|
||||
state directory in, so the pins survive a restart; the container root
|
||||
doesn't. The agent trusts the first key a host shows and refuses a changed
|
||||
one.
|
||||
one;
|
||||
- the same config starts with `Match exec "HIVE_SSH_CERT_ENSURE=1 <helper> </dev/null"`,
|
||||
with no settings of its own. `ssh` runs the command while it reads the config,
|
||||
before it loads an identity. With `HIVE_SSH_CERT_ENSURE` the helper is silent and
|
||||
its exit status says whether a usable certificate exists: it exits 0 at once
|
||||
when the certificate has more than ten minutes left, asks the store nothing
|
||||
for ten seconds after a refusal, and otherwise logs in and signs. Nothing in
|
||||
the config depends on the answer; the point is the certificate it leaves
|
||||
behind. Every `ssh` on the agent runs this, so a loop of them while the switch
|
||||
is off costs one login per ten seconds.
|
||||
|
||||
## The target module
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue