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.

Run the exec verbs on a session, not an SSH channel

5ff8dfc964d8e05c5f5b7a8ec5e5f229178e5e4c · Keenan Nemetz · 16d ago · parent 22e290b0

Run the exec verbs on a session, not an SSH channel

Every handler behind the exec verb took an *xssh.Channel, and the two that
answer the exec request took the request too. That tied twenty functions to the
SSH transport, but the front door needs the same verbs, with the same access
rules, from a forced command that reaches the service over a local socket.

A Session is now what a verb runs on: stdin, stdout, a separate error stream,
Accept, CloseWrite, Exit, and Close. sshSession is the only implementation that
knows what an SSH channel is, so the handlers no longer name a transport and a
second one cannot become a second copy of the access rules.

No behaviour change. The handlers keep their names and bodies; the refusal and
exit-status paths move behind the interface, which is also what removes the
standalone exit helper. A new test drives vole-whoami and git-upload-pack over
SSH and over a session with no channel behind it, comparing stdout, stderr, and
the exit status of both.

server/ssh/admin.go +3−5

@@ -13,8 +13,6 @@ import (
13 13 "strings"
14 14 "time"
15 15
16 xssh "golang.org/x/crypto/ssh"
17
18 16 "rodent.software/vole/forge/access"
19 17 "rodent.software/vole/forge/identity"
20 18 "rodent.software/vole/forge/repo"
@@ -41,7 +39,7 @@ func (e *adminUsageError) Error() string { return e.msg }
41 39 type adminRender func(stdout, stderr io.Writer)
42 40
43 41 // serveAdmin runs one `vole-admin` command and returns the process exit code.
44 func (s *Server) serveAdmin(ch xssh.Channel, argv []string, user, remote string) int {
42 func (s *Server) serveAdmin(ch Session, argv []string, user, remote string) int {
45 43 jsonOut, args, err := splitAdminJSON(argv)
46 44 if err != nil {
47 45 return s.adminError(ch, jsonOut, "usage", err, user, remote)
@@ -80,7 +78,7 @@ func (s *Server) serveAdmin(ch xssh.Channel, argv []string, user, remote string)
80 78
81 79 // adminUnavailable answers a command that was not run because it could not be
82 80 // recorded. It does not try to record the refusal: that is the thing that failed.
83 func (s *Server) adminUnavailable(ch xssh.Channel, jsonOut bool, err error) int {
81 func (s *Server) adminUnavailable(ch Session, jsonOut bool, err error) int {
84 82 if jsonOut {
85 83 _ = json.NewEncoder(ch).Encode(adminResponse{OK: false, Error: &adminError{
86 84 Code: "audit_unavailable", Message: "the audit log could not be written: " + err.Error()}})
@@ -91,7 +89,7 @@ func (s *Server) adminUnavailable(ch xssh.Channel, jsonOut bool, err error) int
91 89 return 1
92 90 }
93 91
94 func (s *Server) adminError(ch xssh.Channel, jsonOut bool, code string, err error, user, remote string) int {
92 func (s *Server) adminError(ch Session, jsonOut bool, code string, err error, user, remote string) int {
95 93 exitCode := 1
96 94 if _, ok := err.(*adminUsageError); ok {
97 95 exitCode = 129