ADR-0044: Branch previews on a separate CloudFront host#

  • Status: proposed. Would refine ADR-0019.
  • Date: 2026-12-01

Context#

Reviewing a docs change means seeing it rendered, and the renderer has shipped faults that only rendering shows (radar). From a phone or a cloud session, where make site cannot run, nothing shows a branch rendered: CI discards its build, whose links all start at /.

A preview per ref needs a role that unmerged code can hold and that publishes, which ADR-0019 ruled out. Its Revisit when names this case.

Decision#

If previews are built:

  1. A second distribution serves them, on the *.cloudfront.net name AWS assigns, from a bucket of their own, at https://<id>.cloudfront.net/refs/heads/<branch>/. cloudfront.net is on the Public Suffix List, so browsers treat that host as a site unrelated to testz.dev. The production distribution, bucket, roles and site-deploy do not change.
  2. A role, testz-gha-preview, trusts the preview environment from refs/heads/*, and may only list, write and delete in the preview bucket: no state, no site bucket, no CloudFront. Any branch can overwrite another's preview, which push access already allows. A branch controls its own workflow, so this policy is the boundary.
  3. The build takes a base path and labels every page as a preview of a named ref and commit, not what is running, with placeholders for the facts it does not read from state. The host sends X-Robots-Tag: noindex and a CSP with script-src 'none'.
  4. A workflow builds a pushed branch before taking credentials, runs make secrets and make docs-lint, then syncs into that branch's prefix. It runs on pushes changing docs/ or site/, except to main and renovate/**. A branch name reaches scripts only through env:, and only if it matches ^[A-Za-z0-9._/-]+$ without ...
  5. Cleanup has three layers. Deleting a branch runs a sweep from main that removes every preview whose branch git ls-remote no longer lists, ignoring the event's payload. Every preview run sweeps too, catching missed events and renames. Objects expire 30 days after upload, and each push uploads the whole site, so only an idle branch loses its preview.
  6. Tags are not previewed. A tag is meant to be permanent, so its pages would grow less true of the system: history ADR-0026 keeps in git.

Alternatives considered#

A path on testz.dev, such as testz.dev/refs/heads/<branch>/. Branch scripts would run as the production site: one could rewrite the address bar to any production URL over its own content, or open a production page in another tab and change it. Production's script-src 'self' would cover every preview's scripts, a flagged preview could flag the domain, and the previews' settings would live in the production distribution, against principle 6.

Previews in the site bucket, through a wider deploy role. Unmerged code could overwrite what production serves.

preview.testz.dev. Still the same site, so it could set cookies on testz.dev and shares its reputation. It also adds a name to the certificate the Certificate Transparency check watches, and records to the signed zone.

A subdomain per branch. Needs a wildcard certificate, which the zone's CAA record forbids, or a record and certificate name per branch, which only the apply role can make. Isolating branches from each other buys nothing: the same people push all of them.

A separately registered domain. Real isolation and a readable name, but it roughly doubles what the domain costs, and if it lapsed, someone else could buy every old preview link.

Private previews, by signed cookies or a secret checked at the edge: a long-lived credential, which principle 4 allows only by exception, for docs public on merge.

Nothing. Enough while every review happens where make site runs.

Consequences#

Positive: a rendered branch is a link on its pull request, opened from anywhere, for about $0 a month.

Negative: a branch is public from its push, before review, which is otherwise the last gate before publishing. The checks catch secrets, but no machine reads a screenshot for the account ID (ADR-0011). While main is unprotected and site-deploy publishes every push to it, push access already publishes; once main is protected, previews are where push access alone still does. On AWS's own certificate CloudFront fixes the security policy at TLSv1, so the preview host accepts TLS versions testz.dev refuses, and Trivy's finding needs an ignore saying why. It adds a workflow with nothing to retire (ADR-0029), and a role that trusts unmerged refs.

Neutral: preview URLs change if the distribution is rebuilt.

Revisit when#

  • Reviewing from somewhere make site cannot run becomes routine, or a rendering fault reaches the site that a preview would have shown. Then re-read this, and accept or replace it.
  • A second person gets push access: previews would publish whatever any of them pushes.
  • The project starts cutting releases, which reopens tag previews.

Built 2026-12-01 from commit 5f3eb2c4b04f9d8367364b6f4598a05a364e2263. This page was generated from the same source that provisions the infrastructure it describes.