Overview
The SOP runbook at sop.sanmarcsoft.com is protected by Cloudflare Access (part of Cloudflare Zero Trust). Only authorized GitHub accounts can access the site.
Prerequisites
- Cloudflare account with Zero Trust enabled
- Domain
sanmarcsoft.comon Cloudflare - GitHub OAuth application (or use Cloudflare’s built-in GitHub IdP)
Setup Steps
Step 1: Enable Cloudflare Zero Trust
- Go to https://one.dash.cloudflare.com/
- Select the Cloudflare account
- Navigate to Access > Applications
Step 2: Add GitHub as Identity Provider
Go to Settings > Authentication > Login methods
Click Add new > GitHub
Configure:
- Client ID: Create a GitHub OAuth App at https://github.com/settings/developers
- Client Secret: From the GitHub OAuth App
- Authorization URL:
https://github.com/login/oauth/authorize(auto-filled) - Token URL:
https://github.com/login/oauth/access_token(auto-filled)
GitHub OAuth App settings:
- Application name: SanMarcSoft Cloudflare Access
- Homepage URL:
https://sanmarcsoft.com - Authorization callback URL:
https://<team-domain>.cloudflareaccess.com/cdn-cgi/access/callback- The team domain is found in Zero Trust > Settings > Custom Pages
Step 3: Create Access Application
Go to Access > Applications
Click Add an application > Self-hosted
Configure:
Application Configuration:
- Application name: SOP Runbook
- Session duration: 24 hours
- Application domain:
sop.sanmarcsoft.com
Identity providers:
- Select GitHub only
Step 4: Create Access Policy
In the application configuration, add a policy:
Policy name: Allow smsmatt
Action: Allow
Include rules:
- Selector: GitHub Organizations
- Value:
Sanmarcsoft
OR (more restrictive):
- Selector: Emails
- Value: The email associated with the
smsmattGitHub account
AND:
- Selector: Login Methods
- Value: GitHub
No additional Exclude or Require rules needed for a single-user setup
Step 5: Configure DNS
Add a CNAME or A record for sop.sanmarcsoft.com:
| |
Note: proxied: true is required for Cloudflare Access to intercept requests.
Step 6: Deploy to Cloudflare Pages
Connect the
Sanmarcsoft/sop-runbookGitHub repository to Cloudflare PagesConfigure build settings:
- Build command:
hugo --minify - Build output directory:
public - Root directory:
/(project root) - Environment variable:
HUGO_VERSION=0.139.0(or latest)
- Build command:
Set custom domain:
- Go to the Pages project > Custom domains
- Add
sop.sanmarcsoft.com - Cloudflare will verify DNS automatically
Verification
Test Access Control
- Open
https://sop.sanmarcsoft.comin an incognito browser - You should be redirected to the Cloudflare Access login page
- Select GitHub as the login method
- Authenticate with the
smsmattGitHub account - You should be granted access and redirected to the SOP runbook
Test Denied Access
- Open in incognito
- Authenticate with a different GitHub account
- You should see an “Access Denied” page
Maintenance
Adding Additional Users
- Go to Access > Applications > SOP Runbook > Policies
- Edit the policy
- Add additional email addresses or GitHub org membership rules
Revoking Access
- Go to Access > Applications > SOP Runbook > Policies
- Remove the user from the policy
- To immediately revoke an active session: Access > Overview > Active sessions > Revoke
Viewing Access Logs
- Go to Access > Logs
- Filter by application: SOP Runbook
- View login attempts, approvals, and denials
Cloudflare Access Policy Examples
Allow only a specific GitHub user
Rule: Include
Selector: Emails
Value: matt@sanmarcsoft.com (GitHub email)
Rule: Require
Selector: Login Methods
Value: GitHub
Allow all members of the Sanmarcsoft GitHub org
Rule: Include
Selector: GitHub Organizations
Value: Sanmarcsoft
Allow specific GitHub teams
Rule: Include
Selector: GitHub Organizations
Value: Sanmarcsoft
Rule: Require
Selector: GitHub Teams (if available)
Value: engineering
Troubleshooting
- “Application not found”: Ensure the domain in the Access Application exactly matches
sop.sanmarcsoft.com. - Redirect loop: Check that the DNS record has
proxied: true. Cloudflare Access requires the orange cloud. - GitHub login fails: Verify the GitHub OAuth App callback URL matches the Cloudflare Access team domain.
- Access denied for correct user: Check that the policy selector matches the user’s GitHub email, not their username.
- Pages build fails: Ensure
HUGO_VERSIONenvironment variable is set. Cloudflare Pages needs to know which Hugo version to use.