Skip to content

feat(sql_workbench): align ODC workbench audit gate and non-DQL workflow exec with CloudBeaver#645

Merged
Seechi-Yolo merged 4 commits into
mainfrom
dms/feat-911-odc-audit-workflow
Jul 6, 2026
Merged

feat(sql_workbench): align ODC workbench audit gate and non-DQL workflow exec with CloudBeaver#645
Seechi-Yolo merged 4 commits into
mainfrom
dms/feat-911-odc-audit-workflow

Conversation

@LordofAvernus

@LordofAvernus LordofAvernus commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

User description

背景

ODC SQL 工作台此前缺少与 CloudBeaver 工作台一致的审核门与工单执行能力。本次将 CloudBeaver 已有的 CE 级审核/工单逻辑对齐到 ODC 工作台路径。

变更内容

  • 新增 ODC 非 DQL 工单自动执行workflow_exec.go,CE 构建):工单权限校验、自动建单并上线执行的 API 调用、响应构造与操作日志,行为对齐 CloudBeaver 的 executeNonDQLByWorkflow,两个工作台共用同一套 CE 级逻辑。(actiontech/dms-ee#889
  • 审核中间件接线非 DQL 工单执行workflow_exec_enabled 开启且为合规非 DQL 语句时,走工单自动上线;streamExecute 响应新增 workflowInfo/errorMessage。(actiontech/dms-ee#889
  • ODC 审核门对齐 CloudBeaver:复用 IsSuccess 审核语义、运维时间管控与 isExecuteAnyway(仍要执行)放行逻辑,置于工单/直接执行之前。(actiontech/dms-ee#905
  • SQL Server 审核 schema 归一为 catalog 名:ODC 以 database.schema(如 TestDB.dbo)暴露 SQL Server 节点,SQLE 直连审核以 schema_name 作为连接库,仅取 catalog 部分,避免 Cannot open database TestDB.dbo。(actiontech/dms-ee#911

说明

  • 工单逻辑归 CE:与 CloudBeaver 一致(其工单逻辑本就在 CE 的 internal/dms/biz/cloudbeaver.go),保证社区版 ODC 工作台同样具备该能力。
  • 依赖(维护时间 usecase、cloudbeaver.AllowQuerySQLQueryConfig)在 CE 主线已存在。

测试

  • go build ./...go vet ./internal/sql_workbench/...go test ./internal/sql_workbench/... 均通过(golang:1.24.1 容器)。

Refs actiontech/dms-ee#889
Refs actiontech/dms-ee#905
Fixes actiontech/dms-ee#911


Description

  • 添加maintenanceTimeUsecase及维护时间检查功能

  • 修改请求解析和审核中间件处理isExecuteAnyway参数

  • 实现SQL Server schema归一化支持SQLE审核

  • 新增workflow_exec.go实现非DQL工单自动执行

  • 增加单元测试覆盖新功能逻辑


Diagram Walkthrough

flowchart LR
  A["Request Parsing"] -- "解析SQL及isExecuteAnyway" --> B["审核中间件"]
  B -- "调用SQLE审核、维护时间检查" --> C["审核结果处理"]
  C -- "符合条件" --> D["工单自动执行"]
  C -- "不符合条件" --> E["直接执行SQL"]
Loading

File Walkthrough

Relevant files
Enhancement
sql_workbench_service.go
更新SQL工作台服务逻辑                                                                                         

internal/sql_workbench/service/sql_workbench_service.go

  • 添加maintenanceTimeUsecase字段及初始化
  • 修改parseStreamExecuteRequest解析并传递isExecuteAnyway标识
  • 新增normalizeSQLEAuditSchemaName函数实现schema归一化
  • 更新拦截审核响应逻辑及维护时间检查
+122/-38
workflow_exec.go
新增工单执行逻辑                                                                                                 

internal/sql_workbench/service/workflow_exec.go

  • 新增workflow_exec.go文件实现工单自动创建与执行
  • 实现权限校验、HTTP接口调用和日志记录
  • 封装工单响应构造与错误处理逻辑
+326/-0 
Tests
sql_workbench_service_test.go
新增单元测试覆盖                                                                                                 

internal/sql_workbench/service/sql_workbench_service_test.go

  • 新增Test_isAuditSuccessful单元测试
  • 增加Test_shouldRequireApproval和Test_parseIsExecuteAnywayFromRequest测试
  • 补充Test_normalizeSQLEAuditSchemaName验证函数正确性
+161/-1 

Add CE-built workflow_exec.go implementing workflow permission check,
auto create/execute API call, response builder and operation log for the
ODC SQL workbench non-DQL workflow path, mirroring the CloudBeaver
workflow behavior so both workbenches share the same CE-level logic.

Refs actiontech/dms-ee#889
Route compliant non-DQL SQL through workflow auto-exec when
workflow_exec_enabled is on, and expose workflowInfo in streamExecute.

Refs actiontech/dms-ee#889

(cherry picked from commit d6b3455bdf5575cc3b624dd4568a946996d9a4f0)
Reuse IsSuccess audit semantics, maintenance time checks, and
isExecuteAnyway bypass before workflow/direct execution in the ODC
streamExecute middleware, so the ODC workbench audit gate matches the
CloudBeaver behavior.

Refs actiontech/dms-ee#905
ODC exposes SQL Server nodes as database.schema (e.g. TestDB.dbo).
SQLE direct audit uses schema_name as the connection database, so pass
only the catalog part to avoid "Cannot open database TestDB.dbo".

Fixes actiontech/dms-ee#911
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

PR Reviewer Guide 🔍

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

错误处理

当 maintenanceTimeUsecase 未被初始化时,checkMaintenanceTime 会直接返回错误而中断流程,可能导致中间件处理不一致。建议在使用前确保该依赖已被正确初始化,或对未初始化情况提供更明确的错误处理策略。

func (sqlWorkbenchService *SqlWorkbenchService) checkMaintenanceTime(c echo.Context, userID string, auditResults []cloudbeaver.AuditSQLResV2, dbService *biz.DBService) (blocked bool, err error) {
	if sqlWorkbenchService.maintenanceTimeUsecase == nil {
		return false, fmt.Errorf("maintenance time usecase is nil")
	}
输入验证

在 parseStreamExecuteRequest 中,对请求体中缺失 sql 字段的情况缺少验证,可能导致返回空 sql 值并引发后续异常。建议增加对 sql 字段存在性的检查,并在缺失时返回适当的错误信息。

}

if sqlVal, ok := requestBody["sql"]; ok {
	if sqlStr, ok := sqlVal.(string); ok {
		sql = sqlStr
	}
}

isExecuteAnyway = parseIsExecuteAnywayFromRequest(requestBody)

if sidVal, ok := requestBody["sid"]; ok {

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

Failed to generate code suggestions for PR

@Seechi-Yolo Seechi-Yolo merged commit 20026f9 into main Jul 6, 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