GITv
master
README.md245 lines, 21.9 KB

GITv

Git hosting with SSH pushes, public and private repository browsing, and read-only HTTPS cloning for public repositories.

  • gitv: the SSH forced-command handler (serve) and the root admin CLI (create, visibility, protect, description, default-branch, delete, add-key, keys, remove-key, trash, restore, purge, import)
  • gitv-web: the read-only browser (repositories, tree, blob, raw, log, commit, compare, tags, archive), with Markdown rendering and syntax highlighting (crates/gitv-web/src/render.rs)

Linking to code. A file's History lists the commits that changed it, and a folder's History does the same for everything inside. Permalink opens the file at the commit you're looking at, so the link keeps showing the same content after the branch moves. Click a line number to link that line (#L12). To link a range, add lines= to the address, for example …&lines=12-20#L12; the server marks those lines, and Permalink keeps the range.

Comparing revisions. /<owner>/<name>/compare?from=v0.1.0&to=main lists the commits to has that from lacks and the changes they make. A branch that has diverged is compared from where the two split, so the other branch's newer work isn't shown as undone. Any branch, tag or commit id works on either side, to defaults to the default branch, and the address can be shared. Each tag links to the changes since the previous tag in its history, and a branch's commit list links to its comparison with the default branch.

Source archives. Each tag on the tags page has a Source (.tar.gz) download, made by git archive from the tagged commit as it's requested, with every file under a <repository>-<tag>/ folder. /<owner>/<name>/archive?ref=<branch, tag or commit> works for any revision. The same revision always gives the same files and times. Downloads follow the repository's visibility, and share the raw-download limits below. Tag annotations serve as release notes; there are no uploaded release assets.

Who can read what. Over SSH each key reaches only its owner's repositories. The web browser has one account, and whoever signs in to it can read every repository on the server. It binds to localhost only; put it behind an HTTPS reverse proxy.

Existing and newly created repositories default to private. Publish one as its SSH owner or as the server administrator:

ssh git@git.um9i.dev visibility my-project public
# Equivalent command on the server
gitv visibility um9i my-project public

Anyone can now find it on the repository index, browse its files and history, and run git clone https://git.um9i.dev/um9i/my-project. Use the same visibility command with private to require sign-in again and disable HTTPS fetches. Copies already downloaded remain with their recipients. Pushes use SSH.

Description and default branch. A one-line description shows under the repository's name and on the index, where it can be searched along with names. The default branch is the one the web shows first and that clones check out. Without a value, each command prints the current one:

ssh git@git.um9i.dev description my-project A small toolbox   # "" removes it
ssh git@git.um9i.dev default-branch my-project release        # must be an existing branch
# Equivalent commands on the server
gitv description um9i my-project "A small toolbox"
gitv default-branch um9i my-project release

Protecting history. ssh git@git.um9i.dev protect my-project on (or gitv protect um9i my-project on) makes pushes refuse to force-update or delete any branch; new branches and ordinary pushes still work, and off lifts it. Git applies this to branches only: tags can still be moved or deleted, and the push log records it when they are. It's kept as a gitv-protected file in the repository, like visibility, so backups carry it, and the repository header shows it when you're signed in.

The description lives in git's own description file in the repository. Signed in, the repository header also shows whether it's public, and for a public repository both its HTTPS and SSH addresses.

Limits. The web server runs at most 16 page renders, 6 raw or archive downloads and 4 HTTPS clones at once. Some render and download slots are kept for signed-in sessions, so anonymous visitors can't crowd out the owner. Each anonymous client (an IPv4 address or IPv6 /64, as Caddy reports it) may hold at most 4 renders, 2 downloads and 2 clones at a time. Past these limits a request gets 503 at once rather than queueing.

