S08-02 - Export Repository
Purpose: Which refs and objects the guest can fetch from
export.git, and how wb, its one writer, keeps it safe to run git in.
Design
Section titled “Design”Selected refs
Section titled “Selected refs”export.git holds only the refs that some live session of the project
selected. A session selects:
- the branch the user’s
HEADpoints to; - the refs listed in
export_refsin the project’s settings,<config>/projects/<project-id>.toml(S04-architectureS04-architecture: ArchitectureName the processes, the boundaries between them, and which requirement each boundary serves.).
An entry in export_refs is a full ref name, matched exactly. A listed
ref the user’s repository doesn’t have is skipped with a message. The
list is host configuration only. Repository-supplied configuration
(.wraithbox/, S09-policy-credentials-auditS09-policy-credentials-audit: Policy, Credentials, Certificates and AuditWhere policy comes from, how secrets are held, how TLS inspection is trusted, and what is recorded.) can’t add a ref, because
the guest can write it.
A session is live from its start until it ends.
- A lost session (S06-09-session-lifecycleS06-09-session-lifecycle: Session LifecycleA session's states from wb claude to its summary, how it starts and ends, its deadlines, and when its VM may be saved.) stays live
until its recovery,
wb discardorwb project rmends it. Its WIP push then still has its base. - A session that has ended but isn’t discarded yet isn’t live. Its
pushed work in
landing.gitis kept by the copy in 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., not by refs inexport.git.
Parallel sessions
Section titled “Parallel sessions”Sessions of one project run in parallel (FR05-parallel-sessionsFR05-parallel-sessions: Parallel sessionsSeveral sessions can run at once, in the same project and across projects.).
export.git holds the selections of every live session, not only the
newest.
- Each session’s selection is kept under
refs/wb/session/<session-id>/, at the commits it had when the session started. refs/wb/session/<session-id>/HEADholds the user’sHEAD, also when it is detached. Each other selected ref is below that prefix under its full name.- The newest session’s selection is also under the plain names.
export.git’sHEADpoints to its branch, or is detached at its commit.
Every commit a live session starts from is then reachable from a ref.
receive-pack advertises those refs to a push into landing.git as
bases (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., “Borrowed objects”).
Hidden refs
Section titled “Hidden refs”The guest’s upload-pack runs with uploadpack.hideRefs set to
refs/wb/session/ and !refs/wb/session/<own-session-id>/. A
session’s guest isn’t offered other sessions’ refs.
That is cosmetic. Over protocol v2 the guest can still fetch any object
in export.git by ID. So a guest can read the bases of the project’s
other live sessions, and keeps what it fetched earlier
(T12-shared-exportT12-shared-export: Sessions of a project share what they can
fetchA project's export.git holds the refs that any live session of the project selected (S08-02-export-repository).).
One writer
Section titled “One writer”wb-hostd never opens the user’s repository, and export.git has one
writer, wb. At session start, wb runs as the user and:
- takes the project’s export lock through
wb-hostd’s local IPC (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.); - runs one
git fetchfrom the user’s repository intoexport.git, with an explicit source and destination ref for each selected ref. That fetch runsgit upload-packon the user’s repository locally; - deletes the refs of sessions that
wb-hostdreports as no longer live, after it checks each session ID against the session ID format.
wb-hostd only serves export.git to the guest, read-only, through
the wb-git-upload shim. The shim’s profile doesn’t allow writing it.
wb-hostd’s own profile doesn’t allow writing export.git, the
project directory that holds it, or the projects root
(S04-03-self-sandboxingS04-03-self-sandboxing: Self-SandboxingHow each host daemon confines itself at startup, and the wb-launcher that starts confined programs on macOS., “Each host daemon is self-sandboxed”). That denial
is the control. wb runs git in that repository, and git trusts a
repository’s own configuration.
wb creates the project directory, and export.git in it with
git init --bare --template=, which doesn’t copy template files. Then
it writes config itself.
Layout check
Section titled “Layout check”As a second layer, before each run wb checks that export.git holds
only the fixed layout it creates and the files its own git commands
write:
HEAD,configandpacked-refs;- refs under
refs/; - loose objects under
objects/; - the directories
objects/infoandobjects/pack; - in
objects/pack, packs with their.idx,.revand.bitmapside files.
Every entry must be a regular file or a directory. Every file must
have a link count of 1, so a hard link into export.git is refused
too. config must hold exactly what wb wrote.
Any other file refuses the run. Among them are
objects/info/alternates, objects/info/packs, info/refs,
FETCH_HEAD, commondir, info/grafts and shallow. To keep its own
runs inside that layout, wb runs every git command in export.git
with these settings on its command line:
core.hooksPath=/dev/null;gc.auto=0andmaintenance.auto=false;repack.updateServerInfo=false.
It fetches with --no-write-fetch-head.
An interrupted run of wb can leave files behind. While it holds the
export lock, and before the check, wb removes them, because no other
process writes there:
HEAD.lock,config.lockandpacked-refs.lock;*.lockfiles underrefs/;objects/pack/tmp_*andobjects/pack/*.keep.
It examines each one with lstat. It refuses the run instead of
removing an entry that isn’t a regular file with a link count of 1.
Partial clones
Section titled “Partial clones”On a partial clone, upload-pack refuses to fetch missing objects from
the user’s origin (git-upload-pack(1), GIT_NO_LAZY_FETCH). wb
sets GIT_NO_LAZY_FETCH=1 as well. An update that needs such an object
fails, and the session doesn’t start, with that reason.
What the guest can read
Section titled “What the guest can read”export.git holds a copy of every object it serves, and borrows from
nothing. The guest can read everything in its object store.
- Over protocol v2,
upload-packserves any object it has to a client that names the ID, also one thatuploadpack.hideRefshides. Souploadpack.hideRefsonly trims the advertised ref list, and isn’t access control (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.). - Objects reachable only from the user’s other branches, tags, notes
and stash are never in
export.git. A guest that knows such an object’s ID still can’t fetch it (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.).
When a ref leaves the selection, its objects are removed as 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. says.
Decisions
Section titled “Decisions”Only selected refs
Section titled “Only selected refs”export.git holds only the refs that live sessions selected, not the
whole user repository.
- Why: over protocol v2 the guest can fetch any object it can name.
What isn’t in
export.gitis the only thing it can’t read. - Decided: B41-git-data-scopeB41-git-data-scope: Which git data may reach the guest, and how far does the host trust its own git?Serve the guest from a host-side export repository holding only the session's branch, scan carried-in files, clean remote URLs, and require a minimum git version., item 1.
wb writes export.git, not wb-hostd
Section titled “wb writes export.git, not wb-hostd”- Why:
wb-hostdfaces the guest and never opens the user’s repository. Git trusts a repository’s own configuration, sowb-hostdmust not be able to write the repositorywbruns git in. - Decided: 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)..
Status: Draft