S04-06 - Git and the `wb-hostd` Profile
Purpose: How git runs on data from the guest, what the wb-hostd profile
lets it write, and what wb takes from wb-hostd.
Design
Section titled “Design”wb-git
Section titled “wb-git”The git gateway runs git on data the guest sends. That git starts
through wb-launcher as wb-git: a shim that applies a profile for
one repository and then runs git.
The launcher table has two fixed entries, so the subcommand is never a free string:
wb-git-receive, forgit receive-pack;wb-git-upload, forgit upload-pack.
Besides its program, a wb-git request holds one field: the
repository.
The repository check
Section titled “The repository check”wb-launcher takes the real path of the projects root once, when it
starts. That is <data>/projects, from configuration wb-hostd read
before it confined itself.
It accepts the repository only if it equals, after cleaning,
<real path of the projects root>/<id>/<basename> (I41I41 (closed): S08-workspace-and-git: which git data reaches the guest, and host git as a parserS08-workspace-and-git says how bytes move, but not which data the guest may get or how much the host trusts its own git when it parses guest data:, 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).):
<id>is in the project ID format;<basename>islanding.gitforwb-git-receive, andexport.gitforwb-git-upload.
It never resolves the request string itself, which would follow a
symbolic link an attacker placed. The shim repeats the same check
before it calls sandbox_init.
The repository becomes the shim’s profile parameter and git’s one path argument. This is a bounded exception to “no arguments”. The Seatbelt match on the resolved path is the control that matters. The path check is defense in depth (X23-sandboxed-daemonsX23-sandboxed-daemons: Self-sandboxed Go daemons on macOSCan wb-netd, wb-proxyd and wb-hostd confine themselves at start with a sandbox profile, as S04-architecture says, while the Go runtime, inherited descriptors, and Keychain and Secure Enclave access in wb-proxyd keep w…).
The wb-git profiles
Section titled “The wb-git profiles”Both profiles allow reading the git installation and writing
/dev/null. The only programs they let the shim start are:
- git, and the programs of its own installation
(
libexec/git-core/); - for
wb-git-receive, the pre-receive check in the bundle’s hooks directory (S08-04-push-checksS08-04-push-checks: Push ChecksThe checks that bound the memory and work of a push before git unpacks it: git's allocation limit, the pack scanner, and the pre-receive check., “Pre-receive check”).
Neither allows a shell. A command that git would run through one
fails, such as a core.alternateRefsCommand from a repository’s own
configuration.
- The
wb-git-uploadprofile allows reading itsexport.git, and no other write.upload-packonly reads the repository it serves (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).). - The
wb-git-receiveprofile allows reading and writing itslanding.git. It allows reading, never writing, theexport.gitnext to it, whichlanding.gitborrows objects from (S08-03-pushesS08-03-pushes: PushesWhere the guest's pushes land, the settings receive-pack runs with, which refs a push may write, and the push at session end., “Landing repository”).
wb-hostd writes landing.git/config as fixed content when it creates
the repository. It checks at start that each landing.git/config still
holds exactly that content. It refuses pushes to a project whose
config differs.
export.git has one writer
Section titled “export.git has one writer”wb-hostd never opens the user’s repository, and its profile doesn’t
name one. wb, running as the user outside any profile, fetches the
selected refs from the user’s repository into the project’s
export.git. It is the only writer. wb-hostd only serves export.git
to the guest, through wb-git-upload (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.,
decided on 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).).
The wb-hostd profile
Section titled “The wb-hostd profile”wb-hostd’s profile allows reading <config>, and reading and writing
<logs> and <data>. These are the exceptions
(SEC12-least-privilegeSEC12-least-privilege: Least privilege on the hostNo root or administrator rights at run time and no extra host user accounts., SEC03-no-host-execSEC03-no-host-exec: No host code execution via returned workNothing the agent produces executes on the host without an explicit user action; returned changes to files the host may later execute are flagged.):
- The projects root. Under the projects root
<data>/projectsit may read everything. It may write only inside<data>/projects/<id>/landing.git: that path and everything below it, for any<id>. It can’t writeexport.git, a project directory, or the projects root itself. So it can’t create, rename or remove any of them. - The path down to it. It can’t write
<data>itself, or any other directory between<data>and the projects root. So it can’t rename or remove them. Seatbelt checks a rename against the two paths it names, not against what the moved directory holds. Without this rulewb-hostdcould move<data>into<logs>, write theexport.gitinside it, and move it back. - Hard links. It can’t make a hard link whose source is under the
projects root outside a
landing.git. Seatbelt checksfile-linkagainst the source path as well as the new name. So the rule that denies writingexport.gitdenies linking its files into a placewb-hostdmay write.
wb runs git in export.git, and git trusts a repository’s own
configuration. So a compromised wb-hostd that could write there could
make wb run a program.
wb-hostd can still rename landing.git out of its project directory,
replace it, or create it as a symbolic link to anything. The rule
allows every write at that path. So wb never runs git with
landing.git as its repository, and checks it before every fetch from
it (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.).
The rules on macOS
Section titled “The rules on macOS”On macOS the profile’s rules come in this order:
- allow writes under
<data>and<logs>; - deny writes to the literal path of
<data>, and of each directory between it and the projects root; - deny writes under the projects root;
- allow them again where both
(subpath <projects root>)and a regex match.
A later Seatbelt rule takes precedence over an earlier one.
The regex doesn’t hold any byte of the projects root’s path, which
therefore doesn’t need escaping. It pins the depth instead: ^,
followed by one /[^/]+ per component of the projects root’s real
path, then /[^/]+/landing[.]git(/|$). wb-hostd builds it from that
count before it confines itself, and passes it as a profile parameter.
Who creates what follows from those rules (S05-cliS05-cli: Command Line InterfaceSpecify wb, the single user-facing command.):
wb setupcreates the projects root before it starts the service;wbcreates each project directory and itsexport.git;wb-hostdcreateslanding.gitinside it;- at
wb project rm,wbremoves the project directory.
The profile probes
Section titled “The profile probes”wb setup also creates a probe directory,
<projects root>/.wb-probe/export.git, with one file in it, probe.
.wb-probe isn’t in the project ID format, so no request can name it.
Right after it confines itself, wb-hostd tries each of these:
- creating a file in the projects root;
- writing
.wb-probe/export.git/probe; - hard-linking
.wb-probe/export.git/probeto a fixed name in<data>/run; - renaming
<data>to a fixed name in<logs>; - renaming
.wb-probeto a fixed name in<data>/run; - creating
.wb-probe/landing.git-probe, next to where alanding.gitwould be. That checks that the regex ends atlanding.gitor a/after it.
It exits when one succeeds, or fails for any reason other than the
sandbox’s denial. When the probe file is missing, it exits with a
message that says to run wb setup, which creates it again
(NFR06-explained-refusalsNFR06-explained-refusals: OperabilityEvery refusal names the rule that caused it and how to change it.).
These probes check the macOS profile. They don’t carry over to Windows
as they are, because there <logs> is inside <data>
(S12-01-platform-interfacesS12-01-platform-interfaces: Platform InterfacesHow platform-specific code is isolated behind interfaces, and what each host OS uses for each., “Paths”). I190I190 (open): wb-hostd write rule for landing.git without export.git on Linux and WindowsFound while writing #67 into S04-architecture. covers Linux and Windows.
wb takes no path, URL or program from wb-hostd
Section titled “wb takes no path, URL or program from wb-hostd”wb runs as the user outside any profile. So what it runs is the
boundary that SEC12-least-privilegeSEC12-least-privilege: Least privilege on the hostNo root or administrator rights at run time and no extra host user accounts. puts around a compromised
wb-hostd. wb never:
- runs a binary that
wb-hostdnames; - passes git a path or URL that
wb-hostdhanded it; - runs git with a repository that
wb-hostdcan write as its repository.
Git reads such a repository for wb in two places only:
- the
upload-packthat a fetch from it starts; - on WSL, the
git upload-packthatwb.exe landing-upload-packruns onlanding.gitafter its checks, for the fetch of the WSL-sidewb(S08-10-wslS08-10-wsl: WSLHow the fetches of the git round trip cross between a WSL distribution and the Windows side.).
Neither runs a command from that repository’s own configuration (protected configuration, 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.).
wb derives each path under <data> itself, from IDs it checks
against their format. It compares any path wb-hostd reports with its
own, and refuses on a mismatch. A directory wb-hostd can write, such
as landing.git, is only ever the remote of a fetch that wb runs in
another repository (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., 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.).
Decisions
Section titled “Decisions”Git runs in the wb-git shim
Section titled “Git runs in the wb-git shim”- Why: a git bug then stays inside one repository’s profile.
- Rejected: git as a child of
wb-hostd, under thewb-hostdprofile. That is the measured, weaker fallback. A git bug would then reach every project’s policy, the approvals instate.db, other projects’ landing repositories, and the audit log. Falling back would need a spec change and a T00-indexT00-indexboundary 6 is the host terminal stream. entry for the residual risk. - Decided: I34I34 (closed): X23-sandboxed-daemons: Self-sandboxed Go daemons on macOSX23-sandboxed-daemons (added to S11-verification-and-spikes in #14), B34-sandboxed-daemonsB34-sandboxed-daemons: Can the Go daemons confine themselves on macOS?Yes, with conditions..
A path in the request, with a descriptor as the fallback
Section titled “A path in the request, with a descriptor as the fallback”- Rejected for now:
wb-hostdcould hand over an inherited directory descriptor that the launcher checks withF_GETPATH, in place of a path. That keeps the path out of the request. It is the fallback if the path check turns out to be fragile.
Status: Draft