Skip to main content

PR preview environments

Every PR gets its own environment at prXXX.insfocus.com. Used for review and QA before merge.

Architecture​

  • Cloudflare Access — auth in front of every preview. Entra ID is the IdP.
  • Cloudflare Tunnel — exposes the office cluster. No inbound ports.
  • HAProxy — routes prXXX hosts to the cluster.
  • MicroK8s — dev host k8s.dev.corp.insfocus.com. One Helm release per PR.
  • .NET app — reads the user from the Cf-Access-Jwt-Assertion header.
  • Data — SQLite files on the dev host under /opt/data.

Lifecycle​

  1. PR opened/updated → GitHub Actions builds on the Windows self-hosted runner.
  2. Image pushed to ACR.
  3. Helm deploys the PR release to MicroK8s.
  4. SQLite seeded from a template DB with sqlite3 .backup.
  5. Available at prXXX.insfocus.com behind Cloudflare Access.

Configuration​

  • Deployments use strategy: Recreate. Never two pods on one SQLite file.
  • No SQLite sharing across pods over NFS.
  • Image pulls use ACR scope-mapped repository tokens. See Container registry.

Cloudflare Access user mapping (.NET app)​

  • Code: Server/InsFocus.Core.Common/Extensions/WebApplicationBuilderExtensions.cs, OnTokenValidated.
  • Config model: Server/InsFocusBI.Server.Common/Models/CloudFlareConfiguration.cs (Auth:CloudFlare).
  • Token with email → matched to an InsFocus user by email/name. No match → 401.
  • Token with no email but a common_name → treated as a Cloudflare service token:
    • common_name is looked up in ServiceTokens (case-insensitive). Signs in as the mapped InsFocus user.
    • Not in the map, or mapped user missing → 401, reason logged with the received value.
    • Service tokens are never matched by user name. Only through the map.
"Auth": {
"CloudFlare": {
"TeamDomain": "https://<team>.cloudflareaccess.com",
"Audience": "<aud-tag>",
"ServiceTokens": {
"<client-id>.access": "playwright-bot"
}
}
}
  • Key = the service token Client ID as shown in Cloudflare, including .access.

Decisions​

  • Backfill — Seed SQLite with sqlite3 .backup. Why: live cp -a copies corrupted the DB.
  • Backfill — strategy: Recreate for SQLite workloads. Why: a SQLite file must never be open from two pods.
  • Backfill — Cloudflare Access with Entra as IdP for preview auth.
  • 2026-11-08 — Cloudflare service tokens map to InsFocus users through an explicit Auth:CloudFlare:ServiceTokens list. Why: service-token JWTs have no email, so the app returned 401 after Cloudflare let them through. Unlisted tokens still fail.

Gotchas​

  • Problem: SQLite corruption in fresh previews. Fix: replace cp -a with sqlite3 .backup.

Open​

  • Playwright test bot authenticating with a Cloudflare service token — being evaluated.