Storage. Repositories live in /srv/gitv/repos/<owner>/<name>.git. Owner and repository directories must be real directories: GITv refuses symlinks at either level rather than follow them out of the tree. Everything works through open directory handles: git runs inside the repository directory it opened, new repositories are built and published inside the open owner directory (never replacing anything already at the name), deletion and purging move and remove through handles without following links, and the web index lists and fingerprints repositories the same way. A path swapped for a symlink after a check can't redirect any of it.

Deleting and recovering. delete (over SSH or as root) never removes anything: it moves the repository to <owner>/.trash/<name>.<unix time>, where it stops being served. The operator manages the trash:

gitv trash                                  # what's waiting, and for how long
gitv restore um9i my-project.1763800000     # back under its old name (or --as other-name)
gitv purge                                  # remove entries deleted 30+ days ago (--older-than-days N)

deploy/gitv-purge.timer runs gitv purge daily, so deleted repositories can be restored for 30 days.

History overwritten by a push can be recovered for the same 30 days. Every push records a reflog entry for each ref it changes, and keeps unreachable objects as long as those entries; for example, git -C <repo> rev-parse main@{1} finds where main pointed before a force-push. Git drops a branch's reflog when the branch is deleted, so each push also appends its ref changes to gitv-push.log in the repository (<unix time> <old> <new> <ref>, - for none). To bring back a deleted branch, find its last commit there and run git -C <repo> branch <name> <commit>.

SSH keys. Each key in /etc/gitv/authorized_keys reaches only its owner's repositories. Give each device its own key and a label, so a lost one can be revoked alone:

gitv add-key um9i laptop.pub --label "laptop"   # Ed25519 only; the key file's own comment isn't kept
gitv keys                                       # owner, SHA-256 fingerprint (as ssh-keygen -l shows it), label
gitv keys um9i                                  # one owner's keys
gitv add-key um9i laptop.pub --label "work"     # a key um9i already has: renames it in place
gitv remove-key SHA256:gNSIRW+2Iyiuvsdp/bgjy38bvWHw6wQm3tuoXrl3WjQ

