- Cargo workspace with 5 sub-crates: alkgit-core (storage), alkgit-transport (smart protocol), alkgit-http, alkgit-ssh, alkgitd (binary); sha1 pinned through the gix stack, sha256 passthrough feature - docs/research/: vision, gitoxide alignment, alk stack fit, server-side protocol inventory, license/reference policy, POC plan - AGENTS.md: conventions mirroring alkcall (no comments, thiserror, tokio, no secrets on wire/at rest, visible-surface=authorized-surface, gitoxide-only serving path, bounded resources, registry-resolved repos) Verified: cargo build, clippy -D warnings, fmt, test, check --all-features
5.7 KiB
Research: git smart protocol (server side) — what we must implement
Status: initial pass complete
Date: 2026-09-19
Sources: gitoxide source reading (client-side parsers as reference),
git http-protocol + packfile protocol specs (git-scm.com protocol docs),
observation of gitserver's shape as a sanity check that the surface is this
small (no code reused — MPL-2.0 incompatible with our MIT/Apache-2.0; see
license-note.md).
TL;DR
The server-side surface is well-bounded: capability advertisement (V0/V1 and
V2 flavors), ls-refs, fetch negotiation (wants/haves → acks → pack),
receive-pack (pack ingestion + ref update CAS + status report), plus the
stateless HTTP framing and the SSH exec framing around them. gitoxide gives
us every primitive (pkt-line codec, pack parse/write, ref transactions,
fsck); what's missing is only the orchestration, which is ours to write —
and that's the layer where our auth/ACL model lives, which is exactly where
we want to own code.
Protocol surface inventory
V2 (the target; what modern git speaks first)
- Client sends
GIT_PROTOCOL=version=2(SSH: env line / http: header). - Server replies with capability advertisement:
version 2, then capabilities as pkt-lines:agent=...,ls-refs=...,fetch=...(shallow, filter, sideband-64k, packfile-uris...),object-format=sha1. command=ls-refswith args (peel, symrefs, ref-prefix) → server streams ref lines then flush.command=fetchwith args (want lines, have lines, done, thin-pack, no-progress, include-tag, shallow/deepen...) → server sendsacknowledgmentssection (acked ids orNAK), then eitherready+packfilesection (pack streamed over sideband) if done, or waits for more haves.
V0/V1 (fallback for old clients / http stateless)
- First response line:
"<capabilities> <null-octet> <ref> <obj-id>"style advertisement with refs, then fetch loop: wants → haves (NAK/ACK) → pack over sideband. Stateless-http variant requires the client to POST a separate request for each round;ackstate must be re-derived or the multi-round negotiation declined (we can require V2 for http and keep V0/V1 for ssh only — OQ candidate).
receive-pack (push; mostly version-independent)
- Client sends update requests (
<old> <new> <ref>) + optional shallow lines- pack stream (possibly thin).
- Server: validate CAS per ref (old must match current unless zero-id create),
fsck/connectivity the pack, apply ref transaction atomically, reply with
unpack <ok|ng>+ per-refok|ng <ref> <reason>lines.
Framing per interface
- SSH: single exec request
git-upload-pack '<path>'/git-receive-pack '<path>'/git-upload-archive; pkt-line on stdin/stdout; V2 via env var; sideband on fetch. - HTTP:
GET /info/refs?service=<name>(advertisement in# service=git-upload-packpreamble for smart clients),POST /<name>with pkt-line body; content-typeapplication/x-git-{upload,receive}-pack-*; chunked streaming both ways;Cache-Control: no-cache.
Server-side pack generation — the crux
gitserver (MPL-2.0, read-only reference) demonstrates the pragmatic path:
compute the pack from wants/haves and hand it to the response writer — they
use gix + hand-rolled protocol_v2 (742 LOC) and receive_pack (549 LOC) for
the whole protocol surface. We cannot copy that code, but its size confirms
the surface is small enough to own outright with gitoxide primitives:
- Pack generation options to POC:
a.
gix-pack bundle::writewith an in-memory sink (verify it can stream, not just write files). b.gix-pack::data::output::bytesentries-to-bytes writer fed by an object walk overgix-odb(full control over want/have closure; no file intermediates). - Thin packs (delta against client haves) are an optimization — v0 can
declare
thin-packunsupported initially; V2 fetch arg parsing must still accept/decline it gracefully. filter(partial clone) andpackfile-uriscan be declined in v1 of alkgit; advertised capabilities must be honest (never advertise what we don't serve — the gitea-class bug pattern is promising something and enforcing elsewhere).
Negotiation policy (ours to define)
Minimal correct initial policy:
- V2: respond with full
acknowledgments(common ids) each round; send pack ondone. - Enforce max rounds/haves budget per session (DoS bound), max pack size for receive, wall-clock limits for long negotiations.
- Shallow (` deepen/shallow lines) is a v2-later concern; reject with a clear pkt-line error initially (honest capability advertisement again).
Security-relevant protocol notes
git-upload-archiveis a separate command — do not serve it initially.- Path traversal: repo names on the wire (
git-upload-pack '~/x'or../) must normalize to a registry lookup — never to a filesystem path from the wire. Repo IDs resolve to storage roots configured server-side. - receive-pack ref names: validate against git ref rules (no
.., no control chars, norefs/heads/foo.lockgames) —gix-refname parsing plus our own deny-list for e.g.refs/reserved namespaces. - The advertisement phase must run ACL before emitting a single ref line (ref names leak info; private repos must not advertise anything).
Open items → architecture OQs
- OQ: support V0/V1 at all on http (or V2-only http, V0/V1 ssh)?
- OQ: shallow clone support timeline.
- OQ: thin-pack on fetch (requires delta against client have set).
- OQ: pack streaming composition (POC-1 outcome decides bundle-write vs entries-to-bytes).
- OQ:
object-format=sha256support policy (feature flag exists; no real ecosystem need yet — default sha1, keep flag).