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.

Send a refused git command's reason to the error stream

5bc57be7092ffc4b15a3694010f25ea7924a5044 · Keenan Nemetz · 1d ago · parent 31560d91

Send a refused git command's reason to the error stream

A git client reads the channel body as a pkt-line stream, so the refusal
sentence in front of it was the first four bytes of a frame. git reported
"protocol error: bad line length character" and dropped the reason, leaving
a missing repository, a private one and a busy server indistinguishable.

Choose the refusal stream by verb: git-upload-pack and git-receive-pack
answer on stderr, which the client shows as the remote's message; Vole's own
verbs keep the channel body their CLI parses. The raw first word decides for
the oversized and malformed refusals that happen before argv exists, and the
git path's later refusals share the same closure.

Tests cover both verbs on a local Session and through a real git clone and
push, plus a Vole verb whose answer must stay on the channel body.

server/ssh/sshserver_test.go +36

@@ -499,6 +499,42 @@ func TestUnknownKeyRejected(t *testing.T) {
499 499 }
500 500 }
501 501
502 // TestGitClientShowsTheRefusal covers what the operator sees. A sentence on the
503 // channel body is the first four bytes of git's pkt-line stream, so git reports
504 // "protocol error: bad line length character" and drops the reason; the same
505 // sentence on stderr reaches the client's terminal as the reason git failed.
506 // git inherits the SSH process's stderr rather than relaying it as sideband
507 // data, so it prints the sentence verbatim instead of prefixing `remote: `.
508 func TestGitClientShowsTheRefusal(t *testing.T) {
509 t.Parallel()
510 h := newHarness(t)
511 missing := "ssh://git@" + h.addr + "/nope.git"
512 want := `vole: repository "nope" not found`
513
514 if _, errs, err := h.git("", h.keyPath, "clone", "-q", missing, filepath.Join(t.TempDir(), "clone")); err == nil {
515 t.Fatalf("cloning a missing repository succeeded: %s", errs)
516 } else {
517 if !strings.Contains(errs, want) {
518 t.Errorf("clone stderr = %q, want it to contain %q", errs, want)
519 }
520 if strings.Contains(errs, "protocol error") {
521 t.Errorf("clone stderr = %q, which is the broken answer, not the reason", errs)
522 }
523 }
524
525 work := workRepo(t)
526 if _, errs, err := h.git(work, h.keyPath, "push", missing, "main:refs/heads/main"); err == nil {
527 t.Fatalf("pushing to a missing repository succeeded: %s", errs)
528 } else {
529 if !strings.Contains(errs, want) {
530 t.Errorf("push stderr = %q, want it to contain %q", errs, want)
531 }
532 if strings.Contains(errs, "protocol error") {
533 t.Errorf("push stderr = %q, which is the broken answer, not the reason", errs)
534 }
535 }
536 }
537
502 538 func TestRepoOutsideTheStoreIsRefused(t *testing.T) {
503 539 t.Parallel()
504 540 h := newHarness(t)