-
-
Notifications
You must be signed in to change notification settings - Fork 201
fix: sync supabase roles with $POSTGRES_PASSWORD #1604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/usr/bin/env bash | ||
set -Eeo pipefail | ||
|
||
source /usr/local/bin/upstream-docker-entrypoint.sh | ||
|
||
# sync $POSTGRES_PASSWORD to supabase-specific roles | ||
pg_sync_password() { | ||
# PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless | ||
# e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS | ||
export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}" | ||
docker_temp_server_start "$@" | ||
|
||
# alter the supabase_admin password | ||
docker_process_sql <<-'EOSQL' | ||
\set pgpass `echo "$POSTGRES_PASSWORD"` | ||
ALTER USER supabase_admin WITH PASSWORD :'pgpass'; | ||
EOSQL | ||
|
||
# execute the roles SQL file using docker_process_sql | ||
docker_process_sql -f /docker-entrypoint-initdb.d/init-scripts/99-roles.sql | ||
|
||
docker_temp_server_stop | ||
unset PGPASSWORD | ||
} | ||
|
||
_main() { | ||
# if first arg looks like a flag, assume we want to run postgres server | ||
if [ "${1:0:1}" = '-' ]; then | ||
set -- postgres "$@" | ||
fi | ||
|
||
if [ "$1" = 'postgres' ] && ! _pg_want_help "$@"; then | ||
docker_setup_env | ||
# setup data directories and permissions (when run as root) | ||
docker_create_db_directories | ||
if [ "$(id -u)" = '0' ]; then | ||
# then restart script as postgres user | ||
exec gosu postgres "$BASH_SOURCE" "$@" | ||
fi | ||
|
||
# only run initialization on an empty data directory | ||
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then | ||
docker_verify_minimum_env | ||
|
||
# check dir permissions to reduce likelihood of half-initialized database | ||
ls /docker-entrypoint-initdb.d/ > /dev/null | ||
|
||
docker_init_database_dir | ||
pg_setup_hba_conf "$@" | ||
|
||
# PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless | ||
# e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS | ||
export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}" | ||
docker_temp_server_start "$@" | ||
|
||
docker_setup_db | ||
docker_process_init_files /docker-entrypoint-initdb.d/* | ||
|
||
docker_temp_server_stop | ||
unset PGPASSWORD | ||
|
||
cat <<-'EOM' | ||
|
||
PostgreSQL init process complete; ready for start up. | ||
|
||
EOM | ||
else | ||
cat <<-'EOM' | ||
|
||
PostgreSQL Database directory appears to contain a database; Skipping initialization | ||
|
||
EOM | ||
fi | ||
|
||
pg_sync_password "$@" | ||
fi | ||
|
||
exec "$@" | ||
} | ||
|
||
if ! _is_sourced; then | ||
_main "$@" | ||
fi |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jgoux let's make this path an env var and only run pg_sync_password if this path is defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I'll make the change 👍