From b9f0726c14def6be0ebe5c3aef62b199fb0bb5a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 4 Nov 2026 12:43:09 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20deploy:=20user=20unit=20for=20runni?= =?UTF-8?q?ng=20im=20unprivileged=20under=20a=20lingering=20account,=20kep?= =?UTF-8?q?t=20up=20to=20date=20by=20kur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 26 ++++++++++++++++++++++++++ deploy/user/im.service | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 deploy/user/im.service diff --git a/README.md b/README.md index 84aee94..eaa7b9d 100644 --- a/README.md +++ b/README.md @@ -193,6 +193,32 @@ forwards to `127.0.0.1:7650`; `base_url` must be the same public origin. Three t - Keep secrets out of the access log. Reset, invitation and email-change links carry a one-time token in the path (`/reset/…`, `/invite/…`, `/email/…`), so log without the path for those prefixes, or not at all. +### As a user service (with kur) + +`deploy/user/im.service` runs `im` without root, as an ordinary account (here `apps`) under its own systemd +user manager. As root: + +```sh +useradd -m apps +loginctl enable-linger apps +``` + +Then, in a session of that user (`sudo machinectl shell apps@`): + +```sh +install -d ~/bin ~/.config/im ~/.config/systemd/user +install -m 0755 ~/bin/im +install -m 0600 config/im.toml ~/.config/im/im.toml +install -m 0644 deploy/user/im.service ~/.config/systemd/user/ +systemctl --user daemon-reload +systemctl --user enable --now im.service +``` + +Set `database`, `data_dir` and `[backup] dir` in `~/.config/im/im.toml` to absolute paths under +`~/.local/state/im`, because `im` does not expand `~`. [kur](https://git.tahinli.com/Tahinli/kur) keeps it +updated from im's `v*` releases: give it an app with `path = "~/bin/im"`, `unit = "im.service"`, and +`health_url` set to `listen` with `/healthz` appended (for example `http://127.0.0.1:7650/healthz`). + ## Layout - `crates/im-core`: the domain, the store and its migrations, the configuration, keys, secrets, backups. diff --git a/deploy/user/im.service b/deploy/user/im.service new file mode 100644 index 0000000..e14d963 --- /dev/null +++ b/deploy/user/im.service @@ -0,0 +1,40 @@ +[Unit] +Description=im: the family's sign-in provider (OpenID Connect), as a user service +# No network-online.target: it is a system unit that a user manager cannot see, and im binds 127.0.0.1. +StartLimitIntervalSec=60 +StartLimitBurst=5 + +[Service] +Type=simple +# Runs as the account that owns this unit (for example `apps`), under its user manager. No User= or Group=. +# The binary is installed by kur into ~/bin/im. The config must use absolute paths: im does not expand "~" +# (its paths are used as given, and relative ones resolve against the working directory below). Point +# database, data_dir and [backup] dir under ~/.local/state/im, for example /home/apps/.local/state/im/data/im.db. +Environment=IM_CONFIG=%h/.config/im/im.toml +ExecStart=%h/bin/im serve +# StateDirectory creates ~/.local/state/im (mode 0700) before start; the working directory is that directory. +StateDirectory=im +StateDirectoryMode=0700 +WorkingDirectory=%S/im +Restart=on-failure +RestartSec=2 +LimitNOFILE=65536 +# A photo decode may use up to 96 MiB and two run at once; this leaves room for that and the rest. +MemoryMax=1G +UMask=0077 + +# Hardening. Only the options a user manager applies without special privileges. The namespace-based options +# of the system unit (ProtectSystem, PrivateTmp, ProtectHome, PrivateDevices, and the rest) are left out: +# a user manager can apply them only where unprivileged user namespaces are available. +NoNewPrivileges=yes +LockPersonality=yes +RestrictRealtime=yes +RestrictSUIDSGID=yes +MemoryDenyWriteExecute=yes +SystemCallArchitectures=native +SystemCallFilter=@system-service +SystemCallFilter=~@privileged +RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 + +[Install] +WantedBy=default.target