mirror of
https://github.com/wassname/docker-postgresql.git
synced 2026-08-05 13:00:22 +08:00
Protect usernames and database names in "CREATE ROLE", "CREATE DATABASE" and "GRANT ALL" requests
This enables to use "-" in for usernames or database names (eg myApp-client1).
This commit is contained in:
+4
-4
@@ -188,7 +188,7 @@ if [[ ${PSQL_MODE} == standalone || ${PSQL_MODE} == master ]]; then
|
|||||||
DB_USER=
|
DB_USER=
|
||||||
else
|
else
|
||||||
echo "Creating user \"${REPLICATION_USER}\"..."
|
echo "Creating user \"${REPLICATION_USER}\"..."
|
||||||
echo "CREATE ROLE ${REPLICATION_USER} WITH REPLICATION LOGIN ENCRYPTED PASSWORD '${REPLICATION_PASS}';" |
|
echo "CREATE ROLE \"${REPLICATION_USER}\" WITH REPLICATION LOGIN ENCRYPTED PASSWORD '${REPLICATION_PASS}';" |
|
||||||
sudo -Hu ${PG_USER} ${PG_BINDIR}/postgres --single \
|
sudo -Hu ${PG_USER} ${PG_BINDIR}/postgres --single \
|
||||||
-D ${PG_DATADIR} -c config_file=${PG_CONFDIR}/postgresql.conf >/dev/null
|
-D ${PG_DATADIR} -c config_file=${PG_CONFDIR}/postgresql.conf >/dev/null
|
||||||
fi
|
fi
|
||||||
@@ -203,7 +203,7 @@ if [[ ${PSQL_MODE} == standalone || ${PSQL_MODE} == master ]]; then
|
|||||||
DB_USER=
|
DB_USER=
|
||||||
else
|
else
|
||||||
echo "Creating user \"${DB_USER}\"..."
|
echo "Creating user \"${DB_USER}\"..."
|
||||||
echo "CREATE ROLE ${DB_USER} with LOGIN CREATEDB PASSWORD '${DB_PASS}';" |
|
echo "CREATE ROLE \"${DB_USER}\" with LOGIN CREATEDB PASSWORD '${DB_PASS}';" |
|
||||||
sudo -Hu ${PG_USER} ${PG_BINDIR}/postgres --single \
|
sudo -Hu ${PG_USER} ${PG_BINDIR}/postgres --single \
|
||||||
-D ${PG_DATADIR} -c config_file=${PG_CONFDIR}/postgresql.conf >/dev/null
|
-D ${PG_DATADIR} -c config_file=${PG_CONFDIR}/postgresql.conf >/dev/null
|
||||||
fi
|
fi
|
||||||
@@ -212,7 +212,7 @@ if [[ ${PSQL_MODE} == standalone || ${PSQL_MODE} == master ]]; then
|
|||||||
if [[ -n ${DB_NAME} ]]; then
|
if [[ -n ${DB_NAME} ]]; then
|
||||||
for db in $(awk -F',' '{for (i = 1 ; i <= NF ; i++) print $i}' <<< "${DB_NAME}"); do
|
for db in $(awk -F',' '{for (i = 1 ; i <= NF ; i++) print $i}' <<< "${DB_NAME}"); do
|
||||||
echo "Creating database \"${db}\"..."
|
echo "Creating database \"${db}\"..."
|
||||||
echo "CREATE DATABASE ${db};" | \
|
echo "CREATE DATABASE \"${db}\";" | \
|
||||||
sudo -Hu ${PG_USER} ${PG_BINDIR}/postgres --single \
|
sudo -Hu ${PG_USER} ${PG_BINDIR}/postgres --single \
|
||||||
-D ${PG_DATADIR} -c config_file=${PG_CONFDIR}/postgresql.conf >/dev/null
|
-D ${PG_DATADIR} -c config_file=${PG_CONFDIR}/postgresql.conf >/dev/null
|
||||||
|
|
||||||
@@ -225,7 +225,7 @@ if [[ ${PSQL_MODE} == standalone || ${PSQL_MODE} == master ]]; then
|
|||||||
|
|
||||||
if [[ -n ${DB_USER} ]]; then
|
if [[ -n ${DB_USER} ]]; then
|
||||||
echo "Granting access to database \"${db}\" for user \"${DB_USER}\"..."
|
echo "Granting access to database \"${db}\" for user \"${DB_USER}\"..."
|
||||||
echo "GRANT ALL PRIVILEGES ON DATABASE ${db} to ${DB_USER};" |
|
echo "GRANT ALL PRIVILEGES ON DATABASE \"${db}\" to \"${DB_USER}\";" |
|
||||||
sudo -Hu ${PG_USER} ${PG_BINDIR}/postgres --single \
|
sudo -Hu ${PG_USER} ${PG_BINDIR}/postgres --single \
|
||||||
-D ${PG_DATADIR} -c config_file=${PG_CONFDIR}/postgresql.conf >/dev/null
|
-D ${PG_DATADIR} -c config_file=${PG_CONFDIR}/postgresql.conf >/dev/null
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user