Selaa lähdekoodia

better protection against accidentally removing auth keys file

tags/v1.1.4
Jonathan Cobb 4 vuotta sitten
vanhempi
commit
4d39f1a180
1 muutettua tiedostoa jossa 7 lisäystä ja 1 poistoa
  1. +7
    -1
      bubble-server/src/main/resources/packer/roles/bubble/files/refresh_bubble_ssh_keys.sh

+ 7
- 1
bubble-server/src/main/resources/packer/roles/bubble/files/refresh_bubble_ssh_keys.sh Näytä tiedosto

@@ -28,6 +28,7 @@ NEW_KEYS=$(mktemp /root/.ssh/authorized_keys.XXXXXXX)
chmod 600 ${NEW_KEYS} || die "Error setting permissions on new authorized_keys file: ${NEW_KEYS}"

KEY_COUNT=0
ALL_KEY_COUNT=0
for key in $(echo "${CURRENT_KEYS_SQL}" | PGPASSWORD="$(cat /home/bubble/.BUBBLE_PG_PASSWORD)" psql -U bubble -h 127.0.0.1 bubble -qt) ; do
if [[ -z "$(echo "${key}" | tr -d [[:space:]])" ]] ; then
continue
@@ -40,14 +41,19 @@ for key in $(echo "${CURRENT_KEYS_SQL}" | PGPASSWORD="$(cat /home/bubble/.BUBBLE
else
log "Warning: NOT adding malformed key: $(echo "${KEY}" | tr -d '\n')"
fi
ALL_KEY_COUNT=$(expr ${ALL_KEY_COUNT} + 1)
done

if [[ ${KEY_COUNT} -eq 0 ]] ; then
# Sanity check that we can even talk to psql
# We may be out of memory, in which case we do not want to erase existing installed keys
if [[ -z "$(echo 'SELECT count(*) FROM account_ssh_key' | PGPASSWORD="$(cat /home/bubble/.BUBBLE_PG_PASSWORD)" psql -U bubble -h 127.0.0.1 bubble)" ]] ; then
CHECK_KEY_COUNT="$(echo 'SELECT count(*) FROM account_ssh_key' | PGPASSWORD="$(cat /home/bubble/.BUBBLE_PG_PASSWORD)" psql -U bubble -h 127.0.0.1 bubble)"
if [[ -z "${CHECK_KEY_COUNT}" ]] ; then
log "Warning: error calling psql, not installing/uninstalling any keys"
exit 0
elif [[ ${CHECK_KEY_COUNT} -ne ${ALL_KEY_COUNT} ]] ; then
log "Warning: error CHECK_KEY_COUNT (${CHECK_KEY_COUNT}) -ne ALL_KEY_COUNT (${ALL_KEY_COUNT}), not installing/uninstalling any keys"
exit 0
fi
fi



Ladataan…
Peruuta
Tallenna