2026-03-05 09:22:13 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
# create-secrets.sh — create K8s Secrets for PostgreSQL from gen-secrets.sh output
|
|
|
|
|
#
|
|
|
|
|
# Usage:
|
|
|
|
|
# ./create-secrets.sh <secrets-dir>
|
|
|
|
|
#
|
|
|
|
|
# <secrets-dir> is the output directory produced by sso-mfa/bootstrap/gen-secrets.sh
|
|
|
|
|
# (default: ../../bootstrap/secrets).
|
|
|
|
|
#
|
2026-03-20 02:57:41 +00:00
|
|
|
# Creates one K8s Secret in the databases namespace:
|
2026-03-05 09:22:13 +01:00
|
|
|
# net-kingdom-pg-privacyidea-app — privacyIDEA DB credentials
|
|
|
|
|
#
|
2026-03-20 02:57:41 +00:00
|
|
|
# Note: net-kingdom-pg-keycloak-app removed — Keycloak replaced by Authelia+LLDAP+KeyCape (T05).
|
|
|
|
|
#
|
2026-03-05 09:22:13 +01:00
|
|
|
# These secrets must exist before applying cluster.yaml.
|
|
|
|
|
# Re-run this script whenever you rotate passwords in KeePassXC / gen-secrets.sh.
|
|
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
|
|
SECRETS_DIR="${1:-../../bootstrap/secrets}"
|
|
|
|
|
|
|
|
|
|
if [[ ! -d "$SECRETS_DIR" ]]; then
|
|
|
|
|
echo "ERROR: secrets directory not found: $SECRETS_DIR" >&2
|
|
|
|
|
echo "Run sso-mfa/bootstrap/gen-secrets.sh first, then re-run this script." >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
PI_SECRETS="$SECRETS_DIR/privacyidea/secrets.env"
|
|
|
|
|
|
|
|
|
|
if [[ ! -f "$PI_SECRETS" ]]; then
|
|
|
|
|
echo "ERROR: $PI_SECRETS not found" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2026-03-20 02:57:41 +00:00
|
|
|
# Source the generated env file (KEY=VALUE pairs, no export)
|
2026-03-05 09:22:13 +01:00
|
|
|
# Use a subshell to avoid polluting the current environment.
|
|
|
|
|
PI_DB_PASS=$(bash -c "source $PI_SECRETS 2>/dev/null; echo \$PI_DB_PASSWORD")
|
|
|
|
|
|
2026-03-20 02:57:41 +00:00
|
|
|
if [[ -z "$PI_DB_PASS" ]]; then
|
|
|
|
|
echo "ERROR: could not read PI_DB_PASSWORD from $PI_SECRETS" >&2
|
|
|
|
|
echo "Check that gen-secrets.sh ran successfully and the file is intact." >&2
|
2026-03-05 09:22:13 +01:00
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "Creating K8s Secret: net-kingdom-pg-privacyidea-app"
|
|
|
|
|
kubectl create secret generic net-kingdom-pg-privacyidea-app \
|
|
|
|
|
--namespace=databases \
|
|
|
|
|
--from-literal=username=privacyidea \
|
|
|
|
|
--from-literal=password="$PI_DB_PASS" \
|
|
|
|
|
--dry-run=client -o yaml | kubectl apply -f -
|
|
|
|
|
|
|
|
|
|
echo ""
|
2026-03-20 02:57:41 +00:00
|
|
|
echo "Done. Secret created in namespace: databases"
|
2026-03-05 09:22:13 +01:00
|
|
|
echo ""
|
|
|
|
|
echo "Verify:"
|
|
|
|
|
echo " kubectl get secrets -n databases"
|
2026-03-20 02:57:41 +00:00
|
|
|
echo " kubectl describe secret net-kingdom-pg-privacyidea-app -n databases"
|