From d7d4eef87b33ad3b5dce43e8ae948715903f2b5b Mon Sep 17 00:00:00 2001 From: mapxn <16299874+mapxn@users.noreply.github.com> Date: Sun, 25 Oct 2026 16:23:19 +0800 Subject: [PATCH] ONE-289: README deployment docs distinguish GitHub Actions vs CF console vars --- README.md | 30 ++++++++++++++++++------------ README.zh-CN.md | 32 +++++++++++++++++++------------- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 5b584b8..ec92ea2 100644 --- a/README.md +++ b/README.md @@ -46,26 +46,32 @@ Create the following resources in Cloudflare, please note their IDs for the next | D1 SQL databases | `shortlink` (customizable) | -### 3. Add GitHub Actions secrets +### 3. Add GitHub Actions secrets and variables In your GitHub repository go to **Settings → Secrets and variables → Actions** and add: -Repository secrets: +Repository secrets (the deploy workflow reads these; only `JWT_SECRET` and `SETUP_SECRET` are uploaded to Cloudflare as CF Secrets via `--secrets-file`): | Secret | Value | |---|---| -| `CLOUDFLARE_API_TOKEN` | API token created with the **Edit Cloudflare Workers** template from the [User API Tokens](https://dash.cloudflare.com/profile/api-tokens) page | +| `CLOUDFLARE_API_TOKEN` | API token created with the **Edit Cloudflare Workers** template from the [User API Tokens](https://dash.cloudflare.com/profile/api-tokens) page. Needs edit access to the D1 database and edit/version-read access to the Worker. | +| `JWT_SECRET` | Any random string ≥ 32 characters. CI uploads it as a Cloudflare Secret via `--secrets-file`. | +| `SETUP_SECRET` | `openssl rand -hex 24`. CI uploads it as a Cloudflare Secret via `--secrets-file`; used for setup/migrations. | -Repository variables: +> **Migrating an existing deployment to CI** — the GitHub `JWT_SECRET` and `SETUP_SECRET` values must be the **same values** as the Cloudflare Secrets already configured on the Worker. Fill in the existing values; never generate new ones to replace them, or CI will overwrite the live secrets with different values. + +Repository variables (the deploy workflow reads these): | Variable | Value | |---|---| | `CLOUDFLARE_ACCOUNT_ID` | Your account ID (visible in the Cloudflare dashboard URL) | | `KV_NAMESPACE_ID` | Workers KV ID from the previous step | | `D1_DATABASE_ID` | D1 database ID from the previous step | -| `D1_DATABASE_NAME` |(Configure as needed) If you customized the D1 database name in the previous step, you must configure it with the corresponding name; otherwise, no configuration is required | +| `D1_DATABASE_NAME` | (Optional) Only needed if you customized the D1 database name in the previous step; otherwise, no configuration is required | +| `TABLE_PREFIX` | (Optional) Production environment variable. The CI reserved word `none` means explicit no prefix. Must equal the Worker's `TABLE_PREFIX` plain-text variable (step 4). | +| `APP_URL` | Production environment variable used by the smoke test; must point at the production URL and equal the Worker's `APP_URL` variable (step 4). | -The deploy workflow (`.github/workflows/deploy.yml`) injects these IDs into `wrangler.toml` at deploy time via `sed`, so no IDs are ever committed to the repository. +The deploy workflow (`.github/workflows/deploy.yml`) injects the resource IDs into `wrangler.toml` at deploy time via `sed`, so no IDs are ever committed to the repository. ### 4. Configure variables and secrets @@ -73,18 +79,18 @@ Go to [Cloudflare dashboard](https://dash.cloudflare.com) → **Workers & Pages | Name | Type | Required | Example / Notes | |---|---|---|---| -| `APP_URL` | Variable | Yes | `https://yourdomain.com` | +| `APP_URL` | Variable | Yes | `https://yourdomain.com` — must equal the GitHub `APP_URL` variable (step 3) | | `APP_NAME` | Variable | Yes | `ShortLink` — default app name, overridable in admin UI | | `RP_ID` | Variable | Yes | `yourdomain.com` — WebAuthn relying party ID (domain only) | | `APP_ORIGIN` | Variable | Yes | `https://yourdomain.com` — WebAuthn origin (full URL) | -| `TABLE_PREFIX` | Variable | No | Three-state table prefix. Unset → default `sl` (`sl_users`, `sl_links`, …). A custom value → that value, case preserved, `[^a-zA-Z0-9_]` stripped. Explicit empty string → no prefix (deployer accepts the table-collision risk). Set **before** first setup and never change it once data exists. | -| `JWT_SECRET` | Secret | Yes | Any random string ≥ 32 chars | -| `TOTP_ENCRYPTION_KEY` | Secret | Yes | `openssl rand -hex 32` | -| `SETUP_SECRET` | Secret | Yes | `openssl rand -hex 24` — used to trigger migrations | +| `TABLE_PREFIX` | Variable | No | Three-state table prefix. Unset → default `sl` (`sl_users`, `sl_links`, …). A custom value → that value, case preserved, `[^a-zA-Z0-9_]` stripped. Explicit empty string → no prefix (deployer accepts the table-collision risk). Must equal the GitHub `TABLE_PREFIX` variable (step 3). Set **before** first setup and never change it once data exists. | +| `TOTP_ENCRYPTION_KEY` | Secret | Yes | `openssl rand -hex 32` — encrypts TOTP credentials; rotating it invalidates every bound TOTP. The **only** secret configured in the Cloudflare console and never handled by CI. | > `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. +> `JWT_SECRET` and `SETUP_SECRET` are **not** configured here — CI uploads them from the GitHub Secrets added in step 3. `TOTP_ENCRYPTION_KEY` is the only secret that stays exclusively in the Cloudflare console. +> +> The 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. `APP_URL` and `TABLE_PREFIX` are also read by CI as GitHub variables (step 3) for the smoke test and prefix resolution, so keep those two GitHub variables equal to these Worker variables. > > Email provider settings (Resend API key, SMTP credentials, etc.) are configured in the **admin UI** after first login — no Cloudflare dashboard config needed. diff --git a/README.zh-CN.md b/README.zh-CN.md index 66869b5..a5047a3 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -46,27 +46,33 @@ | D1 SQL databases | `shortlink`(可自定义) | -### 3. 添加 GitHub Actions 密钥 +### 3. 添加 GitHub Actions 密钥与变量 在你的 GitHub 仓库中前往 **Settings → Secrets and variables → Actions** -添加Repository secrets: +添加 Repository secrets(deploy 工作流读取;其中只有 `JWT_SECRET`、`SETUP_SECRET` 两项会经 CI 以 `--secrets-file` 上传为 Cloudflare Secret): | 密钥 | 值 | |---|---| -| `CLOUDFLARE_API_TOKEN` | 进入[User API Tokens](https://dash.cloudflare.com/profile/api-tokens)页面,使用 **Edit Cloudflare Workers** 模板创建的 API 令牌 | +| `CLOUDFLARE_API_TOKEN` | 进入[User API Tokens](https://dash.cloudflare.com/profile/api-tokens)页面,使用 **Edit Cloudflare Workers** 模板创建的 API 令牌。需具备目标 D1 的编辑权限和 Worker 的编辑/版本读取权限。 | +| `JWT_SECRET` | 任意长度 ≥ 32 字符的随机字符串。CI 经 `--secrets-file` 上传为 Cloudflare Secret。 | +| `SETUP_SECRET` | `openssl rand -hex 24`。CI 经 `--secrets-file` 上传为 Cloudflare Secret,用于 setup/迁移。 | +> **存量部署迁移到 CI** — GitHub 中的 `JWT_SECRET`、`SETUP_SECRET` 值必须与 Worker 上**已有的** Cloudflare Secret **同值**:请填入现有值,切勿生成新值替代,否则 CI 会用不同值覆盖线上 Secret。 + + +添加 Repository variables(deploy 工作流读取): -添加Repository variables: | 变量 | 值 | |---|---| | `CLOUDFLARE_ACCOUNT_ID` | 你的账户 ID(可在 Cloudflare 控制台 URL 中找到) | | `KV_NAMESPACE_ID`| 上一步中的 WORKERS KV ID | | `D1_DATABASE_ID` | 上一步中的 D1 database ID | -| `D1_DATABASE_NAME` | (按需配置)若上一步自定义配置了D1数据库名称,则须配置为对应名称,否则无须配置。 | +| `D1_DATABASE_NAME` | (可选)仅当上一步自定义了 D1 数据库名称时才需配置为对应名称,否则无须配置。 | +| `TABLE_PREFIX` | (可选)production 环境变量。CI 中保留字 `none` 表示显式无前缀。必须与 Worker 的同名明文变量一致(见第 4 步)。 | +| `APP_URL` | production 环境变量,smoke test 使用,须指向生产 URL,并与 Worker 的 `APP_URL` 变量一致(见第 4 步)。 | - -部署工作流(`.github/workflows/deploy.yml`)在部署时通过 `sed` 将这些 ID 注入 `wrangler.toml`,因此 ID 不会提交到仓库。 +部署工作流(`.github/workflows/deploy.yml`)在部署时通过 `sed` 将这些资源 ID 注入 `wrangler.toml`,因此 ID 不会提交到仓库。 ### 4. 配置变量和密钥 @@ -74,18 +80,18 @@ | 名称 | 类型 | 必填 | 示例 / 说明 | |---|---|---|---| -| `APP_URL` | Variable | 是 | `https://yourdomain.com` | +| `APP_URL` | Variable | 是 | `https://yourdomain.com` — 须与 GitHub 中的 `APP_URL` 变量一致(第 3 步) | | `APP_NAME` | Variable | 是 | `ShortLink` — 默认应用名称,可在管理界面覆盖 | | `RP_ID` | Variable | 是 | `yourdomain.com` — WebAuthn 依赖方 ID(仅域名) | | `APP_ORIGIN` | Variable | 是 | `https://yourdomain.com` — WebAuthn 来源(完整 URL) | -| `TABLE_PREFIX` | Variable | 否 | 三态表前缀。未配置 → 默认 `sl`(`sl_users`、`sl_links` 等);配置自定义值 → 该值(保留大小写,剔除 `[^a-zA-Z0-9_]`);显式配置为空字符串 → 无前缀(部署者自担撞表风险)。必须在**首次** setup 前设置,一旦有数据后不得更改。 | -| `JWT_SECRET` | Secret | 是 | 任意长度 ≥ 32 字符的随机字符串 | -| `TOTP_ENCRYPTION_KEY` | Secret | 是 | `openssl rand -hex 32` | -| `SETUP_SECRET` | Secret | 是 | `openssl rand -hex 24` — 用于触发迁移 | +| `TABLE_PREFIX` | Variable | 否 | 三态表前缀。未配置 → 默认 `sl`(`sl_users`、`sl_links` 等);配置自定义值 → 该值(保留大小写,剔除 `[^a-zA-Z0-9_]`);显式配置为空字符串 → 无前缀(部署者自担撞表风险)。须与 GitHub 中的 `TABLE_PREFIX` 变量一致(第 3 步)。必须在**首次** setup 前设置,一旦有数据后不得更改。 | +| `TOTP_ENCRYPTION_KEY` | Secret | 是 | `openssl rand -hex 32` — 加密 TOTP 凭据,轮换会使已绑定的 TOTP 全部失效。这是**唯一**在 Cloudflare 控制台配置的 Secret,不经 CI。 | > `wrangler.toml` 中设置了 `keep_vars = true`,因此部署不会覆盖这些值。 > -> 四个普通变量 `APP_NAME` / `APP_URL` / `RP_ID` / `APP_ORIGIN` 仅在 **Cloudflare 控制台** 设置,本次改动不迁移;其值**严禁变更**——`RP_ID` / `APP_ORIGIN` 是 WebAuthn 通行密钥的依赖方标识,一旦变更将导致所有用户的通行密钥失效。 +> `JWT_SECRET` 与 `SETUP_SECRET` **不在此处配置** — 由 CI 从第 3 步添加的 GitHub Secret 上传。只有 `TOTP_ENCRYPTION_KEY` 仅存在于 Cloudflare 控制台、从不经 CI。 +> +> 普通变量 `APP_NAME` / `APP_URL` / `RP_ID` / `APP_ORIGIN` 仅在 **Cloudflare 控制台** 设置,不迁移;其值**严禁变更**——`RP_ID` / `APP_ORIGIN` 是 WebAuthn 通行密钥的依赖方标识,一旦变更将导致所有用户的通行密钥失效。`APP_URL` 与 `TABLE_PREFIX` 同时作为 GitHub 变量(第 3 步)供 smoke test 与前缀解析读取,需与这里的 Worker 变量保持同值。 > > 邮件提供商设置(Resend API 密钥、SMTP 凭据等)在首次登录后通过**管理界面**配置 — 无需在 Cloudflare 控制台中配置。