Skip to content

Conversation

@BlackHole1
Copy link
Contributor

使用 https://github.com/bspk/mkjwk.org 项目,本地断网生成。
其和 jwt 的公钥和私钥一一对应。

Signed-off-by: Kevin Cui <bh@bugs.cc>
@coderabbitai
Copy link

coderabbitai bot commented Sep 22, 2025

Summary by CodeRabbit

  • 新功能
    • 新增公开 JWKS 端点:/.well-known/jwks.json 与 /.well-known/dev-jwks.json,提供 RS256 RSA 公钥供 JWT 验证使用,便于第三方与内部服务自动获取签名公钥,实现更便捷、安全的令牌校验与密钥轮换集成。无界面或流程变更,兼容现有客户端,不涉及 API 行为变更与额外配置。

Walkthrough

新增两个静态 JWKS 文件于 static/.well-known/ 目录:分别为开发用 dev-jwks.json 与生产/默认用 jwks.json,均包含单个 RSA 公钥条目。未涉及代码或公开接口改动。

Changes

Cohort / File(s) Change Summary
JWKS 静态文件新增
static/.well-known/dev-jwks.json, static/.well-known/jwks.json
新增 JWKS JSON,内含单个 RSA 公钥(字段:kty, e, n, kid, alg=RS256, use=sig);仅静态资源,无代码改动。

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Pre-merge checks

✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed PR 标题 "chore: add jwks.json" 采用了要求的 type: subject 风格(scope 为可选项),格式合规;标题直接反映了主要变更——新增 JWKS 静态文件,与 raw_summary 中列出的 static/.well-known/jwks.json 和 static/.well-known/dev-jwks.json 一致;因此标题与变更集相关且能清晰传达主要目的,判定为通过。
Description Check ✅ Passed PR 描述说明使用 mkjwk.org 在本地离线生成 JWKS,并指出该 JWKS 与 JWT 的公私钥一一对应,描述与 raw_summary 中新增静态 jwks 文件相符且不偏题;描述虽简短但与变更集相关,满足宽松的描述检查标准,判定为通过。

Comment @coderabbitai help to get the list of available commands and usage tips.

@cloudflare-workers-and-pages
Copy link

Deploying oomol-com with  Cloudflare Pages  Cloudflare Pages

Latest commit: 41e39a0
Status: ✅  Deploy successful!
Preview URL: https://367846ea.oomol-com.pages.dev
Branch Preview URL: https://add-jwks.oomol-com.pages.dev

View logs

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
static/.well-known/jwks.json (1)

1-12: 提前规划无缝密钥轮换与缓存控制

  • 轮换建议:在 JWKS 中同时发布“当前密钥+新密钥”,先让验证端预热新 kid,再切换签发端使用新 kid,最后移除旧钥,避免验证失败。
  • 缓存:为 /.well-known/jwks.json 设置合理 Cache-Control(如 public, max-age=300)并提供 ETag,平衡流量与切换时效。
  • MIME:确保静态服务返回 application/jwk-set+json(若做不到,application/json 也可接受)。
static/.well-known/dev-jwks.json (1)

1-12: static/.well-known/dev-jwks.json 已验证 — 建议(可选)

  • 验证结果:必备字段存在;未包含私钥参数(d/p/q/dp/dq/qi/oth);RSA modulus = 2048 位。
  • 建议(可选):
    • 在 JWK 中添加 "key_ops": ["verify"] 以显式限定用途;
    • 服务端为 /.well-known/dev-jwks.json 设置短 TTL(例如 300s)以减少开发环境中缓存时间;
    • 文档化开发/测试密钥的轮换频率与失效流程,避免长期复用。
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 947521c and 41e39a0.

📒 Files selected for processing (2)
  • static/.well-known/dev-jwks.json (1 hunks)
  • static/.well-known/jwks.json (1 hunks)
🔇 Additional comments (1)
static/.well-known/jwks.json (1)

1-12: 结构正确,可用于 RS256 验签;确认 kid 与签发端一致

JWKS 包含单把 RSA 公钥,e=AQAB(65537),可按 kid 选键。

  • 核对 JWT header 中的 kid 与 static/.well-known/jwks.json 中的 kid 完全一致。
  • 在仓库运行的脚本输出 JWKS kid:BoY3rIHJMYk6ox5ZS2Rq0WnOZLOWunl1D-7z5gNvu_0;示例 JWT 未提供(TOKEN 环境变量未设置),因此未完成对比。
  • 确认发行方(issuer)与该 JWKS URL 的绑定在配置中已生效,避免从错误的 JKU 拉取密钥。

在本地将 TOKEN 设置为示例 JWT 并重跑原脚本以完成一致性检查。

@BlackHole1 BlackHole1 merged commit 9177b79 into main Sep 22, 2025
4 checks passed
@BlackHole1 BlackHole1 deleted the add-jwks branch September 22, 2025 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants