From f5e674d60faa9d34775e3cc7f6f54f973efb0423 Mon Sep 17 00:00:00 2001 From: "Kai G. Schwebke" Date: Fri, 1 Sep 2023 11:19:06 +0200 Subject: [PATCH] Escape username and password for pgbouncer auth file generation. Signed-off-by: Kai G. Schwebke --- .../rootfs/opt/bitnami/scripts/libpgbouncer.sh | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/bitnami/pgbouncer/1/debian-11/rootfs/opt/bitnami/scripts/libpgbouncer.sh b/bitnami/pgbouncer/1/debian-11/rootfs/opt/bitnami/scripts/libpgbouncer.sh index b5cfe900a9297..2e68a97f94292 100644 --- a/bitnami/pgbouncer/1/debian-11/rootfs/opt/bitnami/scripts/libpgbouncer.sh +++ b/bitnami/pgbouncer/1/debian-11/rootfs/opt/bitnami/scripts/libpgbouncer.sh @@ -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"