Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2020-11-22 21:52:33 +0300
committerJacob Vosmaer <jacob@gitlab.com>2020-11-22 21:52:33 +0300
commit8fb818986f4c052fe63bfcc039a7181ec88b6ae0 (patch)
treedfbb1035ecaf403d9cc678745a99f37f76a419e5
parentc2e4eb39fa3f09312183c0a2df2a360eb7285240 (diff)
Add ssh
-rw-r--r--internal/git/hooks.go2
-rw-r--r--internal/gitaly/service/register.go1
-rw-r--r--internal/gitaly/service/smarthttp/upload_pack.go2
-rw-r--r--internal/gitaly/service/ssh/server.go8
-rw-r--r--internal/gitaly/service/ssh/testhelper_test.go11
-rw-r--r--internal/gitaly/service/ssh/upload_pack.go8
6 files changed, 29 insertions, 3 deletions
diff --git a/internal/git/hooks.go b/internal/git/hooks.go
index 41d7ef22b..d4b34316b 100644
--- a/internal/git/hooks.go
+++ b/internal/git/hooks.go
@@ -36,7 +36,7 @@ func WithRefTxHook(ctx context.Context, repo *gitalypb.Repository, cfg config.Cf
}
}
-func WithPackObjectsHook(ctx context.Context, repo *gitalypb.Repository, cfg config.Cfg) CmdOpt {
+func WithPackObjectsHookEnv(ctx context.Context, repo *gitalypb.Repository, cfg config.Cfg) CmdOpt {
return func(cc *cmdCfg) error {
if repo == nil {
return fmt.Errorf("missing repo: %w", ErrInvalidArg)
diff --git a/internal/gitaly/service/register.go b/internal/gitaly/service/register.go
index d02aaf73e..08d60d1bd 100644
--- a/internal/gitaly/service/register.go
+++ b/internal/gitaly/service/register.go
@@ -80,6 +80,7 @@ func RegisterAll(grpcServer *grpc.Server, cfg config.Cfg, rubyServer *rubyserver
gitalypb.RegisterSSHServiceServer(grpcServer, ssh.NewServer(
locator,
ssh.WithPackfileNegotiationMetrics(sshPackfileNegotiationMetrics),
+ ssh.WithConfig(cfg),
))
gitalypb.RegisterSmartHTTPServiceServer(grpcServer, smarthttp.NewServer(
locator,
diff --git a/internal/gitaly/service/smarthttp/upload_pack.go b/internal/gitaly/service/smarthttp/upload_pack.go
index 5d0dd913f..628eff034 100644
--- a/internal/gitaly/service/smarthttp/upload_pack.go
+++ b/internal/gitaly/service/smarthttp/upload_pack.go
@@ -87,7 +87,7 @@ func (s *server) PostUploadPack(stream gitalypb.SmartHTTPService_PostUploadPackS
Args: []string{repoPath},
},
git.WithGitProtocol(ctx, req),
- git.WithPackObjectsHook(ctx, req.Repository, s.cfg),
+ git.WithPackObjectsHookEnv(ctx, req.Repository, s.cfg),
)
if err != nil {
diff --git a/internal/gitaly/service/ssh/server.go b/internal/gitaly/service/ssh/server.go
index 3a92c72b5..962af9f94 100644
--- a/internal/gitaly/service/ssh/server.go
+++ b/internal/gitaly/service/ssh/server.go
@@ -4,6 +4,7 @@ import (
"time"
"github.com/prometheus/client_golang/prometheus"
+ "gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/storage"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
)
@@ -18,6 +19,7 @@ type server struct {
uploadPackRequestTimeout time.Duration
uploadArchiveRequestTimeout time.Duration
packfileNegotiationMetrics *prometheus.CounterVec
+ cfg config.Cfg
}
// NewServer creates a new instance of a grpc SSHServer
@@ -61,3 +63,9 @@ func WithPackfileNegotiationMetrics(c *prometheus.CounterVec) ServerOpt {
s.packfileNegotiationMetrics = c
}
}
+
+func WithConfig(cfg config.Cfg) ServerOpt {
+ return func(s *server) {
+ s.cfg = cfg
+ }
+}
diff --git a/internal/gitaly/service/ssh/testhelper_test.go b/internal/gitaly/service/ssh/testhelper_test.go
index 1d805651b..41271e167 100644
--- a/internal/gitaly/service/ssh/testhelper_test.go
+++ b/internal/gitaly/service/ssh/testhelper_test.go
@@ -1,12 +1,15 @@
package ssh
import (
+ "net"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
+ gitalyhook "gitlab.com/gitlab-org/gitaly/internal/gitaly/hook"
+ "gitlab.com/gitlab-org/gitaly/internal/gitaly/service/hook"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"google.golang.org/grpc"
@@ -42,10 +45,18 @@ func testMain(m *testing.M) int {
func runSSHServer(t *testing.T, serverOpts ...ServerOpt) (string, func()) {
srv := testhelper.NewServer(t, nil, nil)
+ serverOpts = append([]ServerOpt{WithConfig(config.Config)}, serverOpts...)
gitalypb.RegisterSSHServiceServer(srv.GrpcServer(), NewServer(config.NewLocator(config.Config), serverOpts...))
+ gitalypb.RegisterHookServiceServer(srv.GrpcServer(), hook.NewServer(gitalyhook.NewManager(gitalyhook.GitlabAPIStub, config.Config)))
reflection.Register(srv.GrpcServer())
+ internalListener, err := net.Listen("unix", config.Config.GitalyInternalSocketPath())
+ if err != nil {
+ t.Fatal(err)
+ }
+
require.NoError(t, srv.Start())
+ go srv.GrpcServer().Serve(internalListener)
return "unix://" + srv.Socket(), srv.Stop
}
diff --git a/internal/gitaly/service/ssh/upload_pack.go b/internal/gitaly/service/ssh/upload_pack.go
index 8bb1aed2d..4a5fd7d59 100644
--- a/internal/gitaly/service/ssh/upload_pack.go
+++ b/internal/gitaly/service/ssh/upload_pack.go
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io"
+ "path/filepath"
"sync"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
@@ -79,6 +80,8 @@ func (s *server) sshUploadPack(stream gitalypb.SSHService_SSHUploadPackServer, r
git.WarnIfTooManyBitmaps(ctx, req.GetRepository())
globalOpts := git.UploadPackFilterConfig()
+ hookBin := filepath.Join(s.cfg.BinDir, "gitaly-hooks")
+ globalOpts = append(globalOpts, git.ValueFlag{"-c", "uploadpack.packobjectshook=" + hookBin})
for _, o := range req.GitConfigOptions {
globalOpts = append(globalOpts, git.ValueFlag{"-c", o})
}
@@ -106,7 +109,10 @@ func (s *server) sshUploadPack(stream gitalypb.SSHService_SSHUploadPackServer, r
cmd, monitor, err := monitorStdinCommand(ctx, stdin, stdout, stderr, nil, globalOpts, git.SubCmd{
Name: "upload-pack",
Args: []string{repoPath},
- }, git.WithGitProtocol(ctx, req))
+ },
+ git.WithGitProtocol(ctx, req),
+ git.WithPackObjectsHookEnv(ctx, req.Repository, s.cfg),
+ )
if err != nil {
return err