Skip to article frontmatterSkip to article content

πŸ” CNC Lab Documentation Security & Deployment Guide

CRITICAL: This documentation site (docs.cnclab.io) uses client-side authentication to restrict access to lab members only.

Security ImplementationΒΆ

How It WorksΒΆ

  1. Client-side authentication gate (_static/auth-gate.js) runs on every page load

  2. Google OAuth integration uses same system as main site (cnclab.io)

  3. Lab member verification against existing team whitelist API

  4. Secure token storage in browser localStorage with expiration

Authentication FlowΒΆ

1. User visits docs.cnclab.io
2. auth-gate.js loads and checks for stored token
3. If no token: redirect to Google OAuth
4. OAuth callback processes authorization code
5. Main site API exchanges code for access token
6. Email verified against lab member whitelist
7. Token stored locally, user sees documentation

Deployment RequirementsΒΆ

Vercel Environment Variables (Main Site: cnclab.io)ΒΆ

These must be configured in the Vercel dashboard for the main site project:

GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret

Google OAuth ConfigurationΒΆ

In your Google Cloud Console OAuth client, add these authorized redirect URIs:

https://docs.cnclab.io/auth/callback

File StructureΒΆ

docs-book/
β”œβ”€β”€ _static/
β”‚   └── auth-gate.js          # Client-side authentication script
β”œβ”€β”€ auth/
β”‚   └── callback.html         # OAuth callback handler  
β”œβ”€β”€ _config.yml              # Injects auth-gate.js into all pages
β”œβ”€β”€ vercel.json              # Deployment configuration
└── DEPLOYMENT_SECURITY.md   # This guide

API Endpoints (Main Site)ΒΆ

/api/docs/configΒΆ

/api/auth/exchange-tokenΒΆ

/api/auth/whitelistΒΆ

Testing AuthenticationΒΆ

βœ… With Authentication Enabled (Production)ΒΆ

  1. Visit docs.cnclab.io

  2. Should show Google login page

  3. After login with lab email β†’ documentation visible

  4. Login with non-lab email β†’ access denied

⚠️ Troubleshooting¢

Site shows login but fails after Google auth:

β€œCould not load auth config” in browser console:

User gets β€œAccess denied” after successful Google auth:

Security FeaturesΒΆ

Emergency AccessΒΆ

If authentication breaks and you need to disable it temporarily:

  1. Go to main site Vercel dashboard

  2. Remove GOOGLE_CLIENT_ID environment variable

  3. Redeploy main site

  4. Docs site will fall back to public access

The auth-gate.js script automatically detects missing configuration and allows public access as fallback.


Last Updated: September 6, 2025
Next Review: After any changes to OAuth setup or team member management