21 lines
1.3 KiB
Bash
21 lines
1.3 KiB
Bash
#!/bin/sh
|
|
# Operator bootstrap, idempotent, nothing printed: local PKI, random service passwords, Redis ACL file, .env. All under ./secrets (0700, ignored by Git).
|
|
set -eu
|
|
cd "$(dirname "$0")/.."
|
|
S="${SECRETS_DIR:-secrets}"; O="$S/ops"
|
|
umask 077; mkdir -p "$O"; chmod 700 "$S"
|
|
gen() { [ -s "$O/$1" ] || { openssl rand -base64 36 | tr -d '/+=\n' | cut -c1-32 > "$O/$1"; }; }
|
|
for n in postgres_password db_api_password db_worker_password db_dispatcher_password db_sweeper_password \
|
|
redis_api_password redis_health_password s3_root_password s3_api_secret s3_worker_secret s3_sweeper_secret grafana_admin_password kafka_ssl_password; do gen "$n"; done
|
|
sh scripts/pki.sh init
|
|
[ -s "$O/s3_root_user" ] || printf 'root-%s' "$(openssl rand -hex 4)" > "$O/s3_root_user"
|
|
h() { printf %s "$(cat "$O/$1")" | sha256sum | cut -d' ' -f1; }
|
|
cat > "$O/redis_users.acl" <<ACL
|
|
user default off
|
|
user api on #$(h redis_api_password) ~session:* ~rl:* resetchannels -@all +get +set +setex +del +incr +incrby +expire +ttl +ping +multi +exec +client|setinfo
|
|
user health on #$(h redis_health_password) resetkeys resetchannels -@all +ping
|
|
ACL
|
|
chmod 644 "$O"/* # ./secrets is 0700: only the operator can enter; containers run as other uids and mount single files read-only
|
|
[ -f .env ] || { cp .env.example .env; }
|
|
echo "bootstrap done (PKI, passwords, Redis ACL). Next: scripts/up.sh"
|