Skip to content

Commit 52945d1

Browse files
committed
Merge branch 'develop' into fix/postgres-storage-grants
2 parents 29aa02a + e321760 commit 52945d1

File tree

8 files changed

+156
-0
lines changed

8 files changed

+156
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
%gandalf ALL= NOPASSWD: /usr/bin/salt-call
2+
%gandalf ALL= NOPASSWD: /usr/bin/gpg --homedir /etc/salt/gpgkeys --import, /usr/bin/gpg --homedir /etc/salt/gpgkeys --list-secret-keys *
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[Unit]
2+
Description=Configuration management via gandalf salt
3+
After=network.target
4+
5+
[Service]
6+
Type=oneshot
7+
ExecStart=/opt/gandalf/gandalf --config /opt/gandalf/config.yaml salt --apply --store-result
8+
User=gandalf
9+
Group=gandalf
10+
StandardOutput=journal
11+
StandardError=journal
12+
StateDirectory=gandalf
13+
CacheDirectory=gandalf
14+
15+
# Security hardening
16+
PrivateTmp=true
17+
18+
[Install]
19+
WantedBy=multi-user.target
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[Unit]
2+
Description=Run Supabase gandalf salt on a schedule
3+
Requires=gandalf_salt.service
4+
5+
[Timer]
6+
OnCalendar=*:0/10
7+
# Random delay up to 30 seconds splay
8+
RandomizedDelaySec=30
9+
AccuracySec=1s
10+
Persistent=true
11+
12+
[Install]
13+
WantedBy=timers.target

ansible/files/permission_check.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,17 @@
9494
"systemd-coredump": [
9595
{"groupname": "systemd-coredump", "username": "systemd-coredump"}
9696
],
97+
"gandalf": [
98+
{"groupname": "gandalf", "username": "gandalf"},
99+
{"groupname": "admin", "username": "gandalf"},
100+
{"groupname": "salt", "username": "gandalf"},
101+
],
97102
}
98103

99104
# postgresql.service is expected to mount /etc as read-only
100105
expected_mount = "/etc ro"
101106

107+
102108
# This program depends on osquery being installed on the system
103109
# Function to run osquery
104110
def run_osquery(query):
@@ -154,6 +160,7 @@ def check_nixbld_users():
154160

155161
print("All nixbld users are in the 'nixbld' group.")
156162

163+
157164
def check_postgresql_mount():
158165
# processes table has the nix .postgres-wrapped path as the
159166
# binary path, rather than /usr/lib/postgresql/bin/postgres which
@@ -182,6 +189,7 @@ def check_postgresql_mount():
182189

183190
print("postgresql.service mounts /etc as read-only.")
184191

192+
185193
def main():
186194
parser = argparse.ArgumentParser(
187195
prog="Supabase Postgres Artifact Permissions Checker",
@@ -234,6 +242,7 @@ def main():
234242
"postgrest",
235243
"tcpdump",
236244
"systemd-coredump",
245+
"gandalf",
237246
]
238247
if not qemu_artifact:
239248
usernames.append("ec2-instance-connect")
@@ -251,5 +260,6 @@ def main():
251260
# Check if postgresql.service is using a read-only mount for /etc
252261
check_postgresql_mount()
253262

263+
254264
if __name__ == "__main__":
255265
main()

ansible/manifest-playbook.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@
6161
shell: |
6262
cd /tmp && tar -cJf admin-mgr-{{ adminmgr_release }}-arm64.tar.xz admin-mgr
6363
64+
- name: Download gandalf archive
65+
get_url:
66+
url: "https://supabase-public-artifacts-bucket.s3.amazonaws.com/gandalf/v{{ gandalf_release }}/gandalf_{{ gandalf_release }}_linux_arm64.tar.gz"
67+
dest: "/tmp/gandalf.tar.gz"
68+
timeout: 90
69+
70+
- name: gandalf - unpack archive in /tmp
71+
unarchive:
72+
remote_src: yes
73+
src: /tmp/gandalf.tar.gz
74+
dest: /tmp
75+
76+
- name: gandalf - pack archive
77+
shell: |
78+
cd /tmp && tar -cJf gandalf-{{ gandalf_release }}-arm64.tar.xz gandalf
79+
6480
- name: upload archives
6581
shell: |
6682
aws s3 cp /tmp/{{ item.file }} s3://{{ internal_artifacts_bucket }}/upgrades/{{ item.service }}/{{ item.file }}
@@ -73,3 +89,5 @@
7389
file: supabase-admin-api-{{ adminapi_release }}-arm64.tar.xz
7490
- service: admin-mgr
7591
file: admin-mgr-{{ adminmgr_release }}-arm64.tar.xz
92+
- service: gandalf
93+
file: gandalf-{{ gandalf_release }}-arm64.tar.xz

