Skip to content

Subdomains & Access Management โ€‹

Guide for creating new subdomains, managing Cloudflare Access policies, and maintaining security.


Table of Contents โ€‹

  1. Domain Structure
  2. Creating New Subdomains
  3. Access Policies
  4. Testing Workflows
  5. Troubleshooting

Domain Structure โ€‹

Our domain structure follows this pattern:

ourlantern.app
โ”œโ”€โ”€ ourlantern.app              (production root)
โ”œโ”€โ”€ dev.ourlantern.app          (development staging)
โ”œโ”€โ”€ docs.ourlantern.app         (documentation site)
โ”œโ”€โ”€ docs.dev.ourlantern.app     (dev documentation)
โ”œโ”€โ”€ storybook.ourlantern.app    (component library)
โ”œโ”€โ”€ storybook.dev.ourlantern.app (dev component library)
โ”œโ”€โ”€ api.ourlantern.app          (future: backend/API)
โ””โ”€โ”€ blog.ourlantern.app         (future: marketing site)

Current Domains โ€‹

DomainEnvironmentPurposeAccess Policy
ourlantern.appProductionMain app (live)lantern-app (PIN)
dev.ourlantern.appDevelopmentTeam testing/staginglantern-app-dev (PIN)
docs.ourlantern.appProductionDocumentation sitePublic (or PIN if restricted)
docs.dev.ourlantern.appDevelopmentDev documentationPublic (or PIN if restricted)
storybook.ourlantern.appProductionComponent libraryPublic (recommended)
storybook.dev.ourlantern.appDevelopmentDev component libraryPublic (recommended)
*.ourlantern.appAnyCatch-all wildcardlantern-app-wildcard (PIN)

Creating New Subdomains โ€‹

Scenario: Adding a New Subdomain (e.g., api.ourlantern.app) โ€‹

Step 1: Code Your Feature โ€‹

Create a feature branch and develop your subdomain code:

bash
git checkout -b feature/api-endpoint dev
# ... implement API functionality ...
git push origin feature/api-endpoint

Step 2: Test on Preview URL โ€‹

Cloudflare auto-generates a preview URL:

  • https://feature-api-endpoint.lantern-app-dev.pages.dev
  • Already protected by dev Access app
  • Test thoroughly before proceeding

Step 3: Merge to Dev โ€‹

bash
git checkout dev
git merge feature/api-endpoint
git push origin dev

Result: Deploys to dev.ourlantern.app for staging.

Step 4: Add DNS Record in Cloudflare โ€‹

  1. Go to Cloudflare Dashboard โ†’ DNS
  2. Click Add record
  3. Configure:
    • Type: CNAME
    • Name: api
    • Content: lantern-app.pages.dev (or your prod project)
    • Proxy status: Proxied (orange cloud)
    • TTL: Auto
  4. Save

Step 5: Create/Update Access App โ€‹

Option A: Use Wildcard App (Recommended)

  • The existing lantern-app-wildcard app already protects *.ourlantern.app
  • No new Access app needed
  • New subdomain automatically inherits PIN policy

Option B: Create Specific Access App

  1. Go to Cloudflare Zero Trust โ†’ Access โ†’ Applications
  2. Click Add an application โ†’ Self-hosted
  3. Configure:
    • Application name: lantern-app-api
    • Domain: api.ourlantern.app
  4. Add same PIN policy as other apps
  5. Save

Step 6: Deploy to Production โ€‹

Once tested in dev:

bash
git checkout main
git merge dev
git push origin main

Result: Lives at https://api.ourlantern.app (protected by Access)


Access Policies โ€‹

Current Access Setup โ€‹

Three Access applications protect our domains:

  1. lantern-app (Production)

    • Domain: ourlantern.app
    • Policy: One-time PIN
    • Purpose: Main app, live users
  2. lantern-app-dev (Development)

    • Domain: dev.ourlantern.app
    • Policy: One-time PIN
    • Purpose: Team testing/staging
  3. lantern-app-wildcard (Catch-all)

    • Domain: *.ourlantern.app
    • Policy: One-time PIN
    • Purpose: Protect any future subdomains automatically

Modifying Access Policies โ€‹

Change Authentication Method โ€‹

For example, switch from "One-time PIN" to "Email Domain":

  1. Go to Cloudflare Zero Trust โ†’ Access โ†’ Applications
  2. Click the app name (e.g., lantern-app-dev)
  3. Click Edit
  4. Go to Policies tab
  5. Click your existing policy
  6. Change Require from "One-time PIN" to "Email addresses":
    • Add allowed email addresses (e.g., team members)
  7. Save policy

