Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Clone

Read only, no credentials:

https://rodent.software/git/vole.git

Write over SSH with a registered key:

git clone ssh://git@0.0.0.0: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 · 12d 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).

server/ssh/sshserver_test.go +12−3

@@ -62,7 +62,12 @@ type harness struct {
62 62 writerID string // the account id the writer's key belongs to
63 63 }
64 64
65 func newHarness(t *testing.T) *harness {
65 func newHarness(t *testing.T) *harness { return newHarnessWith(t, nil) }
66
67 // newHarnessWith lets a test set the server's resource bounds before it starts,
68 // which is how the handshake, connection and process caps get exercised at a
69 // size a test can reach.
70 func newHarnessWith(t *testing.T, tweak func(*Config)) *harness {
66 71 t.Helper()
67 72 dir := t.TempDir()
68 73 usersDB := filepath.Join(dir, "users.db")
@@ -125,14 +130,18 @@ func newHarness(t *testing.T) *harness {
125 130 objects := lfs.New(filepath.Join(dir, "objects"), 1<<20)
126 131
127 132 log := slog.New(slog.NewTextHandler(io.Discard, nil))
128 srv, err := New(Config{
133 cfg := Config{
129 134 Identity: ident,
130 135 Repos: rs,
131 136 Runs: queue,
132 137 LFS: objects,
133 138 Log: log,
134 139 HostKeyPath: filepath.Join(dir, "host_key"),
135 })
140 }
141 if tweak != nil {
142 tweak(&cfg)
143 }
144 srv, err := New(cfg)
136 145 if err != nil {
137 146 t.Fatal(err)
138 147 }