Remove firewalld support from VPC fabric

venix
admin 1 month ago
parent 82ce350001
commit ecf221d181

@ -178,7 +178,11 @@ location = /engine-console {
1. 管理员添加宿主机:填写现有 SSH/root/私钥口令、从可信控制台核验指纹,并填写仅用于展示的位置标签、`default_network`、存储/ISO/救援目录后测试连接。位置标签不决定销售地区或 Fabric/VPC 归属;宿主机基础表单不再写入旧版单 CIDR、网关或 DNS 字段。`Fabric 传输 IPv4` 可留空:当 SSH 地址是字面 IPv4 时 Engine 会将它作为当前公网 underlay;SSH 使用域名或希望以后改走同地区内网时,应填写宿主机真实持有、所有地区成员都能访问的 IPv4。该地址只用于 WireGuard,不是 VM 公网网桥或地址池;修改后必须重新检测,不会自动迁移已固定的 Fabric 计划。
2. 在“资源调度”中把宿主机加入一个资源池,并设置容量、安全余量和调度状态。宿主机的权威销售地区由该成员关系沿资源池、线路到地区唯一确定,而不是读取宿主机位置标签。当前每台宿主机只有一个权威资源池成员关系,因此也只有该资源池对应的一条权威线路;一台宿主机挂多条线路、多个 bridge/VLAN 或多个路由表属于后续阶段。
3. 打开宿主机“公网地址池”,为同一个 `default_network` 添加一个或多个互不重叠的实际公网 IPv4 CIDR,分别填写网关、DNS、客户机前缀、保留地址和状态。面板先在事务中保存期望配置,再向引擎提交同一版本;引擎确认后标记为 `applied`,并由面板把 CIDR 物化为具体 IP 账本。网络超时或响应不确定时保留同一 `request_key` 和版本重试,不能创建第二个池。调度器只使用面板策略、reservation 和 IP 账本计算的剩余资源。完整顺序和失败/回滚边界见 [单宿主机多公网 IPv4 地址池](MULTI_PUBLIC_IPV4_POOLS.md)。
4. 打开“地区私网”,选择一个地区后按页面向导执行“检测宿主机 → 自动配置地区私网 → 重新核对”。检测通过后先核对服务端只读方案摘要;不要准备或提交 Fabric JSON,也不要直接写地区映射。只有服务端阶段允许时相应按钮才会启用,自动配置或重新核对只有在最新权威投影到达 `active` 后才算成功。全新且无 desired state 的地区才使用“自动配置”;页面发现任何固定方案、历史 disabled 映射或确定性部分成功时,应按提示使用“重新核对”,不能重复创建。未绑定的自定义 Fabric 不会自动认领或兼容,会保持 `migration_required`。宿主机防火墙必须落入且只落入两种受支持模式之一:native `nftables.service` active/enabled,且 firewalld unit 不存在或 inactive+masked;或 firewalld active/enabled、`FirewallBackend=nftables`、`NftablesTableOwner=yes`,且 native `nftables.service` 不存在或 inactive+disabled/masked。仅 disabled 的 firewalld 仍可被 D-Bus 激活,不能进入 native 模式;混合、未知、source-bound zone 或运行态/持久 zone 不一致均 fail-closed。firewalld 模式只在 endpoint 是本机真实地址、普通路由和带该 endpoint 源地址的路由均选择同一地址归属接口、且该物理接口不在 `trusted` zone 时,自动添加目标为本机 endpoint `/32` 和固定 UDP 端口的精确 rich rule。endpoint 还必须位于全局租户 VPC CIDR 池之外;当前默认池为 `10.0.0.0/8`,后续内网 underlay 应使用与它隔离的地址规划。平台不会把所选 endpoint 的物理接口设为 `trusted`,也不会代替外部 NAT、云安全组或上游防火墙。两种模式都要求先完整回读原始 nft ACL,再激活平台创建的 WireGuard/私网接口;仅 firewalld 模式使用临时 runtime `trusted`,native 模式既不使用也不要求 firewalld zone/trusted。不要手工把这些接口永久加入 `trusted`。失败事务留下的 emergency guard 只能由相同 owner token 和完整规则快照证明后恢复或清理。只有没有 VPC state、panel manifest 或未完成 journal 的空宿主,才能在把一次失败的 firewalld 前置尝试纠正为 native 后,由“重新核对”接管并清理 guard;已有 VPC 的宿主切换防火墙 owner 是尚未自动化的维护迁移,必须先恢复原模式并在维护窗口迁出/清空 VPC,不能手工删除同名 nft table、owner intent、snapshot 或 manifest。按 [Fabric 宿主机验收矩阵](FABRIC_HOST_ACCEPTANCE.md) 验证 MTU、SELinux、firewalld/nftables 与网络管理器重启、libvirt 启动门禁、握手和跨宿主机流量。64 台探针的引擎窗口为 180 秒,浏览器为 240 秒;Web 服务器、反代和 PHP-FPM 的请求终止/读超时应至少配置为 270 秒。HTTP 超时、连接中断或 HTTP 5xx 不能视为失败或成功;不要重复点击自动配置,只使用“重新核对”读取并收敛固定 desired state。
4. 打开“地区私网”,选择一个地区后按页面向导执行“检测宿主机 → 自动配置地区私网 → 重新核对”。检测通过后先核对服务端只读方案摘要;不要准备或提交 Fabric JSON,也不要直接写地区映射。只有服务端阶段允许时相应按钮才会启用,自动配置或重新核对只有在最新权威投影到达 `active` 后才算成功。全新且无 desired state 的地区才使用“自动配置”;页面发现任何固定方案、历史 disabled 映射或确定性部分成功时,应按提示使用“重新核对”,不能重复创建。未绑定的自定义 Fabric 不会自动认领或兼容,会保持 `migration_required`。
宿主机防火墙只支持 native nftables:`nftables.service` 必须 active/enabled,且 firewalld unit 不存在或 inactive+masked。仅 disabled 的 firewalld 仍可被 D-Bus 激活,不得通过检测;实时规则中也不得存在 `inet firewalld` table。旧 `firewalld_nft` desired state、manifest、journal 或 zone/rich-rule 所有权一律 fail-closed;即使旧 journal 标记为 native,只要仍携带已退役的 `firewalld_*`/`underlay_*` schema 字段,也不会被普通 apply/reconcile 恢复或删除。测试环境需要转换时,应先停止租户流量并保存规则/journal 快照,在维护窗口清理旧所有权状态,然后以全新 native 方案重建;不要直接删除未完成事务的 nft table、owner intent、snapshot 或 manifest。
Endpoint 必须位于全局租户 VPC CIDR 池之外;当前默认池为 `10.0.0.0/8`,后续内网 underlay 应使用与它隔离的地址规划。panel-owned Fabric nft table 不负责放行 underlay UDP;运维必须在宿主持久 native nftables 规则或上游云安全组/防火墙中,以最窄可证明的 peer 源地址、本机 endpoint `/32`、UDP 和固定 Fabric 端口显式放行,外部 NAT 也由运维管理。平台先完整回读受管 nft ACL,再激活 WireGuard/私网接口;接口 active 或 unit green 不能代替双向握手和实际流量验收。按 [Fabric 宿主机验收矩阵](FABRIC_HOST_ACCEPTANCE.md) 验证 MTU、SELinux、native nftables 持久化与网络管理器重启、libvirt 启动门禁、握手和跨宿主机流量。64 台探针的引擎窗口为 180 秒,浏览器为 240 秒;Web 服务器、反代和 PHP-FPM 的请求终止/读超时应至少配置为 270 秒。HTTP 超时、连接中断或 HTTP 5xx 不能视为失败或成功;不要重复点击自动配置,只使用“重新核对”读取并收敛固定 desired state。
5. 导入云镜像与救援模板;无已有模板不能开通云镜像 VM。云镜像是面板全局目录,验证后的源文件持久保存在 `runtime/engine/cloud-templates/`;首次在某宿主机创建或重装时才同步一份缓存,之后复用,所以切换地区不会更换或刷新镜像列表。支持 AlmaLinux 8/9/10、Debian 11/12/13、CentOS Stream 9/10、Ubuntu 20.04/22.04/24.04/25.04/25.10/26.04 x86_64 云镜像。官方镜像可填写官方镜像站的 HTTPS 文件地址,引擎只跟随由官方入口返回且通过公网地址安全校验的跳转链;例如 AlmaLinux 8 可使用 `https://repo.almalinux.org/almalinux/8/cloud/x86_64/images/AlmaLinux-8-GenericCloud-latest.x86_64.qcow2`,Debian 12 可使用 `https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-amd64.qcow2`,CentOS Stream 9 可使用 `https://cloud.centos.org/centos/9-stream/x86_64/images/CentOS-Stream-GenericCloud-9-latest.x86_64.qcow2`,Ubuntu 24.04 可使用 `https://cloud-images.ubuntu.com/releases/noble/release/ubuntu-24.04-server-cloudimg-amd64.img`。自制或修复镜像使用管理员页面的本地 QCOW2 上传入口,并明确选择与内容一致的系统和版本;文件必须是 1 MiB 至 4 GiB 的独立、未加密 QCOW2,不能包含 backing file 或外部 data file,ISO 和 raw 镜像均不接受。面板磁盘需为上传临时文件、全局源镜像及 256 MiB 安全余量预留空间,各宿主机的镜像存储池也需容纳本地缓存。远程导入的 SHA-256 可留空;本地上传始终由面板计算、签名并保存实际摘要。
6. 套餐设置规格、每期价格、账期天数、每期流量额度和库存,并绑定可销售的资源池。用户提交部署后先生成 30 分钟有效的开通账单,支付成功才创建实例;实例到期前 7 天再生成续费账单。两种账单均可用余额支付,也可由启用的易支付、Paytaro 或 USDT 渠道生成支付订单。在线支付回调会自动结清对应账单;失效账单的晚到款只保留在账户余额中,不会创建实例或恢复已进入删除流程的实例。
7. 测试用户注册验证码、密码重置、充值、生成开通账单和账单支付,确认未支付时没有引擎任务,支付后只创建一个实例,并收到一次开通成功邮件;再验证到期前 7 天只生成一张续费账单并发送提醒、到期仅断网、宽限期内续费恢复网络,以及到期满 3 天后永久删除实例和系统盘;同时验收任务、VM 控制台、SSH、重装、救援、手动删除与图表。

@ -22,74 +22,55 @@
两种来源字段都必须等于本机 endpoint,地址 owner 接口也必须与出口接口一致;loopback、dummy、
`wg-fabric0`、VPC bridge、多路径、错误源地址或不同出口均应阻断自动放行。
## 防火墙所有权模式
每台宿主机必须精确落入下列一种模式,不能混用:
1. `native_nftables`:`nftables.service` active/enabled,firewalld unit 不存在或
inactive+masked。仅 disabled 不够,因为 D-Bus 仍可激活 firewalld。发行版 nftables
主配置只有一个 panel 受管 include。
2. `firewalld_nft`:firewalld active/enabled,`FirewallBackend=nftables`、
`NftablesTableOwner=yes`、`firewall-cmd` 可用,native `nftables.service` unit 不存在或
inactive+disabled/masked。`/etc/virt-cloud/nftables.conf` 是 root-only 的 panel
manifest,发行版 nftables 主配置不能再 include panel table。
active/enabled/masked 状态无法确定、两个服务可能同时接管、firewalld 使用非 nft 后端、
存在 source-bound zone、panel manifest 多出未知 include,或模式与已保存状态漂移时都应
fail-closed。两种模式都支持全新部署及同模式恢复;已有 VPC state、panel manifest 或未完成
journal 时切换防火墙 owner 属于维护窗口迁移,当前向导不会在线转换这些宿主级持久化对象,
也不能把一次普通 reconcile 当成迁移。
### firewalld underlay 放行
对所选公网或内网 endpoint 核验其 effective runtime zone 和持久 zone 完全一致且不为 `trusted`。
平台只能在该 zone 建立一条目标为本机 endpoint `/32`、协议 UDP、端口为 Fabric listen
port 的精确 runtime+permanent rich rule。核对以下所有权边界:
- 规则原本两处都不存在时,apply 创建两处并记录 panel-owned;回滚和 endpoint 迁移只
删除该精确旧规则。
- 两处原本都存在且内容完全一致时,视为外部规则并只复用;panel 绝不能删除。
- 只有 runtime 或只有 permanent、zone 漂移或内容不一致时拒绝继续,不能猜测所有权。
- 所选 endpoint 的物理接口、默认 route 接口和 VM 公网桥永远不能被加入 `trusted`。外部 DNAT、云
安全组和上游防火墙仍由运维显式管理;公布的 NAT 地址不是本机地址时不支持自动放行。
正常执行 `firewall-cmd --reload` 和 `systemctl restart firewalld`,确认精确 rich rule、
panel raw nft table、WireGuard/VPC 隔离在 repair timer 一个周期内恢复。不要把
`firewall-cmd --complete-reload` 当日常测试;它可能丢失运行状态并中断连接,只能在已
隔离或迁走 VM 的维护窗口单独演练。
## 防火墙所有权
每台宿主机只支持 `native_nftables`:`nftables.service` 必须
active/enabled,发行版主配置只能有一个 panel 受管 include。firewalld
unit 必须不存在或 inactive+masked,且实时规则中不得存在其所有的
`inet firewalld` table。仅 disabled 不够,因为 D-Bus 仍可重新激活它。
能力探测发现 firewalld 服务、旧 `firewalld_nft` desired state、manifest、
journal、zone/rich-rule 所有权或其他管理器冲突时必须 fail-closed。普通
apply/reconcile 不得把旧模式静默映射为 native nftables,也不得删除旧对象。
测试环境的一次性转换应先停止租户流量,备份规则与 journal,在维护窗口
清理 firewalld 及旧 panel 所有权记录,再以全新 native 方案重建。
panel-owned Fabric nft table 不负责放行 underlay UDP。管理员必须在宿主的持久
native nftables 规则或上游防火墙/云安全组中,以可证明的最窄 peer 源地址、
本机 endpoint `/32`、UDP 和 Fabric listen port 显式放行。外部 DNAT 也由运维
显式管理。执行 `systemctl reload nftables` 后必须重新核对这条 underlay 路径、
panel owner/revision/digest、Fabric/VPC table、WireGuard 双向握手及允许/拒绝流量。
单纯看到 `wg-fabric0` active 或 systemd unit green 不能证明 underlay 可达。
## AlmaLinux 10 / NetworkManager
确认 NetworkManager 是唯一网络管理器。panel 的 `virt-cloud-wg-fabric0` 和 VPC bridge
keyfile 必须位于 `/etc/NetworkManager/system-connections/`、owner 为 root、mode 为
`0600`,并设置 `connection.autoconnect=no`、不含持久 `connection.zone`;`/run`、
`/usr/lib`、in-memory/external profile 或其他 mode 不作为可持久恢复证据。两种模式都只
能在 ACL 精确回读后通过已验证的 UUID 激活接口;仅 `firewalld_nft` 模式在激活前使用
带 `--temporary` 的 `nmcli connection modify` 将 `connection.zone` 设为 `trusted`,并
精确回读 runtime zone。`native_nftables` 模式不查询、设置或要求 firewalld
zone/trusted。执行 `nmcli connection reload` 和 `systemctl restart NetworkManager`
时,接口不得先于 repair helper 自动连接;firewalld 模式不得永久进入 `trusted`,
`0600`,并设置 `connection.autoconnect=no`、不含 `connection.zone`;`/run`、
`/usr/lib`、in-memory/external profile 或其他 mode 不作为可持久恢复证据。接口只能在
nft ACL 精确回读后通过已验证的 UUID 激活,不查询、设置或要求任何
firewalld zone/trusted 状态。执行 `nmcli connection reload` 和
`systemctl restart NetworkManager` 时,接口不得先于 repair helper 自动连接,
`br0`、管理接口和默认路由不得改变。
AlmaLinux 10 的 `nmcli` 把 `FILENAME` 作为无 ID 的 `connection show` 列表字段,
不提供 `connection show uuid <UUID>` 下的 `GENERAL.FILENAME`。验收必须确认引擎
使用 `nmcli -t --escape no -f UUID,FILENAME connection show` 并按 UUID 精确、唯一
解析 keyfile;不得因为无效的 detail 字段把合法 endpoint 误报为
`firewalld_endpoint_zone_unverified`。与 endpoint 无关的 `/run`/external profile 可以单独
解析 keyfile;不得因为无效的 detail 字段拒绝合法 endpoint。与 endpoint 无关的
`/run`/external profile 可以单独
fail-closed,但不得污染已有唯一持久 keyfile 的 endpoint 接口。
分别在 native 与 firewalld 模式执行相应防火墙 reload,然后重启宿主机。记录
执行 native nftables reload,然后重启宿主机。记录
`wg show wg-fabric0`、`ip -4 route show table all`、受管 nft table/marker、默认路由和
管理地址;确认 helper 先恢复并回读 Fabric 隔离及全部 VPC inet/bridge/arp ACL,随后才
激活接口。native 模式不应出现 firewalld zone/trusted 依赖;firewalld 模式还应记录接口
runtime zone,并确认接口只在 ACL 精确回读后加入 runtime `trusted`。
激活接口。过程中不应出现 firewalld zone/trusted 依赖。
## Debian 13 / ifupdown
确认 `/etc/network/interfaces` 或 `interfaces.d` 由经典 ifupdown 管理,探测到的
`ifup`、`ifdown`、`ifquery` 路径与面板记录一致,systemd-networkd 和 NetworkManager
没有 active/enabled/configured 接管证据。panel fragment 不得包含 `auto`,同名 ifcfg
不得存在;仅 `firewalld_nft` 模式要求 permanent firewalld zone 为空。
不得存在。
`ifup --force wg-fabric0` 只能在 ACL 精确回读后运行,不能触碰 `br0`、默认路由或管理
地址。
@ -100,10 +81,9 @@ Debian 13 的 iproute2 6.15 在 WireGuard 内核模块尚未加载时,
仍必须 fail-closed。此兼容不代替 `modinfo`/模块可用性证据,也不允许引擎在只读
检测中执行 `modprobe`。
分别在 native 与 firewalld 模式执行相应 reload,并执行 `systemctl restart networking`
执行 native nftables reload,并执行 `systemctl restart networking`
和宿主机重启。确认 fragment、peer、地址、路由和受管 nft table 都由 helper 按
ACL-first 顺序恢复;native 模式不应出现 firewalld zone/trusted 依赖,firewalld 模式还
应确认 runtime `trusted` 只在 ACL 精确回读后恢复。
ACL-first 顺序恢复,且不应出现 firewalld zone/trusted 依赖。
## libvirt 启动门禁
@ -111,7 +91,7 @@ ACL-first 顺序恢复;native 模式不应出现 firewalld zone/trusted 依赖
`virtqemud.service`、`virtproxyd.service` 以及 `libvirt-guests.service`。受管
daemon drop-in 必须同时包含对 Fabric service 的 `Requires=` 与 `After=`;外部同名冲突 drop-in
应阻断 apply。分别测试普通 service 启动、socket activation 和 VM autostart,均不得在
Fabric/VPC ACL、bridge,以及 firewalld 模式的 runtime zone 恢复前开放来宾私网。
Fabric/VPC ACL 和 bridge 恢复前开放来宾私网。
socket 保留发行版默认启动顺序,其激活的 daemon 仍受上述门禁约束。不得给默认
`Before=sockets.target` 的 socket 再添加 `After=Fabric`,也不得让 Fabric `Before=socket`;
Fabric 是依赖网络的普通 service,这种顺序会通过 `basic.target` 形成启动循环。
@ -135,14 +115,15 @@ repair timer 有两个互斥且可核验的分支:主 Fabric service 明确 fa
且有效门禁完整时才可自动排队。每 daemon 每 boot 只消费一次有界、root-owned 的证据,
修复后再次回读并用 `--no-block --job-mode=fail start` 排队;缺日志、未知对象、后续手动
stop/新 job/成功/自身错误均跳过。不得用 service `Result=dependency` 判断:dependency
是 job 的结果,不是 service 的 Result。主 service 为 active、firewalld 也为 running,但受管 Fabric
或 VPC 接口缺少 runtime `trusted` 时,reconcile service 直接执行同一份带 flock 的完整
ACL-first helper。后一分支不得 restart 主 Fabric unit 或任何 libvirt unit,健康状态也
是 job 的结果,不是 service 的 Result。主 service 为 active 但受管 nft table、
Fabric 或 VPC 接口漂移时,reconcile service 直接执行同一份带 flock 的完整
ACL-first helper。该分支不得 restart 主 Fabric unit 或任何 libvirt unit,健康状态也
不得进入 helper。
在全新宿主执行 apply 后、不重启宿主机,确认事务 `committed` 后 apply 释放 flock、同步
启动独立 dispatcher,主 oneshot 最终进入 active,完整 helper 清理双 guard 后 apply 才返回
成功;再 reload/restart firewalld,确认 timer 能在首次 reboot 之前修复 runtime 漂移。
启动独立 dispatcher,主 oneshot 最终进入 active,完整 helper 证明无旧
emergency owner/table 并完成 ACL/WireGuard 回读后 apply 才返回
成功;再 reload nftables,确认 timer 能在首次 reboot 之前修复 runtime 漂移。
人为让主 helper 持有 Fabric flock,确认 dispatcher 等待期间 apply 不会持锁死锁;让同步
启动失败时,确认 committed journal 仍保留且旧进程不会删除并发新事务的 ready journal。
@ -180,7 +161,7 @@ ACL-first helper。后一分支不得 restart 主 Fabric unit 或任何 libvirt
出现一个同 ID 任务,已接纳节点不得重派,也不得生成新 ID;在终态未证明前,新 apply 必须
被拒绝、Fabric gate 必须关闭。
5. 人为卡住宿主 helper 超过 operation 运行上限,systemd 必须终止该 cgroup,状态只记录
固定的 interrupted/uncertain 原因,保留 journal/emergency guard 并禁止自动重放。
固定的 interrupted/uncertain 原因,保留 journal 与当前现场并禁止自动重放。
6. 在 Debian 13 把 `/run` 挂载为 `noexec`,确认 transient oneshot 的命令行为绝对路径
`/bin/sh /run/virt-cloud/fabric-operations/<id>/runner`,任务能进入 `host_lock` 而不是
`203/EXEC`;确认 unit 使用 `TimeoutStartSec=840s` 且没有无效的 `RuntimeMaxSec=`。
@ -192,34 +173,31 @@ ACL-first helper。后一分支不得 restart 主 Fabric unit 或任何 libvirt
## 失败回滚和安全边界
保留同计划的 `ready` journal 和历史 `helper.present`:即使历史 helper 不支持新版
NetworkManager runtime shadow,也只能在旧 helper 与 journal pre/post-image 精确一致、
meta 中 digest/UUID/manager/firewall/underlay 全部绑定当前方案、当前临时 helper 的权限与
计划头核验后,交由当前实现恢复。恢复完成的 recovery-only 调用不得再次执行已恢复的
旧 helper。跨计划仍沿历史恢复合同,不得把旧计划的权限移交给新模板;外部文件/密钥/nft
保留同计划的 `native_nftables` `ready` journal 和历史 `helper.present`:只能在旧 helper
与 journal pre/post-image 精确一致、meta 中 digest/UUID/manager/firewall 全部绑定
当前方案,且 underlay 由当前 plan/helper digest 间接绑定时,才能在核验
当前临时 helper 的权限与计划头后,交由当前实现恢复。恢复完成的 recovery-only
调用不得再次执行已恢复的旧 helper。任何 `firewalld_nft` journal 及其 snapshot 不进入此
恢复路径;标记为 native 但仍携带已退役 `firewalld_*`/`underlay_*` 字段的旧 schema
也只保留现场并进入维护清理。跨计划不得把旧计划的权限移交给新模板。外部文件/密钥/nft
漂移必须保留现场并拒绝。新增 timer 必须在 `state=committed` 同步落盘之后才启动,
timer 启动失败只能保留 committed journal,不能回滚已提交的数据面。
在隔离环境中分别让 `nft -c/-f`、`firewall-cmd`、`wg`、`ip route`、
在隔离环境中分别让 `nft -c/-f`、`wg`、`ip route`、
`nmcli/ifup`、systemd gate 和 timer 返回失败。每次都应看到 apply 失败并保持
`uncertain/degraded`;firewalld 模式的回滚先撤销 panel 接口的 runtime `trusted`,再以
单次 nft batch 恢复旧 Fabric/VPC table,精确回读后才能重加原 trusted 状态。
panel-owned peer、地址、
路由、profile/fragment、rich rule、manifest/include 和 systemd 状态必须按快照恢复;
`uncertain/degraded`。panel-owned peer、地址、路由、profile/fragment、
manifest/include 和 systemd 状态必须按快照恢复;
无法恢复时不得报告 active。
分别在 emergency guard owner intent 写入后、nft 安装前、安装后、manifest refresh 前后
中断进程并重跑;每次只能在随机 token、完整 shape 和 snapshot 全部匹配时继续。随后在没有
任何 VPC state、manifest 或未完成 journal 的空宿主上,把一次前置门禁失败的
`firewalld_nft` 尝试纠正为 `native_nftables`:native 必须接管遗留 guard、保持隔离直到
Fabric/WireGuard/route/path 全部回读,再清理 guard;owner-only 可以在证明 table 不存在后
清理,table-only、token 漂移或伪造的同名 table 必须拒绝且不得删除。若宿主已有任一 VPC
state,即使它仍是合法 native state,也必须保留 guard 并进入维护迁移,不能用 owner comment
数量代替三族 VPC ACL 的完整语义证明后解除隔离。
分别在 snapshot/journal 写入后、nft 预检前、原子 batch 提交前后和 manifest refresh
前后中断进程并重跑;每次只能在 owner、完整 shape、snapshot 和现场回读全部匹配时继续。
预先放置旧 emergency owner/table、`firewalld_nft` owner/manifest/journal 或 `inet firewalld`
table,确认普通
apply/reconcile 拒绝并保留现场;不得用新 native desired state 覆盖或清理它们。
让 `bridge link show master` 失败或返回畸形、重复、超过上限的端口记录,并模拟
`ip link set down` 返回成功但 NetworkManager 立即把 bridge 恢复为 `UP`。boot/apply 均
必须 fail-closed、保留 bridge/tap 端口关系且不得移除 emergency guard 或提前恢复 trusted。
必须 fail-closed、保留 bridge/tap 端口关系,不得继续改写 nft 或提前恢复流量。
预先放置非 panel-owned 同名 nft table、宽前缀路由、策略表路由、同名接口或冲突
systemd drop-in,apply 必须拒绝并保留原状态。最后从其他宿主机核验 WireGuard UDP、

@ -53,12 +53,12 @@ Debian 13 只接受 `apt`、经典 ifupdown/ifupdown2 共有的
NetworkManager、systemd-networkd、ifupdown 同时运行、开机启用或持有配置时
一律标为冲突并拒绝私网变更;持有配置包括 NetworkManager keyfile、
systemd-networkd 的 `.network/.netdev` 文件以及 ifupdown 的 interfaces 文件。
防火墙只接受两个互斥且可证明的所有权模式:native `nftables.service`
active/enabled,且 firewalld unit 不存在或 inactive+masked;或 firewalld
active/enabled、`FirewallBackend=nftables`、`NftablesTableOwner=yes`,且 native
`nftables.service` unit 不存在或 inactive+disabled/masked。仅 disabled 的 firewalld
仍可能被 D-Bus 激活,不能归入 native 模式。混合、未知、source-bound firewalld zone
和当前/持久 zone 漂移均 fail-closed。探测只识别现状,不在租户请求中安装包、加载
防火墙只接受 `native_nftables` 所有权:`nftables.service` 必须
active/enabled,firewalld unit 必须不存在或 inactive+masked,且实时规则中
不得存在 `inet firewalld` table。仅 disabled 的 firewalld 仍可能被 D-Bus
激活,不能归入 native 模式。任何旧 `firewalld_nft` desired state、manifest、
journal、zone/rich-rule 所有权或其他管理器冲突都 fail-closed;普通
apply/reconcile 不做静默映射或自动接管。探测只识别现状,不在租户请求中安装包、加载
模块或修改规则。缺少能力时旧公网 VM 路径仍可保存宿主机,但 VPC 控制器
必须要求 `vpc_ready=true`,否则拒绝创建或变更私网。
@ -91,7 +91,7 @@ active/enabled、`FirewallBackend=nftables`、`NftablesTableOwner=yes`,且 nat
VPC reconciler 单独管理。私网 libvirt 网卡在该阶段只接受已核验的独立
bridge/tap/device 来源,不接受无法确认底层桥接的 `network=` 间接来源;公网
nwfilter 与私网 ACL 永远是两套策略上下文。WireGuard 能力探测通过不改变系统的命令完成,
真正的 AlmaLinux/Debian 部署、SELinux/firewalld 共存和跨宿主机连通性仍须
真正的 AlmaLinux/Debian 部署、SELinux/native nftables 持久化和跨宿主机连通性仍须
在验收环境验证。
当前阶段已增加引擎全局 Fabric 控制面。管理员页面按地区展示宿主机 readiness,正常
@ -153,8 +153,8 @@ systemd 以绝对路径 `/bin/sh` 解释 runner,runner/update/apply 的内部
`/run` 文件,从而兼容宿主把 `/run` 挂载为 `noexec`;oneshot 用 `TimeoutStartSec` 约束完整
任务,不使用对 `Type=oneshot` 无效的 `RuntimeMaxSec`。
SSH 只负责精确 ID 的 dispatch/status 协议;任务 stdout/stderr 不返回面板,journal 只记录
operation ID、固定 state、checkpoint 和 reason。运行时间有上限,中断保留事务日志与
emergency guard;远端 operation 目录有严格 owner/mode/hash 校验和有界终态清理,不删除
operation ID、固定 state、checkpoint 和 reason。运行时间有上限,中断保留事务日志和当前现场
并禁止自动重放;远端 operation 目录有严格 owner/mode/hash 校验和有界终态清理,不删除
queued/running 或无法证明归属的对象。
Engine 重启或 dispatch 回包丢失时,页面 GET 与周期 reconcile 只使用原 operation ID
@ -231,44 +231,38 @@ apply 会先保存 panel-owned 配置、WireGuard peer/地址/路由、systemd
nftables 规则保存为 root-only 的
`/etc/nftables.d/virt-cloud-wg-fabric.nft`。native 模式要求 Debian 的
`/etc/nftables.conf` 或 AlmaLinux 的 `/etc/sysconfig/nftables.conf` 存在唯一受管
include;firewalld+nft 模式不修改发行版 nftables 主配置,而使用
`/etc/virt-cloud/nftables.conf` 的受限 manifest,由 Fabric helper/timer 在 firewalld
之后原子恢复受管 Fabric/VPC table。两种模式的规则均带 owner 和 digest;helper 校验
归属、结构、revision 和完整 include 集合,不把 raw nft 规则写入 firewalld direct
接口,也不执行会重载所有 zone 的全局 firewalld reload。
firewalld 模式的 underlay 只允许本机真实 endpoint:普通路由及显式 `from endpoint`
路由都必须返回唯一且相同的地址归属接口,并选择该 endpoint 作为源地址;运行态与持久
effective zone 必须一致且不得为 `trusted`。
平台只维护该 zone 内目标为本机 endpoint `/32`、协议 UDP、固定监听端口的精确
runtime+permanent rich rule;已有的完全相同外部规则只复用不删除,半存在或发生漂移则
fail-closed。平台不会信任所选 endpoint 的物理接口,也不代替云安全组、上游防火墙或外部 DNAT;
NAT 后公布的非本机地址仍需外部显式管理,不能走自动 firewalld 放行。
两种模式的 NetworkManager profile 都不写持久 zone、禁止 autoconnect,ifupdown
fragment 都不写 `auto`。`native_nftables` 不查询、设置或要求 firewalld zone/trusted;
仅 `firewalld_nft` 要求永久 zone 为空,并让 `wg-fabric0` 与 VPC 私网 bridge 使用可恢复的
runtime `trusted`,激活时按已核验 UUID 使用 temporary zone。helper 必须先在单次原子
nft transaction 恢复并回读 Fabric 隔离和全部 VPC inet/bridge/arp ACL,再激活接口;仅
firewalld 模式随后加入 runtime `trusted`,异常与回滚先撤销 trust。panel-owned systemd
include。规则均带 owner 和 digest;helper 校验归属、结构、revision 和完整 include
集合。发现旧 firewalld manifest、journal、zone/rich-rule 所有权或 `inet firewalld`
table 时保留现场并拒绝普通 apply/reconcile,不会继续写规则。
underlay 只允许本机真实 endpoint:普通路由及显式 `from endpoint` 路由都必须
返回唯一且相同的地址归属接口,并选择该 endpoint 作为源地址。
panel-owned Fabric nft table 不放行 underlay UDP;管理员必须在宿主持久 native nftables
规则或上游云安全组/防火墙中,以最窄可证明的 peer 源地址、本机 endpoint
`/32`、UDP 和固定监听端口显式放行。外部 DNAT 也由运维管理;本地接口 active
或 unit green 不能代替双向 WireGuard 握手和实际流量验收。
NetworkManager profile 不写 zone、禁止 autoconnect,ifupdown fragment 不写 `auto`。
helper 必须先在单次原子 nft transaction 恢复并回读 Fabric 隔离和全部 VPC
inet/bridge/arp ACL,再激活接口,不查询、设置或要求任何 firewalld
zone/trusted 状态。panel-owned systemd
gate 同时约束已安装的 libvirt/
virtqemud/virtproxyd service 与 socket,避免 socket activation 或 VM autostart 在 ACL
恢复前开放私网。公网/内网 endpoint 实际可达、NAT、MTU、SELinux、正常 firewalld/
恢复前开放私网。公网/内网 endpoint 实际可达、NAT、MTU、SELinux、native nftables/
NetworkManager/ifupdown 重启以及宿主机重启后的恢复仍属于真实宿主机验收项。Fabric
只使用独立的 `wg-fabric0`;管理器适配不得修改 `br0`、默认路由或宿主机管理接口。
repair timer 在主 Fabric service 明确 failed 时只重新排队该主 service,并只附带此前
确因 dependency 失败的 libvirt 单元;若主 service 为 active 且核验到 firewalld 重启
造成的受管 runtime trusted 漂移,则 reconcile service 直接执行同一份带 flock 的完整
确因 dependency 失败的 libvirt 单元;若主 service 为 active 且核验到受管 nft table
或接口漂移,则 reconcile service 直接执行同一份带 flock 的完整
ACL-first helper,不 restart 主 Fabric unit 或 libvirt。两条分支都保证完整 helper 每轮
最多执行一次,健康状态不触发修复。
firewalld 事务在读取可变 profile、zone、manifest 或 VPC state 前先建立独立 emergency
nft guard。guard 使用每次事务随机 token,并由 `/run/virt-cloud` 下 root-only owner
intent 与完整 stateless snapshot 共同证明所有权;同名 table 缺少 intent、token/规则
漂移或回读不完整时一律保留现场且拒绝删除。空宿主把一次失败的 firewalld 前置尝试纠正为
native 后,native helper 只能接管并最终清理由上述证据完整证明的遗留 guard,不会在正常
native 路径创建额外 table;一旦存在任何 VPC state、firewalld manifest 或未完成 journal,
跨 owner 切换必须 fail-closed 并进入单独的维护迁移,当前 reconcile 不改写这些持久状态。
受管 nft 事务使用完整 stateless snapshot、阶段 journal、`nft -c` 预检、最后一次
precommit 回读和单次原子 `nft -f` batch 保护现有数据面;任何所有权、snapshot
或回读不完整都保留现场并 fail-closed。旧 emergency owner/table 以及
firewalld owner/manifest/journal 都只是遗留检测证据,不是当前事务机制;它们
只能在事先备份且已停止租户流量的维护窗口由运维显式清理;当前 reconcile
不改写这些持久状态。
nft journal 明确记录 mutation/install/refresh 阶段,崩溃点恢复会重新核验 live table,而
不是根据上一条命令返回值推断提交完成。
@ -277,8 +271,8 @@ bridge 命令失败、畸形/重复/超量输出或端口集合变化,并在 `
`UP` flag 已消失。这样 NetworkManager 竞态不能越过 hard quarantine,同时不需要停用
bridge profile 或拆除正在运行 VM 的 tap。首次 apply 在 durable transaction commit 后释放
flock,再同步启动独立 reconcile dispatcher;dispatcher 等待 `RemainAfterExit` oneshot,
或在主 unit 已 active 时直接执行同一份完整 helper。apply 重新持锁并确认 helper 已清理
双 guard、主 service/timer active 及当前 digest/ACL/WireGuard 均匹配后才返回成功;提交态
或在主 unit 已 active 时直接执行同一份完整 helper。apply 重新持锁并确认不存在旧
emergency owner/table,且主 service/timer active 及当前 digest/ACL/WireGuard 均匹配后才返回成功;提交态
旧进程不删除共享 journal,使 repair timer 在首次重启前也有可恢复、可核验的状态。
受管 nft 事务以完整 stateless snapshot、`nft -c` 后的最后 precommit 回读、单次原子
@ -389,9 +383,9 @@ fail closed,不能回退接受仅有 XML 的旧 succeeded receipt。
且完成资源不存在性证明后才清理 journal。PHP
只在每台宿主机的 XML、路由、ACL、反欺骗、代理 ARP、rp_filter 和完整 peer
AllowedIPs 证据都匹配当前 revision/digest 后才把 VPC 标为 `active`。
在 firewalld 模式中,VPC apply/remove/rollback/启动恢复先隔离 runtime trusted,再以
单次 nft batch 建立或恢复受管 table;只有全部 ACL marker/digest 精确回读后才能重新
激活 bridge 和 trust。NetworkManager 或 ifupdown 重启不会依赖 profile 自动连接来绕过
VPC apply/remove/rollback/启动恢复以单次 nft batch 建立或恢复受管 table;
只有全部 ACL marker/digest 精确回读后才能重新激活 bridge。NetworkManager 或
ifupdown 重启不会依赖 profile 自动连接来绕过
该顺序;libvirt daemon service 受 Fabric gate 约束,socket activation 触发的仍是
同一个受门禁的 daemon。socket 保留默认早期启动顺序,避免与网络依赖形成循环。
@ -441,7 +435,7 @@ VPC,以及未释放或仍有 claim 的私网 reservation,避免独立 VPC wo
租户计划。
AlmaLinux 10 与 Debian 13 的 WireGuard/NetworkManager/ifupdown 能力、真实宿主机
路由、SELinux/firewalld、MTU 和跨机房连通性尚未在本地环境宣称通过;必须完成
路由、SELinux/native nftables 持久化、MTU 和跨机房连通性尚未在本地环境宣称通过;必须完成
上述 Fabric 与 VPC 宿主机验收矩阵后,才能把环境状态推进为可上线。
PHP 不直接解密 Python 记录或执行任意 virsh 命令。主库与日志库可同实例或分别配置地址/端口。敏感业务数据加密;部署数据库连接配置仍是权限受限配置文件,不代表配置文件本身加密。

@ -1,5 +1,24 @@
# 本版验证记录
## 2026-10-10:firewalld 支持退役
- 当前 Fabric/VPC 宿主机只支持 `native_nftables`。能力探测只在
`firewall_manager=nftables` 且 `firewall_mode=native_nftables` 时允许 readiness。
旧 `firewalld_nft` 输入、manifest、journal、zone/rich-rule 所有权或实时
`inet firewalld` table 必须 fail-closed,不得在普通 apply/reconcile 中静默
映射、接管或删除。
- PHP readiness 边界会再次核验原生 nftables 模式;即使旧 Engine 将
`firewalld_nft` 回报为 ready,页面也必须关闭写入并显示维护迁移阻断。
- 本次本地已通过 `admin-fabric.js` 语法检查、
`AdminFabricWizardBehaviorTest.mjs` 前端行为回归及 `git diff --check`。
当前工作区没有 PHP CLI 且没有 `web/vendor/autoload.php`,因此本地未能
执行 PHP lint 和 PHP 合同/readiness 测试;发布前必须在完整 PHP 依赖环境补跑。
- 本节之后仍出现的 firewalld 段落只是 2026-10-08/09 的历史实测与旧实现
记录,不表示当前仍支持该模式,也不能作为新部署验收依据。
- 仍需在 AlmaLinux 10 和 Debian 13 验证 native nftables apply/readback、reload、
restart/reboot、WireGuard 握手、VPC 允许/拒绝流量及失败回滚;本地静态
回归不代替这些真机证据。
## 2026-10-09:严格 NM shadow 恢复与丢失回执只读查询
- Fabric 的共享 NM 归属检查只新增对固定 runtime shadow 的支持:持久/临时
@ -217,7 +236,7 @@
因而 `AdminFabricReadinessWorkflowTest.php` 仅完成语法检查,未执行数据库流程;该测试必须在
部署端完整 Composer dev 依赖与 PDO SQLite 环境复跑。
- 尚未连接真实 Debian 13 / AlmaLinux 10 宿主机验证 SSH 断线、transient unit、journal、重启、
NetworkManager/ifupdown 及 firewalld/native nftables。部署后必须用页面显示的同一 ID 查询
NetworkManager/ifupdown 及 native nftables。部署后必须用页面显示的同一 ID 查询
`journalctl --utc -u virt-cloud-fabric-apply-<operation_id>.service --no-pager -o short-iso-precise`,
并完成双宿主 WireGuard 握手、跨宿主 VPC 流量和重启恢复后,才能认定生产组网验收完成。
@ -246,7 +265,7 @@
不涉及本次探针代码。
- 上述现场输出是修复输入,不代表新版本已经在宿主机验收。部署本提交后仍须重新点击
“检测宿主机”,确认两个旧阻断消失;随后执行地区自动配置、WireGuard 握手、跨宿主流量、
firewalld/NetworkManager reload 与重启恢复验收,才能认定生产组网完成。
native nftables/NetworkManager reload 与重启恢复验收,才能认定生产组网完成。
## 2026-10-09:Fabric canonical nft 回读与首装事务恢复
@ -276,11 +295,11 @@
3 个公网池 fixture,均不在本次 Fabric 改动范围。`git diff --check`、生产/测试 Python
`py_compile` 与最终只读源码审计通过。上述静态与本地回归不替代真实宿主机验收;部署后
仍须证明 journal/emergency guard 收敛、两台主机 WireGuard 握手、跨宿主 VPC 流量
以及 firewalld/native reload 与重启恢复。
以及 native nftables reload 与重启恢复。
## 2026-10-08:公网优先 underlay 与 firewalld+nft 兼容
## 2026-10-08:公网优先 underlay 与已退役 firewalld+nft 实验
- Fabric/VPC 现在只接受两个互斥模式:native nftables 要求
- 当时的 Fabric/VPC 实验曾接受两个互斥模式:native nftables 要求
`nftables.service` active/enabled 且 firewalld 不存在或 inactive+masked;
firewalld 模式要求 active/enabled、nft backend、`NftablesTableOwner=yes`,native
nftables unit 则只能不存在或 inactive+disabled/masked。能力探针不会查询 inactive
@ -342,7 +361,7 @@
VPC 创建和 CIDR
allocator 回归、Fabric Node 行为测试、两份 JavaScript 语法检查及 `git diff --check`
通过。
- 这些结果没有替代真实宿主机验收。AlmaLinux 10、Debian 13、firewalld/nftables reload、
- 这些结果没有替代真实宿主机验收。AlmaLinux 10、Debian 13、native nftables reload、
NetworkManager/ifupdown 重启、libvirt socket activation、宿主重启、跨宿主 WireGuard
握手、MTU、SELinux、外部 NAT/安全组和允许/拒绝流量仍须按验收矩阵执行。
- nft CLI 不提供跨进程 CAS。本轮以完整 stateless snapshot、`nft -c` 后的最后
@ -378,7 +397,7 @@
关系相同”的正常路径,并覆盖实例 pool pin 不一致、多条 live membership、
pool/line/region 断链与跨地区拒绝。本轮 Engine Fabric/VPC/边界回归 `268 passed`,
21 个聚焦 PHP 测试脚本、7 个变更 PHP 文件语法检查和管理员 Fabric Node.js 行为测试
通过。开发环境仍未替代真实多宿主 WireGuard、nftables/firewalld、libvirt 和重启恢复验收。
通过。开发环境仍未替代真实多宿主 WireGuard、native nftables、libvirt 和重启恢复验收。
- 扩大探测仍命中未修改的既有测试问题:`SourceSyntaxTest` 被
`AdminSystemLogsContractTest.php` 的双引号插值语法错误阻断;
`CloudEngineReadinessTest` 保留了已过时的静态次数断言;`CloudProtocolTest` 未导入
@ -418,7 +437,7 @@
ID/lease/phase。映射提交前已在长网络操作后重读拓扑,并在事务中锁地区、映射和 live
VPC;跨全部库存写路径的 topology generation/CAS 仍是后续并发强化项。
- 开发环境没有连接真实多宿主 SSH、
WireGuard、nftables/firewalld 或 libvirt,生产部署仍须执行 Fabric 宿主机验收矩阵。
WireGuard、native nftables 或 libvirt,生产部署仍须执行 Fabric 宿主机验收矩阵。
## 2026-10-08:管理员地区宿主机 readiness 与自动组网
@ -452,9 +471,9 @@
detail envelope 和 3 个公网池 fixture;本轮 Fabric/readiness 与 Engine boundary 没有
新增失败。
- 当前未连接真实 PHP-FPM、MariaDB、浏览器或 SSH/libvirt 多宿主机。生产验收仍须覆盖
WireGuard 握手、UDP/51820 underlay、MTU、SELinux、受支持的 native nftables 或
firewalld+nft 持久化、网络/防火墙重启修复和跨宿主机租户流量。两种防火墙模式必须
互斥;不受支持或所有权不明确的组合继续 fail-closed,不能直接清空生产防火墙。
WireGuard 握手、UDP/51820 underlay、MTU、SELinux、native nftables 持久化、
网络/防火墙重启修复和跨宿主机租户流量。不受支持或所有权不明确的组合
继续 fail-closed,不能直接清空生产防火墙。
反代与 PHP-FPM 请求终止/读超时建议至少 270 秒。
## 2026-10-08:租户单自动子网与创建页简化
@ -529,7 +548,7 @@ HAVING live_subnets <> 1 OR deleting_subnets <> 0;
- SQLite 不实现 MariaDB 的 `SELECT ... FOR UPDATE` 并发语义;上线前仍须在隔离 MariaDB
上并发争抢账户最后一个名额、并发同 key 丢响应重试,并核对最终仅有一条 root、network、
claim 和 create operation。当前未连接真实数据库、PHP-FPM、浏览器或宿主机,也未改变
WireGuard/libvirt/firewalld 数据面。额外全仓 `SourceSyntaxTest` 仍被未修改的
WireGuard/libvirt 宿主数据面。额外全仓 `SourceSyntaxTest` 仍被未修改的
`AdminSystemLogsContractTest.php:108` 既有解析错误阻断,不归因于本轮 VPC 修改。
## 2026-10-08:VPC 来宾网络启动代次门禁

@ -18,12 +18,13 @@
- AlmaLinux 10 只有 NetworkManager/nmcli 处于 active/enabled,Debian 13 只有
ifupdown 的 `ifup`、`ifdown`、`ifquery` 和 `/etc/network/interfaces`(含已加载
的 `interfaces.d`)作为网络管理来源;
- 防火墙精确处于 Fabric 已确认的 `native_nftables` 或 `firewalld_nft` 模式,不能混合;
native 模式的持久主配置只有一个受管 include,firewalld 模式则只有 root-only panel
manifest,且精确 underlay rich rule 的 panel/external 所有权已回读;
- NetworkManager profile 不 autoconnect、不写持久 zone;ifupdown fragment 不含 `auto`。
native 模式不查询、设置或要求 firewalld zone/trusted;仅 firewalld 模式让
`wg-fabric0` 和 VPC bridge 使用 runtime `trusted`,endpoint/管理接口绝不 trusted;
- 防火墙精确处于 Fabric 已确认的 `native_nftables` 模式;
`nftables.service` active/enabled,持久主配置只有一个受管 include,
firewalld 不存在或 inactive+masked,且没有遗留 `inet firewalld` table。任何旧
`firewalld_nft` desired/manifest/journal 都必须阻断普通 reconcile,不得自动迁移;
- NetworkManager profile 不 autoconnect、不写 zone;ifupdown fragment 不含 `auto`。
`wg-fabric0` 和 VPC bridge 只在受管 nft ACL 精确回读后激活,不依赖任何
firewalld zone/trusted 状态;
- Fabric 公网或内网 endpoint 均不位于全局租户 VPC CIDR 池,且当前 VPC CIDR 不包含
任一 Fabric endpoint;否则目的策略路由会吸走 WireGuard underlay,必须在 apply 前阻断;
`/etc/virt-cloud`、`/run/virt-cloud`、`/etc/nftables.d` 和 `sysctl.d` 不是符号链;
@ -76,19 +77,18 @@
## 管理器和重启矩阵
AlmaLinux 10:执行 `nmcli connection reload`、`systemctl restart NetworkManager` 和
宿主机重启;native 模式另执行 `systemctl reload nftables`,firewalld 模式执行正常
`firewall-cmd --reload` 与 `systemctl restart firewalld`。每一步都要确认 private bridge
AlmaLinux 10:执行 `nmcli connection reload`、`systemctl restart NetworkManager`、
`systemctl reload nftables` 和宿主机重启。每一步都要确认 private bridge
没有靠 autoconnect 抢先启动,helper 先恢复并回读 nft inet/bridge/arp ACL,再按 UUID
激活 profile;仅 firewalld 模式随后加入 runtime `trusted`,native 模式不应出现
firewalld zone/trusted 依赖;随后 route/rule、proxy ARP、WireGuard peer、
激活 profile;过程不应出现 firewalld zone/trusted 依赖;随后
route/rule、proxy ARP、WireGuard peer、
`ua-private0` XML 和默认公网路径恢复,NetworkManager 没有接管 `br0` 或管理接口。
Debian 13:执行 `ifquery <private-bridge>`、`systemctl restart networking` 和宿主机
重启;native 模式另执行 `systemctl reload nftables`,firewalld 模式执行正常 reload/
restart。确认不含 `auto` 的 `interfaces.d` fragment 不能让 bridge 绕过 helper 抢先启动,
ACL 精确回读后才执行 `ifup --force`;仅 firewalld 模式随后恢复 runtime `trusted`,
native 模式不应出现 firewalld zone/trusted 依赖;随后 route/rule、proxy ARP、WireGuard
重启,并执行 `systemctl reload nftables`。确认不含 `auto` 的 `interfaces.d`
fragment 不能让 bridge 绕过 helper 抢先启动,ACL 精确回读后才执行
`ifup --force`,且不应出现 firewalld zone/trusted 依赖;随后 route/rule、
proxy ARP、WireGuard
peer 和 `ua-private0` XML 恢复。严禁用 ifdown 操作 `br0` 或管理接口。
两种发行版都要分别测试 libvirt service、socket activation 和 VM autostart。实际存在的
@ -104,12 +104,12 @@ peer 和 `ua-private0` XML 恢复。严禁用 ifdown 操作 `br0` 或管理接
- apply、实例接入和停机 libvirt 变更失败时,原 panel-owned bridge、route/rule、
peer AllowedIPs、nft 表/include、proxy 项、sysctl、XML 和 seed 按快照恢复;
- firewalld 模式的 apply/remove/rollback/journal 恢复必须先撤销 panel 接口的 runtime
trusted,再以单次 nft batch 建立或恢复受管 table;只有 marker/digest 精确回读后才
能重新激活接口并恢复 trust,不能用分离的 table delete/load 暴露无 ACL 窗口;
- apply/remove/rollback/journal 恢复必须以单次 nft batch 建立或恢复受管
table;只有 marker/digest 精确回读后才能重新激活接口,不能用分离的
table delete/load 暴露无 ACL 窗口;
- boot 对 panel-owned bridge 执行 hard quarantine 时,必须在 down 前后严格核对有界端口
快照并回读确认 `UP` flag 消失;bridge 命令/解析失败、端口变化或 NetworkManager 竞态
重新拉起接口都必须保留 emergency guard 并停止恢复,不能靠停用 profile 拆除 tap;
重新拉起接口都必须停止恢复且不得继续改写 nft,不能靠停用 profile 拆除 tap;
- 删除/撤销路径使用阶段 journal 和 fail-closed 收敛:未提交的 journal 在回读前
返回 `uncertain/manual_reconcile` 并保留现场,不重复执行破坏性删除;只有已经
提交且能证明面板资源全部不存在的 journal 才会被清理。因此删除路径的“回滚”
@ -122,9 +122,10 @@ peer 和 `ua-private0` XML 恢复。严禁用 ifdown 操作 `br0` 或管理接
- 重试只依据新的完整宿主机回读,不对不确定的 libvirt 或网络变更盲目反向执行。
跨宿主机最后还要单独验证 underlay 公网防火墙、NAT、MTU、SELinux 和 UDP 监听。
firewalld 的本机精确 rich rule 也不能替代外部 DNAT/云安全组;Fabric/VPC 的本地 nft
表不等于端到端 underlay 已放行。`firewall-cmd --complete-reload` 只在隔离或迁走 VM 的
维护窗口演练,不能作为普通在线 reload 验收。
Fabric/VPC 的 panel-owned nft 表不负责放行 underlay UDP;运维必须在宿主
持久 native nftables 规则或上游云安全组/防火墙中,以精确 peer 源地址、
本机 endpoint `/32`、UDP 和 Fabric 监听端口放行。还需单独核对外部 DNAT,
并用双向握手和实际流量验收;接口 active 或 unit green 不能证明端到端可达。
## 发布和规模边界

File diff suppressed because it is too large Load Diff

@ -1,7 +1,7 @@
"""Execute the production-rendered final readback with real CLI serialization.
Only external tools are replaced. The final shell body, nft owner checks,
tenant-set matcher and firewall-zone enumerator are the production code.
Only external tools are replaced. The final shell body, nft owner checks and
tenant-set matcher are the production code.
"""
from __future__ import annotations
@ -15,10 +15,10 @@ import sys
import pytest
from virsh_panel.fabric import (
FIREWALL_MODE_NATIVE,
_FABRIC_NFT_VALIDATION_SH,
_FABRIC_WG_READBACK_SH,
_BOOT_HELPER,
_FIREWALL_MODE_GUARD_SH,
_TRANSACTION_SCRIPT,
_VPC_STATE_LOADER,
_apply_script,
@ -79,11 +79,11 @@ class FinalFixture:
tool = tmp_path / "tool"
tool.write_text(f"#!{sys.executable}\n" + _TOOLS, encoding="utf-8")
tool.chmod(0o700)
for name in ("ip", "wg", "nft", "firewall-cmd"):
for name in ("ip", "wg", "nft"):
(tmp_path / name).symlink_to(tool)
(tmp_path / "private").write_text("test-only-private-identity\n")
(tmp_path / "config").write_text(_config_text(
self.plan, self.plan.nodes[0], self.keys, "firewalld_nft"))
self.plan, self.plan.nodes[0], self.keys, FIREWALL_MODE_NATIVE))
for filename in ("vpc-peers", "vpc-routes", "vpc-tenants"):
(tmp_path / filename).write_text("")
@ -129,15 +129,6 @@ class FinalFixture:
"from", "100.64.1.1"],
node.overlay_ip + " from 100.64.1.1 dev wg-fabric0 uid 0\n"
" cache\n")
for permanent in (False, True):
prefix = ["--permanent"] if permanent else []
self.respond("firewall-cmd", prefix + ["--get-zones"], "public trusted\n")
for zone in ("public", "trusted"):
active = not permanent and zone == "trusted"
self.respond("firewall-cmd", prefix + [f"--zone={zone}",
"--query-interface=wg-fabric0"],
"yes\n" if active else "no\n", 0 if active else 1)
def respond(self, tool: str, args: list[str], stdout: str, status: int = 0):
self.responses[json.dumps([tool, *args])] = {
"stdout": stdout, "status": status,
@ -162,7 +153,7 @@ class FinalFixture:
def run(self):
rendered = _apply_script(
self.plan, self.plan.nodes[0], self.keys,
deployment_mode=self.manager, firewall_mode="firewalld_nft")
deployment_mode=self.manager, firewall_mode=FIREWALL_MODE_NATIVE)
final = _between(rendered, "vc_fabric_operation_checkpoint final_readback\n",
"_txn_state_tmp=$(mktemp")
final = final.split("\n", 1)[1]
@ -173,12 +164,10 @@ class FinalFixture:
_between(_VPC_STATE_LOADER, "vpc_state_allowed_for_peer() {",
"vpc_state_route_owned() {"),
_VPC_STATE_LOADER[_VPC_STATE_LOADER.index("vpc_state_nft_set_matches() {"):],
_between(_FIREWALL_MODE_GUARD_SH, "vc_firewall_zone() {",
"vc_firewall_zone_exists() {"),
))
env = {**os.environ, "VC_FINAL_ROOT": str(self.root),
"IFACE": "wg-fabric0", "EXPECTED_DIGEST": self.plan.digest,
"FIREWALL_MODE": "firewalld_nft",
"FIREWALL_MODE": FIREWALL_MODE_NATIVE,
"MANAGED_PEERS": " ".join(self.keys[n.host_id] for n in self.plan.nodes[1:]),
"MANAGED_ROUTES": " ".join(n.allowed_ip for n in self.plan.nodes[1:]),
"KEY": str(self.root / "private"), "CONF": str(self.root / "config"),
@ -186,8 +175,7 @@ class FinalFixture:
"VPC_ROUTE_FILE": str(self.root / "vpc-routes"),
"VPC_TENANT_FILE": str(self.root / "vpc-tenants")}
env.update({name: str(self.root / tool) for name, tool in (
("WG", "wg"), ("IP", "ip"), ("NFT", "nft"),
("FIREWALL_CMD", "firewall-cmd"))})
("WG", "wg"), ("IP", "ip"), ("NFT", "nft"))})
(self.root / "responses").write_text(json.dumps(self.responses))
result = subprocess.run(["/bin/sh", "-eu", "-c", functions + "\n" + final],
capture_output=True, text=True, env=env, check=False)
@ -210,7 +198,7 @@ def test_actual_final_slice_accepts_debian_and_alma_serialization(tmp_path, mana
@pytest.mark.parametrize("drift", ["nft", "public-key", "listen-port", "down", "address",
"extra-peer", "endpoint", "allowed", "route", "path", "zone"])
"extra-peer", "endpoint", "allowed", "route", "path"])
def test_actual_final_slice_rejects_mutable_readback_drift(tmp_path, drift):
fixture = FinalFixture(tmp_path, "ifupdown")
key = fixture.keys["2"]
@ -237,8 +225,6 @@ def test_actual_final_slice_rejects_mutable_readback_drift(tmp_path, drift):
elif drift == "path":
fixture.respond("ip", ["route", "get", "100.64.1.2", "from", "100.64.1.1"],
"100.64.1.2 from 100.64.1.1 dev br0 uid 0\n cache\n")
else:
fixture.respond("firewall-cmd", ["--zone=trusted", "--query-interface=wg-fabric0"], "no\n", 1)
result = fixture.run()
assert result.returncode in (71, 78), result.stderr

@ -36,7 +36,7 @@ def _write(path: Path, body: str, mode: int = 0o700):
path.chmod(mode)
def _render(manager="ifupdown", firewall="firewalld_nft"):
def _render(manager="ifupdown", firewall="native_nftables"):
plan = parse_fabric_plan({
"fabric_id": "safe-log-test", "region": "hk",
"overlay_cidr": "100.64.1.0/24", "revision": 1,
@ -82,7 +82,7 @@ def _journal_wrapper(body):
@pytest.mark.parametrize("detail", [
"entry", "final_acl", "final_tenants", "final_identity", "final_link",
"final_addresses", "final_peers", "final_endpoints", "final_allowed_ips",
"final_routes", "final_overlay_paths", "final_zone", "commit", "convergence",
"final_routes", "final_overlay_paths", "commit", "convergence",
"complete",
])
def test_rendered_apply_logger_has_one_fixed_fd3_record(detail):
@ -217,9 +217,8 @@ def test_first_apply_failure_precedes_secondary_rollback_cleanup_record(tmp_path
@pytest.mark.parametrize("manager", ["ifupdown", "networkmanager_nmcli"])
@pytest.mark.parametrize("firewall", ["native_nftables", "firewalld_nft"])
def test_rendered_timer_start_strictly_follows_durable_commit(manager, firewall):
rendered = _render(manager, firewall)
def test_rendered_timer_start_strictly_follows_durable_commit(manager):
rendered = _render(manager)
timer_command = '"$SYSTEMCTL" start virt-cloud-wg-fabric-reconcile.timer >/dev/null'
assert rendered.count(timer_command) == 1
commit_marker = rendered.rindex('committed > "$_txn_state_tmp"')

@ -12,7 +12,7 @@ from pathlib import Path
import pytest
from virsh_panel.fabric import (
FIREWALL_MODE_FIREWALLD,
FIREWALL_MODE_NATIVE,
_apply_script,
_ifupdown_fragment,
_nm_profile_template,
@ -28,34 +28,6 @@ def _write(path: Path, content: str, mode: int = 0o600) -> None:
path.chmod(mode)
def _emergency_table(family: str, token: str) -> str:
rows = [f"table {family} virt_cloud_fabric_emergency {{"]
for chain in ("input", "output", "forward"):
rows.extend((f" chain {chain} {{", (
f" type filter hook {chain} priority 300; policy accept;"
)))
if family == "inet":
matches = []
if chain in ("input", "forward"):
matches.extend(('iifname "wg-fabric0"', 'iifname "vcv-*"'))
if chain in ("output", "forward"):
matches.extend(('oifname "wg-fabric0"', 'oifname "vcv-*"'))
else:
matches = []
if chain in ("input", "forward"):
matches.append('meta ibrname "vcv-*"')
if chain in ("output", "forward"):
matches.append('meta obrname "vcv-*"')
for match in matches:
rows.append(
f' {match} counter drop comment '
f'"virt-cloud-fabric-emergency-v2:{token}"'
)
rows.append(" }")
rows.append("}")
return "\n".join(rows) + "\n"
_TOOLS = r'''import hashlib
import json
import os
@ -112,10 +84,7 @@ elif name == "ip":
raise SystemExit(1)
elif name == "nft":
table_root = root / "tables"
if args == ["-j", "list", "table", "inet", "firewalld"]:
print('{"nftables":[{"table":{"family":"inet",'
'"name":"firewalld","flags":["owner","persist"]}}]}')
elif args == ["list", "tables"]:
if args == ["list", "tables"]:
for path in sorted(table_root.glob("*")):
family, table = path.name.split("--", 1)
print("table", family, table)
@ -127,7 +96,7 @@ elif name == "nft":
elif len(args) in (2, 3) and args[-2] == "-f":
batch = Path(args[-1]).read_text(encoding="utf-8")
# Recovery may delete only the completely proved interrupted Fabric
# table. Releasing emergency isolation is a test failure.
# table.
if batch != "delete table inet virt_cloud_wg_fabric\n":
raise SystemExit(2)
if "-c" not in args:
@ -137,37 +106,20 @@ elif name == "nft":
elif name == "systemctl":
if args[:2] == ["show", "-p"]:
if args[2] == "LoadState":
print("loaded" if args[-1] in ("firewalld", "nftables")
else "not-found")
print("masked" if args[-1] == "firewalld" else
"loaded" if args[-1] == "nftables" else "not-found")
elif args[2] == "ActiveState":
print("inactive")
else:
raise SystemExit(2)
elif args[0] == "is-active" and args[1] in ("firewalld", "nftables"):
print("active" if args[1] == "firewalld" else "inactive")
print("inactive" if args[1] == "firewalld" else "active")
elif args[0] == "is-enabled" and args[1] in ("firewalld", "nftables"):
print("enabled" if args[1] == "firewalld" else "disabled")
print("masked" if args[1] == "firewalld" else "enabled")
elif args and args[0] in ("daemon-reload", "disable"):
pass
else:
raise SystemExit(2)
elif name == "firewall-cmd":
if args == ["--state"]:
print("running")
elif "--get-zones" in args:
print("public trusted")
elif any(arg.startswith("--query-interface=") for arg in args):
zone = root / "runtime-zone"
wanted = next(arg.split("=", 1)[1] for arg in args
if arg.startswith("--zone="))
raise SystemExit(0 if "--permanent" not in args and zone.is_file()
and zone.read_text().strip() == wanted else 1)
elif args == ["--zone=trusted", "--remove-interface=wg-fabric0"]:
(root / "runtime-zone").unlink(missing_ok=True)
elif any(arg.startswith("--query-rich-rule=") for arg in args):
raise SystemExit(1)
else:
raise SystemExit(2)
elif name == "nmcli":
profile = (root / "NetworkManager" / "system-connections" /
"virt-cloud-wg-fabric0.nmconnection")
@ -238,7 +190,7 @@ def _fixture(tmp_path: Path, mode: str):
}
apply = _apply_script(
plan, plan.nodes[0], public_keys, deployment_mode=mode,
firewall_mode=FIREWALL_MODE_FIREWALLD,
firewall_mode=FIREWALL_MODE_NATIVE,
)
start = apply.index("#!/bin/sh\n# virt-cloud-wg-fabric-v1\n")
end = re.search(r"\n__VC_FABRIC_[0-9a-f]{16}\n", apply[start:]).start() + start
@ -251,7 +203,7 @@ def _fixture(tmp_path: Path, mode: str):
tool_path = tools / "external-tool"
_write(tool_path, f"#!{sys.executable}\n" + _TOOLS, 0o700)
for name in ("stat", "sha256sum", "ip", "nft", "systemctl",
"firewall-cmd", "nmcli", "wg", "bridge", "flock", "sync",
"nmcli", "wg", "bridge", "flock", "sync",
"ifup", "ifquery", "ifdown"):
(tools / name).symlink_to(tool_path)
@ -266,13 +218,15 @@ def _fixture(tmp_path: Path, mode: str):
"/etc/network": tmp_path / "network",
"/etc/sysctl.d": tmp_path / "sysctl.d",
"/etc/nftables.d": tmp_path / "nftables.d",
"/etc/nftables.conf": tmp_path / "nftables.conf",
"/proc/sys/net/ipv4": tmp_path / "proc" / "ipv4",
}
# Only redirect host resources/external tools. Keep all production shell
# control flow and variable declarations, notably TIMER_UNIT, intact.
for source, destination in roots.items():
helper = helper.replace(source, str(destination))
destination.mkdir(parents=True, exist_ok=True)
if source != "/etc/nftables.conf":
destination.mkdir(parents=True, exist_ok=True)
# The secure shadow ancestor check also reads /run itself; redirect only
# that exact loop token, not unrelated paths or production control flow.
helper = helper.replace("in /run ", "in " + shlex.quote(str(tmp_path / "run")) + " ")
@ -289,7 +243,7 @@ def _fixture(tmp_path: Path, mode: str):
for name in ("ifup", "ifquery", "ifdown"):
helper = helper.replace(f"/usr/sbin/{name}", str(tools / name))
for name in ("wg", "ip", "nft", "stat", "sha256sum", "systemctl",
"firewall-cmd", "nmcli", "bridge", "flock"):
"nmcli", "bridge", "flock"):
helper = re.sub(
rf"find_tool (?:/(?:usr/)?s?bin/{re.escape(name)} ?)+",
f"find_tool {shlex.quote(str(tools / name))} ",
@ -300,14 +254,10 @@ def _fixture(tmp_path: Path, mode: str):
tables = tmp_path / "tables"
tables.mkdir()
token = "A" * 24
_write(runtime / "wg-fabric-emergency.owner", (
f"virt-cloud-fabric-emergency-v2:{token}\n"
))
for family in ("inet", "bridge"):
_write(tables / f"{family}--virt_cloud_fabric_emergency", (
_emergency_table(family, token)
))
_write(roots["/etc/nftables.conf"], (
'# distribution-owned main file\n'
f'include "{roots["/etc/nftables.d"]}/*.nft"\n'
), 0o644)
return plan, helper_path, base, runtime, roots
@ -322,22 +272,14 @@ def _journal(plan, base: Path, mode: str, helper: Path, root: Path, *,
).group(1)
metadata = {
"schema": "1", "deployment_mode": mode,
"firewall_mode": FIREWALL_MODE_FIREWALLD,
"firewall_mode": FIREWALL_MODE_NATIVE,
"plan_digest": plan.digest, "connection_uuid": uuid,
"nft_main": str(base / "nftables.conf"),
"nft_main": str(root / "nftables.conf"),
"iface_before": "no", "iface_up_before": "no",
"rp_filter_before": "missing", "nft_before": "no",
"service_enabled_before": "not-found",
"service_active_before": "inactive",
"timer_enabled_before": "not-found", "timer_active_before": "inactive",
"firewalld_runtime_zone_before": "none",
"firewalld_permanent_zone_before": "none",
"underlay_endpoint": "203.0.113.1", "underlay_port": "51820",
"underlay_zone": "public", "underlay_rule_owner": "panel",
"underlay_rule_runtime_before": "no",
"underlay_rule_permanent_before": "no",
"old_underlay_rule_remove": "no", "old_underlay_endpoint": "",
"old_underlay_port": "", "old_underlay_zone": "",
}
_write(journal / "meta", "".join(
f"{key}={value}\n" for key, value in metadata.items()
@ -347,8 +289,13 @@ def _journal(plan, base: Path, mode: str, helper: Path, root: Path, *,
_write(journal / "nft.table", "")
for name in ("conf", "owner", "helper", "unit", "repair", "timer",
"gate_generator", "nm_profile", "ifupdown_fragment",
"sysctl", "nft_rules", "nft_main"):
"sysctl", "nft_rules"):
_write(journal / f"{name}.absent", "")
_write(journal / "nft_main.present", "")
_write(journal / "nft_main", (
'# distribution-owned main file\n'
f'include "{root / "nftables.d"}/*.nft"\n'
), 0o644)
_write(journal / "key.present", "")
_write(journal / "key", "test-private-key-snapshot\n")
_write(base / "wg-fabric0.key", "test-private-key-snapshot\n")
@ -385,12 +332,7 @@ def test_first_deploy_complete_entry_recovers_absent_generator_and_timer(
assert not (roots["/etc/systemd/system"] /
"virt-cloud-wg-fabric-reconcile.timer").exists()
assert not (tmp_path / "tables" / "inet--virt_cloud_wg_fabric").exists()
# Recovery keeps independent isolation; only a complete normal apply may
# activate interfaces or release these tables.
assert (runtime / "wg-fabric-emergency.owner").is_file()
for family in ("inet", "bridge"):
assert (tmp_path / "tables" /
f"{family}--virt_cloud_fabric_emergency").is_file()
assert not (runtime / "wg-fabric-emergency.owner").exists()
calls = [json.loads(line) for line in
(tmp_path / "calls").read_text(encoding="utf-8").splitlines()]
assert ["systemctl", "show", "-p", "LoadState", "--value",
@ -424,10 +366,7 @@ def test_ready_refreshed_complete_entry_recovers_exact_first_deploy_snapshots(
assert not (tmp_path / "tables" / "inet--virt_cloud_wg_fabric").exists()
assert (base / "wg-fabric0.key").read_text(encoding="utf-8") == (
"test-private-key-snapshot\n")
assert (runtime / "wg-fabric-emergency.owner").is_file()
for family in ("inet", "bridge"):
assert (tmp_path / "tables" /
f"{family}--virt_cloud_fabric_emergency").is_file()
assert not (runtime / "wg-fabric-emergency.owner").exists()
calls = [json.loads(line) for line in
(tmp_path / "calls").read_text(encoding="utf-8").splitlines()]
assert any(call[0] == "nft" and call[1] == "-f" for call in calls)
@ -437,11 +376,8 @@ def test_ready_refreshed_complete_entry_recovers_exact_first_deploy_snapshots(
and call[-1] == "up" for call in calls)
@pytest.mark.parametrize("mode,runtime_shadow", [
("networkmanager_nmcli", False), ("networkmanager_nmcli", True), ("ifupdown", False),
])
def test_ready_refreshed_persistent_entry_recovers_created_trusted_link(
tmp_path, mode, runtime_shadow):
@pytest.mark.parametrize("mode", ["networkmanager_nmcli", "ifupdown"])
def test_ready_refreshed_persistent_entry_recovers_created_link(tmp_path, mode):
plan, helper, base, runtime, roots = _fixture(tmp_path, mode)
journal = _journal(plan, base, mode, helper, tmp_path,
nft_phase="refreshed")
@ -459,26 +395,14 @@ def test_ready_refreshed_persistent_entry_recovers_created_trusted_link(
uuid = re.search(r'^CONNECTION_UUID="([^"]+)"$', content,
re.MULTILINE).group(1)
profile = _nm_profile_template(
plan, plan.nodes[0], uuid, FIREWALL_MODE_FIREWALLD,
plan, plan.nodes[0], uuid, FIREWALL_MODE_NATIVE,
).replace("private-key=\n", "private-key=" +
base64.b64encode(bytes([7]) * 32).decode() + "\n")
persistent = (roots["/etc/NetworkManager"] / "system-connections" /
"virt-cloud-wg-fabric0.nmconnection")
publish(persistent, "nm_profile", profile)
if runtime_shadow:
shadow = (roots["/run/NetworkManager"] / "system-connections" /
"virt-cloud-wg-fabric0.nmconnection")
shadow_content = "\n".join(line for line in profile.splitlines()
if not line.startswith("#"))
shadow_content = shadow_content.replace(
"[connection]", "[connection]\nzone=trusted")
shadow_content += ("\n[proxy]\n[.nmmeta]\n"
f"shadowed-storage={persistent}\nshadowed-owned=true\n")
_write(shadow, shadow_content)
for directory in (tmp_path / "run", shadow.parent.parent, shadow.parent):
directory.chmod(0o755)
_write(tmp_path / "nm-loaded-uuid", uuid + "\n")
_write(tmp_path / "nm-zone", "trusted\n")
_write(tmp_path / "nm-zone", "\n")
else:
fragment = _ifupdown_fragment(plan, plan.nodes[0]).replace(
"/usr/local/libexec", str(roots["/usr/local/libexec"]),
@ -487,7 +411,6 @@ def test_ready_refreshed_persistent_entry_recovers_created_trusted_link(
"virt-cloud-wg-fabric0", "ifupdown_fragment", fragment)
_write(tmp_path / "link-present", "")
_write(tmp_path / "link-up", "")
_write(tmp_path / "runtime-zone", "trusted\n")
rpf = roots["/proc/sys/net/ipv4"] / "conf" / "wg-fabric0" / "rp_filter"
_write(rpf, "2\n")
@ -497,19 +420,14 @@ def test_ready_refreshed_persistent_entry_recovers_created_trusted_link(
assert not helper.exists()
assert not (tmp_path / "link-present").exists()
assert not (tmp_path / "link-up").exists()
assert not (tmp_path / "runtime-zone").exists()
assert not rpf.exists()
assert not (base / "wg-fabric0.owner").exists()
assert not (tmp_path / "tables" / "inet--virt_cloud_wg_fabric").exists()
assert (runtime / "wg-fabric-emergency.owner").is_file()
for family in ("inet", "bridge"):
assert (tmp_path / "tables" /
f"{family}--virt_cloud_fabric_emergency").is_file()
assert not (runtime / "wg-fabric-emergency.owner").exists()
calls = [json.loads(line) for line in
(tmp_path / "calls").read_text(encoding="utf-8").splitlines()]
assert ["ip", "link", "del", "dev", "wg-fabric0"] in calls
assert ["firewall-cmd", "--zone=trusted",
"--remove-interface=wg-fabric0"] in calls
assert not any(call[0] == "firewall-cmd" for call in calls)
if mode == "networkmanager_nmcli":
assert ["nmcli", "device", "set", "wg-fabric0", "managed", "no"] in calls
assert ["nmcli", "connection", "delete", "uuid", uuid] in calls
@ -546,10 +464,7 @@ def test_ready_refreshed_persistent_entry_rejects_unproved_post_images(
assert journal.is_dir()
assert helper.read_text(encoding="utf-8") == content
assert live.read_bytes() == before
assert (runtime / "wg-fabric-emergency.owner").is_file()
for family in ("inet", "bridge"):
assert (tmp_path / "tables" /
f"{family}--virt_cloud_fabric_emergency").is_file()
assert not (runtime / "wg-fabric-emergency.owner").exists()
calls = [json.loads(line) for line in
(tmp_path / "calls").read_text(encoding="utf-8").splitlines()]
assert not any(call[0] == "nft" and call[1] == "-f" for call in calls)
@ -598,12 +513,9 @@ def test_full_ifupdown_transition_requires_transaction_published_gate(
assert result.returncode == (0 if gate_state == "valid" else 71), result.stderr
# A first deployment has no config yet; nested hooks only operate on the
# transaction-owned link and rp_filter. They must not parse stale desired
# config, release the emergency guard, or start any systemd/libvirt unit.
# config or start any systemd/libvirt unit.
assert not (base / "wg-fabric0.conf").exists()
assert (runtime / "wg-fabric-emergency.owner").is_file()
for family in ("inet", "bridge"):
assert (tmp_path / "tables" /
f"{family}--virt_cloud_fabric_emergency").is_file()
assert not (runtime / "wg-fabric-emergency.owner").exists()
assert (tmp_path / "link-up").exists() == (
gate_state == "valid" and entry == "--ifupdown-configure")
rpf = (roots["/proc/sys/net/ipv4"] / "conf" /
@ -620,7 +532,7 @@ def test_ifupdown_configure_without_transition_flags_cannot_activate(tmp_path):
result = _run(helper, tmp_path, "--ifupdown-configure")
assert result.returncode != 0, result.stderr
assert not (tmp_path / "link-up").exists()
assert (runtime / "wg-fabric-emergency.owner").is_file()
assert not (runtime / "wg-fabric-emergency.owner").exists()
@pytest.mark.parametrize("mode", ["ifupdown", "networkmanager_nmcli"])
@ -638,7 +550,7 @@ def test_transaction_publishes_generator_before_network_activation(mode):
keys = {host.host_id: base64.b64encode(bytes([index]) * 32).decode()
for index, host in enumerate(plan.nodes, start=1)}
script = _apply_script(plan, plan.nodes[0], keys, deployment_mode=mode,
firewall_mode=FIREWALL_MODE_FIREWALLD)
firewall_mode=FIREWALL_MODE_NATIVE)
# Inspect the real transaction after the embedded helper here-document.
transaction = script.index("COMMITTED=no\nROLLBACK_FAILED=no")
snapshot = script.index('snapshot_file "$GATE_GENERATOR" gate_generator',
@ -680,8 +592,7 @@ def test_normal_complete_entry_rejects_config_outside_rendered_plan(tmp_path, fi
key = base64.b64encode(bytes([2]) * 32).decode()
_write(base / "wg-fabric0.conf", (
f"schema|1\nfabric|{fabric}\nrevision|1\ndigest|{plan.digest}\n"
"firewall|firewalld_nft\nunderlay|local|203.0.113.1|eth0|public\n"
"firewall_rule|51820|panel\n"
"firewall|native_nftables\n"
f"network|{network}\noverlay|{overlay}\nlisten|51820\n"
f"peer|b|{key}|203.0.113.2:51820|{peer_ip}/32\nroute|{peer_ip}/32\n"
))
@ -689,11 +600,11 @@ def test_normal_complete_entry_rejects_config_outside_rendered_plan(tmp_path, fi
assert result.returncode == 72, result.stderr
calls = [json.loads(line) for line in
(tmp_path / "calls").read_text(encoding="utf-8").splitlines()]
assert ["nft", "-j", "list", "table", "inet", "firewalld"] in calls
assert not any(call[-3:] == ["table", "inet", "firewalld"] for call in calls)
# Both otherwise syntactically valid configurations fail at their exact
# identity/network assertion, before any route or link activation.
assert not any(call[0] == "ip" and "route" in call for call in calls)
assert (runtime / "wg-fabric-emergency.owner").is_file()
assert not (runtime / "wg-fabric-emergency.owner").exists()
assert not any(call[0] == "systemctl" and call[1] in
("start", "enable") for call in calls)
@ -717,7 +628,7 @@ def test_first_deploy_complete_entry_rejects_unproved_artifacts(
assert journal.is_dir()
assert (tmp_path / "tables" /
"inet--virt_cloud_wg_fabric").read_bytes() == before
assert (runtime / "wg-fabric-emergency.owner").is_file()
assert not (runtime / "wg-fabric-emergency.owner").exists()
@pytest.mark.parametrize("gate_state", ["absent", "insecure", "wrong_digest", "valid"])
@ -740,4 +651,4 @@ def test_normal_complete_entry_still_validates_generator(tmp_path, gate_state):
sysctl_dir_checked = ["stat", "-c", "%u:%a",
str(roots["/etc/sysctl.d"])] in calls
assert sysctl_dir_checked == (gate_state == "valid")
assert (runtime / "wg-fabric-emergency.owner").is_file()
assert not (runtime / "wg-fabric-emergency.owner").exists()

@ -159,9 +159,8 @@ find_tool() {{
esac
}}
vc_primary_inactive_retry_ready() {{ return 1; }}
vc_fabric_emergency_reconcile_needed() {{ return 1; }}
vc_legacy_firewalld_state_detected() {{ return 1; }}
vc_fabric_rpf_repair_needed() {{ return 1; }}
vc_firewalld_runtime_repair_needed() {{ return 1; }}
{branch}
'''

@ -19,9 +19,7 @@ from virsh_panel.fabric import (
@pytest.fixture(params=[
("ifupdown", "native_nftables"),
("ifupdown", "firewalld_nft"),
("networkmanager_nmcli", "native_nftables"),
("networkmanager_nmcli", "firewalld_nft"),
])
def rendered_transaction(request):
plan = parse_fabric_plan({

@ -13,7 +13,7 @@ import pytest
from virsh_panel.fabric import _apply_script, parse_fabric_plan
@pytest.fixture(params=["native_nftables", "firewalld_nft"])
@pytest.fixture(params=["native_nftables"])
def rendered_nm_publication(request):
plan = parse_fabric_plan({
"fabric_id": "nm-dir-test", "region": "test",

@ -1,304 +0,0 @@
"""Strict ownership for NetworkManager's normal in-memory keyfile shadow."""
from __future__ import annotations
import base64
import json
import re
import shlex
import subprocess
import sys
from pathlib import Path
import pytest
from virsh_panel.fabric import (
_BOOT_HELPER,
_FIREWALL_MODE_GUARD_SH,
_NMCLI_FILENAME_RESOLVER_SH,
_apply_script,
_fabric_connection_uuid,
_nm_profile_template,
_observe_script,
parse_fabric_plan,
)
KEY = base64.b64encode(bytes([7]) * 32).decode()
UUID = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
DIGEST = "a" * 64
NAME = "virt-cloud-wg-fabric0"
def _write(path: Path, text: str, mode=0o600):
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(text, encoding="utf-8")
path.chmod(mode)
def _persistent():
return f'''# virt-cloud-wg-fabric-v1
# fabric-plan-digest={DIGEST}
[connection]
id={NAME}
uuid={UUID}
type=wireguard
interface-name=wg-fabric0
autoconnect=false
autoconnect-retries=0
[wireguard]
private-key={KEY}
listen-port=51820
[ipv4]
method=manual
address1=100.64.1.1/32
never-default=true
route-metric=50
route1=100.64.1.2/32
[ipv6]
method=disabled
'''
def _runtime(persistent: Path, zone="trusted"):
# Real NM serialization loses comments, changes section/key order and adds
# only zone, an empty proxy group and these exact two shadow metadata keys.
return f'''[wireguard]
listen-port=51820
private-key={KEY}
[connection]
autoconnect-retries=0
interface-name=wg-fabric0
uuid={UUID}
autoconnect=false
type=wireguard
id={NAME}
zone={zone}
[ipv6]
method=disabled
[ipv4]
route1=100.64.1.2/32
route-metric=50
never-default=true
address1=100.64.1.1/32
method=manual
[proxy]
[.nmmeta]
shadowed-storage={persistent}
shadowed-owned=true
'''
_TOOL = r'''import hashlib, json, os, stat, sys
from pathlib import Path
name = Path(sys.argv[0]).name
args = sys.argv[1:]
root = Path(os.environ["VC_SHADOW_ROOT"])
if name == "stat":
path = Path(args[-1])
value = os.stat(path)
override = json.loads((root / "owners").read_text())
uid, gid = override.get(str(path), [0, 0])
mode = format(stat.S_IMODE(value.st_mode), "o")
values = {"%u": str(uid), "%a": mode, "%u:%a": f"{uid}:{mode}",
"%u:%g:%a": f"{uid}:{gid}:{mode}", "%s": str(value.st_size)}
print(values[args[1]])
elif name == "sha256sum":
print(hashlib.sha256(Path(args[0]).read_bytes()).hexdigest(), args[0])
elif name == "nmcli":
if args[:5] == ["-t", "--escape", "no", "-f", "NAME,UUID"]:
print((root / "names").read_text(), end="")
elif args[:5] == ["-t", "--escape", "no", "-f", "UUID,FILENAME"]:
print((root / "filenames").read_text(), end="")
else:
raise SystemExit(2)
else:
raise SystemExit(2)
'''
def _fixture(tmp_path):
roots = {
"/etc/NetworkManager": tmp_path / "etc" / "NetworkManager",
"/run": tmp_path / "run",
}
persistent = roots["/etc/NetworkManager"] / "system-connections" / (NAME + ".nmconnection")
runtime = roots["/run"] / "NetworkManager" / "system-connections" / (NAME + ".nmconnection")
_write(persistent, _persistent())
_write(runtime, _runtime(persistent))
for path in (roots["/run"], runtime.parent.parent, runtime.parent):
path.chmod(0o755)
_write(tmp_path / "names", f"{NAME}:{UUID}\n")
_write(tmp_path / "filenames", f"{UUID}:{runtime}\n")
_write(tmp_path / "owners", "{}")
tools = tmp_path / "tools"
tools.mkdir()
actual = tools / "tool"
_write(actual, f"#!{sys.executable}\n" + _TOOL, 0o700)
for name in ("stat", "sha256sum", "nmcli"):
(tools / name).symlink_to(actual)
start = _FIREWALL_MODE_GUARD_SH.index("vc_fabric_nm_profile_secure_hash() {")
end = _FIREWALL_MODE_GUARD_SH.index("\nvc_fabric_nm_active()", start)
body = _NMCLI_FILENAME_RESOLVER_SH + "\n" + _FIREWALL_MODE_GUARD_SH[start:end]
for source, target in roots.items():
body = body.replace(source, str(target))
prefix = (
f"STAT={shlex.quote(str(tools / 'stat'))}\n"
f"NMCLI={shlex.quote(str(tools / 'nmcli'))}\n"
f"NM_PROFILE={shlex.quote(str(persistent))}\n"
f"CONNECTION={shlex.quote(NAME)}\nCONNECTION_UUID={shlex.quote(UUID)}\n"
f"EXPECTED_DIGEST={shlex.quote(DIGEST)}\nFIREWALL_MODE=firewalld_nft\n"
"find_tool() { printf '%s' " + shlex.quote(str(tools / "sha256sum")) + "; }\n"
)
script = prefix + body + "\nvc_fabric_nm_profile_owned expected\n"
return persistent, runtime, script
def _run(tmp_path, script):
return subprocess.run(["/bin/sh", "-eu", "-c", script], capture_output=True,
text=True, check=False,
env={"VC_SHADOW_ROOT": str(tmp_path)}, timeout=15)
@pytest.mark.parametrize("location", ["persistent", "runtime"])
@pytest.mark.parametrize("zone", ["trusted", "", "absent"])
def test_same_owned_profile_accepts_only_exact_normal_shadow(tmp_path, location, zone):
persistent, runtime, script = _fixture(tmp_path)
text = _runtime(persistent, zone if zone != "absent" else "")
if zone == "absent":
text = text.replace("zone=\n", "")
_write(runtime, text)
if location == "persistent":
_write(tmp_path / "filenames", f"{UUID}:{persistent}\n")
result = _run(tmp_path, script)
assert result.returncode == 0, result.stderr
assert result.stdout == result.stderr == ""
@pytest.mark.parametrize("drift", [
"key", "port", "address", "route", "route_metric", "ipv4_method", "ipv6_method",
"autoconnect", "uuid", "type", "zone", "persistent_zone", "metadata_path",
"metadata_owner", "metadata_extra", "unknown_key", "unknown_section", "duplicate_key",
"duplicate_section", "extra_route", "proxy_key", "metadata_missing",
])
def test_shadow_semantic_drift_or_unknown_shape_fails_without_secret_output(tmp_path, drift):
persistent, runtime, script = _fixture(tmp_path)
text = runtime.read_text(encoding="utf-8")
substitutions = {
"key": (KEY, base64.b64encode(bytes([8]) * 32).decode()),
"port": ("listen-port=51820", "listen-port=51821"),
"address": ("address1=100.64.1.1/32", "address1=100.64.1.3/32"),
"route": ("route1=100.64.1.2/32", "route1=100.64.1.3/32"),
"route_metric": ("route-metric=50", "route-metric=51"),
"ipv4_method": ("method=manual", "method=auto"),
"ipv6_method": ("method=disabled", "method=auto"),
"autoconnect": ("autoconnect=false", "autoconnect=true"),
"uuid": (UUID, "f" * 36),
"type": ("type=wireguard", "type=bridge"),
"zone": ("zone=trusted", "zone=public"),
"metadata_path": (f"shadowed-storage={persistent}", "shadowed-storage=/etc/external"),
"metadata_owner": ("shadowed-owned=true", "shadowed-owned=false"),
"metadata_extra": ("shadowed-owned=true", "shadowed-owned=true\nexternal=true"),
"unknown_key": ("listen-port=51820", "listen-port=51820\nfwmark=1"),
"unknown_section": ("[proxy]", "[unmanaged]"),
"duplicate_key": ("listen-port=51820", "listen-port=51820\nlisten-port=51820"),
"duplicate_section": ("[proxy]", "[ipv4]\nmethod=manual\n[proxy]"),
"extra_route": ("route1=100.64.1.2/32", "route1=100.64.1.2/32\nroute2=10.1.0.1/32"),
"proxy_key": ("[proxy]", "[proxy]\nmethod=auto"),
"metadata_missing": ("shadowed-owned=true\n", ""),
}
if drift == "persistent_zone":
_write(persistent, persistent.read_text().replace("[connection]", "[connection]\nzone=trusted"))
else:
old, new = substitutions[drift]
_write(runtime, text.replace(old, new))
result = _run(tmp_path, script)
assert result.returncode != 0
assert result.stdout == result.stderr == ""
@pytest.mark.parametrize("drift", [
"filename", "basename", "runtime_symlink", "parent_symlink", "parent_writable",
"runtime_wide", "runtime_owner", "persistent_owner", "duplicate_uuid", "duplicate_name",
"runtime_empty", "runtime_large",
])
def test_runtime_path_and_ownership_are_not_widened(tmp_path, drift):
persistent, runtime, script = _fixture(tmp_path)
if drift in ("filename", "basename"):
path = tmp_path / "external" if drift == "filename" else runtime.with_name("external.nmconnection")
_write(path, runtime.read_text())
_write(tmp_path / "filenames", f"{UUID}:{path}\n")
elif drift == "runtime_symlink":
external = tmp_path / "external"
_write(external, runtime.read_text())
runtime.unlink()
runtime.symlink_to(external)
elif drift == "parent_symlink":
external = runtime.parent.with_name("external")
runtime.parent.rename(external)
runtime.parent.symlink_to(external)
elif drift == "parent_writable":
runtime.parent.chmod(0o775)
elif drift == "runtime_wide":
runtime.chmod(0o644)
elif drift in ("runtime_owner", "persistent_owner"):
path = runtime if drift == "runtime_owner" else persistent
_write(tmp_path / "owners", json.dumps({str(path): [1000, 0]}))
elif drift == "duplicate_uuid":
_write(tmp_path / "names", f"{NAME}:{UUID}\nother:{UUID}\n")
elif drift == "duplicate_name":
_write(tmp_path / "names", f"{NAME}:{UUID}\n{NAME}:other\n")
elif drift == "runtime_empty":
_write(runtime, "")
else:
_write(runtime, runtime.read_text() + "#" * 65536)
result = _run(tmp_path, script)
assert result.returncode != 0
assert result.stdout == result.stderr == ""
def test_shared_shadow_contract_is_rendered_in_apply_observe_and_boot():
plan = parse_fabric_plan({
"fabric_id": "shadow-fabric", "region": "hk", "overlay_cidr": "100.64.1.0/24",
"revision": 1, "nodes": [
{"host_id": "a", "overlay_ip": "100.64.1.1", "endpoint": "203.0.113.1:51820"},
{"host_id": "b", "overlay_ip": "100.64.1.2", "endpoint": "203.0.113.2:51820"},
],
})
keys = {node.host_id: KEY for node in plan.nodes}
apply = _apply_script(plan, plan.nodes[0], keys, firewall_mode="firewalld_nft")
observe = _observe_script(("100.64.1.2",), "100.64.1.1", firewall_mode="firewalld_nft")
for script in (apply, observe):
assert "vc_fabric_nm_profile_semantics_match() {" in script
assert "shadowed-storage" in script
subprocess.run(["/bin/sh", "-n"], input=script, text=True, check=True)
assert "vc_fabric_nm_profile_semantics_match" in _BOOT_HELPER or "__VC_FIREWALL_MODE_GUARD__" in _BOOT_HELPER
def test_first_deploy_recovery_dispatch_requires_exact_published_old_helper():
plan = parse_fabric_plan({
"fabric_id": "shadow-fabric", "region": "hk", "overlay_cidr": "100.64.1.0/24",
"revision": 1, "nodes": [
{"host_id": "a", "overlay_ip": "100.64.1.1", "endpoint": "203.0.113.1:51820"},
{"host_id": "b", "overlay_ip": "100.64.1.2", "endpoint": "203.0.113.2:51820"},
],
})
script = _apply_script(plan, plan.nodes[0], {node.host_id: KEY for node in plan.nodes},
firewall_mode="firewalld_nft")
start = script.index("transaction_first_deploy_helper_absent=no")
end = script.index("transaction_missing_installing_snapshot=no", start)
guard = script[start:end]
assert 'transaction_recovery_helper_owned || exit 79' in guard
assert 'fabric-plan-digest=$EXPECTED_DIGEST' in guard
assert 'PLAN_DIGEST=\\"$EXPECTED_DIGEST\\"' in guard
assert guard.index('helper.present') < guard.index('transaction_recovery_helper_owned')
current = script.index('/bin/sh "$_tmp_helper" --recover-current', end)
ordinary = script.index('/bin/sh "$HELPER" --recover-only', current)
assert current < ordinary

@ -1,121 +0,0 @@
"""Replay a failed first-deploy post-image through the current recovery helper."""
from __future__ import annotations
import base64
import json
import re
import shlex
import subprocess
from pathlib import Path
import pytest
from test_fabric_first_deploy_entry import _fixture, _journal, _write
from virsh_panel.fabric import (
FIREWALL_MODE_FIREWALLD,
_FABRIC_NFT_VALIDATION_SH,
_FABRIC_SYSCTL_VALIDATION_SH,
_FIREWALL_MODE_GUARD_SH,
_NMCLI_FILENAME_RESOLVER_SH,
_TRANSACTION_SCRIPT,
_nm_profile_template,
)
def _failed_first_deploy(tmp_path):
plan, current, base, runtime, roots = _fixture(tmp_path, "networkmanager_nmcli")
journal = _journal(plan, base, "networkmanager_nmcli", current, tmp_path,
nft_phase="refreshed")
content = current.read_text(encoding="utf-8")
legacy = "\n".join(content.splitlines()[:4]) + (
"\n# --recover-only\nprintf 'LEGACY_HELPER_EXECUTED\\n' >&2\nexit 99\n")
installed = roots["/usr/local/libexec"] / "virt-cloud-wg-fabric"
_write(installed, legacy, 0o700)
_write(journal / "helper.desired", legacy, 0o700)
_write(base / "wg-fabric0.owner", "virt-cloud-wg-fabric-v1\n")
_write(journal / "owner.desired", "virt-cloud-wg-fabric-v1\n")
uuid = re.search(r'^CONNECTION_UUID="([^"]+)"$', content, re.MULTILINE)[1]
persistent = (roots["/etc/NetworkManager"] / "system-connections" /
"virt-cloud-wg-fabric0.nmconnection")
profile = _nm_profile_template(plan, plan.nodes[0], uuid, FIREWALL_MODE_FIREWALLD).replace(
"private-key=\n", "private-key=" + base64.b64encode(bytes([7]) * 32).decode() + "\n")
_write(persistent, profile)
_write(journal / "nm_profile.desired", profile)
shadow = roots["/run/NetworkManager"] / "system-connections" / persistent.name
shadow_text = "\n".join(line for line in profile.splitlines() if not line.startswith("#"))
_write(shadow, shadow_text.replace("[connection]", "[connection]\nzone=trusted") + (
f"\n[proxy]\n[.nmmeta]\nshadowed-storage={persistent}\nshadowed-owned=true\n"))
for directory in (tmp_path / "run", shadow.parent.parent, shadow.parent):
directory.chmod(0o755)
_write(tmp_path / "nm-loaded-uuid", uuid + "\n")
_write(tmp_path / "nm-zone", "trusted\n")
for name in ("link-present", "link-up"):
_write(tmp_path / name, "")
_write(tmp_path / "runtime-zone", "trusted\n")
_write(roots["/proc/sys/net/ipv4"] / "conf" / "wg-fabric0" / "rp_filter", "2\n")
return plan, current, installed, base, runtime, roots, journal, shadow
def _driver(plan, current, installed, base, runtime, roots, tmp_path):
boundary = "# A fixed-path sysctl file may be reused only when the authoritative owner\n"
recovery = _TRANSACTION_SCRIPT.split(boundary, 1)[0]
body = (_NMCLI_FILENAME_RESOLVER_SH + "\n" + _FABRIC_NFT_VALIDATION_SH + "\n"
+ _FABRIC_SYSCTL_VALIDATION_SH + "\n" + _FIREWALL_MODE_GUARD_SH + "\n" + recovery)
for source, destination in roots.items():
body = body.replace(source, str(destination))
body = body.replace("in /run ", "in " + shlex.quote(str(tmp_path / "run")) + " ")
tools = tmp_path / "tools"
values = {"BASE": base, "HELPER": installed, "_tmp_helper": current,
"OWNER": base / "wg-fabric0.owner", "CONF": base / "wg-fabric0.conf",
"NM_PROFILE": roots["/etc/NetworkManager"] / "system-connections" /
"virt-cloud-wg-fabric0.nmconnection",
"EMERGENCY_OWNER": runtime / "wg-fabric-emergency.owner",
"EXPECTED_DIGEST": plan.digest, "DEPLOYMENT_MODE": "networkmanager_nmcli",
"FIREWALL_MODE": "firewalld_nft", "IFACE": "wg-fabric0",
"CONNECTION": "virt-cloud-wg-fabric0"}
uuid = re.search(r'^CONNECTION_UUID="([^"]+)"$', current.read_text(), re.MULTILINE)[1]
values["CONNECTION_UUID"] = uuid
for variable, name in (("STAT", "stat"), ("NFT", "nft"), ("IP", "ip"),
("WG", "wg"), ("SYSTEMCTL", "systemctl"),
("NMCLI", "nmcli"), ("FIREWALL_CMD", "firewall-cmd")):
values[variable] = tools / name
values["CMP"] = "/usr/bin/cmp"
prefix = "\n".join(key + "=" + shlex.quote(str(value)) for key, value in values.items())
prefix += ("\nfind_tool() { printf '%s' " + shlex.quote(str(tools / "sha256sum")) + "; }\n"
"vc_fabric_operation_checkpoint() { :; }\n"
"PATH=" + shlex.quote(str(tools)) + ":/usr/bin:/bin; export PATH\n")
return "set -eu\n" + prefix + body
@pytest.mark.parametrize("failure", [None, "foreign_helper", "wrong_digest", "runtime_key"])
def test_current_first_deploy_recovery_replays_only_exact_same_plan_post_image(tmp_path, failure):
plan, current, installed, base, runtime, roots, journal, shadow = _failed_first_deploy(tmp_path)
if failure == "foreign_helper":
_write(installed, installed.read_text() + "# external replacement\n", 0o700)
elif failure == "wrong_digest":
changed = installed.read_text().replace(plan.digest, "b" * 64)
_write(installed, changed, 0o700)
_write(journal / "helper.desired", changed, 0o700)
elif failure == "runtime_key":
value = base64.b64encode(bytes([7]) * 32).decode()
_write(shadow, shadow.read_text().replace(value, base64.b64encode(bytes([8]) * 32).decode()))
result = subprocess.run(["/bin/sh", "-c", _driver(
plan, current, installed, base, runtime, roots, tmp_path)],
capture_output=True, text=True, check=False,
env={"VC_ENTRY_ROOT": str(tmp_path), "VC_FABRIC_LOCK_HELD": "1"}, timeout=45)
assert result.returncode == (0 if failure is None else 79), result.stderr
assert "LEGACY_HELPER_EXECUTED" not in result.stdout + result.stderr
assert (runtime / "wg-fabric-emergency.owner").is_file()
for family in ("inet", "bridge"):
assert (tmp_path / "tables" / f"{family}--virt_cloud_fabric_emergency").is_file()
if failure is None:
assert not journal.exists()
assert not installed.exists()
assert not shadow.exists()
assert not (tmp_path / "link-present").exists()
assert not (tmp_path / "tables" / "inet--virt_cloud_wg_fabric").exists()
calls = [json.loads(line) for line in (tmp_path / "calls").read_text().splitlines()]
assert not any(call[0] == "systemctl" and call[1] in ("start", "enable") for call in calls)
else:
assert journal.is_dir()
assert installed.is_file()

@ -1,272 +1,187 @@
"""Recover a same-plan ready journal without redispatching its old helper."""
"""Native journal recovery and retired firewalld fail-closed contracts."""
from __future__ import annotations
import base64
import json
from pathlib import Path
import re
import shlex
import stat
import subprocess
import sys
import pytest
from test_fabric_first_deploy_entry import _write
from test_fabric_nm_runtime_shadow_recovery import _failed_first_deploy
from test_fabric_first_deploy_entry import _fixture, _journal, _run, _write
from virsh_panel.fabric import (
FIREWALL_MODE_FIREWALLD,
FIREWALL_MODE_NATIVE,
_FABRIC_NFT_VALIDATION_SH,
_FABRIC_SYSCTL_VALIDATION_SH,
_FIREWALL_MODE_GUARD_SH,
_NMCLI_FILENAME_RESOLVER_SH,
_apply_script,
)
def _baseline_fixture(tmp_path):
values = _failed_first_deploy(tmp_path)
_, _, installed, _, _, _, journal, _ = values
# The real Alma host now has a journaled old helper baseline, not the
# helper.absent case covered by the first-deployment recovery path.
(journal / "helper.absent").unlink()
_write(journal / "helper.present", "")
_write(journal / "helper", installed.read_text(encoding="utf-8"), 0o700)
return values
def _rendered_driver(values, root, firewall_mode=FIREWALL_MODE_FIREWALLD):
plan, current, installed, base, runtime, roots, _, _ = values
keys = {host.host_id: base64.b64encode(bytes([index]) * 32).decode()
for index, host in enumerate(plan.nodes, start=1)}
rendered = _apply_script(
plan, plan.nodes[0], keys, deployment_mode="networkmanager_nmcli",
firewall_mode=firewall_mode,
)
start = rendered.index("COMMITTED=no\nROLLBACK_FAILED=no")
end = rendered.index("vc_fabric_operation_checkpoint preflight\n", start)
# Execute the actual rendered outer recovery functions and dispatch, then
# the complete current helper. Only host resources and CLI paths redirect
# to fixture doubles; no ownership/recovery shell function is replaced.
recovery = rendered[start:end]
body = (_NMCLI_FILENAME_RESOLVER_SH + "\n" + _FABRIC_NFT_VALIDATION_SH + "\n"
+ _FABRIC_SYSCTL_VALIDATION_SH + "\n" + _FIREWALL_MODE_GUARD_SH + "\n"
+ recovery)
for source, destination in roots.items():
body = body.replace(source, str(destination))
body = body.replace("in /run ", "in " + shlex.quote(str(root / "run")) + " ")
tools = root / "tools"
identity = re.search(r'^CONNECTION_UUID="([^"]+)"$', current.read_text(), re.MULTILINE)[1]
variables = {
"BASE": base, "HELPER": installed, "_tmp_helper": current,
"OWNER": base / "wg-fabric0.owner", "CONF": base / "wg-fabric0.conf",
"NM_PROFILE": roots["/etc/NetworkManager"] / "system-connections" /
"virt-cloud-wg-fabric0.nmconnection",
"EMERGENCY_OWNER": runtime / "wg-fabric-emergency.owner",
"EXPECTED_DIGEST": plan.digest, "DEPLOYMENT_MODE": "networkmanager_nmcli",
"FIREWALL_MODE": firewall_mode, "IFACE": "wg-fabric0",
"CONNECTION": "virt-cloud-wg-fabric0", "CONNECTION_UUID": identity,
"CMP": "/usr/bin/cmp",
def _journal_image(journal: Path) -> dict[str, tuple[bytes, int]]:
return {
str(path.relative_to(journal)): (
path.read_bytes(), stat.S_IMODE(path.stat().st_mode),
)
for path in journal.rglob("*")
if path.is_file() and not path.is_symlink()
}
for variable, name in (("STAT", "stat"), ("NFT", "nft"), ("IP", "ip"),
("WG", "wg"), ("SYSTEMCTL", "systemctl"),
("NMCLI", "nmcli"), ("FIREWALL_CMD", "firewall-cmd")):
variables[variable] = tools / name
prefix = "\n".join(key + "=" + shlex.quote(str(value)) for key, value in variables.items())
prefix += ("\nfind_tool() { printf '%s' " + shlex.quote(str(tools / "sha256sum")) + "; }\n"
"vc_fabric_operation_checkpoint() { :; }\n"
"PATH=" + shlex.quote(str(tools)) + ":/usr/bin:/bin; export PATH\n")
return "set -eu\n" + prefix + body
def _run(values, root, firewall_mode=FIREWALL_MODE_FIREWALLD):
return subprocess.run(
["/bin/sh", "-c", _rendered_driver(values, root, firewall_mode)], check=False,
capture_output=True, text=True,
env={"VC_ENTRY_ROOT": str(root), "VC_FABRIC_LOCK_HELD": "1"}, timeout=45,
def _assert_no_recovery_mutation(root: Path) -> None:
calls_path = root / "calls"
calls = (
[json.loads(line) for line in calls_path.read_text().splitlines()]
if calls_path.is_file() else []
)
assert not any(call[0] == "nft" and "-f" in call for call in calls)
assert not any(
call[:3] == ["ip", "link", "set"] or
call[:3] == ["ip", "link", "del"]
for call in calls
)
assert not any(
call[0] == "nmcli" and call[1:3] in (
["connection", "delete"], ["connection", "modify"],
)
for call in calls
)
assert not any(
call[0] == "systemctl" and call[1] in ("start", "enable")
for call in calls
)
def _native_baseline_fixture(tmp_path, *, empty_header=False):
values = _baseline_fixture(tmp_path)
_, current, _, _, _, roots, journal, shadow = values
# Rendered helper implementation is identical for both owners; the
# explicit literal backend selects the native branch. No shell function
# or recovery conditional is replaced in this fixture.
content = current.read_text().replace(
'FIREWALL_MODE="firewalld_nft"', 'FIREWALL_MODE="native_nftables"', 1,
@pytest.mark.parametrize("state", ("ready", "committed"))
def test_legacy_firewalld_journal_is_rejected_and_preserved(tmp_path, state):
plan, helper, base, _, _ = _fixture(tmp_path, "networkmanager_nmcli")
journal = _journal(
plan, base, "networkmanager_nmcli", helper, tmp_path,
nft_phase="refreshed",
)
native_main = tmp_path / "nftables.conf"
roots["/etc/nftables.conf"] = native_main
content = content.replace("/etc/nftables.conf", str(native_main))
if empty_header:
content = content.replace('UNDERLAY_ENDPOINT="203.0.113.1"', 'UNDERLAY_ENDPOINT=""')
content = content.replace('UNDERLAY_PORT="51820"', 'UNDERLAY_PORT=""')
_write(current, content, 0o700)
metadata = dict(line.split("=", 1) for line in (journal / "meta").read_text().splitlines())
metadata.update({
"firewall_mode": FIREWALL_MODE_NATIVE, "nft_main": str(native_main),
"firewalld_runtime_zone_before": "na", "firewalld_permanent_zone_before": "na",
"underlay_endpoint": "", "underlay_port": "", "underlay_zone": "",
"underlay_rule_owner": "none", "underlay_rule_runtime_before": "na",
"underlay_rule_permanent_before": "na",
})
_write(journal / "meta", "".join(f"{key}={value}\n" for key, value in metadata.items()))
distribution_rules = '# distribution-owned main file\ninclude "/etc/nftables.d/*.nft"\n'
_write(native_main, distribution_rules, 0o644)
(journal / "nft_main.absent").unlink()
_write(journal / "nft_main.present", "")
_write(journal / "nft_main", distribution_rules, 0o644)
_write(shadow, shadow.read_text().replace("zone=trusted", "zone="))
_write(tmp_path / "nm-zone", "")
(tmp_path / "runtime-zone").unlink()
# Native owner fixture: nftables enabled/running, firewalld masked and
# inactive. Only external systemctl evidence differs from firewalld.
tool = tmp_path / "tools" / "external-tool"
external = tool.read_text().replace(
'print("active" if args[1] == "firewalld" else "inactive")',
'print("inactive" if args[1] == "firewalld" else "active")',
).replace(
'print("enabled" if args[1] == "firewalld" else "disabled")',
'print("masked" if args[1] == "firewalld" else "enabled")',
_write(journal / "state", state + "\n")
_write(
journal / "meta",
(journal / "meta").read_text(encoding="utf-8").replace(
"firewall_mode=native_nftables",
"firewall_mode=firewalld_nft",
),
)
_write(tool, external, 0o700)
return values
before = _journal_image(journal)
result = _run(helper, tmp_path, "--recover-current")
@pytest.mark.parametrize("empty_header", [False, True])
@pytest.mark.parametrize("failure", [None, "endpoint", "port"])
def test_native_same_plan_handoff_requires_empty_underlay_metadata_not_unused_header(
tmp_path, empty_header, failure):
values = _native_baseline_fixture(tmp_path, empty_header=empty_header)
_, _, installed, _, runtime, _, journal, shadow = values
historical = installed.read_bytes()
if failure:
_write(journal / "meta", (journal / "meta").read_text().replace(
f"underlay_{failure}=\n",
f"underlay_{failure}=" + ("203.0.113.1" if failure == "endpoint" else "51820") + "\n",
1,
))
live = tmp_path / "tables" / "inet--virt_cloud_wg_fabric"
original = live.read_bytes()
result = _run(values, tmp_path, FIREWALL_MODE_NATIVE)
assert result.returncode == (0 if failure is None else 79), result.stderr
assert "LEGACY_HELPER_EXECUTED" not in result.stdout + result.stderr
assert installed.read_bytes() == historical
assert (runtime / "wg-fabric-emergency.owner").is_file()
if failure is None:
assert not journal.exists()
assert not live.exists()
assert not shadow.exists()
assert not (tmp_path / "link-present").exists()
else:
assert journal.is_dir()
assert live.read_bytes() == original
assert shadow.is_file()
assert result.returncode == 79, result.stderr
assert journal.is_dir()
assert _journal_image(journal) == before
_assert_no_recovery_mutation(tmp_path)
@pytest.mark.parametrize("state", ("preparing", "committed"))
def test_malformed_native_journal_is_rejected_and_preserved(tmp_path, state):
plan, helper, base, _, _ = _fixture(tmp_path, "ifupdown")
journal = _journal(plan, base, "ifupdown", helper, tmp_path)
_write(journal / "state", state + "\n")
_write(
journal / "meta",
(journal / "meta").read_text(encoding="utf-8")
+ "firewall_mode=native_nftables\n",
)
before = _journal_image(journal)
result = _run(helper, tmp_path, "--recover-current")
def test_rendered_outer_replays_same_plan_old_baseline_with_current_helper(tmp_path):
values = _baseline_fixture(tmp_path)
_, current, installed, base, runtime, _, journal, shadow = values
historical = installed.read_bytes()
assert current.read_bytes() != historical
assert "vc_fabric_nm_profile_semantics_match" not in historical.decode()
result = _run(values, tmp_path)
assert result.returncode == 0, result.stderr
assert "LEGACY_HELPER_EXECUTED" not in result.stdout + result.stderr
assert not journal.exists()
# Complete recovery preserves its pre-existing, precisely journaled old
# helper but must not execute it again under --recover-current.
assert installed.read_bytes() == historical
assert not shadow.exists()
assert not (tmp_path / "link-present").exists()
assert not (base / "wg-fabric0.owner").exists()
assert not (tmp_path / "tables" / "inet--virt_cloud_wg_fabric").exists()
assert (runtime / "wg-fabric-emergency.owner").is_file()
for family in ("inet", "bridge"):
assert (tmp_path / "tables" / f"{family}--virt_cloud_fabric_emergency").is_file()
calls = [json.loads(line) for line in (tmp_path / "calls").read_text().splitlines()]
assert not any(call[0] == "systemctl" and call[1] in ("start", "enable") for call in calls)
assert not any(call[:5] == ["ip", "link", "set", "dev", "wg-fabric0"]
and call[-1] == "up" for call in calls)
assert result.returncode == 79, result.stderr
assert journal.is_dir()
assert _journal_image(journal) == before
_assert_no_recovery_mutation(tmp_path)
def test_normal_boot_recovery_still_reenters_verified_historical_helper(tmp_path):
values = _baseline_fixture(tmp_path)
_, current, installed, _, runtime, _, journal, _ = values
historical = installed.read_bytes()
result = subprocess.run(
["/bin/sh", str(current)], check=False, capture_output=True, text=True,
env={"VC_ENTRY_ROOT": str(tmp_path), "VC_FABRIC_LOCK_HELD": "1"}, timeout=45,
@pytest.mark.parametrize("state", ("ready", "committed"))
def test_needs_repair_reports_every_native_transaction_journal(tmp_path, state):
plan, helper, base, _, _ = _fixture(tmp_path, "ifupdown")
journal = _journal(
plan, base, "ifupdown", helper, tmp_path, nft_phase="refreshed",
)
# This complete non-recovery-only entry still uses the restored old
# implementation. Its deliberate exit99 proves the normal exec contract
# was preserved instead of silently treating a regular boot as finished.
assert result.returncode == 99, result.stderr
assert "LEGACY_HELPER_EXECUTED" in result.stderr
assert not journal.exists()
assert installed.read_bytes() == historical
assert (runtime / "wg-fabric-emergency.owner").is_file()
_write(journal / "state", state + "\n")
before = _journal_image(journal)
result = _run(helper, tmp_path, "--needs-repair")
@pytest.mark.parametrize("failure", [
"foreign_helper", "baseline_and_desired_drift", "temporary_mode", "temporary_digest",
"endpoint", "port", "runtime_key", "live_nft_verdict",
])
def test_rendered_same_plan_handoff_rejects_unproved_ownership_or_plan(tmp_path, failure):
values = _baseline_fixture(tmp_path)
plan, current, installed, _, runtime, _, journal, shadow = values
if failure == "foreign_helper":
_write(installed, installed.read_text() + "# external replacement\n", 0o700)
elif failure == "baseline_and_desired_drift":
for name in ("helper", "helper.desired"):
_write(journal / name, (journal / name).read_text() + "# changed snapshot\n", 0o700)
elif failure == "temporary_mode":
current.chmod(0o600)
elif failure == "temporary_digest":
_write(current, current.read_text().replace(plan.digest, "a" * 64), 0o700)
elif failure in ("endpoint", "port"):
old, new = (("underlay_endpoint=203.0.113.1", "underlay_endpoint=203.0.113.9")
if failure == "endpoint" else ("underlay_port=51820", "underlay_port=51821"))
_write(journal / "meta", (journal / "meta").read_text().replace(old, new))
elif failure == "runtime_key":
old = base64.b64encode(bytes([7]) * 32).decode()
_write(shadow, shadow.read_text().replace(old, base64.b64encode(bytes([8]) * 32).decode()))
else:
live = tmp_path / "tables" / "inet--virt_cloud_wg_fabric"
_write(live, live.read_text().replace("counter drop comment", "counter accept comment", 1))
live = tmp_path / "tables" / "inet--virt_cloud_wg_fabric"
original = live.read_bytes()
result = _run(values, tmp_path)
assert result.returncode == 79, result.stderr
assert "LEGACY_HELPER_EXECUTED" not in result.stdout + result.stderr
assert result.returncode == 0, result.stderr
assert journal.is_dir()
assert installed.is_file()
assert live.read_bytes() == original
assert (runtime / "wg-fabric-emergency.owner").is_file()
calls = [json.loads(line) for line in (tmp_path / "calls").read_text().splitlines()]
assert not any(call[0] == "nft" and call[1] == "-f" for call in calls)
assert _journal_image(journal) == before
_assert_no_recovery_mutation(tmp_path)
def _stat_tool(tmp_path: Path) -> Path:
tool = tmp_path / "stat"
tool.write_text(
f"#!{sys.executable}\n"
"import os, stat, sys\n"
"value = os.lstat(sys.argv[3])\n"
"mode = format(stat.S_IMODE(value.st_mode), 'o')\n"
"fields = {\n"
" '%u:%g:%a': '0:0:' + mode,\n"
" '%u:%a': '0:' + mode,\n"
" '%s': str(value.st_size),\n"
"}\n"
"print(fields[sys.argv[2]])\n",
encoding="utf-8",
)
tool.chmod(0o700)
return tool
@pytest.mark.parametrize("field,value", [
("plan_digest", "f" * 64),
("connection_uuid", "ffffffff-ffff-ffff-ffff-ffffffffffff"),
("deployment_mode", "ifupdown"),
("firewall_mode", "native_nftables"),
])
def test_different_plan_keeps_historical_recovery_contract_without_current_handoff(
tmp_path, field, value):
values = _baseline_fixture(tmp_path)
_, _, _, _, runtime, _, journal, _ = values
text = (journal / "meta").read_text()
_write(journal / "meta", re.sub(rf"^{field}=.*$", f"{field}={value}", text,
flags=re.MULTILINE))
before = (tmp_path / "tables" / "inet--virt_cloud_wg_fabric").read_bytes()
result = _run(values, tmp_path)
assert result.returncode == 79, result.stderr
# This controlled historical helper rejects at exit99. Existing cross-
# revision dispatch stays intact, and the current template never assumes
# authority over the other journal identity.
assert "LEGACY_HELPER_EXECUTED" in result.stderr
assert "helper_state=failed" not in result.stderr
assert journal.is_dir()
assert (tmp_path / "tables" / "inet--virt_cloud_wg_fabric").read_bytes() == before
assert (runtime / "wg-fabric-emergency.owner").is_file()
def test_rendered_apply_initializes_awk_before_running_native_guard(tmp_path):
plan, _, _, _, _ = _fixture(tmp_path, "networkmanager_nmcli")
keys = {
node.host_id: base64.b64encode(bytes([index]) * 32).decode()
for index, node in enumerate(plan.nodes, start=1)
}
rendered = _apply_script(
plan, plan.nodes[0], keys,
deployment_mode="networkmanager_nmcli",
firewall_mode=FIREWALL_MODE_NATIVE,
)
assignment = re.search(
r"^AWK=\$\(find_tool [^\n]+\) \|\| exit 70$",
rendered,
re.MULTILINE,
)
assert assignment is not None
guard_call = rendered.index("vc_legacy_firewalld_state_absent || exit 79")
assert assignment.start() < guard_call
etc = tmp_path / "etc" / "virt-cloud"
state_dir = etc / "vpc-dataplane"
runtime = tmp_path / "run" / "virt-cloud"
state_dir.mkdir(parents=True)
runtime.mkdir(parents=True, exist_ok=True)
config = etc / "wg-fabric0.conf"
config.write_text("firewall|native_nftables\n", encoding="utf-8")
config.chmod(0o600)
guard = _FIREWALL_MODE_GUARD_SH.replace(
"/etc/virt-cloud", str(etc),
).replace(
"/run/virt-cloud", str(runtime),
)
result = subprocess.run(
["/bin/sh", "-eu", "-c", "\n".join((
"find_tool() { for p in \"$@\"; do [ -x \"$p\" ] && "
"{ printf '%s' \"$p\"; return 0; }; done; return 1; }",
assignment.group(0),
f"STAT={_stat_tool(tmp_path)}",
"vc_test_nft() {",
" [ \"$*\" = \"list tables\" ] || return 2",
" printf '%s\\n' 'table inet filter'",
"}",
"NFT=vc_test_nft",
guard,
"vc_legacy_firewalld_state_absent",
))],
capture_output=True, text=True, check=False,
)
assert result.returncode == 0, result.stderr

@ -8,7 +8,7 @@ import subprocess
import pytest
from virsh_panel.fabric import (
FIREWALL_MODE_FIREWALLD,
FIREWALL_MODE_NATIVE,
_BOOT_HELPER,
_FABRIC_NFT_VALIDATION_SH,
_apply_script,
@ -36,7 +36,7 @@ def _render_apply(mode="ifupdown"):
keys = {node.host_id: base64.b64encode(bytes([index]) * 32).decode()
for index, node in enumerate(plan.nodes, 1)}
return _apply_script(plan, plan.nodes[0], keys, deployment_mode=mode,
firewall_mode=FIREWALL_MODE_FIREWALLD)
firewall_mode=FIREWALL_MODE_NATIVE)
def _assignment(script, name, start=0):
@ -209,7 +209,7 @@ def _observe_route_program():
script = _observe_script(("100.64.1.2",), "100.64.1.1",
endpoint_ips=("203.0.113.2",),
deployment_mode="ifupdown",
firewall_mode=FIREWALL_MODE_FIREWALLD)
firewall_mode=FIREWALL_MODE_NATIVE)
start = script.index('awk -v vpc_file="${VPC_ROUTE_FILE:-}"')
program = script[start:script.index("\n }'", start) + len("\n }'")]
return program.replace('"${VPC_ROUTE_FILE:-}"', '"$VPC_ROUTE_FILE"')

@ -26,8 +26,6 @@ from virsh_panel.remote_host import (
HostProfile,
RemoteHostError,
RemoteHostManager,
_parse_firewall_interface_zones,
_parse_networkmanager_interface_zones,
parse_host_capabilities,
)
from virsh_panel.ssh_agent import SSHAgentError
@ -59,7 +57,6 @@ __VCAP_TOOL__wg=/usr/bin/wg
__VCAP_TOOL__wg_quick=/usr/bin/wg-quick
__VCAP_TOOL__ip=/usr/sbin/ip
__VCAP_TOOL__nft=/usr/sbin/nft
__VCAP_TOOL__firewall_cmd=
__VCAP_TOOL__nmcli=/usr/bin/nmcli
__VCAP_TOOL__networkctl=
__VCAP_TOOL__ifup=
@ -77,6 +74,13 @@ __VCAP_MODULE_FILE_BEGIN__
__VCAP_MODULE_FILE_END__
__VCAP_FABRIC_OWNER_BEGIN__
__VCAP_FABRIC_OWNER_END__
__VCAP_LEGACY_FIREWALL__manifest=absent
__VCAP_LEGACY_FIREWALL__fabric_transaction=absent
__VCAP_LEGACY_FIREWALL__emergency_owner=absent
__VCAP_LEGACY_FIREWALL__vpc_transaction=absent
__VCAP_LEGACY_FIREWALL__vpc_snapshot=absent
__VCAP_LEGACY_FIREWALL__fabric_desired_state=absent
__VCAP_LEGACY_FIREWALL__vpc_state=absent
__VCAP_SYSCTL__ip_forward=1
__VCAP_SYSCTL__rp_filter=2
__VCAP_SYSCTL__rp_filter_default=2
@ -93,24 +97,6 @@ __VCAP_SERVICE_ENABLED__firewall=masked
__VCAP_SERVICE_ENABLED__nftables=enabled
__VCAP_SERVICE_LOAD__firewall=masked
__VCAP_SERVICE_LOAD__nftables=loaded
__VCAP_FIREWALL_CONF__backend=nftables
__VCAP_FIREWALL_CONF__table_owner=yes
__VCAP_FIREWALL_CONF__source_zones=absent
__VCAP_FIREWALL_CONF__default_runtime=public
__VCAP_FIREWALL_CONF__default_permanent=public
__VCAP_FIREWALL_CONF__runtime_nft=ready
__VCAP_FIREWALL_IFACE_BEGIN__runtime
br0|public
eth1|public
__VCAP_FIREWALL_IFACE_END__runtime=0
__VCAP_FIREWALL_IFACE_BEGIN__permanent
__VCAP_FIREWALL_IFACE_END__permanent=0
__VCAP_NM_ZONE_BEGIN__
br0|
eth1|
__VCAP_NM_ZONE_END__=0
__VCAP_IFCFG_ZONE_BEGIN__
__VCAP_IFCFG_ZONE_END__=0
__VCAP_FILE__interfaces=absent
__VCAP_FILE__interfaces_d=absent
__VCAP_FILE__networkmanager_profiles=absent
@ -128,7 +114,7 @@ __VCAP_IP_BEGIN__wireguard
[]
__VCAP_IP_END__wireguard=0
__VCAP_NFT_BEGIN__
[{{"family":"inet","name":"filter"}}]
{{"nftables":[{{"table":{{"family":"inet","name":"filter"}}}}]}}
__VCAP_NFT_END__0
__VCAP_END__
"""
@ -142,27 +128,27 @@ def test_capability_probe_command_is_parseable_by_posix_sh():
assert result.returncode == 0, result.stderr
assert "probe_ip_json addresses -j -4 address show up scope global" in (
_CAPABILITY_PROBE_COMMAND)
assert "-g GENERAL.FILENAME" not in _CAPABILITY_PROBE_COMMAND
assert (
"$firewall_nmcli -t --escape no -f UUID,FILENAME connection show"
in _CAPABILITY_PROBE_COMMAND
)
assert 'test "${#firewall_nm_profiles}" -le 262144' in (
_CAPABILITY_PROBE_COMMAND)
assert "systemctl show -p LoadState --value" in _CAPABILITY_PROBE_COMMAND
assert "FirewallBackend" in _CAPABILITY_PROBE_COMMAND
assert "NftablesTableOwner" in _CAPABILITY_PROBE_COMMAND
assert "__VCAP_FIREWALL_CONF__source_zones=" in _CAPABILITY_PROBE_COMMAND
assert "--permanent --get-default-zone" not in _CAPABILITY_PROBE_COMMAND
# firewall-cmd is a D-Bus client and can activate an inactive unit. Every
# use must therefore be dominated by the read-only systemd active check.
assert _CAPABILITY_PROBE_COMMAND.count(
'test "$firewall_service_state" = active') == 4
assert _CAPABILITY_PROBE_COMMAND.count(
'$firewall_cmd --state') == 4
assert _CAPABILITY_PROBE_COMMAND.index(
'firewall_service_state="$status"') < _CAPABILITY_PROBE_COMMAND.index(
'$firewall_cmd --state')
assert "probe_service firewall firewalld" in _CAPABILITY_PROBE_COMMAND
assert "probe_service_enabled firewall firewalld" in _CAPABILITY_PROBE_COMMAND
assert "probe_service_load firewall firewalld" in _CAPABILITY_PROBE_COMMAND
assert "firewall-cmd" not in _CAPABILITY_PROBE_COMMAND
assert "FirewallBackend" not in _CAPABILITY_PROBE_COMMAND
assert "NftablesTableOwner" not in _CAPABILITY_PROBE_COMMAND
assert '"$capability_nft_path" -j list tables' in _CAPABILITY_PROBE_COMMAND
assert "probe_legacy_firewall_path manifest /etc/virt-cloud/nftables.conf" in (
_CAPABILITY_PROBE_COMMAND
)
assert "probe_legacy_firewall_path fabric_transaction " in (
_CAPABILITY_PROBE_COMMAND
)
assert "probe_legacy_firewall_path emergency_owner " in (
_CAPABILITY_PROBE_COMMAND
)
for marker in (
"vpc_transaction", "vpc_snapshot", "fabric_desired_state", "vpc_state",
):
assert f"__VCAP_LEGACY_FIREWALL__{marker}=" in _CAPABILITY_PROBE_COMMAND
def test_capability_probe_executes_the_discovered_ip_binary():
@ -227,105 +213,6 @@ def test_capability_probe_executes_discovered_nft_and_modinfo_paths(tmp_path):
"-F filename wireguard\n")
def test_capability_probe_resolves_nm_filename_from_bounded_list_mode(tmp_path):
connection_uuid = "00000000-0000-0000-0000-000000000001"
profile = tmp_path / "br0:primary.nmconnection"
profile.write_text("[connection]\nzone=public\n", encoding="utf-8")
profile.chmod(0o600)
calls = tmp_path / "nmcli.calls"
nmcli = tmp_path / "nmcli"
nmcli.write_text(
"#!/bin/sh\n"
f'printf "%s\\n" "$*" >> "{calls}"\n'
'case "$*" in\n'
' "-t --escape no -f UUID,DEVICE connection show --active")\n'
f' printf "%s\\n" "{connection_uuid}:br0" '
'"22222222-2222-4222-8222-222222222222:vnet3"; exit 0 ;;\n'
' "-t --escape no -f UUID,FILENAME connection show")\n'
f' printf "%s\\n" "{connection_uuid}:{profile}" '
'"22222222-2222-4222-8222-222222222222:'
'/run/NetworkManager/system-connections/vnet3.nmconnection"; exit 0 ;;\n'
' "-g GENERAL.FILENAME connection show uuid '
f'{connection_uuid}") exit 2 ;;\n'
"esac\n"
"exit 64\n",
encoding="utf-8",
)
nmcli.chmod(0o700)
systemctl = tmp_path / "systemctl"
systemctl.write_text(
"#!/bin/sh\n"
'if test "$*" = "is-active NetworkManager"; then\n'
' printf "%s\\n" active\n'
" exit 0\n"
"fi\n"
"exit 3\n",
encoding="utf-8",
)
systemctl.chmod(0o700)
stat_command = tmp_path / "stat"
stat_command.write_text(
"#!/bin/sh\n"
'if test "$1" = -c && test "$2" = %u:%a; then\n'
' printf "%s\\n" 0:600\n'
" exit 0\n"
"fi\n"
'if test "$1" = -c && test "$2" = %s; then\n'
' printf "%s\\n" 25\n'
" exit 0\n"
"fi\n"
"exit 64\n",
encoding="utf-8",
)
stat_command.chmod(0o700)
detail = subprocess.run(
[
str(nmcli), "-g", "GENERAL.FILENAME", "connection", "show",
"uuid", connection_uuid,
],
capture_output=True,
text=True,
check=False,
)
assert detail.returncode == 2
command = _CAPABILITY_PROBE_COMMAND.replace(
"for firewall_candidate in /usr/bin/nmcli /usr/sbin/nmcli "
"/bin/nmcli /sbin/nmcli; do",
f"for firewall_candidate in {nmcli}; do",
).replace(
"for firewall_candidate in /usr/bin/stat /bin/stat /usr/sbin/stat "
"/sbin/stat; do",
f"for firewall_candidate in {stat_command}; do",
).replace(
"for firewall_candidate in /usr/bin/systemctl /bin/systemctl "
"/usr/sbin/systemctl /sbin/systemctl; do",
f"for firewall_candidate in {systemctl}; do",
).replace(
"/etc/NetworkManager/system-connections/",
f"{tmp_path}/",
)
result = subprocess.run(
shlex.split(command),
capture_output=True,
text=True,
check=False,
timeout=15,
)
assert result.returncode == 0, result.stderr
assert (
"__VCAP_NM_ZONE_BEGIN__\nbr0|public\nvnet3|?\n"
"__VCAP_NM_ZONE_END__=0"
) in result.stdout
assert calls.read_text(encoding="utf-8").splitlines()[-2:] == [
"-t --escape no -f UUID,DEVICE connection show --active",
"-t --escape no -f UUID,FILENAME connection show",
]
def test_capability_probe_command_executes_the_complete_wrapped_script():
@ -347,33 +234,8 @@ def test_capability_probe_command_executes_the_complete_wrapped_script():
assert result.stdout.rstrip().endswith("__VCAP_END__")
def test_zone_inventory_parsers_allow_bounded_guest_density():
firewalld = "\n".join(
["br0|public"]
+ [f"vnet{index}|public" for index in range(300)])
networkmanager = "\n".join(
["br0|public"]
+ [f"vnet{index}|" for index in range(300)])
firewall_ok, firewall_values = _parse_firewall_interface_zones(
firewalld, "0")
nm_ok, nm_values = _parse_networkmanager_interface_zones(
networkmanager, "0")
assert firewall_ok is True
assert firewall_values["br0"] == "public"
assert len(firewall_values) == 301
assert nm_ok is True
assert nm_values["br0"] == "public"
assert len(nm_values) == 301
def test_zone_inventory_parsers_reject_more_than_4096_interfaces():
oversized = "\n".join(
f"vnet{index}|public" for index in range(4097))
assert _parse_firewall_interface_zones(oversized, "0") == (False, {})
assert _parse_networkmanager_interface_zones(
oversized, "0") == (False, {})
class Runner:
@ -793,14 +655,14 @@ def test_stage_test_commit_writes_private_pinned_ssh_config(tmp_path):
"firewalld_active": False,
"firewalld_enabled": False,
"firewalld_load_state": "masked",
"firewalld_backend": "nftables",
"firewalld_table_owner": "yes",
"firewalld_source_zones": "absent",
"firewalld_default_runtime": "public",
"firewalld_default_permanent": "public",
"firewalld_runtime_nft": "ready",
"firewalld_interface_inventory_ready": True,
"firewalld_command_available": False,
"legacy_firewalld_table_present": False,
"legacy_manifest_state": "absent",
"fabric_transaction_state": "absent",
"emergency_owner_state": "absent",
"vpc_transaction_state": "absent",
"vpc_snapshot_state": "absent",
"fabric_desired_state": "absent",
"vpc_state": "absent",
"nftables_active": True,
"nftables_enabled": True,
"nftables_load_state": "loaded",
@ -974,118 +836,47 @@ def test_capability_probe_rejects_firewalld_enabled_for_next_boot():
assert capabilities["nftables"]["ready"] is False
assert capabilities["vpc_ready"] is False
assert "firewall_manager_conflict" in capabilities["reasons"]
assert "firewalld_unsupported_requires_maintenance" in capabilities["reasons"]
assert "firewall_owner_not_nftables" in capabilities["reasons"]
def firewalld_capability_output(
*, nft_active="inactive", nft_enabled="masked", nft_load="masked",
backend="nftables", table_owner="yes", source_zones="absent",
firewalld_enabled="enabled", default_runtime="public",
default_permanent="public", runtime_nft="ready",
*, firewalld_active="active", firewalld_enabled="enabled",
firewalld_load="loaded", nft_active="inactive",
nft_enabled="masked", nft_load="masked", live_table=False,
):
replacements = (
("__VCAP_TOOL__firewall_cmd=",
"__VCAP_TOOL__firewall_cmd=/usr/bin/firewall-cmd"),
("__VCAP_SERVICE__firewall=inactive",
"__VCAP_SERVICE__firewall=active"),
f"__VCAP_SERVICE__firewall={firewalld_active}"),
("__VCAP_SERVICE__nftables=active",
f"__VCAP_SERVICE__nftables={nft_active}"),
("__VCAP_SERVICE_ENABLED__firewall=masked",
f"__VCAP_SERVICE_ENABLED__firewall={firewalld_enabled}"),
("__VCAP_SERVICE_LOAD__firewall=masked",
"__VCAP_SERVICE_LOAD__firewall=loaded"),
f"__VCAP_SERVICE_LOAD__firewall={firewalld_load}"),
("__VCAP_SERVICE_ENABLED__nftables=enabled",
f"__VCAP_SERVICE_ENABLED__nftables={nft_enabled}"),
("__VCAP_SERVICE_LOAD__nftables=loaded",
f"__VCAP_SERVICE_LOAD__nftables={nft_load}"),
("__VCAP_FIREWALL_CONF__backend=nftables",
f"__VCAP_FIREWALL_CONF__backend={backend}"),
("__VCAP_FIREWALL_CONF__table_owner=yes",
f"__VCAP_FIREWALL_CONF__table_owner={table_owner}"),
("__VCAP_FIREWALL_CONF__source_zones=absent",
f"__VCAP_FIREWALL_CONF__source_zones={source_zones}"),
("__VCAP_FIREWALL_CONF__default_runtime=public",
f"__VCAP_FIREWALL_CONF__default_runtime={default_runtime}"),
("__VCAP_FIREWALL_CONF__default_permanent=public",
f"__VCAP_FIREWALL_CONF__default_permanent={default_permanent}"),
("__VCAP_FIREWALL_CONF__runtime_nft=ready",
f"__VCAP_FIREWALL_CONF__runtime_nft={runtime_nft}"),
)
output = CAPABILITY_OUTPUT
for old, new in replacements:
output = output.replace(old, new)
if live_table:
output = output.replace(
'{"nftables":[{"table":{"family":"inet","name":"filter"}}]}',
'{"nftables":[{"table":{"family":"inet","name":"filter"}},'
'{"table":{"family":"inet","name":"firewalld"}}]}',
)
return output
@pytest.mark.parametrize(("nft_active", "nft_enabled", "nft_load"), [
("inactive", "disabled", "loaded"),
("inactive", "masked", "masked"),
("unknown", "unknown", "not-found"),
])
def test_capability_probe_accepts_supported_firewalld_nft_owner(
nft_active, nft_enabled, nft_load,
):
capabilities = parse_host_capabilities(firewalld_capability_output(
nft_active=nft_active, nft_enabled=nft_enabled, nft_load=nft_load,
), public_network="bridge:br0")
assert capabilities["network"]["firewall_manager"] == "firewalld"
assert capabilities["network"]["firewall_mode"] == "firewalld_nft"
assert capabilities["nftables"]["firewall_mode"] == "firewalld_nft"
# Raw nft remains required for the panel-owned tables even though
# firewalld owns the host's primary firewall lifecycle.
assert capabilities["nftables"]["ready"] is True
assert capabilities["vpc_ready"] is True
assert capabilities["reasons"] == []
@pytest.mark.parametrize(("backend", "table_owner", "reason"), [
("iptables", "yes", "firewalld_backend_not_nftables"),
("unknown", "yes", "firewalld_backend_not_nftables"),
("nftables", "no", "firewalld_table_owner_not_enabled"),
("nftables", "unknown", "firewalld_table_owner_not_enabled"),
])
def test_capability_probe_rejects_unsupported_firewalld_configuration(
backend, table_owner, reason,
):
capabilities = parse_host_capabilities(firewalld_capability_output(
backend=backend, table_owner=table_owner,
), public_network="bridge:br0")
assert capabilities["network"]["firewall_mode"] == "unsupported"
assert capabilities["nftables"]["ready"] is False
assert capabilities["vpc_ready"] is False
assert reason in capabilities["reasons"]
@pytest.mark.parametrize(("default_runtime", "default_permanent"), [
("trusted", "trusted"),
("public", "drop"),
("unknown", "public"),
])
def test_capability_probe_rejects_unsafe_or_drifted_firewalld_default_zone(
default_runtime, default_permanent,
):
capabilities = parse_host_capabilities(firewalld_capability_output(
default_runtime=default_runtime,
default_permanent=default_permanent,
), public_network="bridge:br0")
assert capabilities["network"]["firewall_mode"] == "unsupported"
assert capabilities["nftables"]["ready"] is False
assert capabilities["vpc_ready"] is False
assert "firewalld_default_zone_unsafe_or_drifted" in capabilities["reasons"]
def test_capability_probe_requires_live_firewalld_nft_owner_evidence():
capabilities = parse_host_capabilities(firewalld_capability_output(
runtime_nft="unknown",
), public_network="bridge:br0")
assert capabilities["network"]["firewall_mode"] == "unsupported"
assert capabilities["nftables"]["ready"] is False
assert capabilities["vpc_ready"] is False
assert "firewalld_runtime_nft_backend_unverified" in capabilities["reasons"]
def test_capability_probe_rejects_runtime_only_firewalld_enablement():
@ -1096,7 +887,7 @@ def test_capability_probe_rejects_runtime_only_firewalld_enablement():
assert capabilities["network"]["firewall_manager"] == "firewalld"
assert capabilities["network"]["firewall_mode"] == "unsupported"
assert capabilities["vpc_ready"] is False
assert "firewalld_service_not_enabled" in capabilities["reasons"]
assert "firewalld_unsupported_requires_maintenance" in capabilities["reasons"]
def test_capability_probe_rejects_runtime_only_native_nft_enablement():
@ -1121,17 +912,9 @@ def test_capability_probe_rejects_an_active_competing_nftables_service():
assert capabilities["network"]["firewall_mode"] == "unsupported"
assert capabilities["nftables"]["ready"] is False
assert "firewall_manager_conflict" in capabilities["reasons"]
assert "firewalld_unsupported_requires_maintenance" in capabilities["reasons"]
@pytest.mark.parametrize("source_zones", ["present", "unknown"])
def test_capability_probe_rejects_firewalld_source_zone_ambiguity(source_zones):
capabilities = parse_host_capabilities(firewalld_capability_output(
source_zones=source_zones,
), public_network="bridge:br0")
assert capabilities["network"]["firewall_mode"] == "unsupported"
assert capabilities["nftables"]["ready"] is False
assert "firewalld_source_zones_present_or_unknown" in capabilities["reasons"]
def test_capability_probe_accepts_native_owner_when_firewalld_is_not_found():
@ -1163,7 +946,89 @@ def test_capability_probe_rejects_inactive_but_unmasked_firewalld_competitor():
native_capabilities = parse_host_capabilities(
native, public_network="bridge:br0")
assert native_capabilities["network"]["firewall_mode"] == "unsupported"
assert "firewall_competing_service_unknown" in native_capabilities["reasons"]
assert "firewalld_unsupported_requires_maintenance" in (
native_capabilities["reasons"])
@pytest.mark.parametrize(("family", "table"), (
("inet", "firewalld"),
("inet", "virt_cloud_fabric_emergency"),
("bridge", "virt_cloud_fabric_emergency"),
))
def test_capability_probe_rejects_live_legacy_firewall_table(family, table):
output = CAPABILITY_OUTPUT.replace(
'{"nftables":[{"table":{"family":"inet","name":"filter"}}]}',
'{"nftables":[{"table":{"family":"inet","name":"filter"}},'
f'{{"table":{{"family":"{family}","name":"{table}"}}}}]}}',
)
capabilities = parse_host_capabilities(
output, public_network="bridge:br0",
)
assert capabilities["network"]["firewall_manager"] == "nftables"
assert capabilities["network"]["firewall_mode"] == "unsupported"
assert capabilities["network"]["firewall_manager_evidence"][
"legacy_firewalld_table_present"] is True
assert capabilities["nftables"]["ready"] is False
assert capabilities["vpc_ready"] is False
assert "legacy_firewalld_state_requires_cleanup" in capabilities["reasons"]
@pytest.mark.parametrize(("marker", "reason"), (
("manifest", "legacy_firewalld_state_requires_cleanup"),
("vpc_snapshot", "legacy_firewalld_state_requires_cleanup"),
("fabric_desired_state", "legacy_firewalld_state_requires_cleanup"),
("vpc_state", "legacy_firewalld_state_requires_cleanup"),
("emergency_owner", "legacy_firewalld_state_requires_cleanup"),
("fabric_transaction", "firewall_transaction_requires_recovery_or_cleanup"),
("vpc_transaction", "firewall_transaction_requires_recovery_or_cleanup"),
))
def test_capability_probe_rejects_legacy_firewall_artifact(marker, reason):
output = CAPABILITY_OUTPUT.replace(
f"__VCAP_LEGACY_FIREWALL__{marker}=absent",
f"__VCAP_LEGACY_FIREWALL__{marker}=present",
)
capabilities = parse_host_capabilities(output, public_network="bridge:br0")
assert capabilities["probe_valid"] is True
assert capabilities["vpc_ready"] is False
assert capabilities["network"]["firewall_mode"] == "unsupported"
evidence_key = {
"manifest": "legacy_manifest_state",
"fabric_transaction": "fabric_transaction_state",
"emergency_owner": "emergency_owner_state",
"vpc_transaction": "vpc_transaction_state",
"vpc_snapshot": "vpc_snapshot_state",
}.get(marker, marker)
assert capabilities["network"]["firewall_manager_evidence"][
evidence_key
] == "present"
assert reason in capabilities["reasons"]
@pytest.mark.parametrize("failure", ("missing", "duplicate", "unknown"))
@pytest.mark.parametrize("marker", (
"manifest", "fabric_transaction", "emergency_owner", "vpc_transaction",
"vpc_snapshot", "fabric_desired_state", "vpc_state",
))
def test_capability_probe_fails_closed_on_invalid_legacy_firewall_evidence(
marker, failure,
):
line = f"__VCAP_LEGACY_FIREWALL__{marker}=absent"
if failure == "missing":
replacement = ""
elif failure == "duplicate":
replacement = line + "\n" + line
else:
replacement = f"__VCAP_LEGACY_FIREWALL__{marker}=unknown"
capabilities = parse_host_capabilities(
CAPABILITY_OUTPUT.replace(line, replacement),
public_network="bridge:br0",
)
assert capabilities["probe_valid"] is False
assert capabilities["vpc_ready"] is False
assert "legacy_firewall_evidence_invalid" in capabilities["reasons"]

@ -320,33 +320,28 @@ def test_rendered_data_plane_has_exact_routes_proxy_arp_and_atomic_nft_batch():
@pytest.mark.parametrize("mode", ("networkmanager_nmcli", "ifupdown"))
def test_rp_filter_is_set_before_first_up_and_reasserted_after_manager(mode):
script = render_apply_script(
_plan(), deployment_mode=mode, firewall_mode="firewalld_nft")
_plan(), deployment_mode=mode, firewall_mode="native_nftables")
guard = script.index(
"# Install and exactly read back the raw tenant guard")
calls = [match.start() for match in re.finditer(
r"^[ ]*vc_vpc_rp_filter_set \|\| exit 72$", script, re.MULTILINE)]
assert len(calls) == 4
assert len(calls) == 3
first_up = script.index('"$IP" link set dev "$BRIDGE" up', guard)
assert guard < calls[0] < first_up
if mode == "networkmanager_nmcli":
activation = script.index(
'"$NMCLI" connection up uuid "$NM_PROFILE_UUID"', first_up)
trusted = script.index("connection.zone trusted", activation)
else:
activation = script.index(
'VC_FABRIC_APPLYING=1 "$IFUP" --force "$BRIDGE"', first_up)
trusted = script.index(
'"$FIREWALL_CMD" --zone=trusted --add-interface="$BRIDGE"',
activation,
)
reassert = script.index("vc_vpc_rp_filter_set || exit 72", activation)
assert first_up < activation < reassert < trusted
assert first_up < activation < reassert
def test_rp_filter_failure_and_rollback_remain_fail_closed():
script = render_apply_script(
_plan(), firewall_mode="firewalld_nft")
_plan(), firewall_mode="native_nftables")
helper = _shell_block(
script, "vc_vpc_rp_filter_set() {", "vc_vpc_native_ifupdown_rollback_reopen() {")
assert helper.index("RP_FILTER_CHANGED=yes") < helper.index(
@ -365,9 +360,7 @@ def test_rp_filter_failure_and_rollback_remain_fail_closed():
'cat "$TXN/rp_filter.before" > '
'"/proc/sys/net/ipv4/conf/$BRIDGE/rp_filter"')
restore_nft = rollback.index('NFT_ROLLBACK="$TXN/rollback.nft"')
reopen_trusted = rollback.index(
'connection.zone trusted', restore_nft)
assert quarantine < restore_raw < restore_nft < reopen_trusted
assert quarantine < restore_raw < restore_nft
def test_sysctl_artifact_contract_binds_fixed_shape_and_identity(tmp_path):

File diff suppressed because it is too large Load Diff

@ -44,7 +44,6 @@ _GEN_NAME = re.compile(r"gen-[0-9a-f]{32}\Z")
_POOL_PATH = re.compile(r"/[A-Za-z0-9_.-]+(?:/[A-Za-z0-9_.-]+)*\Z")
_BRIDGE_NAME = re.compile(r"[A-Za-z0-9][A-Za-z0-9_.-]{0,14}\Z")
_IFACE_NAME = re.compile(r"[A-Za-z0-9_.:-]{1,15}\Z")
_FIREWALL_ZONE = re.compile(r"[A-Za-z0-9_-]{1,64}\Z")
PUBLIC_POOL_KEY = re.compile(r"[0-9a-f]{32}\Z")
PUBLIC_POOL_STATES = frozenset({"active", "draining", "disabled"})
MAX_PUBLIC_NETWORK_POOLS = 32
@ -95,7 +94,6 @@ probe_binary wg /usr/bin/wg /usr/sbin/wg /bin/wg /sbin/wg
probe_binary wg_quick /usr/bin/wg-quick /usr/sbin/wg-quick /bin/wg-quick /sbin/wg-quick
probe_binary ip /usr/sbin/ip /usr/bin/ip /sbin/ip /bin/ip
probe_binary nft /usr/sbin/nft /usr/bin/nft /sbin/nft /bin/nft
probe_binary firewall_cmd /usr/bin/firewall-cmd /usr/sbin/firewall-cmd /bin/firewall-cmd /sbin/firewall-cmd
probe_binary nmcli /usr/bin/nmcli /usr/sbin/nmcli /bin/nmcli /sbin/nmcli
probe_binary networkctl /usr/bin/networkctl /usr/sbin/networkctl /bin/networkctl /sbin/networkctl
probe_binary ifup /usr/sbin/ifup /usr/bin/ifup /sbin/ifup /bin/ifup
@ -160,7 +158,6 @@ for rp_file in /proc/sys/net/ipv4/conf/*/rp_filter; do
printf "__VCAP_RPF__%s=%s\n" "$rp_iface" "$rp_value"
done
firewall_service_state=unknown
probe_service() {
name="$1"
service="$2"
@ -174,7 +171,6 @@ probe_service() {
active|inactive|failed|activating|deactivating) ;;
*) status="unknown" ;;
esac
if test "$name" = firewall; then firewall_service_state="$status"; fi
printf "__VCAP_SERVICE__%s=%s\n" "$name" "$status"
}
probe_service network_manager NetworkManager
@ -220,341 +216,112 @@ probe_service_load() {
probe_service_load firewall firewalld
probe_service_load nftables nftables
# firewalld documents nftables/yes as the defaults when these keys (or the
# whole system configuration file) are absent. Project only those two
# normalized effective values; malformed, duplicate, or unsupported values
# remain unknown and fail closed in the parser.
firewall_backend=nftables
firewall_table_owner=yes
if test -e /etc/firewalld/firewalld.conf; then
if test -f /etc/firewalld/firewalld.conf && test ! -L /etc/firewalld/firewalld.conf; then
if test -x /usr/bin/grep; then firewall_grep=/usr/bin/grep; else firewall_grep=/bin/grep; fi
if test -x /usr/bin/tr; then firewall_tr=/usr/bin/tr; else firewall_tr=/bin/tr; fi
firewall_backend_lines=$($firewall_grep -E "^[[:space:]]*FirewallBackend[[:space:]]*=" /etc/firewalld/firewalld.conf 2>/dev/null || true)
firewall_owner_lines=$($firewall_grep -E "^[[:space:]]*NftablesTableOwner[[:space:]]*=" /etc/firewalld/firewalld.conf 2>/dev/null || true)
firewall_backend_count=$(printf "%s\n" "$firewall_backend_lines" | $firewall_grep -c "=" 2>/dev/null || true)
firewall_owner_count=$(printf "%s\n" "$firewall_owner_lines" | $firewall_grep -c "=" 2>/dev/null || true)
if test "$firewall_backend_count" = 1; then
firewall_backend=${firewall_backend_lines#*=}
firewall_backend=$(printf "%s" "$firewall_backend" | $firewall_tr -d "[:space:]")
elif test "$firewall_backend_count" != 0; then
firewall_backend=unknown
fi
if test "$firewall_owner_count" = 1; then
firewall_table_owner=${firewall_owner_lines#*=}
firewall_table_owner=$(printf "%s" "$firewall_table_owner" | $firewall_tr -d "[:space:]")
elif test "$firewall_owner_count" != 0; then
firewall_table_owner=unknown
fi
else
firewall_backend=unknown
firewall_table_owner=unknown
# Native nftables is the only supported firewall owner. firewalld service
# state remains in the probe solely as fail-closed migration evidence.
probe_legacy_firewall_path() {
name="$1"
path="$2"
state=absent
if test -e "$path" || test -L "$path"; then state=present; fi
printf "__VCAP_LEGACY_FIREWALL__%s=%s\n" "$name" "$state"
}
probe_legacy_firewall_path manifest /etc/virt-cloud/nftables.conf
probe_legacy_firewall_path fabric_transaction /etc/virt-cloud/.wg-fabric-txn
probe_legacy_firewall_path emergency_owner /run/virt-cloud/wg-fabric-emergency.owner
vpc_transaction_state=absent
for vpc_transaction in /etc/virt-cloud/.vpc-dataplane-*.txn; do
if test -e "$vpc_transaction" || test -L "$vpc_transaction"; then
vpc_transaction_state=present
break
fi
fi
case "$firewall_backend" in nftables|iptables) : ;; *) firewall_backend=unknown ;; esac
case "$firewall_table_owner" in yes|no) : ;; *) firewall_table_owner=unknown ;; esac
printf "__VCAP_FIREWALL_CONF__backend=%s\n" "$firewall_backend"
printf "__VCAP_FIREWALL_CONF__table_owner=%s\n" "$firewall_table_owner"
firewall_source_zones=unknown
firewall_cmd=
for firewall_candidate in /usr/bin/firewall-cmd /usr/sbin/firewall-cmd /bin/firewall-cmd /sbin/firewall-cmd; do
if test -x "$firewall_candidate"; then firewall_cmd="$firewall_candidate"; break; fi
done
if test "$firewall_service_state" = active && test -n "$firewall_cmd" &&
test "$($firewall_cmd --state 2>/dev/null)" = running; then
firewall_source_zones=absent
for firewall_scope in runtime permanent; do
if test "$firewall_scope" = permanent; then
firewall_zones=$($firewall_cmd --permanent --get-zones 2>/dev/null)
else
firewall_zones=$($firewall_cmd --get-zones 2>/dev/null)
fi
if test $? != 0; then firewall_source_zones=unknown; break; fi
firewall_zone_count=0
for firewall_zone in $firewall_zones; do
case "$firewall_zone" in ""|*[!A-Za-z0-9_-]*) firewall_source_zones=unknown; break 2 ;; esac
if test "${#firewall_zone}" -gt 64; then firewall_source_zones=unknown; break 2; fi
firewall_zone_count=$((firewall_zone_count + 1))
if test "$firewall_zone_count" -gt 64; then firewall_source_zones=unknown; break 2; fi
if test "$firewall_scope" = permanent; then
firewall_sources=$($firewall_cmd --permanent --zone="$firewall_zone" --list-sources 2>/dev/null)
else
firewall_sources=$($firewall_cmd --zone="$firewall_zone" --list-sources 2>/dev/null)
fi
if test $? != 0; then firewall_source_zones=unknown; break 2; fi
if test -n "$firewall_sources"; then firewall_source_zones=present; break 2; fi
done
if test "$firewall_zone_count" -eq 0; then firewall_source_zones=unknown; break; fi
done
fi
printf "__VCAP_FIREWALL_CONF__source_zones=%s\n" "$firewall_source_zones"
firewall_default_runtime=unknown
firewall_default_permanent=unknown
if test "$firewall_service_state" = active && test -n "$firewall_cmd" &&
test "$($firewall_cmd --state 2>/dev/null)" = running; then
firewall_default_runtime=$($firewall_cmd --get-default-zone 2>/dev/null)
if test $? != 0; then firewall_default_runtime=unknown; fi
# firewalld has one default zone for both views; --get-default-zone does not
# accept --permanent. Project the single authoritative value into both
# fields so the parser can retain its drift/fail-closed contract without
# invoking an unsupported CLI combination.
firewall_default_permanent=$firewall_default_runtime
case "$firewall_default_runtime" in ""|*[!A-Za-z0-9_-]*) firewall_default_runtime=unknown ;; esac
case "$firewall_default_permanent" in ""|*[!A-Za-z0-9_-]*) firewall_default_permanent=unknown ;; esac
if test "${#firewall_default_runtime}" -gt 64; then firewall_default_runtime=unknown; fi
if test "${#firewall_default_permanent}" -gt 64; then firewall_default_permanent=unknown; fi
fi
printf "__VCAP_FIREWALL_CONF__default_runtime=%s\n" "$firewall_default_runtime"
printf "__VCAP_FIREWALL_CONF__default_permanent=%s\n" "$firewall_default_permanent"
# Keep the interface-to-zone inventory bounded and syntactically closed. It
# is consumed only as structured evidence for the selected local Fabric
# endpoint; arbitrary firewalld output is never returned by the API.
probe_firewall_interfaces() {
firewall_iface_scope="$1"
printf "__VCAP_FIREWALL_IFACE_BEGIN__%s\n" "$firewall_iface_scope"
firewall_iface_status=1
if test "$firewall_service_state" = active && test -n "$firewall_cmd" &&
test "$($firewall_cmd --state 2>/dev/null)" = running; then
if test "$firewall_iface_scope" = permanent; then
firewall_iface_zones=$($firewall_cmd --permanent --get-zones 2>/dev/null)
else
firewall_iface_zones=$($firewall_cmd --get-zones 2>/dev/null)
fi
if test $? = 0; then
firewall_iface_status=0
firewall_iface_zone_count=0
firewall_iface_binding_count=0
for firewall_iface_zone in $firewall_iface_zones; do
case "$firewall_iface_zone" in ""|*[!A-Za-z0-9_-]*) firewall_iface_status=1; break ;; esac
if test "${#firewall_iface_zone}" -gt 64; then firewall_iface_status=1; break; fi
firewall_iface_zone_count=$((firewall_iface_zone_count + 1))
if test "$firewall_iface_zone_count" -gt 64; then firewall_iface_status=1; break; fi
if test "$firewall_iface_scope" = permanent; then
firewall_ifaces=$($firewall_cmd --permanent --zone="$firewall_iface_zone" --list-interfaces 2>/dev/null)
else
firewall_ifaces=$($firewall_cmd --zone="$firewall_iface_zone" --list-interfaces 2>/dev/null)
fi
if test $? != 0; then firewall_iface_status=1; break; fi
for firewall_iface in $firewall_ifaces; do
case "$firewall_iface" in ""|*[!A-Za-z0-9_.:-]*) firewall_iface_status=1; break 2 ;; esac
if test "${#firewall_iface}" -gt 15; then firewall_iface_status=1; break 2; fi
firewall_iface_binding_count=$((firewall_iface_binding_count + 1))
if test "$firewall_iface_binding_count" -gt 4096; then firewall_iface_status=1; break 2; fi
printf "%s|%s\n" "$firewall_iface" "$firewall_iface_zone"
done
done
if test "$firewall_iface_zone_count" -eq 0; then firewall_iface_status=1; fi
fi
printf "__VCAP_LEGACY_FIREWALL__vpc_transaction=%s\n" \
"$vpc_transaction_state"
vpc_snapshot_state=absent
for vpc_snapshot in \
/etc/virt-cloud/vpc-dataplane/*.nft.inet.live \
/etc/virt-cloud/vpc-dataplane/*.nft.bridge.live \
/etc/virt-cloud/vpc-dataplane/*.nft.arp.live; do
if test -e "$vpc_snapshot" || test -L "$vpc_snapshot"; then
vpc_snapshot_state=present
break
fi
printf "__VCAP_FIREWALL_IFACE_END__%s=%s\n" "$firewall_iface_scope" "$firewall_iface_status"
}
probe_firewall_interfaces runtime
probe_firewall_interfaces permanent
# For NetworkManager, permanent interface ownership lives in the active
# connection keyfile rather than in firewalld zone XML. Resolve every active
# interface through one UUID and parse only the exact [connection] zone key
# from a root-owned 0600 system profile. UUIDs, filenames and profile data
# are deliberately not emitted.
printf "%s\n" "__VCAP_NM_ZONE_BEGIN__"
firewall_nm_status=1
firewall_nmcli=
firewall_stat=
firewall_systemctl=
for firewall_candidate in /usr/bin/nmcli /usr/sbin/nmcli /bin/nmcli /sbin/nmcli; do
if test -x "$firewall_candidate"; then firewall_nmcli="$firewall_candidate"; break; fi
done
for firewall_candidate in /usr/bin/stat /bin/stat /usr/sbin/stat /sbin/stat; do
if test -x "$firewall_candidate"; then firewall_stat="$firewall_candidate"; break; fi
printf "__VCAP_LEGACY_FIREWALL__vpc_snapshot=%s\n" \
"$vpc_snapshot_state"
legacy_stat=
for legacy_tool in /usr/bin/stat /bin/stat /usr/sbin/stat /sbin/stat; do
if test -x "$legacy_tool"; then legacy_stat="$legacy_tool"; break; fi
done
for firewall_candidate in /usr/bin/systemctl /bin/systemctl /usr/sbin/systemctl /sbin/systemctl; do
if test -x "$firewall_candidate"; then firewall_systemctl="$firewall_candidate"; break; fi
legacy_awk=
for legacy_tool in /usr/bin/awk /bin/awk /usr/sbin/awk /sbin/awk; do
if test -x "$legacy_tool"; then legacy_awk="$legacy_tool"; break; fi
done
if test -n "$firewall_nmcli" && test -n "$firewall_stat" &&
test -n "$firewall_systemctl" &&
test "$($firewall_systemctl is-active NetworkManager 2>/dev/null)" = active; then
firewall_nm_active=$($firewall_nmcli -t --escape no -f UUID,DEVICE connection show --active 2>/dev/null)
firewall_nm_active_status=$?
firewall_nm_profiles=
firewall_nm_profiles_status=1
if test "$firewall_nm_active_status" = 0; then
# FILENAME is a list-mode field. It is not available as
# GENERAL.FILENAME in `connection show UUID` on current AlmaLinux 10.
# Capture one bounded inventory and resolve each active UUID exactly once;
# malformed rows, duplicate UUIDs and non-system keyfiles fail closed.
firewall_nm_profiles=$($firewall_nmcli -t --escape no -f UUID,FILENAME connection show 2>/dev/null)
firewall_nm_profiles_status=$?
fi
if test "$firewall_nm_active_status" = 0 &&
test "$firewall_nm_profiles_status" = 0 &&
test "${#firewall_nm_active}" -le 262144 &&
test "${#firewall_nm_profiles}" -le 262144; then
firewall_nm_status=0
firewall_nm_count=0
while IFS=: read -r firewall_nm_uuid firewall_nm_iface firewall_nm_extra; do
test -n "$firewall_nm_uuid$firewall_nm_iface$firewall_nm_extra" || continue
# Active profiles without a kernel device do not own an ingress zone.
test -n "$firewall_nm_iface" || continue
if test -n "$firewall_nm_extra"; then firewall_nm_status=1; break; fi
case "$firewall_nm_iface" in ""|*[!A-Za-z0-9_.-]*) firewall_nm_status=1; break ;; esac
if test "${#firewall_nm_iface}" -gt 15; then firewall_nm_status=1; break; fi
firewall_nm_count=$((firewall_nm_count + 1))
if test "$firewall_nm_count" -gt 4096; then firewall_nm_status=1; break; fi
firewall_nm_profile_valid=yes
case "$firewall_nm_uuid" in ????????-????-????-????-????????????) : ;; *) firewall_nm_profile_valid=no ;; esac
case "$firewall_nm_uuid" in *[!0-9A-Fa-f-]*) firewall_nm_profile_valid=no ;; esac
if test "$firewall_nm_profile_valid" != yes; then
printf "%s|?\n" "$firewall_nm_iface"
continue
fi
firewall_nm_file=
firewall_nm_file_count=0
firewall_nm_profile_count=0
firewall_nm_inventory_valid=yes
while IFS= read -r firewall_nm_profile_line || test -n "$firewall_nm_profile_line"; do
test -n "$firewall_nm_profile_line" || continue
firewall_nm_profile_count=$((firewall_nm_profile_count + 1))
if test "$firewall_nm_profile_count" -gt 4096; then
firewall_nm_inventory_valid=no
break
fi
case "$firewall_nm_profile_line" in
*:*) : ;;
*) firewall_nm_inventory_valid=no; break ;;
esac
firewall_nm_list_uuid=${firewall_nm_profile_line%%:*}
firewall_nm_list_file=${firewall_nm_profile_line#*:}
case "$firewall_nm_list_uuid" in ????????-????-????-????-????????????) : ;; *) firewall_nm_inventory_valid=no; break ;; esac
case "$firewall_nm_list_uuid" in *[!0-9A-Fa-f-]*) firewall_nm_inventory_valid=no; break ;; esac
if test "${#firewall_nm_list_file}" -gt 4096; then
firewall_nm_inventory_valid=no
break
fi
if test "$firewall_nm_list_uuid" = "$firewall_nm_uuid"; then
firewall_nm_file_count=$((firewall_nm_file_count + 1))
firewall_nm_file=$firewall_nm_list_file
fi
done <<__VCAP_NM_PROFILES__
$firewall_nm_profiles
__VCAP_NM_PROFILES__
if test "$firewall_nm_inventory_valid" != yes ||
test "$firewall_nm_file_count" != 1 || test -z "$firewall_nm_file"; then
printf "%s|?\n" "$firewall_nm_iface"
continue
fi
case "$firewall_nm_file" in
/etc/NetworkManager/system-connections/*.nmconnection) : ;;
*) printf "%s|?\n" "$firewall_nm_iface"; continue ;;
esac
if test ! -f "$firewall_nm_file" || test -L "$firewall_nm_file" ||
test "$($firewall_stat -c %u:%a "$firewall_nm_file" 2>/dev/null)" != 0:600; then
printf "%s|?\n" "$firewall_nm_iface"
continue
fi
firewall_nm_size=$($firewall_stat -c %s "$firewall_nm_file" 2>/dev/null)
case "$firewall_nm_size" in
""|*[!0-9]*) printf "%s|?\n" "$firewall_nm_iface"; continue ;;
esac
if test "$firewall_nm_size" -gt 65536; then
printf "%s|?\n" "$firewall_nm_iface"
continue
fi
firewall_nm_section=
firewall_nm_zone=
firewall_nm_zone_count=0
firewall_nm_line_count=0
firewall_nm_file_valid=yes
while IFS= read -r firewall_nm_line || test -n "$firewall_nm_line"; do
firewall_nm_line_count=$((firewall_nm_line_count + 1))
if test "$firewall_nm_line_count" -gt 4096; then firewall_nm_file_valid=no; break; fi
case "$firewall_nm_line" in
"[connection]") firewall_nm_section=connection ;;
\[*\]) firewall_nm_section=other ;;
zone=*)
if test "$firewall_nm_section" = connection; then
firewall_nm_zone_count=$((firewall_nm_zone_count + 1))
firewall_nm_zone=${firewall_nm_line#zone=}
fi
;;
esac
done < "$firewall_nm_file"
if test "$firewall_nm_file_valid" != yes || test "$firewall_nm_zone_count" -gt 1; then
printf "%s|?\n" "$firewall_nm_iface"
continue
fi
if test -n "$firewall_nm_zone"; then
case "$firewall_nm_zone" in
*[!A-Za-z0-9_-]*) printf "%s|?\n" "$firewall_nm_iface"; continue ;;
esac
if test "${#firewall_nm_zone}" -gt 64; then
printf "%s|?\n" "$firewall_nm_iface"
continue
fi
fi
printf "%s|%s\n" "$firewall_nm_iface" "$firewall_nm_zone"
done <<__VCAP_NM_ACTIVE__
$firewall_nm_active
__VCAP_NM_ACTIVE__
fabric_desired_state_legacy=absent
fabric_desired_state=/etc/virt-cloud/wg-fabric0.conf
if test -e "$fabric_desired_state" || test -L "$fabric_desired_state"; then
fabric_desired_state_legacy=unknown
if test -n "$legacy_stat" && test -n "$legacy_awk" &&
test -f "$fabric_desired_state" && ! test -L "$fabric_desired_state" &&
test "$("$legacy_stat" -c "%u:%g:%a" "$fabric_desired_state" 2>/dev/null)" = 0:0:600; then
fabric_desired_size=$("$legacy_stat" -c "%s" "$fabric_desired_state" 2>/dev/null)
case "$fabric_desired_size" in
""|*[!0-9]*) ;;
*)
if test "$fabric_desired_size" -le 65536 2>/dev/null; then
fabric_desired_state_legacy=$("$legacy_awk" -F"|" "
length(\$0)>4096 {unsafe=1}
\$1==\"firewall\" {firewall++; if (NF!=2 || \$2!=\"native_nftables\") legacy=1; next}
\$1==\"underlay\" || \$1==\"firewall_rule\" {legacy=1; next}
END {
if (legacy) print \"present\"
else if (unsafe || firewall>1) print \"unknown\"
else print \"absent\"
}
" "$fabric_desired_state" 2>/dev/null) || fabric_desired_state_legacy=unknown
fi ;;
esac
fi
fi
printf "__VCAP_NM_ZONE_END__=%s\n" "$firewall_nm_status"
# ifupdown hosts must not have a competing RHEL ifcfg zone owner for the
# endpoint interface. Only validated interface names are projected.
printf "%s\n" "__VCAP_IFCFG_ZONE_BEGIN__"
firewall_ifcfg_status=0
firewall_ifcfg_count=0
for firewall_ifcfg in /etc/sysconfig/network-scripts/ifcfg-*; do
if test ! -e "$firewall_ifcfg" && test ! -L "$firewall_ifcfg"; then continue; fi
firewall_ifcfg_iface=${firewall_ifcfg##*/ifcfg-}
case "$firewall_ifcfg_iface" in ""|*[!A-Za-z0-9_.:-]*) firewall_ifcfg_status=1; break ;; esac
if test "${#firewall_ifcfg_iface}" -gt 15; then firewall_ifcfg_status=1; break; fi
firewall_ifcfg_count=$((firewall_ifcfg_count + 1))
if test "$firewall_ifcfg_count" -gt 256; then firewall_ifcfg_status=1; break; fi
printf "%s\n" "$firewall_ifcfg_iface"
done
printf "__VCAP_IFCFG_ZONE_END__=%s\n" "$firewall_ifcfg_status"
firewall_runtime_nft=unknown
firewall_nft=
firewall_dd=
firewall_wc=
firewall_tr_runtime=
firewall_grep_runtime=
for firewall_candidate in /usr/sbin/nft /usr/bin/nft /sbin/nft /bin/nft; do
if test -x "$firewall_candidate"; then firewall_nft="$firewall_candidate"; break; fi
done
for firewall_candidate in /usr/bin/dd /bin/dd /usr/sbin/dd /sbin/dd; do
if test -x "$firewall_candidate"; then firewall_dd="$firewall_candidate"; break; fi
done
for firewall_candidate in /usr/bin/wc /bin/wc /usr/sbin/wc /sbin/wc; do
if test -x "$firewall_candidate"; then firewall_wc="$firewall_candidate"; break; fi
done
for firewall_candidate in /usr/bin/tr /bin/tr /usr/sbin/tr /sbin/tr; do
if test -x "$firewall_candidate"; then firewall_tr_runtime="$firewall_candidate"; break; fi
done
for firewall_candidate in /usr/bin/grep /bin/grep /usr/sbin/grep /sbin/grep; do
if test -x "$firewall_candidate"; then firewall_grep_runtime="$firewall_candidate"; break; fi
done
if test "$firewall_service_state" = active &&
test -n "$firewall_cmd" && test -n "$firewall_nft" && test -n "$firewall_dd" &&
test -n "$firewall_wc" && test -n "$firewall_tr_runtime" && test -n "$firewall_grep_runtime" &&
test "$($firewall_cmd --state 2>/dev/null)" = running; then
firewall_json=$($firewall_nft -j list table inet firewalld 2>/dev/null | $firewall_dd bs=262145 count=1 2>/dev/null)
firewall_json_size=$(printf "%s" "$firewall_json" | $firewall_wc -c 2>/dev/null || printf 262145)
firewall_json_size=$(printf "%s" "$firewall_json_size" | $firewall_tr_runtime -d "[:space:]" 2>/dev/null || printf 262145)
if test "$firewall_json_size" -gt 0 2>/dev/null && test "$firewall_json_size" -le 262144 2>/dev/null; then
firewall_compact=$(printf "%s" "$firewall_json" | $firewall_tr_runtime -d "[:space:]" 2>/dev/null)
firewall_table=$(printf "%s\n" "$firewall_compact" | $firewall_grep_runtime -Eo "\"table\":\\{[^{{}}]*\\}" 2>/dev/null | $firewall_grep_runtime -E "\"family\":\"inet\"" 2>/dev/null | $firewall_grep_runtime -E "\"name\":\"firewalld\"" 2>/dev/null)
firewall_table_count=$(printf "%s\n" "$firewall_table" | $firewall_grep_runtime -c "\"table\"" 2>/dev/null || true)
if test "$firewall_table_count" = 1 &&
printf "%s\n" "$firewall_table" | $firewall_grep_runtime -Eq "\"flags\":\\[[^]]*\"owner\"" 2>/dev/null &&
printf "%s\n" "$firewall_table" | $firewall_grep_runtime -Eq "\"flags\":\\[[^]]*\"persist\"" 2>/dev/null; then
firewall_runtime_nft=ready
fi
printf "__VCAP_LEGACY_FIREWALL__fabric_desired_state=%s\n" \
"$fabric_desired_state_legacy"
vpc_state_legacy=absent
vpc_state_count=0
for vpc_state_file in /etc/virt-cloud/vpc-dataplane/*.state; do
test -e "$vpc_state_file" || test -L "$vpc_state_file" || continue
vpc_state_count=$((vpc_state_count + 1))
if test "$vpc_state_count" -gt 256 || test -z "$legacy_stat" ||
test -z "$legacy_awk" || ! test -f "$vpc_state_file" ||
test -L "$vpc_state_file" ||
! test "$("$legacy_stat" -c "%u:%g:%a" "$vpc_state_file" 2>/dev/null)" = 0:0:600; then
vpc_state_legacy=unknown
break
fi
fi
printf "__VCAP_FIREWALL_CONF__runtime_nft=%s\n" "$firewall_runtime_nft"
vpc_state_size=$("$legacy_stat" -c "%s" "$vpc_state_file" 2>/dev/null)
case "$vpc_state_size" in
""|*[!0-9]*) vpc_state_legacy=unknown; break ;;
esac
if ! test "$vpc_state_size" -le 65536 2>/dev/null; then
vpc_state_legacy=unknown
break
fi
vpc_state_result=$("$legacy_awk" -F"|" "
length(\$0)>4096 {unsafe=1}
\$1==\"firewall_mode\" {firewall++; if (NF!=2 || \$2!=\"native_nftables\") legacy=1; next}
\$1==\"nft_snapshot\" {legacy=1; next}
END {
if (legacy) print \"present\"
else if (unsafe || firewall>1) print \"unknown\"
else print \"absent\"
}
" "$vpc_state_file" 2>/dev/null) || vpc_state_result=unknown
case "$vpc_state_result" in
present) vpc_state_legacy=present; break ;;
absent) : ;;
*) vpc_state_legacy=unknown; break ;;
esac
done
printf "__VCAP_LEGACY_FIREWALL__vpc_state=%s\n" "$vpc_state_legacy"
# ifupdown ownership is represented by bounded facts only. The contents of
# interfaces files can include addresses, credentials, and arbitrary hooks;
@ -1189,23 +956,6 @@ def _capability_section(output: str, begin: str, end: str) -> str | None:
return output[start:finish]
def _capability_status_section(
output: str,
begin: str,
end_prefix: str,
) -> tuple[str | None, str | None]:
"""Return one bounded section followed by its exact status marker."""
if output.count(begin) != 1:
return None, None
start = output.find(begin) + len(begin)
finish = output.find(end_prefix, start)
if (finish < 0 or finish - start > _MAX_CAPABILITY_OUTPUT
or output.find(end_prefix, finish + len(end_prefix)) >= 0):
return None, None
status_line = output[finish:].splitlines()[0]
return output[start:finish], status_line[len(end_prefix):].strip()
def _capability_lines(output: str, prefix: str) -> dict[str, str]:
values: dict[str, str] = {}
for line in output.splitlines():
@ -1361,76 +1111,6 @@ def _parse_local_ipv4_addresses(
)
def _parse_firewall_interface_zones(
section: str | None,
status: str | None,
) -> tuple[bool, dict[str, str]]:
"""Parse a bounded ``interface|zone`` inventory without partial use."""
if section is None or status != "0":
return False, {}
values: dict[str, str] = {}
lines = section.splitlines()
if len(lines) > 4096:
return False, {}
for line in lines:
interface, separator, zone = line.partition("|")
if (not separator or "|" in zone
or _IFACE_NAME.fullmatch(interface) is None
or _FIREWALL_ZONE.fullmatch(zone) is None
or interface in values):
return False, {}
values[interface] = zone
return True, values
def _parse_networkmanager_interface_zones(
section: str | None,
status: str | None,
) -> tuple[bool, dict[str, str]]:
"""Parse active interface to persistent NM zone (blank means default).
``?`` is a per-interface fail-closed sentinel for an active in-memory,
external, ambiguous, or otherwise unverifiable profile. It must not make
an unrelated, fully verified endpoint unusable.
"""
if section is None or status != "0":
return False, {}
values: dict[str, str] = {}
lines = section.splitlines()
if len(lines) > 4096:
return False, {}
for line in lines:
interface, separator, zone = line.partition("|")
if (not separator or "|" in zone
or _IFACE_NAME.fullmatch(interface) is None
or (zone not in {"", "?"}
and _FIREWALL_ZONE.fullmatch(zone) is None)):
return False, {}
if interface in values:
# Multiple active profiles for one device are ambiguous even when
# they currently report the same zone.
values[interface] = "?"
else:
values[interface] = zone
return True, values
def _parse_ifcfg_interfaces(
section: str | None,
status: str | None,
) -> tuple[bool, list[str]]:
if section is None or status != "0":
return False, []
lines = section.splitlines()
if len(lines) > 256:
return False, []
if any(_IFACE_NAME.fullmatch(line) is None for line in lines):
return False, []
if len(set(lines)) != len(lines):
return False, []
return True, sorted(lines)
def _parse_integer(value: str | None) -> int | None:
if value is None or not re.fullmatch(r"[0-9]+", value.strip()):
return None
@ -1440,18 +1120,46 @@ def _parse_integer(value: str | None) -> int | None:
return None
def _parse_nft_tables(section: str | None, status: str | None) -> bool:
"""Confirm that the read-only nft probe returned valid JSON."""
def _parse_nft_tables(
section: str | None,
status: str | None,
) -> tuple[bool, set[tuple[str, str]]]:
"""Parse the bounded native nft table inventory.
Table names are retained only to reject stale firewalld ownership and
retired emergency tables. The platform never reads or edits them.
"""
if section is None or status != "0":
return False
return False, set()
try:
payload = json.loads(section.strip())
except (TypeError, ValueError):
return False
# ``nft -j list tables`` returns an object in newer nft versions and a
# list in a few vendor builds. Both are evidence that the command ran;
# arbitrary text is not.
return isinstance(payload, (dict, list)) and len(section) <= _MAX_CAPABILITY_OUTPUT
return False, set()
if len(section) > _MAX_CAPABILITY_OUTPUT:
return False, set()
if isinstance(payload, dict):
records = payload.get("nftables")
elif isinstance(payload, list):
records = payload
else:
return False, set()
if not isinstance(records, list):
return False, set()
tables: set[tuple[str, str]] = set()
for record in records:
if not isinstance(record, dict):
return False, set()
table = record.get("table")
if table is None:
continue
if not isinstance(table, dict):
return False, set()
family = table.get("family")
name = table.get("name")
if not isinstance(family, str) or not isinstance(name, str):
return False, set()
tables.add((family, name))
return True, tables
def parse_host_capabilities(
@ -1479,20 +1187,15 @@ def parse_host_capabilities(
"__VCAP_IP_BEGIN__bridges\n", "__VCAP_IP_END__bridges=",
"__VCAP_IP_BEGIN__wireguard\n", "__VCAP_IP_END__wireguard=",
"__VCAP_NFT_BEGIN__\n", "__VCAP_NFT_END__",
"__VCAP_FIREWALL_CONF__backend=",
"__VCAP_FIREWALL_CONF__table_owner=",
"__VCAP_FIREWALL_CONF__source_zones=",
"__VCAP_FIREWALL_CONF__default_runtime=",
"__VCAP_FIREWALL_CONF__default_permanent=",
"__VCAP_FIREWALL_CONF__runtime_nft=",
"__VCAP_FIREWALL_IFACE_BEGIN__runtime\n",
"__VCAP_FIREWALL_IFACE_END__runtime=",
"__VCAP_FIREWALL_IFACE_BEGIN__permanent\n",
"__VCAP_FIREWALL_IFACE_END__permanent=",
"__VCAP_NM_ZONE_BEGIN__\n", "__VCAP_NM_ZONE_END__=",
"__VCAP_IFCFG_ZONE_BEGIN__\n", "__VCAP_IFCFG_ZONE_END__=",
"__VCAP_SERVICE_LOAD__firewall=",
"__VCAP_SERVICE_LOAD__nftables=",
"__VCAP_LEGACY_FIREWALL__manifest=",
"__VCAP_LEGACY_FIREWALL__fabric_transaction=",
"__VCAP_LEGACY_FIREWALL__emergency_owner=",
"__VCAP_LEGACY_FIREWALL__vpc_transaction=",
"__VCAP_LEGACY_FIREWALL__vpc_snapshot=",
"__VCAP_LEGACY_FIREWALL__fabric_desired_state=",
"__VCAP_LEGACY_FIREWALL__vpc_state=",
"__VCAP_END__",
)
protocol_ok = all(section in output for section in required_sections)
@ -1507,7 +1210,8 @@ def parse_host_capabilities(
services = _capability_lines(output, "__VCAP_SERVICE__")
service_enabled = _capability_lines(output, "__VCAP_SERVICE_ENABLED__")
service_load = _capability_lines(output, "__VCAP_SERVICE_LOAD__")
firewall_conf = _capability_lines(output, "__VCAP_FIREWALL_CONF__")
legacy_firewall = _capability_lines(
output, "__VCAP_LEGACY_FIREWALL__")
files = _capability_lines(output, "__VCAP_FILE__")
rp_filter_interfaces = {
name: parsed for name, raw in _capability_named_lines(
@ -1551,30 +1255,6 @@ def parse_host_capabilities(
_parse_local_ipv4_addresses(
ip_sections.get("addresses"), ip_statuses.get("addresses"))
)
firewall_runtime_section, firewall_runtime_status = (
_capability_status_section(
output, "__VCAP_FIREWALL_IFACE_BEGIN__runtime\n",
"__VCAP_FIREWALL_IFACE_END__runtime="))
firewall_permanent_section, firewall_permanent_status = (
_capability_status_section(
output, "__VCAP_FIREWALL_IFACE_BEGIN__permanent\n",
"__VCAP_FIREWALL_IFACE_END__permanent="))
firewall_runtime_zones_valid, firewall_runtime_interface_zones = (
_parse_firewall_interface_zones(
firewall_runtime_section, firewall_runtime_status))
firewall_permanent_zones_valid, firewall_permanent_interface_zones = (
_parse_firewall_interface_zones(
firewall_permanent_section, firewall_permanent_status))
nm_zone_section, nm_zone_status = _capability_status_section(
output, "__VCAP_NM_ZONE_BEGIN__\n", "__VCAP_NM_ZONE_END__=")
nm_zones_valid, nm_persistent_interface_zones = (
_parse_networkmanager_interface_zones(
nm_zone_section, nm_zone_status))
ifcfg_section, ifcfg_status = _capability_status_section(
output, "__VCAP_IFCFG_ZONE_BEGIN__\n",
"__VCAP_IFCFG_ZONE_END__=")
ifcfg_interfaces_valid, ifcfg_zone_interfaces = _parse_ifcfg_interfaces(
ifcfg_section, ifcfg_status)
ip_probe_valid = bool(
_valid_json_interfaces(
ip_sections.get("links"), ip_statuses.get("links"))
@ -1596,7 +1276,7 @@ def parse_host_capabilities(
for name in (
"wg", "wg_quick", "ip", "nft", "nmcli", "networkctl",
"ifup", "ifdown", "ifquery", "ifreload", "flock", "systemctl",
"modinfo", "dnf", "apt_get", "firewall_cmd",
"modinfo", "dnf", "apt_get",
)
}
os_id = os_values.get("ID", "").lower()
@ -1729,28 +1409,6 @@ def parse_host_capabilities(
or (services.get("firewall") == "inactive"
and service_enabled.get("firewall") == "masked")
)
# nftables.service has no D-Bus activation path. On a firewalld host an
# inactive disabled (or masked/absent) unit follows the documented
# single-manager setup and cannot spontaneously take ownership.
nftables_cannot_take_over = bool(
nftables_load == "not-found"
or (services.get("nftables") == "inactive"
and service_enabled.get("nftables") in {"disabled", "masked"})
)
firewalld_backend = firewall_conf.get("backend", "unknown")
firewalld_table_owner = firewall_conf.get("table_owner", "unknown")
firewalld_source_zones = firewall_conf.get("source_zones", "unknown")
firewalld_default_runtime = firewall_conf.get("default_runtime", "unknown")
firewalld_default_permanent = firewall_conf.get(
"default_permanent", "unknown")
firewalld_runtime_nft = firewall_conf.get("runtime_nft", "unknown")
firewalld_interface_inventory_ready = bool(
firewall_runtime_zones_valid and firewall_permanent_zones_valid
and (
(network_manager == "networkmanager" and nm_zones_valid)
or (network_manager == "ifupdown" and ifcfg_interfaces_valid)
)
)
firewall_managers = {
# An enabled-but-currently-inactive service can take ownership after
# a reboot. Treat it as ownership evidence so Fabric never installs
@ -1764,9 +1422,7 @@ def parse_host_capabilities(
elif len(active_firewall_managers) > 1:
firewall_manager = "conflict"
elif (services.get("firewall") == "unknown"
and services.get("nftables") == "unknown"
and not firewalld_cannot_take_over
and not nftables_cannot_take_over):
and services.get("nftables") == "unknown"):
firewall_manager = "unknown"
else:
firewall_manager = "unmanaged"
@ -1798,7 +1454,59 @@ def parse_host_capabilities(
# into a safe fabric interface.
fabric_interface_present = WG_FABRIC_INTERFACE in all_interfaces
fabric_interface_is_wireguard = WG_FABRIC_INTERFACE in wireguard_names
nft_readable = _parse_nft_tables(nft_section, nft_status)
nft_readable, nft_tables = _parse_nft_tables(nft_section, nft_status)
legacy_firewalld_table_present = bool(
("inet", "firewalld") in nft_tables
or ("inet", "virt_cloud_fabric_emergency") in nft_tables
or ("bridge", "virt_cloud_fabric_emergency") in nft_tables
)
legacy_manifest_state = legacy_firewall.get("manifest", "unknown")
fabric_transaction_state = legacy_firewall.get(
"fabric_transaction", "unknown")
emergency_owner_state = legacy_firewall.get(
"emergency_owner", "unknown")
vpc_transaction_state = legacy_firewall.get(
"vpc_transaction", "unknown")
vpc_snapshot_state = legacy_firewall.get("vpc_snapshot", "unknown")
fabric_desired_state = legacy_firewall.get(
"fabric_desired_state", "unknown")
vpc_legacy_state = legacy_firewall.get("vpc_state", "unknown")
legacy_firewall_evidence_valid = all(
state in {"absent", "present"}
for state in (
legacy_manifest_state,
fabric_transaction_state,
emergency_owner_state,
vpc_transaction_state,
vpc_snapshot_state,
fabric_desired_state,
vpc_legacy_state,
)
) and all(
sum(
line.startswith(
f"__VCAP_LEGACY_FIREWALL__{name}=")
for line in output.splitlines()
) == 1
for name in (
"manifest", "fabric_transaction", "emergency_owner",
"vpc_transaction",
"vpc_snapshot",
"fabric_desired_state", "vpc_state",
)
)
protocol_ok = protocol_ok and legacy_firewall_evidence_valid
legacy_manifest_present = legacy_manifest_state == "present"
legacy_vpc_snapshot_present = vpc_snapshot_state == "present"
legacy_emergency_owner_present = emergency_owner_state == "present"
legacy_desired_state_present = bool(
fabric_desired_state == "present"
or vpc_legacy_state == "present"
)
firewall_transaction_present = bool(
fabric_transaction_state == "present"
or vpc_transaction_state == "present"
)
# This is only a capability result: a later reconciler still has to create
# and own a dedicated private ACL table, then read it back before marking
# a VPC revision active. An unknown or unmanaged firewall is rejected so
@ -1811,31 +1519,17 @@ def parse_host_capabilities(
and nftables_enabled
and nftables_load == "loaded"
and firewalld_cannot_take_over
and not legacy_firewalld_table_present
and legacy_firewall_evidence_valid
and not legacy_manifest_present
and not legacy_emergency_owner_present
and not legacy_vpc_snapshot_present
and not legacy_desired_state_present
and not firewall_transaction_present
)
firewalld_nft_ready = bool(
tool_state["nft"]["available"]
and nft_readable
and firewall_manager == "firewalld"
and firewalld_active
and firewalld_enabled
and firewalld_load == "loaded"
and nftables_cannot_take_over
and tool_state["firewall_cmd"]["available"]
and firewalld_backend == "nftables"
and firewalld_table_owner == "yes"
and firewalld_source_zones == "absent"
and firewalld_default_runtime not in {"unknown", "trusted"}
and firewalld_default_runtime == firewalld_default_permanent
and firewalld_runtime_nft == "ready"
and firewalld_interface_inventory_ready
)
if native_nftables_ready:
firewall_mode = "native_nftables"
elif firewalld_nft_ready:
firewall_mode = "firewalld_nft"
else:
firewall_mode = "unsupported"
nft_ready = native_nftables_ready or firewalld_nft_ready
firewall_mode = (
"native_nftables" if native_nftables_ready else "unsupported")
nft_ready = native_nftables_ready
forwarding_ready = ip_forward == 1
selector = public_network if isinstance(public_network, str) else ""
if selector.startswith("bridge:"):
@ -1922,47 +1616,29 @@ def parse_host_capabilities(
elif not nftables_enabled:
reasons.append("nftables_service_not_enabled")
if not firewalld_cannot_take_over:
reasons.append("firewall_competing_service_unknown")
reasons.append("firewalld_unsupported_requires_maintenance")
elif firewall_manager == "firewalld":
if not firewalld_active:
reasons.append("firewalld_service_not_active")
if not firewalld_enabled:
reasons.append("firewalld_service_not_enabled")
if not tool_state["firewall_cmd"]["available"]:
reasons.append("firewalld_command_missing")
if firewalld_backend != "nftables":
reasons.append("firewalld_backend_not_nftables")
if firewalld_table_owner != "yes":
reasons.append("firewalld_table_owner_not_enabled")
if firewalld_source_zones != "absent":
reasons.append("firewalld_source_zones_present_or_unknown")
if (firewalld_default_runtime in {"unknown", "trusted"}
or firewalld_default_runtime != firewalld_default_permanent):
reasons.append("firewalld_default_zone_unsafe_or_drifted")
if firewalld_runtime_nft != "ready":
reasons.append("firewalld_runtime_nft_backend_unverified")
if not firewalld_interface_inventory_ready:
reasons.append("firewalld_endpoint_zone_unverified")
if not nftables_cannot_take_over:
reasons.append("firewall_manager_conflict")
reasons.append("firewalld_unsupported_requires_maintenance")
elif firewall_manager == "conflict":
reasons.append("firewall_manager_conflict")
reasons.append("firewalld_unsupported_requires_maintenance")
else:
reasons.append("firewall_owner_unsupported")
if firewall_mode == "unsupported" and not any(
reason in reasons for reason in (
"nftables_service_not_active", "nftables_service_not_enabled",
"firewalld_service_not_active", "firewalld_service_not_enabled",
"firewalld_command_missing", "firewalld_backend_not_nftables",
"firewalld_table_owner_not_enabled", "firewall_manager_conflict",
"firewalld_source_zones_present_or_unknown",
"firewalld_default_zone_unsafe_or_drifted",
"firewalld_runtime_nft_backend_unverified",
"firewalld_endpoint_zone_unverified",
"firewall_competing_service_unknown",
"firewall_owner_unsupported",
)
):
if legacy_firewalld_table_present:
reasons.append("legacy_firewalld_state_requires_cleanup")
if legacy_manifest_present:
reasons.append("legacy_firewalld_state_requires_cleanup")
if legacy_emergency_owner_present:
reasons.append("legacy_firewalld_state_requires_cleanup")
if legacy_vpc_snapshot_present:
reasons.append("legacy_firewalld_state_requires_cleanup")
if legacy_desired_state_present:
reasons.append("legacy_firewalld_state_requires_cleanup")
if firewall_transaction_present:
reasons.append("firewall_transaction_requires_recovery_or_cleanup")
if not legacy_firewall_evidence_valid:
reasons.append("legacy_firewall_evidence_invalid")
if firewall_mode == "unsupported":
reasons.append("firewall_mode_unsupported")
if firewall_mode == "unsupported" and firewall_manager != "nftables":
# Preserve the established coarse reason for older callers while the
@ -2029,14 +1705,11 @@ def parse_host_capabilities(
"wireguard_kernel_unavailable", "iproute2_missing", "nftables_tool_missing",
"nftables_probe_failed", "firewall_owner_not_nftables",
"firewall_owner_unsupported", "firewall_mode_unsupported",
"firewall_manager_conflict", "firewalld_service_not_active",
"firewalld_service_not_enabled", "firewalld_command_missing",
"firewalld_backend_not_nftables",
"firewalld_table_owner_not_enabled",
"firewalld_source_zones_present_or_unknown",
"firewalld_runtime_nft_backend_unverified",
"firewalld_endpoint_zone_unverified",
"firewall_competing_service_unknown",
"firewall_manager_conflict",
"firewalld_unsupported_requires_maintenance",
"legacy_firewalld_state_requires_cleanup",
"firewall_transaction_requires_recovery_or_cleanup",
"legacy_firewall_evidence_invalid",
"nftables_service_not_active", "nftables_service_not_enabled",
"iproute2_probe_failed", "flock_missing",
"ipv4_forwarding_disabled_or_unknown", "rp_filter_not_compatible",
@ -2044,7 +1717,7 @@ def parse_host_capabilities(
"network_manager_unknown", "network_manager_policy_mismatch",
"systemd_networkd_not_supported", "networkmanager_nmcli_missing",
"networkmanager_service_not_active", "networkmanager_service_not_enabled",
"ifupdown_tools_missing", "ifupdown_configuration_missing",
"ifupdown_tools_missing", "ifupdown_configuration_missing",
"ifupdown_interfaces_d_not_included",
"ifupdown_service_not_active_or_enabled",
))
@ -2103,16 +1776,15 @@ def parse_host_capabilities(
"firewalld_active": firewalld_active,
"firewalld_enabled": firewalld_enabled,
"firewalld_load_state": firewalld_load,
"firewalld_backend": firewalld_backend,
"firewalld_table_owner": firewalld_table_owner,
"firewalld_source_zones": firewalld_source_zones,
"firewalld_default_runtime": firewalld_default_runtime,
"firewalld_default_permanent": firewalld_default_permanent,
"firewalld_runtime_nft": firewalld_runtime_nft,
"firewalld_interface_inventory_ready":
firewalld_interface_inventory_ready,
"firewalld_command_available": bool(
tool_state["firewall_cmd"]["available"]),
"legacy_firewalld_table_present":
legacy_firewalld_table_present,
"legacy_manifest_state": legacy_manifest_state,
"fabric_transaction_state": fabric_transaction_state,
"emergency_owner_state": emergency_owner_state,
"vpc_transaction_state": vpc_transaction_state,
"vpc_snapshot_state": vpc_snapshot_state,
"fabric_desired_state": fabric_desired_state,
"vpc_state": vpc_legacy_state,
"nftables_active": nftables_active,
"nftables_enabled": nftables_enabled,
"nftables_load_state": nftables_load,
@ -2121,17 +1793,7 @@ def parse_host_capabilities(
"bridges": bridge_names,
"interfaces": all_interfaces,
"local_ipv4_addresses": local_ipv4_addresses,
# These maps are retained for the coordinator's endpoint-specific
# readiness check. The public projection exposes only the one
# selected interface and its normalized effective zones.
"local_ipv4_interfaces": local_ipv4_interfaces,
"firewalld_runtime_interface_zones":
firewall_runtime_interface_zones,
"firewalld_permanent_interface_zones":
firewall_permanent_interface_zones,
"networkmanager_persistent_interface_zones":
nm_persistent_interface_zones,
"ifcfg_zone_interfaces": ifcfg_zone_interfaces,
"wireguard_interfaces": wireguard_names,
"ip_forward": ip_forward,
# ``rp_filter`` is the established name for ``conf/all``. Keep it

File diff suppressed because it is too large Load Diff

@ -67,8 +67,10 @@ final class CloudAdminFabricService
'fabric_endpoint_invalid', 'fabric_endpoint_missing',
'fabric_endpoint_mismatch', 'fabric_endpoint_not_local',
'fabric_endpoint_vpc_conflict', 'fabric_vpc_record_corrupt',
'firewalld_endpoint_zone_unverified',
'firewalld_endpoint_zone_unsafe_or_drifted',
'firewalld_unsupported_requires_maintenance',
'legacy_firewalld_state_requires_cleanup',
'firewall_transaction_requires_recovery_or_cleanup',
'legacy_firewall_evidence_invalid',
'fabric_host_identity_mismatch', 'fabric_host_interface_conflict',
'fabric_host_firewall_mode_conflict', 'fabric_host_key_locked',
'fabric_host_network_manager_conflict',
@ -1693,9 +1695,7 @@ final class CloudAdminFabricService
? $item['capabilities'] : [];
foreach (['os_id', 'os_version', 'network_manager',
'network_manager_expected', 'deployment_mode', 'firewall_manager',
'firewall_mode', 'underlay_interface',
'underlay_runtime_zone', 'underlay_permanent_zone',
'public_selector'] as $key) {
'firewall_mode', 'underlay_interface', 'public_selector'] as $key) {
if (is_string($rawCapabilities[$key] ?? null)
&& strlen($rawCapabilities[$key]) <= 128
&& preg_match('/[\x00-\x1f\x7f]/', $rawCapabilities[$key]) !== 1) {
@ -1725,6 +1725,18 @@ final class CloudAdminFabricService
$capabilities[$key] = null;
}
}
$nativeNftables = ($rawCapabilities['firewall_manager'] ?? null)
=== 'nftables'
&& ($rawCapabilities['firewall_mode'] ?? null)
=== 'native_nftables';
if (!$nativeNftables) {
$reasons[] = (($rawCapabilities['firewall_manager'] ?? null)
=== 'firewalld'
|| ($rawCapabilities['firewall_mode'] ?? null)
=== 'firewalld_nft')
? 'firewalld_unsupported_requires_maintenance'
: 'firewall_mode_unsupported';
}
$result[$hostId] = [
'configured' => ($item['configured'] ?? false) === true,
'reachable' => ($item['reachable'] ?? false) === true,
@ -1732,7 +1744,8 @@ final class CloudAdminFabricService
'endpoint_ip' => $endpoint,
'endpoint_source' => $endpointSource,
'probed_at' => max(0, (int) ($item['probed_at'] ?? time())),
'vpc_ready' => ($item['vpc_ready'] ?? false) === true,
'vpc_ready' => $nativeNftables
&& ($item['vpc_ready'] ?? false) === true,
'reasons' => array_values(array_unique($reasons)),
'capabilities' => $capabilities,
];

@ -308,8 +308,10 @@ final class CloudEngineClient
'fabric_endpoint_rp_filter_unverified' => '无法确认 Fabric 传输接口的 rp_filter',
'fabric_endpoint_vpc_conflict' => 'Fabric 传输地址与现有 VPC CIDR 冲突',
'fabric_vpc_record_corrupt' => 'VPC 资源目录损坏,无法确认 Fabric 地址安全性',
'firewalld_endpoint_zone_unverified' => '无法确认 Fabric 传输接口的 firewalld 区域',
'firewalld_endpoint_zone_unsafe_or_drifted' => 'Fabric 传输接口的 firewalld 运行态与持久区域不一致或不安全',
'firewalld_unsupported_requires_maintenance' => 'firewalld 不再受支持;请在维护窗口清理旧所有权状态并启用原生 nftables',
'legacy_firewalld_state_requires_cleanup' => '检测到旧 firewalld 规则或事务状态;必须在维护窗口备份并清理后重建原生 nftables 数据面',
'firewall_transaction_requires_recovery_or_cleanup' => '检测到未收敛的防火墙事务;请先完成恢复或在维护窗口清理',
'legacy_firewall_evidence_invalid' => '无法安全核验宿主的旧防火墙状态;已禁止 VPC 变更',
'fabric_host_firewall_mode_conflict' => '宿主机防火墙与 Fabric 部署模式冲突',
'fabric_host_network_manager_conflict' => '宿主机网络管理器与 Fabric 部署模式冲突',
'fabric_identity_conflict' => 'Fabric 宿主机公钥身份冲突',

@ -202,16 +202,10 @@ const reasonLabels = {
firewall_mode_unsupported: '防火墙运行模式不受支持',
firewall_manager_conflict: 'firewalld 与 nftables 服务存在所有权冲突',
firewall_competing_service_unknown: '无法排除另一防火墙服务在重启后接管',
firewalld_service_not_active: 'firewalld 服务未运行',
firewalld_service_not_enabled: 'firewalld 服务未启用',
firewalld_command_missing: '缺少 firewall-cmd',
firewalld_backend_not_nftables: 'firewalld 后端不是 nftables',
firewalld_table_owner_not_enabled: 'firewalld 未启用 nftables 表所有权保护',
firewalld_runtime_nft_backend_unverified: '无法核验 firewalld 当前 nft 表的所有权与持久属性',
firewalld_default_zone_unsafe_or_drifted: 'firewalld 默认区域不安全,或运行态与持久配置不一致',
firewalld_endpoint_zone_unverified: '无法确认 Fabric 传输地址对应的宿主机接口和 firewalld 区域',
firewalld_endpoint_zone_unsafe_or_drifted: 'Fabric 传输接口的 firewalld 运行态与持久区域不一致或使用了 trusted',
firewalld_source_zones_present_or_unknown: 'firewalld 存在或无法排除按来源地址选区,无法安全定位 underlay 规则',
firewalld_unsupported_requires_maintenance: 'firewalld 已不受支持;请在维护窗口清理旧所有权状态并启用原生 nftables',
legacy_firewalld_state_requires_cleanup: '检测到旧 firewalld 规则或事务状态;请在维护窗口备份并清理后重建',
firewall_transaction_requires_recovery_or_cleanup: '检测到未收敛的防火墙事务;请先完成恢复或在维护窗口清理',
legacy_firewall_evidence_invalid: '无法安全核验宿主的旧防火墙状态;已禁止 VPC 变更',
nftables_service_not_active: 'nftables 服务未运行',
nftables_service_not_enabled: 'nftables 服务未启用',
ipv4_forwarding_disabled_or_unknown: 'IPv4 forwarding 未启用或无法核验',
@ -751,7 +745,6 @@ function renderHosts(region) {
'时间:' + date(host.probed_at),
]));
const manager = el('td');
const firewalldNft = capabilities.firewall_mode === 'firewalld_nft';
manager.append(compactLines([
'系统:' + text(capabilities.os_id) + ' ' + text(capabilities.os_version, ''),
'Manager:' + text(capabilities.network_manager),
@ -766,8 +759,8 @@ function renderHosts(region) {
'WireGuard:' + flag(capabilities.wireguard_ready, '就绪', '未就绪'),
'接口归属:' + flag(capabilities.wireguard_owned, '平台', '冲突/未归属'),
'nftables:' + flag(capabilities.nftables_ready, '就绪', '未就绪'),
'nft 服务:' + (firewalldNft ? '由 firewalld 管理' : flag(capabilities.nftables_active)),
'规则恢复:' + (firewalldNft ? '平台 manifest + 修复服务' : flag(capabilities.nftables_persistent)),
'nft 服务:' + flag(capabilities.nftables_active),
'规则恢复:' + flag(capabilities.nftables_persistent),
]));
const publicPath = el('td');
publicPath.append(compactLines([

@ -1,2 +1,2 @@
{* Shared Venix CSS/JS cache key. Increment whenever a shared browser asset changes. *}
{assign var=venix_asset_version value='2026100907' scope='global'}
{assign var=venix_asset_version value='2026101001' scope='global'}

@ -631,13 +631,6 @@ CloudRegionFabric::query()->delete();
$probeRows = [
$probeHost(1, [
'endpoint_source' => 'configured',
'capabilities' => [
'firewall_manager' => 'firewalld',
'firewall_mode' => 'firewalld_nft',
'nftables_ready' => true,
'nftables_active' => false,
'nftables_persistent' => false,
],
]),
$probeHost(2, [
'reachable' => false,
@ -646,14 +639,16 @@ $probeRows = [
]),
$probeHost(3, [
'endpoint_ip' => '10.20.0.10',
'vpc_ready' => false,
'reasons' => ['firewall_owner_not_nftables'],
'vpc_ready' => true,
'reasons' => [],
'capabilities' => [
'firewall_manager' => 'firewalld',
'firewall_mode' => 'unsupported',
'nftables_ready' => false,
'firewall_mode' => 'firewalld_nft',
'nftables_ready' => true,
'nftables_active' => false,
'nftables_persistent' => false,
'underlay_runtime_zone' => 'public',
'underlay_permanent_zone' => 'public',
'rp_filter_all' => 3,
'rp_filter_default' => '1',
'rp_filter_fabric_raw' => true,
@ -677,10 +672,10 @@ $assert(count($rows) === 6 && ($hostById($rows, 1)['readiness_state'] ?? null) =
$assert(($hostById($rows, 1)['endpoint_source'] ?? null) === 'configured',
'An explicit effective Fabric endpoint source was not projected.');
$assert(($hostById($rows, 1)['capabilities']['firewall_mode'] ?? null)
=== 'firewalld_nft'
=== 'native_nftables'
&& ($hostById($rows, 1)['capabilities']['firewall_manager'] ?? null)
=== 'firewalld',
'A supported firewalld+nft host was not preserved as ready.');
=== 'nftables',
'A native nftables host was not preserved as ready.');
$rpFilterCapabilities = $hostById($rows, 1)['capabilities'] ?? [];
$assert(($rpFilterCapabilities['rp_filter'] ?? null) === 0
&& ($rpFilterCapabilities['rp_filter_all'] ?? null) === 0
@ -704,13 +699,18 @@ $assert(is_array($failed) && $failed['probe_checked'] === true
'The isolated failed-host result was dropped or promoted.');
$assert(is_array($firewalld)
&& ($firewalld['capabilities']['firewall_manager'] ?? null) === 'firewalld'
&& ($firewalld['capabilities']['firewall_mode'] ?? null) === 'firewalld_nft'
&& ($firewalld['vpc_ready'] ?? true) === false
&& !array_key_exists('underlay_runtime_zone', $firewalld['capabilities'])
&& !array_key_exists('underlay_permanent_zone', $firewalld['capabilities'])
&& !array_key_exists('rp_filter_all', $firewalld['capabilities'])
&& !array_key_exists('rp_filter_default', $firewalld['capabilities'])
&& !array_key_exists('rp_filter_fabric_raw', $firewalld['capabilities'])
&& in_array('firewall_owner_not_nftables', $firewalld['reasons'], true)
&& in_array('firewalld_unsupported_requires_maintenance',
$firewalld['reasons'], true)
&& in_array('fabric_endpoint_vpc_pool_conflict',
$firewalld['reasons'], true),
'A firewall or tenant-pool endpoint blocker was not preserved in readiness.');
'A legacy firewalld result was not failed closed with its endpoint blocker.');
$assert(is_array($nonIpv4) && $nonIpv4['endpoint_ip'] === null
&& $nonIpv4['endpoint_source'] === null
&& in_array('fabric_endpoint_unavailable', $nonIpv4['reasons'], true),
@ -768,9 +768,10 @@ $blockedWizard = CloudAdminFabricService::probeRegion('1', $actor, $engine([
$response([]),
$response(['hosts' => [
$probeHost(1, [
'vpc_ready' => false,
'reasons' => ['firewall_owner_not_nftables'],
'capabilities' => ['firewall_manager' => 'firewalld'],
'capabilities' => [
'firewall_manager' => 'firewalld',
'firewall_mode' => 'firewalld_nft',
],
]),
$probeHost(2),
]]),
@ -781,9 +782,9 @@ $assert(($blockedWorkflow['stage'] ?? null) === 'blocked'
&& ($blockedWorkflow['can_apply'] ?? true) === false
&& ($blockedWorkflow['can_reconcile'] ?? true) === false
&& ($blockedWorkflow['action_mode'] ?? null) === 'probe'
&& in_array('firewall_owner_not_nftables',
&& in_array('firewalld_unsupported_requires_maintenance',
$blockedWorkflow['blocking_reasons'] ?? [], true),
'A failed fresh host probe did not keep the wizard blocked.');
'A legacy firewalld probe did not keep the wizard blocked.');
// A fresh successful detection is the only path to ready_to_apply. The
// browser receives a bounded server-owned preview, never nodes or endpoints.
@ -942,11 +943,12 @@ $assert($paths === [
$missingEndpointSource = $probeHost(1);
unset($missingEndpointSource['endpoint_source']);
$blockedProbeSets = [
'firewalld' => [
'legacy firewalld mode' => [
$probeHost(1, [
'vpc_ready' => false,
'reasons' => ['firewall_owner_not_nftables'],
'capabilities' => ['firewall_manager' => 'firewalld'],
'capabilities' => [
'firewall_manager' => 'firewalld',
'firewall_mode' => 'firewalld_nft',
],
]),
$probeHost(2),
],
@ -1506,8 +1508,11 @@ $client = $engine([
$response(['hosts' => [
$probeHost(1, [
'vpc_ready' => false,
'reasons' => ['firewall_owner_not_nftables'],
'capabilities' => ['firewall_manager' => 'firewalld'],
'reasons' => ['firewalld_unsupported_requires_maintenance'],
'capabilities' => [
'firewall_manager' => 'firewalld',
'firewall_mode' => 'unsupported',
],
]),
$probeHost(2),
]]),
@ -1570,8 +1575,11 @@ $activeProbeFailure = CloudAdminFabricService::probeRegion('1', $actor, $engine(
$probeHost(1, [
'endpoint_ip' => $overlappingEndpoint,
'vpc_ready' => false,
'reasons' => ['firewall_owner_not_nftables'],
'capabilities' => ['firewall_manager' => 'firewalld'],
'reasons' => ['firewalld_unsupported_requires_maintenance'],
'capabilities' => [
'firewall_manager' => 'firewalld',
'firewall_mode' => 'unsupported',
],
]),
$probeHost(2),
]]),
@ -1582,7 +1590,7 @@ $assert(($activeBlockedWorkflow['stage'] ?? null) === 'blocked'
&& ($activeBlockedWorkflow['can_apply'] ?? true) === false
&& ($activeBlockedWorkflow['can_reconcile'] ?? true) === false
&& ($activeBlockedWorkflow['action_mode'] ?? null) === 'probe'
&& in_array('firewall_owner_not_nftables',
&& in_array('firewalld_unsupported_requires_maintenance',
$activeBlockedWorkflow['blocking_reasons'] ?? [], true),
'A failed complete fresh probe left active Fabric reconcile enabled.');

@ -18,7 +18,7 @@ $assert(str_contains($template, 'data-instance-setting-tab="firewall"')
&& str_contains($template, 'id="vm-firewall-rules"'),
'Instance settings must expose the integrated firewall tab and whole-policy editor.');
$assert(str_contains($assets, "venix_asset_version value='2026100907'"),
$assert(str_contains($assets, "venix_asset_version value='2026101001'"),
'Shared Venix asset cache key must publish the firewall JavaScript and CSS.');
$assert(str_contains($template, '反欺骗保护始终开启')

@ -48,6 +48,18 @@ $assert(str_contains($engineClient, "'host_fabric_endpoint_invalid'")
&& str_contains($engineClient, "'fabric_host_firewall_mode_conflict'")
&& str_contains($engineClient, "'vpc_dataplane_firewall_mode_conflict'"),
'Reviewed endpoint validation failures are not safely mapped for administrators.');
$assert(str_contains($engineClient,
"'firewalld_unsupported_requires_maintenance'")
&& str_contains($engineClient,
"'legacy_firewalld_state_requires_cleanup'")
&& str_contains($engineClient,
"'firewall_transaction_requires_recovery_or_cleanup'")
&& str_contains($engineClient,
"'legacy_firewall_evidence_invalid'")
&& !str_contains($engineClient, "'firewalld_endpoint_zone_unverified'")
&& !str_contains($engineClient,
"'firewalld_endpoint_zone_unsafe_or_drifted'"),
'Retired firewalld compatibility errors remain in the web boundary.');
$assert(str_contains($template, 'id="host-fabric-endpoint-ip"')
&& preg_match('/id="host-fabric-endpoint-ip"[^>]*maxlength="15"/', $template) === 1
@ -73,10 +85,16 @@ $assert(str_contains($fabricService, 'private const ENDPOINT_SOURCES')
&& str_contains($fabricService, 'CloudPrivateCidrAllocator::normalize')
&& str_contains($fabricService, "'firewall_mode'")
&& str_contains($fabricService, "'public_selector'")
&& str_contains($fabricService, "=== 'nftables'")
&& str_contains($fabricService, "=== 'native_nftables'")
&& str_contains($fabricService,
"? 'firewalld_unsupported_requires_maintenance'")
&& str_contains($fabricService,
"'endpoint_source' => \$endpointSource")
&& str_contains($fabricService,
"'endpoint_source' => \$probe['endpoint_source'] ?? null")
&& !str_contains($fabricService, "'underlay_runtime_zone'")
&& !str_contains($fabricService, "'underlay_permanent_zone'")
&& !str_contains($fabricService, "'private_key'")
&& !str_contains($fabricService, "'ssh_command'"),
'Fabric readiness does not expose a bounded effective endpoint source.');
@ -90,14 +108,21 @@ $assert(str_contains($fabricClient, 'function endpointSource(value)')
&& str_contains($fabricClient, 'fabric_endpoint_source_invalid')
&& str_contains($fabricClient, 'fabric_endpoint_vpc_pool_conflict')
&& str_contains($fabricClient, 'fabric_region_conflict')
&& str_contains($fabricClient, 'firewalld_backend_not_nftables')
&& str_contains($fabricClient, 'firewalld_runtime_nft_backend_unverified')
&& str_contains($fabricClient, 'firewalld_default_zone_unsafe_or_drifted')
&& str_contains($fabricClient, 'firewalld_source_zones_present_or_unknown')
&& str_contains($fabricClient, 'firewalld_unsupported_requires_maintenance')
&& str_contains($fabricClient, 'legacy_firewalld_state_requires_cleanup')
&& str_contains($fabricClient,
'firewall_transaction_requires_recovery_or_cleanup')
&& str_contains($fabricClient, 'legacy_firewall_evidence_invalid')
&& !str_contains($fabricClient, 'firewalld_backend_not_nftables')
&& !str_contains($fabricClient, 'firewalld_runtime_nft_backend_unverified')
&& !str_contains($fabricClient, 'firewalld_default_zone_unsafe_or_drifted')
&& !str_contains($fabricClient, 'firewalld_source_zones_present_or_unknown')
&& !str_contains($fabricClient, 'const firewalldNft')
&& !str_contains($fabricClient, '由 firewalld 管理')
&& str_contains($fabricClient, 'firewall_competing_service_unknown')
&& str_contains($fabricClient, 'firewall_manager_conflict'),
'Fabric readiness UI does not distinguish explicit and SSH-IPv4 fallback endpoints.');
$assert(str_contains($assets, "venix_asset_version value='2026100907'"),
$assert(str_contains($assets, "venix_asset_version value='2026101001'"),
'Changed host/Fabric browser assets did not advance the shared cache key.');
echo "Cloud host Fabric endpoint contracts passed.\n";

Loading…
Cancel
Save