Skip to content

feat(services/cloudwalker-cwpp): add CloudWalker CWPP host security service - #560

Merged
Daemonceltics merged 3 commits into
chaitin:mainfrom
Daemonceltics:pr/cloudwalker-cwpp
Nov 5, 2026
Merged

Daemonceltics merged 3 commits into
chaitin:mainfrom
Daemonceltics:pr/cloudwalker-cwpp

Conversation

@Daemonceltics

Copy link
Copy Markdown
Collaborator

Summary

新增牧云 CloudWalker CWPP(主机安全)只读查询 service:

  • JSON-RPC 2.0 over HTTP POST /rpc,Cookie API-Token 认证
  • 3 个只读方法:ListRealTimeEvents / GetHostAssetList / GetAgentGroupTree
  • 增加 socks5 代理支持(socks-proxy-agent)与 skipTlsVerify

Test plan

  • node scripts/validate-service-package.mjs --service-dir chaitin__cloudwalker-cwpp
  • node --test 单测(mock 上游)

@monkeyscan

monkeyscan Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

PR Title: feat(services/cloudwalker-cwpp): add CloudWalker C...

Commit: ebd3512

整体评估

本次变更新增了 chaitin__cloudwalker-cwpp 只读服务包,包含 proto、配置与密钥 schema、入口、SDK 封装、测试和包注册,整体结构与仓库内其他服务保持一致,三个只读 RPC 的请求映射与错误分类思路清晰。主要风险集中在依赖清单以及上游错误和代理语义的处理上。

总结

新增依赖未在仓库根安装清单中声明,按当前注册方式服务可能一启动就失败,这是合并前必须修复的问题;此外上游 err/msg 未透传、HTTP 代理支持与文档不符,建议一并修正后再合并。

Findings (3)

  • 🟠 [HIGH] services/package.json:319 — services/package.json 缺少 socks-proxy-agent 依赖,服务启动时会因模块解析失败而崩溃
  • 🟡 [MEDIUM] services/chaitin__cloudwalker-cwpp/config.schema.json:20 — 配置声明支持 HTTP 代理,但实现只支持 SOCKS 代理
  • 🟡 [MEDIUM] services/chaitin__cloudwalker-cwpp/src/cloudwalker-cwpp.js:360 — 三个 handler 固定把 err/msg 返回为 null,上游业务错误被静默吞掉
Prompt To Fix All With AI
# Review 1

This is a comment left during a code review.
Repository: https://github.com/chaitin/OctoBus
Path: services/chaitin__cloudwalker-cwpp/config.schema.json
Line: 17-20

Comment:
配置声明支持 HTTP 代理,但实现只支持 SOCKS 代理

proxy_url 的 schema 描述写明支持“SOCKS/HTTP 代理 URL”,但 callCwppRpc 无论协议都直接 new SocksProxyAgent(proxyUrl),而该库只接受 socks/socks4/socks5 协议。运维按文档把 proxy_url 配成 http://... 时请求会在构造代理阶段报错(且不是 GrpcError),所有查询都会失败并被映射为未知错误。

# Review 2

This is a comment left during a code review.
Repository: https://github.com/chaitin/OctoBus
Path: services/chaitin__cloudwalker-cwpp/src/cloudwalker-cwpp.js
Line: 353-360

Comment:
三个 handler 固定把 err/msg 返回为 null,上游业务错误被静默吞掉

三个 handler 都把响应的 err/msg 固定写成 toValue(null),从未读取上游 result 中的 err/msg,而 proto 专门为三个响应定义了这两个字段。若上游在 HTTP 200 的 result.err 中报告鉴权过期或业务失败,适配器会返回“成功”加空列表,调用方无法区分无数据与查询失败。

# Review 3

This is a comment left during a code review.
Repository: https://github.com/chaitin/OctoBus
Path: services/package.json
Line: 319

