Security model
drawbar sits in front of git for every agent and service you run, so a flaw
in it runs with your rights. The model below says whose rights those are, what
the shim does to avoid running the wrong git, and what each command that
changes your machine checks before it does.
Trust boundary
drawbar runs as the user who installed it. It needs no root, installs nothing
system-wide, and Phase 1 has no daemon and no socket
(ADR 0001).
Phase 2 adds drawbard, a per-user daemon on a Unix socket that runs a
git fetch for the shim
(ADR 0014).
A leased git fetch sends it the real git’s path, the working directory with
its device and inode, the umask, the arguments, the lease wait and the whole
environment, which can hold tokens. The shim sends nothing unless every
directory and symlink from the root to $XDG_RUNTIME_DIR belongs to root or
this user, any of them another user can write to is sticky, the drawbar
directory below it belongs to this user with no group or other access, and the
socket is a socket, not a symlink, that belongs to this user. Otherwise it
runs its own fetch under the lease. The daemon opens the working directory by
its path, so it refuses a request whose path passes through a directory that
belongs to another user, or that another user can write to without the sticky
bit: no other user can then put their own repository at that path between the
daemon’s check and the git it starts there
(ADR 0016).
Other processes that run as the same user share that trust boundary. They can
already run anything drawbar can, so drawbar treats these inputs as trusted:
the environment (DRAWBAR_REAL_GIT, DRAWBAR_LEASE_WAIT, DRAWBAR_MAKE,
DRAWBAR_SYSTEMCTL and the other DRAWBAR_* variables), the config file, and
everything under ~/.local/opt and ~/.local/bin. The checks below defend
against a wrong git being run by accident, a corrupted download, and a
half-finished install. They do not defend against another process of the same
user.
The crate denies unsafe_code in Cargo.toml. System calls such as flock,
kill and waitid come from the safe API of rustix, and signal handling
from signal-hook
(ADR 0005).
Finding the real git
The shim never searches PATH for git, so a directory an attacker or a
mistake puts ahead of /usr/bin cannot choose the binary it runs. It tries a
fixed list of candidates in order:
$DRAWBAR_REAL_GIT,$AGENT_GIT_REAL, the shell prototype’s name for it,- the newest
~/.local/opt/git-2.56.*/bin/git, - the newest
~/.local/opt/git-2.*/bin/git, /usr/bin/git.
A candidate must be an absolute path to a regular file with an execute bit. The shim then rejects it when any of these holds:
- it is the running executable, by canonical path or by device and inode,
- its bytes contain a marker string that every drawbar build embeds, so a copy of the shim, however it was renamed or moved, is recognized,
--version, run with a 2 second timeout and a 4 KiB output cap, does not answer like git. The probe runs withDRAWBAR_DEPTHalready at its limit, so a wrapper that execs the shim refuses at once instead of looping.
A rejected candidate is skipped, except for an explicit override. A
DRAWBAR_REAL_GIT or AGENT_GIT_REAL that names the shim or a copy of it
fails resolution with exit 78 and a message naming the variable, because
following it would loop and quietly running the next candidate would hide the
mistake
(ADR 0002).
As a second guard, every git the shim starts gets DRAWBAR_DEPTH one higher
than its own. At 16 the shim refuses to run and exits 78.
The shim hands your arguments to git as raw bytes with no shell in between, so
a repository path or argument is never reparsed. It adds only its own -c
flags ahead of them. Its diagnostics
are one line each, with any newline in a path or variable escaped, so a hostile
file name cannot forge extra output lines.
The resolve cache
So that the common call stays under a millisecond, the shim caches the answer in
$XDG_CACHE_HOME/drawbar/real-git.cache, or ~/.cache/drawbar/real-git.cache.
XDG_CACHE_HOME and HOME count only when they are absolute paths. A hit costs
one small file read and a stat of the opt directory, the cached git, and each
higher-priority candidate that was skipped, and it spawns nothing. The entry is
used only while the override variables, the opt directory’s modification time,
and each stat (device, inode, size, mode and modification time) still match
what was probed, so replacing or adding a candidate sends the next call back
through the probes. A candidate whose probe failed is not cached. The shim
writes the entry to a temporary file and renames it into place, so a concurrent
call reads the old entry or the new one, never half of one.
drawbar status reads the cache without writing it.
The lease lock file
Commands that rewrite refs and packs take an exclusive flock on
<common-dir>/drawbar-lease.lock (Per-repo lease).
- Close-on-exec. The lock file is opened with
O_CLOEXEC, so git and any process git starts, such as a detachedgit maintenanceor a hook, never holds the lease. The kernel releases it however the shim exits (ADR 0005). - Permissions. The shim creates the file exclusively (
O_EXCL) with mode0644whatever the caller’s umask, so every user of the repository can open it to lock it from the moment it exists. Otherwise it opens the file read-only, sinceflockneeds no write access, so a lock file that another user created still serializes both users. The shim sets the umask briefly before it starts any thread, so the change reaches no other file. - Refusal paths. When git cannot name a common directory, as outside a
repository, the command runs unleased and git reports its own error. Once git
has named it, a lock file that cannot be opened or locked stops the command
with exit
75and one line naming the file, because running git unleased there would bring back the races the lease prevents. A lease still held when the wait ends also exits75. In both cases git never ran. - The lease is advisory. It orders processes that take it. A process that
can open the file can also hold it, and everyone else waits, up to
lease.timeout_secs(120 seconds by default), then exits75. - Stamp. A taken lease sets the file’s modification time to now, which
drawbar doctoruses to tell how long it has been held. A user who cannot write the file leaves the time as it was. - Signals. The shim forwards
SIGTERM,SIGINT,SIGHUPandSIGQUITto git and stops forwarding before it reaps git, so it never signals a process ID the kernel has handed to something else. When git dies of a signal, the shim turns off its own core dumps (RLIMIT_COREandPR_SET_DUMPABLEto 0) and dies of the same signal.
Stopping fsmonitor daemons
drawbar gc-daemons only looks at processes whose real and effective user ID
are yours. It signals a daemon by its exact PID through a pidfd, opened before
it checks the PID’s owner, command line and start time again, so a PID that
changes hands after the check is never signaled. It never matches by name with
pkill -f. When the config file is ignored it stops nothing
(ADR 0006).
Building Git
drawbar build-git downloads source and compiles it, so it checks the source
first
(ADR 0007):
- Pinned digests. The SHA-256 of each supported tarball (Git 2.56.0 and
2.56.1,
.tar.gzand.tar.xz) is in the binary, copied from kernel.org’s signedsha256sums.asc. drawbar does not fetch a checksum file at build time, because a digest fetched from the same mirror as the tarball proves nothing about the tarball. - Hash what is unpacked. The download, or a copy of
--tarball, lands in a scratch directory under the cache directory. drawbar hashes that copy and unpacks the same copy, so a file that changes after the check never reachestar. A mismatch stops the build before anything is unpacked. - Download.
curl -fsSL --proto =https --tlsv1.2from kernel.org’s mirror.tarruns with--no-same-owner. - Your digest is your decision. A version or tarball with no pinned digest
builds only when
--sha256supplies one, and drawbar checks the file against it and nothing else. - Stage, verify, rename.
make installwrites to a staging directory. drawbar checks thatlibexec/git-coreholdsgit-remote-httpsandgit-fsmonitor--daemon, then renames the tree onto~/.local/opt/git-<version>. A build that fails at any step removes its scratch and staging directories and leaves the destination untouched. - Never overwrite. drawbar refuses to build when the destination exists.
- Bounded.
make -j4by default, and a refusal to start below 4 GiB of available memory, so a build on a shared machine cannot exhaust it.
Install and uninstall
drawbar install changes a short, fixed list of paths, all in your home
directory
(ADR 0008):
| Path | Change |
|---|---|
~/.local/opt/drawbar/drawbar | The running binary, copied through a temporary file and a rename. |
~/.local/bin/git, ~/.local/bin/drawbar | Symlinks to that copy, each created under a temporary name and renamed over the old path. |
~/.local/opt/drawbar/displaced/ | Hard links to any entry the symlinks replaced. |
| Git’s global config file | An [init] defaultRefFormat = files block, appended only when init.defaultRefFormat is unset. |
~/.local/opt/drawbar/gitconfig.marker | A record of whether install appended that block and whether it created the file. |
| The systemd user unit directory | Four unit files, only with --timers, and drawbard.service, only with --drawbard. |
What keeps it reversible:
- Check, then change. Install reads every
~/.local/binentry and the config value before it writes anything, so a refusal leaves the home directory as it was. - Replace only on request. An entry drawbar did not make is replaced only
with
--force, or with--adopt-legacyfor the agent-git prototype’s symlink.--adopt-legacydecides by asking the filesystem whether the link resolves to the same file as~/.local/opt/agent-git/git, never by comparing link text, because a symlinked~/.local/binor a..after a symlink can make matching text point elsewhere. Install never replaces a directory. - Keep what was replaced. Install hard-links the old entry into
displaced/before the swap, and uninstall moves it back. - Edit git config the way git does. drawbar creates
<file>.lockexclusively before it reads the file and renames the lock over the file to commit, so nogit configwrite can land between its read and its write. A symlinked config file is locked and written at its target. - Strip the exact bytes. Uninstall removes the recorded bytes when the file
still ends with them. When it does not, it runs
git config --unset init.defaultRefFormat '^files$', which removes the value only while it is stillfiles. - Never
worktree.useRelativePaths. Install does not set it, because git older than 2.48 cannot read such worktrees. - Uninstall finishes. Each step runs even when an earlier one fails, every
failure is reported, and a
~/.local/binentry that no longer points at drawbar is left alone.
Deleting ~/.local/opt/drawbar by hand loses the displaced entries and the
marker, and uninstall can then no longer restore ~/.local/bin/git or remove
the config block.
The install script
deploy/install.sh downloads a release and hands it to drawbar install. It
checks the download before it runs anything from it:
- Checksum. It reads the archive’s SHA-256 from the release’s
SHA256SUMSand stops, changing nothing, when the archive is not listed or the digest does not match. - Attestation. When
ghis installed and signed in, it runsgh attestation verifyagainstOttoOps/drawbarand stops when that fails. Whenghis missing or not signed in, it says it skipped the check. The checksum file comes from the same release as the archive, so on its own it catches a corrupt or mismatched download. The attestation ties the archive to the release workflow’s build, which attests every release and signs and notarizes the macOS binaries (ADR 0010). - Local archives.
--archivewith--sumschecks the checksum only and prints thegh attestation verifycommand to run yourself. - Transport.
DRAWBAR_RELEASES_URLmust be anhttpsURL, or plainhttpon127.0.0.1orlocalhost, andcurlfollows redirects only to the same scheme. - Shape. The archive must be named
drawbar-<version>-<target>.tar.gzand hold adrawbarbinary that runs on this machine. It is unpacked into a temporary directory that the script removes on exit.
The systemd units
drawbar install --timers writes four units to the systemd user directory
(~/.config/systemd/user, or under $XDG_CONFIG_HOME), and
drawbar install --drawbard writes drawbard.service there, so nothing runs
as root and nothing is system-wide
(ADR 0009):
- Every unit starts with a
# drawbar unit:line. Install refuses, changing nothing, when a file at one of those names does not, or whensystemctl --user show -p FragmentPathsays systemd loads the unit from another file. Uninstall leaves such a file alone, and does not stop or disable a unit systemd loads from another file. - Both services are
Type=oneshot, run%h/.local/bin/drawbar, and setPATH=%h/.local/bin:/usr/local/bin:/usr/bin:/binandLimitNOFILE=1048576. The maintenance service also runs atNice=10with idle I/O scheduling. drawbar maintenancestarts each repository’s run through the shim, so it takes the repository’s lease and waits its turn behind agents. Maintenance never bypasses the lease.- The units are built into the binary, so
install --timerswrites the units that match the binary it installs. Customize them withsystemctl --user editdrop-ins, which drawbar does not touch. - Uninstall disables the timers and stops and disables
drawbard.servicebefore it removes any unit file, so a failedsystemctlcannot leave an enabled unit with a dangling link. drawbard.serviceruns%h/.local/bin/drawbar daemonwith the samePATHandLimitNOFILE, andXDG_RUNTIME_DIR=%t. ItsKillMode=mixedsendsSIGTERMto the daemon alone, so the fetches it runs for other processes finish before it exits. Uninstall removes$XDG_RUNTIME_DIR/drawbaronly when it belongs to you and no daemon holds its lock (ADR 0017).
The units set no sandboxing options such as ProtectHome. They run with your
full user rights, like any other command you run.
Reporting a vulnerability
Report suspected vulnerabilities privately through the security policy, not in a public issue or pull request.