From eadad6c163aaad3312d2d4387ae16b6c86e0da9e Mon Sep 17 00:00:00 2001 From: Mike Reeves Date: Thu, 23 Apr 2026 10:01:38 -0400 Subject: [PATCH] soup: bootstrap postgres pillar stubs and secret on 3.0.0 upgrade pillar/top.sls now references postgres.soc_postgres / postgres.adv_postgres unconditionally, but make_some_dirs only runs at install time so managers upgrading from 3.0.0 have no local/pillar/postgres/ and salt-master fails pillar render on the first post-upgrade restart. Similarly, secrets_pillar is a no-op on upgrade (secrets.sls already exists), so secrets:postgres_pass never gets seeded and the postgres container's POSTGRES_PASSWORD_FILE and SOC's PG_ADMIN_PASS would land empty after highstate. Add ensure_postgres_local_pillar and ensure_postgres_secret to up_to_3.1.0 so the stubs and secret exist before masterlock/salt-master restart. Both are idempotent and safe to re-run. --- salt/manager/tools/sbin/soup | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/salt/manager/tools/sbin/soup b/salt/manager/tools/sbin/soup index 2c727c0f7..d54af4a13 100755 --- a/salt/manager/tools/sbin/soup +++ b/salt/manager/tools/sbin/soup @@ -477,7 +477,44 @@ elasticsearch_backup_index_templates() { tar -czf /nsm/backup/3.0.0_elasticsearch_index_templates.tar.gz -C /opt/so/conf/elasticsearch/templates/index/ . } +ensure_postgres_local_pillar() { + # Postgres was added as a service after 3.0.0, so the new pillar/top.sls + # references postgres.soc_postgres / postgres.adv_postgres unconditionally. + # Managers upgrading from 3.0.0 have no /opt/so/saltstack/local/pillar/postgres/ + # (make_some_dirs only runs at install time), so the stubs must be created + # here before salt-master restarts against the new top.sls. + echo "Ensuring postgres local pillar stubs exist." + local dir=/opt/so/saltstack/local/pillar/postgres + mkdir -p "$dir" + [[ -f "$dir/soc_postgres.sls" ]] || touch "$dir/soc_postgres.sls" + [[ -f "$dir/adv_postgres.sls" ]] || touch "$dir/adv_postgres.sls" + chown -R socore:socore "$dir" +} + +ensure_postgres_secret() { + # On a fresh install, generate_passwords + secrets_pillar seed + # secrets:postgres_pass in /opt/so/saltstack/local/pillar/secrets.sls. That + # code path is skipped on upgrade (secrets.sls already exists from 3.0.0 + # with import_pass/influx_pass but no postgres_pass), so the postgres + # container's POSTGRES_PASSWORD_FILE and SOC's PG_ADMIN_PASS would be empty + # after highstate. Generate one now if missing. + local secrets_file=/opt/so/saltstack/local/pillar/secrets.sls + if [[ ! -f "$secrets_file" ]]; then + echo "WARNING: $secrets_file missing; skipping postgres_pass backfill." + return 0 + fi + if so-yaml.py get -r "$secrets_file" secrets.postgres_pass >/dev/null 2>&1; then + echo "secrets.postgres_pass already set; leaving as-is." + return 0 + fi + echo "Seeding secrets.postgres_pass in $secrets_file." + so-yaml.py add "$secrets_file" secrets.postgres_pass "$(get_random_value)" + chown socore:socore "$secrets_file" +} + up_to_3.1.0() { + ensure_postgres_local_pillar + ensure_postgres_secret determine_elastic_agent_upgrade elasticsearch_backup_index_templates # Clear existing component template state file.