update logger driver

This commit is contained in:
Boshi Lian 2022-04-17 09:20:25 +00:00
parent ac04660939
commit 02e551ed2b
24 changed files with 69 additions and 32 deletions

1
go.mod
View file

@ -17,6 +17,7 @@ require (
github.com/jessevdk/go-flags v1.5.0
github.com/jinzhu/gorm v1.9.16
github.com/pockost/sshpipe-k8s-lib v0.0.3
github.com/sirupsen/logrus v1.8.1
github.com/tg123/remotesigner v0.0.0-20210928104451-7c20285909d1
github.com/tg123/sshkey v0.0.0-20201202190454-3bb356f89f1f
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519

4
go.sum
View file

@ -269,6 +269,8 @@ github.com/pockost/sshpipe-k8s-lib v0.0.3/go.mod h1:gDUHQhvnDsuvrIVuVD6HCaFYEZ1i
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
@ -277,6 +279,7 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
@ -395,6 +398,7 @@ golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

View file

@ -1,10 +1,11 @@
package typescriptlogger
import (
"log"
"os"
"path"
log "github.com/sirupsen/logrus"
"golang.org/x/crypto/ssh"
"github.com/tg123/sshpiper/sshpiperd/auditor"

View file

@ -2,10 +2,11 @@ package authy
import (
"fmt"
"log"
"net/url"
"time"
log "github.com/sirupsen/logrus"
"golang.org/x/crypto/ssh"
"github.com/dcu/go-authy"

View file

@ -2,9 +2,10 @@ package azdevicecode
import (
"context"
"log"
"net/http"
log "github.com/sirupsen/logrus"
"golang.org/x/crypto/ssh"
"github.com/Azure/azure-sdk-for-go/services/graphrbac/1.6/graphrbac"

View file

@ -1,7 +1,7 @@
package challenger
import (
"log"
log "github.com/sirupsen/logrus"
)
type plugin struct {

View file

@ -1,9 +1,9 @@
package pome
import (
log "github.com/sirupsen/logrus"
"github.com/tg123/sshpiper/sshpiperd/challenger"
"github.com/tg123/sshpiper/sshpiperd/upstream"
"log"
)
type plugin struct {

View file

@ -1,7 +1,7 @@
package pome
import (
"log"
log "github.com/sirupsen/logrus"
)
type pipe struct {

View file

@ -3,10 +3,11 @@ package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"strings"
log "github.com/sirupsen/logrus"
"github.com/jessevdk/go-flags"
"github.com/tg123/sshkey"
@ -177,7 +178,9 @@ func main() {
}
provider := upstream.Get(config.UpstreamDriver)
err := provider.Init(log.New(ioutil.Discard, "", 0))
logger := log.New()
logger.SetOutput(ioutil.Discard)
err := provider.Init(logger)
if err != nil {
return nil, err
}

View file

@ -37,6 +37,7 @@ services:
- "SSHPIPERD_UPSTREAM_WORKINGDIR_NOCHECKPERM=true"
- "SSHPIPERD_AUDITOR=typescript-logger"
- "SSHPIPERD_BANNERTEXT=hellopiper"
- "SSHPIPERD_LOG_LEVEL=trace"
build: ../..
volumes:
- workingdir:/var/sshpiper
@ -55,6 +56,7 @@ services:
- "SSHPIPERD_UPSTREAM_YAML_FILE=/sshpiperd.yaml"
- "SSHPIPERD_AUDITOR=typescript-logger"
- "SSHPIPERD_BANNERTEXT=hellopiper"
- "SSHPIPERD_LOG_LEVEL=trace"
build: ../..
volumes:
- localkey:/local
@ -87,6 +89,7 @@ services:
- "SSHPIPERD_UPSTREAM_MYSQL_HOST=mysql"
- "SSHPIPERD_AUDITOR=typescript-logger"
- "SSHPIPERD_BANNERTEXT=hellopiper"
- "SSHPIPERD_LOG_LEVEL=trace"
build: ../..
volumes:
- ./piper.sh:/piper.sh
@ -115,6 +118,7 @@ services:
- "SSHPIPERD_UPSTREAM_POSTGRES_SSLMODE=disable"
- "SSHPIPERD_AUDITOR=typescript-logger"
- "SSHPIPERD_BANNERTEXT=hellopiper"
- "SSHPIPERD_LOG_LEVEL=trace"
build: ../..
volumes:
- ./piper.sh:/piper.sh
@ -145,6 +149,7 @@ services:
- "SSHPIPERD_UPSTREAM_MSSQL_DBNAME=master"
- "SSHPIPERD_AUDITOR=typescript-logger"
- "SSHPIPERD_BANNERTEXT=hellopiper"
- "SSHPIPERD_LOG_LEVEL=trace"
build: ../..
volumes:
- ./piper.sh:/piper.sh
@ -179,6 +184,7 @@ services:
- "SSHPIPERD_UPSTREAM_GRPC_ENDPOINT=grpc_remotesigner_host1:2233"
- "SSHPIPERD_AUDITOR=typescript-logger"
- "SSHPIPERD_BANNERTEXT=hellopiper"
- "SSHPIPERD_LOG_LEVEL=trace"
build: ../..
volumes:
- workingdir:/var/sshpiper
@ -200,6 +206,7 @@ services:
- "SSHPIPERD_UPSTREAM_GRPC_ENDPOINT=grpc_privatekey_host1:2233"
- "SSHPIPERD_AUDITOR=typescript-logger"
- "SSHPIPERD_BANNERTEXT=hellopiper"
- "SSHPIPERD_LOG_LEVEL=trace"
build: ../..
volumes:
- workingdir:/var/sshpiper
@ -219,6 +226,7 @@ services:
- "SSHPIPERD_UPSTREAM_GRPC_ENDPOINT=grpc_remotepass_host2:2233"
- "SSHPIPERD_AUDITOR=typescript-logger"
- "SSHPIPERD_BANNERTEXT=hellopiper"
- "SSHPIPERD_LOG_LEVEL=trace"
build: ../..
depends_on:
- grpc_remotepass_host2

View file

@ -1,19 +1,20 @@
package main
import (
"log"
"os"
log "github.com/sirupsen/logrus"
)
type loggerConfig struct {
LogFile string `long:"log" description:"LogFile path. Leave empty or any error occurs will fall back to stdout" env:"SSHPIPERD_LOG_PATH" ini-name:"log-path"`
LogFlags int `long:"log-flags" default:"3" description:"Flags for logger see https://godoc.org/log, default LstdFlags" env:"SSHPIPERD_LOG_FLAGS" ini-name:"log-flags"`
LogLevel string `long:"log-level" default:"info" description:"These are the different logging levels, see https://pkg.go.dev/github.com/sirupsen/logrus#Level" env:"SSHPIPERD_LOG_LEVEL" ini-name:"log-level"`
}
func (l loggerConfig) createLogger() (logger *log.Logger) {
logger = log.New(os.Stdout, "", l.LogFlags)
logger = log.New()
if l.LogFile != "" {
f, err := os.OpenFile(l.LogFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
@ -22,8 +23,16 @@ func (l loggerConfig) createLogger() (logger *log.Logger) {
return
}
logger = log.New(f, "", logger.Flags())
logger.SetOutput(f)
}
level, err := log.ParseLevel(l.LogLevel)
if err != nil {
log.Fatalf("parse log level %v error %v", l.LogLevel, err)
return
}
logger.SetLevel(level)
return
}

View file

@ -1,7 +1,7 @@
package registry
import (
"log"
log "github.com/sirupsen/logrus"
)
// Plugin is to be registered with sshpiper to provide additional functions

View file

@ -1,9 +1,10 @@
package registry
import (
"log"
"reflect"
"testing"
log "github.com/sirupsen/logrus"
)
type testplugin struct {

View file

@ -9,7 +9,7 @@ import (
"golang.org/x/crypto/ssh"
"log"
log "github.com/sirupsen/logrus"
"github.com/tg123/sshpiper/sshpiperd/auditor"
"github.com/tg123/sshpiper/sshpiperd/challenger"
@ -187,11 +187,11 @@ func startPiper(config *piperdConfig, logger *log.Logger) error {
for {
conn, err := listener.Accept()
if err != nil {
logger.Printf("failed to accept connection: %v", err)
logger.Debugf("failed to accept connection: %v", err)
continue
}
logger.Printf("connection accepted: %v", conn.RemoteAddr())
logger.Debugf("connection accepted: %v", conn.RemoteAddr())
go func(c net.Conn) {
defer c.Close()
@ -215,10 +215,10 @@ func startPiper(config *piperdConfig, logger *log.Logger) error {
select {
case p = <-pipec:
case err := <-errorc:
logger.Printf("connection from %v establishing failed reason: %v", c.RemoteAddr(), err)
logger.Debugf("connection from %v establishing failed reason: %v", c.RemoteAddr(), err)
return
case <-time.After(config.LoginGraceTime):
logger.Printf("pipe establishing timeout, disconnected connection from %v", c.RemoteAddr())
logger.Debugf("pipe establishing timeout, disconnected connection from %v", c.RemoteAddr())
return
}
@ -236,8 +236,9 @@ func startPiper(config *piperdConfig, logger *log.Logger) error {
p.HookDownstreamMsg = a.GetDownstreamHook()
}
logger.Infof("ssh connection accepted from %v", c.RemoteAddr())
err = p.Wait()
logger.Printf("connection from %v closed reason: %v", c.RemoteAddr(), err)
logger.Infof("connection from %v closed reason: %v", c.RemoteAddr(), err)
}(conn)
}
}

View file

@ -1,17 +1,19 @@
package main
import (
"log"
"testing"
log "github.com/sirupsen/logrus"
"fmt"
"net"
"time"
"github.com/tg123/sshpiper/sshpiperd/auditor"
"github.com/tg123/sshpiper/sshpiperd/challenger"
"github.com/tg123/sshpiper/sshpiperd/registry"
"github.com/tg123/sshpiper/sshpiperd/upstream"
"golang.org/x/crypto/ssh"
"net"
"time"
)
type testplugin struct {

View file

@ -1,11 +1,12 @@
package database
import (
"log"
"net"
"os"
"testing"
log "github.com/sirupsen/logrus"
"github.com/tg123/sshkey"
"golang.org/x/crypto/ssh"

View file

@ -1,7 +1,7 @@
package database
import (
"log"
log "github.com/sirupsen/logrus"
"github.com/jinzhu/gorm"

View file

@ -5,7 +5,8 @@ import (
"crypto/x509"
"fmt"
"io/ioutil"
"log"
log "github.com/sirupsen/logrus"
"github.com/tg123/remotesigner/grpcsigner"
"github.com/tg123/sshpiper/sshpiperd/upstream"

View file

@ -4,7 +4,8 @@ import (
"context"
"fmt"
"io/ioutil"
"log"
log "github.com/sirupsen/logrus"
"github.com/tg123/sshpiper/sshpiperd/upstream/grpcupstream"
)

View file

@ -4,11 +4,12 @@ import (
"crypto"
"fmt"
"io/ioutil"
"log"
"net"
"reflect"
"unsafe"
log "github.com/sirupsen/logrus"
"github.com/jessevdk/go-flags"
"github.com/tg123/remotesigner/grpcsigner"
"github.com/tg123/sshpiper/sshpiperd/upstream/grpcupstream"

View file

@ -1,7 +1,7 @@
package kubernetes
import (
"log"
log "github.com/sirupsen/logrus"
"github.com/tg123/sshpiper/sshpiperd/upstream"
)

View file

@ -1,8 +1,8 @@
package workingdir
import (
log "github.com/sirupsen/logrus"
"github.com/tg123/sshpiper/sshpiperd/upstream"
"log"
)
var logger *log.Logger

View file

@ -9,7 +9,8 @@ import (
"bytes"
"io"
"io/ioutil"
"log"
log "github.com/sirupsen/logrus"
"net"
"os"

View file

@ -1,7 +1,7 @@
package yaml
import (
"log"
log "github.com/sirupsen/logrus"
"github.com/tg123/sshpiper/sshpiperd/upstream"
)