vole
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software:2222/vole.git
A free and open-source forge that lives in your Git repo.
Bound what an unauthenticated SSH client can spend
78cd3437a597b0155682d2e8d5129bf7cdeac85d · Keenan Nemetz · 13d ago · parent b1499c72
Bound what an unauthenticated SSH client can spend
The SSH listener accepted every connection, gave each one a goroutine, and
started a process per session channel. A client that opened a socket and
never finished the handshake held all three for as long as it liked, and a
client that opened channels held a goroutine each. The host key was
hardened by `vole serve` on the way in, but the SSH package on its own
would happily load a key the whole machine could read.
Four bounds, all enforced before the expensive thing happens:
- A handshake deadline, cleared once the handshake completes so a clone
or a push is not cut. `ssh_handshake_timeout_seconds`, default 20.
- `ssh_max_connections` (default 64) tokens, one per open connection. Past
the cap the connection is closed before the handshake, the goroutine or
the process, and the accept loop keeps running so the listener cannot be
wedged. The "listener is full" warning is throttled to once per 10s so a
flood cannot become a disk problem instead.
- Eight session channels per connection, rejected at the channel layer
rather than by spawning a goroutine per request.
- `ssh_max_git_processes` (default 16) across every connection, covering
upload-pack, receive-pack and vole-change-merge. A command waits up to
30s for a slot and is then told to retry, rather than parked forever.
Payloads are bounded too: an exec line over 4 KiB is refused before it is
parsed, and a vole-runner request line over 1 MiB ends the session with an
error. The runner bound is a per-line reader, so json.Decoder's buffering
cannot hide an oversized request and a long-lived runner is not limited in
total.
Loading an existing host key now tightens it to 0600 and warns, and a mode
that cannot be tightened fails startup, so the package is safe on its own
rather than only behind `vole serve`.
Tests hold a connection without handshaking (it is dropped and its slot
returns), flood one connection with channels (the ninth is rejected and
closing one releases a slot), send an oversized exec line and an oversized
runner request (both refused), saturate the process pool (a bounded wait,
then a refusal), and load a 0644 host key (tightened).
forge/config/config.go +21−5
| @@ -31,6 +31,19 @@ type Config struct { | |||
| 31 | 31 | ACMEDirectoryURL string `toml:"acme_directory_url"` | |
| 32 | 32 | // SSHAddr is the only write githttp. | |
| 33 | 33 | SSHAddr string `toml:"ssh_addr"` | |
| 34 | // SSHMaxConnections bounds simultaneous connections on the SSH listener. Past | ||
| 35 | // it a connection is closed before the handshake rather than queued, because a | ||
| 36 | // queue is the unbounded thing the cap exists to avoid. Zero means 64: enough | ||
| 37 | // for a team, small enough that a flood cannot take every file descriptor. | ||
| 38 | SSHMaxConnections int `toml:"ssh_max_connections"` | ||
| 39 | // SSHMaxGitProcesses bounds git processes across every SSH connection, so a | ||
| 40 | // burst of sessions cannot turn into a burst of processes. Zero means 16, the | ||
| 41 | // same order as git_http_max_concurrent. | ||
| 42 | SSHMaxGitProcesses int `toml:"ssh_max_git_processes"` | ||
| 43 | // SSHHandshakeTimeoutSeconds bounds how long a connection may take to finish the | ||
| 44 | // SSH handshake, so a client that opens a socket and says nothing cannot hold a | ||
| 45 | // connection slot indefinitely. Zero means 20. | ||
| 46 | SSHHandshakeTimeoutSeconds int `toml:"ssh_handshake_timeout_seconds"` | ||
| 34 | 47 | // MaxBlobBytes rejects individual objects in pre-receive. | |
| 35 | 48 | MaxBlobBytes int64 `toml:"max_blob_bytes"` | |
| 36 | 49 | // GitHTTP enables the anonymous smart-HTTP read transport: clone, fetch and | |
| @@ -125,11 +138,14 @@ type Config struct { | |||
| 125 | 138 | ||
| 126 | 139 | func defaults() *Config { | |
| 127 | 140 | return &Config{ | |
| 128 | DataDir: "./data", | ||
| 129 | HTTPAddr: "127.0.0.1:8080", | ||
| 130 | SSHAddr: "127.0.0.1:2222", | ||
| 131 | MaxBlobBytes: 100 << 20, // 100 MiB per blob | ||
| 132 | ReceiveMaxBytes: 1 << 30, // 1 GiB per push | ||
| 141 | DataDir: "./data", | ||
| 142 | HTTPAddr: "127.0.0.1:8080", | ||
| 143 | SSHAddr: "127.0.0.1:2222", | ||
| 144 | SSHMaxConnections: 64, | ||
| 145 | SSHMaxGitProcesses: 16, | ||
| 146 | SSHHandshakeTimeoutSeconds: 20, | ||
| 147 | MaxBlobBytes: 100 << 20, // 100 MiB per blob | ||
| 148 | ReceiveMaxBytes: 1 << 30, // 1 GiB per push | ||
| 133 | 149 | ||
| 134 | 150 | GitHTTP: true, | |
| 135 | 151 | GitHTTPMaxConcurrent: 16, | |