How to run your own RoamID instance on Cloudflare Workers. The repository runs standalone with the defaults in src/platform/; a deployment may replace that module (styling, search engine metadata, edge integration, operator notifications, a human check on the report form).
如何在 Cloudflare Workers 上运行自己的 RoamID 实例。本仓库使用 src/platform/ 中的默认实现即可独立运行;部署时可替换该模块(样式、搜索引擎元数据、边缘集成、运营方通知、举报表单的人机验证)。
cp wrangler.example.toml wrangler.local.toml # git-ignored; fill in the placeholders
export CLOUDFLARE_ACCOUNT_ID=<account id>
npx wrangler d1 create roamid # put the database id into wrangler.local.toml
npx wrangler d1 migrations apply roamid --remote -c wrangler.local.toml
npx wrangler deploy -c wrangler.local.toml
The account needs a workers.dev subdomain for cron triggers, even with workers_dev = false.
账户需要有 workers.dev 子域名,cron 触发器才能创建(即使 workers_dev = false)。
Set with npx wrangler secret put <NAME> -c wrangler.local.toml. Keep an offline copy of SIGNING_KEYS and CLIENT_KEYS: losing CLIENT_KEYS means every identity provider using private_key_jwt must register the new keys.
用 npx wrangler secret put <NAME> -c wrangler.local.toml 设置。SIGNING_KEYS 与 CLIENT_KEYS 要保留离线副本:丢失 CLIENT_KEYS 意味着所有使用 private_key_jwt 的身份提供方都要重新登记公钥。
| Name | Content |
|---|---|
SIGNING_KEYS |
JSON array of private JWKs: at least one RS256 key (the default ID token algorithm) and one ES256 key. node scripts/keygen.mjs signing |
CLIENT_KEYS |
JSON array of private JWKs, RS256 or ES256. node scripts/keygen.mjs client |
ADMIN_TOKEN |
bearer token for POST /admin/sync |
IDP_SECRET_<ID> |
client secret at an identity provider using client_secret_* (<ID>: id in upper case, - as _) |
SAML_KEYS |
JSON array of {kid, cert, key} (PEM), SAML signing and encryption |
OPERATOR_SUBS |
RoamID public sub values (comma or space separated) allowed into /admin/reports |
OPERATOR_WEBHOOK_URL (variable) |
optional: new reports and appeals are posted there as JSON (subject, body, link); without it they are logged and listed at /admin/reports |
APPEAL_TOKEN |
shared with the repository secret of the same name; lets the issue-register workflow deliver appeals filed with the issue form (POST /admin/appeal) |
In SIGNING_KEYS, the first RS256 key signs RS256 ID tokens and the first ES256 key signs ES256 ID tokens; every key in the array is published at /jwks.json. Rotate each algorithm on its own. In CLIENT_KEYS the first key signs assertions; every key is published at /client-jwks.json.
SIGNING_KEYS 中,第一个 RS256 密钥签发 RS256 的 ID 令牌,第一个 ES256 密钥签发 ES256 的 ID 令牌;数组中所有密钥都发布在 /jwks.json。两种算法各自轮换。CLIENT_KEYS 的第一个密钥签发断言,所有密钥都发布在 /client-jwks.json。
- Publish: append a new key at the end of the array and
secret putit. It is published, not used. 发布:把新密钥追加到数组末尾并secret put。它被发布,但不使用。 - Overlap: wait at least 24 hours, so that applications and identity providers caching the key set see the new key. 重叠:至少等待 24 小时,让缓存公钥集的应用与身份提供方取到新密钥。
- Switch: move the new key before the old key of the same algorithm and
secret put. 切换:把新密钥移到同算法旧密钥之前并secret put。 - Retire: after another 24 hours (ID tokens live 1 hour; assertions 60 seconds), remove the old key. 退役:再过 24 小时(ID 令牌有效 1 小时,断言 60 秒)移除旧密钥。
/status lists the key ids and their creation dates, and warns when a signing or client key is older than one year.
/status 列出密钥 id 及其创建日期,签名或客户端密钥超过一年时显示警告。
SAML_KEYS holds {kid, cert, key} pairs. The first pair signs; every certificate is published in both metadata documents, and every key is tried for encrypted assertions. Generate a pair with openssl req -x509 -newkey rsa:3072 -nodes -days 1095 -subj "/CN=RoamID SAML" -keyout key.pem -out cert.pem (the key as PKCS#8).
SAML_KEYS 保存 {kid, cert, key}。第一对用于签名;所有证书都发布在两份元数据中,解密加密断言时逐一尝试所有私钥。
- Publish: append the new pair,
secret put. Its certificate appears in/saml/sp/metadata.xmland/saml/idp/metadata.xml. / 发布:追加新的一对并secret put,其证书出现在两份元数据中。 - Overlap: identity providers and service providers that load the metadata pick it up; tell the operators of those that pasted the certificate by hand (the registry
contact). Wait until they confirm, or at least 7 days. / 重叠:载入元数据的身份提供方与服务方会自动取到;手工粘贴证书的,通过登记表的contact通知其运营方,等其确认或至少 7 天。 - Switch: move the new pair to the front. / 切换:把新的一对移到最前。
- Retire: remove the old pair after another 7 days. / 退役:再过 7 天移除旧的一对。
/status warns 30 days before a RoamID or identity provider SAML certificate expires.
RoamID 或身份提供方的 SAML 证书到期前 30 天,/status 显示警告。
| Credential | Rotation |
|---|---|
IDP_SECRET_<ID> |
Create the new secret at the identity provider while the old one stays valid there, secret put, then remove the old one at the provider. / 在身份提供方处新建密钥(旧密钥暂保留),secret put,再在提供方处删除旧密钥。 |
| Console client secrets | Owners rotate in the console: "New client secret" keeps the previous one valid until "Revoke the previous secret". / 所有者在控制台轮换:「生成新的客户端密钥」后上一个继续有效,直到「吊销上一个密钥」。 |
ADMIN_TOKEN, APPEAL_TOKEN |
secret put the new value; for APPEAL_TOKEN change the repository secret of the same name at the same time. / secret put 新值;APPEAL_TOKEN 要同时修改同名仓库密钥。 |
Every 5 minutes: registry sync, email domain proofs, identity provider health (OIDC discovery and JWKS; SAML metadata refresh with the last good copy kept until validUntil), console application domain proofs (pending every 15 minutes, proven daily), block lists (daily), clean-up of expired rows.
每 5 分钟:登记表同步、邮箱域名证明、身份提供方健康(OIDC discovery 与 JWKS;SAML 元数据刷新,保留最后一份有效副本直到 validUntil)、控制台应用的域名证明(待证明的每 15 分钟、已证明的每天)、黑名单(每天)、清理过期数据。
| Limit | Value |
|---|---|
/authorize, /select, /callback, SAML endpoints, /test |
60 per minute per address |
/token |
120 per minute per address, 600 per minute per client |
/userinfo |
300 per minute per address |
/report |
5 per hour per address (and the platform's human check, when the deployment has one) |
| Console form posts | 30 per minute per person |
| Console applications | 10 per person, 200 new per day in total, 500 sign-ins per day during the first 7 days |
| Registry | 500 identity providers, 5000 applications, 2 MiB |
| Upstream requests | 10 seconds each |
| SAML messages | 512 KiB, no DTD |
Addresses are stored only as truncated hashes, per window. 地址只以截断的哈希按时间窗保存。
- The cron (every 5 minutes) fetches
REGISTRY_URL, validates it entry by entry and stores the result in D1. On a fetch or parse failure the previous copy stays in use and the error is shown on/status. cron(每 5 分钟)获取REGISTRY_URL,逐条校验并存入 D1。获取或解析失败时继续使用上一份,错误显示在/status。 - Immediate sync / 立即同步:
curl -X POST -H "Authorization: Bearer $ADMIN_TOKEN" https://<host>/admin/sync. This also re-checks every email domain proof and probes every identity provider. 同时重新检查所有邮箱域名证明并探测所有身份提供方。
- Notification: each report and each appeal is posted to
OPERATOR_WEBHOOK_URLwhen it is set (the message names the target and links tohttps://<host>/admin/reports#<report-id>), otherwise logged. 通知:设置了OPERATOR_WEBHOOK_URL时,每条举报与申诉都发送到该地址(写明对象并链接到https://<host>/admin/reports#<report-id>),否则写入日志。 /admin/reports: the operator queue, for the accounts inOPERATOR_SUBS. Items are grouped by target and ordered by distinct reporters in 24 hours;#<report-id>scrolls to the report. Decisions and "Publish report" are taken on the target page./admin/reports:运营方队列,仅OPERATOR_SUBS中的账户可访问。条目按对象分组,按 24 小时内不同举报者数排序;#<report-id>定位到该举报。处理与「公开举报」在对象页面进行。- Public record: decisions at
/transparency.jsonand intransparency/(workflowtransparency, hourly, by pull request); published reports as issues labelledreport-upheld. Appeals filed with the issue form reach the queue throughPOST /admin/appeal(APPEAL_TOKEN, workflowissue-register). 公开记录:处理结果见/transparency.json与transparency/(工作流transparency,每小时);公开的举报为带report-upheld标签的 issue。通过 issue 表单提交的申诉经POST /admin/appeal(APPEAL_TOKEN,工作流issue-register)进入队列。
maincannot be deleted or force-pushed, by anyone. Every change is a pull request with the required status checkcheck.main不能被任何人删除或强制推送。所有改动都经拉取请求,且必须通过状态检查check。.github/CODEOWNERS: every path needs a code owner's review, exceptregistry/clients/andtransparency/. Those pull requests are merged by the automatic review (automerge): application entries that pass the review, and the transparency record opened bygithub-actions[bot]from atransparency/<date>branch..github/CODEOWNERS:除registry/clients/与transparency/外,所有路径都需代码所有者审核。这两类拉取请求由自动审核(automerge)合并:通过审核的应用条目,以及由github-actions[bot]从transparency/<日期>分支提交的公开记录。- For a pull request opened by a workflow, GitHub holds its
checkrun (action_required). The bot releases that run only for its own branch (issue-<n>ortransparency/<date>), the exact head commit it pushed, this repository and thecheckworkflow (a workflow-run approval; pull requests are never approved by a workflow), waits for the result, then startsautomergefor the pull request. The schedule (twice an hour) picks up anything left. 对由工作流创建的拉取请求,GitHub 会暂停其check运行(action_required)。机器人只为自己的分支(issue-<编号>或transparency/<日期>)、自己推送的确切头提交、本仓库与check工作流放行该运行(工作流运行的批准;工作流从不批准拉取请求),等待结果,再为该拉取请求启动automerge。定时任务(每小时两次)处理其余情况。 - Workflow actions are pinned to full commit SHAs. 工作流中的 action 均固定到完整提交 SHA。
| Situation / 情况 | Action / 处置 |
|---|---|
| Disable an identity provider quickly / 快速停用身份提供方 | Emergency: /admin/target/idp/<id>, "Emergency disable" with a reason. It takes effect on the next request everywhere (picker, callbacks, SAML ACS) and is recorded in the audit log; "Remove override" undoes it. Permanent: merge a pull request setting "status": "disabled", then POST /admin/sync. / 紧急:在 /admin/target/idp/<id> 点「紧急停用」并注明原因,下一次请求起在各处(选择页、回调、SAML ACS)生效并记入审计日志;「撤销停用」恢复。永久:合并把 status 改为 disabled 的拉取请求,再 POST /admin/sync。 |
| A report arrives / 收到举报 | The operator is notified (webhook) and the item is in /admin/reports, ordered by distinct reporters in 24 hours. Open the target, check the site, tick the reports the decision is based on, then dismiss, warn, suspend (temporary) or ban (illegal sites; the domain is blocked for new applications). Every action needs a reason; the owner sees it. / 运营方收到通知(webhook),条目出现在 /admin/reports,按 24 小时内不同举报者数排序。打开对象、检查站点,勾选处理所依据的举报,然后驳回、警告、暂停(临时)或封禁(违法站点;其域名不能再用于新应用)。每个处理都要写原因,所有者可见。 |
| An appeal arrives / 收到申诉 | It is a new item for the same application. Restore (the application returns to active when its checks and domain proof hold) or keep the action and dismiss the appeal. / 申诉是同一应用的新条目。恢复(检查与域名证明仍成立时回到 active)或维持处理并驳回申诉。 |
| An operator loses access / 运营方无法登录 | OPERATOR_SUBS lists RoamID public subs. An operator signs in through any active identity provider; when that provider is disabled, use another account listed in OPERATOR_SUBS, or update the secret. / OPERATOR_SUBS 列出 RoamID public sub。运营方可经任一启用中的身份提供方登录;该提供方被停用时,用 OPERATOR_SUBS 中的其他账户,或更新该密钥。 |
| Automatic merges must stop / 需要停止自动合并 | Disable the automerge workflow in the repository's Actions settings, or remove its triggers. Pull requests then wait for a maintainer. / 在仓库 Actions 设置中停用 automerge 工作流,或删除其触发器;拉取请求随后等待维护者处理。 |
| Rotate keys / 轮换密钥 | See Key rotation. / 见上文。 |
| Restore the registry / 恢复登记表 | Revert the bad commit on main (a new commit; identifiers must not disappear), let the publish workflow run, then POST /admin/sync. Until then RoamID keeps serving the last copy that loaded. / 在 main 上以新提交撤销错误改动(标识不得消失),等发布工作流完成后 POST /admin/sync。在此之前 RoamID 继续使用最后一份成功载入的副本。 |
| A domain proof is lost / 域名证明失效 | /status shows grace for 48 hours, then lost. Ask the provider's contact to restore the TXT record, then POST /admin/sync. / /status 先显示 48 小时 grace,之后 lost。请提供方联系人恢复 TXT 记录,然后 POST /admin/sync。 |