Repository navigation
refactor(platform): 远程服务端与 AskPass 共用同一份 Unix socket 对端账户检查(#2231) - #143
Merged
Merged
Conversation
git-host 的 AskPass 通道和 remote 服务端的常驻会话各有一份逐字相同的 peer_uid(Linux 用 SO_PEERCRED,其他 Unix 用 getpeereid)。现在合并到 lithe_platform::socket,两处都改用它;git-host 的 effective_uid 也一并移入。 remote 服务端多依赖一个只依赖 libc 的叶子 crate lithe-platform;remote 自己的 current_uid(getuid,也是 server.hello 的 userId)不变,行为不变。新增 lithe-platform-tests 的真实 socket 测试,两端都核对对端账户。
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.
关联 Issue
1lck/Lithe-IDEA#2231(远程开发完整设计)。#137 合入时留下的重复代码:AskPass 通道(S13)和远程服务端的常驻会话(S20)各有一份 Unix socket 对端账户检查。
类型
改动说明
原来的问题
git-host/src/authentication/unix.rs和remote/src/server/platform/{linux,macos}.rs里各有一份逐字相同的peer_uid:Linux 和 Android 用getsockopt(SO_PEERCRED),其他 Unix 用getpeereid。两处都是安全检查,以后只改一处、漏掉另一处,就会出现两种判定。lithe-platform(新增
socket模块,只在 Unix 上编译)peer_uid(&UnixStream) -> io::Result<u32>:返回 socket 另一端进程的有效用户 id。对从监听 socket 接受的连接,是发起连接的账户;对客户端的连接,是创建监听 socket 的账户。参数从裸RawFd改为借用UnixStream,调用方不能再传一个已经关闭或不是 Unix socket 的描述符。effective_uid():本进程的有效用户 id,从 git-host 移过来。cfg后面,真实主机上的测试放在 lithe-platform-tests”,所以没有新建 crate。为此新增唯一的依赖[target.'cfg(unix)'.dependencies] libc。git-host
peer_uid和effective_uid,改用lithe_platform::socket。监听端读不到对端账户时,仍当作其他账户拒绝;助手端读不到时,仍返回错误。remote(服务端)
linux.rs、macos.rs里的两份peer_uid。platform/mod.rs改为转出lithe_platform::socket::peer_uid,daemon.rs的对端检查只改成借用 stream。server特性新增可选依赖 lithe-platform。这是一个只依赖 libc 的叶子 crate,不会把 Core 的其他 crate 带进服务端;Cargo.toml里“服务端和客户端不依赖 Core crate”的注释已改成写明这个例外。客户端(client特性)的依赖不变。current_uid(getuid,也是server.hello里的userId和信任键的一部分)不变,常驻会话仍拿对端账户与它比较,行为不变。改动超出
rust/crates/remote的原因要去掉重复,至少要动 remote 之外的两个 crate:git-host(删除副本)和 lithe-platform(放共享实现)。测试按 CONTRIBUTING 的平台测试规则第 2 条放进 lithe-platform-tests,因为结果取决于真实操作系统的系统调用。
体积(D9)
x86_64-unknown-linux-muslreleaseaarch64-unknown-linux-muslrelease两者都用
--release --no-default-features --features server、rust-lld链接,在同一台机器上构建。本 PR 不改插件契约、能力版本或插件函数协议,不需要更新协议更新记录。
测试
lithe-platform-tests的socket::unix::both_ends_of_a_socket_see_the_account_that_opened_the_other:在临时目录里建一个真实的监听 socket,连接排进队列后用非阻塞accept取出,不做任何等待;在服务端和客户端两端分别核对peer_uid等于effective_uid()。Linux 上测SO_PEERCRED分支,macOS 上测getpeereid分支。askpass)和 remote 常驻会话测试(tests/persistence.rs)覆盖两个调用方。验证
cargo fmt --all -- --checkcargo clippy --workspace --all-targets --features lithe-remote/server -- -D warningscargo clippy --target x86_64-unknown-linux-musl -p lithe-platform -p lithe-git-host -p lithe-platform-tests -p lithe-remote --features lithe-remote/server --all-targets -- -D warningsSO_PEERCRED分支编译通过)cargo clippy --target x86_64-pc-windows-msvc -p lithe-platform -p lithe-git-host -p lithe-platform-tests --all-targets -- -D warningssocket模块不编译)cargo test -p lithe-platform -p lithe-platform-tests -p lithe-git-hostcargo test -p lithe-remote --features servernode scripts/rust-core/verify-platform-tests.mjsnode --test scripts/rust-core/*.test.mjsnode scripts/rust-core/affected-crates.mjs --base origin/main未能执行的检查: Linux 上没有在本地实际运行
SO_PEERCRED分支的测试,依靠 CI 的 Linux 车道;Windows 上只做了交叉 clippy。