Skip to main content

GitHub Secrets & Token Management

This runbook explains the GitHub Secrets used across Factory Core and all Factory apps, with special attention to the CloudFlare token naming issue.

CloudFlare Token Confusion: CF_API_TOKEN vs. CLOUDFLARE_API_TOKEN

⚠️ IMPORTANT: There are two different environment variable names for CloudFlare API tokens, and this causes confusion.

Current State

Why We Have Two

The naming inconsistency occurred because:
  1. Different CloudFlare tools expect different env var names
  2. Wrangler uses CF_API_TOKEN natively
  3. Older CloudFlare documentation referenced CLOUDFLARE_API_TOKEN
  4. Both were created at different times without consolidation

Action Required

For all app repositories:
  1. ✅ In .github/workflows/deploy.yml, verify it uses:
  1. ❌ Never use:
  1. In wrangler.jsonc, do not set api_token — let it read from CF_API_TOKEN env var

Complete GitHub Secrets Inventory

Required for Factory Core (monorepo)

Required for Each App Repository

Required for Factory Video Rendering Pipeline

These secrets are required before apps/schedule-worker, apps/video-cron, and the render-video.yml workflow can complete a synthetic job flow.

Required for Prime Self Smoke Validation

These secrets are required by .github/workflows/smoke-prime-self.yml and apps/prime-self-smoke/tests/workspace-contract.spec.ts. Without them, authenticated workspace contract checks (personal + practitioner route/tool discoverability) will fail in CI. Canonical contract note: use only SMOKE_USER_* and SMOKE_PRACTITIONER_* secrets. Legacy SMOKE_EMAIL / SMOKE_PASSWORD aliases are no longer used by CI workflows.

How to Set GitHub Secrets

For Factory Core (monorepo)

  1. Navigate to: https://github.com/adrper79-dot/Factory/settings/secrets/actions
  2. Click “New repository secret”
  3. Add each secret from the inventory above
  4. Verify in workflows: Go to Actions → select any workflow → check “Secrets” are populated

For Each App (original 6 apps + any standalone apps)

The original 6 apps (prime-self, wordis-bond, cypher-healing, the-calling, ijustus, neighbor-aid) use setup-all-apps.mjs for bulk setup. Standalone apps added after Stage 6 (xpelevator, xico-city, and any future apps) use their own setup-{app}-secrets.yml workflow in the Factory repo instead.
  1. Navigate to: https://github.com/adrper79-dot/{app}/settings/secrets/actions
  2. Click “New repository secret”
  3. Add secrets from “Required for Each App Repository” table
  4. Commit the app’s wrangler.jsonc to reference via interpolation

Setting Secrets in wrangler.jsonc

✅ Good — Reference via env var:
❌ Bad — Hardcoded secrets:
Then in GitHub Actions:

Wrangler Secret vs. GitHub Secret

JWT_SECRET Example:

Rotation Schedule

Troubleshooting

Error: “403 Forbidden: PUT https://npm.pkg.github.com”

Cause: NODE_AUTH_TOKEN is missing or expired
Fix:
  1. Generate new GitHub PAT: https://github.com/settings/tokens?type=beta
  2. Scopes needed: read:packages only
  3. Update Secret: https://github.com/adrper79-dot/{repo}/settings/secrets/actions
  4. Re-run workflow

Error: “Unauthorized: CF_API_TOKEN invalid”

Cause: Token name mismatch (CLOUDFLARE_API_TOKEN used instead of CF_API_TOKEN)
Fix:
  1. Check .github/workflows/deploy.yml for correct env var name
  2. Verify GitHub Secrets page lists CF_API_TOKEN (not CLOUDFLARE_API_TOKEN)
  3. Test locally: CF_API_TOKEN=xxx wrangler deploy

Error: “Failed to connect to database: ECONNREFUSED”

Cause: NEON_URL / DATABASE_URL is wrong or expired
Fix:
  1. In Neon console: Project → Connection string → Copy fresh string
  2. Update GitHub Secrets: NEON_URL or DATABASE_URL (match app’s naming convention)
  3. Redeploy: wrangler deploy --env production

Error: “Sentry 401: Invalid DSN”

Cause: SENTRY_DSN is missing or typo’d
Fix:
  1. In Sentry: Settings → Projects → → Client Keys (DSN)
  2. Copy exact URL
  3. Update GitHub Secrets: SENTRY_DSN
  4. Redeploy

Error: “render-video workflow secret not found”

Cause: One of the video rendering pipeline secrets is missing from GitHub Actions. Fix:
  1. Compare the repository secrets against the “Required for Factory Video Rendering Pipeline” table above.
  2. Add the missing secret in Settings → Secrets and variables → Actions.
  3. Re-run the failed workflow and verify the schedule-worker callback succeeds.

Audit Checklist

Run this quarterly:
  • All Factory app repos have CF_API_TOKEN set (original 6 + xpelevator + xico-city + any new standalone apps)
  • No repo has CLOUDFLARE_API_TOKEN set without also having CF_API_TOKEN (both are needed for compatibility)
  • Each app has SENTRY_DSN and POSTHOG_KEY set as Wrangler secrets (not GitHub Secrets)
  • NODE_AUTH_TOKEN / GH_PAT is fresh (< 90 days old)
  • Wrangler secrets are up to date (run wrangler secret list --name {app} per app)
  • No hardcoded passwords in wrangler.jsonc or source code
  • HYPERDRIVE_* secrets exist in Factory repo for all apps with standalone workflows
  • Rate limiter ID registry in add-new-app.md is up to date