Browse Source

Add ssh public key to Fuel master node

This commit adds an ability to use ssh public key authentication for
the Fuel master node by uploading your ssh public key to it. The path
to the public key file can be provided in the 'config.sh' file.

Closes-Bug: #1579123
Change-Id: I93560126940457518fc4385c0518ab00c0cac01a
Vasiliy Pleshakov 3 years ago
parent
commit
904eec20f8
3 changed files with 37 additions and 0 deletions
  1. 6
    0
      actions/master-node-create-and-install.sh
  2. 3
    0
      config.sh
  3. 28
    0
      functions/product.sh

+ 6
- 0
actions/master-node-create-and-install.sh View File

@@ -69,6 +69,12 @@ enable_outbound_network_for_product_vm $vm_master_ip $vm_master_username $vm_mas
69 69
 # Wait until the machine gets installed and Puppet completes its run
70 70
 wait_for_product_vm_to_install $vm_master_ip $vm_master_username $vm_master_password "$vm_master_prompt"
71 71
 
72
+#Add public key to authorized_keys
73
+if [ -e "${public_key_file}" ]; then
74
+  public_key=$(cat "${public_key_file}")
75
+  update_authorized_key $vm_master_ip $vm_master_username $vm_master_password "$vm_master_prompt" "$public_key"
76
+fi
77
+
72 78
 # Report success
73 79
 echo
74 80
 echo "Master node has been installed."

+ 3
- 0
config.sh View File

@@ -190,3 +190,6 @@ skipfuelmenu="yes"
190 190
 
191 191
 # default cmdline parameters passed to the kernel when boot the Fuel Master node
192 192
 cmdline="initrd=initrd.img net.ifnames=0 biosdevname=0 ks=hd:sr0:/ks.cfg ip=10.20.0.2::10.20.0.1:255.255.255.0:fuel.domain.tld:eth0:off::: dns1=10.20.0.1"
193
+
194
+# If necessary uncomment and edit line below to add your public ssh key to the master node
195
+#public_key_file="${HOME}/.ssh/id_rsa.pub"

+ 28
- 0
functions/product.sh View File

@@ -300,3 +300,31 @@ print_no_internet_connectivity_banner() {
300 300
     echo "#          because there is no Internet connectivity       #"
301 301
     echo "############################################################"
302 302
 }
303
+
304
+update_authorized_key() {
305
+    local ip=$1
306
+    local username=$2
307
+    local password=$3
308
+    local prompt=$4
309
+    local key=$5
310
+
311
+    echo -n "Adding public ssh key for '${username}' on '${ip}' node... "
312
+
313
+    result=$(
314
+        execute expect << ENDOFEXPECT
315
+        spawn ssh $ssh_options $username@$ip
316
+        expect "connect to host" exit
317
+        expect "*?assword:*"
318
+        send "$password\r"
319
+        expect "$prompt"
320
+        send "mkdir -p -m 0700 ~/.ssh\r"
321
+        expect "$prompt"
322
+        send "echo \"$key\" >>~/.ssh/authorized_keys\r"
323
+        expect "$prompt"
324
+        send "logout\r"
325
+        expect "$prompt"
326
+ENDOFEXPECT
327
+    )
328
+    echo "OK"
329
+    return 0
330
+}

Loading…
Cancel
Save