Skip to the page
gužvadocs
Menu

Engineering

The server

The machine, where files live, the systemd service and its sandbox (exposure 6.2 to 1.4), and TLS.

The machine

WhatValue
Providernetcup (Germany), since 2026-10-31; before that a Google Cloud e2-micro
OSDebian 13 (trixie), systemd 257
Size2 vCPU, 2 GB RAM, 58 GB disk (measured 2026-11-23: 324 MB RAM used, disk 5% used)
Namesguzva.ba, www.guzva.ba, ingest.guzva.ba, docs.guzva.ba
AccessSSH 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

PathWhatOwner and mode
/srv/guzva/bin/releases/<tag>/guzvaOne folder per released version (last 3 kept)root, 0755
/srv/guzva/bin/currentSymlink to the live releaseroot
/var/lib/guzva/Database, public pages, picture ring, certificatesguzva, 0750
/etc/guzva/guzva.envSecrets: admin hash, cookie secret, Telegram, SMTProot, 0600
/etc/guzva/tls.{crt,key}Self-signed certificate for cameras flashed with the IP addressroot:guzva
/etc/systemd/system/guzva.serviceThe service definition (repo: deploy/guzva.service)root
/var/backups/guzva/Nightly database snapshotsguzva

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.

SettingWhat it doesWhy
User=guzvaRuns as a user with no login and no rights outside its dataA bug can't act as root
AmbientCapabilities=CAP_NET_BIND_SERVICEThe one root-only right it gets: binding ports below 1024It must listen on 80 and 443 itself (no proxy in front)
Restart=always, RestartSec=2Comes back 2 s after any exitCameras retry, and idempotent ingest absorbs the gap
MemoryMax=700MKilled and restarted if it uses more than 700 MBPicture rendering must never starve the OS
EnvironmentFile=/etc/guzva/guzva.envSecrets come from a root-only fileSecrets 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.

SettingTakes away
ProtectSystem=strict + ReadWritePaths=/var/lib/guzvaWrite access to the whole disk except the data folder
ProtectHome=trueHome folders, including /root with the SSH keys
PrivateTmp=trueOther programs' temp files
PrivateDevices=true, DevicePolicy=closedHardware devices (disks, USB, memory)
ProtectKernelTunables/Modules/Logs, ProtectClock, ProtectHostname, ProtectControlGroupsChanging the kernel, loading modules, reading kernel logs, setting the clock or hostname
ProtectProc=invisible, ProcSubset=pidSeeing other processes
RestrictNamespaces, RestrictRealtime, RestrictSUIDSGID, LockPersonalityTricks used to escape a sandbox
MemoryDenyWriteExecute=trueMemory that is both writable and executable (how injected code runs)
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIXRaw, packet and netlink sockets (sniffing, network config)
SystemCallFilter=@system-service, ~@privileged @resourcesAbout 200 kernel calls a normal service never uses
SystemCallErrorNumber=EPERMA blocked call returns an error instead of killing the process
UMask=0027New files readable by the owner and group only, not every user

Why EPERM matters: Go's runtime calls setrlimit at 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.