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
prXXXhosts 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-Assertionheader. - Data — SQLite files on the dev host under
/opt/data.
Lifecycle
- PR opened/updated → GitHub Actions builds on the Windows self-hosted runner.
- Image pushed to ACR.
- Helm deploys the PR release to MicroK8s.
- SQLite seeded from a template DB with
sqlite3 .backup. - Available at
prXXX.insfocus.combehind 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
emailbut acommon_name→ treated as a Cloudflare service token:common_nameis looked up inServiceTokens(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: livecp -acopies corrupted the DB. - Backfill —
strategy: Recreatefor 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:ServiceTokenslist. 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 -awithsqlite3 .backup.
Open
- Playwright test bot authenticating with a Cloudflare service token — being evaluated.