Files
panel-auth/README.md
T

55 lines
1.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# panel-auth — DSH 面板访问密码插件
`dsh web` 面板加一层原生 HTTP 认证(Basic + 签名 Cookie),挂载在
`/root/.dsh/profiles/web/cordis.patch.yml` 的用户补丁层,升级 DSH 不会丢。
## 认证逻辑
- 每个 HTTP 请求 / WebSocket 升级都必须携带以下二者之一:
1. 有效的 `dsh_panel` 签名 Cookie(登录成功后签发,浏览器自动带上,WS 握手也带);
2. 有效的 HTTP Basic 凭据(`config.users` 中的用户名 + scrypt 哈希)。
- 匿名请求返回 `401` + `WWW-Authenticate`,浏览器弹原生密码框。
- 凭 Basic 成功登录时签发 Cookie(默认 30 天),之后无需重复输入。
- **Fail-open**`users` 为空或 `secret` 缺失/过短时插件不拦截任何请求,
配置写错不会把面板锁死。
## 修改密码
```bash
cd /root/.dsh/profiles/web/panel-auth
node hash.js admin 新密码 # 输出新 passwordHash
```
把输出的 `passwordHash` 替换进 `../cordis.patch.yml` 后:
```bash
systemctl restart dsh-web # 或利用 loader 对 cordis.patch.yml 的 HMR 自动生效
```
## 新增用户
`cordis.patch.yml``users` 列表里再加一组 `username`/`passwordHash`
## 更换签名密钥
```bash
node hash.js --secret # 生成新 secret
```
替换 `cordis.patch.yml``secret` 后重启。注意:更换密钥会使所有已签发
Cookie 立即失效,所有人需重新输入密码。
## 应急解锁(忘记密码时)
编辑 `/root/.dsh/profiles/web/cordis.patch.yml`
- 临时把 `users` 置为 `[]`(fail-open,面板恢复无密码状态),或
- 用上面的命令生成新哈希替换。
改动会由 loader 的用户补丁层 HMR 热应用,无需重启。
## 文件
- `index.js` — 插件本体(webServer 包装 + 认证守卫)
- `crypto.js` — scrypt 哈希 / HMAC Cookie 签名(无依赖,纯 node:crypto
- `hash.js` — 生成密码哈希与随机密钥的 CLI