berth

API and automation

Webhooks and extensions

Send signed panel events to your own systems with HMAC-signed, retried webhooks, and extend the panel with separate-process extensions that add pages, API routes and hooks that can veto or adjust actions.

Updated 10 min readwebhooks · hmac · extensions · plugins · sdk · hooks · integrationView as Markdown

On this page
  1. Webhooks
  2. Extensions
  3. Related

Berth offers two ways to connect your own software. Webhooks push events from the activity log to a URL you choose: a domain was created, a backup was restored, a site went down. Extensions go further: a separate program that the panel starts and supervises, which can receive events, add its own pages and API routes, and step in before an action happens. Both are for administrators.

Webhooks

Every change in the panel is an entry in the activity log with a dotted name such as domain.create, mail.account.create, customer.create, backup.restore or uptime.down, whether it came from the panel, the API or the CLI. A webhook subscribes to those names with patterns: domain.* for everything about domains, * for everything.

Creating a webhook

Panel: Integrations → Webhooks. Enter the https address of the receiver and the event patterns. The signing secret is shown once.

berth webhook add --url https://hooks.example.nl/berth --events 'domain.*,customer.create'
berth webhook list                 # with the latest deliveries per webhook
berth webhook test 3               # queue a test message
berth webhook disable 3

The receiver must use https. A receiver on your own network or on the server itself (a private or loopback address) is refused unless you allow it explicitly with --allow-private, which also permits plain http for that target.

What the receiver gets

A POST with a JSON body:

{
  "event": "domain.create",
  "at": "2026-10-29T09:14:03Z",
  "actor": "admin",
  "target": "acme.nl",
  "details": {},
  "audit_id": 48213,
  "server": "srv1.example.nl"
}

and these headers:

HeaderValue
Content-Typeapplication/json
User-AgentBerth/<version>
X-Berth-EventThe event name, e.g. domain.create
X-Berth-DeliveryA delivery id; the same id on every retry
X-Berth-TimestampUnix time in seconds when this attempt was sent
X-Berth-Signaturesha256= followed by the hex HMAC-SHA256 of <timestamp>.<body> with the webhook's secret

Retries

A delivery succeeds when the receiver answers with a 2xx status. On an error or any other status, Berth tries again after 1 minute, 5 minutes, 30 minutes, 2 hours, 6 hours and 12 hours; after seven attempts the delivery is marked as failed and shown as such in the webhook's delivery list. Redirects are not followed. Because a delivery can arrive more than once, make your receiver idempotent on X-Berth-Delivery or audit_id.

Verifying the signature

Compute the HMAC over the timestamp, a dot and the raw body exactly as received, compare in constant time, and reject messages whose timestamp is too far from your own clock (five minutes is a sensible window). This proves the message came from your panel and stops an old message from being replayed.

import hashlib, hmac, time

def verify(secret: bytes, headers: dict, body: bytes, window: int = 300) -> bool:
    ts = headers.get("X-Berth-Timestamp", "")
    sig = headers.get("X-Berth-Signature", "")
    if not ts.isdigit() or abs(time.time() - int(ts)) > window:
        return False
    expected = "sha256=" + hmac.new(secret, ts.encode() + b"." + body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, sig)

The same in Node.js:

const crypto = require('node:crypto');

function verify(secret, headers, rawBody, windowSeconds = 300) {
  const ts = headers['x-berth-timestamp'] || '';
  const sig = headers['x-berth-signature'] || '';
  if (!/^\d+$/.test(ts) || Math.abs(Date.now() / 1000 - Number(ts)) > windowSeconds) return false;
  const expected = 'sha256=' + crypto.createHmac('sha256', secret).update(ts + '.').update(rawBody).digest('hex');
  return expected.length === sig.length && crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(sig));
}

Use the raw request body: parsing and re-serialising the JSON changes the bytes and breaks the signature.

Extensions

An extension is a separate program that extends the panel. The panel starts it, talks to it, and restarts it if it crashes, hangs or stops answering pings, without the rest of the panel noticing. An extension can:

  • receive events from the activity log, with the same patterns as webhooks;
  • offer its own API routes under /api/v1/ext/<name>/…, for administrators or for every signed-in user;
  • add pages to the panel under /ext/<name>/…, optionally in the menu, built from blocks rather than HTML;
  • hook into actions: before a domain, customer, subscription, database or mailbox is created, or a package is saved, the panel asks the extension whether it may proceed, and the extension can adjust certain fields;
  • use the panel's API with its own scoped key;
  • update itself from a signed update source.

Typical uses: enforce naming rules for customers, sync new customers to a CRM, block domains on an internal deny list, add a report page for your support team, or adjust a package's limits to match a contract.

Isolation

A program extension runs as its own temporary system user with resource limits from its manifest (memory, CPU share, number of processes). The system is read-only to it except its own data directory; it has no access to the panel's configuration, webspaces, mail or databases, no extra privileges and its own /tmp. Whatever it needs from the panel goes through the API with its own key, so even a compromised extension cannot read panel secrets or customer files.

Failures stay contained: a page that fails shows a clean error, a hook that does not answer in time lets the action continue by default, and an extension can always be switched off under Settings → Extensions or with berth extension disable. That page shows state, restarts, recent errors and the extension's log.

The manifest

An extension is a directory with extension.json and the program:

{
  "name": "crm-sync",
  "version": "1.0.0",
  "description": "Sends new customers to the CRM",
  "command": "crm-sync",
  "events": ["customer.*", "provisioning.*"],
  "routes": [{"method": "GET", "path": "/status", "access": "admin"}],
  "pages": [{"path": "/", "title": "CRM", "access": "admin", "menu": true}],
  "hooks": ["customer.create"],
  "hook_failure": "allow",
  "api": "read",
  "limits": {"memory_mb": 128, "cpu_percent": 25, "tasks": 32}
}

