Deploy the issuer on Cloudflare Workers
DevCentr runs the published issuer at https://login.devcentr.orgunchecked as a Cloudflare Worker.
The Node server (private-docs-login serve) is still the reference host.
The Worker is an optional deploy target under deploy/cloudflare/, and nothing in src/ depends on it.
Why a Worker with D1
The issuer core already uses Web standard Request, Response, and Web Crypto, so it runs on Workers without a Node shim.
A Worker has no single machine to keep running, and DevCentr’s DNS and Cloudflare Access are in the same account.
Sign-in state is three short-lived kinds of row: pending authorize requests (10 minutes), one-time authorization codes (5 minutes), and access tokens (10 minutes).
D1 holds them.
D1 deletes and returns a row in one statement (DELETE … RETURNING), so a code cannot be redeemed twice.
Workers KV was not chosen: it is eventually consistent, it cannot take a row atomically, and its shortest TTL is 60 seconds.
Durable Objects would also work, with more code that only runs on Workers.
The same table backs the Node host in a SQLite file (PRIVATE_DOCS_LOGIN_STATE_PATH, node:sqlite, Node 22.13 or later).
Tests use the in-memory adapter.
Expired rows are swept on the next write, so there is no cron trigger.
The signing key is a Worker secret, not generated at startup, so /jwks stays the same across deploys and isolates.
Files
deploy/cloudflare/wrangler.toml-
Worker name, the
login.devcentr.orgcustom domain, the D1 bindingPRIVATE_DOCS_LOGIN_STATE, and the account that holds the devcentr.org zone. No secrets. deploy/cloudflare/issuer.sdl-
The Worker’s config: issuer
https://login.devcentr.orgunchecked, GitHub App ownerdev-centr, and the Cloudflare Access client for theamdphreakteam. Every secret is an environment name. deploy/cloudflare/migrations/-
The D1 table.
deploy/cloudflare/secrets.mjs-
Builds
var/worker-secrets.jsonforwrangler secret bulkfrom the gitignoredvar/folder. It prints names only.
Secrets
| Worker secret | Comes from | Kept in |
|---|---|---|
|
|
Bitwarden, as an attachment on the Private Docs Login item. Then delete |
|
|
Bitwarden. |
|
|
Bitwarden. The same value goes into the Cloudflare Access OpenID Connect identity provider as its client secret. |
|
The old |
Not secret. Delete it after the rotation window. |
First deploy
Run these from the repository root on the operator’s machine, logged in with npx wrangler@4 login.
-
Register the GitHub App under dev-centr (see Register the GitHub App under dev-centr). This writes
var/github-app.json. -
Create the D1 database, paste the printed
database_idintodeploy/cloudflare/wrangler.toml, and commit that change. The id is not a secret.npm run cf:d1:create npm run cf:d1:migrate -
Upload the secrets. This writes
var/worker-secrets.json, sends it withwrangler secret bulk, and deletes it.npm run cf:secrets -
Deploy. The custom domain route creates the proxied DNS record for
login.devcentr.organd its certificate. Do not create that record by hand.npm run cf:check npm run cf:deploy -
Check health.
npm run healthz/healthzanswers200with{"ok":true,"storage":"d1","state":"ok",…}. It answers503when the signing key, a secret, or the D1 table is missing. It names no secret, client, or key material./healthis the older liveness answer and stays.
Then give the Cloudflare Access identity provider these values:
-
Auth URL
https://login.devcentr.org/authorizeunchecked -
Token URL
https://login.devcentr.org/tokenunchecked -
Certificate URL
https://login.devcentr.org/jwksunchecked -
Client id
cloudflare-access, client secret fromvar/cloudflare-access-client-secret(Bitwarden item Private Docs Login - Cloudflare Access client secret) -
The token URL accepts the secret as HTTP Basic or as form fields, so either Access behavior works
-
Scope
openid email, email claimemail, groups claimgroups, values likegithub:github.com:dev-centr
Register the GitHub App under dev-centr
node bin/private-docs-login.mjs github-manifest --config deploy/cloudflare/issuer.sdl
The command prints the owner, the GitHub form URL, and the callback and setup URLs before it starts:
-
GitHub form
https://github.com/organizations/dev-centr/settings/apps/newunchecked -
Callback URL
https://login.devcentr.org/github/callbackunchecked -
Setup URL
https://login.devcentr.org/github/setupunchecked -
Manifest return
http://127.0.0.1:8765/setup/github/callbackunchecked
Open http://127.0.0.1:8765/unchecked on the same machine and choose Continue to GitHub.
The one manual step is on GitHub: an owner of dev-centr reviews the app named Private Docs Login and chooses Create GitHub App for dev-centr.
GitHub returns to the local command, which writes var/github-app.json and var/github-app.pem and prints neither secret.
GitHub’s manifest code expires after one hour, so finish in one sitting.
The app is public, asks for Organization members read and Email addresses read, and has no webhook.
Organizations opt in at https://github.com/apps/private-docs-login/installations/newunchecked.
Rotate secrets
- Signing key
-
-
Save the current public keys:
curl.exe -s https://login.devcentr.org/jwksunchecked -o var/previous-jwks.json(plaincurlon Linux and macOS). -
Upload them as
PRIVATE_DOCS_LOGIN_PREVIOUS_JWKSfromdeploy/cloudflare:npx wrangler@4 secret put PRIVATE_DOCS_LOGIN_PREVIOUS_JWKSwith the file piped in. The value is public keys only; the issuer refuses a value with private key fields. -
Move the old
var/signing.peminto Bitwarden as the retired key and delete it fromvar/. -
Change
kidindeploy/cloudflare/issuer.sdl(for exampleprivate-docs-login-2) and commit it. -
Run
npm run cf:secrets(it creates the new key) andnpm run cf:deploy. -
After at least 24 hours, delete the previous keys:
npx wrangler@4 secret delete PRIVATE_DOCS_LOGIN_PREVIOUS_JWKS. Tokens live 10 minutes; the extra time covers relying parties that cache/jwks.
-
- GitHub client secret
-
Generate a new client secret on the app’s GitHub settings page, put it in
var/github-app.jsonand Bitwarden, runnpm run cf:secrets, then delete the old secret on GitHub. - Cloudflare Access client secret
-
Delete
var/cloudflare-access-client-secret, runnpm run cf:secrets, and set the new value on the Access identity provider straight away. Sign-ins fail between the two steps.