feat(security): 启动时自动迁移并持久化JWT密钥
- 新增 security_secrets 表及 Ent schema 用于存储系统级密钥 - 启动阶段支持无 jwt.secret 配置并在数据库中自动生成持久化 - 在 Ent 初始化后补齐密钥并执行完整配置校验 - 增加并发与异常分支单元测试,覆盖密钥引导核心路径 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -575,6 +575,20 @@ var (
|
||||
},
|
||||
},
|
||||
}
|
||||
// SecuritySecretsColumns holds the columns for the "security_secrets" table.
|
||||
SecuritySecretsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||
{Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
|
||||
{Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
|
||||
{Name: "key", Type: field.TypeString, Unique: true, Size: 100},
|
||||
{Name: "value", Type: field.TypeString, SchemaType: map[string]string{"postgres": "text"}},
|
||||
}
|
||||
// SecuritySecretsTable holds the schema information for the "security_secrets" table.
|
||||
SecuritySecretsTable = &schema.Table{
|
||||
Name: "security_secrets",
|
||||
Columns: SecuritySecretsColumns,
|
||||
PrimaryKey: []*schema.Column{SecuritySecretsColumns[0]},
|
||||
}
|
||||
// SettingsColumns holds the columns for the "settings" table.
|
||||
SettingsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||
@@ -1003,6 +1017,7 @@ var (
|
||||
PromoCodeUsagesTable,
|
||||
ProxiesTable,
|
||||
RedeemCodesTable,
|
||||
SecuritySecretsTable,
|
||||
SettingsTable,
|
||||
UsageCleanupTasksTable,
|
||||
UsageLogsTable,
|
||||
@@ -1059,6 +1074,9 @@ func init() {
|
||||
RedeemCodesTable.Annotation = &entsql.Annotation{
|
||||
Table: "redeem_codes",
|
||||
}
|
||||
SecuritySecretsTable.Annotation = &entsql.Annotation{
|
||||
Table: "security_secrets",
|
||||
}
|
||||
SettingsTable.Annotation = &entsql.Annotation{
|
||||
Table: "settings",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user