mirror of
https://github.com/Security-Onion-Solutions/securityonion.git
synced 2026-05-09 04:42:40 +02:00
8225d41661
- Deliver postgres super and app passwords via mounted 0600 secret files (POSTGRES_PASSWORD_FILE, SO_POSTGRES_PASS_FILE) instead of plaintext env vars visible in docker inspect output - Mount a managed pg_hba.conf that only allows local trust and hostssl scram-sha-256 so TCP clients cannot negotiate cleartext sessions - Restrict postgres.key to 0400 and ensure owner/group 939 - Set umask 0077 on so-postgres-backup output - Validate host values in so-stats-show against [A-Za-z0-9._-] before SQL interpolation so a compromised minion cannot inject SQL via a tag value - Coerce postgres:telegraf:retention_days to int before rendering into SQL - Escape single quotes when rendering pillar values into postgresql.conf - Own postgres tooling in /usr/sbin as root:root so a container escape cannot rewrite admin scripts - Gate ES migration TLS verification on esVerifyCert (default false, matching the elastic module's existing pattern)
40 lines
1.2 KiB
Bash
40 lines
1.2 KiB
Bash
#!/bin/bash
|
|
#
|
|
# Copyright Security Onion Solutions LLC and/or licensed to Security Onion Solutions LLC under one
|
|
# or more contributor license agreements. Licensed under the Elastic License 2.0 as shown at
|
|
# https://securityonion.net/license; you may not use this file except in compliance with the
|
|
# Elastic License 2.0.
|
|
|
|
. /usr/sbin/so-common
|
|
|
|
# Backups contain role password hashes and full chat data; keep them 0600.
|
|
umask 0077
|
|
|
|
TODAY=$(date '+%Y_%m_%d')
|
|
BACKUPDIR=/nsm/backup
|
|
BACKUPFILE="$BACKUPDIR/so-postgres-backup-$TODAY.sql.gz"
|
|
MAXBACKUPS=7
|
|
|
|
mkdir -p $BACKUPDIR
|
|
|
|
# Skip if already backed up today
|
|
if [ -f "$BACKUPFILE" ]; then
|
|
exit 0
|
|
fi
|
|
|
|
# Skip if container isn't running
|
|
if ! docker ps --format '{{.Names}}' | grep -q '^so-postgres$'; then
|
|
exit 0
|
|
fi
|
|
|
|
# Dump all databases and roles, compress
|
|
docker exec so-postgres pg_dumpall -U postgres | gzip > "$BACKUPFILE"
|
|
|
|
# Retention cleanup
|
|
NUMBACKUPS=$(find $BACKUPDIR -type f -name "so-postgres-backup*" | wc -l)
|
|
while [ "$NUMBACKUPS" -gt "$MAXBACKUPS" ]; do
|
|
OLDEST=$(find $BACKUPDIR -type f -name "so-postgres-backup*" -printf '%T+ %p\n' | sort | head -n 1 | awk -F" " '{print $2}')
|
|
rm -f "$OLDEST"
|
|
NUMBACKUPS=$(find $BACKUPDIR -type f -name "so-postgres-backup*" | wc -l)
|
|
done
|