[bitnami/pgbouncer] Escape username and password for pgbouncer auth file generation. (#46916)

Escape username and password for pgbouncer auth file generation.

Signed-off-by: Kai G. Schwebke <kai@schwebke.com>
This commit is contained in:
Kai G. Schwebke 2023-09-12 10:46:07 +02:00 committed by GitHub
parent 99f0821173
commit d384b3e9ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 1 deletions

View File

@ -162,6 +162,19 @@ pgbouncer_is_file_external() {
fi
}
########################
# Output helper for escaped auth fields
# Arguments:
# $1 - raw username or password
# Returns:
# None
#########################
pgbouncer_escape_auth() {
# replace each " with ""
echo "$1" | sed 's/"/""/g'
}
########################
# Ensure PgBouncer is initialized
# Globals:
@ -190,7 +203,8 @@ pgbouncer_initialize() {
info "Configuring credentials"
# Create credentials file
if ! pgbouncer_is_file_external "userlist.txt"; then
echo "\"$POSTGRESQL_USERNAME\" \"$POSTGRESQL_PASSWORD\"" > "$PGBOUNCER_AUTH_FILE"
echo "\""$(pgbouncer_escape_auth "$POSTGRESQL_USERNAME")"\" \""$(pgbouncer_escape_auth "$POSTGRESQL_PASSWORD")"\"" \
> "$PGBOUNCER_AUTH_FILE"
echo "$PGBOUNCER_USERLIST" >> "$PGBOUNCER_AUTH_FILE"
else
debug "User list file mounted externally, skipping configuration"