Cloudflare Access IdP Setup¶
One-time steps to configure Cloudflare Zero Trust Identity Providers and extend the API token before running terraform apply for the docs site (docs_site.tf).
Run this runbook once per Cloudflare account. Terraform looks up the IdP UUIDs automatically at plan time via a data source — no manual UUID copying or Doppler secrets needed for IdP IDs.
Prerequisites¶
- Cloudflare account admin access (Zero Trust > Settings + API Tokens)
- Google Workspace admin access (to create the OAuth client in Google Cloud Console)
- GitHub org admin access (to create the OAuth App under the
unipukaorg) CLOUDFLARE_API_TOKENalready in Doppleroep.base(will be extended in Step 1)
Step 1: Extend the Cloudflare API token¶
The existing CLOUDFLARE_API_TOKEN is scoped to DNS editing only. Add Zero Trust permissions.
- Log in to dash.cloudflare.com
- Go to My Profile → API Tokens
- Find the token used by Terraform (name matches what you set; check the value in Doppler
oep.base) - Click Edit
- Under Permissions, add:
Account/Access: Apps and Policies/ EditAccount/Access: Identity Providers/ ReadAccount/Cloudflare Pages/ Edit (forcloudflare_pages_project+cloudflare_pages_domain)Zone/Zone Settings/ Edit (forcloudflare_zone_settingSSL mode)- Click Continue to summary → Update Token
No value change — token UUID stays the same. No Doppler update needed.
Step 2: Record the Cloudflare account ID¶
The cf_account_id local in tenants.tf needs the real value.
- In dash.cloudflare.com, select the
unipukaaccount - Go to any zone or the account home — the Account ID is in the right sidebar under "API"
- Copy the 32-char hex value
Edit unipuka-infra-do/oep-infra/tenants.tf:
Step 3: Create the Google Workspace (G Suite) IdP¶
- In dash.cloudflare.com, navigate to Zero Trust → Integrations → Identity providers
- Click Add new → select Google Workspace
- Fill in:
- Name:
unipuka Google Workspace - App ID and Client secret: create an OAuth 2.0 Client in Google Cloud Console → APIs & Services → Credentials → Create credentials → OAuth client ID → Web application
- Authorized redirect URIs: the CF form shows the exact callback URL once you open the Google Workspace IdP page — copy it from there. It follows the pattern
https://<team-domain>.cloudflareaccess.com/cdn-cgi/access/callbackwhere<team-domain>is your team name shown in Zero Trust → Settings → Custom Pages → Team domain (e.g.unipuka→https://unipuka.cloudflareaccess.com/cdn-cgi/access/callback). - Copy the Client ID and Client Secret
- Authorized redirect URIs: the CF form shows the exact callback URL once you open the Google Workspace IdP page — copy it from there. It follows the pattern
- Account: your Google Workspace account domain (e.g.
unipuka.com) - Click Save
Terraform looks up the IdP UUID automatically at plan time via the data.cloudflare_zero_trust_access_identity_providers data source - no need to copy the UUID manually.
Step 4: Create the GitHub IdP¶
- Go to Zero Trust → Integrations → Identity providers
- Click Add new → select GitHub
- Fill in:
- Name:
unipuka GitHub - App ID and Client secret: create a GitHub OAuth App (org-level):
- Application name:
unipuka-cloudflare-access - Homepage URL:
https://docs.unipuka.app - Authorization callback URL: same URL as above — copy from the CF GitHub IdP form, or use
https://<team-domain>.cloudflareaccess.com/cdn-cgi/access/callbackwith your team domain from Zero Trust → Settings → Custom Pages - Click Register application → Generate a client secret
- Application name:
- Paste the Client ID and Client Secret into Cloudflare
- Click Save
Same as above - Terraform looks up the UUID automatically. No manual copy needed.
Step 5: Run terraform apply¶
cd unipuka-infra-do/oep-infra
# Plan — Terraform looks up IdP UUIDs automatically via the data source
direnv exec . doppler run --config base -- terraform plan
# Apply
direnv exec . doppler run --config base -- terraform apply
V&V¶
After terraform apply succeeds:
# CNAME resolves (CF returns CNAME chain when proxied)
dig +short CNAME docs.unipuka.app
# Unauthenticated request gets CF Access redirect (302 to cloudflareaccess.com)
curl -I https://docs.unipuka.app
- Open
https://docs.unipuka.appin an incognito window — you should see the CF Access login screen showing Google Workspace and GitHub options. - Log in with a
@unipuka.comGoogle account → docs site loads. - Log in with a non-
@unipuka.comaccount + not inunipukaGitHub org → 403 "Access denied" page. - Push a trivial commit to
unipuka-infra-ops/master→ CF Pages dashboard shows a new deployment within ~2 minutes (dash.cloudflare.com→ Pages →unipuka-docs→ Deployments).