Cloudflare Access Policies
Cloudflare Access adds an identity-aware proxy in front of NodeKAT, allowing you to enforce authentication and authorization policies before users reach your application.
Overview
Section titled “Overview”Access Policies enable you to:
- Require Authentication: Force users to log in via identity providers
- Granular Control: Define who can access what based on email, groups, or IP
- Audit Logging: Track all access attempts and actions
- Session Management: Control session duration and re-authentication
Prerequisites
Section titled “Prerequisites”- Cloudflare account with Zero Trust enabled
- Domain configured with Cloudflare Tunnels
- NodeKAT accessible via Cloudflare Tunnel
- Identity provider configured (GitHub, Google, Okta, etc.)
Setting Up Access
Section titled “Setting Up Access”Step 1: Configure Identity Provider
Section titled “Step 1: Configure Identity Provider”- Go to Zero Trust → Settings → Authentication
- Click Add new under Login methods
- Select your identity provider (GitHub recommended for development teams)
- Follow the configuration steps
GitHub OAuth Setup:
- Go to GitHub → Settings → Developer settings → OAuth Apps
- Click New OAuth App
- Fill in the details:
- Application name: NodeKAT Access
- Homepage URL:
https://nodekat.yourdomain.com - Authorization callback URL:
https://your-team.cloudflareaccess.com/cdn-cgi/access/callback
- Copy Client ID and Client Secret to Cloudflare Access
Step 2: Create Access Application
Section titled “Step 2: Create Access Application”- Go to Zero Trust → Access → Applications
- Click Add an application
- Select Self-hosted
- Configure:
- Application name: NodeKAT
- Session duration: 24 hours (or your preference)
- Application domain:
nodekat.yourdomain.com
Step 3: Create Access Policy
Section titled “Step 3: Create Access Policy”Create a policy to control who can access NodeKAT:
Allow Specific Users:
Action: AllowInclude: - Email: user1@example.com - Email: user2@example.comAllow Organization Members:
Action: AllowInclude: - GitHub Organization: your-orgRequire MFA:
Action: AllowInclude: - Email domain: example.comRequire: - Authentication method: MFAIP-Based Access:
Action: AllowInclude: - IP range: 203.0.113.0/24Policy Types
Section titled “Policy Types”Allow Policies
Section titled “Allow Policies”Grant access to users who meet criteria:
- Email: Specific email addresses
- Email domain: All users from a domain
- IP range: Users from specific networks
- Country: Users from specific countries
- GitHub organization: Members of a GitHub org
- Google groups: Members of Google Workspace groups
- SAML attributes: Custom SAML assertions
Block Policies
Section titled “Block Policies”Explicitly deny access:
Action: BlockInclude: - Country: CN, RU, KPBypass Policies
Section titled “Bypass Policies”Skip authentication for specific conditions:
Action: BypassInclude: - IP range: 10.0.0.0/8Useful for internal networks or service accounts.
Advanced Policy Configuration
Section titled “Advanced Policy Configuration”Combining Rules
Section titled “Combining Rules”AND Logic:
Action: AllowInclude: - Email domain: example.comRequire: - Authentication method: MFAOR Logic:
Action: AllowInclude: - Email: admin@example.com - Email: user@example.comTime-Based Access
Section titled “Time-Based Access”Restrict access to business hours:
Action: AllowInclude: - Email domain: example.comRequire: - Time: Monday-Friday 9:00-17:00Device Posture
Section titled “Device Posture”Require device compliance:
Action: AllowInclude: - Email domain: example.comRequire: - Device Posture: Disk encrypted - Device Posture: OS version currentIntegration with NodeKAT
Section titled “Integration with NodeKAT”Pass User Headers
Section titled “Pass User Headers”Cloudflare Access sends user identity as headers:
| Header | Description |
|---|---|
CF-Access-Client-Id | Client application ID |
CF-Access-Jwt-Assertion | JWT with user claims |
Cf-Access-Authenticated-User-Email | User’s email address |
Configure NodeKAT
Section titled “Configure NodeKAT”Update NodeKAT to trust these headers:
environment: - TRUST_CLOUDFLARE_HEADERS=true - CLOUDFLARE_AUTH_HEADER=Cf-Access-Authenticated-User-EmailValidate JWT (Advanced)
Section titled “Validate JWT (Advanced)”For additional security, validate the JWT:
// NodeKAT middleware exampleconst jwt = require('jsonwebtoken');
function validateCloudflareJWT(req, res, next) { const token = req.headers['cf-access-jwt-assertion'];
if (!token) { return res.status(401).json({ error: 'Missing authentication' }); }
try { const decoded = jwt.verify(token, process.env.CLOUDFLARE_JWT_PUBLIC_KEY); req.user = decoded; next(); } catch (err) { return res.status(401).json({ error: 'Invalid token' }); }}Get your JWT public key from:
https://<your-team>.cloudflareaccess.com/cdn-cgi/access/certsMonitoring and Auditing
Section titled “Monitoring and Auditing”Access Logs
Section titled “Access Logs”View all authentication attempts:
- Go to Zero Trust → Logs → Access
- Filter by user, application, or action
- Export logs for compliance
Real-Time Notifications
Section titled “Real-Time Notifications”Set up alerts for:
- Failed login attempts
- Blocked access attempts
- New device authentications
Configure in Zero Trust → Settings → Notifications
Troubleshooting
Section titled “Troubleshooting”Infinite Redirect Loop
Section titled “Infinite Redirect Loop”If you see an infinite redirect:
- Check your tunnel configuration
- Ensure
noTLSVerify: trueif using self-signed certificates - Verify the application domain matches exactly
Users Can’t Authenticate
Section titled “Users Can’t Authenticate”- Verify identity provider configuration
- Check policy rules aren’t too restrictive
- Review identity provider logs
JWT Validation Failures
Section titled “JWT Validation Failures”- Ensure you’re using the correct public key
- Check token hasn’t expired
- Verify algorithm matches (usually RS256)
Best Practices
Section titled “Best Practices”- Require MFA for all administrative access
- Set session timeouts appropriately (8-24 hours)
- Use IP restrictions for additional security layer
- Monitor logs regularly for suspicious activity
- Test policies with a small group before full rollout
- Document your policies for team reference