Import the node's host keys before every ssh, not only scp

A fresh VM's first vm_ssh can fail strict host-key checking, because only vm_scp imported the node's keys. This imports them before the first connect on every gcloud ssh path.

Closes the issue drafted beside this MR.

First contact

sequenceDiagram
    participant E as engine
    participant G as GCE
    participant V as fresh VM
    E->>G: create VM
    V->>G: guest agent publishes host keys
    E->>G: read instance id (once per process, then cached)
    E->>G: read published keys
    E->>E: pin keys as compute.id in known_hosts
    E->>V: first ssh, strict checking
    V-->>E: connected

Changes

  • vm_ssh, components_ssh and cmd_ssh in gce/simulation.sh, and vm_ssh, vm_scp and cmd_ssh in gce/openshift-local.sh, call prov_host_key_import before their first connect.
  • prov_host_key_import caches the instance id per process, so repeat calls make no API read.
  • prov_node_create, prov_node_delete, prov_nested_create and recreate_vm drop the cached id, so a recreated VM is read afresh.
  • The status read (components_ssh) imports with no wait and one id read, so a stopped node or a fresh known_hosts reads as unreadable at once instead of stalling.
  • Checking stays strict, and only keys GCE published are pinned. A node that publishes none is not connected to.

The raw ssh in gce/geo.sh and gce/praefect.sh keeps its own per-lab known_hosts and is unchanged.

Test

Twenty new checks in gce/engine-selftest.sh pass here. Fourteen fail on the code before the fix. Three more, covering the status read, fail on a first version that waited on a node publishing no key. The first group covers a fresh node's first ssh, repeat calls reading the id once, a recreated node importing anew, a node that publishes no key, an interactive ssh and a live status read. The full engine self-test and iap-selftest pass.

Live

One geo up on a pair, then geo verify and geo down. Neither member's log shows a host-key error or an ssh retry. Each member's first install pass ended in 255 and then recovered. That is the SELinux reboot the install expects, with the host key already pinned. The secondary's install, which died on 5d2f688d, completed.

Closes #64 (closed)

Merge request reports

Loading
Loading