From 7a936c0cf3d09c61cd75b19e9daf95ed0dcca424 Mon Sep 17 00:00:00 2001 From: Ash McKenzie Date: Mon, 19 Jun 2023 16:53:36 +1000 Subject: [PATCH 1/4] Remove empty line --- cmd/gitlab-sshd/main.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/gitlab-sshd/main.go b/cmd/gitlab-sshd/main.go index bc931f610..b0f702e6a 100644 --- a/cmd/gitlab-sshd/main.go +++ b/cmd/gitlab-sshd/main.go @@ -109,7 +109,6 @@ func main() { <-time.After(gracePeriod) cancel() - }() if err := server.ListenAndServe(ctx); err != nil { -- GitLab From b57d6dcc4137024924f491b317458b338b0b0a55 Mon Sep 17 00:00:00 2001 From: Ash McKenzie Date: Mon, 19 Jun 2023 16:54:19 +1000 Subject: [PATCH 2/4] Move handleConn: start where it belongs Also make it an Info call to match up with the 'handleConn: done' log line. --- internal/sshd/connection.go | 2 ++ internal/sshd/sshd.go | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/sshd/connection.go b/internal/sshd/connection.go index 402e89f90..e691d331d 100644 --- a/internal/sshd/connection.go +++ b/internal/sshd/connection.go @@ -51,6 +51,8 @@ func newConnection(cfg *config.Config, nconn net.Conn) *connection { } func (c *connection) handle(ctx context.Context, srvCfg *ssh.ServerConfig, handler channelHandler) { + log.WithContextFields(ctx, log.Fields{}).Info("server: handleConn: start") + sconn, chans, err := c.initServerConn(ctx, srvCfg) if err != nil { return diff --git a/internal/sshd/sshd.go b/internal/sshd/sshd.go index fbb505231..4c6463e51 100644 --- a/internal/sshd/sshd.go +++ b/internal/sshd/sshd.go @@ -180,7 +180,6 @@ func (s *Server) handleConn(ctx context.Context, nconn net.Conn) { remoteAddr := nconn.RemoteAddr().String() ctxlog := log.WithContextFields(ctx, log.Fields{"remote_addr": remoteAddr}) - ctxlog.Debug("server: handleConn: start") // Prevent a panic in a single connection from taking out the whole server defer func() { -- GitLab From 6c4334ea2c1236358b2feab09c7140afbe12f3bb Mon Sep 17 00:00:00 2001 From: Ash McKenzie Date: Mon, 19 Jun 2023 16:55:13 +1000 Subject: [PATCH 3/4] Extract started creation out into new variable --- internal/sshd/sshd.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/sshd/sshd.go b/internal/sshd/sshd.go index 4c6463e51..92469533e 100644 --- a/internal/sshd/sshd.go +++ b/internal/sshd/sshd.go @@ -190,7 +190,9 @@ func (s *Server) handleConn(ctx context.Context, nconn net.Conn) { } }() + started := time.Now() conn := newConnection(s.Config, nconn) + conn.handle(ctx, s.serverConfig.get(ctx), func(sconn *ssh.ServerConn, channel ssh.Channel, requests <-chan *ssh.Request) error { session := &session{ cfg: s.Config, @@ -198,7 +200,7 @@ func (s *Server) handleConn(ctx context.Context, nconn net.Conn) { gitlabKeyId: sconn.Permissions.Extensions["key-id"], gitlabKrb5Principal: sconn.Permissions.Extensions["krb5principal"], remoteAddr: remoteAddr, - started: time.Now(), + started: started, } return session.handle(ctx, requests) -- GitLab From c643b314e297f9f3faaae209543886e4a89fa4e5 Mon Sep 17 00:00:00 2001 From: Ash McKenzie Date: Mon, 19 Jun 2023 16:55:53 +1000 Subject: [PATCH 4/4] Log 'access: finish' line --- internal/sshd/sshd.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/sshd/sshd.go b/internal/sshd/sshd.go index 92469533e..f26458228 100644 --- a/internal/sshd/sshd.go +++ b/internal/sshd/sshd.go @@ -205,6 +205,8 @@ func (s *Server) handleConn(ctx context.Context, nconn net.Conn) { return session.handle(ctx, requests) }) + + ctxlog.WithFields(log.Fields{"duration_s": time.Since(started).Seconds()}).Info("access: finish") } func (s *Server) proxyPolicy() (proxyproto.PolicyFunc, error) { -- GitLab