forge
Explore
Log in

Don't you dare go Hollow

✨ deploy: user unit for running im unprivileged under a lingering account, kept up to date by kur

Browse files at this commit

b9f0726c14def6be0ebe5c3aef62b199fb0bb5a2Ahmet Kaan GümüşParent: 93dee0c
All checks have passed
Show checks
README.mdmodified+26 -0
@@ -193,6 +193,32 @@ forwards to `127.0.0.1:7650`; `base_url` must be the same public origin. Three t
193193 - Keep secrets out of the access log. Reset, invitation and email-change links carry a one-time token in
194194 the path (`/reset/…`, `/invite/…`, `/email/…`), so log without the path for those prefixes, or not at all.
195195
196+### As a user service (with kur)
197+
198+`deploy/user/im.service` runs `im` without root, as an ordinary account (here `apps`) under its own systemd
199+user manager. As root:
200+
201+```sh
202+useradd -m apps
203+loginctl enable-linger apps
204+```
205+
206+Then, in a session of that user (`sudo machinectl shell apps@`):
207+
208+```sh
209+install -d ~/bin ~/.config/im ~/.config/systemd/user
210+install -m 0755 <built im binary> ~/bin/im
211+install -m 0600 config/im.toml ~/.config/im/im.toml
212+install -m 0644 deploy/user/im.service ~/.config/systemd/user/
213+systemctl --user daemon-reload
214+systemctl --user enable --now im.service
215+```
216+
217+Set `database`, `data_dir` and `[backup] dir` in `~/.config/im/im.toml` to absolute paths under
218+`~/.local/state/im`, because `im` does not expand `~`. [kur](https://git.tahinli.com/Tahinli/kur) keeps it
219+updated from im's `v*` releases: give it an app with `path = "~/bin/im"`, `unit = "im.service"`, and
220+`health_url` set to `listen` with `/healthz` appended (for example `http://127.0.0.1:7650/healthz`).
221+
196222 ## Layout
197223
198224 - `crates/im-core`: the domain, the store and its migrations, the configuration, keys, secrets, backups.
deploy/user/im.serviceadded+40 -0
@@ -0,0 +1,40 @@
1+[Unit]
2+Description=im: the family's sign-in provider (OpenID Connect), as a user service
3+# No network-online.target: it is a system unit that a user manager cannot see, and im binds 127.0.0.1.
4+StartLimitIntervalSec=60
5+StartLimitBurst=5
6+
7+[Service]
8+Type=simple
9+# Runs as the account that owns this unit (for example `apps`), under its user manager. No User= or Group=.
10+# The binary is installed by kur into ~/bin/im. The config must use absolute paths: im does not expand "~"
11+# (its paths are used as given, and relative ones resolve against the working directory below). Point
12+# database, data_dir and [backup] dir under ~/.local/state/im, for example /home/apps/.local/state/im/data/im.db.
13+Environment=IM_CONFIG=%h/.config/im/im.toml
14+ExecStart=%h/bin/im serve
15+# StateDirectory creates ~/.local/state/im (mode 0700) before start; the working directory is that directory.
16+StateDirectory=im
17+StateDirectoryMode=0700
18+WorkingDirectory=%S/im
19+Restart=on-failure
20+RestartSec=2
21+LimitNOFILE=65536
22+# A photo decode may use up to 96 MiB and two run at once; this leaves room for that and the rest.
23+MemoryMax=1G
24+UMask=0077
25+
26+# Hardening. Only the options a user manager applies without special privileges. The namespace-based options
27+# of the system unit (ProtectSystem, PrivateTmp, ProtectHome, PrivateDevices, and the rest) are left out:
28+# a user manager can apply them only where unprivileged user namespaces are available.
29+NoNewPrivileges=yes
30+LockPersonality=yes
31+RestrictRealtime=yes
32+RestrictSUIDSGID=yes
33+MemoryDenyWriteExecute=yes
34+SystemCallArchitectures=native
35+SystemCallFilter=@system-service
36+SystemCallFilter=~@privileged
37+RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
38+
39+[Install]
40+WantedBy=default.target