refactor(security): 简化为单主密钥架构,废弃离线重加密与冗余警告
- 废弃 DATA_ENCRYPTION_KEY 独立要求,敏感数据加密默认统一由 JWT_SECRET 派生 - 移除 cmd/reencrypt_secrets 离线全表重加密脚本与 docs/密钥轮换说明.md,避免生产原地 UPDATE 高危反模式 - 精简 Config.SecurityWarnings,不再刷屏 DATA_ENCRYPTION_KEY 未显式配置警告,保持启动日志干净 - 更新 .env.example、README.md 与项目分析文档说明 - 验证:make lint 与 make test 全量测试 100% 通过
This commit is contained in:
@@ -18,42 +18,25 @@ func containsWarning(warnings []string, fragment string) bool {
|
||||
func TestSecurityWarnings(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
dataKeyEnv string
|
||||
cfg Config
|
||||
wantWarning string // 期望命中的告警片段;为空表示期望无任何告警
|
||||
}{
|
||||
{
|
||||
name: "示例 JWT_SECRET 必须告警",
|
||||
dataKeyEnv: "a-real-data-key",
|
||||
cfg: Config{JWTSecret: exampleJWTSecret, DataEncryptionKey: "a-real-data-key", Mode: "debug"},
|
||||
cfg: Config{JWTSecret: exampleJWTSecret, Mode: "debug"},
|
||||
wantWarning: "JWT_SECRET",
|
||||
},
|
||||
{
|
||||
name: "未显式设置 DATA_ENCRYPTION_KEY 时提示回退 JWT_SECRET",
|
||||
dataKeyEnv: "",
|
||||
cfg: Config{JWTSecret: "a-real-jwt-secret", DataEncryptionKey: "a-real-jwt-secret", Mode: "debug"},
|
||||
wantWarning: "DATA_ENCRYPTION_KEY 未显式设置",
|
||||
},
|
||||
{
|
||||
name: "示例 DATA_ENCRYPTION_KEY 必须告警",
|
||||
dataKeyEnv: exampleDataKey,
|
||||
cfg: Config{JWTSecret: "a-real-jwt-secret", DataEncryptionKey: exampleDataKey, Mode: "debug"},
|
||||
wantWarning: "DATA_ENCRYPTION_KEY 仍是",
|
||||
},
|
||||
{
|
||||
name: "release 模式开启 OPEN_API_DEBUG 必须告警",
|
||||
dataKeyEnv: "a-real-data-key",
|
||||
cfg: Config{JWTSecret: "a-real-jwt-secret", DataEncryptionKey: "a-real-data-key", Mode: "release", OpenAPIDebug: true},
|
||||
cfg: Config{JWTSecret: "a-real-jwt-secret", Mode: "release", OpenAPIDebug: true},
|
||||
wantWarning: "OPEN_API_DEBUG",
|
||||
},
|
||||
{
|
||||
name: "健康配置不应产生任何告警",
|
||||
dataKeyEnv: "a-real-data-key",
|
||||
name: "健康配置不应产生任何告警",
|
||||
cfg: Config{
|
||||
JWTSecret: "a-real-jwt-secret",
|
||||
DataEncryptionKey: "a-real-data-key",
|
||||
Mode: "release",
|
||||
OpenAPIDebug: false,
|
||||
JWTSecret: "a-real-jwt-secret",
|
||||
Mode: "release",
|
||||
OpenAPIDebug: false,
|
||||
},
|
||||
wantWarning: "",
|
||||
},
|
||||
@@ -61,7 +44,6 @@ func TestSecurityWarnings(t *testing.T) {
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Setenv("DATA_ENCRYPTION_KEY", tc.dataKeyEnv)
|
||||
warnings := tc.cfg.SecurityWarnings()
|
||||
|
||||
if tc.wantWarning == "" {
|
||||
|
||||
Reference in New Issue
Block a user