From 4c2a0dc531ca1078cf972b16f3c3374c73550368 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 6 Apr 2011 15:53:03 +0000 Subject: [PATCH] * Add multipath-tools (specifically, kpartx) to nova-compute's $PATH so that it can inject SSH keys into disk images. * Use the injected key if available. svn path=/nixos/trunk/; revision=26724 --- modules/virtualisation/ec2-data.nix | 26 +++++++++++++++----------- modules/virtualisation/nova.nix | 2 +- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/modules/virtualisation/ec2-data.nix b/modules/virtualisation/ec2-data.nix index cd1e3da69bde..7a8c957af095 100644 --- a/modules/virtualisation/ec2-data.nix +++ b/modules/virtualisation/ec2-data.nix @@ -18,18 +18,22 @@ echo "setting host name..." ${pkgs.nettools}/bin/hostname $(${pkgs.curl}/bin/curl http://169.254.169.254/1.0/meta-data/hostname) - echo "obtaining SSH key..." - mkdir -p /root/.ssh - ${pkgs.curl}/bin/curl --retry 3 --retry-delay 0 --fail \ - -o /root/key.pub \ - http://169.254.169.254/1.0/meta-data/public-keys/0/openssh-key - if [ $? -eq 0 -a -e /root/key.pub ]; then - if ! grep -q -f /root/key.pub /root/.ssh/authorized_keys; then - cat /root/key.pub >> /root/.ssh/authorized_keys - echo "new key added to authorized_keys" + # Don't download the SSH key if it has already been injected + # into the image (a Nova feature). + if ! [ -e /root/.ssh/authorized_keys ]; then + echo "obtaining SSH key..." + mkdir -p /root/.ssh + ${pkgs.curl}/bin/curl --retry 3 --retry-delay 0 --fail \ + -o /root/key.pub \ + http://169.254.169.254/1.0/meta-data/public-keys/0/openssh-key + if [ $? -eq 0 -a -e /root/key.pub ]; then + if ! grep -q -f /root/key.pub /root/.ssh/authorized_keys; then + cat /root/key.pub >> /root/.ssh/authorized_keys + echo "new key added to authorized_keys" + fi + chmod 600 /root/.ssh/authorized_keys + rm -f /root/key.pub fi - chmod 600 /root/.ssh/authorized_keys - rm -f /root/key.pub fi # Print the host public key on the console so that the user diff --git a/modules/virtualisation/nova.nix b/modules/virtualisation/nova.nix index 033885c2f906..a838f7f63d47 100644 --- a/modules/virtualisation/nova.nix +++ b/modules/virtualisation/nova.nix @@ -104,7 +104,7 @@ in path = [ pkgs.sudo pkgs.vlan pkgs.nettools pkgs.iptables pkgs.qemu_kvm - pkgs.e2fsprogs pkgs.utillinux + pkgs.e2fsprogs pkgs.utillinux pkgs.multipath_tools ]; exec = "${nova}/bin/nova-compute --nodaemon --verbose";