Merge blocked
变更摘要
本 PR 针对 issue #16 中「setenforce 0 只修改 SELinux 运行态、重启后回落到 /etc/selinux/config 配置的 enforcing 模式,导致 containerd / harbor 被 AVC 拒绝并无限重启」的问题,将 SELinux 处理从单一运行态操作升级为「运行态与持久配置一致性」检查。核心改动是在 deploy/common.sh 中新增 selinux_runtime_vs_config()、selinux_persist_hint()、disable_selinux_runtime() 三个共用函数,deploy/build.sh 改用 disable_selinux_runtime 替代裸 setenforce 0,deploy/check-env.sh 把不一致场景提升为 FAIL 并在部署前拦截;同时补充了相关文档说明。
主要改动
- 新增 SELinux 一致性判断函数:
deploy/common.sh增加selinux_runtime_vs_config(),将getenforce结果与/etc/selinux/config中SELINUX=取值统一小写后比较,不一致返回非 0;未安装getenforce或配置缺键时返回 0 以避免误报。 - 新增提示与运行态关闭封装: 同文件新增
selinux_persist_hint()输出两种持久化方案(改写配置为permissive/disabled,或restorecon -R加策略后再验证),以及disable_selinux_runtime()在setenforce 0后若检测到「重启会回退」即通过warn告警。 - 构建流程替换裸命令:
deploy/build.sh的install()与install_client()中command -v setenforce >/dev/null 2>&1 && setenforce 0均替换为disable_selinux_runtime,避免静默改变安全姿态而未告知后果。 - 环境检查判定升级为 FAIL:
deploy/check-env.sh的check_common()中原「未关闭则warn」逻辑改为对运行态与配置一致性执行check,不一致时记为失败并给出重启风险说明与两种修复命令,使--install与--start均能在部署前拦截。 - 文档补充持久化说明:
docs/zh/e2b_user_guide.md4.3 与deploy/DEPLOY_DESIGN.md10.1 补充「setenforce仅对当前内核生效」以及持久化二选一方案。


代码审查
审查结论
逐文件确认
| 文件 | 结论 |
|---|---|
deploy/build.sh |
只有两处替换(setenforce 0 → disable_selinux_runtime),common.sh 在 build.sh:91 已先 source,warn 定义在 common.sh:14,调用顺序正确;脚本无 set -e,函数返回非 0 不会中断。无新增问题(仍是上文 common.sh 缺陷的调用方)。 |
deploy/check-env.sh |
有问题(1 项:方向无关的相等性判断导致误报 FAIL)。脚本无 set -e,"$([ ... ]; echo $?)" 的写法在本文件中与既有风格一致,不会取到空值。 |
deploy/common.sh |
有问题(2 项:setenforce 0 失败被吞导致静默继续;持久化提示文案方向错误)。 |
docs/zh/e2b_user_guide.md |
有问题(1 项:声称 check-env.sh 部署前即可检出,与实际必然通过不符)。 |
deploy/DEPLOY_DESIGN.md |
无独立问题(10.1 内容与代码基本一致,仅"build.sh 的 disable_selinux_runtime"归属描述及"部署前即可发现"这两处准确性/表述问题,其中后者已并入文档项,其余属文档措辞,不单列)。 |
发现统计
- P2 × 2:
check-env.sh:93-98方向无关判断导致误报 FAIL;common.sh:59-63setenforce 0失败被|| true吞掉后仍静默在 enforcing 下部署。 - P3 × 2:
common.sh:48-51提示文案假设"重启后变严格";docs/zh/e2b_user_guide.md:421关于部署前可检出的描述不成立。 - P0/P1:无。
总体风险判断
改动方向正确(补齐 setenforce 只改运行态这一根因的检测与告知,且没有自动改写 /etc/selinux/config 这一危险动作),不引入构建/语法/安全回归。主要风险集中在判断语义而非脚本健壮性:把"运行态与配置不相等"等同于"重启后会被 enforcing 拦截",会在用户按文档改用 disabled/临时切回 enforcing 等安全方向上产生误报 FAIL 和相反结论的提示;同时 setenforce 0 的失败被完全吞掉,使 #16 的"静默掩盖"在最需要提示的场景下仍可能复现。建议合并前修正判据方向与失败可见性,并校正两处文档中"部署前即可发现"的说法。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 0 |
| 🟡 建议 | 2 |
💬 仅评论


