@iasiv5/dsh-obmc-web 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 iasiv5
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,136 @@
1
+ # @iasiv5/dsh-obmc-web
2
+
3
+ 在 DSH GUI 里使用 **BMC Web UI**(OpenBMC / bmcweb,AST2700 EVB 实测)。
4
+ host 半身在 DSH web 服务器的 GUI origin 上注册一组同源代理路由,经
5
+ `obmc-web-relay.service`(SSH 本地转发,仅绑 `127.0.0.1`,端口默认
6
+ 18443、被占自动顺延)抵达 BMC;client 半身仿照 dsh-surf,在「设置」
7
+ 菜单位注册一个 **BMC 控制台** 启动面板:显示隧道状态芯片与当前 BMC
8
+ 地址,一键在顶层标签页打开控制台,并支持 BMC IP 变化后的 SSH 自动
9
+ 探测与隧道重定向。
10
+
11
+ > 控制台不放进侧边栏 iframe:公网入口的 dsh-auth-caddy 给所有响应盖了
12
+ > `X-Frame-Options: DENY`,因此面板用 `window.open` 做**顶层导航**(XFO
13
+ > 不约束顶层页面)。登录仍在 BMC 自己的页面里完成,本插件不经手凭据。
14
+
15
+ ```
16
+ 浏览器 ── GUI origin (/bmc, /js, /css, /redfish, /login, /logout, /kvm·/console WS)
17
+ └─ dsh web server (127.0.0.1:3080) ── @iasiv5/dsh-obmc-web host 路由
18
+ │ (剥 XFO/HSTS/WWW-Authenticate/frame-ancestors)
19
+ └─ obmc-web-relay.service (ssh -N -L 127.0.0.1:<relay端口> → $BMC_TARGET)
20
+ └─ BMC (bmcweb, hash 路由 SPA)
21
+ ```
22
+
23
+ ## 面板一览
24
+
25
+ 「设置 → BMC 控制台」从上到下:
26
+
27
+ - **状态芯片**:整个面板共享一次轮询,每 15s 打一次 `/bmc-status?probe=1`
28
+ (探测轮进行中改为 2s),实测隧道后显示:隧道在线 / 正在 SSH 探测 /
29
+ DSH 会话已过期 / 可达但响应异常 / BMC 不可达;保存配置、探测 IP、
30
+ 安装 relay 这类影响隧道的动作完成后会**立即重新探测**,芯片在 1~2s 内
31
+ 跟上动作结果,不必等下一个轮询周期;
32
+ - **当前 BMC IP** 与最近一次探测结果(找到的地址、时间、是否已切换并验证);
33
+ - **部署配置表单**:五个等宽输入框(SSH 跳板机、SSH 端口、BMC 地址、
34
+ 网段、relay 本地端口),加 保存配置 / 探测 BMC IP / 安装并启动 relay
35
+ 服务 三个动作与 relay 运行状态一行;
36
+ - **打开 BMC Web 控制台**:顶层标签页打开;尚未配置 BMC 地址时置灰。
37
+
38
+ ## 为什么是这些路由
39
+
40
+ bmcweb 的 SPA 以根绝对路径引用资源与 API(`/js/…`、`/css/…`、`/redfish/…`、
41
+ `/login`、`/logout`;KVM/串口走 `/kvm`、`/console` WebSocket),且路由为
42
+ hash 模式,因此挂在 `/bmc` 前缀下不会与 SPA 内部导航冲突。DSH web 服务器
43
+ 按「精确表优先、前缀最长者胜」分发,GUI 自身的路由永远优先;重复注册只
44
+ 跳过、不会让插件失败。
45
+
46
+ ## 安装
47
+
48
+ ```bash
49
+ # 任意目录执行即可(dsh plugin 把参数转发给 profile 目录里的 pnpm)
50
+ dsh plugin --profile web add @iasiv5/dsh-obmc-web
51
+ ```
52
+
53
+ 然后重启 dsh web。「设置」菜单里会出现 **BMC 控制台** 面板。
54
+
55
+ 本地开发可用 link 方式直装源码:
56
+
57
+ ```bash
58
+ dsh plugin --profile web add link:/path/to/dsh-obmc-web
59
+ ```
60
+
61
+ ## 配置
62
+
63
+ **推荐方式:全部在网页里完成。** 首次安装后打开「设置 → BMC 控制台」,
64
+ 展开「部署配置」表单:
65
+
66
+ 1. 填 **SSH 跳板机**(`user@host`;与 BMC 链路网段相通、已配好对本机
67
+ BatchMode 免密登录的机器)与 SSH 端口;**BMC 地址可以留空**;
68
+ 链路网段、relay 本地端口(默认 18443)均可留空用默认;
69
+ 2. 点 **「探测 BMC IP」**——先保存表单,再 SSH 登录跳板机自动发现
70
+ bmcweb 地址并回填;BMC IP 被 DHCP 改变后,也用同一个按钮(此时显示
71
+ 「重新探测 IP」)重新找回并切换隧道;同一时刻只有一轮探测在跑;
72
+ 3. 点 **「安装并启动 relay 服务」**——插件按当前配置生成
73
+ `~/.config/systemd/user/obmc-web-relay.service`,daemon-reload 并启动,
74
+ 隧道验证通过后报告;若配置的 relay 端口被其他程序占用,会自动顺延到
75
+ 空闲端口并提示。之后升级配置也用同一个按钮。
76
+
77
+ **保存配置**单独说明:表单立即写入 env 文件并生效;若 BMC 地址或 relay
78
+ 端口发生变化且 relay 正在运行,会自动重启 relay 并验证隧道,结果随保存
79
+ 响应返回(首次保存、只改跳板机等不影响隧道的编辑不会重启 relay)。
80
+
81
+ **手动方式(高级)**:配置实际存储在插件与 relay unit 共用的
82
+ `KEY=VALUE` 文件 `~/.config/systemd/user/obmc-relay.env`(可用环境变量
83
+ `OBMC_WEB_ENV` 改位置)。首次启动若文件不存在,插件自动生成一份全注释
84
+ 的模板(含说明与文档示例地址);手改后重启 dsh web 生效。模板见
85
+ `deploy/relay.env.example`;手工安装用的 unit 示例在
86
+ `deploy/obmc-web-relay.service.example`(一般用不着——面板按钮会生成):
87
+
88
+ | 键 | 必填 | 说明 |
89
+ |---|---|---|
90
+ | `BMC_TARGET` | 是* | 当前 BMC 地址 `ip:port`,relay unit 的 ExecStart 消费;自动探测会原地改写此行(保留其他键)。表单保存与探测都会补全成 `ip:443`——**手写时请务必带端口**,`ssh -L` 的转发目标需要 `host:port` 形式。*可用「探测 BMC IP」自动发现 |
91
+ | `OBMC_SSH_TARGET` | 探测必填 | 跳板机 SSH 目标 `user@host`(BatchMode 免密);不配则探测关闭,代理不受影响 |
92
+ | `OBMC_SSH_PORT` | 否 | 跳板机 SSH 端口,默认 22 |
93
+ | `OBMC_SUBNET` | 否 | 探测网段 `a.b.c`;缺省先取 `BMC_TARGET` IP 的 /24,连 BMC IP 都没有时,探测会在跳板机上自动枚举直连 IPv4 网段逐个扫 |
94
+ | `OBMC_RELAY_PORT` | 否 | relay 本地监听端口,默认 18443,需与 relay unit 的 `-L` 参数一致(面板的安装按钮会保持两者同步) |
95
+
96
+ 代码本身不含任何站点相关默认值——你的网络拓扑只活在这份配置里(表单
97
+ 和 env 文件是同一份数据的两个入口)。真正必须由人类提供的只有跳板机
98
+ 这一项;DSH 自身的 3080、公网反代端口等属于 DSH/网关层,与本插件无关,
99
+ 无需在此配置。
100
+
101
+ ## BMC IP 自动探测
102
+
103
+ BMC 地址常由跳板侧 DHCP 动态分配,可能变化。当隧道目标失联(代理上游
104
+ 报错,或 `/bmc-status?probe=1` 实测失败)时,插件自动 SSH 到跳板机定位
105
+ bmcweb 实际地址:先查 dnsmasq 租约表 + ARP 表(单纯换址时亚秒级返回),
106
+ 不通再对候选网段做 TCP-443 扫描;候选地址以 `/redfish/v1` 应答做指纹
107
+ 校验(200 或 401 都算 bmcweb 在场)。探测网段的确定顺序:配置的
108
+ `OBMC_SUBNET` → `BMC_TARGET` IP 的 /24 → 跳板机自身枚举的直连 IPv4
109
+ 网段。找到后写回 env 文件的 `BMC_TARGET` 行、经 user manager 重启
110
+ relay,并通过隧道验证后才报告成功;若 relay unit 尚未安装(首次
111
+ bootstrap),地址仍会写入配置并提示下一步去点「安装并启动 relay
112
+ 服务」。SSH 层失败(地址/端口/免密)会透出真实原因,不会伪装成
113
+ 「未发现 bmcweb」。触发方式:
114
+
115
+ - 手动:部署配置里的「探测 BMC IP / 重新探测 IP」按钮(`POST
116
+ /bmc-status`),不设冷却,但同一时刻仅一轮;
117
+ - 自动:代理上游报错时触发,自带 60s 冷却。
118
+
119
+ ## 安全说明
120
+
121
+ - 上游仅 `127.0.0.1`(SSH 隧道,端口默认 18443),不新增任何公网监听。
122
+ - 剥掉的响应头:`X-Frame-Options`、`Strict-Transport-Security`、
123
+ `WWW-Authenticate`(防止 bmcweb 的 401 Basic challenge 弹浏览器原生
124
+ 凭据框;BMC SPA 走 POST /login JSON + cookie),CSP 仅移除
125
+ `frame-ancestors` 指令;其余(含 Cookie)原样透传。
126
+ - 不在任何地方存储 BMC 凭据;登录在 BMC 自身页面完成。
127
+ - 信任围栏仿照 dsh-better-sidebar 的 trust-fence(Host 必须是 loopback
128
+ 或部署信任的 authority、`Sec-Fetch-Site` 不得为 cross-site、Origin 若有
129
+ 必须与 Host 同 hostname)——这是 DNS-rebinding 防御,不是认证;真正的
130
+ 访问控制由部署在 GUI 前面的既有网关承担。
131
+ - 已知取舍:代理内容与 GUI 同源(bmcweb 需要 Cookie 登录,无法用
132
+ opaque-origin sandbox)。信任级别等同于在浏览器同站打开 BMC 页面。
133
+
134
+ ## License
135
+
136
+ [MIT](./LICENSE)
@@ -0,0 +1,3 @@
1
+ # dsh-obmc-web bundle patch: mounts the host half (webServer routes) into
2
+ # the profile's plugin tree.
3
+ - insert: [{ id: obmc-web, name: '@iasiv5/dsh-obmc-web' }]
@@ -0,0 +1,22 @@
1
+ [Unit]
2
+ Description=SSH local-forward relay to the BMC Web UI via jump host
3
+ # Local port 18443 -> (over ssh to the jump host) -> BMC $BMC_TARGET
4
+ # Binds loopback only — the DSH GUI's same-origin proxy is the only client.
5
+ # BMC_TARGET can be overridden by relay.env (rewritten in place by the
6
+ # @iasiv5/dsh-obmc-web plugin's SSH discovery when the DHCP-assigned BMC
7
+ # address changes). Install as ~/.config/systemd/user/obmc-web-relay.service
8
+ # — or just click「安装并启动 relay 服务」in the plugin's Settings panel,
9
+ # which generates this unit from the current configuration.
10
+ After=network-online.target
11
+ Wants=network-online.target
12
+
13
+ [Service]
14
+ Type=simple
15
+ Environment=BMC_TARGET=192.0.2.10:443
16
+ EnvironmentFile=-%h/.config/systemd/user/obmc-relay.env
17
+ ExecStart=/usr/bin/ssh -o ExitOnForwardFailure=yes -o ServerAliveInterval=30 -o ServerAliveCountMax=3 -o BatchMode=yes -N -L 127.0.0.1:18443:${BMC_TARGET} -p 22 user@jump.example.net
18
+ Restart=always
19
+ RestartSec=5
20
+
21
+ [Install]
22
+ WantedBy=default.target
@@ -0,0 +1,38 @@
1
+ # @iasiv5/dsh-obmc-web / obmc-web-relay shared configuration.
2
+ #
3
+ # PREFERRED: you normally do NOT edit this file by hand — open the DSH
4
+ # Settings → BMC 控制台 panel and fill in the 部署配置 form; it writes this
5
+ # file (validated, comments preserved) and can install/restart the relay
6
+ # unit for you. On first plugin start this file is auto-generated as a
7
+ # fully commented template.
8
+ #
9
+ # Location: ~/.config/systemd/user/obmc-relay.env (the plugin side can be
10
+ # moved anywhere with the OBMC_WEB_ENV env var). KEY=VALUE lines; keys the
11
+ # plugin or the relay unit do not know are ignored.
12
+ #
13
+ # The plugin reads this file at dsh web startup; hand edits require a
14
+ # restart (saving from the Settings form applies immediately).
15
+
16
+ # Current BMC address (ip:port). Consumed by the relay unit's ExecStart and
17
+ # rewritten in place by the plugin's SSH discovery. 192.0.2.x are
18
+ # documentation addresses — replace with your BMC's.
19
+ BMC_TARGET=192.0.2.10:443
20
+
21
+ # ---- Optional: SSH auto-discovery ---------------------------------------
22
+ # With these set, when the tunnel stops answering the plugin SSHes to the
23
+ # jump host (BatchMode key expected to be already authorized) and re-locates
24
+ # the bmcweb speaker on the link subnet: dnsmasq leases + ARP table first,
25
+ # full TCP-443 sweep as fallback. Without them the proxy still works — it
26
+ # just cannot retarget itself.
27
+ OBMC_SSH_TARGET=user@jump.example.net
28
+ OBMC_SSH_PORT=22
29
+ # Link subnet to sweep; defaults to the BMC target IP's /24, and when even
30
+ # BMC_TARGET is absent the discovery enumerates the jump host's
31
+ # directly-connected IPv4 /24s by itself.
32
+ OBMC_SUBNET=192.0.2
33
+
34
+ # ---- Optional: relay local port -----------------------------------------
35
+ # Local loopback port the relay forwards; must match the relay unit's -L
36
+ # argument (the Settings form's install button keeps them in sync).
37
+ # Default: 18443.
38
+ #OBMC_RELAY_PORT=18443