From f334d4f99507a8464c4fbe02a04c435ab8435e41 Mon Sep 17 00:00:00 2001 From: mapxn <16299874+mapxn@users.noreply.github.com> Date: Sun, 25 Oct 2026 10:06:50 +0800 Subject: [PATCH 1/2] ONE-253: deploy via --secrets-file + .dev.vars.example + var provenance - deploy workflow: add fail-closed 'Write secrets file' step (JWT_SECRET / TOTP_ENCRYPTION_KEY / SETUP_SECRET -> $RUNNER_TEMP/secrets.json, mode 600, per-key non-empty check naming any missing secret); Deploy step passes --secrets-file so wrangler uploads them as Cloudflare Secrets. - add apps/worker/.dev.vars.example listing the 7 keys with empty values. - CLAUDE.md / README.md / README.zh-CN.md: register provenance for APP_NAME / APP_URL / RP_ID / APP_ORIGIN (CF dashboard only, not migrated, values immutable). --- .github/workflows/deploy.yml | 40 ++++++++++++++++++++++++++++++++++- CLAUDE.md | 2 +- README.md | 2 ++ README.zh-CN.md | 2 ++ apps/worker/.dev.vars.example | 21 ++++++++++++++++++ 5 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 apps/worker/.dev.vars.example diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 19b7f7b..ffa763b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -125,6 +125,44 @@ jobs: TABLE_PREFIX: ${{ steps.prefix.outputs.table_prefix }} run: bash ../../.github/scripts/d1-prefixed-migrations.sh + # Fail-closed: refuse to deploy if any of the three runtime secrets 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 }} + TOTP_ENCRYPTION_KEY: ${{ secrets.TOTP_ENCRYPTION_KEY }} + "SETUP_SECRET": ${{ secrets.SETUP_SECRET }} + run: | + set -euo pipefail + check_secret() { + local value + value="$(printenv "$1" 2>/dev/null || true)" + if [ -z "$value" ]; then + echo "::error::GitHub Secret '$1' is empty or missing; aborting deploy (fail-closed)." + return 1 + fi + } + check_secret JWT_SECRET + check_secret TOTP_ENCRYPTION_KEY + check_secret 'SETUP_SECRET' + 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, + TOTP_ENCRYPTION_KEY: process.env.TOTP_ENCRYPTION_KEY, + "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 +170,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= From 1038164ba39a514dd0a575a0f1f46bb0756f3ab5 Mon Sep 17 00:00:00 2001 From: mapxn <16299874+mapxn@users.noreply.github.com> Date: Sun, 25 Oct 2026 10:12:01 +0800 Subject: [PATCH 2/2] ONE-253: CI-ize only JWT_SECRET + SETUP_SECRET (TOTP stays manual) Per parent ONE-249 final decision: the CI secrets list contains exactly two keys (JWT_SECRET, SETUP_SECRET), both fail-closed validated; TOTP_ENCRYPTION_KEY is not referenced, validated, or written by the deploy workflow. --- .github/workflows/deploy.yml | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index ffa763b..cb30a5e 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -125,28 +125,22 @@ jobs: TABLE_PREFIX: ${{ steps.prefix.outputs.table_prefix }} run: bash ../../.github/scripts/d1-prefixed-migrations.sh - # Fail-closed: refuse to deploy if any of the three runtime secrets 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. + # 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 }} - TOTP_ENCRYPTION_KEY: ${{ secrets.TOTP_ENCRYPTION_KEY }} "SETUP_SECRET": ${{ secrets.SETUP_SECRET }} run: | set -euo pipefail - check_secret() { - local value - value="$(printenv "$1" 2>/dev/null || true)" - if [ -z "$value" ]; then - echo "::error::GitHub Secret '$1' is empty or missing; aborting deploy (fail-closed)." - return 1 + 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 - } - check_secret JWT_SECRET - check_secret TOTP_ENCRYPTION_KEY - check_secret 'SETUP_SECRET' + done node --disable-warning=MODULE_TYPELESS_PACKAGE_JSON -e ' const fs = require("node:fs"); const path = require("node:path"); @@ -155,7 +149,6 @@ jobs: file, JSON.stringify({ JWT_SECRET: process.env.JWT_SECRET, - TOTP_ENCRYPTION_KEY: process.env.TOTP_ENCRYPTION_KEY, "SETUP_SECRET": process.env["SETUP_SECRET"], }, null, 2) + "\n", { mode: 0o600 },