Welcome To openEuler Community
Hey @yaqiangchen , thanks for your contribution to the community.
Bot Usage Manual
I'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands. You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
Contact Guide
If you have any questions, please contact the SIG: sig-CloudNative ,
and any of the maintainers: @duguhaotian, @feijianqiang, @gaodaweiky, @jimmieme, @lu-wei-army, @weibaohui, @wonleing, @yangzhao_kl, @zhaoyifan28, @zmr_2020 ,
and any of the committers: @feijianqiang, @fly_1997, @zhourenjianz .


门禁正在运行, 您可以通过以下链接查看实时门禁检查结果.
若您对门禁结果含义不清晰或者遇到问题不知如何解决,可参考门禁指导手册
门禁入口及编码规范检查: multiarch/openeuler/trigger/KASandbox/649


🟡 Medium Priority
改动行:deploy/common.sh:59 setenforce 0 2>/dev/null || true,替代了 deploy/build.sh:627 / deploy/build.sh:652 原来的裸 setenforce 0。
失败链条:2>/dev/null 丢弃了 stderr,|| true 丢弃了退出码 → 无论 setenforce 0 是否成功,函数都继续;紧随其后的唯一判据是 selinux_runtime_vs_config()(deploy/common.sh:32-42),它比较"运行态 vs 配置"。当 setenforce 0 失败时运行态仍是 enforcing,而配置通常也是 enforcing,两者相等 → 返回 0 → disable_selinux_runtime 不打印任何警告,warn 分支根本不进入。
触发条件:setenforce 存在但写入 /sys/fs/selinux/enforce 失败(容器化/裁剪环境、内核以 selinux=0 启动但用户态留了 setenforce、非预期权限上下文等)。结果:部署在 enforcing 下继续推进,而 issue #16 的容器 AVC 拦截问题在部署阶段就存在(只是被 selinux 策略拦在别处先失败),操作者拿不到任何提示——这正是本 PR 想消除的"静默执行让操作者误以为 SELinux 已关闭"。另外此时 deploy/common.sh:62 的文案"已临时置为 Permissive"也与事实不符(实际仍是 enforcing)。
建议:去掉 || true,在 setenforce 0 失败时告警并输出当前运行态;同时校验执行后的 getenforce 结果,只有确认为 permissive/disabled 时才走"持久化提示"分支,否则直接提示 SELinux 未关闭、containerd/harbor 可能启动失败。
|
63 | + setenforce 0 2>/dev/null || { |
|
64 | + warn "setenforce 0 执行失败,SELinux 仍为 $(getenforce 2>/dev/null || echo 未知),containerd / harbor 可能无法启动" |
|
65 | + } |
|
66 | + |
|
67 | + if ! selinux_runtime_vs_config; then |
|
68 | + warn "SELinux 已临时置为 Permissive,但它只对当前内核生效。" |
| 63
| - selinux_persist_hint |
|
69 | + selinux_persist_hint |
|
70 | + fi |