Comment:
services/package.json 缺少 socks-proxy-agent 依赖,服务启动时会因模块解析失败而崩溃

新增的 src/cloudwalker-cwpp.js 直接 import socks-proxy-agent,但本仓库实际的安装清单 services/package.json 的 dependencies 和 bundledDependencies 都没有该包,只有服务子目录的 package.json 声明了它。本仓库依赖在 services/ 根目录安装,并通过 services/bin/cloudwalker-cwpp.js 和 octobus-tentacles.js 注册加载该服务,因此运行时会出现 ERR_MODULE_NOT_FOUND,服务根本无法启动。
---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

"proxy_url": {
"type": "string",
"description": "可选 SOCKS/HTTP 代理 URL,如 socks5h://user:pass@host:port。"
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 配置声明支持 HTTP 代理,但实现只支持 SOCKS 代理

Category: 功能正确性

proxy_url 的 schema 描述写明支持“SOCKS/HTTP 代理 URL”,但 callCwppRpc 无论协议都直接 new SocksProxyAgent(proxyUrl),而该库只接受 socks/socks4/socks5 协议。运维按文档把 proxy_url 配成 http://... 时请求会在构造代理阶段报错(且不是 GrpcError),所有查询都会失败并被映射为未知错误。

Problem code:

"proxy_url": {
"type": "string",
"description": "可选 SOCKS/HTTP 代理 URL,如 socks5h://user:pass@host:port。"
},

Recommendation:
要么把 schema/README 明确限定为 SOCKS 代理,要么在实现中按代理协议选择支持 HTTP 代理的 Agent。

Prompt To Fix All With AI
This is a comment left during a code review.
Repository: https://github.com/chaitin/OctoBus
Path: services/chaitin__cloudwalker-cwpp/config.schema.json
Line: 17-20

Comment:
配置声明支持 HTTP 代理,但实现只支持 SOCKS 代理

proxy_url 的 schema 描述写明支持“SOCKS/HTTP 代理 URL”,但 callCwppRpc 无论协议都直接 new SocksProxyAgent(proxyUrl),而该库只接受 socks/socks4/socks5 协议。运维按文档把 proxy_url 配成 http://... 时请求会在构造代理阶段报错(且不是 GrpcError),所有查询都会失败并被映射为未知错误。
---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix with MonkeyCode
Fix with Claude
Fix with Codex


logFlow('ListRealTimeEvents:done', { count: events.length });

return { err: toValue(null), msg: toValue(null), data: { events } };

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 三个 handler 固定把 err/msg 返回为 null,上游业务错误被静默吞掉

Category: 数据完整性与集成

三个 handler 都把响应的 err/msg 固定写成 toValue(null),从未读取上游 result 中的 err/msg,而 proto 专门为三个响应定义了这两个字段。若上游在 HTTP 200 的 result.err 中报告鉴权过期或业务失败,适配器会返回“成功”加空列表,调用方无法区分无数据与查询失败。

Problem code:

const dataField = result?.data;
const events = Array.isArray(dataField)
? dataField.map((e) => (e && typeof e === 'object' ? e : {}))
: [];
logFlow('ListRealTimeEvents:done', { count: events.length });
return { err: toValue(null), msg: toValue(null), data: { events } };

Recommendation:
读取上游 result.err/result.msg(或实际嵌套位置),err 非零时抛出对应 GrpcError,其余情况将上游 err/msg 原样透传到响应。

Prompt To Fix All With AI
This is a comment left during a code review.
Repository: https://github.com/chaitin/OctoBus
Path: services/chaitin__cloudwalker-cwpp/src/cloudwalker-cwpp.js
Line: 353-360

Comment:
三个 handler 固定把 err/msg 返回为 null,上游业务错误被静默吞掉

三个 handler 都把响应的 err/msg 固定写成 toValue(null),从未读取上游 result 中的 err/msg,而 proto 专门为三个响应定义了这两个字段。若上游在 HTTP 200 的 result.err 中报告鉴权过期或业务失败,适配器会返回“成功”加空列表,调用方无法区分无数据与查询失败。
---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix with MonkeyCode
Fix with Claude
Fix with Codex

Comment thread services/package.json
"prometheus__alertmanager_0-27-0",
"das__apt",
"chaitin__cloudwalker",
"chaitin__cloudwalker-cwpp",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 services/package.json 缺少 socks-proxy-agent 依赖,服务启动时会因模块解析失败而崩溃

Category: 稳定性与可用性

新增的 src/cloudwalker-cwpp.js 直接 import socks-proxy-agent,但本仓库实际的安装清单 services/package.json 的 dependencies 和 bundledDependencies 都没有该包,只有服务子目录的 package.json 声明了它。本仓库依赖在 services/ 根目录安装,并通过 services/bin/cloudwalker-cwpp.js 和 octobus-tentacles.js 注册加载该服务,因此运行时会出现 ERR_MODULE_NOT_FOUND,服务根本无法启动。

Problem code:

"chaitin__cloudwalker-cwpp",

Recommendation:
在 services/package.json 的 dependencies 与 bundledDependencies 中加入 socks-proxy-agent(版本与子包一致,如 ^8.0.5)。

Prompt To Fix All With AI
This is a comment left during a code review.
Repository: https://github.com/chaitin/OctoBus
Path: services/package.json
Line: 319

Comment:
services/package.json 缺少 socks-proxy-agent 依赖,服务启动时会因模块解析失败而崩溃

新增的 src/cloudwalker-cwpp.js 直接 import socks-proxy-agent,但本仓库实际的安装清单 services/package.json 的 dependencies 和 bundledDependencies 都没有该包,只有服务子目录的 package.json 声明了它。本仓库依赖在 services/ 根目录安装,并通过 services/bin/cloudwalker-cwpp.js 和 octobus-tentacles.js 注册加载该服务,因此运行时会出现 ERR_MODULE_NOT_FOUND,服务根本无法启动。
---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix with MonkeyCode
Fix with Claude
Fix with Codex

…ervice

- 牧云 CWPP JSON-RPC 2.0 over HTTP /rpc,Cookie API-Token 认证
- 三个只读方法:ListRealTimeEvents / GetHostAssetList / GetAgentGroupTree
- 增加 socks5 代理支持(socks-proxy-agent),skipTlsVerify 支持自签证书
- export internal helpers via _test for unit testing
- cover proxiedFetch socks5 transport via mocked http.request
- cover fetch timeout/network/JSON-RPC error mappings and validation helpers
…h SocksProxyAgent

The smoke harness synthesizes the mock upstream as an http base URL, which was
fed verbatim to SocksProxyAgent and failed every Connect call with "A socks
protocol must be specified! Got: http:". Fall back to a direct connection for
non-socks URLs.
@monkeyscan

monkeyscan Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

PR Title: feat(services/cloudwalker-cwpp): add CloudWalker C...

Commit: 2e4df55

整体评估

上一轮已确认该服务包整体结构与仓库其他服务一致,但代理语义、依赖声明和上游错误透传仍存在风险。本轮只做了一处小改动:在 rpcdef 中增加 SOCKS 协议前缀判断,让非 socks 代理 URL 回退为直连,以修复 smoke 环境把 mock 上游地址当作代理传入而触发的 SocksProxyAgent 报错;方向明确,但处理方式引出了新的行为风险。

总结

该修复能让 smoke 场景不再因非法代理 URL 崩溃,但它把"代理配置无效"从显式错误变成了静默直连:配置 schema 宣称支持的 HTTP 代理会被悄悄丢弃,请求可能绕过预期的代理链路,这是合并前需要处理的主要风险。建议对不支持/非法的代理 URL 显式报错或至少记录告警(并修复 smoke harness 的传参),而不是静默降级。

Findings (1)

  • 🟡 [MEDIUM] services/chaitin__cloudwalker-cwpp/src/cloudwalker-cwpp.js:313 — 非 SOCKS 代理 URL 被静默丢弃,请求改走直连
Prompt To Fix All With AI
This is a comment left during a code review.
Repository: https://github.com/chaitin/OctoBus
Path: services/chaitin__cloudwalker-cwpp/src/cloudwalker-cwpp.js
Line: 313

Comment:
非 SOCKS 代理 URL 被静默丢弃,请求改走直连

新增的过滤只保留 socks/socks4/socks4a/socks5/socks5h 前缀的代理 URL,其他任何值(包括 config.schema.json 明确宣称支持的 HTTP 代理)都会被替换为空字符串,且没有任何日志或错误。这样运维配置的代理会被静默绕过,请求直接连向目标(或直接失败),既可能违反出口代理与网络隔离要求,也让排障时看不到配置无效的原因。
---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

const rawProxyUrl = String(firstNonEmpty(bindings.proxy_url, bindings.proxyUrl) ?? '').trim();
// Only socks:// schemes are routable through SocksProxyAgent; a plain http(s)
// URL (e.g. the smoke harness synthesizing the mock upstream) is not a proxy.
const proxyUrl = /^socks(4a?|5h?)?:\/\//i.test(rawProxyUrl) ? rawProxyUrl : '';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 非 SOCKS 代理 URL 被静默丢弃,请求改走直连

Category: 安全与隐私

新增的过滤只保留 socks/socks4/socks4a/socks5/socks5h 前缀的代理 URL,其他任何值(包括 config.schema.json 明确宣称支持的 HTTP 代理)都会被替换为空字符串,且没有任何日志或错误。这样运维配置的代理会被静默绕过,请求直接连向目标(或直接失败),既可能违反出口代理与网络隔离要求,也让排障时看不到配置无效的原因。

Problem code:

const proxyUrl = /^socks(4a?|5h?)?:\/\//i.test(rawProxyUrl) ? rawProxyUrl : '';

Recommendation:
不要静默降级:对非空但非 SOCKS 的代理 URL 抛出 INVALID_ARGUMENT 或至少打印明确告警,同时修复 smoke harness 把 mock 上游地址当代理传参的问题;若确实要兑现 schema 中的 HTTP 代理支持,应实现并补充相应测试。

Suggested change
const proxyUrl = /^socks(4a?|5h?)?:\/\//i.test(rawProxyUrl) ? rawProxyUrl : '';
const rawProxyUrl = String(firstNonEmpty(bindings.proxy_url, bindings.proxyUrl) ?? '').trim();
const proxyUrl = /^socks(4a?|5h?)?:\/\//i.test(rawProxyUrl) ? rawProxyUrl : '';
if (rawProxyUrl && !proxyUrl) {
throw errorWithCode('INVALID_ARGUMENT', 'proxy_url must use a socks://, socks4://, socks4a://, socks5:// or socks5h:// scheme');
}
Prompt To Fix All With AI
This is a comment left during a code review.
Repository: https://github.com/chaitin/OctoBus
Path: services/chaitin__cloudwalker-cwpp/src/cloudwalker-cwpp.js
Line: 313

Comment:
非 SOCKS 代理 URL 被静默丢弃,请求改走直连

新增的过滤只保留 socks/socks4/socks4a/socks5/socks5h 前缀的代理 URL,其他任何值(包括 config.schema.json 明确宣称支持的 HTTP 代理)都会被替换为空字符串,且没有任何日志或错误。这样运维配置的代理会被静默绕过,请求直接连向目标(或直接失败),既可能违反出口代理与网络隔离要求,也让排障时看不到配置无效的原因。
---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix with MonkeyCode
Fix with Claude
Fix with Codex

@Daemonceltics
Daemonceltics merged commit 2dc3d5b into chaitin:main Nov 5, 2026
4 checks 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.

1 participant