From 81c4d879ebbe09a811c4e757b733a5e4b3bd476f Mon Sep 17 00:00:00 2001 From: m0duspwnens Date: Tue, 5 Jan 2021 10:26:19 -0500 Subject: [PATCH 1/8] first round of testing for automated testing ssh/scp --- setup/so-functions | 108 ++++++++++++++++++++++++++++++++++----------- setup/so-setup | 25 +++++++---- 2 files changed, 99 insertions(+), 34 deletions(-) diff --git a/setup/so-functions b/setup/so-functions index d0e502941..fa52b4adb 100755 --- a/setup/so-functions +++ b/setup/so-functions @@ -97,8 +97,6 @@ airgap_rules() { # Don't leave Strelka out cp -Rv /root/SecurityOnion/agrules/strelka /nsm/repo/rules/ - - } analyze_system() { @@ -112,17 +110,19 @@ analyze_system() { } accept_salt_key_remote() { + + local automated=$1 + local sshcmd=get_ssh_cmd $automated + systemctl restart salt-minion echo "Accept the key remotely on the manager" >> "$setup_log" 2>&1 # Delete the key just in case. - ssh -i /root/.ssh/so.key soremote@"$MSRV" sudo salt-key -d "$MINION_ID" -y + $sshcmd -i /root/.ssh/so.key soremote@"$MSRV" sudo salt-key -d "$MINION_ID" -y salt-call state.apply ca >> /dev/null 2>&1 - ssh -i /root/.ssh/so.key soremote@"$MSRV" sudo salt-key -a "$MINION_ID" -y - + $sshcmd -i /root/.ssh/so.key soremote@"$MSRV" sudo salt-key -a "$MINION_ID" -y } - add_admin_user() { # Add an admin user with full sudo rights if this is an ISO install. { @@ -558,7 +558,10 @@ check_requirements() { } compare_versions() { - manager_ver=$(ssh -i /root/.ssh/so.key soremote@"$MSRV" cat /etc/soversion) + local automated=$1 + local sshcmd=get_ssh_cmd $automated + + manager_ver=$("$sshcmd" -i /root/.ssh/so.key soremote@"$MSRV" cat /etc/soversion) if [[ $manager_ver == "" ]]; then rm /root/install_opt @@ -671,6 +674,11 @@ copy_salt_master_config() { } copy_minion_tmp_files() { + + local automated=$1 + local sshcmd=get_ssh_cmd $automated + local scpcmd=get_scp_cmd $automated + case "$install_type" in 'MANAGER' | 'EVAL' | 'HELIXSENSOR' | 'MANAGERSEARCH' | 'STANDALONE' | 'IMPORT') echo "Copying pillar and salt files in $temp_install_dir to $local_salt_dir" @@ -682,15 +690,15 @@ copy_minion_tmp_files() { *) { echo "scp pillar and salt files in $temp_install_dir to manager $local_salt_dir"; - ssh -i /root/.ssh/so.key soremote@"$MSRV" mkdir -p /tmp/"$MINION_ID"/pillar; - ssh -i /root/.ssh/so.key soremote@"$MSRV" mkdir -p /tmp/"$MINION_ID"/schedules; - scp -prv -i /root/.ssh/so.key "$temp_install_dir"/pillar/minions/* soremote@"$MSRV":/tmp/"$MINION_ID"/pillar/; + $sshcmd -i /root/.ssh/so.key soremote@"$MSRV" mkdir -p /tmp/"$MINION_ID"/pillar; + $sshcmd -i /root/.ssh/so.key soremote@"$MSRV" mkdir -p /tmp/"$MINION_ID"/schedules; + $scpcmd -prv -i /root/.ssh/so.key "$temp_install_dir"/pillar/minions/* soremote@"$MSRV":/tmp/"$MINION_ID"/pillar/; if [ -d $temp_install_dir/salt/patch/os/schedules/ ]; then if [ "$(ls -A $temp_install_dir/salt/patch/os/schedules/)" ]; then - scp -prv -i /root/.ssh/so.key $temp_install_dir/salt/patch/os/schedules/* soremote@$MSRV:/tmp/$MINION_ID/schedules; + $scpcmd -prv -i /root/.ssh/so.key $temp_install_dir/salt/patch/os/schedules/* soremote@$MSRV:/tmp/$MINION_ID/schedules; fi fi - ssh -i /root/.ssh/so.key soremote@"$MSRV" sudo $default_salt_dir/salt/manager/files/add_minion.sh "$MINION_ID"; + $sshcmd -i /root/.ssh/so.key soremote@"$MSRV" sudo $default_salt_dir/salt/manager/files/add_minion.sh "$MINION_ID"; } >> "$setup_log" 2>&1 ;; esac @@ -698,6 +706,9 @@ copy_minion_tmp_files() { copy_ssh_key() { + local automated=$1 + local sshcopyidcmd=get_ssh_copy_id_cmd $automated + echo "Generating SSH key" # Generate SSH key mkdir -p /root/.ssh @@ -709,7 +720,7 @@ copy_ssh_key() { echo "Copying the SSH key to the manager" #Copy the key over to the manager - ssh-copy-id -f -i /root/.ssh/so.key soremote@"$MSRV" + $sshcopyidcmd -f -i /root/.ssh/so.key soremote@"$MSRV" } create_local_directories() { @@ -974,11 +985,15 @@ docker_seed_registry() { } download_repo_tarball() { + local automated=$1 + local sshcmd=get_ssh_cmd $automated + local scpcmd=get_scp_cmd $automated + mkdir -p /root/manager_setup/securityonion { local manager_ver - manager_ver=$(ssh -i /root/.ssh/so.key soremote@"$MSRV" cat /etc/soversion) - scp -i /root/.ssh/so.key soremote@"$MSRV":/opt/so/repo/"$manager_ver".tar.gz /root/manager_setup + manager_ver=$("$sshcmd" -i /root/.ssh/so.key soremote@"$MSRV" cat /etc/soversion) + $scpcmd -i /root/.ssh/so.key soremote@"$MSRV":/opt/so/repo/"$manager_ver".tar.gz /root/manager_setup } >> "$setup_log" 2>&1 # Fail if the file doesn't download @@ -1082,6 +1097,42 @@ get_minion_type() { echo "$minion_type" } +get_scp_cmd() { + local automated=$1 + + if [ $automated == yes ]; then + local scpcmd='sshpass -p "PASSWORD" scp -o StrictHostKeyChecking=no' + else + local scpcmd='scp' + fi + + echo $scpcmd +} + +get_ssh_cmd() { + local automated=$1 + + if [ $automated == yes ]; then + local sshcmd='sshpass -p "PASSWORD" ssh -o StrictHostKeyChecking=no' + else + local sshcmd='ssh' + fi + + echo $sshcmd +} + +get_ssh_copy_id_cmd() { + local automated=$1 + + if [ $automated == yes ]; then + local sshcopyidcmd='sshpass -p "PASSWORD" ssh-copy-id -o StrictHostKeyChecking=no' + else + local sshcopyidcmd='ssh-copy-id' + fi + + echo $sshcopyidcmd +} + host_pillar() { local pillar_file="$temp_install_dir"/pillar/minions/"$MINION_ID".sls @@ -1629,6 +1680,9 @@ remove_package() { # - securityonion/salt/salt/minion.defaults.yaml saltify() { + local automated=$1 + local scpcmd=get_scp_cmd $automated + # Install updates and Salt if [ $OS = 'centos' ]; then set_progress_str 5 'Installing Salt repo' @@ -1774,7 +1828,7 @@ saltify() { # Copy down the gpg keys and install them from the manager mkdir "$temp_install_dir"/gpg >> "$setup_log" 2>&1 echo "scp the gpg keys and install them from the manager" >> "$setup_log" 2>&1 - scp -v -i /root/.ssh/so.key soremote@"$MSRV":/opt/so/gpg/* "$temp_install_dir"/gpg >> "$setup_log" 2>&1 + $scpcmd -v -i /root/.ssh/so.key soremote@"$MSRV":/opt/so/gpg/* "$temp_install_dir"/gpg >> "$setup_log" 2>&1 echo "Using apt-key add to add SALTSTACK-GPG-KEY.pub and GPG-KEY-WAZUH" >> "$setup_log" 2>&1 apt-key add "$temp_install_dir"/gpg/SALTSTACK-GPG-KEY.pub >> "$setup_log" 2>&1 apt-key add "$temp_install_dir"/gpg/GPG-KEY-WAZUH >> "$setup_log" 2>&1 @@ -2054,6 +2108,8 @@ set_hostname() { set_initial_firewall_policy() { set_main_ip + local automated=$1 + local sshcmd=get_ssh_cmd $automated if [ -f $default_salt_dir/pillar/data/addtotab.sh ]; then chmod +x $default_salt_dir/pillar/data/addtotab.sh; fi if [ -f $default_salt_dir/salt/common/tools/sbin/so-firewall ]; then chmod +x $default_salt_dir/salt/common/tools/sbin/so-firewall; fi @@ -2087,24 +2143,24 @@ set_initial_firewall_policy() { $default_salt_dir/salt/common/tools/sbin/so-firewall --apply includehost sensor "$MAINIP" ;; 'SENSOR' | 'SEARCHNODE' | 'HEAVYNODE' | 'FLEET') - ssh -i /root/.ssh/so.key soremote@"$MSRV" sudo $default_salt_dir/salt/common/tools/sbin/so-firewall includehost minion "$MAINIP" + $sshcmd -i /root/.ssh/so.key soremote@"$MSRV" sudo $default_salt_dir/salt/common/tools/sbin/so-firewall includehost minion "$MAINIP" case "$install_type" in 'SENSOR') - ssh -i /root/.ssh/so.key soremote@"$MSRV" sudo $default_salt_dir/salt/common/tools/sbin/so-firewall --apply includehost sensor "$MAINIP" - ssh -i /root/.ssh/so.key soremote@"$MSRV" sudo $default_salt_dir/pillar/data/addtotab.sh sensorstab "$MINION_ID" "$MAINIP" "$num_cpu_cores" "$random_uid" "$MNIC" "$filesystem_root" "$filesystem_nsm" "$INTERFACE" + $sshcmd -i /root/.ssh/so.key soremote@"$MSRV" sudo $default_salt_dir/salt/common/tools/sbin/so-firewall --apply includehost sensor "$MAINIP" + $sshcmd -i /root/.ssh/so.key soremote@"$MSRV" sudo $default_salt_dir/pillar/data/addtotab.sh sensorstab "$MINION_ID" "$MAINIP" "$num_cpu_cores" "$random_uid" "$MNIC" "$filesystem_root" "$filesystem_nsm" "$INTERFACE" ;; 'SEARCHNODE') - ssh -i /root/.ssh/so.key soremote@"$MSRV" sudo $default_salt_dir/salt/common/tools/sbin/so-firewall --apply includehost search_node "$MAINIP" - ssh -i /root/.ssh/so.key soremote@"$MSRV" sudo $default_salt_dir/pillar/data/addtotab.sh nodestab "$MINION_ID" "$MAINIP" "$num_cpu_cores" "$random_uid" "$MNIC" "$filesystem_root" "$filesystem_nsm" + $sshcmd -i /root/.ssh/so.key soremote@"$MSRV" sudo $default_salt_dir/salt/common/tools/sbin/so-firewall --apply includehost search_node "$MAINIP" + $sshcmd -i /root/.ssh/so.key soremote@"$MSRV" sudo $default_salt_dir/pillar/data/addtotab.sh nodestab "$MINION_ID" "$MAINIP" "$num_cpu_cores" "$random_uid" "$MNIC" "$filesystem_root" "$filesystem_nsm" ;; 'HEAVYNODE') - ssh -i /root/.ssh/so.key soremote@"$MSRV" sudo $default_salt_dir/salt/common/tools/sbin/so-firewall includehost sensor "$MAINIP" - ssh -i /root/.ssh/so.key soremote@"$MSRV" sudo $default_salt_dir/salt/common/tools/sbin/so-firewall --apply includehost heavy_node "$MAINIP" - ssh -i /root/.ssh/so.key soremote@"$MSRV" sudo $default_salt_dir/pillar/data/addtotab.sh sensorstab "$MINION_ID" "$MAINIP" "$num_cpu_cores" "$random_uid" "$MNIC" "$filesystem_root" "$filesystem_nsm" "$INTERFACE" - ssh -i /root/.ssh/so.key soremote@"$MSRV" sudo $default_salt_dir/pillar/data/addtotab.sh nodestab "$MINION_ID" "$MAINIP" "$num_cpu_cores" "$random_uid" "$MNIC" "$filesystem_root" "$filesystem_nsm" + $sshcmd -i /root/.ssh/so.key soremote@"$MSRV" sudo $default_salt_dir/salt/common/tools/sbin/so-firewall includehost sensor "$MAINIP" + $sshcmd -i /root/.ssh/so.key soremote@"$MSRV" sudo $default_salt_dir/salt/common/tools/sbin/so-firewall --apply includehost heavy_node "$MAINIP" + $sshcmd -i /root/.ssh/so.key soremote@"$MSRV" sudo $default_salt_dir/pillar/data/addtotab.sh sensorstab "$MINION_ID" "$MAINIP" "$num_cpu_cores" "$random_uid" "$MNIC" "$filesystem_root" "$filesystem_nsm" "$INTERFACE" + $sshcmd -i /root/.ssh/so.key soremote@"$MSRV" sudo $default_salt_dir/pillar/data/addtotab.sh nodestab "$MINION_ID" "$MAINIP" "$num_cpu_cores" "$random_uid" "$MNIC" "$filesystem_root" "$filesystem_nsm" ;; 'FLEET') - ssh -i /root/.ssh/so.key soremote@"$MSRV" sudo $default_salt_dir/salt/common/tools/sbin/so-firewall --apply includehost beats_endpoint_ssl "$MAINIP" + $sshcmd -i /root/.ssh/so.key soremote@"$MSRV" sudo $default_salt_dir/salt/common/tools/sbin/so-firewall --apply includehost beats_endpoint_ssl "$MAINIP" ;; esac ;; diff --git a/setup/so-setup b/setup/so-setup index bede7990d..f66b0a687 100755 --- a/setup/so-setup +++ b/setup/so-setup @@ -124,6 +124,15 @@ if [[ -f automation/$automation && $(basename $automation) == $automation ]]; th ip a | grep "$MNIC:" | grep "state UP" >> $setup_log 2>&1 done echo "Network is up on $MNIC" >> $setup_log 2>&1 + + if [[ ! $is_iso ]]; then + echo "Installing sshpass for automated testing." >> $setup_log 2>&1 + if [ "$OS" == ubuntu ]; then + yum -y install sshpass >> $setup_log 2>&1 + else + apt-get -y install sshpass >> $setup_log 2>&1 + fi + fi fi case "$setup_type" in @@ -287,10 +296,10 @@ if ! [[ -f $install_opt_file ]]; then fi if [[ $is_minion ]]; then - [ "$automated" == no ] && copy_ssh_key >> $setup_log 2>&1 + copy_ssh_key $automated >> $setup_log 2>&1 fi - if [[ $is_minion ]] && ! (compare_versions); then + if [[ $is_minion ]] && ! (compare_versions $automated); then info "Installer version mismatch, downloading correct version from manager" printf '%s\n' \ "install_type=$install_type" \ @@ -298,7 +307,7 @@ if ! [[ -f $install_opt_file ]]; then "HOSTNAME=$HOSTNAME" \ "MSRV=$MSRV" \ "MSRVIP=$MSRVIP" > "$install_opt_file" - download_repo_tarball + download_repo_tarball $automated exec bash /root/manager_setup/securityonion/setup/so-setup "${original_args[@]}" fi @@ -553,7 +562,7 @@ set_redirect >> $setup_log 2>&1 if [[ $is_minion ]]; then set_progress_str 1 'Configuring firewall' - set_initial_firewall_policy >> $setup_log 2>&1 + set_initial_firewall_policy $automated >> $setup_log 2>&1 fi set_progress_str 2 'Updating packages' @@ -573,7 +582,7 @@ set_redirect >> $setup_log 2>&1 fi set_progress_str 5 'Installing Salt and dependencies' - saltify 2>> $setup_log + saltify $automated 2>> $setup_log set_progress_str 6 'Installing Docker and dependencies' docker_install >> $setup_log 2>&1 @@ -626,7 +635,7 @@ set_redirect >> $setup_log 2>&1 if [[ $is_minion ]]; then set_progress_str 20 'Accepting Salt key on manager' - accept_salt_key_remote >> $setup_log 2>&1 + accept_salt_key_remote $automated >> $setup_log 2>&1 fi if [[ $is_manager || $is_import || $is_helix ]]; then @@ -635,7 +644,7 @@ set_redirect >> $setup_log 2>&1 fi set_progress_str 21 'Copying minion pillars to manager' - copy_minion_tmp_files >> $setup_log 2>&1 + copy_minion_tmp_files $automated >> $setup_log 2>&1 if [[ $is_minion ]]; then set_progress_str 22 'Checking if the Salt Minion needs to be updated' @@ -647,7 +656,7 @@ set_redirect >> $setup_log 2>&1 if [[ $is_manager || $is_helix || $is_import ]]; then set_progress_str 25 'Configuring firewall' - set_initial_firewall_policy >> $setup_log 2>&1 + set_initial_firewall_policy $automated >> $setup_log 2>&1 # create these so the registry state can add so-registry to /opt/so/conf/so-status/so-status.conf mkdir -p /opt/so/conf/so-status/ >> $setup_log 2>&1 From c93dfa7b33980b56538fa4cf993912b52d54efef Mon Sep 17 00:00:00 2001 From: m0duspwnens Date: Tue, 5 Jan 2021 11:47:22 -0500 Subject: [PATCH 2/8] hardcode automation pw --- setup/so-functions | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/setup/so-functions b/setup/so-functions index fa52b4adb..fc5f79bda 100755 --- a/setup/so-functions +++ b/setup/so-functions @@ -1101,7 +1101,7 @@ get_scp_cmd() { local automated=$1 if [ $automated == yes ]; then - local scpcmd='sshpass -p "PASSWORD" scp -o StrictHostKeyChecking=no' + local scpcmd='sshpass -p "automation" scp -o StrictHostKeyChecking=no' else local scpcmd='scp' fi @@ -1113,7 +1113,7 @@ get_ssh_cmd() { local automated=$1 if [ $automated == yes ]; then - local sshcmd='sshpass -p "PASSWORD" ssh -o StrictHostKeyChecking=no' + local sshcmd='sshpass -p "automation" ssh -o StrictHostKeyChecking=no' else local sshcmd='ssh' fi @@ -1125,7 +1125,7 @@ get_ssh_copy_id_cmd() { local automated=$1 if [ $automated == yes ]; then - local sshcopyidcmd='sshpass -p "PASSWORD" ssh-copy-id -o StrictHostKeyChecking=no' + local sshcopyidcmd='sshpass -p "automation" ssh-copy-id -o StrictHostKeyChecking=no' else local sshcopyidcmd='ssh-copy-id' fi From 0f9bf9deb643be9e5291e45b8680d5e2f06c737c Mon Sep 17 00:00:00 2001 From: m0duspwnens Date: Tue, 5 Jan 2021 13:49:51 -0500 Subject: [PATCH 3/8] make sshcmd, scpcmd, ssh_copy_id_cmd global to so-functions; --- setup/so-functions | 39 ++++++--------------------------------- setup/so-setup | 17 ++++++++++------- 2 files changed, 16 insertions(+), 40 deletions(-) diff --git a/setup/so-functions b/setup/so-functions index fc5f79bda..8d12156ae 100755 --- a/setup/so-functions +++ b/setup/so-functions @@ -110,10 +110,6 @@ analyze_system() { } accept_salt_key_remote() { - - local automated=$1 - local sshcmd=get_ssh_cmd $automated - systemctl restart salt-minion echo "Accept the key remotely on the manager" >> "$setup_log" 2>&1 @@ -558,9 +554,6 @@ check_requirements() { } compare_versions() { - local automated=$1 - local sshcmd=get_ssh_cmd $automated - manager_ver=$("$sshcmd" -i /root/.ssh/so.key soremote@"$MSRV" cat /etc/soversion) if [[ $manager_ver == "" ]]; then @@ -675,10 +668,6 @@ copy_salt_master_config() { copy_minion_tmp_files() { - local automated=$1 - local sshcmd=get_ssh_cmd $automated - local scpcmd=get_scp_cmd $automated - case "$install_type" in 'MANAGER' | 'EVAL' | 'HELIXSENSOR' | 'MANAGERSEARCH' | 'STANDALONE' | 'IMPORT') echo "Copying pillar and salt files in $temp_install_dir to $local_salt_dir" @@ -706,9 +695,6 @@ copy_minion_tmp_files() { copy_ssh_key() { - local automated=$1 - local sshcopyidcmd=get_ssh_copy_id_cmd $automated - echo "Generating SSH key" # Generate SSH key mkdir -p /root/.ssh @@ -985,9 +971,6 @@ docker_seed_registry() { } download_repo_tarball() { - local automated=$1 - local sshcmd=get_ssh_cmd $automated - local scpcmd=get_scp_cmd $automated mkdir -p /root/manager_setup/securityonion { @@ -1101,36 +1084,31 @@ get_scp_cmd() { local automated=$1 if [ $automated == yes ]; then - local scpcmd='sshpass -p "automation" scp -o StrictHostKeyChecking=no' + scpcmd='sshpass -p "automation" scp -o StrictHostKeyChecking=no' else - local scpcmd='scp' + scpcmd='scp' fi - - echo $scpcmd } get_ssh_cmd() { local automated=$1 if [ $automated == yes ]; then - local sshcmd='sshpass -p "automation" ssh -o StrictHostKeyChecking=no' + sshcmd='sshpass -p "automation" ssh -o StrictHostKeyChecking=no' else - local sshcmd='ssh' + sshcmd='ssh' fi - echo $sshcmd } get_ssh_copy_id_cmd() { local automated=$1 if [ $automated == yes ]; then - local sshcopyidcmd='sshpass -p "automation" ssh-copy-id -o StrictHostKeyChecking=no' + sshcopyidcmd='sshpass -p "automation" ssh-copy-id -o StrictHostKeyChecking=no' else - local sshcopyidcmd='ssh-copy-id' + sshcopyidcmd='ssh-copy-id' fi - - echo $sshcopyidcmd } host_pillar() { @@ -1680,9 +1658,6 @@ remove_package() { # - securityonion/salt/salt/minion.defaults.yaml saltify() { - local automated=$1 - local scpcmd=get_scp_cmd $automated - # Install updates and Salt if [ $OS = 'centos' ]; then set_progress_str 5 'Installing Salt repo' @@ -2108,8 +2083,6 @@ set_hostname() { set_initial_firewall_policy() { set_main_ip - local automated=$1 - local sshcmd=get_ssh_cmd $automated if [ -f $default_salt_dir/pillar/data/addtotab.sh ]; then chmod +x $default_salt_dir/pillar/data/addtotab.sh; fi if [ -f $default_salt_dir/salt/common/tools/sbin/so-firewall ]; then chmod +x $default_salt_dir/salt/common/tools/sbin/so-firewall; fi diff --git a/setup/so-setup b/setup/so-setup index f66b0a687..020882347 100755 --- a/setup/so-setup +++ b/setup/so-setup @@ -108,6 +108,9 @@ if [[ -f automation/$automation && $(basename $automation) == $automation ]]; th echo "Preselecting variable values based on automated setup: $automation" >> $setup_log 2>&1 source automation/$automation automated=yes + get_scp_cmd $automated + get_ssh_cmd $automated + get_ssh_copy_id_cmd $automated attempt=1 attempts=60 @@ -296,7 +299,7 @@ if ! [[ -f $install_opt_file ]]; then fi if [[ $is_minion ]]; then - copy_ssh_key $automated >> $setup_log 2>&1 + copy_ssh_key >> $setup_log 2>&1 fi if [[ $is_minion ]] && ! (compare_versions $automated); then @@ -307,7 +310,7 @@ if ! [[ -f $install_opt_file ]]; then "HOSTNAME=$HOSTNAME" \ "MSRV=$MSRV" \ "MSRVIP=$MSRVIP" > "$install_opt_file" - download_repo_tarball $automated + download_repo_tarball exec bash /root/manager_setup/securityonion/setup/so-setup "${original_args[@]}" fi @@ -562,7 +565,7 @@ set_redirect >> $setup_log 2>&1 if [[ $is_minion ]]; then set_progress_str 1 'Configuring firewall' - set_initial_firewall_policy $automated >> $setup_log 2>&1 + set_initial_firewall_policy >> $setup_log 2>&1 fi set_progress_str 2 'Updating packages' @@ -582,7 +585,7 @@ set_redirect >> $setup_log 2>&1 fi set_progress_str 5 'Installing Salt and dependencies' - saltify $automated 2>> $setup_log + saltify 2>> $setup_log set_progress_str 6 'Installing Docker and dependencies' docker_install >> $setup_log 2>&1 @@ -635,7 +638,7 @@ set_redirect >> $setup_log 2>&1 if [[ $is_minion ]]; then set_progress_str 20 'Accepting Salt key on manager' - accept_salt_key_remote $automated >> $setup_log 2>&1 + accept_salt_key_remote >> $setup_log 2>&1 fi if [[ $is_manager || $is_import || $is_helix ]]; then @@ -644,7 +647,7 @@ set_redirect >> $setup_log 2>&1 fi set_progress_str 21 'Copying minion pillars to manager' - copy_minion_tmp_files $automated >> $setup_log 2>&1 + copy_minion_tmp_files >> $setup_log 2>&1 if [[ $is_minion ]]; then set_progress_str 22 'Checking if the Salt Minion needs to be updated' @@ -656,7 +659,7 @@ set_redirect >> $setup_log 2>&1 if [[ $is_manager || $is_helix || $is_import ]]; then set_progress_str 25 'Configuring firewall' - set_initial_firewall_policy $automated >> $setup_log 2>&1 + set_initial_firewall_policy >> $setup_log 2>&1 # create these so the registry state can add so-registry to /opt/so/conf/so-status/so-status.conf mkdir -p /opt/so/conf/so-status/ >> $setup_log 2>&1 From 749b21e6843877a7a0b73eb1fa07cfbc0dcc02b0 Mon Sep 17 00:00:00 2001 From: m0duspwnens Date: Tue, 5 Jan 2021 14:12:43 -0500 Subject: [PATCH 4/8] make sure ssh commands get set whether automated install or not --- setup/so-setup | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/setup/so-setup b/setup/so-setup index 020882347..3804b1e96 100755 --- a/setup/so-setup +++ b/setup/so-setup @@ -108,9 +108,6 @@ if [[ -f automation/$automation && $(basename $automation) == $automation ]]; th echo "Preselecting variable values based on automated setup: $automation" >> $setup_log 2>&1 source automation/$automation automated=yes - get_scp_cmd $automated - get_ssh_cmd $automated - get_ssh_copy_id_cmd $automated attempt=1 attempts=60 @@ -148,6 +145,11 @@ case "$setup_type" in ;; esac +#set ssh command thats will be used based on if this is an automated test install or not +get_scp_cmd $automated +get_ssh_cmd $automated +get_ssh_copy_id_cmd $automated + # Allow execution of SO tools during setup local_sbin="$(pwd)/../salt/common/tools/sbin" export PATH=$PATH:$local_sbin From 91ad7f26bfe5df04a887fc4ed92f021a1c229ff8 Mon Sep 17 00:00:00 2001 From: m0duspwnens Date: Wed, 6 Jan 2021 08:45:33 -0500 Subject: [PATCH 5/8] no longer need to pass $automated to compare_versions --- setup/so-setup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/so-setup b/setup/so-setup index 3804b1e96..3ea6fe570 100755 --- a/setup/so-setup +++ b/setup/so-setup @@ -304,7 +304,7 @@ if ! [[ -f $install_opt_file ]]; then copy_ssh_key >> $setup_log 2>&1 fi - if [[ $is_minion ]] && ! (compare_versions $automated); then + if [[ $is_minion ]] && ! (compare_versions); then info "Installer version mismatch, downloading correct version from manager" printf '%s\n' \ "install_type=$install_type" \ From aecc0c025eca68689acce0c86059aab12ab40480 Mon Sep 17 00:00:00 2001 From: m0duspwnens Date: Wed, 6 Jan 2021 08:49:08 -0500 Subject: [PATCH 6/8] fix comment --- setup/so-setup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/so-setup b/setup/so-setup index 3ea6fe570..4c5760856 100755 --- a/setup/so-setup +++ b/setup/so-setup @@ -145,7 +145,7 @@ case "$setup_type" in ;; esac -#set ssh command thats will be used based on if this is an automated test install or not +#set ssh commands that will be used based on if this is an automated test install or not get_scp_cmd $automated get_ssh_cmd $automated get_ssh_copy_id_cmd $automated From 94fd79cd289a617346f799489a83cba603a35067 Mon Sep 17 00:00:00 2001 From: m0duspwnens Date: Wed, 6 Jan 2021 08:51:33 -0500 Subject: [PATCH 7/8] originally had sshpass package install reveresed, fixed it here --- setup/so-setup | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup/so-setup b/setup/so-setup index 4c5760856..7ab87a23a 100755 --- a/setup/so-setup +++ b/setup/so-setup @@ -128,9 +128,9 @@ if [[ -f automation/$automation && $(basename $automation) == $automation ]]; th if [[ ! $is_iso ]]; then echo "Installing sshpass for automated testing." >> $setup_log 2>&1 if [ "$OS" == ubuntu ]; then - yum -y install sshpass >> $setup_log 2>&1 - else apt-get -y install sshpass >> $setup_log 2>&1 + else + yum -y install sshpass >> $setup_log 2>&1 fi fi fi From 48f81d9ac6640e77dddecd2d116953ad7da1957b Mon Sep 17 00:00:00 2001 From: m0duspwnens Date: Wed, 6 Jan 2021 08:58:33 -0500 Subject: [PATCH 8/8] reduce setting ssh commands down to 1 function and 1 function call --- setup/so-functions | 45 ++++++++++++++------------------------------- setup/so-setup | 4 +--- 2 files changed, 15 insertions(+), 34 deletions(-) diff --git a/setup/so-functions b/setup/so-functions index 8d12156ae..52c8b19c9 100755 --- a/setup/so-functions +++ b/setup/so-functions @@ -1080,37 +1080,6 @@ get_minion_type() { echo "$minion_type" } -get_scp_cmd() { - local automated=$1 - - if [ $automated == yes ]; then - scpcmd='sshpass -p "automation" scp -o StrictHostKeyChecking=no' - else - scpcmd='scp' - fi -} - -get_ssh_cmd() { - local automated=$1 - - if [ $automated == yes ]; then - sshcmd='sshpass -p "automation" ssh -o StrictHostKeyChecking=no' - else - sshcmd='ssh' - fi - -} - -get_ssh_copy_id_cmd() { - local automated=$1 - - if [ $automated == yes ]; then - sshcopyidcmd='sshpass -p "automation" ssh-copy-id -o StrictHostKeyChecking=no' - else - sshcopyidcmd='ssh-copy-id' - fi -} - host_pillar() { local pillar_file="$temp_install_dir"/pillar/minions/"$MINION_ID".sls @@ -2005,6 +1974,20 @@ set_progress_str() { "----" >> "$setup_log" 2>&1 } +set_ssh_cmds() { + local automated=$1 + + if [ $automated == yes ]; then + sshcmd='sshpass -p "automation" ssh -o StrictHostKeyChecking=no' + sshcopyidcmd='sshpass -p "automation" ssh-copy-id -o StrictHostKeyChecking=no' + scpcmd='sshpass -p "automation" scp -o StrictHostKeyChecking=no' + else + sshcmd='ssh' + sshcopyidcmd='ssh-copy-id' + scpcmd='scp' + fi +} + sensor_pillar() { local pillar_file=$temp_install_dir/pillar/minions/$MINION_ID.sls diff --git a/setup/so-setup b/setup/so-setup index 7ab87a23a..991273b65 100755 --- a/setup/so-setup +++ b/setup/so-setup @@ -146,9 +146,7 @@ case "$setup_type" in esac #set ssh commands that will be used based on if this is an automated test install or not -get_scp_cmd $automated -get_ssh_cmd $automated -get_ssh_copy_id_cmd $automated +set_ssh_cmds $automated # Allow execution of SO tools during setup local_sbin="$(pwd)/../salt/common/tools/sbin"