🟡 Medium Priority
改动行:deploy/check-env.sh:93-98(以及 deploy/common.sh:39-41/48-51 同一判据的 selinux_runtime_vs_config / selinux_persist_hint)只比较 if [ "$selinux_runtime" = "$selinux_config" ],把任意运行态/配置差异都判定为"重启后 containerd / harbor 可能无限重启(issue #16)"。
#16 的危险方向只有一个:重启后回到 enforcing(config=enforcing 且运行态≠enforcing)。反之方向是安全的(重启后更宽松),但同样会走 FAIL 分支:
- 用户按本次新增文档
docs/zh/e2b_user_guide.md:415/deploy/DEPLOY_DESIGN.md:680的"a) 保持关闭"用例执行sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config(文档明确写了"或 disabled"),在重启前运行./check-env.sh --start:运行态仍是 permissive(/etc/selinux/config只在重启时生效),配置已是 disabled → 判为 FAIL,并打印"重启后会回到 disabled,containerd / harbor 可能无限重启(issue #16)"。该结论是错的:disabled 比 permissive 更宽松,重启不会产生 AVC 硬拦截。用户被要求去"修复"一个已经正确的配置,检查项退出码非 0(exit "$FAIL_COUNT")。 - 用户按"b) 保持 enforcing"改回
SELINUX=enforcing、尚未重启(或运维临时setenforce 1):运行态 permissive / 配置 enforcing 以外的组合——例如运行态 enforcing、配置 permissive——同样 FAIL 并声称"重启后会回到 permissive,可能无限重启",与实际相反。
deploy/common.sh:48 的提示同样无条件写成"重启后会回到 {config}` 为 enforcing 时才成立。
建议:把判据从"是否相等"改为"重启后是否会回到 enforcing":只有 selinux_config=enforcing 且运行态不是 enforcing 时才 FAIL,其余(config 为 permissive/disabled)视为通过或降级为 WARN;同时把 check 描述改成"重启后不会回到 enforcing",避免描述与实际判据不符。最佳做法是直接复用 deploy/common.sh 的 selinux_runtime_vs_config(),删掉这里的重复 sed 解析。
| 98
| - |
|
98 | + check "SELinux 重启后不会回到 enforcing(运行态: $selinux_runtime / 配置: $selinux_config)" \ |
|
99 | + "$([ "$selinux_runtime" = "$selinux_config" ] || [ "$selinux_config" != "enforcing" ]; echo $?)" \ |


fix #16
问题
部署脚本里只有
setenforce 0:# deploy/build.sh command -v setenforce >/dev/null 2>&1 && setenforce 0它只修改当前内核的 SELinux 模式。
/etc/selinux/config仍是SELINUX=enforcing时:execute_no_trans等)→ 无限重启。deploy/check-env.sh原来也只检查运行态("SELinux 未关闭,建议 setenforce 0"),同样发现不了这个陷阱;文档里也只写了setenforce 0。改动
deploy/common.sh新增三个共用函数(build.sh/deploy.sh都 source 本文件):selinux_runtime_vs_config()getenforce运行态与/etc/selinux/config的SELINUX=,不一致返回非 0;未启用 SELinux 或配置缺键时返回 0(不误报)selinux_persist_hint()disable_selinux_runtime()setenforce 0:临时置 permissive 后,若检测到「重启会回退」立即告警并给出命令deploy/build.sh:install()与install_client()里的setenforce 0改为disable_selinux_runtime,不再静默改变安全姿态却不说后果。deploy/check-env.sh:SELinux 检查从「运行态未关闭就 warn」改为「运行态与持久配置必须一致」,不一致列为 FAIL:放在
check_common()里,--install与--start都会检查,部署前就能拦住,而不是重启后才发现。文档:
docs/zh/e2b_user_guide.md4.3、deploy/DEPLOY_DESIGN.md10.1 补充「setenforce只对当前内核生效」以及两种持久化方案。验证
bash -n deploy/common.sh deploy/build.sh deploy/check-env.sh全部通过;SELINUX=键Enforcing(大小写混写)getenforce实跑check-env.sh --install:SELinux 分支输出正常、脚本未中断。设计取舍
/etc/selinux/config。那属于静默修改系统安全姿态,部署脚本不该替用户决定;这里只做「检测 + 明确告知 + 给出命令」。WARN该有的分量重得多。SELINUX=键或未装 SELinux 时跳过,避免在容器/裁剪系统里误报。