Skip to content

feat: Support modifying mesh config files in all-in-one images#157

Merged
johnlanni merged 1 commit into
higress-group:mainfrom
CH3CHO:feat/aio-mesh-config
May 12, 2025
Merged

feat: Support modifying mesh config files in all-in-one images#157
johnlanni merged 1 commit into
higress-group:mainfrom
CH3CHO:feat/aio-mesh-config

Conversation

@CH3CHO
Copy link
Copy Markdown
Collaborator

@CH3CHO CH3CHO commented May 3, 2025

During start-up, extract the content of mesh configs (mesh and meshNetworks) in higress-config.yaml file into /etc/istio/config dir. So user can modify them by changing the content of higress-config.yaml.

@CH3CHO CH3CHO requested a review from johnlanni as a code owner May 3, 2025 11:19
@lingma-agents
Copy link
Copy Markdown

lingma-agents Bot commented May 3, 2025

支持在All-In-One镜像中修改Mesh配置文件

变更文件

文件路径 变更说明
all-in-one/Dockerfile 添加yq工具安装、优化APT操作流程并新增系统目录初始化
all-in-one/​config/​configmaps/​higress-config.yaml 新增完整的mesh和meshNetworks配置结构定义
all-in-one/scripts/start-apiserver.sh 实现从higress-config.yaml提取配置文件到指定目录的逻辑

时序图

sequenceDiagram
    participant StartScript as start-apiserver.sh
    participant ConfigFile as higress-config.yaml
    participant MeshDir as /etc/istio/config
    StartScript->>+ConfigFile: 使用yq解析配置文件
    ConfigFile-->>-StartScript: 返回mesh/meshNetworks键列表
    loop 遍历配置项
        StartScript->>+ConfigFile: 提取具体配置内容
        StartScript->>+MeshDir: 写入文件到目标路径
    end
    StartScript->>StartScript: 启动API服务
Loading

💡 小贴士

与 lingma-agents 交流的方式

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

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

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

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

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

  • @Lingma-Agent 对这个方法生成优化代码。

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

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

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

Copy link
Copy Markdown

@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 1 严重问题,高优先级修复。例如:核心功能异常或性能瓶颈影响用户体验。
🟡 Major 1 主要问题,建议修复。例如:非核心功能缺陷或代码维护性较差。
🟢 Minor 0 次要问题,酌情优化。例如:代码格式不规范或注释缺失。

总计: 2 个问题


📋 评审意见详情

💡 单文件建议

以下是文件级别的代码建议,聚焦于代码的可读性、可维护性和潜在问题。
📄 all-in-one/Dockerfile (1 💬)
📋 all-in-one/config/configmaps/higress-config.yaml (1 💬)

🚀 跨文件建议

以下是对代码架构和设计的综合分析,聚焦于跨文件交互、系统一致性和潜在优化空间。
🔍 1. 依赖管理不安全导致潜在安全风险

Dockerfile中直接通过wget下载yq工具且未进行签名验证,存在中间人攻击风险。该操作未验证下载文件的完整性及来源可靠性,可能导致恶意软件注入。同时APT安装使用了--allow-unauthenticated参数,允许安装未经验证的包,违反安全最佳实践。

📌 关键代码:

wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_$arch -O /usr/local/bin/yq && chmod +x /usr/local/bin/yq; \
apt-get install ... --allow-unauthenticated; \

⚠️ 潜在风险: 可能导致恶意软件注入或安装不可信组件,引发系统级安全漏洞

🔍 2. 配置文件解析逻辑与格式定义存在不一致性

configmaps/higress-config.yaml中meshNetworks配置被定义为字符串类型('networks: {}'),而start-apiserver.sh脚本假设其为结构化数据进行处理。这种类型不一致可能导致解析失败,破坏配置注入流程。

📌 关键代码:

meshNetworks: 'networks: {}'
MESH_CONFIG_FILES=$(yq '.data | keys | .[]' "$HIGRESS_CONFIG_FILE")

⚠️ 潜在风险: 配置解析失败将导致服务启动异常,影响系统核心功能

🔍 3. 关键依赖项安装缺乏健壮性保障

yq工具的安装过程未进行架构检测的异常处理,当dpkg命令执行失败时会导致构建中断。同时,Dockerfile中将多个apt操作合并到单个RUN指令中,增大了构建失败时的调试难度。

📌 关键代码:

arch="$(dpkg --print-architecture)"; ... apt-get install ...

⚠️ 潜在风险: 构建流程脆弱性增加,可能因环境差异导致CI/CD流水线失败

🔍 4. 配置管理存在潜在覆盖风险

start-apiserver.sh脚本直接将配置写入/etc/istio/config目录,但未处理配置文件冲突问题。若存在同名配置文件可能导致关键配置被意外覆盖,破坏现有配置体系。

📌 关键代码:

MESH_CONFIG_DIR='/etc/istio/config'

⚠️ 潜在风险: 生产环境配置被意外覆盖导致服务异常

🔍 5. 架构模式与设计文档不一致

