From 2709d8136dd716d950acf4c2f0acb941462ee355 Mon Sep 17 00:00:00 2001 From: Boshi Lian Date: Fri, 6 Jan 2023 05:47:56 -0800 Subject: [PATCH] add downstream username to log (#120) * add downstream username to log * add username when pipe created --- cmd/sshpiperd/daemon.go | 2 +- cmd/sshpiperd/internal/plugin/grpc.go | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cmd/sshpiperd/daemon.go b/cmd/sshpiperd/daemon.go index 93480228..98fe986b 100644 --- a/cmd/sshpiperd/daemon.go +++ b/cmd/sshpiperd/daemon.go @@ -144,7 +144,7 @@ func (d *daemon) run() error { defer p.Close() - log.Infof("ssh connection pipe created %v -> %v", p.DownstreamConnMeta().RemoteAddr(), p.UpstreamConnMeta().RemoteAddr().String()) + log.Infof("ssh connection pipe created %v (username [%v]) -> %v (username [%v])", p.DownstreamConnMeta().RemoteAddr(), p.DownstreamConnMeta().User(), p.UpstreamConnMeta().RemoteAddr(), p.UpstreamConnMeta().User()) var uphook func([]byte) ([]byte, error) if d.recorddir != "" { diff --git a/cmd/sshpiperd/internal/plugin/grpc.go b/cmd/sshpiperd/internal/plugin/grpc.go index 62de7307..d167288a 100644 --- a/cmd/sshpiperd/internal/plugin/grpc.go +++ b/cmd/sshpiperd/internal/plugin/grpc.go @@ -70,49 +70,49 @@ func (g *GrpcPlugin) InstallPiperConfig(config *ssh.PiperConfig) error { log.Errorf("cannot get next auth methods %v", err) } - log.Debugf("next auth methods %v", methods) + log.Debugf("next auth methods %v for downstream %v (username [%v])", methods, conn.RemoteAddr().String(), conn.User()) return methods, err } case "NoneAuth": config.NoClientAuthCallback = func(conn ssh.ConnMetadata, challengeCtx ssh.ChallengeContext) (*ssh.Upstream, error) { - log.Debugf("downstream %v is sending none auth", conn.RemoteAddr().String()) + log.Debugf("downstream %v (username [%v]) is sending none auth", conn.RemoteAddr().String(), conn.User()) u, err := g.NoClientAuthCallback(conn, challengeCtx) if err != nil { - log.Errorf("cannot create upstream for %v with none auth: %v", conn.RemoteAddr().String(), err) + log.Errorf("cannot create upstream for %v (username [%v]) with none auth: %v", conn.RemoteAddr().String(), conn.User(), err) } return u, err } case "PasswordAuth": config.PasswordCallback = func(conn ssh.ConnMetadata, password []byte, challengeCtx ssh.ChallengeContext) (*ssh.Upstream, error) { - log.Debugf("downstream %v is sending password auth", conn.RemoteAddr().String()) + log.Debugf("downstream %v (username [%v]) is sending password auth", conn.RemoteAddr().String(), conn.User()) u, err := g.PasswordCallback(conn, password, challengeCtx) if err != nil { - log.Errorf("cannot create upstream for %v with password auth: %v", conn.RemoteAddr().String(), err) + log.Errorf("cannot create upstream for %v (username [%v]) with password auth: %v", conn.RemoteAddr().String(), conn.User(), err) } return u, err } case "PublicKeyAuth": config.PublicKeyCallback = func(conn ssh.ConnMetadata, key ssh.PublicKey, challengeCtx ssh.ChallengeContext) (*ssh.Upstream, error) { - log.Debugf("downstream %v is sending public key auth", conn.RemoteAddr().String()) + log.Debugf("downstream %v (username [%v]) is sending public key auth", conn.RemoteAddr().String(), conn.User()) u, err := g.PublicKeyCallback(conn, key, challengeCtx) if err != nil { - log.Errorf("cannot create upstream for %v with public key auth: %v", conn.RemoteAddr().String(), err) + log.Errorf("cannot create upstream for %v (username [%v]) with public key auth: %v", conn.RemoteAddr().String(), conn.User(), err) } return u, err } case "KeyboardInteractiveAuth": config.KeyboardInteractiveCallback = func(conn ssh.ConnMetadata, challenge ssh.KeyboardInteractiveChallenge, challengeCtx ssh.ChallengeContext) (*ssh.Upstream, error) { - log.Debugf("downstream %v is sending keyboard interactive auth", conn.RemoteAddr().String()) + log.Debugf("downstream %v (username [%v]) is sending keyboard interactive auth", conn.RemoteAddr().String(), conn.User()) u, err := g.KeyboardInteractiveCallback(conn, challenge, challengeCtx) if err != nil { - log.Errorf("cannot create upstream for %v with keyboard interactive auth: %v", conn.RemoteAddr().String(), err) + log.Errorf("cannot create upstream for %v (username [%v]) with keyboard interactive auth: %v", conn.RemoteAddr().String(), conn.User(), err) } return u, err } case "UpstreamAuthFailure": config.UpstreamAuthFailureCallback = func(conn ssh.ConnMetadata, method string, err error, challengeCtx ssh.ChallengeContext) { - log.Debugf("upstream rejected [%v] auth: %v", method, err) + log.Debugf("upstream rejected [%v] auth: %v from downstream %v (username [%v])", method, err, conn.RemoteAddr().String(), conn.User()) g.UpstreamAuthFailureCallbackRemote(conn, method, err, challengeCtx) } case "Banner":