Sign in

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

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.

forge/sshsession/sshsession.go +11−5

@@ -47,6 +47,11 @@ type Token struct {
47 47 // Credential is the fingerprint of the run credential the key was, when the
48 48 // key was one. Empty means the key is the account's own.
49 49 Credential string
50 // Key is the fingerprint sshd authenticated. It travels with the session so
51 // the service reports the same identity detail the built-in listener reports:
52 // the hook environment, the audit detail, and the run-credential lookup all
53 // key off it.
54 Key string
50 55 // Repo and RunID scope a credential session to the job it was minted for.
51 56 Repo string
52 57 RunID string
@@ -79,6 +84,7 @@ CREATE TABLE IF NOT EXISTS ssh_sessions (
79 84 token_hash TEXT PRIMARY KEY,
80 85 account TEXT NOT NULL,
81 86 credential TEXT NOT NULL DEFAULT '',
87 key_fp TEXT NOT NULL DEFAULT '',
82 88 repo TEXT NOT NULL DEFAULT '',
83 89 run_id TEXT NOT NULL DEFAULT '',
84 90 client TEXT NOT NULL,
@@ -124,9 +130,9 @@ func (s *Store) Mint(t Token, now time.Time) (string, error) {
124 130 return "", fmt.Errorf("sshsession: drop expired tokens: %w", err)
125 131 }
126 132 if _, err := tx.Exec(`INSERT INTO ssh_sessions
127 (token_hash, account, credential, repo, run_id, client, expires)
128 VALUES (?,?,?,?,?,?,?)`,
129 hash(token), t.Account, t.Credential, t.Repo, t.RunID, client, expires.Unix()); err != nil {
133 (token_hash, account, credential, key_fp, repo, run_id, client, expires)
134 VALUES (?,?,?,?,?,?,?,?)`,
135 hash(token), t.Account, t.Credential, t.Key, t.Repo, t.RunID, client, expires.Unix()); err != nil {
130 136 return "", fmt.Errorf("sshsession: store token: %w", err)
131 137 }
132 138 if err := tx.Commit(); err != nil {
@@ -162,9 +168,9 @@ func (s *Store) Consume(token, client string, now time.Time) (*Token, error) {
162 168 var t Token
163 169 var gotClient string
164 170 var expires int64
165 err = tx.QueryRow(`SELECT account, credential, repo, run_id, client, expires
171 err = tx.QueryRow(`SELECT account, credential, key_fp, repo, run_id, client, expires
166 172 FROM ssh_sessions WHERE token_hash = ?`, hash(token)).
167 Scan(&t.Account, &t.Credential, &t.Repo, &t.RunID, &gotClient, &expires)
173 Scan(&t.Account, &t.Credential, &t.Key, &t.Repo, &t.RunID, &gotClient, &expires)
168 174 if errors.Is(err, sql.ErrNoRows) {
169 175 return nil, nil
170 176 }