Skip to content
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

Merge 15.6 into develop #1367

Closed
wants to merge 44 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
549f9eb
fix: account for `public` grantee
soedirgo Sep 26, 2024
c83b1c6
fix(ci): respect postgresVersion input (#1237)
soedirgo Sep 26, 2024
5671a39
feat: bump gotrue version to v2.162.0 (#1241)
kangmingtay Sep 28, 2024
a2f1ff8
fix: only grant pg_read_all_data if it exists (#1242)
soedirgo Sep 30, 2024
d71ec5f
fix(15.6): account for pg_stat_monitor major version upgrade (#1247)
pcnc Oct 2, 2024
8706e3a
chore: release updates to run physical backup as a service to 15.6 im…
dragarcia Oct 2, 2024
1d1396e
fix(15.6/pg_upgrade): retry commands within the cleanup step; wait un…
pcnc Oct 2, 2024
320305e
fix(15.6/upgrades): collision when patching wrappers lib locations fo…
pcnc Oct 2, 2024
d264b9d
feat: bump auth 2.162.1 on 15.6 (#1256)
hf Oct 3, 2024
5177fa3
fix(15.6): disable pg_stat_monitor (#1260)
pcnc Oct 4, 2024
ce2eb0c
fix(15.6): disable pg_stat_monitor (#1262)
pcnc Oct 4, 2024
9062da4
feat: bump gotrue to v2.162.2 (#1264)
kangmingtay Oct 7, 2024
0c52b1f
chore: add timescaledb 2.9.1; wrappers upgrade fix; wrappers & plv8 n…
pcnc Oct 15, 2024
ba417af
chore(15.6): bump pg version (#1273)
pcnc Oct 15, 2024
82152fa
feat: bump auth to v2.163.0 on 15.6 (#1275)
hf Oct 15, 2024
1912ed8
fix: restart PG during pre-upgrade steps to shed hanging connections …
pcnc Oct 16, 2024
3cf6055
fix(upgrades): wrappers 4.2.0 -> wrappers 4.2.0 (#1278)
pcnc Oct 17, 2024
054dbc1
fix: handle supabase_admin authenticator membership snowflake
soedirgo Oct 21, 2024
fb024e8
feat: add auth v2.163.1 to 15.6 (#1283)
hf Oct 22, 2024
223952b
feat: bump gotrue to v2.163.2 (#1287)
kangmingtay Oct 23, 2024
2d658fc
pg_net 0.11 on 15.6 release branch (#1290)
olirice Oct 24, 2024
a5e5919
fix: don't copy custom extension scripts during pg_upgrade (#1291)
pcnc Oct 25, 2024
1211077
fix: add recursive flag to custom extension script directory delete (…
pcnc Oct 25, 2024
407d41a
[GEN-11027] chore: reserve a fixed amount of blocks for the data volu…
pcnc Oct 30, 2024
19ac493
fix: grant predefined roles post-upgrade
soedirgo Oct 31, 2024
21d3823
fix: add more roles to reserved_roles & reserved_memberships (#1303)
soedirgo Oct 31, 2024
1273c41
feat: update envoy lds config with auth jwks, oidc URLs, strip `sb-op…
hf Nov 1, 2024
936713c
chore: udpate package repo for salt (#1307)
dragarcia Nov 4, 2024
5350420
fix: use sudo for apt-get commands
soedirgo Nov 6, 2024
9e285dd
Update pg net to 0.13.0 on pg 15.6 branch (#1315)
olirice Nov 8, 2024
a627e17
chore: cleanup pgbouncer.get_auth ownership accordingly
dragarcia Nov 6, 2024
4b0e661
chore: standardize
dragarcia Nov 6, 2024
7065738
Upgrade pgvector to 0.8.0
pashkinelfe Nov 11, 2024
f34519d
Update common-nix.vars.pkr.hcl
pashkinelfe Nov 18, 2024
42c6d7e
feat: upgrade to auth v2.164.0 (#1329)
J0 Nov 21, 2024
bf452e4
fix: replace `alter routine` with `alter function|procedure` (#1333)
soedirgo Nov 21, 2024
3bc1710
fix: pg_upgrade_script (#1336)
pcnc Nov 21, 2024
d4bcb35
feat: supautils v2.5.0
soedirgo Nov 21, 2024
63303c6
pgmq in 15.6 image (#1337)
olirice Nov 25, 2024
6bbd27a
fix: upload gotrue binary to internal-artifacts as a gz file (#1340)
kangmingtay Nov 28, 2024
af0f41b
feat: upgrade to auth v2.165.0 (#1357)
cstockton Dec 6, 2024
57149e1
feat: bump gotrue to v2.165.1 (#1358)
kangmingtay Dec 6, 2024
34cbe36
feat: build and cache debug and src on this branch (#1360)
samrose Dec 6, 2024
8b3db2e
fix: pgmq ownership (#1362)
soedirgo Dec 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/publish-nix-pgupgrade-scripts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ jobs:
id: process_release_version
run: |
VERSION=$(grep 'postgres-version' common-nix.vars.pkr.hcl | sed -e 's/postgres-version = "\(.*\)"/\1/g')
if [[ "${{ inputs.postgresVersion }}" != "" ]]; then
VERSION=${{ inputs.postgresVersion }}
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"

- name: Create a tarball containing pg_upgrade scripts
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ARG hypopg_release=1.3.1
ARG pgvector_release=0.4.0
ARG pg_tle_release=1.3.2
ARG index_advisor_release=0.2.0
ARG supautils_release=2.2.1
ARG supautils_release=2.5.0
ARG wal_g_release=2.0.1

####################
Expand Down
25 changes: 19 additions & 6 deletions ansible/files/admin_api_scripts/pg_upgrade_scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,24 @@ swap_postgres_and_supabase_admin() {
alter database postgres connection limit 0;
select pg_terminate_backend(pid) from pg_stat_activity where backend_type = 'client backend' and pid != pg_backend_pid();
EOSQL

if [ -z "$IS_CI" ]; then
retry 5 systemctl restart postgresql
else
CI_start_postgres ""
fi

retry 8 pg_isready -h localhost -U supabase_admin

run_sql <<'EOSQL'
set statement_timeout = '600s';
begin;
create role supabase_tmp superuser;
set session authorization supabase_tmp;

-- to handle snowflakes that happened in the past
revoke supabase_admin from authenticator;

do $$
begin
if exists (select from pg_extension where extname = 'timescaledb') then
Expand Down Expand Up @@ -356,7 +368,8 @@ begin
end
, case when rec.grantee = 'postgres'::regrole then 'supabase_admin'
when rec.grantee = 'supabase_admin'::regrole then 'postgres'
else rec.grantee::regrole
when rec.grantee = 0 then 'public'
else rec.grantee::regrole::text
end
));
end if;
Expand All @@ -382,7 +395,7 @@ begin
when obj->>'objtype' = 'T' then 'types'
when obj->>'objtype' = 'n' then 'schemas'
end
, rec.grantee::regrole
, case when rec.grantee = 0 then 'public' else rec.grantee::regrole::text end
, case when rec.is_grantable then 'with grant option' else '' end
));
end if;
Expand Down Expand Up @@ -443,7 +456,10 @@ begin
foreach obj in array functions
loop
if obj->>'owner' = 'postgres' then
execute(format('alter routine %s(%s) owner to postgres;', (obj->>'oid')::regproc, pg_get_function_identity_arguments((obj->>'oid')::regproc)));
execute(format('alter %s %s(%s) owner to postgres;'
, case when obj->>'kind' = 'p' then 'procedure' else 'function' end
, (obj->>'oid')::regproc
, pg_get_function_identity_arguments((obj->>'oid')::regproc)));
end if;
for rec in
select grantor, grantee, privilege_type, is_grantable
Expand Down Expand Up @@ -528,9 +544,6 @@ $$;

alter database postgres connection limit -1;

-- #incident-2024-09-12-project-upgrades-are-temporarily-disabled
grant pg_read_all_data, pg_signal_backend to postgres;

set session authorization supabase_admin;
drop role supabase_tmp;
commit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ EOF

run_sql -c "$RECREATE_PG_CRON_QUERY"
fi

# #incident-2024-09-12-project-upgrades-are-temporarily-disabled
run_sql -c "grant pg_read_all_data, pg_signal_backend to postgres"
}

function complete_pg_upgrade {
Expand Down
92 changes: 33 additions & 59 deletions ansible/files/admin_api_scripts/pg_upgrade_scripts/initiate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# them depending on regtypes referencing system OIDs or outdated library files.
EXTENSIONS_TO_DISABLE=(
"pg_graphql"
"pg_stat_monitor"
)

PG14_EXTENSIONS_TO_DISABLE=(
Expand Down Expand Up @@ -38,6 +39,7 @@ MOUNT_POINT="/data_migration"
LOG_FILE="/var/log/pg-upgrade-initiate.log"

POST_UPGRADE_EXTENSION_SCRIPT="/tmp/pg_upgrade/pg_upgrade_extensions.sql"
POST_UPGRADE_POSTGRES_PERMS_SCRIPT="/tmp/pg_upgrade/pg_upgrade_postgres_perms.sql"
OLD_PGVERSION=$(run_sql -A -t -c "SHOW server_version;")

SERVER_LC_COLLATE=$(run_sql -A -t -c "SHOW lc_collate;")
Expand All @@ -46,7 +48,6 @@ SERVER_ENCODING=$(run_sql -A -t -c "SHOW server_encoding;")

POSTGRES_CONFIG_PATH="/etc/postgresql/postgresql.conf"
PGBINOLD="/usr/lib/postgresql/bin"
PGLIBOLD="/usr/lib/postgresql/lib"

PG_UPGRADE_BIN_DIR="/tmp/pg_upgrade_bin/$PGVERSION"
NIX_INSTALLER_PATH="/tmp/persistent/nix-installer"
Expand Down Expand Up @@ -119,20 +120,38 @@ cleanup() {
CI_start_postgres
fi

retry 8 pg_isready -h localhost -U supabase_admin

echo "Re-enabling extensions"
if [ -f $POST_UPGRADE_EXTENSION_SCRIPT ]; then
run_sql -f $POST_UPGRADE_EXTENSION_SCRIPT
retry 5 run_sql -f $POST_UPGRADE_EXTENSION_SCRIPT
fi

echo "Removing SUPERUSER grant from postgres"
run_sql -c "ALTER USER postgres WITH NOSUPERUSER;"
retry 5 run_sql -c "ALTER USER postgres WITH NOSUPERUSER;"

echo "Resetting postgres database connection limit"
run_sql -c "ALTER DATABASE postgres CONNECTION LIMIT -1;"
retry 5 run_sql -c "ALTER DATABASE postgres CONNECTION LIMIT -1;"

echo "Making sure postgres still has access to pg_shadow"
cat << EOF >> $POST_UPGRADE_POSTGRES_PERMS_SCRIPT
DO \$\$
begin
if exists (select from pg_authid where rolname = 'pg_read_all_data') then
execute('grant pg_read_all_data to postgres');
end if;
end
\$\$;
grant pg_signal_backend to postgres;
EOF

if [ -f $POST_UPGRADE_POSTGRES_PERMS_SCRIPT ]; then
retry 5 run_sql -f $POST_UPGRADE_POSTGRES_PERMS_SCRIPT
fi

if [ -z "$IS_CI" ] && [ -z "$IS_LOCAL_UPGRADE" ]; then
echo "Unmounting data disk from ${MOUNT_POINT}"
umount $MOUNT_POINT
retry 3 umount $MOUNT_POINT
fi
echo "$UPGRADE_STATUS" > /tmp/pg-upgrade-status

Expand All @@ -145,6 +164,14 @@ cleanup() {
}

function handle_extensions {
if [ -z "$IS_CI" ]; then
retry 5 systemctl restart postgresql
else
CI_start_postgres
fi

retry 8 pg_isready -h localhost -U supabase_admin

rm -f $POST_UPGRADE_EXTENSION_SCRIPT
touch $POST_UPGRADE_EXTENSION_SCRIPT

Expand Down Expand Up @@ -178,58 +205,6 @@ EOF
done
}

function patch_wrappers {
local IS_NIX_UPGRADE=$1

WRAPPERS_ENABLED=$(run_sql -A -t -c "SELECT EXISTS(SELECT 1 FROM pg_extension WHERE extname = 'wrappers');")
if [ "$WRAPPERS_ENABLED" = "f" ]; then
echo "Wrappers extension not enabled. Skipping."
return
fi

# This is a workaround for older versions of wrappers which don't have the expected
# naming scheme, containing the version in their library's file name
# e.g. wrappers-0.1.16.so, rather than wrappers.so
# pg_upgrade errors out when it doesn't find an equivalent file in the new PG version's
# library directory, so we're making sure the new version has the expected (old version's)
# file name.
# After the upgrade completes, the new version's library file is used.
# i.e.
# - old version: wrappers-0.1.16.so
# - new version: wrappers-0.1.18.so
# - workaround to make pg_upgrade happy: copy wrappers-0.1.18.so to wrappers-0.1.16.so
if [ "$IS_NIX_UPGRADE" = "true" ]; then
if [ -d "$PGLIBOLD" ]; then
OLD_WRAPPER_LIB_PATH=$(find "$PGLIBOLD" -name "wrappers*so" -print -quit)
OLD_LIB_FILE_NAME=$(basename "$OLD_WRAPPER_LIB_PATH")

find /nix/store/ -name "wrappers*so" -print0 | while read -r -d $'\0' WRAPPERS_LIB_PATH; do
if [ -f "$WRAPPERS_LIB_PATH" ]; then
WRAPPERS_LIB_PATH_DIR=$(dirname "$WRAPPERS_LIB_PATH")
if [ "$WRAPPERS_LIB_PATH" != "$WRAPPERS_LIB_PATH_DIR/${OLD_LIB_FILE_NAME}" ]; then
echo "Copying $WRAPPERS_LIB_PATH to $WRAPPERS_LIB_PATH_DIR/${OLD_LIB_FILE_NAME}"
cp "$WRAPPERS_LIB_PATH" "$WRAPPERS_LIB_PATH_DIR/${OLD_LIB_FILE_NAME}"
fi
fi
done
fi
else
if [ -d "$PGLIBOLD" ]; then
WRAPPERS_LIB_PATH=$(find "$PGLIBNEW" -name "wrappers*so" -print -quit)
if [ -f "$WRAPPERS_LIB_PATH" ]; then
OLD_WRAPPER_LIB_PATH=$(find "$PGLIBOLD" -name "wrappers*so" -print -quit)
if [ -f "$OLD_WRAPPER_LIB_PATH" ]; then
LIB_FILE_NAME=$(basename "$OLD_WRAPPER_LIB_PATH")
if [ "$WRAPPERS_LIB_PATH" != "$PGLIBNEW/${LIB_FILE_NAME}" ]; then
echo "Copying $WRAPPERS_LIB_PATH to $PGLIBNEW/${LIB_FILE_NAME}"
cp "$WRAPPERS_LIB_PATH" "$PGLIBNEW/${LIB_FILE_NAME}"
fi
fi
fi
fi
fi
}

function initiate_upgrade {
mkdir -p "$MOUNT_POINT"
SHARED_PRELOAD_LIBRARIES=$(cat "$POSTGRES_CONFIG_PATH" | grep shared_preload_libraries | sed "s/shared_preload_libraries =\s\{0,1\}'\(.*\)'.*/\1/")
Expand Down Expand Up @@ -406,8 +381,6 @@ function initiate_upgrade {
export LD_LIBRARY_PATH="${PGLIBNEW}"
fi

patch_wrappers "$IS_NIX_UPGRADE"

echo "9. Creating new data directory, initializing database"
chown -R postgres:postgres "$MOUNT_POINT/"
rm -rf "${PGDATANEW:?}/"
Expand Down Expand Up @@ -470,6 +443,7 @@ EOF
cp -R /etc/postgresql-custom/* "$MOUNT_POINT/conf/"
# removing supautils config as to allow the latest one provided by the latest image to be used
rm -f "$MOUNT_POINT/conf/supautils.conf" || true
rm -rf "$MOUNT_POINT/conf/extension-custom-scripts" || true

# removing wal-g config as to allow it to be explicitly enabled on the new instance
rm -f "$MOUNT_POINT/conf/wal-g.conf"
Expand Down
2 changes: 2 additions & 0 deletions ansible/files/adminapi.sudoers.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Cmnd_Alias PGBOUNCER = /bin/systemctl start pgbouncer.service, /bin/systemctl st
%adminapi ALL= NOPASSWD: /usr/bin/systemctl restart postgresql.service
%adminapi ALL= NOPASSWD: /usr/bin/systemctl show -p NRestarts postgresql.service
%adminapi ALL= NOPASSWD: /usr/bin/systemctl restart adminapi.service
%adminapi ALL= NOPASSWD: /usr/bin/systemctl is-active commence-backup.service
%adminapi ALL= NOPASSWD: /usr/bin/systemctl start commence-backup.service
%adminapi ALL= NOPASSWD: /bin/systemctl daemon-reload
%adminapi ALL= NOPASSWD: /bin/systemctl restart services.slice
%adminapi ALL= NOPASSWD: /usr/sbin/nft -f /etc/nftables/supabase_managed.conf
Expand Down
12 changes: 12 additions & 0 deletions ansible/files/commence-backup.service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Async commence physical backup

[Service]
Type=simple
User=adminapi
ExecStart=/usr/bin/admin-mgr commence-backup --run-as-service true
Restart=no
OOMScoreAdjust=-1000

[Install]
WantedBy=multi-user.target
23 changes: 22 additions & 1 deletion ansible/files/envoy_config/lds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,13 @@ resources:
type.googleapis.com/envoy.extensions.filters.http.rbac.v3.RBACPerRoute
- match:
safe_regex:
google_re2:
max_program_size: 150
regex: >-
/auth/v1/(verify|callback|authorize|sso/saml/(acs|metadata|slo))
/auth/v1/(verify|callback|authorize|sso/saml/(acs|metadata|slo)|\.well-known/(openid-configuration|jwks\.json))
request_headers_to_remove:
- apikey
- sb-opk
route:
cluster: gotrue
regex_rewrite:
Expand All @@ -269,6 +274,9 @@ resources:
typed_per_filter_config: *ref_0
- match:
prefix: /auth/v1/
request_headers_to_remove:
- apikey
- sb-opk
route:
cluster: gotrue
prefix_rewrite: /
Expand All @@ -280,6 +288,7 @@ resources:
present_match: true
request_headers_to_remove:
- apikey
- sb-opk
route:
cluster: postgrest
prefix_rewrite: /
Expand All @@ -293,6 +302,7 @@ resources:
prefix: /rest/v1/
request_headers_to_remove:
- apikey
- sb-opk
route:
cluster: postgrest
prefix_rewrite: /
Expand All @@ -309,6 +319,7 @@ resources:
present_match: true
request_headers_to_remove:
- apikey
- sb-opk
route:
cluster: postgrest_admin
prefix_rewrite: /
Expand All @@ -321,6 +332,7 @@ resources:
prefix: /rest-admin/v1/
request_headers_to_remove:
- apikey
- sb-opk
route:
cluster: postgrest_admin
prefix_rewrite: /
Expand All @@ -330,18 +342,25 @@ resources:
header:
key: Content-Profile
value: graphql_public
request_headers_to_remove:
- apikey
- sb-opk
route:
cluster: postgrest
prefix_rewrite: /rpc/graphql
timeout: 125s
- match:
prefix: /admin/v1/
request_headers_to_remove:
- sb-opk
route:
cluster: admin_api
prefix_rewrite: /
timeout: 600s
- match:
prefix: /customer/v1/privileged/
request_headers_to_remove:
- sb-opk
route:
cluster: admin_api
prefix_rewrite: /privileged/
Expand All @@ -365,6 +384,8 @@ resources:
treat_missing_header_as_empty: true
- match:
prefix: /metrics/aggregated
request_headers_to_remove:
- sb-opk
route:
cluster: admin_api
prefix_rewrite: /supabase-internal/metrics
Expand Down
2 changes: 1 addition & 1 deletion ansible/files/postgresql_config/postgresql.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ default_text_search_config = 'pg_catalog.english'
#local_preload_libraries = ''
#session_preload_libraries = ''

shared_preload_libraries = 'pg_stat_statements, pg_stat_monitor, pgaudit, plpgsql, plpgsql_check, pg_cron, pg_net, pgsodium, timescaledb, auto_explain, pg_tle, plan_filter' # (change requires restart)
shared_preload_libraries = 'pg_stat_statements, pgaudit, plpgsql, plpgsql_check, pg_cron, pg_net, pgsodium, timescaledb, auto_explain, pg_tle, plan_filter' # (change requires restart)
jit_provider = 'llvmjit' # JIT library to use

# - Other Defaults -
Expand Down
Loading
Loading