berth

How Berth works

Architecture

How Berth is built: an unprivileged panel daemon, a small root agent that accepts only typed and individually authorised operations, a subprocess per operation, modules with their own tables, a MariaDB panel database, an event bus, jobs and an OS adapter.

Updated 8 min readarchitecture · berthd · berth-agent · privilege separation · design · internalsView as Markdown

On this page
  1. The four programs
  2. berthd: the unprivileged panel
  3. berth-agent: a small root service with a closed vocabulary
  4. Modules
  5. The panel database
  6. Event bus
  7. Jobs and background tasks
  8. OS adapter
  9. Open-source components and licensing
  10. Extensions run outside the panel
  11. Further reading

Berth is split along one line: the part that talks to the internet never has root, and the part that has root never talks to the internet. This article describes the four programs, the protocol between the panel and the root agent, how each operation is authorised and executed, and the building blocks inside the panel: modules, the panel database, the event bus, jobs and the OS adapter. It is meant for administrators, auditors and developers who want to know what runs where and why.

The four programs

ProgramRuns asRole
berthdthe unprivileged user berthThe panel: web UI, REST API with OpenAPI, the MCP endpoint for AI assistants, the modules and the panel database. Listens only on loopback, behind nginx.
berth-agentrootCarries out everything that needs root, on request, over a local unix socket. Accepts only a closed set of typed operations.
berththe administrator, usually rootThe command line. Talks to the agent like the panel does, or runs in-process as root with --local when the agent itself is not running.
berth-probeanyone, anywhereMeasures domains from outside: HTTP, HTTPS, TLS, DNS, MX and STARTTLS, optionally IMAP, POP3, submission and FTP, and a few pages per site. Writes one JSON line per domain, compares two runs and builds a parity report. Used for migration parity checks.
 browser / API client / AI connector
              │  https
              ▼
           nginx ──────────────► websites (Apache, PHP-FPM, apps, containers)
              │  loopback
              ▼
     berthd (user berth) ── MariaDB: panel database "berth"
              │  unix socket: typed requests, one response each
              ▼
     berth-agent (root) ── one worker subprocess per operation
              │
              ▼
   /etc/berth/rendered, systemd units, users, quotas, nftables, ...

berthd: the unprivileged panel

berthd runs as the system user berth under a systemd sandbox: NoNewPrivileges, ProtectSystem=strict, ProtectHome, PrivateTmp, PrivateDevices, protected kernel tunables, modules and control groups, RestrictSUIDSGID, and memory and task limits so a leak cannot take the server with it. It is not a member of the customer groups. It cannot read webspaces, Maildirs or customer databases directly; it reaches them only by asking the agent.

Every API and UI request runs with panic recovery: a bug in one handler returns an error for that request, not a dead panel. The same applies to every background job.

berth-agent: a small root service with a closed vocabulary

The agent listens only on a local unix socket, never on the network. The wire format is deliberately plain: newline-delimited JSON, one request, one response. Each request names an operation and carries its parameters.

There are a little over 300 operations, and each one is a Go type with its own Validate() method: enums for choices, bounds for numbers, strict patterns for domain names, user names and paths. The agent does not trust anything the panel sends; it validates every field again before acting. There is no generic "run this command" or "write this file anywhere" operation. Where the panel needs something new from root, a new typed operation has to be written for it.

Derived data comes from the agent's own lookups, not from the request. For example, when the panel asks for a PHP-FPM pool or a web server virtual host, the agent renders the file itself from a typed specification and looks up the subscription's uid, sockets and certificate paths on its own, binding them to the subscription the request names.

Who is asking: peer credentials

The agent identifies the caller through the kernel, with SO_PEERCRED on the socket, not from anything in the request. If the kernel cannot tell, the request is denied. A request may carry an actor (which panel user asked for it), but the agent treats that as information for its audit trail only, never as authorisation.

  • Root (the berth CLI run by an administrator, the installer, timers) may use every operation.
  • Any other caller, in practice berthd, goes through an explicit policy.

Per-operation policy

Every operation has exactly one rule for non-root callers:

  • allowed, with a written reason for why that is safe (what Validate() and the handler already limit);
  • root only, for things the panel must never do itself, such as changing the hoster's server policy;
  • checked, guarded by a named check, for example that a file operation stays inside the webspace of the subscription it names, that a service unit is not on the protected list, or that a quota value fits.

An operation without a rule is denied to the panel. A test in the build fails when someone adds an operation without deciding its rule, and also when a rule names a check that does not exist. The result is a simple guarantee: even a fully compromised panel process can only do what the agent's policy allows it to do.

