Skip to content

Commit 905c9f2

Browse files
jgouxsoedirgo
andauthored
fix: sync supabase roles with $POSTGRES_PASSWORD (#1604)
* fix: sync supabase roles with $POSTGRES_PASSWORD * add changes to pg 17 Dockerfile * add changes to oriole docker image * Update docker-entrypoint.sh --------- Co-authored-by: Bobbie Soedirgo <31685197+soedirgo@users.noreply.github.com>
1 parent ebaf443 commit 905c9f2

File tree

4 files changed

+104
-3
lines changed

4 files changed

+104
-3
lines changed

Dockerfile-15

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ RUN sed -i \
181181
echo "pgsodium.getkey_script= '/usr/lib/postgresql/bin/pgsodium_getkey.sh'" >> /etc/postgresql/postgresql.conf && \
182182
echo "vault.getkey_script= '/usr/lib/postgresql/bin/pgsodium_getkey.sh'" >> /etc/postgresql/postgresql.conf && \
183183
echo 'auto_explain.log_min_duration = 10s' >> /etc/postgresql/postgresql.conf && \
184+
# Remove supabase_admin line from pg_hba.conf
185+
sed -i '/local all supabase_admin scram-sha-256/d' /etc/postgresql/pg_hba.conf && \
186+
# Add supabase_admin mappings block to pg_ident.conf before supabase-specific users
187+
sed -i '/# supabase-specific users/i\# supabase_admin user mappings\nsupabase_map postgres supabase_admin\nsupabase_map root supabase_admin\nsupabase_map ubuntu supabase_admin\n' /etc/postgresql/pg_ident.conf && \
184188
usermod -aG postgres wal-g && \
185189
mkdir -p /etc/postgresql-custom && \
186190
chown postgres:postgres /etc/postgresql-custom
@@ -194,7 +198,9 @@ COPY ansible/files/stat_extension.sql /docker-entrypoint-initdb.d/migrations/00-
194198
COPY --from=gosu /usr/local/bin/gosu /usr/local/bin/gosu
195199
ADD --chmod=0755 \
196200
https://github.com/docker-library/postgres/raw/master/15/bullseye/docker-entrypoint.sh \
197-
/usr/local/bin/
201+
/usr/local/bin/upstream-docker-entrypoint.sh
202+
# # Add custom entrypoint script
203+
COPY --chmod=0755 docker/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
198204

199205
RUN mkdir -p /var/run/postgresql && chown postgres:postgres /var/run/postgresql
200206

Dockerfile-17

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ RUN sed -i \
181181
echo "pgsodium.getkey_script= '/usr/lib/postgresql/bin/pgsodium_getkey.sh'" >> /etc/postgresql/postgresql.conf && \
182182
echo "vault.getkey_script= '/usr/lib/postgresql/bin/pgsodium_getkey.sh'" >> /etc/postgresql/postgresql.conf && \
183183
echo 'auto_explain.log_min_duration = 10s' >> /etc/postgresql/postgresql.conf && \
184+
# Remove supabase_admin line from pg_hba.conf
185+
sed -i '/local all supabase_admin scram-sha-256/d' /etc/postgresql/pg_hba.conf && \
186+
# Add supabase_admin mappings block to pg_ident.conf before supabase-specific users
187+
sed -i '/# supabase-specific users/i\# supabase_admin user mappings\nsupabase_map postgres supabase_admin\nsupabase_map root supabase_admin\nsupabase_map ubuntu supabase_admin\n' /etc/postgresql/pg_ident.conf && \
184188
usermod -aG postgres wal-g && \
185189
mkdir -p /etc/postgresql-custom && \
186190
chown postgres:postgres /etc/postgresql-custom
@@ -202,7 +206,9 @@ COPY ansible/files/stat_extension.sql /docker-entrypoint-initdb.d/migrations/00-
202206
COPY --from=gosu /usr/local/bin/gosu /usr/local/bin/gosu
203207
ADD --chmod=0755 \
204208
https://github.com/docker-library/postgres/raw/master/17/bullseye/docker-entrypoint.sh \
205-
/usr/local/bin/
209+
/usr/local/bin/upstream-docker-entrypoint.sh
210+
# # Add custom entrypoint script
211+
COPY --chmod=0755 docker/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
206212

207213
RUN mkdir -p /var/run/postgresql && chown postgres:postgres /var/run/postgresql
208214

Dockerfile-orioledb-17

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ RUN sed -i \
181181
echo "pgsodium.getkey_script= '/usr/lib/postgresql/bin/pgsodium_getkey.sh'" >> /etc/postgresql/postgresql.conf && \
182182
echo "vault.getkey_script= '/usr/lib/postgresql/bin/pgsodium_getkey.sh'" >> /etc/postgresql/postgresql.conf && \
183183
echo 'auto_explain.log_min_duration = 10s' >> /etc/postgresql/postgresql.conf && \
184+
# Remove supabase_admin line from pg_hba.conf
185+
sed -i '/local all supabase_admin scram-sha-256/d' /etc/postgresql/pg_hba.conf && \
186+
# Add supabase_admin mappings block to pg_ident.conf before supabase-specific users
187+
sed -i '/# supabase-specific users/i\# supabase_admin user mappings\nsupabase_map postgres supabase_admin\nsupabase_map root supabase_admin\nsupabase_map ubuntu supabase_admin\n' /etc/postgresql/pg_ident.conf && \
184188
usermod -aG postgres wal-g && \
185189
mkdir -p /etc/postgresql-custom && \
186190
chown postgres:postgres /etc/postgresql-custom
@@ -207,7 +211,9 @@ RUN echo "CREATE EXTENSION orioledb;" > /docker-entrypoint-initdb.d/init-scripts
207211
COPY --from=gosu /usr/local/bin/gosu /usr/local/bin/gosu
208212
ADD --chmod=0755 \
209213
https://github.com/docker-library/postgres/raw/master/17/bullseye/docker-entrypoint.sh \
210-
/usr/local/bin/
214+
/usr/local/bin/upstream-docker-entrypoint.sh
215+
# # Add custom entrypoint script
216+
COPY --chmod=0755 docker/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
211217

212218
RUN mkdir -p /var/run/postgresql && chown postgres:postgres /var/run/postgresql
213219

docker/docker-entrypoint.sh

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/usr/bin/env bash
2+
set -Eeo pipefail
3+
4+
source /usr/local/bin/upstream-docker-entrypoint.sh
5+
6+
# sync $POSTGRES_PASSWORD to supabase-specific roles
7+
pg_sync_password() {
8+
# PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless
9+
# e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS
10+
export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}"
11+
docker_temp_server_start "$@"
12+
13+
# alter the supabase_admin password
14+
docker_process_sql <<-'EOSQL'
15+
\set pgpass `echo "$POSTGRES_PASSWORD"`
16+
ALTER USER supabase_admin WITH PASSWORD :'pgpass';
17+
EOSQL
18+
19+
# execute the roles SQL file using docker_process_sql
20+
docker_process_sql -f /docker-entrypoint-initdb.d/init-scripts/99-roles.sql
21+
22+
docker_temp_server_stop
23+
unset PGPASSWORD
24+
}
25+
26+
_main() {
27+
# if first arg looks like a flag, assume we want to run postgres server
28+
if [ "${1:0:1}" = '-' ]; then
29+
set -- postgres "$@"
30+
fi
31+
32+
if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then
33+
docker_setup_env
34+
# setup data directories and permissions (when run as root)
35+
docker_create_db_directories
36+
if [ "$(id -u)" = '0' ]; then
37+
# then restart script as postgres user
38+
exec gosu postgres "$BASH_SOURCE" "$@"
39+
fi
40+
41+
# only run initialization on an empty data directory
42+
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
43+
docker_verify_minimum_env
44+
45+
# check dir permissions to reduce likelihood of half-initialized database
46+
ls /docker-entrypoint-initdb.d/ > /dev/null
47+
48+
docker_init_database_dir
49+
pg_setup_hba_conf "$@"
50+
51+
# PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless
52+
# e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS
53+
export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}"
54+
docker_temp_server_start "$@"
55+
56+
docker_setup_db
57+
docker_process_init_files /docker-entrypoint-initdb.d/*
58+
59+
docker_temp_server_stop
60+
unset PGPASSWORD
61+
62+
cat <<-'EOM'
63+
64+
PostgreSQL init process complete; ready for start up.
65+
66+
EOM
67+
else
68+
cat <<-'EOM'
69+
70+
PostgreSQL Database directory appears to contain a database; Skipping initialization
71+
72+
EOM
73+
fi
74+
75+
pg_sync_password "$@"
76+
fi
77+
78+
exec "$@"
79+
}
80+
81+
if ! _is_sourced; then
82+
_main "$@"
83+
fi

0 commit comments

Comments
 (0)