Skip to content

Commit c132980

Browse files
committed
Merge develop
2 parents f46bd06 + c4d26b8 commit c132980

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2125
-360
lines changed

.github/workflows/check-shellscripts.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ on:
77
pull_request:
88
workflow_dispatch:
99

10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
12+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
13+
1014
permissions:
1115
contents: read
1216

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ on:
66
permissions:
77
contents: read
88

9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
11+
cancel-in-progress: true
12+
913
jobs:
1014
check-release-version:
1115
timeout-minutes: 5

.github/workflows/nix-build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ permissions:
1414
contents: write
1515
packages: write
1616

17+
concurrency:
18+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
19+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
20+
1721
jobs:
1822
build-run-image:
1923
strategy:

README.md

Lines changed: 214 additions & 34 deletions
Large diffs are not rendered by default.

ansible/files/gotrue.service.j2

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,56 @@
11
[Unit]
22
Description=Gotrue
33

4+
# Avoid starting gotrue while cloud-init is running. It makes a lot of changes
5+
# and I would like to rule out side effects of it running concurrently along
6+
# side services.
7+
After=cloud-init.service
8+
Wants=cloud-init.target
9+
10+
# Given the fact that auth uses SO_REUSEADDR, I want to rule out capabilities
11+
# being modified between restarts early in boot. This plugs up the scenario that
12+
# EADDRINUSE errors originate from a previous gotrue process starting without
13+
# the SO_REUSEADDR flag (due to lacking capability at that point in boot proc)
14+
# so when the next gotrue starts it can't re-use a slow releasing socket.
15+
After=apparmor.service
16+
17+
# We want sysctl's to be applied
18+
After=systemd-sysctl.service
19+
20+
# UFW Is modified by cloud init, but started non-blocking, so configuration
21+
# could be in-flight while gotrue is starting. I want to ensure future rules
22+
# that are relied on for security posture are applied before gotrue runs.
23+
After=ufw.service
24+
25+
# We need networking & resolution, auth uses the Go DNS resolver (not libc)
26+
# so it's possible `localhost` resolution could be unstable early in startup. We
27+
# care about this because SO_REUSEADDR eligibility checks the tuple
28+
# (proto, family, addr, port) meaning the AF_INET (ipv4, ipv6) could affect the
29+
# binding resulting in a second way for EADDRINUSE errors to surface.
30+
#
31+
# Note: We should consider removing localhost usage given `localhost` resolution
32+
# can often be racey early in boot, can be difficult to debug and offers no real
33+
# advantage in our infra. At the very least avoiding DNS resolved binding would
34+
# be a good idea.
35+
Wants=network-online.target systemd-resolved.service
36+
After=network-online.target systemd-resolved.service
37+
38+
# Auth server can't start unless postgres is online, lets remove a lot of auth
39+
# server noise during slow starts by requiring it.
40+
Wants=postgresql.service
41+
After=postgresql.service
42+
43+
# Lower start limit ival and burst to prevent the noisy flapping
44+
StartLimitIntervalSec=10
45+
StartLimitBurst=5
46+
447
[Service]
5-
Type=simple
48+
Type=exec
649
WorkingDirectory=/opt/gotrue
7-
{% if qemu_mode is defined and qemu_mode %}
8-
ExecStart=/opt/gotrue/gotrue
9-
{% else %}
50+
51+
# Both v2 & v3 need a config-dir for reloading support.
1052
ExecStart=/opt/gotrue/gotrue --config-dir /etc/auth.d
11-
{% endif %}
53+
ExecReload=/bin/kill -10 $MAINPID
1254

1355
User=gotrue
1456
Restart=always
@@ -17,11 +59,36 @@ RestartSec=3
1759
MemoryAccounting=true
1860
MemoryMax=50%
1961

62+
# These are the historical location of env files. The /etc/auth.d dir will
63+
# override them when present.
2064
EnvironmentFile=-/etc/gotrue.generated.env
2165
EnvironmentFile=/etc/gotrue.env
2266
EnvironmentFile=-/etc/gotrue.overrides.env
2367

