修复全量审查问题;设置接口PATCH化;回传指纹加固
CI / test (push) Successful in 32s

This commit is contained in:
2026-07-22 16:51:23 +08:00
parent 0614ef22af
commit f51fb6c722
66 changed files with 3997 additions and 687 deletions
+17 -7
View File
@@ -24,9 +24,12 @@ type OciConfigService struct {
// auditRaw 按 configId:eventId 暂存审计原始事件(TTL 10 分钟),
// 列表响应剥离 raw 后详情接口据此秒开;miss 走小窗重查兜底。
auditRaw *cache.Cache
// bindWG 追踪保留 IP 后台绑定 goroutine;bindStop 关服时令其提前退出。
// bindWG 追踪保留 IP 绑定与桶清空等后台 goroutine;bindStop 关服时令其提前退出。
bindWG sync.WaitGroup
bindStop chan struct{}
// purgeMu/purgeInFlight 是桶清空在途注册表:同一桶(cfg/region/bucket)单飞。
purgeMu sync.Mutex
purgeInFlight map[string]bool
}
// NewOciConfigService 组装依赖。
@@ -34,6 +37,7 @@ func NewOciConfigService(db *gorm.DB, cipher *crypto.Cipher, client oci.Client)
return &OciConfigService{
db: db, cipher: cipher, client: client,
auditRaw: cache.New(auditRawMax), bindStop: make(chan struct{}),
purgeInFlight: map[string]bool{},
}
}
@@ -71,6 +75,12 @@ func (s *OciConfigService) Import(ctx context.Context, in ImportInput) (*model.O
if err != nil {
return nil, err
}
// 代理先于任何远端访问解析并挂进凭据:不存在/非法的代理直接拒绝导入,
// 避免首次测活绕过代理直连,泄露真实出口
cred.Proxy, err = s.proxySpecOf(in.ProxyID)
if err != nil {
return nil, err
}
cfg, err := s.storeConfig(in.Alias, cred)
if err != nil {
return nil, err
@@ -427,7 +437,7 @@ func (s *OciConfigService) credentialsOf(cfg *model.OciConfig) (oci.Credentials,
return oci.Credentials{}, fmt.Errorf("decrypt passphrase of config %d: %w", cfg.ID, err)
}
}
spec, err := s.proxySpecOf(cfg)
spec, err := s.proxySpecOf(cfg.ProxyID)
if err != nil {
return oci.Credentials{}, err
}
@@ -442,15 +452,15 @@ func (s *OciConfigService) credentialsOf(cfg *model.OciConfig) (oci.Credentials,
}, nil
}
// proxySpecOf 加载租户关联的出站代理;未关联返回 nil(直连)。
// proxySpecOf 加载关联的出站代理;未关联返回 nil(直连)。
// 代理行缺失或解密失败时报错而非静默直连,避免期望走代理的流量泄露真实出口。
func (s *OciConfigService) proxySpecOf(cfg *model.OciConfig) (*oci.ProxySpec, error) {
if cfg.ProxyID == nil {
func (s *OciConfigService) proxySpecOf(proxyID *uint) (*oci.ProxySpec, error) {
if proxyID == nil {
return nil, nil
}
var row model.Proxy
if err := s.db.First(&row, *cfg.ProxyID).Error; err != nil {
return nil, fmt.Errorf("find proxy %d of config %d: %w", *cfg.ProxyID, cfg.ID, err)
if err := s.db.First(&row, *proxyID).Error; err != nil {
return nil, fmt.Errorf("find proxy %d: %w", *proxyID, err)
}
password := ""
if row.PasswordEnc != "" {