Skip to content

Conversation

@CH3CHO
Copy link
Collaborator

@CH3CHO CH3CHO commented Aug 4, 2025

Ⅰ. Describe what this PR did

Support adding a proxy server in between when forwarding requests to upstream.

  1. Update McpBridge resource
    a. Add a new proxies field to spec for configuring a proxy server list.
    b. Add a new proxyName field to the item of registries for linking a proxy server to a registry.
  2. Generate an EnvoyFilter in registry.Reconciler to create a cluster and a listener for each proxy server.
  3. Generate EnvoyFilters in IngressConfig to update the cluster workload for each service bound with a proxy server, making them pointing to the local listener of corresponding proxy server with the SNI of the service.

Ⅱ. Does this pull request fix one issue?

fixes #2664

Ⅲ. Why don't you add test cases (unit test/integration test)?

TBC

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@CH3CHO CH3CHO marked this pull request as draft August 4, 2025 10:10
@lingma-agents
Copy link

lingma-agents bot commented Aug 4, 2025

支持在转发请求到上游时添加代理服务器

变更概述
  • 新功能

    • McpBridge CRD 中新增了 proxies 字段,用于定义代理服务器配置。
    • RegistryConfig 中增加了 proxyName 字段,允许为注册中心配置指定代理。
    • 引入了 ProxyConfig 结构体,用于描述代理服务器的详细配置,包括类型、名称、地址、端口等。
    • 增加了 ProxyWrapperServiceProxyConfig 结构体,用于封装代理相关配置和逻辑。
    • 实现了在 Ingress 控制器中处理代理配置的逻辑,包括调整路由集群和服务代理的 EnvoyFilter 构建。
    • 新增了 ProxyType 类型和相关解析函数,支持 HTTP、HTTPS、SOCKS4 和 SOCKS5 代理类型。
    • 添加了构造代理相关 EnvoyFilter 的函数,用于生成代理服务器和代理服务的配置。
  • 重构

    • 修改了 ConvertOptions 结构体,增加了 ServiceWrappersProxyWrappers 字段,用于存储服务和代理的包装器。
    • 调整了 Ingress 控制器中的虚拟服务转换逻辑,以支持代理配置。
    • 重构了 WasmPlugin 的处理逻辑,使其能够识别并处理代理相关的服务。
  • 问题修复

    • 修复了在处理 WasmPlugin 规则时未考虑代理服务的问题,确保代理服务能够正确地被添加到规则中。
  • 其他

    • 更新了 Makefile,添加了清理 Kubernetes 客户端生成代码的命令。
变更文件
文件路径 变更说明
api/​kubernetes/​customresourcedefinitions.​gen.​yaml 在 McpBridge CRD 中添加了 proxies 字段,并在 RegistryConfig 中增加了 proxyName 字段。
api/​networking/​v1/​mcp_​bridge.​pb.​go 在 McpBridge 结构体中添加了 Proxies 字段,并在 RegistryConfig 中增加了 ProxyName 字段,同时引入了 ProxyConfig 结构体。
api/​networking/​v1/​mcp_​bridge.​proto 在 McpBridge 消息中添加了 proxies 字段,并在 RegistryConfig 中增加了 proxyName 字段,同时定义了 ProxyConfig 消息。
api/​networking/​v1/​mcp_​bridge_​deepcopy.​gen.​go 为 ProxyConfig 结构体添加了 DeepCopy 相关方法。
api/​networking/​v1/​mcp_​bridge_​json.​gen.​go 为 ProxyConfig 结构体添加了 MarshalJSON 和 UnmarshalJSON 方法。
client/Makefile 添加了 clean-k8s-client 目标,用于清理生成的 Kubernetes 客户端代码。
pkg/common/protocol.go 新增了 IsSupportedByProxy 方法,用于判断协议是否支持代理。
pkg/common/proxy.go 新增了 ProxyType 类型及其相关解析和转换函数。
pkg/​ingress/​config/​ingress_​config.​go 实现了代理配置的处理逻辑,包括调整路由集群、构造 EnvoyFilter 以及处理 WasmPlugin 规则。
pkg/​ingress/​kube/​common/​controller.​go 新增了 ServiceProxyConfig 和 ServiceWrapper 结构体,用于封装代理相关配置。