68+
# Both v2 & v3 support reloading via signals, on linux this is SIGUSR1.
69+
Environment=GOTRUE_RELOADING_SIGNAL_ENABLED=true
70+
Environment=GOTRUE_RELOADING_SIGNAL_NUMBER=10
71+
72+
# Both v2 & v3 disable the poller. While gotrue sets it to off by default we
73+
# defensively set it to false here.
74+
Environment=GOTRUE_RELOADING_POLLER_ENABLED=false
75+
76+
# Determines how much idle time must pass before triggering a reload. This
77+
# ensures only 1 reload operation occurs during a burst of config updates.
78+
Environment=GOTRUE_RELOADING_GRACE_PERIOD_INTERVAL=2s
79+
80+
{% if qemu_mode is defined and qemu_mode %}
81+
# v3 does not use filesystem notifications for config reloads.
82+
Environment=GOTRUE_RELOADING_NOTIFY_ENABLED=false
83+
{% else %}
84+
# v2 currently relies on notify support, so we will enable it until both v2 / v3
85+
# have migrated to strictly use signals across all projects. The default is true
86+
# in gotrue but we will set it defensively here.
87+
Environment=GOTRUE_RELOADING_NOTIFY_ENABLED=true
88+
{% endif %}
89+
2490
Slice=services.slice
2591

2692
[Install]
2793
WantedBy=multi-user.target
94+

ansible/files/supabase_admin_agent_config/supabase-admin-agent_salt.service renamed to ansible/files/supabase_admin_agent_config/supabase-admin-agent_salt.service.j2

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@ Requires=local-fs.target
66

77
[Service]
88
Type=oneshot
9+
{% if qemu_mode is defined and qemu_mode %}
10+
ExecStart=/opt/supabase-admin-agent/supabase-admin-agent --config /opt/supabase-admin-agent/config.yaml salt --apply --store-result --salt-archive configmanv3-main.tar.gz
11+
User=root
12+
Group=root
13+
{% else %}
914
ExecStart=/opt/supabase-admin-agent/supabase-admin-agent --config /opt/supabase-admin-agent/config.yaml salt --apply --store-result
1015
User=supabase-admin-agent
1116
Group=supabase-admin-agent
17+
{% endif %}
1218
StandardOutput=journal
1319
StandardError=journal
1420
StateDirectory=supabase-admin-agent

ansible/files/supabase_admin_agent_config/supabase-admin-agent_salt.timer.j2

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,19 @@ Description=Run Supabase supabase-admin-agent salt on a schedule
33
Requires=supabase-admin-agent_salt.service
44

