Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Dockerfile-15
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,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
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile-17
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile-multigres
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ RUN mkdir -p \
/etc/postgresql-custom

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
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile-orioledb-17
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
99 changes: 20 additions & 79 deletions ansible/files/postgresql_config/pg_hba.conf.j2
Original file line number Diff line number Diff line change
@@ -1,94 +1,35 @@
# 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

# trust local connections
local all supabase_admin scram-sha-256
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
95 changes: 95 additions & 0 deletions ansible/files/postgresql_config/pg_hba.conf_15.j2
Original file line number Diff line number Diff line change
@@ -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

2 changes: 2 additions & 0 deletions ansible/files/postgresql_config/pg_hba_public.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
host all all 0.0.0.0/0 scram-sha-256
host all all ::0/0 scram-sha-256
11 changes: 11 additions & 0 deletions ansible/files/postgresql_config/pg_hba_users_public.conf.j2
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion ansible/tasks/setup-pgbouncer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,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'
Expand Down
37 changes: 33 additions & 4 deletions ansible/tasks/setup-postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,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'
Expand All @@ -179,7 +178,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
file:
Expand All @@ -190,6 +189,36 @@
mode: 0664
when: not is_psql_15

- 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

# Install extensions before init
- name: Install Postgres extensions
ansible.builtin.import_tasks:
Expand Down Expand Up @@ -376,7 +405,7 @@
dest: '/var/lib/postgresql/.bashrc'
line: "{{ lang_item }}"
become: true
loop:
loop:
- 'export LOCALE_ARCHIVE=/usr/lib/locale/locale-archive'
- 'export LANG="en_US.UTF-8"'
- 'export LANGUAGE="en_US.UTF-8"'
Expand Down
5 changes: 2 additions & 3 deletions ansible/tasks/test-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,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'
Expand Down
6 changes: 3 additions & 3 deletions ansible/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ postgres_major:

# Full version strings for each major version
postgres_release:
postgresorioledb-17: "17.6.0.061-orioledb"
postgres17: "17.6.1.104"
postgres15: "15.14.1.104"
postgresorioledb-17: "17.6.0.061-orioledb-hba"
postgres17: "17.6.1.104-hba"
postgres15: "15.14.1.104-hba"

# Non Postgres Extensions
pgbouncer_release: 1.25.1
Expand Down
1 change: 1 addition & 0 deletions nix/checks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
PGSODIUM_GETKEY = "${getkey-script}/bin/pgsodium-getkey";
PGSQL_DEFAULT_PORT = pgPort;
};
version = majorVersion;
};

getVersionArg =
Expand Down
13 changes: 12 additions & 1 deletion nix/ext/tests/lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading