全局审计完成
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 8m31s

This commit is contained in:
2026-08-07 11:02:52 +08:00
parent 88cc5e96ec
commit c64f3d8b80
94 changed files with 8641 additions and 6714 deletions

View File

@@ -166,8 +166,9 @@ type GatewayConfig struct {
// WorkerConfig Worker 进程运行配置
type WorkerConfig struct {
Role string `mapstructure:"role"` // Worker 运行角色all、leader、consumer
InstanceName string `mapstructure:"instance_name"` // Worker 实例名称,用于多实例日志区分
Role string `mapstructure:"role"` // Worker 运行角色all、leader、consumer
InstanceName string `mapstructure:"instance_name"` // Worker 实例名称,用于多实例日志区分
AuditRetentionCleanupEnabled bool `mapstructure:"audit_retention_cleanup_enabled"` // 是否启用审计日志月度物理清理
}
// ApprovalConfig 审批新旧入口切换配置。

View File

@@ -137,6 +137,8 @@ polling_auto_trigger:
worker:
role: "all"
instance_name: ""
# 完整自然月灰度验收通过前必须保持关闭
audit_retention_cleanup_enabled: false
# 审批新旧入口切换配置
approval:

View File

@@ -130,6 +130,7 @@ func bindEnvVariables(v *viper.Viper) {
"polling_auto_trigger.auto_trigger_system_user_id",
"worker.role",
"worker.instance_name",
"worker.audit_retention_cleanup_enabled",
"approval.legacy_refund_manual_enabled",
"approval.legacy_offline_recharge_pay_enabled",
"wecom.base_url",

View File

@@ -135,6 +135,12 @@ const (
AuditActionIotCardCreated = "iot_card.create"
// AuditActionIotCardDeleted 表示删除单张 IoT 卡。
AuditActionIotCardDeleted = "iot_card.delete"
// AuditActionIotCardDeactivated 表示人工停用 IoT 卡资产。
AuditActionIotCardDeactivated = "iot_card.deactivate"
// AuditActionIotCardPollingStatusUpdated 表示更新 IoT 卡轮询开关。
AuditActionIotCardPollingStatusUpdated = "iot_card.update_polling_status"
// AuditActionIotCardPollingStatusBatchUpdated 表示批量更新 IoT 卡轮询开关。
AuditActionIotCardPollingStatusBatchUpdated = "iot_card.batch_update_polling_status"
// AuditActionIotCardBatchDeleted 表示批量删除 IoT 卡根事件。
AuditActionIotCardBatchDeleted = "iot_card.batch_delete"
// AuditActionIotCardAllocationBatch 表示 IoT 卡分配批次根事件。
@@ -185,6 +191,10 @@ const (
AuditActionDeviceCreated = "device.create"
// AuditActionDeviceDeleted 表示删除设备。
AuditActionDeviceDeleted = "device.delete"
// AuditActionDeviceDeactivated 表示人工停用设备资产。
AuditActionDeviceDeactivated = "device.deactivate"
// AuditActionDevicePollingStatusUpdated 表示更新设备轮询开关。
AuditActionDevicePollingStatusUpdated = "device.update_polling_status"
// AuditActionDeviceAllocationBatch 表示设备分配批次根事件。
AuditActionDeviceAllocationBatch = "device.allocate_batch"
// AuditActionDeviceAllocated 表示单台设备分配子事件。
@@ -297,6 +307,10 @@ const (
AuditActionPackageUsageRefundInvalidated = "package_usage.invalidate_refund"
// AuditActionPackageUsageAssetInvalidated 表示按资产失效套餐权益。
AuditActionPackageUsageAssetInvalidated = "package_usage.invalidate_asset"
// AuditActionPackageUsageExpiresAtUpdated 表示人工调整套餐权益过期时间。
AuditActionPackageUsageExpiresAtUpdated = "package_usage.update_expires_at"
// AuditActionPackageUsageTrafficAdjusted 表示人工调整套餐权益已用量。
AuditActionPackageUsageTrafficAdjusted = "package_usage.adjust_traffic"
// AuditActionOrderCreated 表示创建套餐订单。
AuditActionOrderCreated = "order.create"
// AuditActionOrderCancelled 表示人工取消待支付订单。
@@ -399,10 +413,6 @@ const (
AuditActionOutboxReplayed = "outbox.replayed"
// AuditActionOutboxExpiredLeaseReleased 表示人工释放 Outbox 过期租约。
AuditActionOutboxExpiredLeaseReleased = "outbox.expired_lease_released"
// AuditActionDeviceBatchAllocationCompleted 表示设备批量分配根事件。
AuditActionDeviceBatchAllocationCompleted = "device.batch_allocation.completed"
// AuditActionDeviceBatchAllocationItem 表示设备批量分配资源子事件。
AuditActionDeviceBatchAllocationItem = "device.batch_allocation.item"
// AuditActionIotCardImportTaskCreated 表示创建 IoT 卡导入任务。
AuditActionIotCardImportTaskCreated = "iot_card_import_task.create"
// AuditActionIotCardImportTaskCompleted 表示 IoT 卡导入任务完成。
@@ -676,8 +686,6 @@ const (
AuditResourceRoleBatchTask = "batch_task"
// AuditResourceRoleRetentionMonth 表示留存清理目标自然月。
AuditResourceRoleRetentionMonth = "retention_month"
// AuditResourceRoleBatchItem 表示批量子事件的单项资源。
AuditResourceRoleBatchItem = "batch_item"
// AuditResourceRoleNotificationTarget 表示本次写操作的通知资源。
AuditResourceRoleNotificationTarget = "notification_target"
// AuditResourceRoleSensitiveReadTarget 表示敏感读取目标资源。
@@ -810,8 +818,6 @@ const (
AuditResourceRolePaymentTarget = "payment_target"
// AuditResourceRolePaymentBusinessOrder 表示支付记录关联的业务单。
AuditResourceRolePaymentBusinessOrder = "payment_business_order"
// AuditResourceRolePaymentWallet 表示支付确认实际变更的钱包。
AuditResourceRolePaymentWallet = "payment_wallet"
// AuditResourceRolePaymentWalletTransaction 表示支付确认产生的钱包流水。
AuditResourceRolePaymentWalletTransaction = "payment_wallet_transaction"
// AuditResourceRoleRechargeTarget 表示充值业务的主要充值单。

View File

@@ -22,7 +22,6 @@ type OrderExpirer interface {
// WorkerStores Worker 侧所有 Store 的集合
type WorkerStores struct {
AssetOperationLog *postgres.AssetOperationLogStore
AssetAllocationRecord *postgres.AssetAllocationRecordStore
IotCardImportTask *postgres.IotCardImportTaskStore
IotCard *postgres.IotCardStore

View File

@@ -5,22 +5,27 @@ import (
"crypto/sha256"
"encoding/hex"
"fmt"
"regexp"
"strings"
"unicode"
"github.com/bytedance/sonic"
)
var forbiddenFragments = []string{
"password", "passwd", "credential", "operation_password", "verification_code", "captcha",
"access_token", "refresh_token", "authorization", "cookie", "secret", "private_key", "public_key",
"token", "access_token", "refresh_token", "id_token", "session_token", "sms_code", "api_key", "payment_key",
"authorization", "cookie", "secret", "private_key", "public_key",
"encoding_aes_key", "callback_token", "signature", "sign", "nonce", "media_id", "signed_url",
"private_url", "qr_content", "id_card", "identity_number",
}
var forbiddenTextPattern = regexp.MustCompile(`(?i)(bearer[[:space:]]+[a-z0-9._~+/=-]{8,}|-----BEGIN [A-Z ]*PRIVATE KEY-----|(?:access_token|refresh_token|id_token|session_token|authorization|cookie|secret|private_key|api_key|payment_key|signed_url|x-amz-signature|x-amz-credential)[[:space:]]*[=:][[:space:]]*[^&[:space:]]+)`)
// IsForbiddenField 判断字段是否禁止进入普通日志、审计或外部交互摘要。
func IsForbiddenField(key string) bool {
normalized := strings.ToLower(strings.NewReplacer("-", "_", ".", "_").Replace(key))
if normalized == "credentials_configured" {
normalized := normalizeFieldName(key)
if normalized == "credentials_configured" || normalized == "token_present" {
return false
}
for _, fragment := range forbiddenFragments {
@@ -34,6 +39,21 @@ func IsForbiddenField(key string) bool {
return false
}
func normalizeFieldName(key string) string {
var normalized strings.Builder
for index, char := range key {
if unicode.IsUpper(char) && index > 0 {
normalized.WriteByte('_')
}
if char == '-' || char == '.' {
normalized.WriteByte('_')
continue
}
normalized.WriteRune(unicode.ToLower(char))
}
return normalized.String()
}
// MarshalSummary 递归删除禁止字段并返回 sonic 编码的安全 JSON。
func MarshalSummary(value any) ([]byte, error) {
if value == nil {
@@ -60,15 +80,31 @@ func RemoveForbiddenFields(value any) {
delete(typed, key)
continue
}
if text, ok := item.(string); ok {
typed[key] = SanitizeText(text)
continue
}
RemoveForbiddenFields(item)
}
case []any:
for _, item := range typed {
for index, item := range typed {
if text, ok := item.(string); ok {
typed[index] = SanitizeText(text)
continue
}
RemoveForbiddenFields(item)
}
}
}
// SanitizeText 将疑似包含安全凭据的文本转换为不可逆摘要。
func SanitizeText(value string) string {
if !forbiddenTextPattern.MatchString(value) {
return value
}
return TextSummary(value)
}
// TextSummary 将不可信外部文本转换为不可逆大小和哈希摘要。
func TextSummary(value string) string {
if value == "" {