55
[Timer]
6+
{# We're using a significantly lower frequency for triggering this agent on qemu images for the moment. Once we've performed additional validations re: the aggregate impact of running it more frequently, the frequency can be increased. #}
7+
{% if qemu_mode is defined and qemu_mode %}
8+
OnCalendar=*-*-* 0,6,12,18:00:00
9+
RandomizedDelaySec={{ supabase_admin_agent_splay }}
10+
AccuracySec=1h
11+
OnBootSec=5m
12+
Persistent=true
13+
{% else %}
614
OnCalendar=*:0/10
7-
# Random delay up to {{ supabase_admin_agent_splay }} seconds splay
815
RandomizedDelaySec={{ supabase_admin_agent_splay }}
916
AccuracySec=1s
1017
Persistent=true
18+
{% endif %}
1119

1220
[Install]
1321
WantedBy=timers.target

ansible/qemu-vars.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
supabase_admin_agent_splay_secs: 2h

ansible/tasks/clean-build-dependencies.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
- name: Remove build dependencies
2-
apt:
2+
ansible.builtin.apt:
3+
autoremove: true
34
pkg:
45
- bison
56
- build-essential
@@ -17,5 +18,4 @@
1718
- ninja-build
1819
- patch
1920
- python2
20-
state: absent
21-
autoremove: yes
21+
state: 'absent'

ansible/tasks/finalize-ami.yml

Lines changed: 82 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,104 @@
11
- name: PG logging conf
2-
template:
3-
src: files/postgresql_config/postgresql-csvlog.conf
4-
dest: /etc/postgresql/logging.conf
5-
group: postgres
2+
ansible.builtin.template:
3+
dest: '/etc/postgresql/logging.conf'
4+
group: 'postgres'
5+
src: 'files/postgresql_config/postgresql-csvlog.conf'
66

77
- name: UFW - Allow SSH connections
8-
ufw:
9-
rule: allow
10-
name: OpenSSH
8+
community.general.ufw:
9+
name: 'OpenSSH'
10+
rule: 'allow'
1111

12-
- name: UFW - Allow connections to postgreSQL (5432)
13-
ufw:
14-
rule: allow
15-
port: "5432"
12+
- name: UFW - Allow SSH/PostgreSQL connections
13+
community.general.ufw:
14+
port: '5432'
15+
rule: 'allow'
1616

17-
- name: UFW - Allow connections to postgreSQL (6543)
18-
ufw:
19-
rule: allow
20-
port: "6543"
17+
- name: UFW - Allow PgBouncer connections
18+
community.general.ufw:
19+
port: '6543'
20+
rule: 'allow'
2121
tags:
2222
- install-pgbouncer
2323

24-
- name: UFW - Allow connections to http (80)
25-
ufw:
26-
rule: allow
27-
port: http
28-
tags:
29-
- install-supabase-internal
30-
31-
- name: UFW - Allow connections to https (443)
32-
ufw:
33-
rule: allow
34-
port: https
24+
- name: UFW - Allow HTTP/HTTPS connections
25+
community.general.ufw:
26+
port: "{{ port_item }}"
27+
rule: 'allow'
28+
loop:
29+
- 'http'
30+
- 'https'
31+
loop_control:
32+
loop_var: 'port_item'
3533
tags:
36-
- install-supabase-internal
34+
- install-supabase-internal
3735

3836
- name: UFW - Deny all other incoming traffic by default
39-
ufw:
40-
state: enabled
41-
policy: deny
42-
direction: incoming
37+
community.general.ufw:
38+
direction: 'incoming'
39+
policy: 'deny'
40+
state: 'enabled'
4341

4442
- name: Move logrotate files to /etc/logrotate.d/
45-
copy:
46-
src: "files/logrotate_config/{{ item.file }}"
47-
dest: "/etc/logrotate.d/{{ item.file }}"
48-
mode: "0700"
49-
owner: root
43+
ansible.builtin.copy:
44+
dest: "/etc/logrotate.d/{{ logrotate_item['file'] }}"
45+
mode: '0700'
46+
owner: 'root'
47+
src: "files/logrotate_config/{{ logrotate_item['file'] }}"
5048
loop:
51-
- { file: "logrotate-postgres-csv.conf" }
52-
- { file: "logrotate-postgres.conf" }
53-
- { file: "logrotate-walg.conf" }
54-
- { file: "logrotate-postgres-auth.conf" }
49+
- { file: 'logrotate-postgres.conf' }
50+
- { file: 'logrotate-postgres-auth.conf' }
51+
- { file: 'logrotate-postgres-csv.conf' }
52+
- { file: 'logrotate-walg.conf' }
53+
loop_control:
54+
loop_var: 'logrotate_item'
5555

56-
- name: Ensure default Postgres logrotate config is removed
57-
file:
58-
path: /etc/logrotate.d/postgresql-common
59-
state: absent
56+
- name: Ensure default PostgreSQL logrotate config is removed
57+
ansible.builtin.file:
58+
path: '/etc/logrotate.d/postgresql-common'
59+
state: 'absent'
6060

6161
- name: Disable cron access
6262
copy:
63-
src: files/cron.deny
64-
dest: /etc/cron.deny
63+
dest: '/etc/cron.deny'
64+
src: 'files/cron.deny'
65+
66+
- name: Create logrotate.timer.d overrides dir
67+
become: true
68+
ansible.builtin.file:
69+
group: 'root'
70+
mode: '0755'
71+
owner: 'root'
72+
path: '/etc/systemd/system/logrotate.timer.d'
73+
state: 'directory'
74+
75+
- name: Configure logrotate.timer.d overrides
76+
become: true
77+
community.general.ini_file:
78+
group: 'root'
79+
mode: '0644'
80+
no_extra_spaces: true
81+
option: 'OnCalendar'
82+
owner: 'root'
83+
path: '/etc/systemd/system/logrotate.timer.d/override.conf'
84+
section: 'Timer'
85+
state: 'present'
86+
value: '*:0/5'
6587

66-
- name: Configure logrotation to run every hour
67-
shell:
68-
cmd: |
69-
cp /usr/lib/systemd/system/logrotate.timer /etc/systemd/system/logrotate.timer
70-
sed -i -e 's;daily;*:0/5;' /etc/systemd/system/logrotate.timer
71-
systemctl reenable logrotate.timer
72-
become: yes
88+
- name: Reload systemd and start logrotate timer
89+
become: true
90+
ansible.builtin.systemd_service:
91+
daemon_reload: true
92+
enabled: true
93+
name: 'logrotate.timer'
94+
state: 'restarted'
7395

7496
- name: import pgsodium_getkey script
75-
template:
76-
src: files/pgsodium_getkey_readonly.sh.j2
97+
ansible.builtin.template:
7798
dest: "{{ pg_bindir }}/pgsodium_getkey.sh"
78-
owner: postgres
79-
group: postgres
80-
mode: 0700
81-
when: debpkg_mode or stage2_nix
99+
group: 'postgres'
100+
mode: '0700'
101+
owner: 'postgres'
102+
src: 'files/pgsodium_getkey_readonly.sh.j2'
103+
when:
104+
- (debpkg_mode or stage2_nix)

0 commit comments

Comments
 (0)