git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #39654 from AmineChikhaoui/issue-38623

GCE: pull the ssh host keys from the metadata service as expected by NixOps.

commit41512bfdae18add49e185d01df9720bcf599ac0f authorRob Vermaas <rob.vermaas@gmail.com> dateThu 3 May 2018, 17:16 (9 years ago) parent773fe1ff514a68
1 file changed+13−1
nixos/modules/virtualisation/google-compute-image.nix+13−1
nixos/modules/virtualisation/google-compute-image.nix+13−1
@@ -221,7 +221,7 @@ in
221221 echo "Obtaining SSH keys..."
222222 mkdir -m 0700 -p /root/.ssh
223223 AUTH_KEYS=$(${mktemp})
224− ${wget} -O $AUTH_KEYS --header="Metadata-Flavor: Google" http://metadata.google.internal/computeMetadata/v1/instance/attributes/sshKeys
224+ ${wget} -O $AUTH_KEYS http://metadata.google.internal/computeMetadata/v1/instance/attributes/sshKeys
225225 if [ -s $AUTH_KEYS ]; then
226226
227227 # Read in key one by one, split in case Google decided
@@ -246,6 +246,18 @@ in
246246 false
247247 fi
248248 rm -f $AUTH_KEYS
249+ SSH_HOST_KEYS_DIR=$(${mktemp} -d)
250+ ${wget} -O $SSH_HOST_KEYS_DIR/ssh_host_ed25519_key http://metadata.google.internal/computeMetadata/v1/instance/attributes/ssh_host_ed25519_key
251+ ${wget} -O $SSH_HOST_KEYS_DIR/ssh_host_ed25519_key.pub http://metadata.google.internal/computeMetadata/v1/instance/attributes/ssh_host_ed25519_key_pub
252+ if [ -s $SSH_HOST_KEYS_DIR/ssh_host_ed25519_key -a -s $SSH_HOST_KEYS_DIR/ssh_host_ed25519_key.pub ]; then
253+ mv -f $SSH_HOST_KEYS_DIR/ssh_host_ed25519_key* /etc/ssh/
254+ chmod 600 /etc/ssh/ssh_host_ed25519_key
255+ chmod 644 /etc/ssh/ssh_host_ed25519_key.pub
256+ else
257+ echo "Setup of ssh host keys from http://metadata.google.internal/computeMetadata/v1/instance/attributes/ failed."
258+ false
259+ fi
260+ rm -f $SSH_HOST_KEYS_DIR
249261 '';
250262 serviceConfig.Type = "oneshot";
251263 serviceConfig.RemainAfterExit = true;