Field note / deployment trust
SSH host-key verification in CI deployments
Separate key discovery from key authentication before a deployment trusts a remote server.
Why ssh-keyscan is not a complete trust check
ssh-keyscan asks a remote endpoint for its public SSH host keys. It is useful for collecting a key, but collection over the same network path does not independently establish that the key belongs to the intended host.
A workflow that appends that result directly to ~/.ssh/known_hosts may accept whatever key was observed during bootstrap. Whether that produces an exploitable failure depends on network conditions, prior verification and other controls; a YAML line alone cannot establish a man-in-the-middle attack.
A more defensible bootstrap
- Obtain the expected SSH host public key or fingerprint through an authenticated, independent operator or provider channel.
- Keep that expected identity in a controlled configuration location rather than blindly trusting the value returned by the first deployment-time connection.
- Compare the received host key with the expected key or prepopulate a verified known_hosts entry; stop deployment if the identity differs.
- Protect the deploy credential separately and review the user/host mapping and whether deployment is restricted to trusted branches or environments.
A failure mode worth examining
mkdir -p ~/.ssh
# This discovers a key, but does not independently authenticate it:
ssh-keyscan -H "$HOST" >> ~/.ssh/known_hosts
# Better pattern: provision a reviewed, independently verified
# known_hosts entry through your controlled deployment configuration.Do not replace a real host fingerprint with a placeholder and treat it as a working deployment configuration. A valid approved key is environment-specific and needs a verifiable source.
Pinned source evidence
The historical LOLM daily workflow conditionally creates an SSH key file and executes ssh-keyscan, appending its output to known_hosts with a || true fallback.
The conditional branch matters: the snippet does not prove it ran on any particular deployment. The real review records the source line and asks whether a separately verified key was available.
Read the workflow's pinned source evidencePrimary reference
GitHub's SSH connection test guidance illustrates comparing observed host-key fingerprints with authenticated published fingerprints before accepting a host.