zerosaturation
|
293c7b14ae
|
fix(security): JWT key governance — MustInit fail-fast + atomic.Value
- pkg/jwt: 删 public SetSecret; 加 MustInit(secret string) 启动时强制注入,
缺/为空/等于弱默认值时返回 error(运行期不可再改); 密钥用 atomic.Value
存 []byte,所有读走 mustSecret() 原子 Load,消除 SetSecret/ParseToken 并发
data race(go test -race 零告警)。
- gateway main + auth_provider: 启动时 MustInit 读 JWT_SECRET env,失败 fatal。
- scripts/loadgen/seed/tokens: 同步 MustInit。
- .env.example: JWT_SECRET 改为 ≥32 字节 base64 示例(原为空,被 MustInit
立即拒);注释提示生产 MUST replace。
- 测试: 4 个 MustInit 行为 + 1 个 50-goroutine race 覆盖。
- 行为变更: 任何 .env 缺 JWT_SECRET 或用占位 secret 的服务,启动会 panic
(这是 fail-fast 期望行为);其余 4 个 .env 文件占位由 ops 单独轮换。
Co-Authored-By: Claude <noreply@anthropic.com>
|
2026-07-23 18:50:12 +08:00 |
|