S08-10 - WSL
Purpose: How the fetches of the git round trip cross between a WSL distribution and the Windows side.
Design
Section titled “Design”When wb runs inside WSL (S12-platformsS12-platforms: PlatformsWhich host and guest operating systems Wraith Box targets, how platform-specific code is isolated, what each platform uses, and how wb works inside WSL.), the repository is in the WSL
distribution. export.git and landing.git are on the Windows side.
Both fetches cross between the two with git fetch --upload-pack=<command>:
| Fetch | Runs on | Its upload-pack runs on |
|---|---|---|
| Export update | the Windows side, wb.exe relay |
the WSL side, wb upload-pack-relay |
| Land and diff | the WSL side, wb |
the Windows side, wb.exe landing-upload-pack |
Everything else in S08-workspace-and-gitS08-workspace-and-git: Workspace and Git Round TripHow code gets into the guest and how the agent's work gets back out, without sharing the host filesystem. is the same under WSL.
The command is shell text
Section titled “The command is shell text”Git runs the --upload-pack value as a POSIX shell command line, with
sh -c. On the Windows side that is the sh of Git for Windows. Git
appends the fetch’s path as the last word.
The side that composes the value:
- checks each project ID and session ID in it against its format;
- single-quotes every word the way git’s
sq_quote_bufdoes. The word goes in single quotes, with each'in it written as'\''and each!as'\!'.
The quoting covers the program’s path, the distribution and user names, the repository’s path and the IDs. No word can expand or split.
- The path of
wsl.exeis written with forward slashes, whichshdoesn’t read as escapes. - The first word is an absolute path. Git then doesn’t look up a remote
helper, and the shell doesn’t search
PATHfor the program.
The Git for Windows sh converts arguments that look like POSIX paths
into Windows paths when it starts a program that isn’t an MSYS program,
such as wsl.exe. /usr/local/bin/wb or /home/<user>/repo would then
reach the distribution as Windows paths. MSYS_NO_PATHCONV=1 turns that
conversion off. The Windows-side fetch runs with it in its environment.
The placeholder path
Section titled “The placeholder path”The fetch’s path is a placeholder that the program ignores. But git
reads an existing bundle file at that path as a bundle, and then
ignores --upload-pack (reproduced with git 2.56.0 for I67I67 (closed): wb-hostd can't read the user's repository under its sandbox profile (S08 upload-pack)Found in the review of #65 (X23-sandboxed-daemons result).). So the
composing side:
- creates a new empty directory, readable only by the user, in its temporary directory;
- uses
wb-relayin it as the placeholder; - checks with
lstat, right before the fetch, that the placeholder doesn’t exist.
The check guards against a file that is already there. Between the
check and git’s own stat, only a process of the user can create one,
because only the user can write the directory.
T00-indexT00-indexboundary 6 is the host terminal stream. trusts the user’s processes. On Windows they include
wb-hostd, until I190I190 (open): wb-hostd write rule for landing.git without export.git on Linux and WindowsFound while writing #67 into S04-architecture. gives it a profile there. What it could gain
depends on the side:
- The WSL-side placeholder belongs to the land and diff fetches. A
bundle there puts objects and refs of its choosing in a landed branch
or the
wb diffscratch repository. T16-hostd-landingT16-hostd-landing: A compromised `wb-hostd` decides what `wb land` brings inwb-hostd faces the guest, and it may read every project's export.git and write every project's landing.git (S04-03-self-sandboxing, "Each host daemon is self-sandboxed"). already covers that. - The Windows-side placeholder belongs to the export update. A bundle
there puts objects and refs of its choosing in
export.git, which T16-hostd-landingT16-hostd-landing: A compromised `wb-hostd` decides what `wb land` brings inwb-hostd faces the guest, and it may read every project's export.git and write every project's landing.git (S04-03-self-sandboxing, "Each host daemon is self-sandboxed"). doesn’t cover. On Windows that adds nothing until I190I190 (open): wb-hostd write rule for landing.git without export.git on Linux and WindowsFound while writing #67 into S04-architecture., because without a profilewb-hostdcan already writeexport.gitthere.
Fetch settings
Section titled “Fetch settings”Each fetch runs with the settings of S08-06-landing-on-the-hostS08-06-landing-on-the-host: Landing on the HostHow wb land and wb diff bring a session's work into the user's repository, and the checks that keep that fetch from running anything.,
“Fetch settings”: GIT_PROTOCOL_FROM_USER=0, protocol.allow=never,
protocol.file.allow=always and --no-recurse-submodules.
Export update
Section titled “Export update”The WSL-side wb starts wb.exe relay on the Windows side
(S12-05-wslS12-05-wsl: WSLHow wb works inside a WSL 2 distribution on a Windows host (FR16-wsl).). The relay runs as the Windows user, outside any
sandbox. It is the wb of S08-02-export-repositoryS08-02-export-repository: Export RepositoryWhich refs and objects the guest can fetch from export.git, and how wb, its one writer, keeps it safe to run git in. and
S08-07-repository-lifecycleS08-07-repository-lifecycle: Repository LifecycleWhen objects leave export.git and landing.git, and the locks that order that work against fetches and pushes. for export.git, with the Windows host git
(S08-08-host-gitS08-08-host-git: Host GitWhich git binary runs on the host, the oldest version Wraith Box accepts, and where that is checked.).
- It takes the export lock over
wb-hostd’s named pipe. - Under the lock it checks the layout and
configofexport.git. - It fetches, deletes refs, and runs the shrink steps and the prune.
Its --upload-pack command is wsl.exe from the Windows system
directory, with:
- the distribution and the Linux user of the WSL-side
wb; --execand the WSL-sidewb’s absolute path;- the subcommand
upload-pack-relay; - the repository’s path.
The WSL-side wb sends those values. wb.exe takes none of them from
wb-hostd.
In the distribution, wb upload-pack-relay checks that the path is the
git common directory that the rules of S05-04-namingS05-04-naming: NamingHow wb identifies a project, a session and its branch, and how projects are registered, checked, moved and removed. give for that
path. Then it runs git upload-pack on it, with GIT_NO_LAZY_FETCH=1
and its own git, which it resolves and checks by S08-08-host-gitS08-08-host-git: Host GitWhich git binary runs on the host, the oldest version Wraith Box accepts, and where that is checked.. WSL
interop carries the standard input and output.
Land and diff
Section titled “Land and diff”The WSL-side wb runs the fetch of S08-06-landing-on-the-hostS08-06-landing-on-the-host: Landing on the HostHow wb land and wb diff bring a session's work into the user's repository, and the checks that keep that fetch from running anything. in the
distribution. It fetches into the user’s repository, or the scratch
repository of wb diff.
Its --upload-pack command is wb.exe, at the path the WSL-side wb
uses to start the relay, with the subcommand landing-upload-pack, the
project ID, and the session ID. wb.exe then:
- checks both IDs against their formats again;
- derives the landing repository’s path itself;
- runs the checks of S08-06-landing-on-the-hostS08-06-landing-on-the-host: Landing on the HostHow wb land and wb diff bring a session's work into the user's repository, and the checks that keep that fetch from running anything. on it;
- runs
git upload-packon it with the Windows git.
Decisions
Section titled “Decisions”wb-hostd stays out of both streams
Section titled “wb-hostd stays out of both streams”- Why:
wb-hostdthen never becomes the fetch client of anupload-packon the user’s repository. Over protocol v2 that client could ask for any object of the repository by its ID (X07-git-round-tripX07-git-round-trip: Git round tripRemote helper over vsock, read-only upload-pack, restricted receive-pack into the landing repository, flagging of risky paths.).
One writer for export.git, on the Windows side
Section titled “One writer for export.git, on the Windows side”The WSL-side wb doesn’t write export.git over the cross-OS file
share. export.git has one writer, on the Windows side, with the
Windows git.
Status: Draft