diff --git a/xCAT-genesis-base/dracut_105/el/module-setup.sh b/xCAT-genesis-base/dracut_105/el/module-setup.sh index 131dadb344..5c113a41f6 100755 --- a/xCAT-genesis-base/dracut_105/el/module-setup.sh +++ b/xCAT-genesis-base/dracut_105/el/module-setup.sh @@ -40,10 +40,25 @@ _dracut_install_opt() { fi } +# openssl req reads the config file at OPENSSLDIR/openssl.cnf and exits 1 without it, so the +# node makes no certificate request. dracut_install copies the program and its libraries only. +# OPENSSLDIR is /usr/lib/ssl on Ubuntu and /etc/pki/tls on EL, so ask openssl where it looks. +_dracut_install_openssl_config() { + local dir cnf + dir=$(openssl version -d 2>/dev/null | sed -e 's/^OPENSSLDIR: *"*//' -e 's/"*$//') + cnf="${dir:-/etc/ssl}/openssl.cnf" + if [ ! -e "$cnf" ]; then + dfatal "xcat: no openssl config at $cnf; Genesis cannot request a certificate" + exit 1 + fi + dracut_install "$cnf" +} + install() { local genesis_openeuler=0 timezone timezone_files locale_file locale_files [[ -f /etc/openEuler-release ]] && genesis_openeuler=1 dracut_install wget openssl tar mstflint ipmitool cpio gzip lsmod ethtool modprobe touch echo cut wc bash + _dracut_install_openssl_config dracut_install netstat # broadcom update requires dracut_install uniq # mellanox update requires dracut_install grep ip hostname /usr/bin/awk egrep grep dirname expr diff --git a/xCAT-genesis-base/dracut_105/ubuntu/module-setup.sh b/xCAT-genesis-base/dracut_105/ubuntu/module-setup.sh index 367439ce4f..325807bcd3 100755 --- a/xCAT-genesis-base/dracut_105/ubuntu/module-setup.sh +++ b/xCAT-genesis-base/dracut_105/ubuntu/module-setup.sh @@ -40,12 +40,27 @@ _dracut_install_opt() { fi } +# openssl req reads the config file at OPENSSLDIR/openssl.cnf and exits 1 without it, so the +# node makes no certificate request. dracut_install copies the program and its libraries only. +# OPENSSLDIR is /usr/lib/ssl on Ubuntu and /etc/pki/tls on EL, so ask openssl where it looks. +_dracut_install_openssl_config() { + local dir cnf + dir=$(openssl version -d 2>/dev/null | sed -e 's/^OPENSSLDIR: *"*//' -e 's/"*$//') + cnf="${dir:-/etc/ssl}/openssl.cnf" + if [ ! -e "$cnf" ]; then + dfatal "xcat: no openssl config at $cnf; Genesis cannot request a certificate" + exit 1 + fi + dracut_install "$cnf" +} + install() { # Ubuntu multiarch triplet for architecture-specific library paths local TRIPLET TRIPLET=$(dpkg-architecture -qDEB_HOST_MULTIARCH 2>/dev/null || echo x86_64-linux-gnu) dracut_install wget openssl tar ipmitool cpio gzip lsmod ethtool modprobe touch echo cut wc bash + _dracut_install_openssl_config _dracut_install_opt mstflint dracut_install netstat # broadcom update requires dracut_install uniq # mellanox update requires diff --git a/xCAT-genesis-scripts/usr/bin/getcert b/xCAT-genesis-scripts/usr/bin/getcert index 7bad27285e..fd71c7694c 100755 --- a/xCAT-genesis-scripts/usr/bin/getcert +++ b/xCAT-genesis-scripts/usr/bin/getcert @@ -21,9 +21,15 @@ fi # requests fail. An emulated node needs minutes for that key. CSR_TIMEOUT=${GETCERT_CSR_TIMEOUT:-600} CSR_DEADLINE=$((SECONDS + CSR_TIMEOUT)) -while ! openssl req -new -key /etc/xcat/certkey.pem -out /tmp/tls.csr -subj "/CN=$(hostname)" >& /dev/null; do +CSR_ERROR=/tmp/getcert.csr.err +while ! openssl req -new -key /etc/xcat/certkey.pem -out /tmp/tls.csr -subj "/CN=$(hostname)" > /dev/null 2> $CSR_ERROR; do if [ "$SECONDS" -ge "$CSR_DEADLINE" ]; then - give_up "no certificate request after ${CSR_TIMEOUT}s; /etc/xcat/certkey.pem is not usable" + # Name the key that was used AND what openssl printed: the key is usually intact and + # the absent file is OPENSSLDIR/openssl.cnf. + # Read and flatten with bash builtins. The Genesis payload is a minimal initramfs + # and need not carry tr or cat. + csr_error=$(< $CSR_ERROR) + give_up "no certificate request after ${CSR_TIMEOUT}s using /etc/xcat/certkey.pem: ${csr_error//$'\n'/ }" fi sleep 1 done