Skip to content

Commit 6bcf9fc

Browse files
committed
Backups: an upgrade adds the backup password an older install lacks
install.sh --upgrade leaves .env alone, so an install from before automatic backups would come up with no GCR_BACKUP_PASSWORD: no nightly backup, and every delete of all findings refused. The upgrade now adds GCR_BACKUP_PATH and a generated GCR_BACKUP_PASSWORD when they are missing, creates the backup folder, and says to copy the password off the server. Values already there are never changed. .env.example lists both.
1 parent d6cbb3c commit 6bcf9fc

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

‎.env.example‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ GCR_OUT_PATH=./out
5050
# flight. Nothing is kept here between runs.
5151
GCR_WORK_PATH=./work
5252

53+
# Automatic backups: one nightly and one before any delete of all findings,
54+
# the newest five of each kept here. They are encrypted with the password
55+
# below; install.sh writes one. Keep a copy of it off this server. Blank
56+
# turns automatic backups off, and deleting all findings is then refused.
57+
GCR_BACKUP_PATH=./backups
58+
GCR_BACKUP_PASSWORD=
59+
5360
# ---- sessions and encryption ------------------------------------------------
5461
# Signs sessions. Set the same value on every instance behind a load balancer.
5562
GCR_SECRET_KEY=

‎install.sh‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,25 @@ if (( UPGRADE )); then
315315
# root owned work directory that docker created, and every scan on it fails.
316316
ensure_container_dir "$REPORTS"
317317
ensure_container_dir "$WORK"
318+
319+
# Automatic backups need a password, and an install from before they existed
320+
# has none, which would leave it with no nightly backup and no backup before
321+
# a delete of all findings. This adds the two keys when they are missing and
322+
# never changes a value that is already there.
323+
BACKUPS="$(existing GCR_BACKUP_PATH || echo "$HERE/backups")"
324+
ensure_container_dir "$BACKUPS"
325+
chmod 700 "$BACKUPS" 2>/dev/null || true
326+
if ! grep -q '^GCR_BACKUP_PASSWORD=.' "$ENV_FILE"; then
327+
{
328+
printf '\n# Added by install.sh --upgrade on %s.\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
329+
printf '# Automatic backups are encrypted with this. Copy it somewhere other\n'
330+
printf '# than this server, or a lost server takes its backups with it.\n'
331+
grep -q '^GCR_BACKUP_PATH=' "$ENV_FILE" || printf 'GCR_BACKUP_PATH=%s\n' "$BACKUPS"
332+
printf 'GCR_BACKUP_PASSWORD=%s\n' "$(random_secret 40)"
333+
} >> "$ENV_FILE"
334+
ok "a backup password was added to $ENV_FILE for the nightly backups"
335+
hint "Copy GCR_BACKUP_PASSWORD from $ENV_FILE somewhere safe, off this server"
336+
fi
318337
export COMPOSE_PROFILES="$DB_PROFILE"
319338

320339
say "Rebuilding"

0 commit comments

Comments
 (0)