From d1adeb4a6bbe77802f999dcf72866011c304590d Mon Sep 17 00:00:00 2001 From: rjshrjndrn Date: Thu, 17 Oct 2024 14:35:52 +0200 Subject: [PATCH] fix(helm): password Signed-off-by: rjshrjndrn --- scripts/helmcharts/databases/templates/job.yaml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/scripts/helmcharts/databases/templates/job.yaml b/scripts/helmcharts/databases/templates/job.yaml index ba665f792..cc0e4642d 100644 --- a/scripts/helmcharts/databases/templates/job.yaml +++ b/scripts/helmcharts/databases/templates/job.yaml @@ -18,7 +18,7 @@ spec: env: - name: PGUSER value: {{.Values.postgresql.postgresqlUser}} - - name: PGPASSWORD + - name: PGPASSWORD_NEW value: {{.Values.postgresql.postgresqlPassword}} # current password - name: PGPASSWORD_OLD value: {{.Values.postgresql.oldPostgresqlPassword}} # old password @@ -30,8 +30,7 @@ spec: args: - | # Try to login with the current password - echo if PGPASSWORD=$PGPASSWORD psql -h $PGHOST -p $PGPORT -U $PGUSER -d postgres -c '\q'; - if PGPASSWORD=$PGPASSWORD psql -h $PGHOST -p $PGPORT -U $PGUSER -d postgres -c '\q'; then + if PGPASSWORD=$PGPASSWORD_NEW psql -h $PGHOST -p $PGPORT -U $PGUSER -d postgres -c '\q'; then echo "Successfully logged in with current password. No update needed." exit 0 else @@ -40,8 +39,7 @@ spec: if PGPASSWORD=$PGPASSWORD_OLD psql -h $PGHOST -p $PGPORT -U $PGUSER -d postgres -c '\q'; then echo "Successfully logged in with old password. Updating password to the new one." # Update the password to the new one - new_password=$(openssl rand -hex 20) - PGPASSWORD=$PGPASSWORD_OLD psql -h $PGHOST -p $PGPORT -U $PGUSER -d postgres -c "ALTER USER $PGUSER WITH PASSWORD '$new_password';" + PGPASSWORD=$PGPASSWORD_OLD psql -h $PGHOST -p $PGPORT -U $PGUSER -d postgres -c "ALTER USER $PGUSER WITH PASSWORD '$PGPASSWORD_NEW';" if [ $? -eq 0 ]; then echo "Password updated successfully." exit 0