Admin Access Guide
Admin Access Guide
How admin endpoints are protected and how to configure admin access.
Current Admin Authentication
Admin routes use Bearer JWT authentication as the primary layer, with optional Cloudflare Access as defense-in-depth. The /admin/* Angular panel and all backing API endpoints are fully protected.
Layer 1: Bearer JWT (Primary)
Admin requests require a valid JWT with role === 'admin'. The Angular admin panel attaches this automatically via the HTTP interceptor. For API access:
# Obtain a session token, then:curl -X GET https://bloqr-backend.jk-com.workers.dev/admin/local-users \ -H "Authorization: Bearer <your-jwt>"Layer 2: Cloudflare Access (Defense-in-Depth)
When configured, admin routes also require a valid Cloudflare Access JWT:
- User authenticates via Cloudflare Access (SSO, email OTP, etc.)
- CF Access sets a
CF-Access-JWT-Assertionheader - Worker verifies the JWT against CF Access JWKS
- If CF Access is not configured (
CF_ACCESS_TEAM_DOMAINnot set), this layer is skipped
Configuration:
wrangler secret put CF_ACCESS_TEAM_DOMAIN # e.g., "mycompany"wrangler secret put CF_ACCESS_AUD # Application audience tagLocal Auth Admin Access
Current State
| Feature | Status |
|---|---|
| CF Access verification | ✅ Active (when configured) |
Bearer JWT requireAuth() on admin routes | ✅ Active |
role === 'admin' check on admin routes | ✅ Active |
| Audit logging for all write/mutation operations | ✅ Active |
How to Become an Admin (Local Auth)
- Sign up — Create an account via
/sign-up - Set
INITIAL_ADMIN_EMAILin.dev.vars:INITIAL_ADMIN_EMAIL=you@youremail.com - Bootstrap — While signed in, call:
The Worker promotes your account to
Terminal window curl -X POST /api/auth/bootstrap-admin \-H "Authorization: Bearer <your-jwt>"adminrole and returns a new JWT. - Sign out and sign back in — The new JWT includes
role: "admin".
Bootstrap Problem: First Admin
When setting up a fresh installation with no existing admins:
-
Option A (Recommended): Use the
POST /auth/bootstrap-adminendpoint (email-gated byINITIAL_ADMIN_EMAIL). -
Option B: Directly update the D1 database via
wrangler d1 execute:Terminal window wrangler d1 execute bloqr-backend-app-db --command "UPDATE local_auth_users SET role='admin' WHERE identifier='you@example.com'"
Admin Endpoints Reference
The admin system exposes API endpoints across several resource groups. See the Admin API Reference for the full list with request/response schemas.
Resource groups:
| Group | Base Path | Description |
|---|---|---|
| Local Users | /admin/local-users | User management, tier editing, role assignment |
| Storage | /admin/storage/* | Storage tools (stats, export, query) |
| API Keys | /admin/auth/api-keys | Cross-user key management + revocation |
| Auth Config | /admin/auth/config | Auth configuration inspector |
| Usage | /admin/usage/* | Per-user API usage statistics |
Example: List Users
curl -X GET https://your-worker.workers.dev/admin/local-users \ -H "Authorization: Bearer eyJhbGciOiJSUzI1NiIs..."Cloudflare Access Setup (Recommended)
For production admin routes, configure Cloudflare Access as a defense-in-depth layer:
1. Create a Cloudflare Access Application
- Go to Cloudflare Zero Trust → Access → Applications
- Click “Add an application” → Self-hosted
- Configure:
- Application name:
Bloqr Compiler Admin - Application domain:
your-worker.workers.dev - Path:
/admin/*
- Application name:
- Add an access policy:
- Policy name:
Admin Users - Action: Allow
- Include: Emails matching your admin list
- Policy name:
2. Get the AUD Tag
- After creating the application, go to its settings
- Copy the Application Audience (AUD) Tag
- Store it:
Terminal window wrangler secret put CF_ACCESS_AUD
3. Set the Team Domain
wrangler secret put CF_ACCESS_TEAM_DOMAIN# Enter your team name (e.g., "mycompany")# This corresponds to: https://mycompany.cloudflareaccess.comHow CF Access Works with the Worker
- User navigates to
/admin/storage/stats - Cloudflare Access intercepts → shows login page (email OTP, SSO, etc.)
- After authentication, CF Access sets
CF-Access-JWT-Assertionheader - Worker verifies the JWT against
https://<team>.cloudflareaccess.com/cdn-cgi/access/certs - If valid, request proceeds to the admin handler
- If invalid (or not configured), request is rejected with 403
Security Recommendations
- Always configure CF Access for production admin routes — it provides an additional authentication layer independent of your application code
- Limit admin users — only grant
role: adminto users who need it - Monitor admin access — check Worker logs for admin endpoint usage
- Use
INITIAL_ADMIN_EMAIL— set this env var to gate bootstrap to a specific email address