💡 小贴士

与 lingma-agents 交流的方式

📜 直接回复评论
直接回复本条评论,lingma-agents 将自动处理您的请求。例如:

  • 在当前代码中添加详细的注释说明。

  • 请详细介绍一下你说的 LRU 改造方案,并使用伪代码加以说明。

📜 在代码行处标记
在文件的特定位置创建评论并 @lingma-agents。例如:

  • @lingma-agents 分析这个方法的性能瓶颈并提供优化建议。

  • @lingma-agents 对这个方法生成优化代码。

📜 在讨论中提问
在任何讨论中 @lingma-agents 来获取帮助。例如:

  • @lingma-agents 请总结上述讨论并提出解决方案。

  • @lingma-agents 请根据讨论内容生成优化代码。

Copy link

@lingma-agents lingma-agents bot left a comment

Choose a reason for hiding this comment

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

🔎 代码评审报告

🎯 评审意见概览
严重度 数量 说明
🔴 Blocker 0 阻断性问题,需立即修复。例如:系统崩溃、关键功能不可用或严重安全漏洞。
🟠 Critical 9 严重问题,高优先级修复。例如:核心功能异常或性能瓶颈影响用户体验。
🟡 Major 0 主要问题,建议修复。例如:非核心功能缺陷或代码维护性较差。
🟢 Minor 2 次要问题,酬情优化。例如:代码格式不规范或注释缺失。

总计: 11 个问题

📋 评审意见详情
💡 代码实现建议
以下是文件级别的代码建议,聚焦于代码的可读性、可维护性和潜在问题。
🔹 pkg/ingress/config/ingress_config.go (3 💬)
🔹 pkg/ingress/kube/common/controller.go (2 💬)
🔹 registry/memory/cache.go (3 💬)
🔹 registry/proxy/factory.go (1 💬)
🔹 registry/reconcile/reconcile.go (1 💬)
🔹 registry/zookeeper/watcher.go (1 💬)
🚀 架构设计建议
以下是对代码架构和设计的综合分析,聚焦于跨文件交互、系统一致性和潜在优化空间。
🔍1. 代理配置的全局一致性与潜在冲突风险

在多个文件中引入了代理配置(ProxyConfig)和相关处理逻辑,但缺乏统一的验证和冲突检测机制。例如,在 pkg/ingress/config/ingress_config.go 中构造 EnvoyFilter 时,没有校验 ProxyName 的全局唯一性,可能导致同名代理配置冲突。此外,ServiceProxyConfig 在多个注册中心(如 Consul、DNS、Eureka)中被独立处理,但未确保配置的一致性,可能引发运行时错误或不可预期的行为。

📌 关键代码

