Repository navigation
fix(config): sudo 下使用调用者本人的配置,root 写入的文件交还本人 - #860
Merged
Merged
Conversation
- 有效用户为 root 且有非 0 的 SUDO_UID 时,默认配置目录、~ 展开和自动查找微信数据目录 都按 getpwuid(SUDO_UID) 的主目录解析;显式的 WEFLOW_HOME 照常优先 - 命令结束时,属于调用者的配置目录和缓存目录中属于 root 的条目交还 SUDO_UID:SUDO_GID, 不跟随也不修改符号链接,其他属主的条目不动;属于 root 的目录不交还 - 新模块 sudo_caller;weflow-core 在 Unix 上依赖 libc - README 两份的首次设置写明 Linux 和 macOS 上用 sudo 运行 key db --save fixed #855 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 17, 2026
334456777
added a commit
that referenced
this pull request
Nov 17, 2026
## 概要 修复 #861(#852 复测 #855 时发现):用 sudo 运行时,`key image` 和 `key image-local` 仍到 root 的主目录找 `kvcomm`,分别报 `none found` 和 `ERROR:KVCOMM_NOT_FOUND`;给出 `--kvcomm-dir` 时可以成功。 ## 改动 - `image_keys::default_kvcomm_dirs` 不再读环境变量 `HOME`,改用 #860 的 `sudo_caller::home_dir`。 - `key_image_local` 改为调用 `image_local_at(sudo_caller::home_dir())`。原先的 `image_local()` 用 `HOME` 或 `getpwuid(getuid())` 定位主目录。 - 不用 sudo 时行为不变:`home_dir` 回退到 `dirs::home_dir`,即先看 `HOME`。 Wiki「密钥获取」已同步:sudo 规则一节和 `--kvcomm-dir` 的默认位置。 ## 测试 - WSL:以 root 运行,并设置 `HOME=/root` 和 `SUDO_UID`/`SUDO_GID`/`SUDO_USER`。`key image-local` 找到 1 个账号;`key image` 不给 `--kvcomm-dir` 也能成功,`verification` 为 `jpeg_decode_and_xor_tail`。只读、只看汇总。没有留下 `/root/.config/weflow`。 - Windows 和 WSL:clippy(`-D warnings`)、`image_keys` 的测试。 fixed #861 🤖 Generated with [Claude Code](https://claude.com/claude-code)
334456777
added a commit
that referenced
this pull request
Nov 17, 2026
## 改动 README 两份的「首次设置与导出」开头说明下面的步骤以 Windows 为例,Linux 的步骤见 Wiki 新页 [Linux 首次设置](https://github.com/334456777/WeFlow/wiki/Linux-首次设置)(安装位置、用 `sudo` 取数据库密钥、没有托盘图标时退出微信、网页向导都写在那里)。第 3 步中 sudo 的那句已由 #860 加入,这里不重复。 Wiki 页面已先推送(`c770ef9`,同时在首页的「阅读路径」和侧边栏加了入口)。页面中的步骤在 #852 的环境(WSL2 的 Ubuntu 26.04、Linux 微信 4.1.13.26、`main@ef7ce03`)中逐项核对过: - 安装位置:sudo 的 `secure_path` 不含 `~/.local/bin`,因此建议 `/usr/local/bin`;`make install` 在 Linux 上也装到这里。 - 以 sudo 运行时读取本人的配置,`weflow lang zh` 的设置同样生效,写入的文件仍归本人所有(#855)。 - `pkill -x wechat` 能让微信在约 2 秒内退出,可用于没有托盘的桌面。 - `key image` 以本人身份运行可以成功;用 sudo 运行时找不到 `kvcomm`(#861)。 - 以本人身份运行的 `weflow serve` 中,向导的数据库密钥一步立即报 `ptrace_scope` 错误;在终端用 sudo 保存密钥后,正在运行的服务无需重启即可读取(进程内的 `/api/chat/sessions` 从 409 变为 200)。 `make docs-check`(`docs_consistency`)通过。 closes #857,Refs #852 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
修复 #855:在 Linux(以及 macOS)上用
sudo weflow key db --save时,密钥存进了 root 的配置。用sudo WEFLOW_HOME=… weflow …指向本人的配置时,config.json的属主会变成 root,本人之后读不了自己的配置。按用户选定的做法 1「sudo 下用本人的配置」修复。改动
新模块
weflow-core/src/sudo_caller.rs:SUDO_UID时,用getpwuid_r(SUDO_UID)取得调用者的主目录和组;SUDO_GID优先。.config,macOS 上是Library/Application Support。expand_home展开~、自动查找微信数据目录时,也按调用者的主目录解析。显式的WEFLOW_HOME照常优先。AppContext::new在建立 home 目录之前,cache_base在建立缓存目录之前,都检查这个目录(或它最近的已存在的上级目录)是否属于调用者。属于调用者时,命令结束时(main中run之后)把其中属于 root 的条目交还SUDO_UID:SUDO_GID:lchown,不跟随也不修改符号链接;weflow-core在 Unix 上新增依赖libc(工作区已在使用,Cargo.lock只多了一行依赖关系)。sudo weflow key db --save,sudo找不到命令时写完整路径。Wiki 已同步:「密钥获取」#Linux x64 的实现、「缓存与配置」#目录,以及「故障排查」中 sudo 相关的两行。
测试
SUDO_UID的解析、最外层缺失目录的判断、按属主列出条目时排除符号链接。SUDO_UID/SUDO_GID/HOME=/root,模拟 sudo。WEFLOW_HOME指向本人目录:root 写配置后,config.json、.lock仍属本人且为 600,本人可以继续读写。WEFLOW_HOME时:config path为调用者的~/.config/weflow/config.json;没有SUDO_UID时仍是/root/...。-D warnings)和整个 workspace 的测试。macOS 由 CI 编译。fixed #855
🤖 Generated with Claude Code