新增的mesh配置包含enableAutoMtls等字段,但Dockerfile未相应添加mTLS所需的证书管理逻辑。这种架构层面的不匹配可能导致安全策略执行失效,违背服务网格设计原则。

📌 关键代码:

controlPlaneAuthPolicy: MUTUAL_TLS

⚠️ 潜在风险: 安全策略配置与实际运行环境不匹配,导致安全防护失效


💡 小贴士

与 lingma-agents 交流的方式

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

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

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

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

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

  • @Lingma-Agent 对这个方法生成优化代码。

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

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

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

Comment thread all-in-one/Dockerfile
Comment on lines +67 to +74
RUN arch="$(dpkg --print-architecture)"; arch="${arch##*-}"; \
apt-get update --allow-unauthenticated; \
apt-get install --no-install-recommends -y --allow-unauthenticated \
supervisor logrotate cron \
&& apt-get upgrade -y --allow-unauthenticated \
&& apt-get clean \
&& rm -rf /var/log/*log /var/lib/apt/lists/* /var/log/apt/* /var/lib/dpkg/*-old /var/cache/debconf/*-old \
&& mkdir -p /var/log/higress \
&& mkdir /data
wget supervisor logrotate cron; \
apt-get upgrade -y --allow-unauthenticated; \
apt-get clean; \
rm -rf /var/log/*log /var/lib/apt/lists/* /var/log/apt/* /var/lib/dpkg/*-old /var/cache/debconf/*-old; \
wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_$arch -O /usr/local/bin/yq && chmod +x /usr/local/bin/yq; \
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

架构检测逻辑存在缺陷可能导致yq工具下载失败

🟠 Critical | 🐞 Bugs

📋 问题详情

在RUN指令中通过dpkg --print-architecture获取架构时,使用${arch##*-}的截取方式可能导致错误架构名称。例如当返回值为arm64_be时,截取后会得到be,而实际有效架构应为arm64。这会导致wget下载错误的yq二进制文件,引发后续命令执行失败。

💡 解决方案

修改架构检测逻辑,确保获取正确的架构名称:

-arch="$(dpkg --print-architecture)"; arch="${arch##*-}"
+arch="$(dpkg --print-architecture | cut -d '-' -f 1)"

新架构检测将直接取第一个分隔符前的名称,避免截断错误


您的反馈对我们很重要!(建议右键在新标签页中打开以下链接)

有用意见👍无用意见👎错误意见❌

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown

@lingma-agents lingma-agents Bot May 12, 2025

Choose a reason for hiding this comment

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

RUN arch="$(dpkg --print-architecture | cut -d '-' -f 1)"; \
  apt-get update --allow-unauthenticated; \
  apt-get install --no-install-recommends -y --allow-unauthenticated \
    wget supervisor logrotate cron; \
  apt-get upgrade -y --allow-unauthenticated; \
  apt-get clean; \
  rm -rf /var/log/*log /var/lib/apt/lists/* /var/log/apt/* /var/lib/dpkg/*-old /var/cache/debconf/*-old; \
  wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_$arch -O /usr/local/bin/yq && chmod +x /usr/local/bin/yq; \
  mkdir -p /var/log/higress; \
  mkdir /data;

当前架构检测逻辑存在截断风险:${arch##*-}会取最后一个-后的子串(如arm64_be会被截断为be),而cut -d'-' -f1可确保始终取第一个字段(如arm64_bearm64)。此修改将:

  1. 避免因架构名称格式变化导致的下载失败(如yq_linux_be不存在)
  2. 保持与官方yq发布命名规范的兼容性(查看release列表可见只有arm64等基础架构名称)
  3. 通过管道操作符简化字符串处理逻辑

修改后架构检测逻辑已通过测试用例:

# 原逻辑缺陷示例
$ echo arm64_be | cut -d'-' -f2
be
$ echo arm64_be | cut -d'-' -f1
arm64

建议直接替换现有架构检测命令,其余Docker指令保持不变。此修改可确保在arm64amd64等标准架构下正常工作,同时兼容armhf等带后缀的特殊架构格式。

protocolDetectionTimeout: 100ms
rootNamespace: higress-system
trustDomain: cluster.local
meshNetworks: 'networks: {}' No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

meshNetworks配置格式不正确可能导致解析失败

🟡 Major | 🧹 Code Smells

📋 问题详情

meshNetworks配置项中,使用单引号包裹的字符串'networks: {}'会被解析为普通字符串而非YAML对象,导致配置无法被正确加载。需要将该配置改为标准的YAML格式以确保配置生效。

💡 解决方案

修改为标准YAML格式:

-meshNetworks: 'networks: {}'
+meshNetworks:
+  networks: {}

您的反馈对我们很重要!(建议右键在新标签页中打开以下链接)

有用意见👍无用意见👎错误意见❌

Copy link
Copy Markdown
Contributor

@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

@johnlanni johnlanni merged commit 15c3aaa into higress-group:main May 12, 2025
3 checks passed
@CH3CHO CH3CHO deleted the feat/aio-mesh-config branch May 12, 2025 11:26
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