@@ -186,47 +186,100 @@ sudo systemctl disable traefik.service
186186< https://github.com/filebrowser/filebrowser >
187187
188188``` sh
189+ # Install FileBrowser
189190curl -fsSL https://raw.githubusercontent.com/filebrowser/get/master/get.sh | bash
190- filebrowser config init --port 8084
191- /usr/local/bin/filebrowser -r /root/Sync
192- # While the above is running (TODO: because the systemctl configuration isn't working)
193- ssh -L 8084:localhost:8084 ubuntu-4gb-hel1-1
194191
195- # Create a systemd service for FileBrowser
192+ # Create FileBrowser user and group (run as root)
193+ sudo groupadd filebrowser
194+ sudo useradd \
195+ -g filebrowser --no-user-group \
196+ -d /var/lib/filebrowser --no-create-home \
197+ -s /usr/sbin/nologin \
198+ -r filebrowser
199+
200+ # Create directories for FileBrowser data and config
201+ sudo mkdir -p /var/lib/filebrowser
202+ sudo mkdir -p /etc/filebrowser
203+
204+ # Move Sync directory to a location accessible by filebrowser user
205+ # Option 1 (Recommended): Use dedicated directory
206+ sudo mkdir -p /srv/filebrowser-data
207+ sudo mv /root/Sync/* /srv/filebrowser-data/
208+ sudo chown -R filebrowser:filebrowser /srv/filebrowser-data
209+
210+ # Option 2 (If you must use /root/Sync):
211+ # sudo chmod 755 /root
212+ # sudo chown -R filebrowser:filebrowser /root/Sync
213+
214+ # Initialize FileBrowser config with filebrowser user
215+ sudo -u filebrowser filebrowser config init --port 8084 --database /var/lib/filebrowser/database.db --config /etc/filebrowser/config.json
216+ sudo chown -R filebrowser:filebrowser /var/lib/filebrowser
217+ sudo chown -R filebrowser:filebrowser /etc/filebrowser
218+ ```
219+
220+ ``` sh
221+ # Create hardened systemd service for FileBrowser
196222sudo tee " /lib/systemd/system/filebrowser.service" > /dev/null << 'EOF '
197- # Adapted from: /lib/systemd/system/traefik.service
198223# /lib/systemd/system/filebrowser.service
199224[Unit]
200- Description=Run Filebrowser at startup
201- # After=network-online.target
202- # Wants=network-online.target systemd-networkd-wait-online.service
225+ Description=FileBrowser web-based file management service
226+ After=network-online.target
227+ Wants=network-online.target systemd-networkd-wait-online.service
203228
204229[Service]
205230Restart=on-failure
231+ RestartSec=5
206232
207- # TODO: run as non-root
208- User=root
233+ User=filebrowser
234+ Group=filebrowser
209235
210- # ProtectHome=true
211- # ProtectSystem=full
212- # ReadWriteDirectories=/etc/traefik/acme
213- # CapabilityBoundingSet=CAP_NET_BIND_SERVICE
214- # AmbientCapabilities=CAP_NET_BIND_SERVICE
215- # NoNewPrivileges=true
216-
217- # TimeoutStopSec=300
218- # EnvironmentFile=/etc/traefik/.env
219- ExecStart=/usr/local/bin/filebrowser -r /root/Sync
236+ # Security hardening
237+ ProtectHome=true
238+ ProtectSystem=strict
239+ ReadWritePaths=/srv/filebrowser-data /var/lib/filebrowser
240+ NoNewPrivileges=true
241+ PrivateTmp=true
242+ PrivateDevices=true
243+ ProtectKernelTunables=true
244+ ProtectKernelModules=true
245+ ProtectControlGroups=true
246+ RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
247+ RestrictNamespaces=true
248+ LockPersonality=true
249+ RestrictRealtime=true
250+ RestrictSUIDSGID=true
251+ RemoveIPC=true
252+ SystemCallFilter=@system-service
253+ SystemCallErrorNumber=EPERM
254+
255+ TimeoutStopSec=30
256+
257+ # Update paths as needed - using recommended /srv/filebrowser-data
258+ ExecStart=/usr/local/bin/filebrowser -r /srv/filebrowser-data --database /var/lib/filebrowser/database.db --config /etc/filebrowser/config.json
220259Type=simple
221260
222261[Install]
223262WantedBy=multi-user.target
224263EOF
264+
225265sudo chown root:root /lib/systemd/system/filebrowser.service
226266sudo chmod 644 /lib/systemd/system/filebrowser.service
227267sudo systemctl daemon-reload
268+ sudo systemctl enable filebrowser.service
269+ sudo systemctl start filebrowser.service
270+ sudo systemctl status filebrowser.service
228271```
229272
273+ ** Key security improvements:**
274+
275+ 1 . ** Non-root execution** : Runs as dedicated ` filebrowser ` user/group
276+ 2 . ** Filesystem protection** : ` ProtectSystem=strict ` with explicit ` ReadWritePaths `
277+ 3 . ** Namespace isolation** : ` PrivateTmp ` , ` PrivateDevices ` , and other isolation directives
278+ 4 . ** System call filtering** : Restricts to safe system calls only
279+ 5 . ** No privilege escalation** : ` NoNewPrivileges=true ` prevents gaining additional privileges
280+
281+ ** Note:** Adjust the data directory path (` /srv/filebrowser-data ` ) in the ExecStart line if you prefer a different location. The current configuration uses ` /srv/filebrowser-data ` instead of ` /root/Sync ` for better security separation.
282+
230283## Caddy
231284
232285** See hosting-base.md for Caddy installation and configuration instructions.**
0 commit comments