Skip to content

feat: add DMS IP/CIDR access restriction - #665

Merged
Seechi-Yolo merged 1 commit into
mainfrom
dms/feat-961
Aug 13, 2026
Merged

feat: add DMS IP/CIDR access restriction#665
Seechi-Yolo merged 1 commit into
mainfrom
dms/feat-961

Conversation

@LordofAvernus

@LordofAvernus LordofAvernus commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

User description

关联的 issue

https://github.com/actiontech/dms-ee/issues/961

描述你的变更

  • 新增 IP/CIDR 访问白名单持久化与配置 API(读/写权限分离)
  • JWT 前挂载访问限制中间件:注册永不拦、已登记服务 IP 豁免、拒绝返回 HTTP 403
  • 开启开关时校验名单非空且当前客户端 IP 已命中,避免管理员自锁

确认项(pr提交后操作)

Tip

请在指定复审人之前,确认并完成以下事项,完成后✅


  • 我已完成自测
  • 我已记录完整日志方便进行诊断
  • 我已在关联的issue里补充了实现方案
  • 我已在关联的issue里补充了测试影响面
  • 我已确认了变更的兼容性,如果不兼容则在issue里标记 not_compatible
  • 我已确认了是否要更新文档,如果要更新则在issue里标记 need_update_doc


Description

  • 新增IP/CIDR访问白名单持久化及配置API

  • 添加访问限制中间件,进行IP白名单匹配

  • 更新DMS服务和路由,支持配置的增删改查

  • 扩展代理服务逻辑,取消注册IP豁免时同步删除


Diagram Walkthrough

flowchart LR
  A["白名单持久化模块"]
  B["访问限制业务逻辑"]
  C["配置API控制器"]
  D["访问限制中间件"]
  E["代理服务IP校验"]
  A -- 存储规则 --> B
  C -- 调用业务API --> B
  B -- 返回配置 --> C
  D -- 校验客户端IP --> B
  E -- 同步删除注册IP --> B
Loading

File Walkthrough

Relevant files
Enhancement
11 files
access_restriction.go
定义IP/CIDR白名单及访问限制API结构体                                                                   
+71/-0   
access_restriction.go
增加中间件实现IP白名单检查逻辑                                                                                 
+67/-0   
dms_controller.go
添加访问限制相关HTTP接口控制器                                                                               
+177/-0 
router.go
新增访问限制及白名单规则路由映射                                                                                 
+9/-0     
access_restriction.go
实现IP白名单逻辑与访问限制开关控制                                                                             
+272/-0 
proxy.go
扩展代理逻辑,添加删除注册IP接口                                                                               
+55/-0   
access_restriction.go
实现访问限制配置API服务逻辑                                                                                   
+131/-0 
service.go
更新服务初始化,注入访问限制业务对象                                                                             
+3/-0     
access_restriction.go
增加存取白名单规则及开关的数据库操作                                                                             
+156/-0 
model.go
定义白名单规则数据模型及表结构                                                                                   
+13/-0   
proxy.go
添加数据库删除代理目标逻辑                                                                                       
+9/-0     
Tests
1 files
proxy_access_restriction_test.go
新增代理IP豁免方法的单元测试                                                                                   
+28/-0   
Additional files
1 files
access_restriction_test.go +133/-0 

@github-actions

github-actions Bot commented Aug 12, 2026

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit 322cec6)

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

@github-actions

Copy link
Copy Markdown

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
刷新更新时戳

建议在更新规则前调用 TouchUpdatedAt(existing) 方法,以确保更新时间字段得到刷新。这样可以避免数据更新时间不一致可能引起的潜在问题。

internal/dms/biz/access_restriction.go [149-155]

 existing.Source = normalized
 existing.Remark = remark
 existing.PolicyType = policy
+TouchUpdatedAt(existing)
 if err := u.repo.UpdateRule(ctx, existing); err != nil {
 	return nil, err
 }
 return u.repo.GetRuleByUID(ctx, uid)
Suggestion importance[1-10]: 7

__

Why: 此建议在更新规则前调用 TouchUpdatedAt(existing) 来刷新 UpdatedAt 字段,有助于确保数据更新时间的一致性,改善了数据的可靠性,但影响相对中等。

Medium
更新数据库时刷新时间

建议在更新数据库记录时,同时更新 updated_at 字段,以确保持久化的更新时间与最新修改保持同步。这可以通过在更新的 map 中添加 "updated_at":
time.Now() 实现。

internal/dms/storage/access_restriction.go [80-84]

 result := tx.WithContext(ctx).Model(&model.AccessWhitelistRule{}).Where("uid = ?", rule.UID).Updates(map[string]interface{}{
 	"source":      rule.Source,
 	"policy_type": rule.PolicyType,
 	"remark":      rule.Remark,
+	"updated_at":  time.Now(),
 })
Suggestion importance[1-10]: 7

__

Why: 通过在更新数据库记录的映射中加入 "updated_at": time.Now(),可以同步持久化更新时戳,提高记录的准确性,此建议具有适中改进效果。

Medium

Persist whitelist rules and enablement, expose configuration APIs,
and enforce access at the API middleware before JWT.
@github-actions

Copy link
Copy Markdown

Persistent review updated to latest commit 322cec6

@Seechi-Yolo
Seechi-Yolo merged commit d8232f9 into main Aug 13, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants