[bug] install.sh 写入的 rpc_portal / foreign_network_whitelist 在配置文件中被静默忽略(安装脚本与源码不一致 / install script writes keys the binary silently ignores)
- Dominant language
- Rust
- Stars
- 13.6k
- Forks
- 1.4k
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 34
Description
## 问题简要描述 / Brief Description
`script/install.sh` 生成的默认配置 `/opt/easytier/config/default.conf` 里有两个键,`easytier-core -c ` 加载时其实被**静默忽略**——安装脚本与当前源码不一致。两个键写的值"恰好"等于实际默认行为,所以表面无害,但会误导用户去编辑它们却不生效。
The default config written by `script/install.sh` contains two keys that `easytier-core -c ` **silently ignores**, i.e. the install script disagrees with the current source. They happen to match the effective default behavior today, so nothing breaks — but a user who edits them expecting an effect will be silently misled.
复现版本 / Affects: current `main` and `v2.6.4` release.
---
### 问题 1 — `rpc_portal` 在配置文件中不生效 / `rpc_portal` is ignored in the config file
- `script/install.sh:251` 写入 `rpc_portal = "0.0.0.0:0"`。
- 但 `easytier-core -c` 加载的配置结构体 `Config`(`easytier/src/common/config.rs`)**没有 `rpc_portal` 字段**,且未启用 `deny_unknown_fields`,所以这个键被 serde/toml 直接丢弃。
- RPC portal 地址实际只由命令行 `--rpc-portal`(或环境变量 `ET_RPC_PORTAL`)决定(`easytier/src/core.rs` 的 `RpcPortalOptions`,进程级、全局唯一)。
- `install.sh` 生成的 systemd unit `ExecStart=.../easytier-core -c .../%i.conf` 不带 `--rpc-portal`,于是回退为:绑 `0.0.0.0`、端口取 `15888..15900` 第一个空闲端口(`easytier/src/rpc_service/api.rs` 的 `select_proper_rpc_port`)。默认带 IP 白名单 `127.0.0.0/8` + `::1/128`(`easytier/src/instance/instance.rs` 的 `InstanceRpcServerHook::new`),所以虽然 bind 在 `0.0.0.0`,默认仍只有本机能连——这点没问题,但配置文件里的 `rpc_portal = "0.0.0.0:0"` 完全是个摆设。
The config struct loaded for `-c` has no `rpc_portal` field (and no `deny_unknown_fields`), so the key is dropped. The RPC portal is controlled solely by the `--rpc-portal` flag / `ET_RPC_PORTAL` env. The generated systemd unit passes neither, so it falls back to binding `0.0.0.0` on the first free port in `15888..15900`, with a default whitelist of `127.0.0.0/8` + `::1/128`.
### 问题 2 — `foreign_network_whitelist` 不是合法键,真名是 `relay_network_whitelist` / wrong key name
- `script/install.sh:270` 写入 `foreign_network_whitelist = "*"`。
- 但源码里这个 flag 叫 `relay_network_whitelist`(`gen_default_flags()` in `easytier/src/common/config.rs`,CLI `--relay-network-whitelist`,环境变量 `ET_RELAY_NETWORK_WHITELIST`,默认 `"*"`)。`foreign_network_whitelist` 不是合法 flag 名,最终被忽略(这也证明 flags 反序列化会忽略未知键,否则带此键的默认配置根本无法启动)。
The flag is actually named `relay_network_whitelist`; `foreign_network_whitelist` is not a valid key and is ignored.
---
### 为什么现在没出问题 / Why nothing breaks today
两个键写入的值都"恰好"等于实际默认行为(`rpc_portal` 默认本机可达、`relay_network_whitelist` 默认 `"*"`),所以没人察觉。
### 实际危害(footgun)/ The real footgun
如果用户照着 `default.conf` 去编辑这两个键:
- 改 `foreign_network_whitelist = ""` 想**禁止外部网络借用本节点转发** → 不生效,必须写 `relay_network_whitelist = ""`。
- 改 `rpc_portal = "127.0.0.1:15888"` 想**把管理 RPC 限制在本机 / 换绑定地址** → 不生效,必须用 `--rpc-portal` / `ET_RPC_PORTAL`。
A user editing `foreign_network_whitelist = ""` to restrict relaying, or editing `rpc_portal` to change the bind address, gets no effect with no warning.
### 相关问题 — 默认自启 `easytier@default` 不安全 / Related: insecure default auto-start
顺带反映一个同样出在 `install.sh` 的安全问题(已有 issue #1539 报告,这里关联记录):`install.sh` 安装末尾会 `systemctl enable --now easytier@default`,在用户不知情下把节点自动加入名为 `default` 的**公开网络**(`network_name`/`network_secret` 均为 `default` + 公共种子 `public.easytier.top`),且默认 `relay_network_whitelist = "*"`、无 `private_mode`,节点可被任意陌生网络借作数据中继。对比之下,Windows 的 `install.ps1` 只安装二进制、**不写默认配置也不自启**,并提示用户手动 `easytier-cli service install` —— 两个官方安装器行为不一致。See #1539.
A related security problem in the same `install.sh`: it ends with `systemctl enable --now easytier@default`, silently joining the node to a **public** network named `default` (`network_name`/`network_secret` both `default`, plus the public seed `public.easytier.top`), with `relay_network_whitelist = "*"` and no `private_mode`, so the node can be used as a data relay by any stranger network. By contrast the Windows `install.ps1` only installs binaries and does **not** write a default config nor auto-start anything (it tells the user to run `easytier-cli service install` manually) — the two official installers behave inconsistently. See #1539.
### 修复计划 / Fix plan
我将直接提一个 PR 修复(而非仅给建议)/ I'll submit a PR directly rather than only suggesting. 计划改动 / Planned changes:
1. **让 `install.sh` 向 `install.ps1` 对齐**:不再自动创建并启动一个默认网络。Align `install.sh` with `install.ps1`: stop auto-creating and auto-starting a default network.
2. **去掉默认自启**:移除 `systemctl enable easytier@default` + `systemctl start easytier@default`(openrc 分支同理),改为安装后提示用户自行写配置、自行启动。参考 #1539。Remove the default auto-start; print guidance to configure & start manually instead. See #1539.
3. **让 `rpc_portal` 在配置文件中真正生效**:与其从模板删掉,不如给 `Config` 增加 `rpc_portal` 字段,使 `-c ` 也能读取,与 `--rpc-portal` / `ET_RPC_PORTAL` 对齐(命令行优先级更高)。Make `rpc_portal` actually work in the config file: add an `rpc_portal` field to `Config` so `-c ` reads it, aligned with the `--rpc-portal` / `ET_RPC_PORTAL` flag (CLI takes precedence).
4. **修正键名**:`install.sh` 的 `foreign_network_whitelist` → `relay_network_whitelist`。Fix the key name in `install.sh`.
5. (可选 / optional)配置加载对未知顶层键 / flag 打印一条 warning,避免这类静默忽略再次误导用户。Print a warning on unknown top-level keys / flags during config load.
### 相关文件 / References
- `script/install.sh:251` (`rpc_portal`), `script/install.sh:270` (`foreign_network_whitelist`)
- `easytier/src/common/config.rs`: `Config` struct (no `rpc_portal` field), `gen_default_flags()` (`relay_network_whitelist`)
- `easytier/src/core.rs`: `RpcPortalOptions` (`--rpc-portal` / `ET_RPC_PORTAL`), `relay_network_whitelist` arg (`--relay-network-whitelist` / `ET_RELAY_NETWORK_WHITELIST`)
- `easytier/src/rpc_service/api.rs`: `select_proper_rpc_port`
- `easytier/src/instance/instance.rs`: `InstanceRpcServerHook::new` (default whitelist `127.0.0.0/8` + `::1/128`)
- 相关 issue / Related issue: #1539(默认安装脚本存在安全问题 / insecure default install)
Contributor guide
Research direction
Start with script/install.sh at the referenced lines, then compare the Config struct and gen_default_flags() in easytier/src/common/config.rs with RpcPortalOptions in easytier/src/core.rs. Check the related RPC files and issue #1539 before deciding scope. Done means the installer keys match supported configuration behavior and no longer silently creates and starts the default network.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, shell
- Domain
- backend, devops, security
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100