1

I am creating a proxy server to tunnel clients git requests to whatever VCS we are using in the backend (reason being we need to perform authentication and authorisation stuff). The proxy is built using Golang. I am facing a weird issue wherein I am not able to fetch git metadata from request payload. Not sure if git sends just the tarball'd code or it sends the metadata as well (git operation, branch/tag name, etc.), I am unable to extract any of them.

Below is what the core part of my code looks like

        downstreamConnection, err := connection.ConnectDownstream(request)

        if err != nil {
            fmt.Println(err)
            panic(1)
        }
        chans := downstreamConnection.IncomingRequestChannel
        for newChannel := range chans {
            fmt.Println("channel type : " + newChannel.ChannelType())
            channel, requests, err := newChannel.Accept()
            if err != nil {
                fmt.Println(err)
                panic(1)
            }
            go func(in <-chan *ssh.Request) {
                for req := range in {
                    if req.Type == "exec" {
                        err := req.Reply(req.Type == "exec", nil)
                        fmt.Println(err)
                    }
                    fmt.Println(string(req.Payload))
                }
            }(requests)
        }
func (c Connection) ConnectDownstream(downstreamRequest DownstreamRequest) (*DownstreamConnection, error) {
    serverConfig := &ssh.ServerConfig{
        PublicKeyCallback: downstreamRequest.PublicKeyAuthFunction,
    }
    key, err := getHostKey()

    if err != nil {
        return nil, err
    }

    serverConfig.AddHostKey(key)
    authenticatedConnection, incomingRequestChannel, request, err := newSSHServerConn(downstreamRequest.Conn, serverConfig)

    if err != nil {
        return nil, err
    }

    return &DownstreamConnection{
        Request:                 request,
        IncomingRequestChannel:  incomingRequestChannel,
        AuthenticatedConnection: authenticatedConnection,
    }, nil
}

Output

local addr: [::1]:2222
channel type : session
LC_TERMINAL_VERSION3.4.19                                                                                                                                                                                              LC_CTYPEUTF-8

LC_TERMINALiTerm2
<nil>
git-receive-pack '/abcd'

Printing the payload just gives me the url path with the command (git-receive-pack '/abcd').

I have one option to dump the git blob by reading from channel, but that's sloppy way of solving my issue, unless my use-case is to implement a git server.

It would be great if someone helps me with a much elegant solution to extract below data:

  1. git operation (push, pull)
  2. branch/tag information

Thanks in advance.

Praveen Kamath
  • 959
  • 2
  • 10
  • 18

0 Answers0