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/server.go +28−2

@@ -553,10 +553,12 @@ func (s *Server) exec(ch Session, command, user, fp, remote string) {
553 553 // A refusal is still answered on the channel rather than at the request
554 554 // layer: replying false makes the client print "exec request failed on
555 555 // channel 0" and the reason is lost. Nothing is ever executed on these
556 // paths — the message is the whole response.
556 // paths — the message is the whole response, and which stream it belongs on
557 // is the verb's answer, not this closure's.
558 refusal := refusalStream(ch, command)
557 559 refuse := func(format string, args ...any) {
558 560 ch.Accept()
559 fmt.Fprintf(ch, "vole: "+format+"\n", args...)
561 fmt.Fprintf(refusal, "vole: "+format+"\n", args...)
560 562 ch.Exit(1)
561 563 }
562 564
@@ -836,6 +838,30 @@ func (s *Server) exec(ch Session, command, user, fp, remote string) {
836 838 ch.Exit(code)
837 839 }
838 840
841 // refusalStream is where a refusal for command belongs.
842 //
843 // Vole's own verbs are read by its CLI from the channel body, so a refusal
844 // there is an answer. git-upload-pack and git-receive-pack are reading a
845 // pkt-line stream from the channel body, where a sentence is not a frame: git
846 // drops it as "protocol error: bad line length character" and the operator
847 // learns nothing. Their refusals go to stderr, the SSH extended-data stream,
848 // which the client shows on its terminal instead of parsing it as protocol.
849 //
850 // The verb is decided from the raw first word because the two refusals that
851 // happen before exec parses the command — an oversized or malformed line —
852 // cannot know it from argv. A git client always sends git-upload-pack or
853 // git-receive-pack as that word.
854 func refusalStream(ch Session, command string) io.Writer {
855 word := strings.TrimLeft(command, " \t")
856 if i := strings.IndexAny(word, " \t"); i >= 0 {
857 word = word[:i]
858 }
859 if word == "git-upload-pack" || word == "git-receive-pack" {
860 return ch.Stderr()
861 }
862 return ch
863 }
864
839 865 // repoName turns a git SSH path argument into a repo name. git sends either
840 866 // "/demo.git" (ssh:// URL) or "demo.git" (scp-like), and never anything we
841 867 // should trust as a path — so the result is a validated name, not a path.