dlboard

dlboard official documentation

View on GitHub

Webhooks

What is this

When a run ends, dlboard can post it to a URL: a Slack or Mattermost channel, a CI pipeline, a bot. Each project’s owners set its webhooks on the project page’s Webhooks tab, each with the ways a run ends it is for: finished, failed, crashed (given up as lost: its process killed, its node gone), or ended without saying how.

When you’d need this

How it works

What is posted

{
  "event": "run.finished",
  "text": "lr-3e-4 finished after 2 hours 14 minutes, in vision / sweep: https://dlboard.example/experiment/12?run=345",
  "project": {"id": 3, "name": "vision"},
  "experiment": {"id": 12, "name": "sweep"},
  "run": {"id": 345, "name": "lr-3e-4", "status": "finished", "created_at": "...", "ended_at": "...", "done_at": "...", "duration_s": 8040.0},
  "url": "https://dlboard.example/experiment/12?run=345"
}

event is run.finished, run.failed, run.crashed or run.ended, and also sent as the X-Dlboard-Event header. run.ended_at is when the run ended by its own word (for a crashed run, when it was last heard from); run.done_at is when the server recorded the end. text says it all in a sentence, which is all a Slack incoming webhook reads, so a Slack webhook URL works as it is. The links start with DLBOARD_WEBHOOK_PUBLIC_URL if an admin set it, and otherwise with the server’s address as the owner who added the webhook reached it.

Checking a post is dlboard’s. X-Dlboard-Signature: t=<unix time>,v1=<hex> is the HMAC-SHA256, keyed with the webhook’s secret, of <unix time>. followed by the raw body. A receiver recomputes it, compares in constant time, and refuses a time more than a few minutes old, so a captured post can’t be replayed:

import hashlib, hmac, time


def is_dlboard(secret: str, header: str, body: bytes) -> bool:
    fields = dict(part.split("=", 1) for part in header.split(","))
    expected = hmac.new(secret.encode(), f"{fields['t']}.".encode() + body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(fields["v1"], expected) and abs(time.time() - int(fields["t"])) < 300

Where the server may post

A webhook makes the server send a request to a URL someone typed in, so the server refuses any URL whose host resolves to an address that isn’t public: this machine, a private network, link-local (a cloud’s metadata service), carrier-grade NAT (a tailnet). It resolves the host once per post and connects to that address, so a DNS answer that changes in between can’t redirect it, and it follows no redirects. For the same reason a post never goes through an HTTP proxy (HTTPS_PROXY is ignored), which would connect to the host by its name. It trusts the system’s CAs and the bundle requests ships, so an internal server with a private CA works once that CA is in the system’s trust store.

To let webhooks reach an internal server (a self-hosted Mattermost, a tailnet bot), an admin lists its host name or address in DLBOARD_WEBHOOK_ALLOWED_HOSTS. The rest of the DLBOARD_WEBHOOK_* settings are in Configuration.

Webhooks are part of every storage bundle (LOCAL_STORAGE, POSTGRES_STORAGE, POSTGRES_S3_STORAGE), beside retention; a deployment that composes its own list adds dlboard.plugins.webhooks.

Taking webhooks off a deployment

Delete each project’s webhooks on its tab first, then take dlboard.plugins.webhooks off the plugin list. A webhook is kept in the database, its secret with it, until it is deleted, and without the plugin nothing can show or delete it. Taken off with webhooks still set, they stay, unseen, and work again as they were once the plugin is listed again. What the server had queued to post is dropped then, not posted, if its run ended more than DLBOARD_WEBHOOK_EXPIRE_H before. A general way to find and clear what a removed plugin leaves behind is #813.