ansible/tasks/internal/gandalf.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
- name: gandalf - system group
2+
group:
3+
name: gandalf
4+
system: yes
5+
6+
- name: gandalf - system user
7+
user:
8+
name: gandalf
9+
group: gandalf
10+
groups: admin,salt
11+
append: yes
12+
system: yes
13+
shell: /bin/sh
14+
15+
- name: gandalf - config dir
16+
file:
17+
path: /opt/gandalf
18+
owner: gandalf
19+
state: directory
20+
21+
- name: gandalf - gpg dir
22+
file:
23+
path: /etc/salt/gpgkeys
24+
owner: root
25+
group: salt
26+
state: directory
27+
28+
- name: give gandalf user permissions
29+
copy:
30+
src: files/gandalf_config/gandalf.sudoers.conf
31+
dest: /etc/sudoers.d/gandalf
32+
mode: "0644"
33+
34+
- name: Setting arch (x86)
35+
set_fact:
36+
arch: "x86"
37+
when: platform == "amd64"
38+
39+
- name: Setting arch (arm)
40+
set_fact:
41+
arch: "arm64"
42+
when: platform == "arm64"
43+
44+
- name: Download gandalf archive
45+
get_url:
46+
url: "https://supabase-public-artifacts-bucket.s3.amazonaws.com/gandalf/v{{ gandalf_release }}/gandalf-{{ gandalf_release }}-linux-{{ arch }}.tar.gz"
47+
dest: "/tmp/gandalf.tar.gz"
48+
timeout: 90
49+
50+
- name: gandalf - unpack archive in /opt
51+
unarchive:
52+
remote_src: yes
53+
src: /tmp/gandalf.tar.gz
54+
dest: /opt/gandalf/
55+
owner: gandalf
56+
extra_opts:
57+
- --strip-components=1
58+
59+
- name: gandalf - create symlink
60+
ansible.builtin.file:
61+
path: /opt/gandalf/gandalf
62+
src: "/opt/gandalf/gandalf-linux-{{ arch }}"
63+
state: link
64+
owner: gandalf
65+
mode: "0755"
66+
force: yes
67+
68+
- name: gandalf - create salt systemd timer file
69+
copy:
70+
src: files/gandalf_config/gandalf_salt.timer
71+
dest: /etc/systemd/system/gandalf_salt.timer
72+
73+
- name: gandalf - create salt service file
74+
copy:
75+
src: files/gandalf_config/gandalf_salt.service
76+
dest: /etc/systemd/system/gandalf_salt.service
77+
78+
- name: gandalf - reload systemd
79+
systemd:
80+
daemon_reload: yes
81+
82+
# Initially ensure gandalf is installed but not started
83+
- name: gandalf - DISABLE service
84+
systemd:
85+
name: gandalf_salt
86+
enabled: no
87+
state: stopped

ansible/tasks/setup-supabase-internal.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,10 @@
115115
tags:
116116
- aws-only
117117

118+
- name: Install gandalf
119+
import_tasks: internal/gandalf.yml
120+
tags:
121+
- aws-only
122+
118123
- name: Envoy - use lds.supabase.yaml for /etc/envoy/lds.yaml
119124
command: mv /etc/envoy/lds.supabase.yaml /etc/envoy/lds.yaml

ansible/vars.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,5 @@ adminmgr_release: 0.25.1
5757

5858
vector_x86_deb: "https://packages.timber.io/vector/0.22.3/vector_0.22.3-1_amd64.deb"
5959
vector_arm_deb: "https://packages.timber.io/vector/0.22.3/vector_0.22.3-1_arm64.deb"
60+
61+
gandalf_release: 1.4.30

0 commit comments

Comments
 (0)