How to lock a door yourself
- Open Zero Trust in the Cloudflare dashboard and create an organisation. Choose the free plan if it is enough.
- Under Access controls → Applications, choose Add an application → Self-hosted and set the address to, say,
example.com/admin. - Add an Allow policy that includes only your own email, and choose a login method (a one-time code by email, or GitHub, for example). An application without a policy denies everyone.
- Let your own code check the ticket again, so a missing rule does not open the door:
// Second lock: the site’s own code checks the Access ticket again (shortened)
const token = request.headers.get('cf-access-jwt-assertion'); // or the CF_Authorization cookie
const [header, body, sig] = token.split('.');
const keys = await fetch(`https://${TEAM}/cdn-cgi/access/certs`); // Cloudflare’s public keys
// 1. the signature must match one of the keys (RS256)
// 2. aud must be the site’s Access application, iss the site’s team
// 3. the ticket must not have expired (exp)
// 4. the email must be on the list of administrators (ADMIN_EMAILS)
if (!valid) return new Response('For the site’s maintainer only.', { status: 403 });
The same check lives in the open engine: the tingsvad.dk project on GitHub. Raw numbers as JSON: /api/maskine/doeren.
The family: The defences·The crawlers·The speed·Denmark right now·The archive cabinet·The door·The infrastructure map·The audit·Back to the machine room