API: add a function that generates a pair of ssh keys and push them on remote hosts
This is common practice when inter-nodes ssh communication is required.
populate_keys(roles: Roles, local_dir: Path) -> Tuple[Path]:
"""Generate and push a new pair of keys to all hosts.
Idempotency:
- a new pair of keys is generated/published every time you call this function (* as a first step)
- the remote key are named with a name that doesn't conflict with any of the common key names (we don't want to overwrite any existing keys).
- the public key is appended to the `authorized_keys` of root user
Args:
roles: The roles on which this should be applied
local_dir: The local destination folder where the keys will be generated
Returns:
The path to the key files as a Tuple (private, public)
"""
Note that in some cases inter-node ssh access might be already possible. For instance on Grid'5000, as a non-root user, the nodes mount the user home dir (en thus the .ssh folder is shared accross the nodes)
Extra stuffs:
- ssh keys can be maybe be generated using the
cryptography
library (https://cryptography.io/en/latest/hazmat/primitives/asymmetric/rsa.html#generation)