Add a New Policy โ€‹

Example: Allow GitHub organization members:

  1. Go to Applications โ†’ Click app โ†’ Edit โ†’ Policies
  2. Click Add a policy
  3. Configure:
    • Action: Allow
    • Include rule:
      • Selector: GitHub Organization
      • Value: Your org name
    • Session duration: 24 hours
  4. Save

Remove/Disable a Policy โ€‹

  1. Go to Applications โ†’ Click app โ†’ Edit โ†’ Policies
  2. Click the X button on the policy to delete
  3. Save

Session Management โ€‹

Adjust how long users stay logged in:

  1. Click app โ†’ Edit โ†’ Click policy
  2. Under Session duration, choose:
    • 15 minutes (most secure)
    • 1 hour
    • 24 hours (current default)
    • Custom duration
  3. Save

Testing Workflows โ€‹

Testing New Subdomains Locally โ€‹

Since new subdomains require Cloudflare DNS, test locally first:

bash
# In your dev server, you can test by mocking the subdomain
# For example, test API logic without hitting Cloudflare DNS
npm run dev

# Visit http://localhost:5173 and test your code

Testing on Preview URL โ€‹

Feature branches auto-deploy to preview URLs:

https://feature-api-endpoint.lantern-app-dev.pages.dev

Access PIN: Same as dev environment (request from team)

Testing in Dev Environment โ€‹

After merging to dev:

https://dev.ourlantern.app

Full staging environment with dev Firebase, staging data, etc.

Testing in Production โ€‹

After merging to main:

https://ourlantern.app

Live environment โ€” use real Firebase, real data, and careful QA!


Common Tasks โ€‹

Add a New Team Member to Access โ€‹

  1. Go to Access โ†’ Applications
  2. Click the app (e.g., lantern-app-dev)
  3. Click Edit โ†’ Policies
  4. Edit the PIN or email policy
  5. Add their email address
  6. Save

Disable Access Temporarily โ€‹

โš ๏ธ Warning: This makes your site public. Use with caution.

  1. Go to Access โ†’ Applications
  2. Click app โ†’ Edit
  3. Click the Delete button at the bottom
  4. Confirm deletion
  5. The domain becomes public (no more Access protection)

To re-enable: Create a new Access app with the same domain and policy.

Monitor Access Logs โ€‹

  1. Go to Access โ†’ Logs
  2. View recent authentication attempts
  3. Filter by domain, date range, or user
  4. Useful for debugging access issues

Set Different PIN for Different Environments โ€‹

Currently all use the same PIN. To differentiate:

  1. Edit dev Access app โ†’ Click policy
  2. Change PIN code
  3. Save

Now dev has a different PIN than prod (useful for separating access).


Security Best Practices โ€‹

โœ… Do โ€‹

  • โœ… Keep Access enabled on all non-local environments
  • โœ… Use strong, random PIN codes
  • โœ… Limit who has access to production
  • โœ… Review Access logs regularly
  • โœ… Test new subdomains on preview before production
  • โœ… Use the wildcard app for automatic protection

โŒ Don't โ€‹

  • โŒ Share PIN codes publicly or in code
  • โŒ Disable Access on production without a reason
  • โŒ Use weak PIN codes (like "1234")
  • โŒ Forget to add DNS records for new subdomains
  • โŒ Commit environment secrets to Git

Troubleshooting โ€‹

New Subdomain Not Working โ€‹

Error: 404 or "Not Found"

Checks:

  1. Is the DNS record created? Go to DNS tab and verify CNAME exists
  2. Is it proxied (orange cloud)? If not, enable proxying
  3. Did you wait for DNS propagation? (Usually instant, but can take 5 mins)
  4. Is the code actually deployed to the right Pages project?

Fix:

bash
# Verify DNS record
nslookup api.ourlantern.app

# Should resolve to lantern-app.pages.dev or lantern-app-dev.pages.dev

Access Redirecting to Wrong Domain โ€‹

Error: dev.ourlantern.app redirects to ourlantern.app

Cause: Multiple Access apps covering the same domain

Fix:

  1. Go to Access โ†’ Applications
  2. Check for duplicate entries
  3. Ensure each domain has only ONE app
  4. Delete duplicates if found

PIN Not Working โ€‹

Error: "Invalid PIN" even though you entered it correctly

Cause: PIN sent to your email may have expired (usually 15 mins)

Fix:

  1. Go back and request a new PIN
  2. Check spam/junk folder
  3. If still issues, contact admin to reset

Built with VitePress