func constructProxyEnvoyFilters(proxyWrappers map[string]*common.ProxyWrapper, serviceWrappers map[string]*common.ServiceWrapper, namespace string) []*config.Config {
type ServiceProxyConfig struct {
	ProxyName        string
	UpstreamProtocol common.Protocol
	UpstreamSni      string
}

⚠️ 潜在风险

代理配置冲突可能导致服务路由错误、连接失败或安全漏洞。缺乏全局一致性校验会增加调试和维护难度。

🔍2. 跨文件的重复逻辑与代码抽象不足

pkg/ingress/config/ingress_config.go 和多个注册中心的 watcher 文件中(如 registry/direct/watcher.go, registry/eureka/watcher.go),都存在生成 ServiceProxyConfig 的相似逻辑。这些重复代码增加了维护负担,并可能导致功能不一致。应抽象出统一的代理配置生成逻辑,供各模块复用。

📌 关键代码

func (m *IngressConfig) adjustWasmPluginForProxy(out []config.Config) {
func (w *watcher) generateProxyConfig(entry *v1alpha3.ServiceEntry) *ingress.ServiceProxyConfig {

⚠️ 潜在风险

重复代码增加维护成本,容易引入不一致的逻辑,导致难以追踪的bug。

🔍3. 代理支持对系统性能和可扩展性的影响

新增的代理功能通过构造 EnvoyFilter 来实现,这会增加 Envoy 配置的复杂度和规模。特别是在大规模服务部署场景下,每个服务都可能生成额外的 EnvoyFilter 和 Cluster 配置,可能导致 Pilot 和 Envoy 的性能下降。此外,频繁更新 EnvoyFilter 可能引发 XDS 推送风暴,影响系统稳定性。

📌 关键代码

func constructProxyEnvoyFilters(proxyWrappers map[string]*common.ProxyWrapper, serviceWrappers map[string]*common.ServiceWrapper, namespace string) []*config.Config {

⚠️ 潜在风险

在大规模部署中,性能下降、XDS 推送延迟或失败,影响服务可用性和用户体验。

🔍4. 安全风险:代理配置可能绕过安全策略

代理功能允许流量通过中间代理服务器转发,但当前实现未明确考虑安全策略的继承和应用。例如,TLS 配置、认证和授权策略可能无法正确传递到代理服务器,导致流量在代理环节被窃听或篡改。此外,ServiceProxyConfig 中的 UpstreamSni 字段如果配置不当,可能引发证书验证失败或中间人攻击。

📌 关键代码

if proxyConfig.UpstreamProtocol.IsHTTPS() {
		tlsTypedConfig := map[string]interface{}{
			"@type": "type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext",
		}
		if proxyConfig.UpstreamSni != "" {
			tlsTypedConfig["sni"] = proxyConfig.UpstreamSni
		}

⚠️ 潜在风险

流量在代理环节可能被窃听、篡改或绕过安全策略,导致数据泄露或服务被非法访问。

🔍5. 测试覆盖不足与业务逻辑验证缺失

新增的代理功能涉及复杂的配置转换和 EnvoyFilter 构造逻辑,但未提供相应的单元测试或集成测试来验证其正确性。特别是在 adjustWasmPluginForProxyadjustRouteClusterForProxy 等关键方法中,缺乏对代理配置生效的测试用例,难以保证业务逻辑的正确性和稳定性。

📌 关键代码

func (m *IngressConfig) adjustWasmPluginForProxy(out []config.Config) {
func (m *IngressConfig) adjustRouteClusterForProxy(convertOptions *common.ConvertOptions, out []config.Config) {

⚠️ 潜在风险

未经充分测试的功能可能包含隐藏的bug,导致生产环境中服务中断或安全漏洞。

🔍6. 依赖管理与版本兼容性问题

新增的代理功能依赖于特定版本的 Envoy API 和 Istio 配置模型。如果这些依赖库发生变更,可能导致代理功能失效或出现兼容性问题。此外,ProxyConfigServiceProxyConfig 的结构定义与底层 Envoy 配置紧密耦合,未来 Envoy 升级时可能需要大量修改。

📌 关键代码

message ProxyConfig {
  string type = 1 [(google.api.field_behavior) = REQUIRED];
  string name = 2 [(google.api.field_behavior) = REQUIRED];
  string serverAddress = 3 [(google.api.field_behavior) = REQUIRED];
  uint32 serverPort = 4 [(google.api.field_behavior) = REQUIRED];
  uint32 listenerPort = 5;
  uint32 connectTimeout = 6;
}

⚠️ 潜在风险

依赖库升级可能导致功能失效或需要大量重构工作,增加维护成本和系统风险。

审查详情
📒 文件清单 (21 个文件)
新增: 2 个文件
删除: 1 个文件
📝 变更: 18 个文件

✅ 新增文件:

  • pkg/common/proxy.go
  • registry/proxy/factory.go

❌ 删除文件:

  • registry/memory/model.go

📝 变更文件:

  • api/kubernetes/customresourcedefinitions.gen.yaml
  • api/networking/v1/mcp_bridge.pb.go
  • api/networking/v1/mcp_bridge.proto
  • api/networking/v1/mcp_bridge_deepcopy.gen.go
  • api/networking/v1/mcp_bridge_json.gen.go
  • client/Makefile
  • pkg/common/protocol.go
  • pkg/ingress/config/ingress_config.go
  • pkg/ingress/kube/common/controller.go
  • pkg/ingress/kube/common/model.go
  • registry/consul/watcher.go
  • registry/direct/watcher.go
  • registry/eureka/watcher.go
  • registry/memory/cache.go
  • registry/nacos/v2/watcher.go
  • registry/nacos/watcher.go
  • registry/reconcile/reconcile.go
  • registry/zookeeper/watcher.go

💡 小贴士

与 lingma-agents 交流的方式

📜 直接回复评论
直接回复本条评论,lingma-agents 将自动处理您的请求。例如:

  • 在当前代码中添加详细的注释说明。

  • 请详细介绍一下你说的 LRU 改造方案,并使用伪代码加以说明。

📜 在代码行处标记
在文件的特定位置创建评论并 @lingma-agents。例如:

  • @lingma-agents 分析这个方法的性能瓶颈并提供优化建议。

  • @lingma-agents 对这个方法生成优化代码。

📜 在讨论中提问
在任何讨论中 @lingma-agents 来获取帮助。例如:

  • @lingma-agents 请总结上述讨论并提出解决方案。

  • @lingma-agents 请根据讨论内容生成优化代码。

@codecov-commenter
Copy link

codecov-commenter commented Aug 4, 2025

Codecov Report

❌ Patch coverage is 0% with 200 lines in your changes missing coverage. Please review.
✅ Project coverage is 45.31%. Comparing base (ef31e09) to head (71f8cf5).
⚠️ Report is 653 commits behind head on main.

Files with missing lines Patch % Lines
pkg/ingress/config/ingress_config.go 0.00% 146 Missing ⚠️
pkg/ingress/kube/common/controller.go 0.00% 26 Missing ⚠️
pkg/common/proxy.go 0.00% 22 Missing ⚠️
pkg/common/protocol.go 0.00% 6 Missing ⚠️

❌ Your patch status has failed because the patch coverage (0.00%) is below the target coverage (50.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2710      +/-   ##
==========================================
+ Coverage   35.91%   45.31%   +9.40%     
==========================================
  Files          69       82      +13     
  Lines       11576    13224    +1648     
==========================================
+ Hits         4157     5992    +1835     
+ Misses       7104     6886     -218     
- Partials      315      346      +31     
Files with missing lines Coverage Δ
pkg/ingress/kube/common/model.go 28.91% <ø> (+26.31%) ⬆️
pkg/common/protocol.go 0.00% <0.00%> (ø)
pkg/common/proxy.go 0.00% <0.00%> (ø)
pkg/ingress/kube/common/controller.go 8.33% <0.00%> (-18.34%) ⬇️
pkg/ingress/config/ingress_config.go 11.57% <0.00%> (-2.30%) ⬇️

... and 74 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@CH3CHO CH3CHO force-pushed the feat/proxy-server branch from 3a535cb to 0b27967 Compare August 7, 2025 07:39
@CH3CHO CH3CHO marked this pull request as ready for review August 11, 2025 04:46
@CH3CHO CH3CHO force-pushed the feat/proxy-server branch from 92ae62d to 1a1509e Compare August 12, 2025 02:05
IngressLog.Infof("Found %d number of envoyFilters", len(envoyFilters))
m.mutex.Lock()
m.cachedEnvoyFilters = envoyFilters
// TODO (by CH3CHO): Make sure pilot can get the latest envoy filters.
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the reason for this TODO?

Copy link
Collaborator

@johnlanni johnlanni left a comment

Choose a reason for hiding this comment

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

LGTM

@CH3CHO CH3CHO merged commit 5822868 into alibaba:main Aug 15, 2025
8 checks passed
@CH3CHO CH3CHO deleted the feat/proxy-server branch August 15, 2025 08:15
ink-hz pushed a commit to ink-hz/higress-ai-capability-auth that referenced this pull request Nov 5, 2025
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.

Support adding a proxy server in between when forwarding requests to upstream

3 participants