Commit 799417a3 authored by Kim "BKC" Carlbäcker's avatar Kim "BKC" Carlbäcker

- Update gitaly vendoring

- Wire up gitaly-*-pack to Gitaly. Don't pass git-*-pack to go
- Disable tests for go1.5 & 1.6
parent 4539a066
......@@ -63,14 +63,6 @@ go:1.7:
<<: *go_definition
image: golang:1.7
go:1.6:
<<: *go_definition
image: golang:1.6
go:1.5:
<<: *go_definition
image: golang:1.5
codeclimate:
before_script: []
image: docker:latest
......
......@@ -29,7 +29,9 @@ func main() {
logger.Fatal("unmarshaling request json failed", err)
}
if err := handler.ReceivePack(os.Args[1], &request); err != nil {
code, err := handler.ReceivePack(os.Args[1], &request)
if err != nil {
logger.Fatal("receive-pack failed", err)
}
os.Exit(int(code))
}
......@@ -29,7 +29,9 @@ func main() {
logger.Fatal("unmarshaling request json failed", err)
}
if err := handler.UploadPack(os.Args[1], &request); err != nil {
code, err := handler.UploadPack(os.Args[1], &request)
if err != nil {
logger.Fatal("upload-pack failed", err)
}
os.Exit(int(code))
}
package handler
import (
"context"
"fmt"
"os"
pb "gitlab.com/gitlab-org/gitaly-proto/go"
"gitlab.com/gitlab-org/gitaly/client"
)
func ReceivePack(gitalyAddress string, request *pb.SSHReceivePackRequest) error {
repoPath := request.Repository.Path
if repoPath == "" {
return fmt.Errorf("empty path in repository message")
func ReceivePack(gitalyAddress string, request *pb.SSHReceivePackRequest) (int32, error) {
if gitalyAddress == "" {
return -1, fmt.Errorf("no gitaly_address given")
}
return execCommand("git-receive-pack", repoPath)
conn, err := client.Dial(gitalyAddress, client.DefaultDialOpts)
if err != nil {
return -1, err
}
defer conn.Close()
ctx, cancel := context.WithCancel(context.TODO())
defer cancel()
return client.ReceivePack(ctx, conn, os.Stdin, os.Stdout, os.Stderr, request)
}
package handler
import (
"context"
"fmt"
"os"
pb "gitlab.com/gitlab-org/gitaly-proto/go"
"gitlab.com/gitlab-org/gitaly/client"
)
func UploadPack(gitalyAddress string, request *pb.SSHUploadPackRequest) error {
repoPath := request.Repository.Path
if repoPath == "" {
return fmt.Errorf("empty path in repository message")
func UploadPack(gitalyAddress string, request *pb.SSHUploadPackRequest) (int32, error) {
if gitalyAddress == "" {
return -1, fmt.Errorf("no gitaly_address given")
}
return execCommand("git-upload-pack", repoPath)
conn, err := client.Dial(gitalyAddress, client.DefaultDialOpts)
if err != nil {
return -1, err
}
defer conn.Close()
ctx, cancel := context.WithCancel(context.TODO())
defer cancel()
return client.UploadPack(ctx, conn, os.Stdin, os.Stdout, os.Stderr, request)
}
package helper
import (
"io"
)
// NewReceiveReader turns receiver into an io.Reader. Errors from the
// receiver function are passed on unmodified. This means receiver should
// emit io.EOF when done.
func NewReceiveReader(receiver func() ([]byte, error)) io.Reader {
return &receiveReader{receiver: receiver}
}
type receiveReader struct {
receiver func() ([]byte, error)
data []byte
err error
}
func (rr *receiveReader) Read(p []byte) (int, error) {
if len(rr.data) == 0 {
rr.data, rr.err = rr.receiver()
}
n := copy(p, rr.data)
rr.data = rr.data[n:]
if len(rr.data) == 0 {
return n, rr.err
}
return n, nil
}
// NewSendWriter turns sender into an io.Writer. The number of 'bytes
// written' reported back is always len(p).
func NewSendWriter(sender func(p []byte) error) io.Writer {
return &sendWriter{sender: sender}
}
type sendWriter struct {
sender func([]byte) error
}
func (sw *sendWriter) Write(p []byte) (int, error) {
return len(p), sw.sender(p)
}
// Code generated by protoc-gen-go.
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: notifications.proto
// DO NOT EDIT!
package gitaly
......
// Code generated by protoc-gen-go.
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: ref.proto
// DO NOT EDIT!
package gitaly
......
// Code generated by protoc-gen-go.
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: shared.proto
// DO NOT EDIT!
package gitaly
......@@ -14,7 +13,6 @@ var _ = fmt.Errorf
var _ = math.Inf
type Repository struct {
Path string `protobuf:"bytes,1,opt,name=path" json:"path,omitempty"`
StorageName string `protobuf:"bytes,2,opt,name=storage_name,json=storageName" json:"storage_name,omitempty"`
RelativePath string `protobuf:"bytes,3,opt,name=relative_path,json=relativePath" json:"relative_path,omitempty"`
}
......@@ -24,13 +22,6 @@ func (m *Repository) String() string { return proto.CompactTextString
func (*Repository) ProtoMessage() {}
func (*Repository) Descriptor() ([]byte, []int) { return fileDescriptor4, []int{0} }
func (m *Repository) GetPath() string {
if m != nil {
return m.Path
}
return ""
}
func (m *Repository) GetStorageName() string {
if m != nil {
return m.StorageName
......@@ -69,16 +60,16 @@ func init() {
func init() { proto.RegisterFile("shared.proto", fileDescriptor4) }
var fileDescriptor4 = []byte{
// 161 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x34, 0x8e, 0xb1, 0xca, 0xc2, 0x40,
0x10, 0x84, 0xc9, 0xff, 0x9b, 0x80, 0x6b, 0x6c, 0x16, 0x8b, 0x94, 0x1a, 0x1b, 0x2b, 0x1b, 0x9f,
0xc1, 0x56, 0xe4, 0x7c, 0x80, 0xb0, 0xe2, 0x92, 0x3b, 0xb8, 0x78, 0xc7, 0xdd, 0x26, 0x98, 0xb7,
0x17, 0x56, 0xed, 0x76, 0xbf, 0x99, 0x61, 0x06, 0xea, 0x6c, 0x29, 0xf1, 0xe3, 0x18, 0x53, 0x90,
0x80, 0x55, 0xef, 0x84, 0xfc, 0xdc, 0x5a, 0x00, 0xc3, 0x31, 0x64, 0x27, 0x21, 0xcd, 0x88, 0xb0,
0x88, 0x24, 0xb6, 0x29, 0xb6, 0xc5, 0x61, 0x69, 0xf4, 0xc6, 0x1d, 0xd4, 0x59, 0x42, 0xa2, 0x9e,
0xbb, 0x27, 0x0d, 0xdc, 0xfc, 0xa9, 0xb6, 0xfa, 0xb2, 0x0b, 0x0d, 0x8c, 0x7b, 0x58, 0x27, 0xf6,
0x24, 0x6e, 0xe2, 0x4e, 0xf3, 0xff, 0xea, 0xa9, 0x7f, 0xf0, 0x4a, 0x62, 0xdb, 0x16, 0xe0, 0xfc,
0x72, 0x72, 0x13, 0x92, 0x31, 0xe3, 0x06, 0xca, 0x89, 0xfc, 0xc8, 0x5a, 0x55, 0x9a, 0xcf, 0x73,
0xaf, 0x74, 0xdc, 0xe9, 0x1d, 0x00, 0x00, 0xff, 0xff, 0xbd, 0xf7, 0x56, 0x73, 0xac, 0x00, 0x00,
0x00,
// 164 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x34, 0xce, 0x31, 0x0f, 0x82, 0x30,
0x10, 0x05, 0xe0, 0x14, 0x81, 0xe8, 0x89, 0x89, 0x69, 0x1c, 0x18, 0x11, 0x17, 0x26, 0x17, 0x7f,
0x83, 0x8b, 0x83, 0x31, 0xf5, 0x07, 0xe0, 0x19, 0x2f, 0xd0, 0xa4, 0xd8, 0xa6, 0x3d, 0x88, 0xfc,
0x7b, 0x23, 0xea, 0xf8, 0xbe, 0xf7, 0x86, 0x07, 0x59, 0x68, 0xd1, 0xd3, 0x63, 0xef, 0xbc, 0x65,
0x2b, 0xd3, 0x46, 0x33, 0x9a, 0xb1, 0xbc, 0x01, 0x28, 0x72, 0x36, 0x68, 0xb6, 0x7e, 0x94, 0x5b,
0xc8, 0x02, 0x5b, 0x8f, 0x0d, 0xd5, 0x4f, 0xec, 0x28, 0x8f, 0x0a, 0x51, 0x2d, 0xd4, 0xf2, 0x67,
0x67, 0xec, 0x48, 0xee, 0x60, 0xe5, 0xc9, 0x20, 0xeb, 0x81, 0x6a, 0x87, 0xdc, 0xe6, 0xb3, 0x69,
0x93, 0xfd, 0xf1, 0x82, 0xdc, 0x9e, 0xe2, 0xb9, 0x58, 0x47, 0x2a, 0xfe, 0xf4, 0x65, 0x09, 0x70,
0x7c, 0x69, 0xbe, 0x32, 0x72, 0x1f, 0xe4, 0x06, 0x92, 0x01, 0x4d, 0x4f, 0xb9, 0x28, 0x44, 0x95,
0xa8, 0x6f, 0xb8, 0xa7, 0xd3, 0xa9, 0xc3, 0x3b, 0x00, 0x00, 0xff, 0xff, 0xfe, 0x53, 0x2c, 0xb6,
0xa4, 0x00, 0x00, 0x00,
}
// Code generated by protoc-gen-go.
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: smarthttp.proto
// DO NOT EDIT!
package gitaly
......@@ -98,9 +97,10 @@ type PostReceivePackRequest struct {
Repository *Repository `protobuf:"bytes,1,opt,name=repository" json:"repository,omitempty"`
// Raw data to be copied to stdin of 'git receive-pack'
Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"`
// gl_id becomes env variable GL_ID, used by the Git {pre,post}-receive
// hooks. Should only be present in the first message of the stream.
GlId string `protobuf:"bytes,3,opt,name=gl_id,json=glId" json:"gl_id,omitempty"`
// gl_id and gl_repository becomes env variables, used by the Git {pre,post}-receive
// hooks. They should only be present in the first message of the stream.
GlId string `protobuf:"bytes,3,opt,name=gl_id,json=glId" json:"gl_id,omitempty"`
GlRepository string `protobuf:"bytes,4,opt,name=gl_repository,json=glRepository" json:"gl_repository,omitempty"`
}
func (m *PostReceivePackRequest) Reset() { *m = PostReceivePackRequest{} }
......@@ -129,6 +129,13 @@ func (m *PostReceivePackRequest) GetGlId() string {
return ""
}
func (m *PostReceivePackRequest) GetGlRepository() string {
if m != nil {
return m.GlRepository
}
return ""
}
type PostReceivePackResponse struct {
// Raw data from stdout of 'git receive-pack'
Data []byte `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"`
......@@ -455,24 +462,26 @@ var _SmartHTTP_serviceDesc = grpc.ServiceDesc{
func init() { proto.RegisterFile("smarthttp.proto", fileDescriptor5) }
var fileDescriptor5 = []byte{
// 304 bytes of a gzipped FileDescriptorProto
// 321 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x53, 0x4d, 0x4b, 0xc3, 0x40,
0x14, 0x74, 0x6b, 0x2d, 0xf4, 0x59, 0xac, 0xbc, 0xa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0xa5, 0x73, 0xe1, 0xc6, 0x60, 0x35, 0x63, 0xe3, 0xb4, 0x16, 0x2f, 0x32, 0x3f, 0xb6,
0xe2, 0xa7, 0x72, 0xf5, 0x19, 0x00, 0x00, 0xff, 0xff, 0x4c, 0x33, 0x8a, 0x1a, 0x53, 0x03, 0x00,
0x00,
}
// Code generated by protoc-gen-go.
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: ssh.proto
// DO NOT EDIT!
package gitaly
......@@ -85,8 +84,10 @@ type SSHReceivePackRequest struct {
Repository *Repository `protobuf:"bytes,1,opt,name=repository" json:"repository,omitempty"`
// A chunk of raw data to be copied to 'git upload-pack' standard input
Stdin []byte `protobuf:"bytes,2,opt,name=stdin,proto3" json:"stdin,omitempty"`
// Contents of GL_ID environment variable for 'git receive-pack'
GlId string `protobuf:"bytes,3,opt,name=gl_id,json=glId" json:"gl_id,omitempty"`
// Contents of GL_ID and GL_REPOSITORY environment variables for
// 'git receive-pack'
GlId string `protobuf:"bytes,3,opt,name=gl_id,json=glId" json:"gl_id,omitempty"`
GlRepository string `protobuf:"bytes,4,opt,name=gl_repository,json=glRepository" json:"gl_repository,omitempty"`
}
func (m *SSHReceivePackRequest) Reset() { *m = SSHReceivePackRequest{} }
......@@ -115,6 +116,13 @@ func (m *SSHReceivePackRequest) GetGlId() string {
return ""
}
func (m *SSHReceivePackRequest) GetGlRepository() string {
if m != nil {
return m.GlRepository
}
return ""
}
type SSHReceivePackResponse struct {
// A chunk of raw data from 'git receive-pack' standard output
Stdout []byte `protobuf:"bytes,1,opt,name=stdout,proto3" json:"stdout,omitempty"`
......@@ -334,23 +342,24 @@ var _SSH_serviceDesc = grpc.ServiceDesc{
func init() { proto.RegisterFile("ssh.proto", fileDescriptor6) }
var fileDescriptor6 = []byte{
// 284 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x52, 0xcd, 0x4a, 0xc3, 0x40,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xaf, 0xa1, 0x9f, 0xe5, 0x0b, 0x2d, 0x2b,
0x47, 0x03, 0x71, 0x91, 0xe5, 0x4f, 0x32, 0xf8, 0x84, 0xf1, 0xa1, 0xee, 0x09, 0x63, 0xc7, 0x5f,
0x0c, 0x7a, 0x49, 0x32, 0xe3, 0x02, 0x2e, 0x3b, 0xcb, 0xe7, 0xb7, 0x3f, 0x83, 0x7f, 0xbd, 0xba,
0x7f, 0x77, 0x04, 0xad, 0xad, 0x07, 0x67, 0x21, 0x7b, 0x60, 0x7c, 0x0e, 0x57, 0xdd, 0x68, 0xbc,
0x3d, 0xf6, 0x7b, 0xd5, 0xfe, 0xfd, 0x31, 0xb8, 0x4d, 0xfb, 0xea, 0x54, 0x1f, 0x72, 0xfa, 0x1d,
0x00, 0x00, 0xff, 0xff, 0x71, 0xde, 0xae, 0x4f, 0xb3, 0x02, 0x00, 0x00,
// 304 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x52, 0xcd, 0x4e, 0xf3, 0x30,
0x10, 0xfc, 0xfc, 0xf5, 0x47, 0xea, 0x36, 0xe5, 0xb0, 0x94, 0xaa, 0x8a, 0x00, 0x55, 0xe1, 0x92,
0x53, 0x84, 0xd2, 0x67, 0x40, 0x2a, 0x37, 0xe4, 0xa8, 0xe7, 0x10, 0x6a, 0x2b, 0xb5, 0xb0, 0xea,
0x60, 0x3b, 0xa8, 0x95, 0xe0, 0x49, 0x78, 0x09, 0x1e, 0x11, 0xc9, 0x09, 0x25, 0x29, 0xf4, 0x08,
0xb7, 0xcc, 0x4e, 0x76, 0x66, 0xd6, 0xbb, 0x30, 0x30, 0x66, 0x1d, 0x15, 0x5a, 0x59, 0x85, 0xfd,
0x5c, 0xd8, 0x4c, 0xee, 0x7c, 0xcf, 0xac, 0x33, 0xcd, 0x59, 0x55, 0x0d, 0xee, 0x61, 0x9c, 0x24,
0x8b, 0x65, 0x21, 0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 0x37, 0x65, 0x1f, 0xfa, 0xee,
0x6c, 0xe7, 0x1f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xa3, 0x3d, 0xb9, 0xce, 0xd9, 0x02, 0x00, 0x00,
}
The MIT License (MIT)
Copyright (c) 2016-2017 GitLab B.V.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
This source diff could not be displayed because it is too large. You can view the blob instead.
package client
import (
"fmt"
"net"
"net/url"
"strings"
"time"
"google.golang.org/grpc"
)
// DefaultDialOpts hold the default DialOptions for connection to Gitaly over UNIX-socket
var DefaultDialOpts = []grpc.DialOption{
grpc.WithInsecure(),
}
// Dial gitaly
func Dial(rawAddress string, connOpts []grpc.DialOption) (*grpc.ClientConn, error) {
network, addr, err := parseAddress(rawAddress)
if err != nil {
return nil, err
}
connOpts = append(connOpts,
grpc.WithDialer(func(a string, _ time.Duration) (net.Conn, error) {
return net.Dial(network, a)
}))
conn, err := grpc.Dial(addr, connOpts...)
if err != nil {
return nil, err
}
return conn, nil
}
func parseAddress(rawAddress string) (network, addr string, err error) {
// Parsing unix:// URL's with url.Parse does not give the result we want
// so we do it manually.
for _, prefix := range []string{"unix://", "unix:"} {
if strings.HasPrefix(rawAddress, prefix) {
return "unix", strings.TrimPrefix(rawAddress, prefix), nil
}
}
u, err := url.Parse(rawAddress)
if err != nil {
return "", "", err
}
if u.Scheme != "tcp" {
return "", "", fmt.Errorf("unknown scheme: %q", rawAddress)
}
if u.Host == "" {
return "", "", fmt.Errorf("network tcp requires host: %q", rawAddress)
}
if u.Path != "" {
return "", "", fmt.Errorf("network tcp should have no path: %q", rawAddress)
}
return "tcp", u.Host, nil
}
package client
import (
"fmt"
"io"
"google.golang.org/grpc"
"golang.org/x/net/context"
pb "gitlab.com/gitlab-org/gitaly-proto/go"
pbhelper "gitlab.com/gitlab-org/gitaly-proto/go/helper"
)
// ReceivePack proxies an SSH git-receive-pack (git push) session to Gitaly
func ReceivePack(ctx context.Context, conn *grpc.ClientConn, stdin io.Reader, stdout, stderr io.Writer, req *pb.SSHReceivePackRequest) (int32, error) {
ctx2, cancel := context.WithCancel(ctx)
defer cancel()
ssh := pb.NewSSHClient(conn)
stream, err := ssh.SSHReceivePack(ctx2)
if err != nil {
return 0, err
}
if err = stream.Send(req); err != nil {
return 0, err
}
inWriter := pbhelper.NewSendWriter(func(p []byte) error {
return stream.Send(&pb.SSHReceivePackRequest{Stdin: p})
})
errC := make(chan error, 1)
go func() {
_, errRecv := io.Copy(inWriter, stdin)
stream.CloseSend()
errC <- errRecv
}()
exitStatus, errRecv := recvStdoutStderrStream(func() (stdoutStderrResponse, error) {
return stream.Recv()
}, stdout, stderr)
if errRecv != nil {
return exitStatus, errRecv
}
select {
case errSend := <-errC:
if errSend != nil {
// This should not happen
errSend = fmt.Errorf("stdin send error: %v", errSend)
}
return exitStatus, errSend
default:
return exitStatus, nil
}
}
package client
import (
"io"
pb "gitlab.com/gitlab-org/gitaly-proto/go"
)
type stdoutStderrResponse interface {
GetExitStatus() *pb.ExitStatus
GetStderr() []byte
GetStdout() []byte
}
func recvStdoutStderrStream(recv func() (stdoutStderrResponse, error), stdout, stderr io.Writer) (int32, error) {
var (
exitStatus int32
err error
resp stdoutStderrResponse
)
for {
resp, err = recv()
if err != nil {
break
}
if resp.GetExitStatus() != nil {
exitStatus = resp.GetExitStatus().GetValue()
}
if len(resp.GetStderr()) > 0 {
if _, errWrite := stderr.Write(resp.GetStderr()); errWrite != nil {
return exitStatus, errWrite
}
}
if len(resp.GetStdout()) > 0 {
if _, errWrite := stdout.Write(resp.GetStdout()); errWrite != nil {
return exitStatus, errWrite
}
}
}
if err == io.EOF {
err = nil
}
return exitStatus, err
}
package client
import (
"fmt"
"io"
"google.golang.org/grpc"
"golang.org/x/net/context"
pb "gitlab.com/gitlab-org/gitaly-proto/go"
pbhelper "gitlab.com/gitlab-org/gitaly-proto/go/helper"
)
// UploadPack proxies an SSH git-upload-pack (git fetch) session to Gitaly
func UploadPack(ctx context.Context, conn *grpc.ClientConn, stdin io.Reader, stdout, stderr io.Writer, req *pb.SSHUploadPackRequest) (int32, error) {
ctx2, cancel := context.WithCancel(ctx)
defer cancel()
ssh := pb.NewSSHClient(conn)
stream, err := ssh.SSHUploadPack(ctx2)
if err != nil {
return 0, err
}
if err = stream.Send(req); err != nil {
return 0, err
}
inWriter := pbhelper.NewSendWriter(func(p []byte) error {
return stream.Send(&pb.SSHUploadPackRequest{Stdin: p})
})
errC := make(chan error, 1)
go func() {
_, errRecv := io.Copy(inWriter, stdin)
stream.CloseSend()
errC <- errRecv
}()
exitStatus, errRecv := recvStdoutStderrStream(func() (stdoutStderrResponse, error) {
return stream.Recv()
}, stdout, stderr)
if errRecv != nil {
return exitStatus, errRecv
}
select {
case errSend := <-errC:
if errSend != nil {
// This should not happen
errSend = fmt.Errorf("stdin send error: %v", errSend)
}
return exitStatus, errSend
default:
return exitStatus, nil
}
}
......@@ -21,13 +21,19 @@
"revisionTime": "2017-03-31T03:19:02Z"
},
{
"checksumSHA1": "EE3twlbq1QkQ5J9dor9QFDR5LX4=",
"checksumSHA1": "guPHQjm2kqtHM03hF2rss9K6YR8=",
"path": "gitlab.com/gitlab-org/gitaly-proto/go",
"revision": "52f77b23166e640a932e50223472d761404afb42",
"revisionTime": "2017-03-29T16:52:58Z",
"revision": "e302a46f7ccd889bfaa683d2ba06ffe06ca5875b",
"revisionTime": "2017-06-12T18:49:50Z",
"tree": true,
"version": "v0.5.0",
"versionExact": "v0.5.0"
"version": "v0.9.0",
"versionExact": "v0.9.0"
},
{
"checksumSHA1": "xDXnu1dEiNdrGdL1VfuCnJZey7s=",
"path": "gitlab.com/gitlab-org/gitaly/client",
"revision": "cf955be6f08f16cca367a97d1ac2631a2ba33be3",
"revisionTime": "2017-06-25T13:40:46Z"
},
{
"checksumSHA1": "Y+HGqEkYM15ir+J93MEaHdyFy0c=",
......
require 'json'
class GitAccessStatus
attr_reader :message, :gl_repository, :repository_path
attr_reader :message, :gl_repository, :repository_path, :gitaly
def initialize(status, message, gl_repository, repository_path)
def initialize(status, message, gl_repository, repository_path, gitaly)
@status = status
@message = message
@gl_repository = gl_repository
@repository_path = repository_path
@gitaly = gitaly
end
def self.create_from_json(json)
values = JSON.parse(json)
self.new(values["status"], values["message"], values["gl_repository"], values["repository_path"])
self.new(values["status"], values["message"], values["gl_repository"], values["repository_path"], values["gitaly"])
end
def allowed?
......
......@@ -17,7 +17,7 @@ class GitlabShell
API_COMMANDS = %w(2fa_recovery_codes)
GL_PROTOCOL = 'ssh'.freeze
attr_accessor :key_id, :gl_repository, :repo_name, :command, :git_access
attr_accessor :key_id, :gl_repository, :repo_name, :command, :git_access, :repository, :gitaly_address
attr_reader :repo_path
def initialize(key_id)
......@@ -99,6 +99,7 @@ class GitlabShell
self.repo_path = status.repository_path
@gl_repository = status.gl_repository
@gitaly = status.gitaly
end
def process_cmd(args)
......@@ -115,15 +116,16 @@ class GitlabShell
executable = @command
args = [repo_path]
if GITALY_MIGRATED_COMMANDS.has_key?(executable)
if GITALY_MIGRATED_COMMANDS.has_key?(executable) && @gitaly
executable = GITALY_MIGRATED_COMMANDS[executable]
gitaly_address = '' # would be returned by gitlab-rails internal API
gitaly_address = @gitaly['address']
# The entire gitaly_request hash should be built in gitlab-ce and passed
# on as-is. For now we build a fake one on the spot.
gitaly_request = JSON.dump({
'repository' => { 'path' => repo_path },
'repository' => @gitaly['repository'],
'gl_repository' => @gl_repository,
'gl_id' => @key_id,
})
......@@ -153,6 +155,11 @@ class GitlabShell
'GL_PROTOCOL' => GL_PROTOCOL,
'GL_REPOSITORY' => @gl_repository
}
if @gitaly && @gitaly.has?('token')
env.merge!({
'GITALY_TOKEN' => @gitaly['token']
})
end
if git_trace_available?
env.merge!({
......
......@@ -7,7 +7,7 @@ describe GitlabAccess do
let(:repo_path) { File.join(repository_path, repo_name) + ".git" }
let(:api) do
double(GitlabNet).tap do |api|
api.stub(check_access: GitAccessStatus.new(true, 'ok', 'project-1', '/home/git/repositories'))
api.stub(check_access: GitAccessStatus.new(true, 'ok', 'project-1', '/home/git/repositories', nil))
end
end
subject do
......@@ -38,7 +38,7 @@ describe GitlabAccess do
context "access is denied" do
before do
api.stub(check_access: GitAccessStatus.new(false, 'denied', nil, nil))
api.stub(check_access: GitAccessStatus.new(false, 'denied', nil, nil, nil))
end
it "returns false" do
......
......@@ -19,10 +19,12 @@ describe GitlabShell do
end
end
let(:gitaly_check_access) { GitAccessStatus.new(true, 'ok', gl_repository, repo_path, { 'repository' => { 'relative_path' => repo_name, 'storage_name' => 'default'} , 'address' => 'unix:gitaly.socket' })}
let(:api) do
double(GitlabNet).tap do |api|
api.stub(discover: { 'name' => 'John Doe' })
api.stub(check_access: GitAccessStatus.new(true, 'ok', gl_repository, repo_path))
api.stub(check_access: GitAccessStatus.new(true, 'ok', gl_repository, repo_path, nil))
api.stub(two_factor_recovery_codes: {
'success' => true,
'recovery_codes' => ['f67c514de60c4953', '41278385fc00c1e0']
......@@ -128,7 +130,7 @@ describe GitlabShell do
end
describe :exec do
let(:gitaly_message) { JSON.dump({ 'repository' => { 'path' => repo_path }, 'gl_id' => key_id }) }
let(:gitaly_message) { JSON.dump({ 'repository' => { 'relative_path' => repo_name, 'storage_name' => 'default' }, 'gl_repository' => gl_repository , 'gl_id' => key_id}) }
context 'git-upload-pack' do
let(:ssh_cmd) { "git-upload-pack gitlab-ci.git" }
......@@ -139,12 +141,40 @@ describe GitlabShell do
end
it "should execute the command" do
subject.should_receive(:exec_cmd).with(File.join(ROOT_PATH, "bin/gitaly-upload-pack"), '', gitaly_message)
subject.should_receive(:exec_cmd).with('git-upload-pack', repo_path)
end
it "should log the command execution" do
message = "gitlab-shell: executing git command "
message << "<git-upload-pack #{repo_path}> "
message << "for user with key #{key_id}."
$logger.should_receive(:info).with(message)
end
it "should use usernames if configured to do so" do
GitlabConfig.any_instance.stub(audit_usernames: true)
$logger.should_receive(:info) { |msg| msg.should =~ /for John Doe/ }
end
end
context 'gitaly-upload-pack' do
let(:ssh_cmd) { "git-upload-pack gitlab-ci.git" }
before {
api.stub(check_access: gitaly_check_access)
}
after { subject.exec(ssh_cmd) }
it "should process the command" do
subject.should_receive(:process_cmd).with(%W(git-upload-pack gitlab-ci.git))
end
it "should execute the command" do
subject.should_receive(:exec_cmd).with(File.join(ROOT_PATH, "bin/gitaly-upload-pack"), 'unix:gitaly.socket', gitaly_message)
end
it "should log the command execution" do
message = "gitlab-shell: executing git command "
message << "<gitaly-upload-pack #{gitaly_message}> "
message << "<gitaly-upload-pack unix:gitaly.socket #{gitaly_message}> "
message << "for user with key #{key_id}."
$logger.should_receive(:info).with(message)
end
......@@ -164,17 +194,45 @@ describe GitlabShell do
end
it "should execute the command" do
subject.should_receive(:exec_cmd).with(File.join(ROOT_PATH, "bin/gitaly-receive-pack"), '', gitaly_message)
subject.should_receive(:exec_cmd).with('git-receive-pack', repo_path)
end
it "should log the command execution" do
message = "gitlab-shell: executing git command "
message << "<gitaly-receive-pack #{gitaly_message}> "
message << "<git-receive-pack #{repo_path}> "
message << "for user with key #{key_id}."
$logger.should_receive(:info).with(message)
end
end
context 'gitaly-receive-pack' do
let(:ssh_cmd) { "git-receive-pack gitlab-ci.git" }
before {
api.stub(check_access: gitaly_check_access)
}
after { subject.exec(ssh_cmd) }
it "should process the command" do
subject.should_receive(:process_cmd).with(%W(git-receive-pack gitlab-ci.git))
end
it "should execute the command" do
subject.should_receive(:exec_cmd).with(File.join(ROOT_PATH, "bin/gitaly-receive-pack"), 'unix:gitaly.socket', gitaly_message)
end
it "should log the command execution" do
message = "gitlab-shell: executing git command "
message << "<gitaly-receive-pack unix:gitaly.socket #{gitaly_message}> "
message << "for user with key #{key_id}."
$logger.should_receive(:info).with(message)
end
it "should use usernames if configured to do so" do
GitlabConfig.any_instance.stub(audit_usernames: true)
$logger.should_receive(:info) { |msg| msg.should =~ /for John Doe/ }
end
end
context 'arbitrary command' do
let(:ssh_cmd) { 'arbitrary command' }
after { subject.exec(ssh_cmd) }
......@@ -268,7 +326,7 @@ describe GitlabShell do
end
it "should disallow access and log the attempt if check_access returns false status" do
api.stub(check_access: GitAccessStatus.new(false, 'denied', nil, nil))
api.stub(check_access: GitAccessStatus.new(false, 'denied', nil, nil, nil))
message = "gitlab-shell: Access denied for git command <git-upload-pack gitlab-ci.git> "
message << "by user with key #{key_id}."
$logger.should_receive(:warn).with(message)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment