From 68e6c951fd2290e739c99cd06c568d7603dc2fb0 Mon Sep 17 00:00:00 2001 From: jtricerolph Date: Thu, 13 Aug 2026 12:21:02 +0000 Subject: [PATCH] settings: re-assert DB role password on every deploy, not just first install MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hit in production 2026-08-13: settings crash-looped with 'password authentication failed' after a routine --only settings redeploy. The settings Postgres role was only ever created once, in deploy_postgres()'s init SQL (fresh-volume-only) — so if CREDS_FILE's SETTINGS_DB_PASS ever drifted from the role's actual password, redeploying settings had no way to self-heal. Mirrors the CREATE-then-fallback pattern other apps' deploy functions use, but falls back to ALTER instead of swallowing the error, since CREATE failing because the role already exists doesn't fix a drifted password. Co-Authored-By: Claude Sonnet 5 --- install-stack.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/install-stack.sh b/install-stack.sh index 9bbdcf1..ffe0ae7 100755 --- a/install-stack.sh +++ b/install-stack.sh @@ -909,6 +909,28 @@ deploy_settings() { install_mgmt_key 116 msg_ok "Docker + SSH ready" + # Re-assert the settings DB role/password on every deploy, not just first + # install — the role was originally only created once, in deploy_postgres()'s + # init SQL (fresh-volume-only), so a redeploy had no way to self-heal if + # CREDS_FILE's SETTINGS_DB_PASS ever drifted from the role's actual password + # (hit in production 2026-08-13: settings crash-looped on "password + # authentication failed" after a routine redeploy). CREATE first (covers a + # brand-new postgres where the role doesn't exist yet), ALTER as fallback + # (covers drift on an already-existing role) — CREATE-with-swallowed-error + # alone, as other apps' deploy functions use, can't fix drift. + msg_info "Syncing settings database credentials" + pct exec 100 -- bash -c " + docker exec hotel-manage-postgres psql -U postgres -c \ + \"CREATE USER settings WITH PASSWORD '${SETTINGS_DB_PASS}';\" 2>/dev/null || \ + docker exec hotel-manage-postgres psql -U postgres -c \ + \"ALTER USER settings WITH PASSWORD '${SETTINGS_DB_PASS}';\" + docker exec hotel-manage-postgres psql -U postgres -c \ + \"CREATE DATABASE settings_db OWNER settings;\" 2>/dev/null || true + docker exec hotel-manage-postgres psql -U postgres -d settings_db -c \ + \"GRANT ALL ON SCHEMA public TO settings;\" 2>/dev/null || true + " &>/dev/null + msg_ok "Database settings_db ready" + # Copy the shared deploy SSH key so settings can SSH into the MQTT broker # LXC (104) to manage dynamic-security clients — same mechanism management # uses for its Shell/exec tab, just consumed by a second container.