Serving Artifacts
How to give artifacts an origin people can open them on: the three self-hosted shapes, their DNS and TLS, what a reverse proxy must and must not do, and object store sizing.
Publishing works without any of this. Until a node serves the artifact
listener, the dashboard lists and versions artifacts but cannot open an html
one, and says which Tier A key to set.
Why artifacts need a host of their own
Section titled “Why artifacts need a host of their own”A page rendered on the dashboard’s origin could act as whoever opened it (the
dashboard acts with a session cookie), so artifacts are served from a
separate listener, api.artifacts, which:
- serves artifact version files, assets, the embedded page runtime and kit, and the company’s adopted brand files, nothing else: no API route, no probe;
- holds no credential: it never reads or sets a cookie;
- opens a version only for a view ticket in the URL, minted by the dashboard for the signed-in viewer and re-checked on every document request.
A design’s artboards are framed documents too, one per ticket. The
dashboard frames each on-screen artboard (at most twelve at once) under a
ticket minted for that board (POST /artifacts/{id}/tickets with document
naming the board’s page). It opens that page and no other as a document: a
board that navigates or fetches another board’s page gets an empty 404,
counted under the document refusal reason; stylesheets, scripts and images
load as for any page. An html page’s single frame still moves between the
version’s pages under one ticket.
Pages sit in a sandboxed frame and talk to the dashboard over a message port; every live call goes through the dashboard, as the viewer. The decision is ADR-0035.
Configuring the listener
Section titled “Configuring the listener”# crewlet.yaml (Tier A), on every ingress nodeapi: external_url: https://crewlet.example.com artifacts: host: 127.0.0.1 # bind; empty binds every interface port: 8001 # 0 (the default) serves no artifacts on this node external_url: https://{artifact}.example-usercontent.netThe listener binds on ingress nodes only, like api.port, before the boot,
so a port somebody else holds fails the start; api_bound names it as
artifacts_addr. Until the node serves, its routes answer an empty 503 with
a Retry-After (see
While a node is starting);
from the handover it logs api_artifacts_listening with the origin mode. A
node without ingress binds nothing and logs INFO
api_artifacts_not_bound. In a fleet, every ingress node serving the
dashboard should serve artifacts, behind the same load balancer. Nothing else
is needed: it reads artifact rows from its own estate copy (ingress requires
data) and bytes from the object store.
external_url decides the origin mode; crewlet validate checks it:
external_url | Mode | What a page gets |
|---|---|---|
A template with {artifact} at the start of its leftmost label, on a registrable domain other than the dashboard’s | per artifact | A real origin of its own: browser storage works, partitioned per artifact |
| A plain origin (one host, or one port) | shared | An opaque origin per document: browser storage throws; pages keep per-viewer state through the runtime |
| A template on the dashboard’s own registrable domain | shared (served opaque), with a warning | As shared |
{artifact} becomes the artifact’s 26-character host label; the rendered
leftmost label must fit DNS’s 63 bytes. Both
https://{artifact}.artifacts.example.net and
https://{artifact}--acme.example-usercontent.net work.
Validation refuses:
{artifact}anywhere but the start of the leftmost label, or twice;- plain
httpon anything but a loopback host; - a path in the URL;
- an origin equal to
api.external_url’s,api.public.external_url’s, or any entry ofapi.auth.allowed_origins(the API trusts those for cross-site writes); - a host that is a parent domain of the API’s host;
- a port with no
external_urlon an ingress node.
The three self-hosted shapes
Section titled “The three self-hosted shapes”In order of preference.
1. A wildcard on a domain of its own
Section titled “1. A wildcard on a domain of its own”api: artifacts: port: 8001 external_url: https://{artifact}.example-usercontent.netEach artifact gets its own origin on a site that is not the dashboard’s: its requests carry nothing of the dashboard’s, and browser storage works per artifact. Choose this when you can register a second domain.
- DNS: a wildcard record,
*.example-usercontent.net, pointing at your ingress (anA/AAAAorCNAME). - TLS: a wildcard certificate for
*.example-usercontent.net. Public CAs issue wildcards only through DNS-01, so your proxy or certificate tool needs API access to the DNS zone. - Use a domain you use for nothing else. Optionally submit it to the Public Suffix List as a private suffix, which makes each artifact host its own site (also partitioning cookies); it takes weeks to reach browsers.
2. A second hostname
Section titled “2. A second hostname”api: artifacts: port: 8001 external_url: https://artifacts.example.comOne hostname, no wildcard; it may be on the dashboard’s own domain. Every
document gets an opaque origin, with no storage: its requests are
cross-site for the host-only dashboard cookie, and the API refuses cross-site
writes and socket handshakes by their Origin.
- DNS: one record for
artifacts.example.com. - TLS: one ordinary certificate (HTTP-01 works).
3. A second port on the dashboard’s host
Section titled “3. A second port on the dashboard’s host”api: artifacts: port: 8443 external_url: https://crewlet.example.com:8443The fewest moving parts: no new name, and no new certificate if the proxy
terminates TLS on both ports with one. A port is a different origin but the
same site, so this shape is always served opaque. Local development is this
shape: http://127.0.0.1:8001 beside a dashboard on http://127.0.0.1:8000.
Serving artifacts on api.port under a path is never offered: a path is not
an origin.
A reverse proxy in front of it
Section titled “A reverse proxy in front of it”The listener speaks plain HTTP; terminate TLS in front of it as for the dashboard.
Caddy, for the wildcard shape (use the DNS provider module for your zone):
*.example-usercontent.net { tls { dns cloudflare {env.CLOUDFLARE_API_TOKEN} } reverse_proxy 127.0.0.1:8001 { flush_interval -1 }}nginx, for the wildcard shape:
server { listen 443 ssl; http2 on; server_name ~^[0-9a-z]{26}\.example-usercontent\.net$;
ssl_certificate /etc/ssl/wildcard.example-usercontent.net.crt; ssl_certificate_key /etc/ssl/wildcard.example-usercontent.net.key;
location / { proxy_pass http://127.0.0.1:8001; proxy_http_version 1.1; proxy_set_header Host $host; proxy_buffering off; proxy_cache off; }}For the second-hostname shape, use server_name artifacts.example.com; and an
ordinary certificate.
The proxy must:
- pass the original
Hostheader through. In per-artifact mode the engine checks the host’s label is the artifact the ticket names, else an empty404; - pass
Sec-Fetch-*request headers through: the engine tells documents from subresources by them and re-authorizes documents every request; - leave the response headers alone:
Content-Security-Policy,Permissions-Policy,Cross-Origin-*,Referrer-PolicyandX-Content-Type-Optionsare built per document; changing them removes the page’s isolation; - never cache
/t/paths in a shared cache. Documents areprivate, no-storeand subresourcesprivate; a cache keyed without the ticket would serve a revoked viewer, and one keyed with it caches nothing useful. Only/_crewlet/runtime/,/_crewlet/kit/and/_crewlet/brand/are public. The first two are safe to cache anywhere, even keyed without the host: a kit release and a runtime named by its bytes (runtime.<digest>.js) are immutable and identical on every host; a runtime at its contract’s name (runtime.js) is revalidated every use, so honour itsno-cache./_crewlet/brand/<sha256>.<ext>(the company’s stylesheet, logos and faces) is immutable for a year and keyed with the host, being one company’s: never drop the host from its key; - never inject anything: no analytics or HTML rewriting, no challenge or captcha page (unsolvable in a frame), no added cookies.
Set HSTS at the proxy or let the engine send it: the listener sends
Strict-Transport-Security whenever its external_url is https.
Checking it works
Section titled “Checking it works”crewlet validate # mode, refusals, and the same-site warningcurl -sI https://abc.example-usercontent.net/_crewlet/runtime/1.0.0/runtime.jsThe runtime answers 200 on any host the listener serves. At its contract’s
name: Cache-Control: public, no-cache, must-revalidate; at the name pages
load it by, runtime.<digest>.js: public, max-age=31536000, immutable. Then open an html artifact in the dashboard:
the frame loads, and the document carries a Content-Security-Policy with a
fresh nonce- on every reload.
| Symptom | Cause |
|---|---|
| The viewer says artifacts are not served | No node serves api.artifacts: set port and external_url on the ingress nodes |
Every frame is an empty 404 | The ticket did not open, or in per-artifact mode the proxy did not pass the original Host |
One design board shows an empty 404 after a click | The board followed a link to another board’s page, which its ticket does not open; boards are separate documents |
A frame shows 401 briefly, then loads | The ticket expired (they live an hour); the viewer mints another itself |
A frame answers 503 with Retry-After | This node’s copy of the artifacts or identity log is stale or out of service and no peer answered; the engine will not serve from rows that may hold a revoked share. See Read Consistency |
| A page reports that storage is unavailable | The listener is in shared mode (opaque origins). Pages that declare state keep per-viewer state through the runtime |
| The frame is blank and the console names a policy | A proxy stripped or rewrote the engine’s headers, or the dashboard was opened on an origin that is neither api.external_url nor an api.auth.allowed_origins entry, which the artifact’s frame-ancestors does not admit |
Traffic is in the crewlet.artifacts.serve.* and
crewlet.artifacts.ticket.refusals instruments (see
Metrics).
The render browser
Section titled “The render browser”An agent checks its page before review with render_artifact
(Authoring artifacts), which
the engine renders in a headless Chromium you run. Name it in the Tier A of
every node that runs seats, beside the two origins its frame is served under,
with the ingress nodes’ values:
api: external_url: https://crewlet.example.com artifacts: external_url: https://{artifact}.example-usercontent.netartifacts: render: browser_url: http://chromium:9222 # or the ws:// address it printsAny Chromium at or above the floor (major 153), started headless with its
DevTools port open to the node, will do, for example
chromium --headless=new --remote-debugging-address=0.0.0.0 --remote-debugging-port=9222. The engine reads /json/version for the
browser’s socket, addresses the port by IP (Chromium refuses a DevTools
request named by host), and refuses a browser below the floor.
- It needs no network. Every request a render makes is paused in the browser and answered by the engine: the version’s files through the node’s own artifact handler, in process; anything on another site is refused and reported. Run it with no route out; the node only has to reach its DevTools port.
- Keep the port private. It is full control of the browser: allow only the engine’s nodes (a loopback sidecar, or a private network). Pages run their authors’ script, so use a container of its own, not the engine’s user.
- One context a render. Each render opens its own browser context, holds new frames and workers until their requests are paused, and disposes of it at the end. A node drives at most two renders at once, each for at most ninety seconds.
- No credential leaves the engine. The render’s frame is minted through a credential name only the render’s resolver knows, for the render’s length; the artifact listener answers it as an ended credential, so a render URL opens nothing elsewhere.
Unset, render_artifact answers which keys to set.
Sizing the object store
Section titled “Sizing the object store”Artifact files live in the company’s object store, beside project files, one object per uploaded file, under the same collection and audit.
- On the default
natsbackend every broker member holds every object, so each artifact byte costsstream.replicasbytes of broker disk. The bucket has a reservation insidestream.store_max_bytes(store.objects.nats_max_bytes, derived when unset), so artifacts never take the space coordination needs; theobjects_bucket_near_ceilingalarm fires at 80 percent of it. The defaultartifacts.limits.company_bytesof 10 GiB is 30 GiB of broker disk at three replicas. Replacing a broker member re-replicates every object, so past a few tens of GiB, prefers3. - On
s3the bucket holds the bytes once and the provider replicates them. When it honours signed checksums and conditional puts, browsers and the harness upload straight to it; add a CORS rule admittingPUTfrom the dashboard’s origin. A self-run S3-compatible service works the same. See Choosing a backend.
Datastore rows are not objects: they live in every data node’s replicated
estate, snapshot and backup, bounded by artifacts.limits.data_bytes and
artifacts.limits.data_store_bytes. Budget them like any replicated table, and
the two logs’ ceilings (stream.artifacts_log_max_bytes,
stream.artifact_data_log_max_bytes) like any other log (see
Retention).
Measured capacity of each path, and how: Artifact Capacity.
Part of Crewlet. Generated from crewlet/crewlet main at 3f5565e.