Skip to content

Commit

Permalink
Merge pull request #22 from hslatman/upgrade-crowdsec-v1.5.4
Browse files Browse the repository at this point in the history
Upgrade crowdsec v1.5.4
  • Loading branch information
hslatman authored Oct 15, 2023
2 parents e198699 + 55879ea commit 6f34a2a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.20
require (
github.com/caddyserver/caddy/v2 v2.7.4
github.com/caddyserver/format-encoder v0.0.0-20201124212233-c10acf81b981
github.com/crowdsecurity/crowdsec v1.5.3-rc4
github.com/crowdsecurity/crowdsec v1.5.4
github.com/crowdsecurity/go-cs-bouncer v0.0.8
github.com/google/go-cmp v0.5.9
github.com/hslatman/ipstore v0.0.0-20210131120430-64b55d649887
Expand Down Expand Up @@ -37,7 +37,7 @@ require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/crowdsecurity/go-cs-lib v0.0.3 // indirect
github.com/crowdsecurity/go-cs-lib v0.0.4 // indirect
github.com/dgraph-io/badger v1.6.2 // indirect
github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,12 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/crowdsecurity/crowdsec v1.5.3-rc4 h1:1lyLVt0yCDZAp61gPsIGN31QYD7w82TwIf2YkUEKnmA=
github.com/crowdsecurity/crowdsec v1.5.3-rc4/go.mod h1:GHVjaiY4Z/41TvzdsIN7CeAJmnmkFrpb0NCxkhbvOsU=
github.com/crowdsecurity/crowdsec v1.5.4 h1:pHwkqyLdyMCJ/0AM71sAWbwgUMP5cgN3pwjy+iAKYDg=
github.com/crowdsecurity/crowdsec v1.5.4/go.mod h1:PCiubBn1mthcc1S3leNpIS4yvykMTH/2X9z92HUeHes=
github.com/crowdsecurity/go-cs-bouncer v0.0.8 h1:icRkrvc9Gzwf/jZx1VYEZQMJFwuHN8+eNaWuKjlSmBI=
github.com/crowdsecurity/go-cs-bouncer v0.0.8/go.mod h1:U6GlXKk7Cu+nY2CrX6kh7iecJ2YKXBVhLh1rd5P6CfU=
github.com/crowdsecurity/go-cs-lib v0.0.3 h1:NPSHTLS83A3wFyzV5R9Py8fBbTrVHu/1PQeaD7id4+I=
github.com/crowdsecurity/go-cs-lib v0.0.3/go.mod h1:8FMKNGsh3hMZi2SEv6P15PURhEJnZV431XjzzBSuf0k=
github.com/crowdsecurity/go-cs-lib v0.0.4 h1:mH3iqz8H8iH9YpldqCdojyKHy9z3JDhas/k6I8M0ims=
github.com/crowdsecurity/go-cs-lib v0.0.4/go.mod h1:8FMKNGsh3hMZi2SEv6P15PURhEJnZV431XjzzBSuf0k=
github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E=
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964/go.mod h1:Xd9hchkHSWYkEqJwUGisez3G1QY8Ryz0sdWrLPMGjLk=
github.com/davecgh/go-spew v0.0.0-20161028175848-04cdfd42973b/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
21 changes: 5 additions & 16 deletions internal/bouncer/bouncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ package bouncer
import (
"context"
"fmt"
"io"
"net"

"github.com/crowdsecurity/crowdsec/pkg/models"
csbouncer "github.com/crowdsecurity/go-cs-bouncer"
"github.com/sirupsen/logrus"

"go.uber.org/zap"
"go.uber.org/zap/zapcore"
Expand Down Expand Up @@ -77,30 +75,22 @@ func (b *Bouncer) EnableHardFails() {

// Init initializes the Bouncer
func (b *Bouncer) Init() error {
// override CrowdSec's default logrus logging
b.overrideLogrusLogger()

// initialize the CrowdSec streaming bouncer
if b.useStreamingBouncer {
// silence the default CrowdSec logrus logging
logrus.SetOutput(io.Discard)

// catch log entries and log them using the *zap.Logger instead
logrus.AddHook(&zapAdapterHook{
logger: b.logger,
shouldFailHard: b.shouldFailHard,
address: b.streamingBouncer.APIUrl,
})

// initialize the CrowdSec streaming bouncer
return b.streamingBouncer.Init()
}

// initialize the CrowdSec live bouncer
return b.liveBouncer.Init()
}

// Run starts the Bouncer processes
func (b *Bouncer) Run() {

// the LiveBouncer has nothing to run in the background; return early
if !b.useStreamingBouncer {
// the LiveBouncer has nothing to run in the background; return early
return
}

Expand Down Expand Up @@ -213,7 +203,6 @@ func (b *Bouncer) IsAllowed(ip net.IP) (bool, *models.Decision, error) {
}

func (b *Bouncer) retrieveDecision(ip net.IP) (*models.Decision, error) {

if b.useStreamingBouncer {
return b.store.get(ip)
}
Expand Down
13 changes: 13 additions & 0 deletions internal/bouncer/logger.go → internal/bouncer/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,25 @@ package bouncer

import (
"errors"
"io"

"github.com/sirupsen/logrus"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)

func (b *Bouncer) overrideLogrusLogger() {
// silence the default CrowdSec logrus logging
logrus.SetOutput(io.Discard)

// catch log entries and log them using the *zap.Logger instead
logrus.AddHook(&zapAdapterHook{
logger: b.logger,
shouldFailHard: b.shouldFailHard,
address: b.streamingBouncer.APIUrl,
})
}

type zapAdapterHook struct {
logger *zap.Logger
shouldFailHard bool
Expand Down

0 comments on commit 6f34a2a

Please sign in to comment.