mirror of
https://github.com/Security-Onion-Solutions/securityonion.git
synced 2026-06-14 14:18:40 +02:00
Harden reinstall_init and add post-saltify readiness gate
- setup/so-functions: dump pre-reinstall salt state (systemctl / journalctl / ls /etc/salt / .rpmnew diff) to the setup log so a failed reinstall leaves a usable post-mortem; swap the manual rm -rf of /etc/salt/* for `dnf -y remove salt` so package configs get cleaned up properly. - setup/so-setup: replace the `sleep 2 / state.show_top / sleep 2` dance after saltify with a readiness gate that waits for /etc/salt/pki/master/master.pub, runs check_salt_master_status, and then wait_for_minion_key_pending before salt-key -ya. Fixes reinstalls on 3.x timing out on "Unable to sign_in to master". - salt/common/tools/sbin/so-common: add wait_for_minion_key_pending helper, polls `salt-key -l pre` until the minion appears.
This commit is contained in:
@@ -162,6 +162,29 @@ check_salt_master_status() {
|
||||
return 0
|
||||
}
|
||||
|
||||
# Wait until $minion shows up in the salt master's unaccepted-keys list.
|
||||
# Used after saltify on a reinstall to replace the old `sleep 2 / state.show_top /
|
||||
# sleep 2` dance — the new minion's key takes longer to appear than 2s on
|
||||
# salt 3006.x and the subsequent salt-key -ya needs something to accept.
|
||||
# Returns 0 as soon as the key is pending, 1 after attempts*delay seconds.
|
||||
wait_for_minion_key_pending() {
|
||||
local minion="$1"
|
||||
local attempts="${2:-30}"
|
||||
local delay="${3:-2}"
|
||||
local count=0
|
||||
while ! salt-key -l pre --out=json 2>/dev/null \
|
||||
| python3 -c "import json,sys; d=json.load(sys.stdin); sys.exit(0 if '$minion' in d.get('minions_pre', []) else 1)" 2>/dev/null; do
|
||||
((count+=1))
|
||||
if [[ $count -ge $attempts ]]; then
|
||||
echo "Gave up waiting for $minion to appear in salt-master's pending keys"
|
||||
return 1
|
||||
fi
|
||||
sleep "$delay"
|
||||
done
|
||||
echo "Minion $minion is pending acceptance after $((count * delay))s"
|
||||
return 0
|
||||
}
|
||||
|
||||
# this is only intended to be used to check the status of the minion from a salt master
|
||||
check_salt_minion_status() {
|
||||
local minion="$1"
|
||||
|
||||
Reference in New Issue
Block a user