diff --git a/Dockerfile-15 b/Dockerfile-15 index 2bd2038fe..7aa73f25b 100644 --- a/Dockerfile-15 +++ b/Dockerfile-15 @@ -127,7 +127,7 @@ RUN chown -R postgres:postgres /usr/lib/postgresql && \ # Setup configs COPY --chown=postgres:postgres ansible/files/postgresql_config/postgresql.conf.j2 /etc/postgresql/postgresql.conf -COPY --chown=postgres:postgres ansible/files/postgresql_config/pg_hba.conf.j2 /etc/postgresql/pg_hba.conf +COPY --chown=postgres:postgres ansible/files/postgresql_config/pg_hba.conf_15.j2 /etc/postgresql/pg_hba.conf COPY --chown=postgres:postgres ansible/files/postgresql_config/pg_ident.conf.j2 /etc/postgresql/pg_ident.conf COPY --chown=postgres:postgres ansible/files/postgresql_config/conf.d /etc/postgresql-custom/conf.d COPY --chown=postgres:postgres ansible/files/postgresql_config/postgresql-stdout-log.conf /etc/postgresql/logging.conf diff --git a/Dockerfile-17 b/Dockerfile-17 index b79dd3787..e88b6fa22 100644 --- a/Dockerfile-17 +++ b/Dockerfile-17 @@ -128,6 +128,8 @@ RUN chown -R postgres:postgres /usr/lib/postgresql && \ # Setup configs COPY --chown=postgres:postgres ansible/files/postgresql_config/postgresql.conf.j2 /etc/postgresql/postgresql.conf COPY --chown=postgres:postgres ansible/files/postgresql_config/pg_hba.conf.j2 /etc/postgresql/pg_hba.conf +COPY --chown=postgres:postgres ansible/files/postgresql_config/pg_hba_users_public.conf.j2 /etc/postgresql/pg_hba_users_public.conf +COPY --chown=postgres:postgres ansible/files/postgresql_config/pg_hba_public.conf.j2 /etc/postgresql/pg_hba_public.conf COPY --chown=postgres:postgres ansible/files/postgresql_config/pg_ident.conf.j2 /etc/postgresql/pg_ident.conf COPY --chown=postgres:postgres ansible/files/postgresql_config/conf.d /etc/postgresql-custom/conf.d COPY --chown=postgres:postgres ansible/files/postgresql_config/postgresql-stdout-log.conf /etc/postgresql/logging.conf diff --git a/Dockerfile-orioledb-17 b/Dockerfile-orioledb-17 index 7cd70a371..3808f68af 100644 --- a/Dockerfile-orioledb-17 +++ b/Dockerfile-orioledb-17 @@ -128,6 +128,8 @@ RUN chown -R postgres:postgres /usr/lib/postgresql && \ # Setup configs COPY --chown=postgres:postgres ansible/files/postgresql_config/postgresql.conf.j2 /etc/postgresql/postgresql.conf COPY --chown=postgres:postgres ansible/files/postgresql_config/pg_hba.conf.j2 /etc/postgresql/pg_hba.conf +COPY --chown=postgres:postgres ansible/files/postgresql_config/pg_hba_users_public.conf.j2 /etc/postgresql/pg_hba_users_public.conf +COPY --chown=postgres:postgres ansible/files/postgresql_config/pg_hba_public.conf.j2 /etc/postgresql/pg_hba_public.conf COPY --chown=postgres:postgres ansible/files/postgresql_config/pg_ident.conf.j2 /etc/postgresql/pg_ident.conf COPY --chown=postgres:postgres ansible/files/postgresql_config/conf.d /etc/postgresql-custom/conf.d COPY --chown=postgres:postgres ansible/files/postgresql_config/postgresql-stdout-log.conf /etc/postgresql/logging.conf diff --git a/Dockerfile-supabase b/Dockerfile-supabase index 446345d93..595e8e850 100644 --- a/Dockerfile-supabase +++ b/Dockerfile-supabase @@ -145,6 +145,16 @@ RUN chown -R postgres:postgres /usr/lib/postgresql && \ # Setup configs COPY --chown=postgres:postgres ansible/files/postgresql_config/postgresql.conf.j2 /etc/postgresql/postgresql.conf COPY --chown=postgres:postgres ansible/files/postgresql_config/pg_hba.conf.j2 /etc/postgresql/pg_hba.conf +COPY --chown=postgres:postgres ansible/files/postgresql_config/pg_hba.conf_15.j2 /etc/postgresql/pg_hba.conf_15.j2 +COPY --chown=postgres:postgres ansible/files/postgresql_config/pg_hba_public.conf.j2 /etc/postgresql/pg_hba_public.conf +COPY --chown=postgres:postgres ansible/files/postgresql_config/pg_hba_users_public.conf.j2 /etc/postgresql/pg_hba_users_public.conf +# pg_hba.conf include_if_exists requires PG16+; PG15 uses the monolithic file and drops the fragments. +RUN if [ "$PG_VERSION" = "15" ]; then \ + mv /etc/postgresql/pg_hba.conf_15.j2 /etc/postgresql/pg_hba.conf; \ + rm -f /etc/postgresql/pg_hba_public.conf /etc/postgresql/pg_hba_users_public.conf; \ + else \ + rm -f /etc/postgresql/pg_hba.conf_15.j2; \ + fi COPY --chown=postgres:postgres ansible/files/postgresql_config/pg_ident.conf.j2 /etc/postgresql/pg_ident.conf COPY --chown=postgres:postgres ansible/files/postgresql_config/conf.d /etc/postgresql/postgresql.conf.d COPY --chown=postgres:postgres ansible/files/postgresql_config/postgresql-stdout-log.conf /etc/postgresql/logging.conf diff --git a/ansible/files/postgresql_config/pg_hba.conf.j2 b/ansible/files/postgresql_config/pg_hba.conf.j2 index 355dd4dc8..6c819ab80 100755 --- a/ansible/files/postgresql_config/pg_hba.conf.j2 +++ b/ansible/files/postgresql_config/pg_hba.conf.j2 @@ -1,80 +1,10 @@ # PostgreSQL Client Authentication Configuration File # =================================================== # -# Refer to the "Client Authentication" section in the PostgreSQL -# documentation for a complete description of this file. A short -# synopsis follows. -# -# This file controls: which hosts are allowed to connect, how clients -# are authenticated, which PostgreSQL user names they can use, which -# databases they can access. Records take one of these forms: -# -# local DATABASE USER METHOD [OPTIONS] -# host DATABASE USER ADDRESS METHOD [OPTIONS] -# hostssl DATABASE USER ADDRESS METHOD [OPTIONS] -# hostnossl DATABASE USER ADDRESS METHOD [OPTIONS] -# hostgssenc DATABASE USER ADDRESS METHOD [OPTIONS] -# hostnogssenc DATABASE USER ADDRESS METHOD [OPTIONS] -# -# (The uppercase items must be replaced by actual values.) -# -# The first field is the connection type: "local" is a Unix-domain -# socket, "host" is either a plain or SSL-encrypted TCP/IP socket, -# "hostssl" is an SSL-encrypted TCP/IP socket, and "hostnossl" is a -# non-SSL TCP/IP socket. Similarly, "hostgssenc" uses a -# GSSAPI-encrypted TCP/IP socket, while "hostnogssenc" uses a -# non-GSSAPI socket. -# -# DATABASE can be "all", "sameuser", "samerole", "replication", a -# database name, or a comma-separated list thereof. The "all" -# keyword does not match "replication". Access to replication -# must be enabled in a separate record (see example below). -# -# USER can be "all", a user name, a group name prefixed with "+", or a -# comma-separated list thereof. In both the DATABASE and USER fields -# you can also write a file name prefixed with "@" to include names -# from a separate file. -# -# ADDRESS specifies the set of hosts the record matches. It can be a -# host name, or it is made up of an IP address and a CIDR mask that is -# an integer (between 0 and 32 (IPv4) or 128 (IPv6) inclusive) that -# specifies the number of significant bits in the mask. A host name -# that starts with a dot (.) matches a suffix of the actual host name. -# Alternatively, you can write an IP address and netmask in separate -# columns to specify the set of hosts. Instead of a CIDR-address, you -# can write "samehost" to match any of the server's own IP addresses, -# or "samenet" to match any address in any subnet that the server is -# directly connected to. -# -# METHOD can be "trust", "reject", "md5", "password", "scram-sha-256", -# "gss", "sspi", "ident", "peer", "pam", "ldap", "radius" or "cert". -# Note that "password" sends passwords in clear text; "md5" or -# "scram-sha-256" are preferred since they send encrypted passwords. -# -# OPTIONS are a set of options for the authentication in the format -# NAME=VALUE. The available options depend on the different -# authentication methods -- refer to the "Client Authentication" -# section in the documentation for a list of which options are -# available for which authentication methods. -# -# Database and user names containing spaces, commas, quotes and other -# special characters must be quoted. Quoting one of the keywords -# "all", "sameuser", "samerole" or "replication" makes the name lose -# its special character, and just match a database or username with -# that name. -# -# This file is read on server startup and when the server receives a -# SIGHUP signal. If you edit the file on a running system, you have to -# SIGHUP the server for the changes to take effect, run "pg_ctl reload", -# or execute "SELECT pg_reload_conf()". -# -# Put your actual configuration here -# ---------------------------------- -# -# If you want to allow non-local connections, you need to add more -# "host" records. In that case you will also need to make PostgreSQL -# listen on a non-local interface via the listen_addresses -# configuration parameter, or via the -i or -h command line switches. +# This file uses the include directive to selectively +# enable features. When present, the included files will +# take effect and order of precedence determines which auth +# rules are applied. # TYPE DATABASE USER ADDRESS METHOD @@ -84,14 +14,25 @@ # security boundary than a database password. local all supabase_admin trust local all all peer map=supabase_map + +include_if_exists pg_hba_pam_local.conf + host all all 127.0.0.1/32 trust host all all ::1/128 trust -# IPv4 external connections host all all 10.0.0.0/8 scram-sha-256 -host all all 172.16.0.0/12 scram-sha-256 +host all all 172.16.0.0/12 scram-sha-256 host all all 192.168.0.0/16 scram-sha-256 -host all all 0.0.0.0/0 scram-sha-256 -# IPv6 external connections -host all all ::0/0 scram-sha-256 +# if ssl is enforced, these files will exist and take precedence +include_if_exists pg_hba_users_public_ssl.conf +include_if_exists pg_hba_pam_public_ssl.conf +include_if_exists pg_hba_public_ssl.conf + +# otherwise, non ssl enforced rules will apply +include_if_exists pg_hba_users_public.conf +include_if_exists pg_hba_pam_public.conf +include_if_exists pg_hba_public.conf + +host replication supabase_replication_admin 0.0.0.0/0 scram-sha-256 +host replication supabase_replication_admin ::0/0 scram-sha-256 diff --git a/ansible/files/postgresql_config/pg_hba.conf_15.j2 b/ansible/files/postgresql_config/pg_hba.conf_15.j2 new file mode 100644 index 000000000..9fb1a688d --- /dev/null +++ b/ansible/files/postgresql_config/pg_hba.conf_15.j2 @@ -0,0 +1,95 @@ +# PostgreSQL Client Authentication Configuration File +# =================================================== +# +# Refer to the "Client Authentication" section in the PostgreSQL +# documentation for a complete description of this file. A short +# synopsis follows. +# +# This file controls: which hosts are allowed to connect, how clients +# are authenticated, which PostgreSQL user names they can use, which +# databases they can access. Records take one of these forms: +# +# local DATABASE USER METHOD [OPTIONS] +# host DATABASE USER ADDRESS METHOD [OPTIONS] +# hostssl DATABASE USER ADDRESS METHOD [OPTIONS] +# hostnossl DATABASE USER ADDRESS METHOD [OPTIONS] +# hostgssenc DATABASE USER ADDRESS METHOD [OPTIONS] +# hostnogssenc DATABASE USER ADDRESS METHOD [OPTIONS] +# +# (The uppercase items must be replaced by actual values.) +# +# The first field is the connection type: "local" is a Unix-domain +# socket, "host" is either a plain or SSL-encrypted TCP/IP socket, +# "hostssl" is an SSL-encrypted TCP/IP socket, and "hostnossl" is a +# non-SSL TCP/IP socket. Similarly, "hostgssenc" uses a +# GSSAPI-encrypted TCP/IP socket, while "hostnogssenc" uses a +# non-GSSAPI socket. +# +# DATABASE can be "all", "sameuser", "samerole", "replication", a +# database name, or a comma-separated list thereof. The "all" +# keyword does not match "replication". Access to replication +# must be enabled in a separate record (see example below). +# +# USER can be "all", a user name, a group name prefixed with "+", or a +# comma-separated list thereof. In both the DATABASE and USER fields +# you can also write a file name prefixed with "@" to include names +# from a separate file. +# +# ADDRESS specifies the set of hosts the record matches. It can be a +# host name, or it is made up of an IP address and a CIDR mask that is +# an integer (between 0 and 32 (IPv4) or 128 (IPv6) inclusive) that +# specifies the number of significant bits in the mask. A host name +# that starts with a dot (.) matches a suffix of the actual host name. +# Alternatively, you can write an IP address and netmask in separate +# columns to specify the set of hosts. Instead of a CIDR-address, you +# can write "samehost" to match any of the server's own IP addresses, +# or "samenet" to match any address in any subnet that the server is +# directly connected to. +# +# METHOD can be "trust", "reject", "md5", "password", "scram-sha-256", +# "gss", "sspi", "ident", "peer", "pam", "ldap", "radius" or "cert". +# Note that "password" sends passwords in clear text; "md5" or +# "scram-sha-256" are preferred since they send encrypted passwords. +# +# OPTIONS are a set of options for the authentication in the format +# NAME=VALUE. The available options depend on the different +# authentication methods -- refer to the "Client Authentication" +# section in the documentation for a list of which options are +# available for which authentication methods. +# +# Database and user names containing spaces, commas, quotes and other +# special characters must be quoted. Quoting one of the keywords +# "all", "sameuser", "samerole" or "replication" makes the name lose +# its special character, and just match a database or username with +# that name. +# +# This file is read on server startup and when the server receives a +# SIGHUP signal. If you edit the file on a running system, you have to +# SIGHUP the server for the changes to take effect, run "pg_ctl reload", +# or execute "SELECT pg_reload_conf()". +# +# Put your actual configuration here +# ---------------------------------- +# +# If you want to allow non-local connections, you need to add more +# "host" records. In that case you will also need to make PostgreSQL +# listen on a non-local interface via the listen_addresses +# configuration parameter, or via the -i or -h command line switches. + +# TYPE DATABASE USER ADDRESS METHOD + +# trust local connections +local all supabase_admin scram-sha-256 +local all all peer map=supabase_map +host all all 127.0.0.1/32 trust +host all all ::1/128 trust + +# IPv4 external connections +host all all 10.0.0.0/8 scram-sha-256 +host all all 172.16.0.0/12 scram-sha-256 +host all all 192.168.0.0/16 scram-sha-256 +host all all 0.0.0.0/0 scram-sha-256 + +# IPv6 external connections +host all all ::0/0 scram-sha-256 + diff --git a/ansible/files/postgresql_config/pg_hba_public.conf.j2 b/ansible/files/postgresql_config/pg_hba_public.conf.j2 new file mode 100644 index 000000000..80c54d2be --- /dev/null +++ b/ansible/files/postgresql_config/pg_hba_public.conf.j2 @@ -0,0 +1,2 @@ +host all all 0.0.0.0/0 scram-sha-256 +host all all ::0/0 scram-sha-256 diff --git a/ansible/files/postgresql_config/pg_hba_users_public.conf.j2 b/ansible/files/postgresql_config/pg_hba_users_public.conf.j2 new file mode 100644 index 000000000..ccc167984 --- /dev/null +++ b/ansible/files/postgresql_config/pg_hba_users_public.conf.j2 @@ -0,0 +1,11 @@ +host all pgbouncer 0.0.0.0/0 scram-sha-256 +host all supabase_admin 0.0.0.0/0 scram-sha-256 +host all supabase_auth_admin 0.0.0.0/0 scram-sha-256 +host all supabase_storage_admin 0.0.0.0/0 scram-sha-256 +host all supabase_replication_admin 0.0.0.0/0 scram-sha-256 + +host all pgbouncer ::0/0 scram-sha-256 +host all supabase_admin ::0/0 scram-sha-256 +host all supabase_auth_admin ::0/0 scram-sha-256 +host all supabase_storage_admin ::0/0 scram-sha-256 +host all supabase_replication_admin ::0/0 scram-sha-256 diff --git a/ansible/tasks/setup-pgbouncer.yml b/ansible/tasks/setup-pgbouncer.yml index daeeb35d0..c2bc0df4d 100644 --- a/ansible/tasks/setup-pgbouncer.yml +++ b/ansible/tasks/setup-pgbouncer.yml @@ -63,7 +63,7 @@ owner: 'pgbouncer' path: '/etc/pgbouncer/userlist.txt' state: 'touch' - + - name: import /etc/tmpfiles.d/pgbouncer.conf ansible.builtin.template: dest: '/etc/tmpfiles.d/pgbouncer.conf' diff --git a/ansible/tasks/setup-postgres.yml b/ansible/tasks/setup-postgres.yml index c4d065451..22b4054cf 100644 --- a/ansible/tasks/setup-postgres.yml +++ b/ansible/tasks/setup-postgres.yml @@ -79,14 +79,13 @@ loop_control: loop_var: 'pg_config_item' - - name: import postgresql.conf, pg_hba.conf, and pg_ident.conf + - name: import postgresql.conf and pg_ident.conf ansible.builtin.template: dest: '/etc/postgresql/{{ pg_config_item }}' group: 'postgres' src: 'files/postgresql_config/{{ pg_config_item }}.j2' loop: - 'postgresql.conf' - - 'pg_hba.conf' - 'pg_ident.conf' loop_control: loop_var: 'pg_config_item' @@ -109,7 +108,7 @@ block: - name: Check if psql_version is psql_15 ansible.builtin.set_fact: - is_psql_15: "{{ psql_version in ['psql_15'] }}" + is_psql_15: "{{ psql_version == 'psql_15' or postgresql_major | int == 15 }}" - name: create placeholder pam config when: not is_psql_15 @@ -120,6 +119,36 @@ group: postgres mode: 0664 + - name: import pg_hba.conf psql_15 + ansible.builtin.template: + dest: /etc/postgresql/pg_hba.conf + src: files/postgresql_config/pg_hba.conf_15.j2 + group: postgres + when: is_psql_15 + + - name: create pg_hba.conf with includes + when: not is_psql_15 + block: + - name: import pg_hba.conf + ansible.builtin.template: + dest: /etc/postgresql/pg_hba.conf + src: files/postgresql_config/pg_hba.conf.j2 + group: postgres + + # Add pg_hba_public.conf + - name: import pg_hba_public.conf + ansible.builtin.template: + dest: /etc/postgresql/pg_hba_public.conf + src: files/postgresql_config/pg_hba_public.conf.j2 + group: postgres + + # Add pg_hba_users_public.conf + - name: import pg_hba_users_public.conf + ansible.builtin.template: + dest: /etc/postgresql/pg_hba_users_public.conf + src: files/postgresql_config/pg_hba_users_public.conf.j2 + group: postgres + - name: Create directory on data volume ansible.builtin.file: group: 'postgres' diff --git a/ansible/tasks/test-image.yml b/ansible/tasks/test-image.yml index 493eed114..1e608396c 100644 --- a/ansible/tasks/test-image.yml +++ b/ansible/tasks/test-image.yml @@ -15,9 +15,8 @@ become: true become_user: 'postgres' loop: - - { in: "^(shared_preload_libraries = '.*)pgsodium(.*')", out: '\1\2' } - - { in: "^(shared_preload_libraries = '.*)supabase_vault(.*')", out: '\1\2' } - - { in: "^(shared_preload_libraries = '.*)*supabase_vault(.*')", out: '\1\2' } + - { in: "^(shared_preload_libraries = '[^']*),\\s*pgsodium", out: '\1' } + - { in: "^(shared_preload_libraries = '[^']*),\\s*supabase_vault", out: '\1' } - { in: '^(pgsodium\.getkey_script=)', out: '#\1' } loop_control: loop_var: 'regx' diff --git a/ansible/vars.yml b/ansible/vars.yml index 7d465d395..fc2e2dd2d 100644 --- a/ansible/vars.yml +++ b/ansible/vars.yml @@ -56,6 +56,49 @@ release_matrix_legacy: target: production pg_version: "17" release_key: postgresorioledb-17 + +# Non Postgres Extensions +pgbouncer_release: 1.25.1 +pgbouncer_release_checksum: sha256:6e566ae92fe3ef7f6a1b9e26d6049f7d7ca39c40e29e7b38f6d5500ae15d8465 + +# The checksum can be found under "Assets", in the GitHub release page for each version. +# The binaries used are: ubuntu-aarch64 and linux-static. +# https://github.com/PostgREST/postgrest/releases +postgrest_release: 14.5 +postgrest_arm_release_checksum: sha256:70c07ff875710538903c9b6b6de00e126250e335da25b0ff7d1b13bb4c94bf41 +postgrest_x86_release_checksum: sha256:ab5cc7e974d4940447991804588cfb8b3f7b2c57b691f0905df04d51ede69470 + +gotrue_release: 2.188.1 +gotrue_release_checksum: sha1:236e8c7bb93e1246b3ff31dbda0fbebe6c3114ca + +aws_cli_release: 2.23.11 + +salt_minion_version: 3007 + +golang_version: 1.22.11 +golang_version_checksum: + arm64: sha256:0fc88d966d33896384fbde56e9a8d80a305dc17a9f48f1832e061724b1719991 + amd64: sha256:9ebfcab26801fa4cf0627c6439db7a4da4d3c6766142a3dd83508240e4f21031 + +envoy_release: 1.28.0 +envoy_release_checksum: sha1:b0a06e9cfb170f1993f369beaa5aa9d7ec679ce5 +envoy_hot_restarter_release_checksum: sha1:6d43b89d266fb2427a4b51756b649883b0617eda + +kong_release_target: focal +kong_deb: kong_2.8.1_arm64.deb +kong_deb_checksum: sha1:2086f6ccf8454fe64435252fea4d29d736d7ec61 + +nginx_release: 1.22.0 +nginx_release_checksum: sha1:419efb77b80f165666e2ee406ad8ae9b845aba93 + +postgres_exporter_release: "0.15.0" +postgres_exporter_release_checksum: + arm64: sha256:29ba62d538b92d39952afe12ee2e1f4401250d678ff4b354ff2752f4321c87a0 + amd64: sha256:cb89fc5bf4485fb554e0d640d9684fae143a4b2d5fa443009bd29c59f9129e84 + +adminapi_release: "0.95.1" +adminmgr_release: "0.32.3" +supabase_admin_agent_release: 1.6.0 supabase_admin_agent_splay: 30s ############################################################################################################### # The following block of yaml is for get_url and co throughout the playbook # diff --git a/nix/checks.nix b/nix/checks.nix index 55fb676b9..9ab937709 100644 --- a/nix/checks.nix +++ b/nix/checks.nix @@ -163,6 +163,7 @@ PGSODIUM_GETKEY = "${getkey-script}/bin/pgsodium-getkey"; PGSQL_DEFAULT_PORT = pgPort; }; + version = majorVersion; }; getVersionArg = diff --git a/nix/ext/tests/lib.nix b/nix/ext/tests/lib.nix index 9c268f35f..3e9e5c5e3 100644 --- a/nix/ext/tests/lib.nix +++ b/nix/ext/tests/lib.nix @@ -48,7 +48,18 @@ let mkdir -p $out/conf.d $out/extension-custom-scripts # Copy ansible config files (make writable so we can append/modify later) - cp ${ansibleConfigDir}/pg_hba.conf.j2 $out/pg_hba.conf + ${ + if majorVersion == "15" then + '' + cp ${ansibleConfigDir}/pg_hba.conf_15.j2 $out/pg_hba.conf + '' + else + '' + cp ${ansibleConfigDir}/pg_hba.conf.j2 $out/pg_hba.conf + cp ${ansibleConfigDir}/pg_hba_public.conf.j2 $out/pg_hba_public.conf + cp ${ansibleConfigDir}/pg_hba_users_public.conf.j2 $out/pg_hba_users_public.conf + '' + } cp ${ansibleConfigDir}/pg_ident.conf.j2 $out/pg_ident.conf chmod u+w $out/pg_hba.conf $out/pg_ident.conf diff --git a/nix/packages/default.nix b/nix/packages/default.nix index c6f1a2939..4bc4b0e8b 100644 --- a/nix/packages/default.nix +++ b/nix/packages/default.nix @@ -101,6 +101,7 @@ inherit pkgs; name = "start-postgres-server"; pgroonga = self'.legacyPackages."psql_${activeVersion}".exts.pgroonga; + version = activeVersion; }; switch-ext-version = pkgs.callPackage ./switch-ext-version.nix { inherit (self'.packages) overlayfs-on-package; diff --git a/nix/packages/lib.nix b/nix/packages/lib.nix index 23e600796..01bbd68f7 100644 --- a/nix/packages/lib.nix +++ b/nix/packages/lib.nix @@ -5,6 +5,7 @@ defaults, supabase-groonga, stdenv, + lib, }: { makePostgresDevSetup = @@ -13,9 +14,10 @@ name, pgroonga, extraSubstitutions ? { }, + version, }: let - paths = { + basePaths = { migrationsDir = builtins.path { name = "migrations"; path = ../../migrations/db; @@ -52,10 +54,6 @@ name = "readreplica.conf"; path = ../../ansible/files/postgresql_config/custom_read_replica.conf; }; - pgHbaConfigFile = builtins.path { - name = "pg_hba.conf"; - path = ../../ansible/files/postgresql_config/pg_hba.conf.j2; - }; pgIdentConfigFile = builtins.path { name = "pg_ident.conf"; path = ../../ansible/files/postgresql_config/pg_ident.conf.j2; @@ -69,6 +67,30 @@ path = ../tests/util/pgsodium_getkey.sh; }; }; + extraPaths = + if version == "15" then + { + pgHbaConfigFile = builtins.path { + name = "pg_hba.conf"; + path = ../../ansible/files/postgresql_config/pg_hba.conf_15.j2; + }; + } + else + { + pgHbaConfigFile = builtins.path { + name = "pg_hba.conf"; + path = ../../ansible/files/postgresql_config/pg_hba.conf.j2; + }; + pgHbaUsersPublicConfigFile = builtins.path { + name = "pg_hba_users_public.conf"; + path = ../../ansible/files/postgresql_config/pg_hba_users_public.conf.j2; + }; + pgHbaPublicConfigFile = builtins.path { + name = "pg_hba_public.conf"; + path = ../../ansible/files/postgresql_config/pg_hba_public.conf.j2; + }; + }; + paths = basePaths // extraPaths; localeArchive = if pkgs.stdenv.isDarwin then @@ -126,6 +148,17 @@ cp ${paths.loggingConfigFile} $out/etc/postgresql-custom/logging.conf || { echo "Failed to copy logging.conf"; exit 1; } cp ${paths.readReplicaConfigFile} $out/etc/postgresql-custom/read-replica.conf || { echo "Failed to copy read-replica.conf"; exit 1; } cp ${paths.pgHbaConfigFile} $out/etc/postgresql/pg_hba.conf || { echo "Failed to copy pg_hba.conf"; exit 1; } + + # these shouldn't exist on psql_15 + ${lib.optionalString (paths ? pgHbaUsersPublicConfigFile) '' + cp ${paths.pgHbaUsersPublicConfigFile} $out/etc/postgresql/pg_hba_users_public.conf || { echo "Failed to copy pg_hba_users_public.conf"; exit 1; } + chmod 664 $out/etc/postgresql/pg_hba_users_public.conf + ''} + ${lib.optionalString (paths ? pgHbaPublicConfigFile) '' + cp ${paths.pgHbaPublicConfigFile} $out/etc/postgresql/pg_hba_public.conf || { echo "Failed to copy pg_hba_public.conf"; exit 1; } + chmod 664 $out/etc/postgresql/pg_hba_public.conf + ''} + cp ${paths.pgIdentConfigFile} $out/etc/postgresql/pg_ident.conf || { echo "Failed to copy pg_ident.conf"; exit 1; } cp -r ${paths.postgresqlExtensionCustomScriptsPath}/* $out/extension-custom-scripts/ || { echo "Failed to copy custom scripts"; exit 1; } @@ -133,7 +166,7 @@ chmod 644 $out/etc/postgresql-custom/supautils.conf chmod 644 $out/etc/postgresql/postgresql.conf chmod 644 $out/etc/postgresql-custom/logging.conf - chmod 644 $out/etc/postgresql/pg_hba.conf + chmod 664 $out/etc/postgresql/pg_hba.conf substitute ${../tools/run-server.sh.in} $out/bin/start-postgres-server \ ${builtins.concatStringsSep " " ( diff --git a/nix/tools/run-server.sh.in b/nix/tools/run-server.sh.in index 333f062bc..938990380 100644 --- a/nix/tools/run-server.sh.in +++ b/nix/tools/run-server.sh.in @@ -34,10 +34,10 @@ start_postgres() { # Start the server pg_ctl start -D "$DATDIR" -l "$LOG_FILE" \ -o "--config-file=$DATDIR/postgresql.conf -p $PORTNO -k $DATDIR/tmp" - + # Give it a moment to write logs sleep 1 - + # Check server status and logs if ! pg_ctl status -D "$DATDIR"; then echo "PostgreSQL failed to start. Full logs:" @@ -192,7 +192,7 @@ export LC_CTYPE=en_US.UTF-8 export KEY_FILE="$DATDIR/pgsodium.key" echo "KEY_FILE: $KEY_FILE" echo "KEY_FILE contents:" -cat "$KEY_FILE" +cat "$KEY_FILE" echo "PGSODIUM_GETKEY_SCRIPT: $PGSODIUM_GETKEY_SCRIPT" echo "NOTE: using port $PORTNO for server" @@ -213,7 +213,17 @@ fi # Copy configuration files echo "NOTE: patching postgresql.conf files" -cp "$PG_HBA_FILE" "$DATDIR/pg_hba.conf" +if [ "$VERSION" = "15" ]; then + cp $(dirname "$PG_HBA_FILE")/pg_hba.conf_15* "$DATDIR/pg_hba.conf" +else + cp "${PG_HBA_FILE}" "$DATDIR/pg_hba.conf" + # copy extra hba_*.conf files over + extra_hba_files=( ${PG_HBA_FILE%pg_hba.conf}pg_hba_*.conf* ) + for f in "${extra_hba_files[@]}"; do + base=$(basename "$f") + cp "$f" "$DATDIR/${base%%.conf*}.conf" + done +fi cp "$PG_IDENT_FILE" "$DATDIR/pg_ident.conf" # Copy entire conf.d directory from postgresql_config POSTGRESQL_CONFIG_DIR="@POSTGRESQL_CONFIG_DIR@" @@ -260,16 +270,16 @@ orioledb_config_items() { # macOS specific configuration echo "macOS detected, applying macOS specific configuration" ls -la "$DATDIR" - + # Use perl instead of sed for macOS perl -pi -e 's/ timescaledb,//g' "$DATDIR/postgresql.conf" perl -pi -e 's/db_user_namespace = off/#db_user_namespace = off/g' "$DATDIR/postgresql.conf" - + perl -pi -e 's/ timescaledb,//g' "$DATDIR/supautils.conf" perl -pi -e 's/ plv8,//g' "$DATDIR/supautils.conf" perl -pi -e 's/ pgjwt,//g' "$DATDIR/supautils.conf" perl -pi -e 's/(shared_preload_libraries\s*=\s*'\''.*?)'\''/\1, orioledb'\''/' "$DATDIR/postgresql.conf" - + echo "default_table_access_method = 'orioledb'" >> "$DATDIR/postgresql.conf" elif [[ "$VERSION" == "17" && "$CURRENT_SYSTEM" != "aarch64-darwin" ]]; then echo "non-macos pg 17 conf" @@ -297,7 +307,7 @@ export GRN_PLUGINS_DIR=$GROONGA/lib/groonga/plugins # Start postgres mkdir -p "$DATDIR/tmp" -chmod 1777 "$DATDIR/tmp" +chmod 1777 "$DATDIR/tmp" start_postgres "daemon" # Wait for PostgreSQL to start @@ -377,6 +387,6 @@ stop_postgres # Step 4: Restart PostgreSQL in the foreground (with log output visible) or as a daemon if [ "$DAEMONIZE" = true ]; then start_postgres "daemon" -else +else start_postgres "foreground" fi