Add PipeCreateErrorCallback to handle pipe creation errors (#290)
* Add PipeCreateErrorCallback to handle pipe creation errors * Add test for FailtobanPipeCreateFail * Fix missing newline at end of file in pluginbase.go
This commit is contained in:
parent
295262fe68
commit
9fee039d93
9 changed files with 499 additions and 117 deletions
|
|
@ -196,9 +196,17 @@ func (d *daemon) run() error {
|
|||
case p = <-pipec:
|
||||
case err := <-errorc:
|
||||
log.Debugf("connection from %v establishing failed reason: %v", c.RemoteAddr(), err)
|
||||
if d.config.PipeCreateErrorCallback != nil {
|
||||
d.config.PipeCreateErrorCallback(c, err)
|
||||
}
|
||||
|
||||
return
|
||||
case <-time.After(d.loginGraceTime):
|
||||
log.Debugf("pipe establishing timeout, disconnected connection from %v", c.RemoteAddr())
|
||||
if d.config.PipeCreateErrorCallback != nil {
|
||||
d.config.PipeCreateErrorCallback(c, fmt.Errorf("pipe establishing timeout"))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package plugin
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/google/uuid"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
|
@ -157,5 +158,13 @@ func (cp *ChainPlugins) InstallPiperConfig(config *GrpcPluginConfig) error {
|
|||
}
|
||||
}
|
||||
|
||||
config.PipeCreateErrorCallback = func(conn net.Conn, err error) {
|
||||
for _, p := range cp.pluginsCallback {
|
||||
if p.PipeCreateErrorCallback != nil {
|
||||
p.PipeCreateErrorCallback(conn, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,8 +22,9 @@ import (
|
|||
type GrpcPluginConfig struct {
|
||||
ssh.PiperConfig
|
||||
|
||||
PipeStartCallback func(conn ssh.ConnMetadata, challengeCtx ssh.ChallengeContext)
|
||||
PipeErrorCallback func(conn ssh.ConnMetadata, challengeCtx ssh.ChallengeContext, err error)
|
||||
PipeCreateErrorCallback func(conn net.Conn, err error)
|
||||
PipeStartCallback func(conn ssh.ConnMetadata, challengeCtx ssh.ChallengeContext)
|
||||
PipeErrorCallback func(conn ssh.ConnMetadata, challengeCtx ssh.ChallengeContext, err error)
|
||||
}
|
||||
|
||||
type GrpcPlugin struct {
|
||||
|
|
@ -130,6 +131,8 @@ func (g *GrpcPlugin) InstallPiperConfig(config *GrpcPluginConfig) error {
|
|||
config.PipeStartCallback = g.PipeStartCallback
|
||||
case "PipeError":
|
||||
config.PipeErrorCallback = g.PipeErrorCallback
|
||||
case "PipeCreateError":
|
||||
config.PipeCreateErrorCallback = g.PipeCreateErrorCallback
|
||||
default:
|
||||
return fmt.Errorf("unknown callback %s", c)
|
||||
}
|
||||
|
|
@ -503,6 +506,13 @@ func (g *GrpcPlugin) BannerCallback(conn ssh.ConnMetadata, challengeCtx ssh.Chal
|
|||
return reply.GetMessage()
|
||||
}
|
||||
|
||||
func (g *GrpcPlugin) PipeCreateErrorCallback(conn net.Conn, err error) {
|
||||
_, _ = g.client.PipeCreateErrorNotice(context.Background(), &libplugin.PipeCreateErrorNoticeRequest{
|
||||
FromAddr: conn.RemoteAddr().String(),
|
||||
Error: err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
func (g *GrpcPlugin) PipeStartCallback(conn ssh.ConnMetadata, challengeCtx ssh.ChallengeContext) {
|
||||
meta := toMeta(challengeCtx, conn)
|
||||
_, _ = g.client.PipeStartNotice(context.Background(), &libplugin.PipeStartNoticeRequest{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue