Add git personal-access-tokens for HTTPS clone and push
Completes the git-over-HTTPS story: CLI `git clone/push https://...` of a
private repo now works via a personal access token, alongside the existing
SSH keys and the just-landed read-collaborator authz.
Backend:
- git_access_tokens table (migration 144): random mnw_-prefixed token shown
once; only its SHA-256 hash is stored. Optional expiry; per-token can_push.
- crypto::generate_git_token / git_token_hash.
- A git HTTP principal resolver: session cookie OR Authorization: Basic
<user>:<token> (git sends the token as the password). Wired into the
upload-pack (clone) routes so token-authed CLI clones resolve the user for
the owner/collaborator read check.
- New git-receive-pack (push) route + service=git-receive-pack on info/refs,
gated by authorize_push: a principal that's owner-or-push-collaborator AND,
if token-authed, a token carrying push scope. The pushed pack is streamed
into git's stdin (not buffered); same permit + kill-deadline as upload-pack;
2 GB body cap.
UI/API:
- Create/list/revoke endpoints + a token section in the git-access dashboard
tab (name, optional expiry, push checkbox); the plaintext is shown once.
Tests: token clone of a private repo (cookie-free, Basic auth), bad/revoked
token → 404, read-only token → 403 on push advert, push token → receive-pack
advert, plus create/revoke. +clear_cookies test helper.
Co-Authored-By
Claude Opus 4.8 <noreply@anthropic.com>
Author: Max Johnson <me@maxj.phd> · 2026-06-16 00:16 UTC