Skip to content

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.

export.git holds only the refs that some live session of the project selected. A session selects:

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.

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>/HEAD holds the user’s HEAD, 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’s HEAD points 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”).

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).).

wb-hostd never opens the user’s repository, and export.git has one writer, wb. At session start, wb runs as the user and:

  1. 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.);
  2. runs one git fetch from the user’s repository into export.git, with an explicit source and destination ref for each selected ref. That fetch runs git upload-pack on the user’s repository locally;
  3. deletes the refs of sessions that wb-hostd reports 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.

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, config and packed-refs;
  • refs under refs/;
  • loose objects under objects/;
  • the directories objects/info and objects/pack;
  • in objects/pack, packs with their .idx, .rev and .bitmap side 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=0 and maintenance.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.lock and packed-refs.lock;
  • *.lock files under refs/;
  • objects/pack/tmp_* and objects/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.

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.

export.git holds a copy of every object it serves, and borrows from nothing. The guest can read everything in its object store.

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.

export.git holds only the refs that live sessions selected, not the whole user repository.

Status: Draft