forge
Explore
Log in

Don't you dare go Hollow

📝 deploy: trusted proxies behind Ferron, tokens out of access logs, tighter systemd unit, example port matches

Browse files at this commit

cddb939db6e88ae7d42ed3780bd9458775aa7ba4Ahmet Kaan GümüşParent: 6ff6a73
README.mdmodified+9 -4
@@ -36,7 +36,7 @@ The settings that matter first:
36 | `data_dir` | Holds the instance key `im.key`, the photos, and the backups. Created with mode 0700. |36 | `data_dir` | Holds the instance key `im.key`, the photos, and the backups. Created with mode 0700. |
37 | `listen` | The loopback address `im` binds to, for example `127.0.0.1:7650`. |37 | `listen` | The loopback address `im` binds to, for example `127.0.0.1:7650`. |
38 | `base_url` | The public origin, with no trailing slash. This is the OpenID issuer and the origin of every link in mail. |38 | `base_url` | The public origin, with no trailing slash. This is the OpenID issuer and the origin of every link in mail. |
39-| `trusted_proxies` | The proxies whose `X-Forwarded-For` is believed. Leave empty when nothing is in front of `im`. |39+| `trusted_proxies` | The proxies whose `X-Forwarded-For` is believed. Behind Ferron on the same host, `["127.0.0.1/32"]`; empty only when nothing is in front of `im`, otherwise every visitor shares the proxy's address and one visitor's failed sign-ins throttle everyone. The proxy must append the client address to `X-Forwarded-For`, never pass a client's own header through unchanged. |
40 40
41 Secrets never go in the file. Client secrets are shown once and stored as hashes. The SMTP password is read41 Secrets never go in the file. Client secrets are shown once and stored as hashes. The SMTP password is read
42 from a file named in the configuration, and the instance key is created on first run.42 from a file named in the configuration, and the instance key is created on first run.
@@ -176,15 +176,20 @@ only to `/var/lib/im`. Create the user and the directories, copy the binary and
176 ```sh176 ```sh
177 useradd --system --home /var/lib/im --shell /usr/sbin/nologin im177 useradd --system --home /var/lib/im --shell /usr/sbin/nologin im
178 install -d -o im -g im -m 0700 /var/lib/im178 install -d -o im -g im -m 0700 /var/lib/im
179-install -d -m 0750 /etc/im179+install -d -o root -g im -m 0750 /etc/im
180-install -m 0640 config/im.toml /etc/im/im.toml180+install -o root -g im -m 0640 config/im.toml /etc/im/im.toml
181 install -m 0644 deploy/im.service /etc/systemd/system/im.service181 install -m 0644 deploy/im.service /etc/systemd/system/im.service
182 systemctl daemon-reload182 systemctl daemon-reload
183 systemctl enable --now im183 systemctl enable --now im
184 ```184 ```
185 185
186 Put a TLS-terminating reverse proxy in front of it. `deploy/ferron.kdl` is an example Ferron site that186 Put a TLS-terminating reverse proxy in front of it. `deploy/ferron.kdl` is an example Ferron site that
187-forwards to `127.0.0.1:7650`; `base_url` must be the same public origin.187+forwards to `127.0.0.1:7650`; `base_url` must be the same public origin. Three things matter in the proxy:
188+
189+- Redirect plain HTTP to HTTPS. `im` sends HSTS itself when `base_url` is `https://`.
190+- Do not buffer responses: the live update streams depend on it.
191+- Keep secrets out of the access log. Reset, invitation and email-change links carry a one-time token in
192+ the path (`/reset/…`, `/invite/…`, `/email/…`), so log without the path for those prefixes, or not at all.
188 193
189 ## Layout194 ## Layout
190 195
config/im.example.tomlmodified+4 -3
@@ -9,13 +9,14 @@ database = "data/im.db"
9 data_dir = "data"9 data_dir = "data"
10 10
11 # Address the HTTP server binds to. Put a TLS-terminating reverse proxy in front of it in production.11 # Address the HTTP server binds to. Put a TLS-terminating reverse proxy in front of it in production.
12-listen = "127.0.0.1:8080"12+listen = "127.0.0.1:7650"
13 13
14 # Public origin, with no trailing slash. This is the OpenID issuer and the origin of links in mail.14 # Public origin, with no trailing slash. This is the OpenID issuer and the origin of links in mail.
15-base_url = "http://localhost:8080"15+base_url = "http://localhost:7650"
16 16
17 # Proxies whose X-Forwarded-For header is believed, as addresses or CIDR networks. Empty means the17 # Proxies whose X-Forwarded-For header is believed, as addresses or CIDR networks. Empty means the
18-# TCP peer is always the client address.18+# TCP peer is always the client address. Behind a reverse proxy on the same host, set ["127.0.0.1/32"]:
19+# left empty there, every visitor counts as 127.0.0.1, and one visitor's failed sign-ins throttle all.
19 trusted_proxies = []20 trusted_proxies = []
20 21
21 [mail]22 [mail]
deploy/ferron.kdlmodified+4 -1
@@ -1,6 +1,9 @@
1 // Example Ferron site for `im`. Ferron terminates TLS and forwards to the loopback listener of `im`.1 // Example Ferron site for `im`. Ferron terminates TLS and forwards to the loopback listener of `im`.
2 // Check the directive names against the Ferron version you run; this file shows the shape, it has not been2 // Check the directive names against the Ferron version you run; this file shows the shape, it has not been
3-// run against a live Ferron here. `base_url` in im.toml must be this same origin.3+// run against a live Ferron here. `base_url` in im.toml must be this same origin, and `trusted_proxies`
4+// must be ["127.0.0.1/32"]. In the real site also: redirect HTTP to HTTPS, do not buffer responses (the
5+// live streams need it), append the client to X-Forwarded-For, and keep /reset/, /invite/ and /email/ paths
6+// out of the access log: they carry one-time tokens.
4 im.example.com {7 im.example.com {
5 proxy http://127.0.0.1:76508 proxy http://127.0.0.1:7650
6 }9 }
deploy/im.servicemodified+10 -0
@@ -12,6 +12,8 @@ Group=im
12 Environment=IM_CONFIG=/etc/im/im.toml12 Environment=IM_CONFIG=/etc/im/im.toml
13 ExecStart=/usr/local/bin/im serve13 ExecStart=/usr/local/bin/im serve
14 WorkingDirectory=/var/lib/im14 WorkingDirectory=/var/lib/im
15+StateDirectory=im
16+StateDirectoryMode=0700
15 Restart=on-failure17 Restart=on-failure
16 RestartSec=218 RestartSec=2
17 LimitNOFILE=6553619 LimitNOFILE=65536
@@ -39,6 +41,14 @@ LockPersonality=yes
39 MemoryDenyWriteExecute=yes41 MemoryDenyWriteExecute=yes
40 SystemCallArchitectures=native42 SystemCallArchitectures=native
41 SystemCallFilter=@system-service43 SystemCallFilter=@system-service
44+SystemCallFilter=~@privileged
45+ProtectProc=invisible
46+ProcSubset=pid
47+RemoveIPC=yes
48+PrivateMounts=yes
49+KeyringMode=private
50+# A photo decode may use up to 96 MiB and two run at once; this leaves room for that and the rest.
51+MemoryMax=1G
42 CapabilityBoundingSet=52 CapabilityBoundingSet=
43 AmbientCapabilities=53 AmbientCapabilities=
44 UMask=007754 UMask=0077