Writing one in Go

Berth ships a Go SDK (package sdk) that handles the protocol:

sdk.Serve(sdk.Extension{
	Name: "crm-sync", Version: "1.0.0",
	OnEvent: func(ctx context.Context, e sdk.Event) error {
		return pushToCRM(ctx, e) // your code
	},
	Routes: map[string]sdk.Handler{
		"GET /status": func(ctx context.Context, r sdk.Request) (sdk.Response, error) {
			return sdk.Text(200, "ok for "+r.Principal.Login), nil
		},
	},
})

Other languages: the protocol

Extensions speak JSON-RPC 2.0, one message per line, over standard input and output:

DirectionMethodPurpose
panel → extensioninitializeStart-up: protocol version, panel version, hostname and, if requested, the API key. The extension answers with its name and version.
panel → extensioneventAn activity-log event (action, target, actor, at, details).
panel → extensionrequestA call to one of its routes or pages, with the signed-in principal.
panel → extensionhookBefore an action: answer {allow: true}, {allow: false, message: "…"} or {allow: true, changes: {…}}.
panel → extensionping, shutdownHealth check and clean stop.
panel → extensionhealthPeriodic health report (only with health in the manifest).
extension → panellogA log line for the extension's log.
extension → panelalertReport a problem or its recovery; the panel notifies through its usual channels.
extension → panelmetricA measurement usable in alert rules as ext:<extension>:<name>.

Events arrive in order. A new extension starts at "now"; it does not get past events.

Pages from blocks

A page is not HTML. The extension returns a view made of blocks: text, heading, notice, facts, table, links, code and form (text, number, e-mail, password, textarea, select, checkbox and hidden fields). The panel draws them in its own design, escapes all text and adds its CSRF protection to forms, so an extension page looks like the rest of the panel, works in light and dark mode, and cannot run scripts on the panel's origin.

Hooks that veto or modify

Hooks are available for domain.create, customer.create, subscription.create, database.create, mail.account.create and plan.save. A refusal shows the extension's message to the user and is logged as extension.hook_denied. A hook can also change fields:

ActionFields an extension may change
customer.createname, email
mail.account.createquota_mb
plan.savethe package's limits and settings (not its name or owner)

The panel then runs the action again with the new values through all its usual checks, and logs which extension changed which field (extension.hook_changed). If the extension does not answer in time, hook_failure decides: allow (the default) or deny. Hooks apply to actions through the panel and the API, not to the CLI.

The extension's API key

With "api": "read" or "api": "admin" the extension receives its own key at every start, acting as the user ext-<name>, so its actions are visible under that name in the activity log. The key is replaced at each start and revoked when the extension is disabled or removed. An extension key is never a full administrator key: accounts, settings, the system and extensions themselves are always out of reach, and so are actions that affect the whole server or move customers around, such as firewall changes, packages, resellers and transfers. Without api_permissions the key reaches all the regular parts of the API (writing with admin, reading with read); api_permissions narrows it further, such as ["domains:read", "mail:write", "stats:read"]. No API key, an extension's included, can manage keys or log in as a customer. Give every extension the narrowest list it needs.

Access to webspaces

An extension has no access to webspaces unless three parties agree: the manifest asks for it with a reason ("webspace": {"access": "read", "reason": "Looks for outdated plugins."}), the administrator approves it, and for each subscription the customer, their reseller or the administrator grants it. The effective level is the lowest of the three, consent is given in a panel session and never with an API token, and every file read or written is logged. Files are always accessed as the subscription's own system user, never as root.

HTTP extensions

An extension can also be a web service in any language, on the same server or elsewhere: use "url": "https://ext.example.nl/rpc" instead of command. The panel sends the same JSON-RPC messages as POST requests, signed like webhooks with X-Berth-Extension, X-Berth-Timestamp and X-Berth-Signature (HMAC-SHA256 over <timestamp>.<body> with a shared secret). Check the signature and the time, and answer 401 when they do not match. Events that do not get a 2xx are delivered again, so process them idempotently on their id.

Instead of a shared secret, an HTTP extension can use mutual TLS: the panel has its own CA for extensions and presents a client certificate for that extension, renewed automatically before it expires. berth extension ca and berth extension cert <name> show the CA and the certificate.

Installing

On the server, as root, from a directory owned by root:

sudo berth extension install /opt/build/crm-sync
berth extension list

From the panel, only extensions signed by a trusted publisher can be installed. Only root can add a publisher, after checking the key's fingerprint with the publisher, so a compromised panel cannot add a publisher of its own:

sudo berth extension trust add acme --key-file acme-publisher.pub
berth extension trust list

Then Settings → Extensions → Install extension: give the https address of the release or upload the archive. The panel shows what the extension asks for (events, pages, routes, hooks, API access) and who signed it; you confirm, with four-eyes approval when enabled. The agent verifies the signature over name, version, SHA-256 and size again before installing.

Signed updates

An extension can carry its own update source and public key in its manifest. The author signs each version:

berth extension keygen --out crm-sync-release.key   # once; the public half goes in extension.json
berth extension pack ./crm-sync --key crm-sync-release.key --out ./dist --notes "What is new"

The panel checks daily for a newer version and offers Update to … with the notes; berth extension update <name> does the same. The agent verifies the signature with the key of the installed version, refuses an older or equal version, and keeps the key fixed across versions. A new version that asks for more than the installed one (API access, webspace access, hooks, events or limits) is only installed after explicit approval of the difference (--accept-widened on the CLI).

  • REST API: the API that extensions and your own scripts use.
  • Billing integration: provisioning events such as provisioning.terminate are a common webhook source.
  • Security model: how the panel, agent and extensions are separated.