Cloudflare

From gilesknap/tpi-k3s-ansible · View interactive version

Cloudflare is an AI agent skill from the GitHub repository gilesknap/tpi-k3s-ansible. Cloudflare Tunnel and Access configuration for exposing K3s services externally.

How to use this skill

Skill file

Cloudflare

Architecture

Exposed Services

The tunnelled hostnames are the tunnel_services list in

cloudflare/locals.tf (grafana, headlamp, oauth2, argocd-monitor, home,

argocd, alertmanager, minecraft, scrap, pages, ntfy, ...): read it there

rather than trusting a copy.

the Access login) and the zone's one Free-plan rate-limiting rule

(path-based: Free cannot match the hostname), both in cloudflare/;

ntfy's own token auth is the gate (docs/how-to/ntfy.md)

DNS-only A record on the VPS relay's public IP (additions/vps-relay/)

Gotchas

Access apps and policies, zone settings, cache and rate-limiting rules (login methods are

dashboard-only)

(docs/how-to/cloudflare-as-code.md). Change it there, just cf-plan

(read-only token) and the owner runs just cf-apply; a dashboard edit

is drift that the next apply reverts. Live per-account values (IDs,

emails) are in the gitignored cloudflare/live.auto.tfvars; state is

local, encrypted, gitignored. Never run cf-apply / tofu apply yourself.

cloudflare/tunnel.tf, output tunnel_token. Rotate: bump

tunnel_secret_rotation, owner runs just cf-apply, then

just cf-seal-tunnel-token (seals it, updates .env's

CLOUDFLARE_TUNNEL_TOKEN if present, never prints it), PR/merge, wait

for sync, kubectl -n cloudflared rollout restart deployment/cloudflared,

then just cf-tunnel-disconnect (old connections survive a rotation)

and check only the pods' connector IDs reconnect. Never rotate in the

dashboard: tofu doesn't read the secret back, so it would reseal a dead

one. The first cf-apply on an imported tunnel rotates it. With no

cluster to seal against (first build, or cluster down too),

just cf-env-tunnel-token writes the token into .env only (adds or

replaces the line, never prints it) and the GENERATE_SECRETS=true run

seals it. Run cf-

recipes from the main checkout (docs/how-to/cloudflare-as-code.md)

(additions/ingress sub-chart) + an entry in

tunnel_services in cloudflare/locals.tf (route + DNS), then plan/apply

tunnel with ssl_redirect: false generate http:// OAuth callbacks. Dex

static clients must list both http:// and https:// redirect URIs.

defaults to Cilium's Gateway, http://cilium-gateway-web.gateway.svc.cluster.local

(local.gateway; ADR 0016), which also serves the node addresses (LAN,

tailnet, the VPS) through servicelb; there is no other ingress

controller (docs/how-to/gateway.md). Direct-to-service routes (e.g.

http://home.home.svc.cluster.local) bypass the HTTPRoutes and

oauth2-proxy entirely, so auth headers like

X-Auth-Request-Email will be empty. Cloudflare Access still authenticates,

but oauth2-proxy features (email headers, sign-out) won't work.

it) or one-time PIN (Viewers). An Access prompt is Cloudflare's; a second

GitHub prompt after it comes from Dex or oauth2-proxy inside the cluster.

Use a service-token (non_identity) policy, as scrap's /mcp does in

cloudflare/access.tf. Only if the host is truly public, set

access_bypass = true on its tunnel_services entry and add a bypass

app in access.tf; cloudflare/access_guard.tf fails the plan for a

bypass app on a hostname not marked that way. Access apps are code: the

most specific destination wins over the *.gkcluster.org wildcard, so

there is no dashboard ordering to check.

Key Files

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.