The machine
| What | Value |
|---|---|
| Provider | netcup (Germany), since 2026-10-31; before that a Google Cloud e2-micro |
| OS | Debian 13 (trixie), systemd 257 |
| Size | 2 vCPU, 2 GB RAM, 58 GB disk (measured 2026-11-23: 324 MB RAM used, disk 5% used) |
| Names | guzva.ba, www.guzva.ba, ingest.guzva.ba, docs.guzva.ba |
| Access | SSH with keys only |
Why netcup: a fixed monthly price for a real VPS with enough RAM, in the EU. The free Google Cloud machine had 1 GB RAM, and uploads to it from home were slow.
Where things live
| Path | What | Owner and mode |
|---|---|---|
/srv/guzva/bin/releases/<tag>/guzva | One folder per released version (last 3 kept) | root, 0755 |
/srv/guzva/bin/current | Symlink to the live release | root |
/var/lib/guzva/ | Database, public pages, picture ring, certificates | guzva, 0750 |
/etc/guzva/guzva.env | Secrets: admin hash, cookie secret, Telegram, SMTP | root, 0600 |
/etc/guzva/tls.{crt,key} | Self-signed certificate for cameras flashed with the IP address | root:guzva |
/etc/systemd/system/guzva.service | The service definition (repo: deploy/guzva.service) | root |
/var/backups/guzva/ | Nightly database snapshots | guzva |
The service
guzva runs as a systemd service. systemd starts it at boot, restarts it 2 s after a crash, collects its logs into the journal, and enforces the limits below. The program runs as the unprivileged user guzva, never as root.
| Setting | What it does | Why |
|---|---|---|
User=guzva | Runs as a user with no login and no rights outside its data | A bug can't act as root |
AmbientCapabilities=CAP_NET_BIND_SERVICE | The one root-only right it gets: binding ports below 1024 | It must listen on 80 and 443 itself (no proxy in front) |
Restart=always, RestartSec=2 | Comes back 2 s after any exit | Cameras retry, and idempotent ingest absorbs the gap |
MemoryMax=700M | Killed and restarted if it uses more than 700 MB | Picture rendering must never starve the OS |
EnvironmentFile=/etc/guzva/guzva.env | Secrets come from a root-only file | Secrets never sit in the unit, the repo or the process arguments |
The sandbox (O4, 2026-11-23)
systemd can take away everything a service doesn't need. systemd-analyze security guzva scores how much is left exposed, from 0 (locked) to 10 (everything). We went from 6.2 MEDIUM to 1.4 OK.
| Setting | Takes away |
|---|---|
ProtectSystem=strict + ReadWritePaths=/var/lib/guzva | Write access to the whole disk except the data folder |
ProtectHome=true | Home folders, including /root with the SSH keys |
PrivateTmp=true | Other programs' temp files |
PrivateDevices=true, DevicePolicy=closed | Hardware devices (disks, USB, memory) |
ProtectKernelTunables/Modules/Logs, ProtectClock, ProtectHostname, ProtectControlGroups | Changing the kernel, loading modules, reading kernel logs, setting the clock or hostname |
ProtectProc=invisible, ProcSubset=pid | Seeing other processes |
RestrictNamespaces, RestrictRealtime, RestrictSUIDSGID, LockPersonality | Tricks used to escape a sandbox |
MemoryDenyWriteExecute=true | Memory that is both writable and executable (how injected code runs) |
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX | Raw, packet and netlink sockets (sniffing, network config) |
SystemCallFilter=@system-service, ~@privileged @resources | About 200 kernel calls a normal service never uses |
SystemCallErrorNumber=EPERM | A blocked call returns an error instead of killing the process |
UMask=0027 | New files readable by the owner and group only, not every user |
Why EPERM matters: Go's runtime calls
setrlimitat start to raise its open-file limit. That call is in@resources, which we block. With the default action the kernel would kill guzva at start; with EPERM it gets "not allowed" and carries on with the normal limit.
What stays open, on purpose (the 1.4): network access, port 443, connections out to any address (Let's Encrypt, Telegram, Brevo, DNS), and read access to the clock device. A public HTTPS service needs all of these.
How it was proven: a throwaway copy of the service with the same settings ran on the VPS, on its own port and data folder, and answered every page. An outbound check (a ping to https://guzva.ba) passed; the same check with outbound traffic blocked failed with operation not permitted, which shows the check can detect a broken path. Only then did the real service get the new unit. Rollback copy: /etc/systemd/system/guzva.service.bak-o4.
TLS
The binary gets its own certificates from Let's Encrypt (-autocert guzva.ba,www.guzva.ba,ingest.guzva.ba,docs.guzva.ba). Let's Encrypt proves we control the domain by fetching a token over port 80 (the HTTP-01 challenge), so port 80 stays open; every other request on 80 is redirected to HTTPS. Certificates are cached in /var/lib/guzva/certs and renewed automatically before they expire.
Cameras are a special case. A freshly booted ESP32 thinks it is 1970, so a normal certificate looks "not yet valid" to it. Boards flashed with the IP address get a self-signed certificate valid from 1970 (-tls-cert), and boards using ingest.guzva.ba get the same trick through -device-cert.
Firewall and SSH
deploy/provision.sh sets up ufw to allow only 22 (SSH), 80 and 443 and drop everything else coming in, writes an SSH policy of keys only, and installs unattended-upgrades for automatic security updates.
Planned (O4 part 2): check each of these on the live machine, since provision.sh hasn't been re-run since the move, and consider a non-root deploy user. Until then, treat this section as the intended setup, not a verified one.