Cloudflare Access Setup¶
This guide locks the docs behind Cloudflare Access so users must authenticate before they can read content.
Prerequisites¶
- Cloudflare account with Zero Trust enabled
- Domain managed in Cloudflare (for example:
user.com) - Cloudflare Pages project deployed from this repository
- Target hostname chosen (for example:
infra-docs.user.com)
1. Create or verify Cloudflare Pages deployment¶
- Cloudflare Dashboard -> Workers & Pages -> Create application -> Pages.
- Connect this Git repository.
- Build settings:
- Build command:
mkdocs build - Build output directory:
site - Deploy and confirm site loads at the generated
*.pages.devURL.
2. Add custom domain to the Pages project¶
- Open Workers & Pages -> your project -> Custom domains.
- Add
infra-docs.user.com(or your chosen docs hostname). - Complete DNS validation and wait for domain status to become Active.
3. Create Access app for custom domain¶
- Cloudflare Zero Trust -> Access -> Applications -> Add an application.
- Type: Self-hosted.
- Application domain:
infra-docs.user.com. - Session duration: choose policy (for example: 24h).
4. Protect the Pages default hostname¶
- Create a second Self-hosted Access application for the generated
project-name.pages.devhostname. - Apply the same policy intent as the custom domain.
- If you use preview deployments, protect preview hostnames as well.
5. Configure identity provider and policy¶
- Zero Trust -> Settings -> Authentication -> Login methods.
- Enable your preferred IdP (Google, GitHub, Okta, or One-time PIN).
- For each Access app, add an allow policy. Recommended baseline:
- Include: Emails ending in
@your-domain.com - Optional Include: explicit break-glass users
- Keep default deny behavior for non-matching users.
6. Validate behavior¶
- Open
infra-docs.user.comin a private browser window. - Confirm Access login appears before any docs content.
- Sign in with allowed account -> access granted.
- Sign in with non-allowed account -> access denied.
- Repeat for
project-name.pages.devand preview URLs.
7. Operational notes¶
- Protecting only the custom domain is not enough; users can bypass via
*.pages.devif unprotected. - Keep Access logs enabled and review denied attempts.
- Rotate IdP credentials and emergency access users regularly.
- If you need stricter privacy of the origin itself, use Cloudflare Tunnel + Access instead of managed static hosting.