Each operation also has a sensitivity class: read, access (new access to data: passwords, keys, sign-in links), export, destroy or security (anything else that changes the server). The agent keeps its own append-only audit trail of everything above read and of every denied request, chained with an HMAC key the panel never has, and anchors it against the panel's activity log so a rewritten log is detected. See Audit trail and approvals.

One subprocess per operation

The agent does not run operations in its own process. For each request it starts itself again as a worker subprocess, passes the request on stdin and reads the response from stdout. The worker validates the request exactly as the agent does. A handler that crashes, hangs or eats memory affects only that one process; the agent enforces a timeout and an output limit and kills the whole process group when either is exceeded.

Concurrency is capped per subscription, per customer and per reseller, with a reserve that is always kept free for system work. One busy customer cannot occupy the agent for everyone else.

Background work (backups, the hourly history, scans, statistics, migration syncs, image conversion) runs in a background slice at the lowest CPU and IO priority, so the panel, PHP and MariaDB come first whenever they need the CPU or the disk. Where the disk scheduler supports weights, Berth switches it to BFQ so the IO priority actually takes effect.

Modules

The panel is built from modules: customers, auth, databases, mail, web, TLS, cron, FTP, SSH access, backups, malware, uptime, statistics, log drains, incidents, the audit watchdog, migration, parity, containers, software, mailing lists, notices, alerts, system apps, vulnerabilities, AI, Fleet and more. berth modules lists them in start order.

  • The core interface is small: a name, a description and dependencies. Optional abilities, such as database migrations, are separate interfaces that a module implements if it needs them.
  • Each module owns its tables, with a prefix, and its own migrations.
  • Modules start in dependency order. A module reports its health as Healthy, Degraded (the rest of the panel keeps running), Disabled or Migrating, during which the panel answers with a temporary error rather than half-migrated data.

The panel database

The panel database is the MariaDB schema berth, reached over a unix socket with socket authentication, so there is no database password to steal. It holds the desired state: customers, subscriptions, domains, mailboxes, schedules, settings. Before each schema migration it is dumped, and the last few dumps are kept.

The agent does not need the database. Services run from the files rendered into /etc/berth/rendered/, so a stopped panel or database does not stop websites or mail. The rescue mode also works without the database. How desired state becomes configuration is described in How changes go live.

Event bus

Modules publish events such as domain.created or cert.renewed on an in-process bus, and other modules subscribe with patterns (domain.*). Delivery is synchronous and isolated per handler: a handler that fails or panics does not affect the others. Every event carries the correlation id of the request or job that caused it, so logs can be followed end to end. Audit events are also what webhooks and extensions receive.

Jobs and background tasks

  • System jobs: long root work, such as an OS upgrade or enabling disk quotas, runs in its own transient systemd unit with a live log, so it survives a panel restart. berth job lists and follows them.
  • Background tasks: long panel work, such as a restore test or an installation, shows a bar at the top of the page with progress and details, and a safe stop where stopping cannot leave things half done. berth task list, berth task show, berth task stop.

OS adapter

All distribution differences live in one place, the OS adapter, with implementations for Debian, Ubuntu (24.04 has its own variant) and the EL family (AlmaLinux, Rocky Linux). The adapter knows package names, service names (apache2 or httpd), paths, the PHP repository (Sury or Remi), the web server user, config test commands, SELinux labels and AppArmor rules. The rest of Berth asks the adapter instead of hard-coding paths, which is also what makes disaster recovery onto a different OS possible.

Open-source components and licensing

Berth uses the standard Linux hosting stack: nginx, Apache, PHP-FPM, Postfix, Dovecot, OpenDKIM, rspamd, ClamAV, ModSecurity and Coraza with the OWASP Core Rule Set, nftables, fail2ban, MariaDB, PostgreSQL, BIND, unbound, ProFTPD, OpenSSH, Roundcube, Adminer, restic, Valkey and Podman.

Libraries compiled into the Berth binaries are MIT, BSD, Apache or MPL licensed only; the build fails if a GPL or AGPL library slips in. GPL tools such as Postfix or ClamAV run as separate programs, as they would without Berth.

Extensions run outside the panel

Extensions are separate processes supervised by the panel, each with its own scoped key and its own sandboxed systemd service, not plugins loaded into berthd. A failing extension cannot crash the panel, and it sees only what its key and the administrator's consent allow. See Webhooks and extensions.

Further reading