Deploy to Cloudflare
Anchor runs as one Cloudflare Worker with one D1 database. One deployment serves one organization.
This guide covers the first deploy. The runbooks for a running instance (key rotation, audit retention, rate limiting, recovery, upgrades) are under Operations.
Prerequisites
Section titled “Prerequisites”- A Cloudflare account on the Workers Paid plan. Password hashing (PBKDF2, 100,000 iterations) needs more CPU per login than the Free plan allows (spec §12).
openssl, to generate the root key.- For the manual path only: Node.js 22+ and pnpm.
Deploy with the button
Section titled “Deploy with the button”The button copies this repository to your GitHub or GitLab account and deploys it with Workers Builds. Its setup page asks for:
- the repository to create, and the Worker name;
- the D1 database (
DB) and the queues (anchor-reencryptand its dead letter queue). Keep the suggested names or pick your own: Cloudflare creates them and writes their IDs into your copy’swrangler.jsonc; - one secret,
ANCHOR_ROOT_KEY; - the build and deploy commands, already filled in. The deploy command applies the database migrations and then deploys. Leave both as they are.
Generate and back up the root key before you paste it. The root key wraps every project’s key, and those keys encrypt every secret value. Cloudflare never shows a Worker secret again:
umask 077openssl rand -base64 32 > anchor-root.key # back this file up offline, then paste its valueBack up
anchor-root.keyoffline now (password manager or offline vault) and confirm the backup reads back the same value. Losing the root key loses every secret, permanently. There is no recovery path by design. Delete the local file once the backup is confirmed.
When the deploy finishes, open https://<your-worker>/setup and create the first owner.
Create the owner right after the deploy. The first account created at
/setupowns the instance, and until it exists anyone who reaches the URL can create it. Open/setupas soon as the deploy finishes. If it says the instance already has an owner and you did not create it, see Troubleshooting.
Your copy is an independent repository, not a fork: it does not follow this one. Every push to its default branch builds and deploys again. To take a new Anchor release, merge it into your copy (see Upgrade an instance).
Upgrading never needs a new database. Deleting the D1 database deletes every secret. If you delete it anyway and start over, your copy’s
wrangler.jsoncstill names the deleted database, and every build fails until you change it (see Troubleshooting).
Deploy manually
Section titled “Deploy manually”Clone the repository and run pnpm install at its root. Run every command below from the
repository root.
1. Create the database
Section titled “1. Create the database”pnpm exec wrangler d1 create anchorAdd the database_id it prints to the DB entry under d1_databases in wrangler.jsonc.
2. Create the re-encryption queues
Section titled “2. Create the re-encryption queues”Project key rotation re-encrypts secret values in the background through Cloudflare Queues (spec §6.2). Create the work queue and its dead letter queue once, before the first deploy:
pnpm exec wrangler queues create anchor-reencryptpnpm exec wrangler queues create anchor-reencrypt-dlq3. Generate, back up, then set the root key
Section titled “3. Generate, back up, then set the root key”The root key wraps every project’s key, and those keys encrypt every secret value. Cloudflare never shows a Worker secret again after you set it, so the backup has to happen first.
umask 077openssl rand -base64 32 > anchor-root.keyBack up
anchor-root.keyoffline now (password manager or offline vault) and confirm the backup reads back the same value. Losing the root key loses every secret, permanently. There is no recovery path by design.
Then set it and remove the local file:
pnpm exec wrangler secret put ANCHOR_ROOT_KEY < anchor-root.keyrm anchor-root.key4. Deploy
Section titled “4. Deploy”pnpm deploy:workerpnpm deploy:worker builds the dashboard (pnpm build writes apps/web/dist), applies the D1
migrations, then runs wrangler deploy. (The script is not called deploy: pnpm deploy is a pnpm
built-in and would run instead.)
5. Create the first owner
Section titled “5. Create the first owner”Create the owner right after the deploy. The first account created at
/setupowns the instance, and until it exists anyone who reaches the URL can create it. Open/setupas soon as the deploy finishes. If it says the instance already has an owner and you did not create it, see Troubleshooting.
Open https://<your-worker>/setup and create the owner. Or use the API:
curl -X POST https://<host>/api/v1/setup \ -H 'content-type: application/json' \ -d '{ "email": "owner@example.com", "name": "Owner", "password": "<at least 12 characters>" }'A 201 response means the owner exists. Setup works only once: later calls return 409.
GET /api/v1/setup/status tells you whether setup is still needed.
What the deploy sets up
Section titled “What the deploy sets up”The Worker serves the dashboard as static assets in single-page-application mode: /api/* always
reaches the Worker, and every other path that is not a file serves index.html. Security headers
(CSP, X-Frame-Options, …) come from apps/web/public/_headers.
The deploy also registers the daily Cron Trigger (0 3 * * *, from triggers.crons in
wrangler.jsonc). There is nothing to set up by hand: it purges audit events past retention (see
Audit retention) and resumes stalled project key rotations (see
Rotating a project key).
Never replace ANCHOR_ROOT_KEY with a new random value on a deployment that already has data. Anchor
refuses to create projects under a root key that cannot open the existing ones (500 with a
config_error log), and every secret read fails until the original key is restored.
Manage users
Section titled “Manage users”The first owner manages everyone else on the dashboard’s Users page (invite links valid 72
hours, role changes, disable, delete, password-reset links), or through the API at
/api/v1/users and /api/v1/invites. An instance always keeps at least one active owner: the API
refuses to demote, disable or delete the last one.
Next steps
Section titled “Next steps”- Rate-limit the public auth endpoints before you share the URL.
- Audit retention
- Rotate a project key and the root key
- Break-glass: lost owner recovery
- Upgrade an instance
Local development
Section titled “Local development”From the repository root:
cp .dev.vars.example .dev.vars # then fill in ANCHOR_ROOT_KEY with openssl rand -base64 32pnpm db:migrate:localpnpm --filter @anchor/server devThe server serves the API and the last dashboard build on http://localhost:8787. For dashboard
work, run pnpm --filter @anchor/web dev as well: Vite serves the UI with hot reload and proxies
/api to http://localhost:8787.
To exercise the Cron Trigger locally, run pnpm exec wrangler dev --test-scheduled and request
http://localhost:8787/__scheduled?cron=0+3+*+*+*; the console shows an audit_purged line.