Skip to content

Latest commit

 

History

History
102 lines (68 loc) · 8.42 KB

hosting.md

File metadata and controls

102 lines (68 loc) · 8.42 KB

Hosting the catalogue

A catalogue maps its owner's attack surface. The site shows everything, licences included, so it must be behind sign-in on every address, assets and calendar file included, and only people who may see everything may pass (ADR 13). Publish only the site's files after a successful build: every entry of the output folder except its .stackledger-build marker and any .stackledger-tmp-* folder. Never serve the build folder while it is being built: staging files hold the whole catalogue (site publication rules).

The catalogue repository template checks and builds a separate catalogue repository and deploys it to Cloudflare Pages. Its README lists the secrets and variable. Protect the project before its first deployment. How it works draws the whole path.

One site, one application

The build writes one site at the root. / is its home page, with no redirect to another path. The old two-site addresses redirect to the same path at the root (/full/software/ goes to /software/, /full/renewals.ics to /renewals.ics), through the _redirects file the build writes, which Cloudflare Pages follows; on another host, add the same redirect (the Caddy example below does).

Access has one application on the whole address, with one policy that allows only the people who may see everything. There is no second application and no path rule: whoever passes sees it all. To go from the two-site layout, change Access first (replace the two applications with the one below, allowing only the people who were on /full/*), then deploy. Access covering the root on every address comes before the first deploy of this layout.

Cloudflare Pages with Access

Follow this order, so there is never an unprotected deployment. See Pages Access settings and Access applications.

  1. Create an empty Pages project, without uploading anything:

    npx wrangler pages project create <project> --production-branch main
  2. In the Pages project's settings, enable its Access policy ("Enable access policy"). Cloudflare creates an application for preview addresses. Edit that application so it is the one below. Do not leave an extra, weaker application matching the same addresses.

  3. Choose an identity provider: Google, Microsoft or another provider you trust (identity providers); one-time PIN by e-mail needs no provider setup. Sign-in is Cloudflare Access's: stackledger has no sign-in code.

  4. Configure the self-hosted application below with every address as a destination: the custom domain if present, the production Pages address and the wildcard Pages address. The wildcard covers branch aliases and deployment previews. Use your own project, domain and people; the examples are fictitious.

  5. Only then run the template's first deploy. Check the requests below before sharing any link.

The application

stackledger

Policy readers: Allow only the people or the identity-provider group who may see every cost, renewal and contract in the catalogue. No Bypass policy and no public Allow policy.

Destinations (the whole address):

  • catalogue.example.org (custom domain, if any)
  • <project>.pages.dev
  • *.<project>.pages.dev

When adding a domain later, add its destination to this application before serving it.

Check the site

On each address (custom domain, production Pages address, and a real preview or branch address), make anonymous requests with curl -sI to:

  • /
  • /reports/
  • /renewals.ics
  • one actual asset below /_astro/ (pick the filename from the built HTML, not a made-up filename)
  • /full/ and /full/renewals.ics: the old addresses must be refused too, since Access answers before the redirect

For example:

curl -sI https://catalogue.example.org/
curl -sI https://catalogue.example.org/renewals.ics

Every request must answer 302, with Location pointing to <team>.cloudflareaccess.com. A 200, a direct asset response or a public error page is a failed check: do not share the address. Check the policy destinations first. Then sign in as one of the people in the policy: / opens the home page, and /full/software/ redirects to /software/. Repeat on every address. Changing an Access policy means repeating these checks.

Rollback

Pages keeps production deployments labelled with the commit and build date by the template. In the project's Deployments list, select a known-good production deployment, then Rollback to this deployment (Pages rollbacks). Access remains in front of it. To fix forward, revert on main. A manual workflow run on an old ref does not deploy: only refs/heads/main can deploy.

Any host: Caddy and oauth2-proxy

The tested example is examples/hosting/Caddyfile. Caddy serves the site's files (it does not read _redirects or _headers; the example writes the same rules itself) and asks oauth2-proxy to authenticate every site request before serving files. The /oauth2/* endpoints themselves are routed to oauth2-proxy for sign-in and callbacks.

  • Every path requires the exact group readers: it is the one audience, so put in it only the people who may see everything.
  • Any other signed-in identity receives 403.
  • Only X-Auth-Request-Groups returned by oauth2-proxy counts. Caddy drops the client's copy first, including when the auth answer has no groups.
  • Anonymous requests go to sign-in. An unavailable auth service fails closed (502, no site content).
  • /full and /full/<path> redirect to /<path> with 301, after the check, so only a reader is redirected.

Use a real identity provider that returns group claims. This fictitious OIDC setup shows the relevant oauth2-proxy flags (oauth2-proxy configuration):

# Supply these through your service's secret store, not the catalogue or a committed file:
# OAUTH2_PROXY_CLIENT_ID, OAUTH2_PROXY_CLIENT_SECRET, OAUTH2_PROXY_COOKIE_SECRET.
oauth2-proxy \
  --provider=oidc \
  --oidc-issuer-url=https://identity.example.org/realms/northwind \
  --redirect-url=https://catalogue.example.org/oauth2/callback \
  --http-address=127.0.0.1:4180 \
  --reverse-proxy=true \
  --upstream=static://202 \
  --email-domain=example.org \
  --oidc-groups-claim=groups \
  --scope='openid profile email groups' \
  --set-xauthrequest=true \
  --cookie-secure=true

Configure the provider to return the readers group claim. Do not use e-mail domains as a replacement for authorisation: Caddy still checks the group. Use your provider's documented scopes (not all providers call the groups scope groups). oauth2-proxy must listen only on loopback or a private network reachable by Caddy, never publicly. Protect its client and cookie secrets in the host's secret store. The site's origin must not be reachable directly around Caddy.

Copy the Caddyfile, replace catalogue.example.org, 127.0.0.1:4180 and /srv/stackledger/publish, and run Caddy with it. Caddy manages HTTPS for the configured domain. Deploy only the site's files into that root (everything in the build folder except .stackledger-build and any .stackledger-tmp-*), never build in it. The example repeats the security headers from _headers and serves .ics as text/calendar.

Run the same anonymous checks as above, plus: sign in as a reader and as a signed-in identity outside readers (refused everywhere), send a client X-Auth-Request-Groups: readers header as that identity (still refused), and stop oauth2-proxy (every site request must fail with no content). The integration test does these with the real example Caddyfile and a small local stand-in for oauth2-proxy; it does not replace checking your identity provider's claims and network boundary.

Calendar files are downloads, not subscriptions

/renewals.ics is for download and import. Calendar services fetch subscriptions without the reader's sign-in, so Access or the generic proxy refuses them. Never publish the file outside the protected address to make subscriptions work: it holds costs (calendar rules).