vole
Site
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software/vole.git
Self-hosted forge that lives in your Git repo.
Serve the front door from vole serve
c5f2c5d49be1d35a0a54fd70029ac9311647194e · Keenan Nemetz · 16d ago · parent e075258f
Serve the front door from vole serve The forced command had nothing to talk to. This gives `vole serve` the local listener, the token it consumes, and the host key a lease now carries. `ssh_listen` decides what serves SSH and is the only switch: "tcp" is the built-in listener on `ssh_addr` (the default, and unchanged), "socket" is the system sshd in front, "none" serves nothing. The socket path stays in `ssh_socket`, which #304 already added, so no value lives in two places. In socket mode `ssh_addr` only names the host and port clone URLs carry, which validation now enforces by refusing another port: the point of the mode is a clone URL with no port, and a leftover 2222 would silently break every link. The local listener speaks the framed protocol from `internal/sshwire` and turns it back into the Session the built-in listener produces, so `handleLocal` calls the same `exec` with the account and key from the token row and the same ACL, credential-scoping, and refusal code runs. A test proves it: every kind of handler — whoami, roster, both git pack services, the admin API, the run queue, release channels, a refused verb, and a job credential that may do less than its account — is driven over both transports and compared byte for byte, status included. A front-door instance has no signer, so `New` no longer creates a private host key it would never present: it reads sshd's public key from `ssh_public_host_key_file` into the same field a lease carries. A missing or unreadable file fails startup rather than handing a job a key that cannot verify its host, and `Serve` refuses outright when there is no host key. The transport's own details: a write larger than a frame is split rather than refused, stdout and stderr share one socket under one lock, expired tokens are swept every thirty seconds and once at startup so a mode switch leaves nothing behind, and the socket is created 0660 with a stale file replaced only after checking that nothing answers on it. `ssh_user` replaces the hardcoded `git` in generated clone URLs, which is what lets a host with another forge's `git` account keep both. Packaging and the sshd drop-in are #306; the documentation and migration are #307.
server/ssh/hostkey_test.go +90
| @@ -0,0 +1,90 @@ | |||
| 1 | package ssh | ||
| 2 | |||
| 3 | // A front-door instance has no SSH listener, so it has no host key of its own. | ||
| 4 | // What a job still needs is the key it will see when it connects: sshd's. These | ||
| 5 | // tests cover reading it, refusing to start without it, and refusing to accept | ||
| 6 | // connections when there is nothing to present. | ||
| 7 | |||
| 8 | import ( | ||
| 9 | "net" | ||
| 10 | "os" | ||
| 11 | "path/filepath" | ||
| 12 | "strings" | ||
| 13 | "testing" | ||
| 14 | |||
| 15 | xssh "golang.org/x/crypto/ssh" | ||
| 16 | ) | ||
| 17 | |||
| 18 | // canonicalKey is an authorized_keys line without its comment, which is the form | ||
| 19 | // both host-key paths produce. | ||
| 20 | func canonicalKey(t *testing.T, line string) string { | ||
| 21 | t.Helper() | ||
| 22 | k, _, _, _, err := xssh.ParseAuthorizedKey([]byte(line)) | ||
| 23 | if err != nil { | ||
| 24 | t.Fatalf("parse key: %v", err) | ||
| 25 | } | ||
| 26 | return strings.TrimSpace(string(xssh.MarshalAuthorizedKey(k))) | ||
| 27 | } | ||
| 28 | |||
| 29 | func TestFrontDoorCarriesSshdsHostKeyInALease(t *testing.T) { | ||
| 30 | t.Parallel() | ||
| 31 | dir := t.TempDir() | ||
| 32 | _, pubLine := keypair(t, filepath.Join(dir, "sshd")) | ||
| 33 | pubPath := filepath.Join(dir, "sshd.pub") | ||
| 34 | privatePath := filepath.Join(dir, "data_host_key") | ||
| 35 | |||
| 36 | srv, err := New(Config{ | ||
| 37 | Log: discardLogger(), | ||
| 38 | PublicHostKeyPath: pubPath, | ||
| 39 | HostKeyPath: privatePath, | ||
| 40 | }) | ||
| 41 | if err != nil { | ||
| 42 | t.Fatalf("new: %v", err) | ||
| 43 | } | ||
| 44 | t.Cleanup(func() { srv.Close() }) | ||
| 45 | |||
| 46 | // The comment is not part of the key, and the built-in path's line has none | ||
| 47 | // either; what has to match is the key itself. | ||
| 48 | if got, want := srv.hostKey, canonicalKey(t, pubLine); got != want { | ||
| 49 | t.Errorf("lease host key is %q, want sshd's %q", got, want) | ||
| 50 | } | ||
| 51 | // Creating a private key nobody presents would be a secret with no purpose. | ||
| 52 | if _, err := os.Stat(privatePath); !os.IsNotExist(err) { | ||
| 53 | t.Errorf("a private host key was created at %s", privatePath) | ||
| 54 | } | ||
| 55 | |||
| 56 | // There is no signer, so there is no SSH listener this server can accept on. | ||
| 57 | ln, err := net.Listen("tcp", "127.0.0.1:0") | ||
| 58 | if err != nil { | ||
| 59 | t.Fatal(err) | ||
| 60 | } | ||
| 61 | defer ln.Close() | ||
| 62 | if err := srv.Serve(ln); err == nil { | ||
| 63 | t.Fatal("a front-door server accepted SSH connections") | ||
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 67 | func TestFrontDoorRefusesToStartWithoutTheHostKey(t *testing.T) { | ||
| 68 | t.Parallel() | ||
| 69 | _, err := New(Config{ | ||
| 70 | Log: discardLogger(), | ||
| 71 | PublicHostKeyPath: filepath.Join(t.TempDir(), "missing.pub"), | ||
| 72 | }) | ||
| 73 | if err == nil { | ||
| 74 | t.Fatal("a front-door server started with no sshd host key") | ||
| 75 | } | ||
| 76 | if !strings.Contains(err.Error(), "missing.pub") { | ||
| 77 | t.Errorf("the error does not name the file: %v", err) | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 | func TestFrontDoorRefusesAFileThatIsNotAKey(t *testing.T) { | ||
| 82 | t.Parallel() | ||
| 83 | path := filepath.Join(t.TempDir(), "sshd.pub") | ||
| 84 | if err := os.WriteFile(path, []byte("not a key\n"), 0o644); err != nil { | ||
| 85 | t.Fatal(err) | ||
| 86 | } | ||
| 87 | if _, err := New(Config{Log: discardLogger(), PublicHostKeyPath: path}); err == nil { | ||
| 88 | t.Fatal("a file that is not a key was accepted as the host key") | ||
| 89 | } | ||
| 90 | } | ||