Adding a key the owner already has, with a label, only renames it: its line keeps its options, and the key never stops working. A key registered to another owner is refused. remove-key rewrites the file atomically under the same lock as add-key and keeps every other line as it was, including hand-written ones (listed with - as the owner when they aren't a gitv serve command). sshd reads the file on each connection, so the key stops working at once, but a connection already open finishes what it is doing.

The browser follows the system's light or dark setting. Its stylesheet (crates/gitv-web/assets/style.css) and the Red Hat Display, Text and Mono fonts (crates/gitv-web/assets/fonts, SIL Open Font License) are built into the gitv-web binary, so the server needs no font packages.

Web sign-in

The browser asks for a username, a password and a code from an authenticator app (TOTP, as used by Google Authenticator, 1Password, Aegis and others). Create the account once on the server, as the user the browser runs as (or as root, which hands the file to the gitv-web account):

gitv-web setup            # account admin; --user NAME for another; --force to replace it (keeping its name)

It prints a generated password (20 random characters, shown only this once), the authenticator secret, and a QR code to scan. Then sign in at the browser's address.

  • Change the password under Account once signed in (it asks for the current password and a code), or on the server with gitv-web password. Either way every other session is signed out.
  • Lost the authenticator? Run gitv-web setup --force on the server for a new password and secret.
  • The account lives in /var/lib/gitv-web/login (or $GITV_WEB_AUTH), readable only by its owner. Root-run setup hands the default service directory to gitv-web. If you point GITV_WEB_AUTH into an existing custom directory, give the service write and search access there first. The password is stored as an Argon2id hash.
  • Sessions last up to 12 hours, including across browser restarts. Sign out to end a session on a shared device. The session cookie is Secure, so the browser must be reached over HTTPS (or on localhost).
  • Failed attempts are counted per client: an IPv4 address, or an IPv6 /64. After five, that client is locked out for a minute, doubling with each further failure up to 15 minutes. A client's count is forgotten after an hour without a failure. Someone guessing from elsewhere therefore can't lock you out. Across all clients together, at most 60 failures an hour are judged, which caps a distributed attack. While that cap is full, only browsers that have signed in before can try: a successful sign-in also sets a trusted-device cookie for 90 days, kept across sign-outs, so an attack spread over many addresses can't lock you out of a browser you've used. gitv-web setup --force (a new authenticator secret) forgets every such browser. The client's address comes from Caddy's X-Forwarded-For, which gitv-web trusts only on loopback connections. A code works once.

Until the account exists, pages requiring sign-in show setup instructions. Public repositories can already be browsed and cloned.

Layout

The repository is a Cargo workspace of three crates:

  • crates/gitv-core: what both programs share: configuration, name rules, working through directory handles, and running git with a deadline and an output cap
  • crates/gitv: the SSH command handler and administrator CLI
  • crates/gitv-web: the web browser and HTTPS clone service, with its templates and assets

gitv depends only on gitv-core and a few small crates, so building it (cargo build -p gitv) never compiles the web server's dependencies.

Run locally

Set GITV_REPOS (and optionally GITV_KEYS) to point at a local tree. When GITV_REPOS is set, admin commands run without root.

cargo build
export GITV_REPOS=$PWD/dev/repos GITV_KEYS=$PWD/dev/authorized_keys GITV_HOST=localhost
mkdir -p dev/repos
./target/debug/gitv create um9i demo
export GITV_WEB_AUTH=$PWD/dev/web-login
./target/debug/gitv-web setup               # note the password; scan the QR code
./target/debug/gitv-web serve --port 8080   # http://localhost:8080

scripts/fake-ssh stands in for ssh, so you can push and clone through gitv serve without an SSH server. The user part of the URL picks the owner whose key it acts as:

export GIT_SSH_VARIANT=simple GIT_SSH_COMMAND=$PWD/scripts/fake-ssh
git push um9i@local:um9i/myrepo.git main
git clone um9i@local:um9i/myrepo.git

Tests

cargo test

Run them from the workspace root, so both binaries are built: the web tests use gitv to set up their repositories. crates/gitv/tests/ssh.rs runs gitv serve the way a key does over SSH, pushing and cloning real repositories through a stand-in for ssh, and crates/gitv/tests/backup.rs runs the backup and restore scripts. crates/gitv-web/tests/web.rs builds a fixture repository and checks every page of a running gitv-web over HTTP, signed in, including escaping and the requests it must refuse. crates/gitv-web/tests/auth.rs covers signing in, two-factor codes, lockout, sessions and changing the password. None needs an SSH server or network access. The integration tests write only to target/tmp; the unit tests use the system's temporary folder, since Cargo names target/tmp only to integration tests. Helpers both packages use are in testing/host.rs.

.github/workflows/ci.yml runs the same checks on every push and pull request (cargo fmt --check, clippy with warnings as errors, cargo test), plus cargo audit against the RustSec advisory database, also weekly so new advisories surface without a push.

Configuration

Settings that differ between installations live in /etc/gitv/gitv.conf (deploy/gitv.conf is this server's copy; $GITV_CONFIG points elsewhere):

host = git.um9i.dev            # in clone addresses and help; default: $GITV_HOST, then the machine's hostname
command = /usr/local/bin/gitv  # what add-key writes into each key's forced command (this is the default)

It must be readable by the git and gitv-web accounts (mode 0644). Both binaries check it at startup and refuse to run with an unknown setting or a bad value. Over SSH, a key holder is told only that the server is misconfigured, and the details go to the operator log. gitv-web serve prints the host it uses and where that came from.

Production configuration

The deployment files are the source copies for the Fedora host. Caddy uses deploy/Caddyfile at /etc/caddy/Caddyfile. The web service runs with deploy/gitv-web.service at /etc/systemd/system/gitv-web.service, alongside Fedora's distribution-provided systemd defaults. OpenSSH uses deploy/sshd-gitv.conf at /etc/ssh/sshd_config.d/90-gitv.conf. GITV's own settings are deploy/gitv.conf at /etc/gitv/gitv.conf. The trash purge runs from deploy/gitv-purge.service and deploy/gitv-purge.timer in /etc/systemd/system, enabled with systemctl enable --now gitv-purge.timer.

Logs. Caddy sends HSTS (a year, so browsers never fall back to plain HTTP) and writes one JSON line per request to /var/log/caddy/gitv-access.log. The log rotates at 50 MiB and keeps 30 days; Caddy leaves cookie and authorization values out of it. Create the folder for Caddy once with install -d -o caddy -g caddy -m 0750 /var/log/caddy. Before reloading, validate as the caddy user: sudo -u caddy caddy validate --config /etc/caddy/Caddyfile. Validating as root opens the log file too, leaving it owned by root, and the reload then fails with permission denied until that file is removed or handed to caddy.

gitv-web logs every judged sign-in and password change to the journal, with the client's address (or IPv6 /64) and whether the password or the code was wrong:

journalctl -u gitv-web -g 'sign-in|password change'

right password, wrong code means someone knows the password: change it. Attempts refused while a client is locked out aren't logged, so a flood can't fill the journal.

Backups

deploy/gitv-backup snapshots everything the server can't rebuild: the repositories (with their trash, reflogs, push logs and visibility markers), /etc/gitv (the SSH keys), /var/lib/gitv-web (the web sign-in) and the server's SSH host keys (/etc/ssh/ssh_host_*), so a rebuilt server is one clients already trust. Each snapshot is a plain copy in /mnt/gitv-backup/gitv/snapshots/<UTC time>/. Files unchanged since the previous snapshot are hard links to it, so a day's snapshot costs only what changed. Each repository is copied under a lock that pushes also take, so no copy catches a push half way. A repository a push holds for more than 15 minutes keeps its copy from the previous snapshot (noted in the snapshot's MANIFEST), so the rest are still backed up, and the run then fails so you hear about it. Every copy is then checked with git fsck, and only a snapshot that passes becomes latest. Snapshots are kept for 30 days.

The backup holds the authenticator secret, the password hash and the SSH host keys' private halves, so it is private to root (mode 0700).

The volume. Create a DigitalOcean block storage volume in the droplet's region (ext4), attach it, and mount it at /mnt/gitv-backup:

# /etc/fstab (use the volume's own /dev/disk/by-id name)
/dev/disk/by-id/scsi-0DO_Volume_gitv-backup /mnt/gitv-backup ext4 defaults,nofail,discard,noatime 0 2

The script refuses to run unless that directory is a mounted volume, so a missing mount can't fill the droplet's own disk.

A volume survives the droplet being destroyed or its disk failing, and the snapshots cover mistakes for 30 days. It doesn't survive a regional outage or the loss of the DigitalOcean account. Take an occasional DigitalOcean snapshot of the volume, and add an off-site copy when that matters.

Install.

install -m 0755 deploy/gitv-backup deploy/gitv-restore /usr/local/sbin/
cp deploy/gitv-backup.{service,timer} deploy/gitv-restore-check.{service,timer} /etc/systemd/system/
systemctl daemon-reload
systemctl enable --now gitv-backup.timer gitv-restore-check.timer
systemctl start gitv-backup      # a first snapshot now

The backup runs daily at about 02:30. Every Sunday, gitv-restore check copies the latest snapshot out, runs a full git fsck on every repository, and deletes the copy, proving the backups restore. That copy is a full one on the backup volume, so keep free space there for at least one more whole snapshot (du -sh /mnt/gitv-backup/gitv/latest/), or the check can fill the volume and break the next backup. A failure of either shows in systemctl --failed and journalctl -u gitv-backup.

Disaster recovery

A deleted repository. For 30 days it waits in the trash: gitv trash, then gitv restore (see Storage). After that, bring it back from a snapshot:

gitv-restore find um9i/my-project                       # the snapshots holding it, newest last
gitv-restore 2026-11-20T023000Z /srv/gitv-restore um9i/my-project
gitv import um9i my-project /srv/gitv-restore/my-project.git
rm -rf /srv/gitv-restore

gitv-restore copies just that repository out of the snapshot and checks it with git fsck, without touching the live tree. gitv import copies it into place, checks it again, and gives it to the git account. It comes back as it was in the snapshot: branches, tags, default branch, visibility, description, reflogs and push log. Import never replaces anything: if the name has been taken since, it refuses, and you can import under another name instead (gitv import um9i my-project-restored …). Pushes made after that snapshot are lost from the server, but every clone still has them.

One file, or an older state. Snapshots are plain folders, so copy what you need straight out of /mnt/gitv-backup/gitv/snapshots/<time>/repos/<owner>/<name>.git. For history overwritten in the last 30 days, the reflog and push log (see Storage) are quicker.

The whole server. On a fresh Fedora droplet:

  1. Detach the volume from the old droplet (if it still exists), attach it to the new one, and mount it at /mnt/gitv-backup as above.

  2. Install git and Caddy. Create the git account with an ordinary shell such as /bin/bash. sshd runs each key's forced command through it, so git-shell would refuse gitv serve, and keys can't run anything else. Also create the gitv-web system account in the git group. Build and install gitv and gitv-web to /usr/local/bin, and the deployment files as described under Production configuration and Backups.

  3. Restore the latest snapshot to a staging folder. This also verifies every repository:

    gitv-restore list
    gitv-restore latest /srv/gitv-restore
    
  4. Move it into place. rsync run as root keeps owners by name, so the new accounts take over their files:

    mkdir -p /srv/gitv /etc/gitv /var/lib/gitv-web
    rsync -a /srv/gitv-restore/repos/ /srv/gitv/repos/
    rsync -a /srv/gitv-restore/etc-gitv/ /etc/gitv/
    rsync -a /srv/gitv-restore/gitv-web/ /var/lib/gitv-web/
    cp -p /srv/gitv-restore/ssh-host-keys/ssh_host_* /etc/ssh/
    # Copied files carry their folder's default SELinux label, not the one the policy names
    # (sshd reads authorized_keys only as ssh_home_t); restorecon gives each its own.
    restorecon -R /srv/gitv /etc/gitv /var/lib/gitv-web /etc/ssh
    rm -rf /srv/gitv-restore
    
  5. Restart sshd (it now presents the old host keys), start gitv-web and caddy, and enable the timers: systemctl enable --now gitv-purge.timer gitv-backup.timer gitv-restore-check.timer. Point DNS at the new droplet. Check a clone over SSH and over HTTPS, and sign in to the web browser.

Pushes made after the last snapshot are lost from the server, but every clone still has them: pushing again restores them.

Licence

Copyright (C) 2026 Um9i

GITv is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. It is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE for the full terms.

The AGPL extends the GPL to software used over a network: if you run a modified GITv that others reach through the web browser or over SSH, you must offer those users the source of your modified version (section 13).

The binaries also contain other people's software, each under its own permissive licence: the Rust crates GITv depends on, the Oniguruma regular-expression library, the Red Hat Display, Text and Mono fonts (SIL Open Font License), and Sublime Text's syntax definitions. THIRD-PARTY-LICENSES reproduces all of their notices, and those licences require it to accompany any copy of the binaries, so every release archive must include both LICENSE and THIRD-PARTY-LICENSES.

scripts/third-party-licenses regenerates the file with cargo-about (cargo install cargo-about --locked --features cli); its configuration is in licenses/. Run it whenever dependencies change: CI fails while the committed file is out of date.