diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 19b7f7b..cb30a5e 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -125,6 +125,37 @@ 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 @@ -132,7 +163,7 @@ jobs: 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. diff --git a/CLAUDE.md b/CLAUDE.md index 545236c..8fa35e1 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -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 | |---|---|---| diff --git a/README.md b/README.md index 061cdb3..5b584b8 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/README.zh-CN.md b/README.zh-CN.md index 41de71d..66869b5 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -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 控制台中配置。 diff --git a/apps/worker/.dev.vars.example b/apps/worker/.dev.vars.example new file mode 100644 index 0000000..7fa3096 --- /dev/null +++ b/apps/worker/.dev.vars.example @@ -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=