~gitpocket/gitpocket

4
b90d94929f3867d85bce0b21f4172d1daedc0276
mainfeed-discovery
gitpocket/README.md -rw-r--r--9.2 KiB ViewLogBlameView rawPermalink 7878eb0781 feat(web): range-diff, pickaxe search and atom feeds 1 months ago

View source

basin

Small and lightweight git server for self hosting. Repositories are served over SSH and HTTPS, trees and logs and diffs and READMEs are rendered on the server rather than in the browser, and pull requests are handled without a working tree ever being checked out. The only JavaScript on the reading side is KaTeX, which is served only when a page contains mathematics.

Features

Design

Every read of git data is a call out to the plumbing with a thirty second timeout, which in practice means ls-tree -l for trees and log with a NUL separated format for history and diff-tree -p --root -M for commit pages and cat-file for blobs. Nothing is cached anywhere and nothing is parsed out of packfiles in process, so a large repository costs exactly what git says it costs and the server itself holds no state between one request and the next.

When a pull request is opened or updated the source branch gets fetched into refs/pull/N/head of the target repository, and from that point on the diff and the commit list and the question of whether it merges cleanly all come from merge-base and diff and merge-tree --write-tree inside that single repo. The merge itself is commit-tree with both parents followed by update-ref carrying the old value it expects to find, so if someone pushes to the branch while you are clicking the button the merge simply fails rather than silently overwriting them. Conflicts are reported back to you and left for you to sort out locally.

SQLite comes from the modernc port, which is pure Go, so a CGO_ENABLED=0 build produces one static binary that will run anywhere there happens to be a system git next to it.

Install

CGO_ENABLED=0 go build -trimpath -ldflags='-s -w' -o basin .
useradd -r -m -d /srv/basin -s /bin/sh git
install -m 755 basin /usr/local/bin/basin
[Service]
User=git
ExecStart=/usr/local/bin/basin -root /srv/basin serve -listen 127.0.0.1:3200 -host git.example.org
Restart=always
ProtectSystem=strict
ReadWritePaths=/srv/basin

Put a reverse proxy with TLS in front of it. The proxy needs to forward Host and X-Forwarded-Proto, and it should set X-Forwarded-For to the client address rather than appending to it because the rate limiter keys on the first value it finds there. Turn request buffering off and raise the body limit as well, otherwise larger pushes over HTTPS will be cut short.

Match User git
    AuthenticationMethods publickey
    AuthorizedKeysFile none
    AuthorizedKeysCommand /usr/local/bin/basin -root /srv/basin keys %u %h %t %k
    AuthorizedKeysCommandUser root
    PermitTTY no
    DisableForwarding yes

The keys command runs as root and opens the database read only and answers sshd with a forced command of basin shell <user>. That in turn runs as the login user, checks what SSH_ORIGINAL_COMMAND is actually asking for against the database, and then execs straight into git upload-pack or git receive-pack so nothing is left running afterwards.

sudo -u git basin -root /srv/basin invite

If you would rather let anyone sign up then serve -open skips the invite step entirely. basin user <name> creates an account from the command line with the password read from stdin, and -ssh-user changes the account name that appears in clone URLs if you did not call yours git.

Mail is configured in smtp.json under the root directory and is read once at startup. Plain SMTP takes host, port, user, password, from and starttls, but many VPS providers block every outbound submission port, so api and key post each message as JSON to a Resend compatible HTTPS endpoint instead.

{"api": "https://api.resend.com/emails", "key": "re_...", "from": "basin <noreply@git.example.org>"}
sudo -u git basin -root /srv/basin mail you@example.org

basin feature ~you/a ~you/b chooses the projects on the logged out front page in that order, -~you/a drops one again, and with none chosen the page falls back to the most recently pushed. basin backup file writes a consistent copy of the database with vacuum into, which is safe to run from a timer while the server is live.

Use

git clone https://git.example.org/~you/repo
git clone git@git.example.org:~you/repo

The .git suffix works but is not required. Pushing over SSH needs a key added under settings, while pushing over HTTPS takes a token or your password as the basic auth secret.

To send changes to something you do not own, fork it from the button beside the title and push a branch to your fork, then open a pull request from the pull requests tab and choose that branch as the source. The owner merges it from the sidebar when they are happy with it.

Limits

Raw files stream straight out of cat-file at any size, but the rendered view stops at 4 MiB and syntax highlighting at 512 KiB, beyond which a file is shown plain or offered as raw only. The quota is checked before a push starts rather than during it, so a single push can overshoot by its own size. There is no wiki and no CI, and there are no plans for either.

Licence

MIT. KaTeX is MIT as well and Source Sans 3 is under the OFL, with both notices kept beside the files.