Repository navigation
Conversation
With the opt-in git-wasi feature, `git` configured through BashBuilder::git(GitConfig) runs upstream git 2.55 compiled to wasm32-wasip1 instead of the simulated git: every command git implements in C, git's own output, real repositories on the VFS, child processes (merge, rebase, stash, local clone, fetch and push) and HTTPS remotes through HttpClient after GitConfig's remote allowlist. - One 33-line patch to git's run-command.c: start_command() uses git's Windows spawn path, start_async() asks the host to copy the process and call one function (fork_call). Host interface `bashkit_proc`: pipe, dup, dup2, spawn, fork_call, waitpid. - CPython's WASI host is shared in builtins/wasi_host.rs, with bounded pipes, /dev/null, a notification-based poll_oneoff and fork support. - Limits per command: 64 processes, the shell deadline (<= 120 s), 256 MB memory each, 16 MB output; every process is charged to the execution budget and aborted with the command. Programs other than git are refused. - New crate bashkit-git-wasm (GPL-2.0-only AND MIT AND Zlib) ships the module and precompiles it; deny.toml allows GPL-2.0-only for it only. - Differential tests against host git, HTTPS against git http-backend, security tests, two fuzz targets, a Criterion bench, CI and publish wiring, knowledge (git-wasm runtime, TM-GIT-016..022, L-GITW-*).
There was a problem hiding this comment.
Reviewed the WASI-host side (git_wasi/mod.rs, remote.rs), the run-command patch, the compat shims, GitConfig allowlist, HttpClient redirect policy, knowledge/runtimes/git-wasm.md + threat-model entries, and the new integration tests. The sandboxing architecture is sound (no host FD/network outside HttpClient, fail-closed spawn gate, process/memory/output caps on both spawn paths). Three findings below, one blocking.
| procs.reserve()?; | ||
| // git's HTTP transport: the host speaks the remote-helper protocol. | ||
| #[cfg(feature = "http_client")] | ||
| if let ("remote-https" | "remote-http", Some(url)) = (args[1].as_str(), args.get(3).cloned()) { |
There was a problem hiding this comment.
[P0] resolve() rejects the helper before the helper branch runs, so HTTPS clone/fetch/push cannot work. spawn() calls resolve(path, &argv)? first (mod.rs:606), and resolve() returns ENOENT for path git-remote-https: the name strips to remote-https, which is not in DASHED (mod.rs:647), and it is not git or sh (mod.rs:651-676). But git's transport-helper spawns exactly git-remote-https <remote> <url> (dashed argv[0]), never git remote-https ..., so the ("remote-https"|"remote-http", args.get(3)) branch at mod.rs:616 is dead for real transports and every HTTPS operation fails at exec. Two corroborating signs: dashed argv carries the URL at index 2 while the branch reads args.get(3) (the shape only a literally-typed git remote-https <r> <u> has), and the resolve unit test covers git-st/vim rejection but has no git-remote-https acceptance case. The new clone_fetch_push_over_https_match_the_server test (tests/integration/git_wasi_tests.rs:524) exercises this path and should fail. Fix: intercept the helper before resolve() (match raw path/argv[0] git-remote-http(s)), or extend DASHED and map to ["git", "remote-https", remote, url] with the URL index corrected.
There was a problem hiding this comment.
This P0 appears to be a false positive at head 6560059874c52057ec5723b9e0264d9d50e3d15f.
Upstream git 2.55's get_helper() appends remote-https, the remote name, and the URL, then sets helper->git_cmd = 1. The Windows spawn path selected by this PR's WASI patch calls prepare_git_cmd() before mingw_spawnvpe(). Consequently the host receives ["git", "remote-https", remote, url], which resolve() accepts, with the URL correctly at index 3.
The clone_fetch_push_over_https_match_the_server test also passed in both the Pulley and native runs in CI job 144247012230. The asserted dashed invocation is therefore not the path taken here; adding these helpers to DASHED is unnecessary for this transport path.
Local verification after installing the pinned Rust 1.100.0 toolchain: cargo test --locked -p bashkit --features git-wasi,http_client --lib --test integration -- git_wasi passed all 4 unit tests and 14 integration tests, including clone_fetch_push_over_https_match_the_server.
| let mut env: Vec<(String, String)> = ctx | ||
| .env | ||
| .iter() | ||
| .filter(|(k, _)| !k.starts_with("__BASHKIT_") && !k.starts_with("GIT_CONFIG_")) |
There was a problem hiding this comment.
[P1] Forced env vars lose to sandbox env because of duplicate order. ctx.env is only filtered for __BASHKIT_*/GIT_CONFIG_* (mod.rs:209), then .sort()ed, and the forced values (GIT_CONFIG_NOSYSTEM=1, GIT_EDITOR=:, GIT_PAGER=cat, GIT_TEMPLATE_DIR=...) are appended last (mod.rs:221-240). GuestState keeps that Vec order and environ_get exposes it in order, while wasi-libc getenv returns the first match — so a sandbox-supplied GIT_EDITOR/GIT_PAGER/GIT_CONFIG_NOSYSTEM/GIT_TEMPLATE_DIR silently overrides the forced value, and other GIT_* (GIT_SSH_COMMAND, GIT_ASKPASS, GIT_EXTERNAL_DIFF, ...) plus PAGER pass through unfiltered. Impact today is fail-closed only because resolve() refuses to exec anything but git and config reads stay inside the VFS — but the documented forcing ("Settings that would start other programs are forced through GIT_CONFIG_*", mod.rs:12-14) does not hold. Fix: strip all GIT_* (and PAGER/EDITOR) from ctx.env except an explicit allowlist, and emit forced entries first / dedup.
|
|
||
| /// A receive-pack request: commands, a flush, then the pack unless every | ||
| /// command deletes. | ||
| async fn read_push(&mut self) -> Option<Vec<u8>> { |
There was a problem hiding this comment.
[P2] read_push buffers the whole pack in host memory with no cap (remote.rs:172-196): after the flush it does req.append(&mut self.buf) then reads stdin to EOF into req. MAX_OUTPUT (16 MiB) caps guest stdio, not this host-side buffer, so a large push duplicates the entire pack in host RAM (bounded in practice only by VFS/repo sizes). Consider applying the same output/memory ceiling here (and a shared cap for read_request), returning a clean error past it.
Review summary (head
|
chaliy
left a comment
There was a problem hiding this comment.
Reviewed head 6560059874c52057ec5723b9e0264d9d50e3d15f with Rust 1.100.0. The existing git WASI slice passed locally: 4 unit tests and 14 integration tests, including the HTTPS clone/fetch/push test. Two additional local probes reproduced the inline findings below.
The argumentless-child panic is contained by the existing builtin panic boundary, so I have classified it as P2. My earlier concern about child cleanup was not reproduced through Bash::exec: request-budget cleanup cancelled the pending VFS read, so I am not posting it as a confirmed defect.
| procs.reserve()?; | ||
| // git's HTTP transport: the host speaks the remote-helper protocol. | ||
| #[cfg(feature = "http_client")] | ||
| if let ("remote-https" | "remote-http", Some(url)) = (args[1].as_str(), args.get(3).cloned()) { |
There was a problem hiding this comment.
[P2] Check for a subcommand before indexing child argv
With git-wasi,http_client, git -c alias.x='!git' x starts a child whose argv is just ["git"]. resolve() accepts that vector, then args[1] panics here. Reproduced locally at this head: index out of bounds: the len is 1 but the index is 1. The existing builtin panic boundary contains the unwind, but the command returns git: builtin failed unexpectedly instead of git's normal usage output. Please use checked access for the helper match and cover an argumentless child git invocation in a regression test.
| let mut result = ExecResult::with_code(out.stdout, code); | ||
| result.stderr = stderr.into(); | ||
| Ok(result) |
There was a problem hiding this comment.
[P2] Propagate the guest output truncation flag
Output::write() discards bytes beyond the shared 16 MiB cap and sets out.truncated, but this return path ignores that flag. With the outer stdout limit raised to 32 MiB and sufficient intermediate-memory budget, a local probe reading a 17 MiB blob through git cat-file blob returned exit code 0, exactly 16,777,216 stdout bytes, and both truncation flags false. Callers therefore receive incomplete blob/archive data presented as complete output. Please propagate truncation into ExecResult and report it, as the CPython return path already does.
This started as an exploration spike. It was looking good, so I thought it was
worth sharing to see if it aligns with where you want git support to go. A
second step is ready on top of this one: running git's hooks, aliases and
editor commands in Bashkit's own interpreter.
What changed
With the new opt-in
git-wasifeature,gitruns upstream git 2.55 compiledto
wasm32-wasip1instead of the simulated git. It is configured as before,through
BashBuilder::git(GitConfig). Without the feature, nothing changes..gitrepositories inthe VFS. This includes merge, rebase, stash,
gc, and local clone, fetchand push.
HttpClient, afterGitConfig's remote allowlist. Credentials never reach git.!aliases, editors andpagers are refused, and ssh and
git://can't connect.and is charged to the execution budget.
git-wasi-native: compiles git to machine code, likecpython-native.How it runs:
run-command.c. Childprocesses use git's existing Windows spawn path, and
start_async()asksthe host to copy the instance instead of forking.
builtins/wasi_host.rs, andboth guests use it.
bashkit-git-wasmcarries the module (1.1 MB). It can berebuilt with
guest/build.sh.Why
The simulated git covers about 20 subcommands and has no network. Agents
expect git's behavior and output.
We first tried rewriting git on gitoxide and stopped at ~17.8k lines, with
most of git still missing. Running git itself takes ~1.5k lines of Rust and
~500 of C.
Before / After
Before:
After:
git_wasi_tests.rsruns 52 steps in Bashkit and inhost git, and requires identical output. The steps include merge, rebase,
clone, push and pull.
git fsck --strictaccepts every repository Bashkit wrote.git http-backend.Timings are Criterion medians on a repository with 200 commits:
status --shortlog --onelinecloneRisk
Medium. The feature is opt-in and off by default.
bashkit-git-wasmisGPL-2.0-only AND MIT AND Zlib,with a
deny.tomlexception for that crate only. Bashkit stays MIT, andgit runs as a separate sandboxed program.
BASHKIT_GIT_WASM. The crate becomes MIT, exceptguest/patches/.L-GITW-001to008andTM-GIT-016to022.Checklist
security, fuzz targets and a benchmark.
GitConfigAPI.
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.