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/session_test.go +62

@@ -126,6 +126,68 @@ func TestRefusalRunsOnALocalSession(t *testing.T) {
126 126 }
127 127 }
128 128
129 // TestGitRefusalGoesToStderr covers the stream a refusal belongs on. git reads
130 // the channel body as a pkt-line stream, so a sentence written there is the
131 // first four bytes of a frame and git drops it as "protocol error: bad line
132 // length character". Both git verbs answer on stderr instead, which the client
133 // shows on its terminal rather than parsing it as protocol.
134 func TestGitRefusalGoesToStderr(t *testing.T) {
135 t.Parallel()
136 h := newHarness(t)
137 for _, tc := range []struct {
138 name string
139 command string
140 want string
141 }{
142 {"upload missing", "git-upload-pack 'nope.git'", `repository "nope" not found`},
143 {"receive missing", "git-receive-pack 'nope.git'", `repository "nope" not found`},
144 {"upload invalid path", "git-upload-pack '/../../etc.git'", "invalid repository path"},
145 {"receive malformed", "git-receive-pack '/unterminated", "malformed command"},
146 {"upload oversized", "git-upload-pack '" + strings.Repeat("x", maxCommandBytes) + "'", "command line is longer"},
147 } {
148 t.Run(tc.name, func(t *testing.T) {
149 local := &memorySession{}
150 h.srv.exec(local, tc.command, "writer", "", "127.0.0.1:1")
151
152 if !local.accepted || !local.exited {
153 t.Fatalf("accepted=%v exited=%v; a refusal is still answered on the session", local.accepted, local.exited)
154 }
155 if local.code == 0 {
156 t.Errorf("exit %d, want nonzero", local.code)
157 }
158 if local.stdout.Len() != 0 {
159 t.Errorf("the refusal reached stdout, where git reads a pkt-line stream: %q", local.stdout.String())
160 }
161 if !strings.Contains(local.stderr.String(), tc.want) {
162 t.Errorf("stderr = %q, want it to contain %q", local.stderr.String(), tc.want)
163 }
164 })
165 }
166 }
167
168 // TestVoleVerbRefusalStaysOnTheChannelBody is the other half: the CLI reads its
169 // verbs' answers from the channel body, so routing every refusal to stderr would
170 // break them instead.
171 func TestVoleVerbRefusalStaysOnTheChannelBody(t *testing.T) {
172 t.Parallel()
173 h := newHarness(t)
174 local := &memorySession{}
175 h.srv.exec(local, "vole-whoami '/../../etc.git'", "writer", "", "127.0.0.1:1")
176
177 if !local.accepted || !local.exited {
178 t.Fatalf("accepted=%v exited=%v; a refusal is still answered on the session", local.accepted, local.exited)
179 }
180 if local.code != 1 {
181 t.Errorf("exit %d, want 1", local.code)
182 }
183 if local.stderr.Len() != 0 {
184 t.Errorf("a Vole verb's refusal reached stderr, where its CLI does not read: %q", local.stderr.String())
185 }
186 if !strings.Contains(local.stdout.String(), "invalid repository path") {
187 t.Errorf("the refusal does not say why: %q", local.stdout.String())
188 }
189 }
190
129 191 // TestSessionWithoutRequestAccepts covers the session the connection layer
130 192 // builds only to report that it refused a shell: there is no exec request to
131 193 // answer, and that is not an error.