Merge "Allow to specify root password when building guest image"

This commit is contained in:
Zuul 2020-08-12 23:08:52 +00:00 committed by Gerrit Code Review
commit a1275bbc43
3 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,5 @@
This element assigns a password to the root account in the image and enables
password login via ssh.
This is useful when booting outside of a cloud environment (e.g. manually via
kvm) and for testing.

View File

@ -0,0 +1,11 @@
#!/bin/bash
if [ -z "$DIB_PASSWORD" ]; then
echo "Error during setup password for root"
exit 1
fi
sed -i "s/disable_root: true/disable_root: false/" /etc/cloud/cloud.cfg
install-packages augeas-tools openssh-server openssh-client
augtool -s set /files/etc/ssh/sshd_config/PasswordAuthentication yes
augtool -s set /files/etc/ssh/sshd_config/PermitRootLogin yes
augtool -s set /files/etc/ssh/ssh_config/PasswordAuthentication yes
echo -e "$DIB_PASSWORD\n$DIB_PASSWORD\n" | passwd

View File

@ -13,6 +13,7 @@ function build_guest_image() {
local image_output=$5 local image_output=$5
local image_type=${image_output##*.} local image_type=${image_output##*.}
local working_dir=$(dirname ${image_output}) local working_dir=$(dirname ${image_output})
local root_password=${TROVE_ROOT_PASSWORD}
local elementes="base vm" local elementes="base vm"
local trove_elements_path=${PATH_TROVE}/integration/scripts/files/elements local trove_elements_path=${PATH_TROVE}/integration/scripts/files/elements
@ -60,6 +61,11 @@ function build_guest_image() {
elementes="$elementes guest-agent" elementes="$elementes guest-agent"
elementes="$elementes ${guest_os}-docker" elementes="$elementes ${guest_os}-docker"
if [[ -n ${root_password} ]]; then
elementes="$elementes root-passwd"
export DIB_PASSWORD=${root_password}
fi
# Build the image # Build the image
disk-image-create -x \ disk-image-create -x \
-a amd64 \ -a amd64 \