Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,45 @@ jobs:
TABLE_PREFIX: ${{ steps.prefix.outputs.table_prefix }}
run: bash ../../.github/scripts/d1-prefixed-migrations.sh

# Fail-closed: refuse to deploy if a required runtime secret is missing
# or empty, so an empty value can never overwrite a live Cloudflare
# Secret. The JSON lives only in $RUNNER_TEMP (mode 600) and is never
# written to the repository workspace.
- name: Write secrets file
env:
JWT_SECRET: ${{ secrets.JWT_SECRET }}
"SETUP_SECRET": ${{ secrets.SETUP_SECRET }}
run: |
set -euo pipefail
for name in JWT_SECRET SETUP_SECRET; do
if [ -z "$(printenv "$name" 2>/dev/null || true)" ]; then
echo "::error::GitHub Secret '$name' is empty or missing; aborting deploy (fail-closed)."
exit 1
fi
done
node --disable-warning=MODULE_TYPELESS_PACKAGE_JSON -e '
const fs = require("node:fs");
const path = require("node:path");
const file = path.join(process.env.RUNNER_TEMP, "secrets.json");
fs.writeFileSync(
file,
JSON.stringify({
JWT_SECRET: process.env.JWT_SECRET,
"SETUP_SECRET": process.env["SETUP_SECRET"],
}, null, 2) + "\n",
{ mode: 0o600 },
);
'
chmod 600 "$RUNNER_TEMP/secrets.json"

# Web and worker were built above; deploy the worker directly so wrangler
# can record the uploaded version ID for the verification step.
- name: Deploy
working-directory: apps/worker
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
WRANGLER_OUTPUT_FILE_PATH: ${{ runner.temp }}/wrangler-output.ndjson
run: pnpm run deploy
run: pnpm run deploy -- --secrets-file "$RUNNER_TEMP/secrets.json"

# Checked through the Cloudflare API rather than the public hostname, so
# the zone's bot protection can't make it inconclusive.
Expand Down
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ For local development, put secrets in `apps/worker/.dev.vars` (gitignored).

## wrangler.toml Variables

All set via the Cloudflare dashboard (Variables and Secrets). `keep_vars = true` prevents deployments from overwriting them.
All set via the Cloudflare dashboard (Variables and Secrets). `keep_vars = true` prevents deployments from overwriting them. The four ordinary variables `APP_NAME` / `APP_URL` / `RP_ID` / `APP_ORIGIN` are set via the CF dashboard only and are **not migrated** by CI; their values must **never change** — `RP_ID` / `APP_ORIGIN` are the WebAuthn passkey relying-party identifiers, and changing them invalidates every user's passkeys.

| Var | Required | Description |
|---|---|---|
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ Go to [Cloudflare dashboard](https://dash.cloudflare.com) → **Workers & Pages

> `keep_vars = true` is set in `wrangler.toml`, so deployments will never overwrite these values.
>
> The four ordinary variables `APP_NAME` / `APP_URL` / `RP_ID` / `APP_ORIGIN` are set via the **Cloudflare dashboard** only and are **not migrated** by CI; their values must **never change** — `RP_ID` / `APP_ORIGIN` are the WebAuthn passkey relying-party identifiers, and changing them invalidates every user's passkeys.
>
> Email provider settings (Resend API key, SMTP credentials, etc.) are configured in the **admin UI** after first login — no Cloudflare dashboard config needed.

### 5. Build and deploy
Expand Down
2 changes: 2 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@

> `wrangler.toml` 中设置了 `keep_vars = true`,因此部署不会覆盖这些值。
>
> 四个普通变量 `APP_NAME` / `APP_URL` / `RP_ID` / `APP_ORIGIN` 仅在 **Cloudflare 控制台** 设置,本次改动不迁移;其值**严禁变更**——`RP_ID` / `APP_ORIGIN` 是 WebAuthn 通行密钥的依赖方标识,一旦变更将导致所有用户的通行密钥失效。
>
> 邮件提供商设置(Resend API 密钥、SMTP 凭据等)在首次登录后通过**管理界面**配置 — 无需在 Cloudflare 控制台中配置。


Expand Down
21 changes: 21 additions & 0 deletions apps/worker/.dev.vars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Local development variables and secrets.
# Copy this file to apps/worker/.dev.vars and fill in real values.
# .dev.vars is gitignored — never commit real secrets.

# ─── Ordinary variables ───────────────────────────────────────────────────────
# Production values are set via the Cloudflare dashboard (Variables) and are
# NOT migrated by CI. Their values must never change:
# RP_ID / APP_ORIGIN are the WebAuthn passkey relying-party identifiers —
# changing them invalidates every user's passkeys.
APP_URL=
APP_NAME=
RP_ID=
APP_ORIGIN=

# ─── Runtime secrets ──────────────────────────────────────────────────────────
# Production values live in Cloudflare Secrets (uploaded from GitHub Secrets by
# the deploy workflow). Generate your own local values; do not reuse production
# values.
JWT_SECRET=
TOTP_ENCRYPTION_KEY=
SETUP_SECRET=
Loading