$npx -y skills add jackspace/ClaudeSkillz --skill cloudflare-zero-trust-accessUse this skill when integrating Cloudflare Zero Trust Access authentication with Cloudflare Workers applications. Provides Hono middleware setup, manual JWT validation patterns, service token authentication, CORS handling with Access, and multi-tenant configurations. Prevents 8 c
| 1 | # Cloudflare Zero Trust Access Skill |
| 2 | |
| 3 | Integrate Cloudflare Zero Trust Access authentication with Cloudflare Workers applications using proven patterns and templates. |
| 4 | |
| 5 | --- |
| 6 | |
| 7 | ## Overview |
| 8 | |
| 9 | This skill provides complete integration patterns for Cloudflare Access, enabling application-level authentication for Workers without managing your own auth infrastructure. |
| 10 | |
| 11 | **What is Cloudflare Access?** |
| 12 | Cloudflare Access is Zero Trust authentication that sits in front of your application, validating users before they reach your Worker. After authentication, Access issues JWT tokens that your Worker validates. |
| 13 | |
| 14 | **Key Benefits**: |
| 15 | - No auth infrastructure to maintain |
| 16 | - Integrates with identity providers (Azure AD, Google, Okta, GitHub) |
| 17 | - Service tokens for machine-to-machine auth |
| 18 | - Built-in MFA and session management |
| 19 | - Comprehensive audit logs |
| 20 | |
| 21 | --- |
| 22 | |
| 23 | ## When to Use This Skill |
| 24 | |
| 25 | Trigger this skill when tasks involve: |
| 26 | |
| 27 | - **Authentication**: Protecting Worker routes, securing admin dashboards, API authentication |
| 28 | - **Access Control**: Role-based access (RBAC), group-based permissions, geographic restrictions |
| 29 | - **Service Auth**: Backend services calling Worker APIs, CI/CD pipelines, cron jobs |
| 30 | - **Multi-Tenant**: SaaS apps with organization-level authentication |
| 31 | - **CORS + Auth**: Single-page applications calling protected APIs |
| 32 | |
| 33 | **Keywords to Trigger**: |
| 34 | cloudflare access, zero trust, access authentication, JWT validation, service tokens, cloudflare auth, hono access, workers authentication, protect worker routes, admin authentication |
| 35 | |
| 36 | --- |
| 37 | |
| 38 | ## Integration Patterns |
| 39 | |
| 40 | ### Pattern 1: Hono Middleware (Recommended) |
| 41 | |
| 42 | Use `@hono/cloudflare-access` for one-line Access integration. |
| 43 | |
| 44 | **When to Use**: |
| 45 | - Building with Hono framework |
| 46 | - Need quick, production-ready setup |
| 47 | - Want automatic JWT validation and key caching |
| 48 | |
| 49 | **Template**: `templates/hono-basic-setup.ts` |
| 50 | |
| 51 | **Setup**: |
| 52 | ```typescript |
| 53 | import { Hono } from 'hono' |
| 54 | import { cloudflareAccess } from '@hono/cloudflare-access' |
| 55 | |
| 56 | const app = new Hono<{ Bindings: Env }>() |
| 57 | |
| 58 | // Public routes |
| 59 | app.get('/', (c) => c.text('Public page')) |
| 60 | |
| 61 | // Protected routes |
| 62 | app.use( |
| 63 | '/admin/*', |
| 64 | cloudflareAccess({ |
| 65 | domain: (c) => c.env.ACCESS_TEAM_DOMAIN, |
| 66 | }) |
| 67 | ) |
| 68 | |
| 69 | app.get('/admin/dashboard', (c) => { |
| 70 | const { email } = c.get('accessPayload') |
| 71 | return c.text(`Welcome, ${email}!`) |
| 72 | }) |
| 73 | ``` |
| 74 | |
| 75 | **Configuration** (`wrangler.jsonc`): |
| 76 | ```jsonc |
| 77 | { |
| 78 | "vars": { |
| 79 | "ACCESS_TEAM_DOMAIN": "your-team.cloudflareaccess.com", |
| 80 | "ACCESS_AUD": "your-app-aud-tag" |
| 81 | } |
| 82 | } |
| 83 | ``` |
| 84 | |
| 85 | **Benefits**: |
| 86 | - ✅ Automatic JWT validation |
| 87 | - ✅ Public key caching (1-hour TTL) |
| 88 | - ✅ Type-safe with TypeScript |
| 89 | - ✅ Production-tested and maintained |
| 90 | |
| 91 | --- |
| 92 | |
| 93 | ### Pattern 2: Manual JWT Validation |
| 94 | |
| 95 | Use Web Crypto API for custom validation logic. |
| 96 | |
| 97 | **When to Use**: |
| 98 | - Not using Hono framework |
| 99 | - Need custom validation beyond standard checks |
| 100 | - Want full control over JWT verification |
| 101 | |
| 102 | **Template**: `templates/jwt-validation-manual.ts` |
| 103 | |
| 104 | **Key Functions**: |
| 105 | ```typescript |
| 106 | // Validate JWT signature and claims |
| 107 | async function validateAccessJWT( |
| 108 | token: string, |
| 109 | env: Env |
| 110 | ): Promise<AccessJWTPayload> { |
| 111 | // 1. Decode header to get kid |
| 112 | // 2. Fetch public keys (with caching) |
| 113 | // 3. Verify signature using Web Crypto API |
| 114 | // 4. Validate aud, exp, iss |
| 115 | // 5. Return payload |
| 116 | } |
| 117 | ``` |
| 118 | |
| 119 | **Complexity**: ~100 lines |
| 120 | **Dependencies**: None (uses Web Crypto |