merge from master
This commit is contained in:
commit
711f0474d9
179 changed files with 1912 additions and 1892 deletions
2
.github/workflows/bats-hub.yml
vendored
2
.github/workflows/bats-hub.yml
vendored
|
@ -15,7 +15,7 @@ jobs:
|
|||
build:
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: ["1.20.5"]
|
||||
go-version: ["1.20.6"]
|
||||
|
||||
name: "Build + tests"
|
||||
runs-on: ubuntu-latest
|
||||
|
|
2
.github/workflows/bats-mysql.yml
vendored
2
.github/workflows/bats-mysql.yml
vendored
|
@ -14,7 +14,7 @@ jobs:
|
|||
build:
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: ["1.20.5"]
|
||||
go-version: ["1.20.6"]
|
||||
|
||||
name: "Build + tests"
|
||||
runs-on: ubuntu-latest
|
||||
|
|
12
.github/workflows/bats-postgres.yml
vendored
12
.github/workflows/bats-postgres.yml
vendored
|
@ -10,14 +10,14 @@ jobs:
|
|||
build:
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: ["1.20.5"]
|
||||
go-version: ["1.20.6"]
|
||||
|
||||
name: "Build + tests"
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
services:
|
||||
database:
|
||||
image: postgres:14
|
||||
image: postgres:15
|
||||
env:
|
||||
POSTGRES_PASSWORD: "secret"
|
||||
ports:
|
||||
|
@ -30,6 +30,14 @@ jobs:
|
|||
|
||||
steps:
|
||||
|
||||
- name: "Install pg_dump v15"
|
||||
# we can remove this when it's released on ubuntu-latest
|
||||
run: |
|
||||
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
|
||||
wget -qO- https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo tee /etc/apt/trusted.gpg.d/pgdg.asc &>/dev/null
|
||||
sudo apt update
|
||||
sudo apt -qq -y -o=Dpkg::Use-Pty=0 install postgresql-client-15
|
||||
|
||||
- name: "Force machineid"
|
||||
run: |
|
||||
sudo chmod +w /etc/machine-id
|
||||
|
|
2
.github/workflows/bats-sqlite-coverage.yml
vendored
2
.github/workflows/bats-sqlite-coverage.yml
vendored
|
@ -11,7 +11,7 @@ jobs:
|
|||
build:
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: ["1.20.5"]
|
||||
go-version: ["1.20.6"]
|
||||
|
||||
name: "Build + tests"
|
||||
runs-on: ubuntu-latest
|
||||
|
|
2
.github/workflows/ci-windows-build-msi.yml
vendored
2
.github/workflows/ci-windows-build-msi.yml
vendored
|
@ -23,7 +23,7 @@ jobs:
|
|||
build:
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: ["1.20.5"]
|
||||
go-version: ["1.20.6"]
|
||||
|
||||
name: Build
|
||||
runs-on: windows-2019
|
||||
|
|
2
.github/workflows/go-tests-windows.yml
vendored
2
.github/workflows/go-tests-windows.yml
vendored
|
@ -22,7 +22,7 @@ jobs:
|
|||
build:
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: ["1.20.5"]
|
||||
go-version: ["1.20.6"]
|
||||
|
||||
name: "Build + tests"
|
||||
runs-on: windows-2022
|
||||
|
|
2
.github/workflows/go-tests.yml
vendored
2
.github/workflows/go-tests.yml
vendored
|
@ -34,7 +34,7 @@ jobs:
|
|||
build:
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: ["1.20.5"]
|
||||
go-version: ["1.20.6"]
|
||||
|
||||
name: "Build + tests"
|
||||
runs-on: ubuntu-latest
|
||||
|
|
|
@ -14,7 +14,7 @@ jobs:
|
|||
build:
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: ["1.20.5"]
|
||||
go-version: ["1.20.6"]
|
||||
|
||||
name: Build and upload binary package
|
||||
runs-on: ubuntu-latest
|
||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -46,6 +46,7 @@ plugins/notifications/slack/notification-slack
|
|||
plugins/notifications/splunk/notification-splunk
|
||||
plugins/notifications/email/notification-email
|
||||
plugins/notifications/dummy/notification-dummy
|
||||
plugins/notifications/sentinel/notification-sentinel
|
||||
|
||||
# Test cache (downloaded files)
|
||||
.cache
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# vim: set ft=dockerfile:
|
||||
ARG GOVERSION=1.20.5
|
||||
ARG GOVERSION=1.20.6
|
||||
|
||||
FROM golang:${GOVERSION}-alpine AS build
|
||||
|
||||
|
@ -56,6 +56,7 @@ COPY --from=build /go/src/crowdsec/plugins/notifications/email/email.yaml /stagi
|
|||
COPY --from=build /go/src/crowdsec/plugins/notifications/http/http.yaml /staging/etc/crowdsec/notifications/http.yaml
|
||||
COPY --from=build /go/src/crowdsec/plugins/notifications/slack/slack.yaml /staging/etc/crowdsec/notifications/slack.yaml
|
||||
COPY --from=build /go/src/crowdsec/plugins/notifications/splunk/splunk.yaml /staging/etc/crowdsec/notifications/splunk.yaml
|
||||
COPY --from=build /go/src/crowdsec/plugins/notifications/sentinel/sentinel.yaml /staging/etc/crowdsec/notifications/sentinel.yaml
|
||||
COPY --from=build /usr/local/lib/crowdsec/plugins /usr/local/lib/crowdsec/plugins
|
||||
|
||||
FROM slim as geoip
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# vim: set ft=dockerfile:
|
||||
ARG GOVERSION=1.20.5
|
||||
ARG GOVERSION=1.20.6
|
||||
|
||||
FROM golang:${GOVERSION}-bookworm AS build
|
||||
|
||||
|
@ -72,6 +72,7 @@ COPY --from=build /go/src/crowdsec/plugins/notifications/email/email.yaml /stagi
|
|||
COPY --from=build /go/src/crowdsec/plugins/notifications/http/http.yaml /staging/etc/crowdsec/notifications/http.yaml
|
||||
COPY --from=build /go/src/crowdsec/plugins/notifications/slack/slack.yaml /staging/etc/crowdsec/notifications/slack.yaml
|
||||
COPY --from=build /go/src/crowdsec/plugins/notifications/splunk/splunk.yaml /staging/etc/crowdsec/notifications/splunk.yaml
|
||||
COPY --from=build /go/src/crowdsec/plugins/notifications/sentinel/sentinel.yaml /staging/etc/crowdsec/notifications/sentinel.yaml
|
||||
COPY --from=build /usr/local/lib/crowdsec/plugins /usr/local/lib/crowdsec/plugins
|
||||
|
||||
FROM slim as geoip
|
||||
|
|
32
Makefile
32
Makefile
|
@ -31,8 +31,8 @@ BUILD_REQUIRE_GO_MINOR ?= 20
|
|||
|
||||
#--------------------------------------
|
||||
|
||||
GOCMD = go
|
||||
GOTEST = $(GOCMD) test
|
||||
GO = go
|
||||
GOTEST = $(GO) test
|
||||
|
||||
BUILD_CODENAME ?= alphaga
|
||||
|
||||
|
@ -43,6 +43,11 @@ PLUGINS_DIR = ./plugins/notifications
|
|||
CROWDSEC_BIN = crowdsec$(EXT)
|
||||
CSCLI_BIN = cscli$(EXT)
|
||||
|
||||
# semver comparison to select the hub branch requires the version to start with "v"
|
||||
ifneq ($(call substr,$(BUILD_VERSION),1,1),v)
|
||||
$(error BUILD_VERSION "$(BUILD_VERSION)" should start with "v")
|
||||
endif
|
||||
|
||||
# Directory for the release files
|
||||
RELDIR = crowdsec-$(BUILD_VERSION)
|
||||
|
||||
|
@ -65,9 +70,9 @@ bool = $(if $(filter $(call lc, $1),1 yes true),1,0)
|
|||
MAKE_FLAGS = --no-print-directory GOARCH=$(GOARCH) GOOS=$(GOOS) RM="$(RM)" WIN_IGNORE_ERR="$(WIN_IGNORE_ERR)" CP="$(CP)" CPR="$(CPR)" MKDIR="$(MKDIR)"
|
||||
|
||||
LD_OPTS_VARS= \
|
||||
-X 'github.com/crowdsecurity/go-cs-lib/pkg/version.Version=$(BUILD_VERSION)' \
|
||||
-X 'github.com/crowdsecurity/go-cs-lib/pkg/version.BuildDate=$(BUILD_TIMESTAMP)' \
|
||||
-X 'github.com/crowdsecurity/go-cs-lib/pkg/version.Tag=$(BUILD_TAG)' \
|
||||
-X 'github.com/crowdsecurity/go-cs-lib/version.Version=$(BUILD_VERSION)' \
|
||||
-X 'github.com/crowdsecurity/go-cs-lib/version.BuildDate=$(BUILD_TIMESTAMP)' \
|
||||
-X 'github.com/crowdsecurity/go-cs-lib/version.Tag=$(BUILD_TAG)' \
|
||||
-X '$(GO_MODULE_NAME)/pkg/cwversion.Codename=$(BUILD_CODENAME)' \
|
||||
-X '$(GO_MODULE_NAME)/pkg/csconfig.defaultConfigDir=$(DEFAULT_CONFIGDIR)' \
|
||||
-X '$(GO_MODULE_NAME)/pkg/csconfig.defaultDataDir=$(DEFAULT_DATADIR)'
|
||||
|
@ -78,6 +83,9 @@ endif
|
|||
|
||||
GO_TAGS := netgo,osusergo,sqlite_omit_load_extension
|
||||
|
||||
# this will be used by Go in the make target, some distributions require it
|
||||
export PKG_CONFIG_PATH:=/usr/local/lib/pkgconfig:$(PKG_CONFIG_PATH)
|
||||
|
||||
ifeq ($(call bool,$(BUILD_RE2_WASM)),0)
|
||||
ifeq ($(PKG_CONFIG),)
|
||||
$(error "pkg-config is not available. Please install pkg-config.")
|
||||
|
@ -201,12 +209,21 @@ PLUGIN_VENDOR = $(foreach plugin,$(PLUGINS),$(shell if [ -f $(PLUGINS_DIR)/$(plu
|
|||
vendor:
|
||||
$(foreach plugin_dir,$(PLUGIN_VENDOR), \
|
||||
cd $(plugin_dir) >/dev/null && \
|
||||
$(GOCMD) mod vendor && \
|
||||
$(GO) mod vendor && \
|
||||
cd - >/dev/null; \
|
||||
)
|
||||
$(GOCMD) mod vendor
|
||||
$(GO) mod vendor
|
||||
tar -czf vendor.tgz vendor $(foreach plugin_dir,$(PLUGIN_VENDOR),$(plugin_dir)/vendor)
|
||||
|
||||
.PHONY: tidy
|
||||
tidy:
|
||||
$(GO) mod tidy
|
||||
$(foreach plugin_dir,$(PLUGIN_VENDOR), \
|
||||
cd $(plugin_dir) >/dev/null && \
|
||||
$(GO) mod tidy && \
|
||||
cd - >/dev/null; \
|
||||
)
|
||||
|
||||
# remove vendor directories and vendor.tgz
|
||||
.PHONY: vendor-remove
|
||||
vendor-remove:
|
||||
|
@ -215,6 +232,7 @@ vendor-remove:
|
|||
)
|
||||
$(RM) vendor vendor.tgz
|
||||
|
||||
|
||||
.PHONY: package
|
||||
package:
|
||||
@echo "Building Release to dir $(RELDIR)"
|
||||
|
|
|
@ -27,7 +27,7 @@ stages:
|
|||
- task: GoTool@0
|
||||
displayName: "Install Go 1.20"
|
||||
inputs:
|
||||
version: '1.20.5'
|
||||
version: '1.20.6'
|
||||
|
||||
- pwsh: |
|
||||
choco install -y make
|
||||
|
|
|
@ -5,9 +5,9 @@ ifeq ($(OS), Windows_NT)
|
|||
endif
|
||||
|
||||
# Go parameters
|
||||
GOCMD = go
|
||||
GOBUILD = $(GOCMD) build
|
||||
GOTEST = $(GOCMD) test
|
||||
GO = go
|
||||
GOBUILD = $(GO) build
|
||||
GOTEST = $(GO) test
|
||||
|
||||
BINARY_NAME = cscli$(EXT)
|
||||
PREFIX ?= "/"
|
||||
|
|
|
@ -19,12 +19,14 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/version"
|
||||
"github.com/crowdsecurity/go-cs-lib/version"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/apiclient"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/database"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/models"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/types"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/require"
|
||||
)
|
||||
|
||||
func DecisionsFromAlert(alert *models.Alert) string {
|
||||
|
@ -525,8 +527,8 @@ func NewAlertsFlushCmd() *cobra.Command {
|
|||
DisableAutoGenTag: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
var err error
|
||||
if err := csConfig.LoadAPIServer(); err != nil || csConfig.DisableAPI {
|
||||
return fmt.Errorf("local API is disabled, please run this command on the local API machine")
|
||||
if err := require.LAPI(csConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
dbClient, err = database.NewClient(csConfig.DbConfig)
|
||||
if err != nil {
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
"github.com/fatih/color"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
|
@ -16,6 +17,8 @@ import (
|
|||
middlewares "github.com/crowdsecurity/crowdsec/pkg/apiserver/middlewares/v1"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/database"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/types"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/require"
|
||||
)
|
||||
|
||||
func getBouncers(out io.Writer, dbClient *database.Client) error {
|
||||
|
@ -58,8 +61,7 @@ func getBouncers(out io.Writer, dbClient *database.Client) error {
|
|||
func NewBouncersListCmd() *cobra.Command {
|
||||
cmdBouncersList := &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List bouncers",
|
||||
Long: `List bouncers`,
|
||||
Short: "list all bouncers within the database",
|
||||
Example: `cscli bouncers list`,
|
||||
Args: cobra.ExactArgs(0),
|
||||
DisableAutoGenTag: true,
|
||||
|
@ -107,7 +109,7 @@ func runBouncersAdd(cmd *cobra.Command, args []string) error {
|
|||
}
|
||||
|
||||
if csConfig.Cscli.Output == "human" {
|
||||
fmt.Printf("Api key for '%s':\n\n", keyName)
|
||||
fmt.Printf("API key for '%s':\n\n", keyName)
|
||||
fmt.Printf(" %s\n\n", apiKey)
|
||||
fmt.Print("Please keep this key since you will not be able to retrieve it!\n")
|
||||
} else if csConfig.Cscli.Output == "raw" {
|
||||
|
@ -126,8 +128,7 @@ func runBouncersAdd(cmd *cobra.Command, args []string) error {
|
|||
func NewBouncersAddCmd() *cobra.Command {
|
||||
cmdBouncersAdd := &cobra.Command{
|
||||
Use: "add MyBouncerName [--length 16]",
|
||||
Short: "add bouncer",
|
||||
Long: `add bouncer`,
|
||||
Short: "add a single bouncer to the database",
|
||||
Example: `cscli bouncers add MyBouncerName
|
||||
cscli bouncers add MyBouncerName -l 24
|
||||
cscli bouncers add MyBouncerName -k <random-key>`,
|
||||
|
@ -159,7 +160,7 @@ func runBouncersDelete(cmd *cobra.Command, args []string) error {
|
|||
func NewBouncersDeleteCmd() *cobra.Command {
|
||||
cmdBouncersDelete := &cobra.Command{
|
||||
Use: "delete MyBouncerName",
|
||||
Short: "delete bouncer",
|
||||
Short: "delete a single bouncer from the database",
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
Aliases: []string{"remove"},
|
||||
DisableAutoGenTag: true,
|
||||
|
@ -188,11 +189,81 @@ func NewBouncersDeleteCmd() *cobra.Command {
|
|||
return cmdBouncersDelete
|
||||
}
|
||||
|
||||
func NewBouncersPruneCmd() *cobra.Command {
|
||||
var parsedDuration time.Duration
|
||||
cmdBouncersPrune := &cobra.Command{
|
||||
Use: "prune",
|
||||
Short: "prune multiple bouncers from the database",
|
||||
Args: cobra.NoArgs,
|
||||
DisableAutoGenTag: true,
|
||||
Example: `cscli bouncers prune -d 60m
|
||||
cscli bouncers prune -d 60m --force`,
|
||||
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
dur, _ := cmd.Flags().GetString("duration")
|
||||
var err error
|
||||
parsedDuration, err = time.ParseDuration(fmt.Sprintf("-%s", dur))
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to parse duration '%s': %s", dur, err)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
force, _ := cmd.Flags().GetBool("force")
|
||||
if parsedDuration >= 0-2*time.Minute {
|
||||
var answer bool
|
||||
prompt := &survey.Confirm{
|
||||
Message: "The duration you provided is less than or equal 2 minutes this may remove active bouncers continue ?",
|
||||
Default: false,
|
||||
}
|
||||
if err := survey.AskOne(prompt, &answer); err != nil {
|
||||
return fmt.Errorf("unable to ask about prune check: %s", err)
|
||||
}
|
||||
if !answer {
|
||||
fmt.Println("user aborted prune no changes were made")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
bouncers, err := dbClient.QueryBouncersLastPulltimeLT(time.Now().UTC().Add(parsedDuration))
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to query bouncers: %s", err)
|
||||
}
|
||||
if len(bouncers) == 0 {
|
||||
fmt.Println("no bouncers to prune")
|
||||
return nil
|
||||
}
|
||||
getBouncersTable(color.Output, bouncers)
|
||||
if !force {
|
||||
var answer bool
|
||||
prompt := &survey.Confirm{
|
||||
Message: "You are about to PERMANENTLY remove the above bouncers from the database these will NOT be recoverable, continue ?",
|
||||
Default: false,
|
||||
}
|
||||
if err := survey.AskOne(prompt, &answer); err != nil {
|
||||
return fmt.Errorf("unable to ask about prune check: %s", err)
|
||||
}
|
||||
if !answer {
|
||||
fmt.Println("user aborted prune no changes were made")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
nbDeleted, err := dbClient.BulkDeleteBouncers(bouncers)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to prune bouncers: %s", err)
|
||||
}
|
||||
fmt.Printf("successfully delete %d bouncers\n", nbDeleted)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
cmdBouncersPrune.Flags().StringP("duration", "d", "60m", "duration of time since last pull")
|
||||
cmdBouncersPrune.Flags().Bool("force", false, "force prune without asking for confirmation")
|
||||
return cmdBouncersPrune
|
||||
}
|
||||
|
||||
func NewBouncersCmd() *cobra.Command {
|
||||
var cmdBouncers = &cobra.Command{
|
||||
Use: "bouncers [action]",
|
||||
Short: "Manage bouncers [requires local API]",
|
||||
Long: `To list/add/delete bouncers.
|
||||
Long: `To list/add/delete/prune bouncers.
|
||||
Note: This command requires database direct access, so is intended to be run on Local API/master.
|
||||
`,
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
|
@ -200,9 +271,10 @@ Note: This command requires database direct access, so is intended to be run on
|
|||
DisableAutoGenTag: true,
|
||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
var err error
|
||||
if err := csConfig.LoadAPIServer(); err != nil || csConfig.DisableAPI {
|
||||
return fmt.Errorf("local API is disabled, please run this command on the local API machine")
|
||||
if err = require.LAPI(csConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dbClient, err = database.NewClient(csConfig.DbConfig)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create new database client: %s", err)
|
||||
|
@ -214,6 +286,7 @@ Note: This command requires database direct access, so is intended to be run on
|
|||
cmdBouncers.AddCommand(NewBouncersListCmd())
|
||||
cmdBouncers.AddCommand(NewBouncersAddCmd())
|
||||
cmdBouncers.AddCommand(NewBouncersDeleteCmd())
|
||||
cmdBouncers.AddCommand(NewBouncersPruneCmd())
|
||||
|
||||
return cmdBouncers
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/version"
|
||||
"github.com/crowdsecurity/go-cs-lib/version"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/apiclient"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/csconfig"
|
||||
|
@ -19,6 +19,8 @@ import (
|
|||
"github.com/crowdsecurity/crowdsec/pkg/fflag"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/models"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/types"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/require"
|
||||
)
|
||||
|
||||
const CAPIBaseURL string = "https://api.crowdsec.net/"
|
||||
|
@ -31,14 +33,12 @@ func NewCapiCmd() *cobra.Command {
|
|||
Args: cobra.MinimumNArgs(1),
|
||||
DisableAutoGenTag: true,
|
||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
if err := csConfig.LoadAPIServer(); err != nil {
|
||||
return fmt.Errorf("local API is disabled, please run this command on the local API machine: %w", err)
|
||||
if err := require.LAPI(csConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
if csConfig.DisableAPI {
|
||||
return nil
|
||||
}
|
||||
if csConfig.API.Server.OnlineClient == nil {
|
||||
log.Fatalf("no configuration for Central API in '%s'", *csConfig.FilePath)
|
||||
|
||||
if err := require.CAPI(csConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -134,10 +134,6 @@ func NewCapiStatusCmd() *cobra.Command {
|
|||
Args: cobra.MinimumNArgs(0),
|
||||
DisableAutoGenTag: true,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
var err error
|
||||
if csConfig.API.Server == nil {
|
||||
log.Fatal("There is no configuration on 'api.server:'")
|
||||
}
|
||||
if csConfig.API.Server.OnlineClient == nil {
|
||||
log.Fatalf("Please provide credentials for the Central API (CAPI) in '%s'", csConfig.API.Server.OnlineClient.CredentialsFilePath)
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ var configShowTemplate = `Global:
|
|||
{{- end }}
|
||||
|
||||
{{- if .Crowdsec }}
|
||||
Crowdsec:
|
||||
Crowdsec{{if and .Crowdsec.Enable (not (ValueBool .Crowdsec.Enable))}} (disabled){{end}}:
|
||||
- Acquisition File : {{.Crowdsec.AcquisitionFilePath}}
|
||||
- Parsers routines : {{.Crowdsec.ParserRoutinesCount}}
|
||||
{{- if .Crowdsec.AcquisitionDirPath }}
|
||||
|
@ -97,7 +97,7 @@ API Client:
|
|||
{{- end }}
|
||||
|
||||
{{- if .API.Server }}
|
||||
Local API Server:
|
||||
Local API Server{{if and .API.Server.Enable (not (ValueBool .API.Server.Enable))}} (disabled){{end}}:
|
||||
- Listen URL : {{.API.Server.ListenURI}}
|
||||
- Profile File : {{.API.Server.ProfilesPath}}
|
||||
|
||||
|
@ -194,7 +194,15 @@ func runConfigShow(cmd *cobra.Command, args []string) error {
|
|||
|
||||
switch csConfig.Cscli.Output {
|
||||
case "human":
|
||||
tmp, err := template.New("config").Parse(configShowTemplate)
|
||||
// The tests on .Enable look funny because the option has a true default which has
|
||||
// not been set yet (we don't really load the LAPI) and go templates don't dereference
|
||||
// pointers in boolean tests. Prefix notation is the cherry on top.
|
||||
funcs := template.FuncMap{
|
||||
// can't use generics here
|
||||
"ValueBool": func(b *bool) bool { return b!=nil && *b },
|
||||
}
|
||||
|
||||
tmp, err := template.New("config").Funcs(funcs).Parse(configShowTemplate)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -4,9 +4,7 @@ import (
|
|||
"context"
|
||||
"encoding/csv"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
|
@ -16,14 +14,16 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/ptr"
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/version"
|
||||
"github.com/crowdsecurity/go-cs-lib/ptr"
|
||||
"github.com/crowdsecurity/go-cs-lib/version"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/apiclient"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/csconfig"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/fflag"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/types"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/require"
|
||||
)
|
||||
|
||||
func NewConsoleCmd() *cobra.Command {
|
||||
|
@ -33,24 +33,14 @@ func NewConsoleCmd() *cobra.Command {
|
|||
Args: cobra.MinimumNArgs(1),
|
||||
DisableAutoGenTag: true,
|
||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
if err := csConfig.LoadAPIServer(); err != nil || csConfig.DisableAPI {
|
||||
var fdErr *fs.PathError
|
||||
if errors.As(err, &fdErr) {
|
||||
log.Fatalf("Unable to load Local API : %s", fdErr)
|
||||
}
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to load required Local API Configuration : %s", err)
|
||||
}
|
||||
log.Fatal("Local API is disabled, please run this command on the local API machine")
|
||||
if err := require.LAPI(csConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
if csConfig.DisableAPI {
|
||||
log.Fatal("Local API is disabled, please run this command on the local API machine")
|
||||
if err := require.CAPI(csConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
if csConfig.API.Server.OnlineClient == nil {
|
||||
log.Fatalf("No configuration for Central API (CAPI) in '%s'", *csConfig.FilePath)
|
||||
}
|
||||
if csConfig.API.Server.OnlineClient.Credentials == nil {
|
||||
log.Fatal("You must configure Central API (CAPI) with `cscli capi register` before accessing console features.")
|
||||
if err := require.Enrolled(csConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"os"
|
||||
|
@ -18,6 +17,8 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/metabase"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/require"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -27,6 +28,7 @@ var (
|
|||
metabaseConfigPath string
|
||||
metabaseConfigFolder = "metabase/"
|
||||
metabaseConfigFile = "metabase.yaml"
|
||||
metabaseImage = "metabase/metabase:v0.46.6.1"
|
||||
/**/
|
||||
metabaseListenAddress = "127.0.0.1"
|
||||
metabaseListenPort = "3000"
|
||||
|
@ -54,23 +56,23 @@ cscli dashboard start
|
|||
cscli dashboard stop
|
||||
cscli dashboard remove
|
||||
`,
|
||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||
if err := metabase.TestAvailability(); err != nil {
|
||||
log.Fatalf("%s", err)
|
||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
if err := require.LAPI(csConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := csConfig.LoadAPIServer(); err != nil || csConfig.DisableAPI {
|
||||
log.Fatal("Local API is disabled, please run this command on the local API machine")
|
||||
if err := metabase.TestAvailability(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
metabaseConfigFolderPath := filepath.Join(csConfig.ConfigPaths.ConfigDir, metabaseConfigFolder)
|
||||
metabaseConfigPath = filepath.Join(metabaseConfigFolderPath, metabaseConfigFile)
|
||||
if err := os.MkdirAll(metabaseConfigFolderPath, os.ModePerm); err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
if err := csConfig.LoadDBConfig(); err != nil {
|
||||
log.Errorf("This command requires direct database access (must be run on the local API machine)")
|
||||
log.Fatal(err)
|
||||
|
||||
if err := require.DB(csConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -84,6 +86,7 @@ cscli dashboard remove
|
|||
metabaseContainerID = oldContainerID
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -96,7 +99,6 @@ cscli dashboard remove
|
|||
return cmdDashboard
|
||||
}
|
||||
|
||||
|
||||
func NewDashboardSetupCmd() *cobra.Command {
|
||||
var force bool
|
||||
|
||||
|
@ -111,7 +113,7 @@ cscli dashboard setup
|
|||
cscli dashboard setup --listen 0.0.0.0
|
||||
cscli dashboard setup -l 0.0.0.0 -p 443 --password <password>
|
||||
`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if metabaseDbPath == "" {
|
||||
metabaseDbPath = csConfig.ConfigPaths.DataDir
|
||||
}
|
||||
|
@ -123,70 +125,23 @@ cscli dashboard setup -l 0.0.0.0 -p 443 --password <password>
|
|||
isValid = passwordIsValid(metabasePassword)
|
||||
}
|
||||
}
|
||||
var answer bool
|
||||
if valid, err := checkSystemMemory(); err == nil && !valid {
|
||||
if !forceYes {
|
||||
prompt := &survey.Confirm{
|
||||
Message: "Metabase requires 1-2GB of RAM, your system is below this requirement continue ?",
|
||||
Default: true,
|
||||
}
|
||||
if err := survey.AskOne(prompt, &answer); err != nil {
|
||||
log.Warnf("unable to ask about RAM check: %s", err)
|
||||
}
|
||||
if !answer {
|
||||
log.Fatal("Unable to continue due to RAM requirement")
|
||||
}
|
||||
} else {
|
||||
log.Warnf("Metabase requires 1-2GB of RAM, your system is below this requirement")
|
||||
}
|
||||
if err := checkSystemMemory(&forceYes); err != nil {
|
||||
return err
|
||||
}
|
||||
groupExist := false
|
||||
dockerGroup, err := user.LookupGroup(crowdsecGroup)
|
||||
if err == nil {
|
||||
groupExist = true
|
||||
warnIfNotLoopback(metabaseListenAddress)
|
||||
if err := disclaimer(&forceYes); err != nil {
|
||||
return err
|
||||
}
|
||||
if !forceYes && !groupExist {
|
||||
prompt := &survey.Confirm{
|
||||
Message: fmt.Sprintf("For metabase docker to be able to access SQLite file we need to add a new group called '%s' to the system, is it ok for you ?", crowdsecGroup),
|
||||
Default: true,
|
||||
}
|
||||
if err := survey.AskOne(prompt, &answer); err != nil {
|
||||
log.Fatalf("unable to ask to force: %s", err)
|
||||
}
|
||||
}
|
||||
if !answer && !forceYes && !groupExist {
|
||||
log.Fatalf("unable to continue without creating '%s' group", crowdsecGroup)
|
||||
}
|
||||
if !groupExist {
|
||||
groupAddCmd, err := exec.LookPath("groupadd")
|
||||
if err != nil {
|
||||
log.Fatalf("unable to find 'groupadd' command, can't continue")
|
||||
}
|
||||
|
||||
groupAdd := &exec.Cmd{Path: groupAddCmd, Args: []string{groupAddCmd, crowdsecGroup}}
|
||||
if err := groupAdd.Run(); err != nil {
|
||||
log.Fatalf("unable to add group '%s': %s", dockerGroup, err)
|
||||
}
|
||||
dockerGroup, err = user.LookupGroup(crowdsecGroup)
|
||||
if err != nil {
|
||||
log.Fatalf("unable to lookup '%s' group: %+v", dockerGroup, err)
|
||||
}
|
||||
}
|
||||
intID, err := strconv.Atoi(dockerGroup.Gid)
|
||||
dockerGroup, err := checkGroups(&forceYes)
|
||||
if err != nil {
|
||||
log.Fatalf("unable to convert group ID to int: %s", err)
|
||||
return err
|
||||
}
|
||||
if err := os.Chown(csConfig.DbConfig.DbPath, 0, intID); err != nil {
|
||||
log.Fatalf("unable to chown sqlite db file '%s': %s", csConfig.DbConfig.DbPath, err)
|
||||
}
|
||||
|
||||
mb, err := metabase.SetupMetabase(csConfig.API.Server.DbConfig, metabaseListenAddress, metabaseListenPort, metabaseUser, metabasePassword, metabaseDbPath, dockerGroup.Gid, metabaseContainerID)
|
||||
mb, err := metabase.SetupMetabase(csConfig.API.Server.DbConfig, metabaseListenAddress, metabaseListenPort, metabaseUser, metabasePassword, metabaseDbPath, dockerGroup.Gid, metabaseContainerID, metabaseImage)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
|
||||
if err := mb.DumpConfig(metabaseConfigPath); err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
|
||||
log.Infof("Metabase is ready")
|
||||
|
@ -194,11 +149,13 @@ cscli dashboard setup -l 0.0.0.0 -p 443 --password <password>
|
|||
fmt.Printf("\tURL : '%s'\n", mb.Config.ListenURL)
|
||||
fmt.Printf("\tusername : '%s'\n", mb.Config.Username)
|
||||
fmt.Printf("\tpassword : '%s'\n", mb.Config.Password)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
cmdDashSetup.Flags().BoolVarP(&force, "force", "f", false, "Force setup : override existing files.")
|
||||
cmdDashSetup.Flags().StringVarP(&metabaseDbPath, "dir", "d", "", "Shared directory with metabase container.")
|
||||
cmdDashSetup.Flags().BoolVarP(&force, "force", "f", false, "Force setup : override existing files")
|
||||
cmdDashSetup.Flags().StringVarP(&metabaseDbPath, "dir", "d", "", "Shared directory with metabase container")
|
||||
cmdDashSetup.Flags().StringVarP(&metabaseListenAddress, "listen", "l", metabaseListenAddress, "Listen address of container")
|
||||
cmdDashSetup.Flags().StringVar(&metabaseImage, "metabase-image", metabaseImage, "Metabase image to use")
|
||||
cmdDashSetup.Flags().StringVarP(&metabaseListenPort, "port", "p", metabaseListenPort, "Listen port of container")
|
||||
cmdDashSetup.Flags().BoolVarP(&forceYes, "yes", "y", false, "force yes")
|
||||
//cmdDashSetup.Flags().StringVarP(&metabaseUser, "user", "u", "crowdsec@crowdsec.net", "metabase user")
|
||||
|
@ -214,18 +171,24 @@ func NewDashboardStartCmd() *cobra.Command {
|
|||
Long: `Stats the metabase container using docker.`,
|
||||
Args: cobra.ExactArgs(0),
|
||||
DisableAutoGenTag: true,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
mb, err := metabase.NewMetabase(metabaseConfigPath, metabaseContainerID)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
warnIfNotLoopback(mb.Config.ListenAddr)
|
||||
if err := disclaimer(&forceYes); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := mb.Container.Start(); err != nil {
|
||||
log.Fatalf("Failed to start metabase container : %s", err)
|
||||
return fmt.Errorf("failed to start metabase container : %s", err)
|
||||
}
|
||||
log.Infof("Started metabase")
|
||||
log.Infof("url : http://%s:%s", metabaseListenAddress, metabaseListenPort)
|
||||
log.Infof("url : http://%s:%s", mb.Config.ListenAddr, mb.Config.ListenPort)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
cmdDashStart.Flags().BoolVarP(&forceYes, "yes", "y", false, "force yes")
|
||||
return cmdDashStart
|
||||
}
|
||||
|
||||
|
@ -236,33 +199,33 @@ func NewDashboardStopCmd() *cobra.Command {
|
|||
Long: `Stops the metabase container using docker.`,
|
||||
Args: cobra.ExactArgs(0),
|
||||
DisableAutoGenTag: true,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if err := metabase.StopContainer(metabaseContainerID); err != nil {
|
||||
log.Fatalf("unable to stop container '%s': %s", metabaseContainerID, err)
|
||||
return fmt.Errorf("unable to stop container '%s': %s", metabaseContainerID, err)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
return cmdDashStop
|
||||
}
|
||||
|
||||
|
||||
func NewDashboardShowPasswordCmd() *cobra.Command {
|
||||
var cmdDashShowPassword = &cobra.Command{Use: "show-password",
|
||||
Short: "displays password of metabase.",
|
||||
Args: cobra.ExactArgs(0),
|
||||
DisableAutoGenTag: true,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
m := metabase.Metabase{}
|
||||
if err := m.LoadConfig(metabaseConfigPath); err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
log.Printf("'%s'", m.Config.Password)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
return cmdDashShowPassword
|
||||
}
|
||||
|
||||
|
||||
func NewDashboardRemoveCmd() *cobra.Command {
|
||||
var force bool
|
||||
|
||||
|
@ -276,53 +239,59 @@ func NewDashboardRemoveCmd() *cobra.Command {
|
|||
cscli dashboard remove
|
||||
cscli dashboard remove --force
|
||||
`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
answer := true
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if !forceYes {
|
||||
var answer bool
|
||||
prompt := &survey.Confirm{
|
||||
Message: "Do you really want to remove crowdsec dashboard? (all your changes will be lost)",
|
||||
Default: true,
|
||||
}
|
||||
if err := survey.AskOne(prompt, &answer); err != nil {
|
||||
log.Fatalf("unable to ask to force: %s", err)
|
||||
return fmt.Errorf("unable to ask to force: %s", err)
|
||||
}
|
||||
if !answer {
|
||||
return fmt.Errorf("user stated no to continue")
|
||||
}
|
||||
}
|
||||
if answer {
|
||||
if metabase.IsContainerExist(metabaseContainerID) {
|
||||
log.Debugf("Stopping container %s", metabaseContainerID)
|
||||
if err := metabase.StopContainer(metabaseContainerID); err != nil {
|
||||
log.Warningf("unable to stop container '%s': %s", metabaseContainerID, err)
|
||||
if metabase.IsContainerExist(metabaseContainerID) {
|
||||
log.Debugf("Stopping container %s", metabaseContainerID)
|
||||
if err := metabase.StopContainer(metabaseContainerID); err != nil {
|
||||
log.Warningf("unable to stop container '%s': %s", metabaseContainerID, err)
|
||||
}
|
||||
dockerGroup, err := user.LookupGroup(crowdsecGroup)
|
||||
if err == nil { // if group exist, remove it
|
||||
groupDelCmd, err := exec.LookPath("groupdel")
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to find 'groupdel' command, can't continue")
|
||||
}
|
||||
dockerGroup, err := user.LookupGroup(crowdsecGroup)
|
||||
if err == nil { // if group exist, remove it
|
||||
groupDelCmd, err := exec.LookPath("groupdel")
|
||||
if err != nil {
|
||||
log.Fatalf("unable to find 'groupdel' command, can't continue")
|
||||
}
|
||||
|
||||
groupDel := &exec.Cmd{Path: groupDelCmd, Args: []string{groupDelCmd, crowdsecGroup}}
|
||||
if err := groupDel.Run(); err != nil {
|
||||
log.Errorf("unable to delete group '%s': %s", dockerGroup, err)
|
||||
}
|
||||
groupDel := &exec.Cmd{Path: groupDelCmd, Args: []string{groupDelCmd, crowdsecGroup}}
|
||||
if err := groupDel.Run(); err != nil {
|
||||
log.Warnf("unable to delete group '%s': %s", dockerGroup, err)
|
||||
}
|
||||
log.Debugf("Removing container %s", metabaseContainerID)
|
||||
if err := metabase.RemoveContainer(metabaseContainerID); err != nil {
|
||||
log.Warningf("unable to remove container '%s': %s", metabaseContainerID, err)
|
||||
}
|
||||
log.Infof("container %s stopped & removed", metabaseContainerID)
|
||||
}
|
||||
log.Debugf("Removing metabase db %s", csConfig.ConfigPaths.DataDir)
|
||||
if err := metabase.RemoveDatabase(csConfig.ConfigPaths.DataDir); err != nil {
|
||||
log.Warningf("failed to remove metabase internal db : %s", err)
|
||||
log.Debugf("Removing container %s", metabaseContainerID)
|
||||
if err := metabase.RemoveContainer(metabaseContainerID); err != nil {
|
||||
log.Warnf("unable to remove container '%s': %s", metabaseContainerID, err)
|
||||
}
|
||||
if force {
|
||||
if err := metabase.RemoveImageContainer(); err != nil {
|
||||
if !strings.Contains(err.Error(), "No such image") {
|
||||
log.Fatalf("removing docker image: %s", err)
|
||||
}
|
||||
log.Infof("container %s stopped & removed", metabaseContainerID)
|
||||
}
|
||||
log.Debugf("Removing metabase db %s", csConfig.ConfigPaths.DataDir)
|
||||
if err := metabase.RemoveDatabase(csConfig.ConfigPaths.DataDir); err != nil {
|
||||
log.Warnf("failed to remove metabase internal db : %s", err)
|
||||
}
|
||||
if force {
|
||||
m := metabase.Metabase{}
|
||||
if err := m.LoadConfig(metabaseConfigPath); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := metabase.RemoveImageContainer(m.Config.Image); err != nil {
|
||||
if !strings.Contains(err.Error(), "No such image") {
|
||||
return fmt.Errorf("removing docker image: %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
cmdDashRemove.Flags().BoolVarP(&force, "force", "f", false, "Remove also the metabase image")
|
||||
|
@ -347,13 +316,95 @@ func passwordIsValid(password string) bool {
|
|||
|
||||
}
|
||||
|
||||
func checkSystemMemory() (bool, error) {
|
||||
func checkSystemMemory(forceYes *bool) error {
|
||||
totMem := memory.TotalMemory()
|
||||
if totMem == 0 {
|
||||
return true, errors.New("Unable to get system total memory")
|
||||
if totMem >= uint64(math.Pow(2, 30)) {
|
||||
return nil
|
||||
}
|
||||
if uint64(math.Pow(2, 30)) >= totMem {
|
||||
return false, nil
|
||||
if !*forceYes {
|
||||
var answer bool
|
||||
prompt := &survey.Confirm{
|
||||
Message: "Metabase requires 1-2GB of RAM, your system is below this requirement continue ?",
|
||||
Default: true,
|
||||
}
|
||||
if err := survey.AskOne(prompt, &answer); err != nil {
|
||||
return fmt.Errorf("unable to ask about RAM check: %s", err)
|
||||
}
|
||||
if !answer {
|
||||
return fmt.Errorf("user stated no to continue")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return true, nil
|
||||
log.Warn("Metabase requires 1-2GB of RAM, your system is below this requirement")
|
||||
return nil
|
||||
}
|
||||
|
||||
func warnIfNotLoopback(addr string) {
|
||||
if addr == "127.0.0.1" || addr == "::1" {
|
||||
return
|
||||
}
|
||||
log.Warnf("You are potentially exposing your metabase port to the internet (addr: %s), please consider using a reverse proxy", addr)
|
||||
}
|
||||
|
||||
func disclaimer(forceYes *bool) error {
|
||||
if !*forceYes {
|
||||
var answer bool
|
||||
prompt := &survey.Confirm{
|
||||
Message: "CrowdSec takes no responsibility for the security of your metabase instance. Do you accept these responsibilities ?",
|
||||
Default: true,
|
||||
}
|
||||
if err := survey.AskOne(prompt, &answer); err != nil {
|
||||
return fmt.Errorf("unable to ask to question: %s", err)
|
||||
}
|
||||
if !answer {
|
||||
return fmt.Errorf("user stated no to responsibilities")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
log.Warn("CrowdSec takes no responsibility for the security of your metabase instance. You used force yes, so you accept this disclaimer")
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkGroups(forceYes *bool) (*user.Group, error) {
|
||||
groupExist := false
|
||||
dockerGroup, err := user.LookupGroup(crowdsecGroup)
|
||||
if err == nil {
|
||||
groupExist = true
|
||||
}
|
||||
if !groupExist {
|
||||
if !*forceYes {
|
||||
var answer bool
|
||||
prompt := &survey.Confirm{
|
||||
Message: fmt.Sprintf("For metabase docker to be able to access SQLite file we need to add a new group called '%s' to the system, is it ok for you ?", crowdsecGroup),
|
||||
Default: true,
|
||||
}
|
||||
if err := survey.AskOne(prompt, &answer); err != nil {
|
||||
return dockerGroup, fmt.Errorf("unable to ask to question: %s", err)
|
||||
}
|
||||
if !answer {
|
||||
return dockerGroup, fmt.Errorf("unable to continue without creating '%s' group", crowdsecGroup)
|
||||
}
|
||||
}
|
||||
groupAddCmd, err := exec.LookPath("groupadd")
|
||||
if err != nil {
|
||||
return dockerGroup, fmt.Errorf("unable to find 'groupadd' command, can't continue")
|
||||
}
|
||||
|
||||
groupAdd := &exec.Cmd{Path: groupAddCmd, Args: []string{groupAddCmd, crowdsecGroup}}
|
||||
if err := groupAdd.Run(); err != nil {
|
||||
return dockerGroup, fmt.Errorf("unable to add group '%s': %s", dockerGroup, err)
|
||||
}
|
||||
dockerGroup, err = user.LookupGroup(crowdsecGroup)
|
||||
if err != nil {
|
||||
return dockerGroup, fmt.Errorf("unable to lookup '%s' group: %+v", dockerGroup, err)
|
||||
}
|
||||
}
|
||||
intID, err := strconv.Atoi(dockerGroup.Gid)
|
||||
if err != nil {
|
||||
return dockerGroup, fmt.Errorf("unable to convert group ID to int: %s", err)
|
||||
}
|
||||
if err := os.Chown(csConfig.DbConfig.DbPath, 0, intID); err != nil {
|
||||
return dockerGroup, fmt.Errorf("unable to chown sqlite db file '%s': %s", csConfig.DbConfig.DbPath, err)
|
||||
}
|
||||
return dockerGroup, nil
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ import (
|
|||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/version"
|
||||
"github.com/crowdsecurity/go-cs-lib/version"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/apiclient"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/models"
|
||||
|
|
|
@ -15,8 +15,8 @@ import (
|
|||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/ptr"
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/slicetools"
|
||||
"github.com/crowdsecurity/go-cs-lib/ptr"
|
||||
"github.com/crowdsecurity/go-cs-lib/slicetools"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/models"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/types"
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
"golang.org/x/exp/slices"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/version"
|
||||
"github.com/crowdsecurity/go-cs-lib/version"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/alertcontext"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/apiclient"
|
||||
|
@ -180,7 +180,7 @@ func NewLapiRegisterCmd() *cobra.Command {
|
|||
cmdLapiRegister := &cobra.Command{
|
||||
Use: "register",
|
||||
Short: "Register a machine to Local API (LAPI)",
|
||||
Long: `Register you machine to the Local API (LAPI).
|
||||
Long: `Register your machine to the Local API (LAPI).
|
||||
Keep in mind the machine needs to be validated by an administrator on LAPI side to be effective.`,
|
||||
Args: cobra.MinimumNArgs(0),
|
||||
DisableAutoGenTag: true,
|
||||
|
|
|
@ -26,6 +26,8 @@ import (
|
|||
"github.com/crowdsecurity/crowdsec/pkg/database"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/database/ent"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/types"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/require"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -144,20 +146,11 @@ func getAgents(out io.Writer, dbClient *database.Client) error {
|
|||
func NewMachinesListCmd() *cobra.Command {
|
||||
cmdMachinesList := &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List machines",
|
||||
Long: `List `,
|
||||
Short: "list all machines in the database",
|
||||
Long: `list all machines in the database with their status and last heartbeat`,
|
||||
Example: `cscli machines list`,
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
Args: cobra.NoArgs,
|
||||
DisableAutoGenTag: true,
|
||||
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
var err error
|
||||
dbClient, err = database.NewClient(csConfig.DbConfig)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create new database client: %s", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
err := getAgents(color.Output, dbClient)
|
||||
if err != nil {
|
||||
|
@ -174,7 +167,7 @@ func NewMachinesListCmd() *cobra.Command {
|
|||
func NewMachinesAddCmd() *cobra.Command {
|
||||
cmdMachinesAdd := &cobra.Command{
|
||||
Use: "add",
|
||||
Short: "add machine to the database.",
|
||||
Short: "add a single machine to the database",
|
||||
DisableAutoGenTag: true,
|
||||
Long: `Register a new machine in the database. cscli should be on the same machine as LAPI.`,
|
||||
Example: `
|
||||
|
@ -182,15 +175,6 @@ cscli machines add --auto
|
|||
cscli machines add MyTestMachine --auto
|
||||
cscli machines add MyTestMachine --password MyPassword
|
||||
`,
|
||||
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
var err error
|
||||
dbClient, err = database.NewClient(csConfig.DbConfig)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create new database client: %s", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
RunE: runMachinesAdd,
|
||||
}
|
||||
|
||||
|
@ -318,26 +302,12 @@ func runMachinesAdd(cmd *cobra.Command, args []string) error {
|
|||
func NewMachinesDeleteCmd() *cobra.Command {
|
||||
cmdMachinesDelete := &cobra.Command{
|
||||
Use: "delete [machine_name]...",
|
||||
Short: "delete machines",
|
||||
Short: "delete machine(s) by name",
|
||||
Example: `cscli machines delete "machine1" "machine2"`,
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
Aliases: []string{"remove"},
|
||||
DisableAutoGenTag: true,
|
||||
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
var err error
|
||||
dbClient, err = database.NewClient(csConfig.DbConfig)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create new database client: %s", err)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
var err error
|
||||
dbClient, err = getDBClient()
|
||||
if err != nil {
|
||||
cobra.CompError("unable to create new database client: " + err.Error())
|
||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
machines, err := dbClient.ListMachines()
|
||||
if err != nil {
|
||||
cobra.CompError("unable to list machines " + err.Error())
|
||||
|
@ -369,6 +339,86 @@ func runMachinesDelete(cmd *cobra.Command, args []string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func NewMachinesPruneCmd() *cobra.Command {
|
||||
var parsedDuration time.Duration
|
||||
cmdMachinesPrune := &cobra.Command{
|
||||
Use: "prune",
|
||||
Short: "prune multiple machines from the database",
|
||||
Long: `prune multiple machines that are not validated or have not connected to the local API in a given duration.`,
|
||||
Example: `cscli machines prune
|
||||
cscli machines prune --duration 1h
|
||||
cscli machines prune --not-validated-only --force`,
|
||||
Args: cobra.NoArgs,
|
||||
DisableAutoGenTag: true,
|
||||
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
dur, _ := cmd.Flags().GetString("duration")
|
||||
var err error
|
||||
parsedDuration, err = time.ParseDuration(fmt.Sprintf("-%s", dur))
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to parse duration '%s': %s", dur, err)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
notValidOnly, _ := cmd.Flags().GetBool("not-validated-only")
|
||||
force, _ := cmd.Flags().GetBool("force")
|
||||
if parsedDuration >= 0-60*time.Second && !notValidOnly {
|
||||
var answer bool
|
||||
prompt := &survey.Confirm{
|
||||
Message: "The duration you provided is less than or equal 60 seconds this can break installations do you want to continue ?",
|
||||
Default: false,
|
||||
}
|
||||
if err := survey.AskOne(prompt, &answer); err != nil {
|
||||
return fmt.Errorf("unable to ask about prune check: %s", err)
|
||||
}
|
||||
if !answer {
|
||||
fmt.Println("user aborted prune no changes were made")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
machines := make([]*ent.Machine, 0)
|
||||
if pending, err := dbClient.QueryPendingMachine(); err == nil {
|
||||
machines = append(machines, pending...)
|
||||
}
|
||||
if !notValidOnly {
|
||||
if pending, err := dbClient.QueryLastValidatedHeartbeatLT(time.Now().UTC().Add(parsedDuration)); err == nil {
|
||||
machines = append(machines, pending...)
|
||||
}
|
||||
}
|
||||
if len(machines) == 0 {
|
||||
fmt.Println("no machines to prune")
|
||||
return nil
|
||||
}
|
||||
getAgentsTable(color.Output, machines)
|
||||
if !force {
|
||||
var answer bool
|
||||
prompt := &survey.Confirm{
|
||||
Message: "You are about to PERMANENTLY remove the above machines from the database these will NOT be recoverable, continue ?",
|
||||
Default: false,
|
||||
}
|
||||
if err := survey.AskOne(prompt, &answer); err != nil {
|
||||
return fmt.Errorf("unable to ask about prune check: %s", err)
|
||||
}
|
||||
if !answer {
|
||||
fmt.Println("user aborted prune no changes were made")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
nbDeleted, err := dbClient.BulkDeleteWatchers(machines)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to prune machines: %s", err)
|
||||
}
|
||||
fmt.Printf("successfully delete %d machines\n", nbDeleted)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
cmdMachinesPrune.Flags().StringP("duration", "d", "10m", "duration of time since validated machine last heartbeat")
|
||||
cmdMachinesPrune.Flags().Bool("not-validated-only", false, "only prune machines that are not validated")
|
||||
cmdMachinesPrune.Flags().Bool("force", false, "force prune without asking for confirmation")
|
||||
|
||||
return cmdMachinesPrune
|
||||
}
|
||||
|
||||
func NewMachinesValidateCmd() *cobra.Command {
|
||||
cmdMachinesValidate := &cobra.Command{
|
||||
Use: "validate",
|
||||
|
@ -377,15 +427,6 @@ func NewMachinesValidateCmd() *cobra.Command {
|
|||
Example: `cscli machines validate "machine_name"`,
|
||||
Args: cobra.ExactArgs(1),
|
||||
DisableAutoGenTag: true,
|
||||
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
var err error
|
||||
dbClient, err = database.NewClient(csConfig.DbConfig)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create new database client: %s", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
machineID := args[0]
|
||||
if err := dbClient.ValidateMachine(machineID); err != nil {
|
||||
|
@ -404,20 +445,21 @@ func NewMachinesCmd() *cobra.Command {
|
|||
var cmdMachines = &cobra.Command{
|
||||
Use: "machines [action]",
|
||||
Short: "Manage local API machines [requires local API]",
|
||||
Long: `To list/add/delete/validate machines.
|
||||
Long: `To list/add/delete/validate/prune machines.
|
||||
Note: This command requires database direct access, so is intended to be run on the local API machine.
|
||||
`,
|
||||
Example: `cscli machines [action]`,
|
||||
DisableAutoGenTag: true,
|
||||
Aliases: []string{"machine"},
|
||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
if err := csConfig.LoadAPIServer(); err != nil || csConfig.DisableAPI {
|
||||
if err != nil {
|
||||
log.Errorf("local api : %s", err)
|
||||
}
|
||||
return fmt.Errorf("local API is disabled, please run this command on the local API machine")
|
||||
var err error
|
||||
if err := require.LAPI(csConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
dbClient, err = database.NewClient(csConfig.DbConfig)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create new database client: %s", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
@ -426,6 +468,7 @@ Note: This command requires database direct access, so is intended to be run on
|
|||
cmdMachines.AddCommand(NewMachinesAddCmd())
|
||||
cmdMachines.AddCommand(NewMachinesDeleteCmd())
|
||||
cmdMachines.AddCommand(NewMachinesValidateCmd())
|
||||
cmdMachines.AddCommand(NewMachinesPruneCmd())
|
||||
|
||||
return cmdMachines
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
|
@ -116,7 +115,7 @@ title: %s
|
|||
---
|
||||
`
|
||||
name := filepath.Base(filename)
|
||||
base := strings.TrimSuffix(name, path.Ext(name))
|
||||
base := strings.TrimSuffix(name, filepath.Ext(name))
|
||||
return fmt.Sprintf(header, base, strings.ReplaceAll(base, "_", " "))
|
||||
}
|
||||
|
||||
|
@ -199,13 +198,13 @@ It is meant to allow you to manage bans, parsers/scenarios/etc, api and generall
|
|||
rootCmd.AddCommand(cmdVersion)
|
||||
|
||||
rootCmd.PersistentFlags().StringVarP(&ConfigFilePath, "config", "c", csconfig.DefaultConfigPath("config.yaml"), "path to crowdsec config file")
|
||||
rootCmd.PersistentFlags().StringVarP(&OutputFormat, "output", "o", "", "Output format: human, json, raw.")
|
||||
rootCmd.PersistentFlags().StringVarP(&OutputColor, "color", "", "auto", "Output color: yes, no, auto.")
|
||||
rootCmd.PersistentFlags().BoolVar(&dbg_lvl, "debug", false, "Set logging to debug.")
|
||||
rootCmd.PersistentFlags().BoolVar(&nfo_lvl, "info", false, "Set logging to info.")
|
||||
rootCmd.PersistentFlags().BoolVar(&wrn_lvl, "warning", false, "Set logging to warning.")
|
||||
rootCmd.PersistentFlags().BoolVar(&err_lvl, "error", false, "Set logging to error.")
|
||||
rootCmd.PersistentFlags().BoolVar(&trace_lvl, "trace", false, "Set logging to trace.")
|
||||
rootCmd.PersistentFlags().StringVarP(&OutputFormat, "output", "o", "", "Output format: human, json, raw")
|
||||
rootCmd.PersistentFlags().StringVarP(&OutputColor, "color", "", "auto", "Output color: yes, no, auto")
|
||||
rootCmd.PersistentFlags().BoolVar(&dbg_lvl, "debug", false, "Set logging to debug")
|
||||
rootCmd.PersistentFlags().BoolVar(&nfo_lvl, "info", false, "Set logging to info")
|
||||
rootCmd.PersistentFlags().BoolVar(&wrn_lvl, "warning", false, "Set logging to warning")
|
||||
rootCmd.PersistentFlags().BoolVar(&err_lvl, "error", false, "Set logging to error")
|
||||
rootCmd.PersistentFlags().BoolVar(&trace_lvl, "trace", false, "Set logging to trace")
|
||||
|
||||
rootCmd.PersistentFlags().StringVar(&cwhub.HubBranch, "branch", "", "Override hub branch on github")
|
||||
if err := rootCmd.PersistentFlags().MarkHidden("branch"); err != nil {
|
||||
|
|
|
@ -14,9 +14,9 @@ import (
|
|||
"github.com/prometheus/prom2json"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"gopkg.in/yaml.v2"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/trace"
|
||||
"github.com/crowdsecurity/go-cs-lib/trace"
|
||||
)
|
||||
|
||||
// FormatPrometheusMetrics is a complete rip from prom2json
|
||||
|
@ -244,26 +244,39 @@ func FormatPrometheusMetrics(out io.Writer, url string, formatType string) error
|
|||
decisionStatsTable(out, decisions_stats)
|
||||
alertStatsTable(out, alerts_stats)
|
||||
stashStatsTable(out, stash_stats)
|
||||
} else if formatType == "json" {
|
||||
for _, val := range []interface{}{acquis_stats, parsers_stats, buckets_stats, lapi_stats, lapi_bouncer_stats, lapi_machine_stats, lapi_decisions_stats, decisions_stats, alerts_stats, stash_stats} {
|
||||
x, err := json.MarshalIndent(val, "", " ")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to unmarshal metrics : %v", err)
|
||||
}
|
||||
out.Write(x)
|
||||
}
|
||||
return nil
|
||||
|
||||
} else if formatType == "raw" {
|
||||
for _, val := range []interface{}{acquis_stats, parsers_stats, buckets_stats, lapi_stats, lapi_bouncer_stats, lapi_machine_stats, lapi_decisions_stats, decisions_stats, alerts_stats, stash_stats} {
|
||||
x, err := yaml.Marshal(val)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to unmarshal metrics : %v", err)
|
||||
}
|
||||
out.Write(x)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
stats := make(map[string]any)
|
||||
|
||||
stats["acquisition"] = acquis_stats
|
||||
stats["buckets"] = buckets_stats
|
||||
stats["parsers"] = parsers_stats
|
||||
stats["lapi"] = lapi_stats
|
||||
stats["lapi_machine"] = lapi_machine_stats
|
||||
stats["lapi_bouncer"] = lapi_bouncer_stats
|
||||
stats["lapi_decisions"] = lapi_decisions_stats
|
||||
stats["decisions"] = decisions_stats
|
||||
stats["alerts"] = alerts_stats
|
||||
stats["stash"] = stash_stats
|
||||
|
||||
switch formatType {
|
||||
case "json":
|
||||
x, err := json.MarshalIndent(stats, "", " ")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to unmarshal metrics : %v", err)
|
||||
}
|
||||
out.Write(x)
|
||||
case "raw":
|
||||
x, err := yaml.Marshal(stats)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to unmarshal metrics : %v", err)
|
||||
}
|
||||
out.Write(x)
|
||||
default:
|
||||
return fmt.Errorf("unknown format type %s", formatType)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -199,7 +199,7 @@ func lapiStatsTable(out io.Writer, stats map[string]map[string]int) {
|
|||
}
|
||||
|
||||
if numRows > 0 {
|
||||
renderTableTitle(out, "\nLocal Api Metrics:")
|
||||
renderTableTitle(out, "\nLocal API Metrics:")
|
||||
t.Render()
|
||||
}
|
||||
}
|
||||
|
@ -213,7 +213,7 @@ func lapiMachineStatsTable(out io.Writer, stats map[string]map[string]map[string
|
|||
numRows := lapiMetricsToTable(t, stats)
|
||||
|
||||
if numRows > 0 {
|
||||
renderTableTitle(out, "\nLocal Api Machines Metrics:")
|
||||
renderTableTitle(out, "\nLocal API Machines Metrics:")
|
||||
t.Render()
|
||||
}
|
||||
}
|
||||
|
@ -227,7 +227,7 @@ func lapiBouncerStatsTable(out io.Writer, stats map[string]map[string]map[string
|
|||
numRows := lapiMetricsToTable(t, stats)
|
||||
|
||||
if numRows > 0 {
|
||||
renderTableTitle(out, "\nLocal Api Bouncers Metrics:")
|
||||
renderTableTitle(out, "\nLocal API Bouncers Metrics:")
|
||||
t.Render()
|
||||
}
|
||||
}
|
||||
|
@ -253,7 +253,7 @@ func lapiDecisionStatsTable(out io.Writer, stats map[string]struct {
|
|||
}
|
||||
|
||||
if numRows > 0 {
|
||||
renderTableTitle(out, "\nLocal Api Bouncers Decisions:")
|
||||
renderTableTitle(out, "\nLocal API Bouncers Decisions:")
|
||||
t.Render()
|
||||
}
|
||||
}
|
||||
|
@ -280,7 +280,7 @@ func decisionStatsTable(out io.Writer, stats map[string]map[string]map[string]in
|
|||
}
|
||||
|
||||
if numRows > 0 {
|
||||
renderTableTitle(out, "\nLocal Api Decisions:")
|
||||
renderTableTitle(out, "\nLocal API Decisions:")
|
||||
t.Render()
|
||||
}
|
||||
}
|
||||
|
@ -301,7 +301,7 @@ func alertStatsTable(out io.Writer, stats map[string]int) {
|
|||
}
|
||||
|
||||
if numRows > 0 {
|
||||
renderTableTitle(out, "\nLocal Api Alerts:")
|
||||
renderTableTitle(out, "\nLocal API Alerts:")
|
||||
t.Render()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,12 +19,14 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
"gopkg.in/tomb.v2"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/version"
|
||||
"github.com/crowdsecurity/go-cs-lib/version"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/apiclient"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/csconfig"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/csplugin"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/csprofiles"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/require"
|
||||
)
|
||||
|
||||
type NotificationsCfg struct {
|
||||
|
@ -41,16 +43,18 @@ func NewNotificationsCmd() *cobra.Command {
|
|||
Args: cobra.MinimumNArgs(1),
|
||||
Aliases: []string{"notifications", "notification"},
|
||||
DisableAutoGenTag: true,
|
||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||
var (
|
||||
err error
|
||||
)
|
||||
if err = csConfig.API.Server.LoadProfiles(); err != nil {
|
||||
log.Fatal(err)
|
||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
if err := require.LAPI(csConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
if csConfig.ConfigPaths.NotificationDir == "" {
|
||||
log.Fatalf("config_paths.notification_dir is not set in crowdsec config")
|
||||
if err := require.Profiles(csConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := require.Notifications(csConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"gopkg.in/tomb.v2"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/ptr"
|
||||
"github.com/crowdsecurity/go-cs-lib/ptr"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/apiserver"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/database"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/require"
|
||||
)
|
||||
|
||||
func NewPapiCmd() *cobra.Command {
|
||||
|
@ -21,14 +22,14 @@ func NewPapiCmd() *cobra.Command {
|
|||
Args: cobra.MinimumNArgs(1),
|
||||
DisableAutoGenTag: true,
|
||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
if err := csConfig.LoadAPIServer(); err != nil || csConfig.DisableAPI {
|
||||
return fmt.Errorf("Local API is disabled, please run this command on the local API machine: %w", err)
|
||||
if err := require.LAPI(csConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
if csConfig.API.Server.OnlineClient == nil {
|
||||
log.Fatalf("no configuration for Central API in '%s'", *csConfig.FilePath)
|
||||
if err := require.CAPI(csConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
if csConfig.API.Server.OnlineClient.Credentials.PapiURL == "" {
|
||||
log.Fatalf("no PAPI URL in configuration")
|
||||
if err := require.PAPI(csConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
|
|
65
cmd/crowdsec-cli/require/require.go
Normal file
65
cmd/crowdsec-cli/require/require.go
Normal file
|
@ -0,0 +1,65 @@
|
|||
package require
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/csconfig"
|
||||
)
|
||||
|
||||
func LAPI(c *csconfig.Config) error {
|
||||
if err := c.LoadAPIServer(); err != nil {
|
||||
return fmt.Errorf("failed to load Local API: %w", err)
|
||||
}
|
||||
|
||||
if c.DisableAPI {
|
||||
return fmt.Errorf("local API is disabled -- this command must be run on the local API machine")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func CAPI(c *csconfig.Config) error {
|
||||
if c.API.Server.OnlineClient == nil {
|
||||
return fmt.Errorf("no configuration for Central API (CAPI) in '%s'", *c.FilePath)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func PAPI(c *csconfig.Config) error {
|
||||
if c.API.Server.OnlineClient.Credentials.PapiURL == "" {
|
||||
return fmt.Errorf("no PAPI URL in configuration")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Enrolled(c *csconfig.Config) error {
|
||||
if c.API.Server.OnlineClient.Credentials == nil {
|
||||
return fmt.Errorf("the Central API (CAPI) must be configured with 'cscli capi register'")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func DB(c *csconfig.Config) error {
|
||||
if err := c.LoadDBConfig(); err != nil {
|
||||
return fmt.Errorf("this command requires direct database access (must be run on the local API machine): %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Profiles(c *csconfig.Config) error {
|
||||
if err := c.API.Server.LoadProfiles(); err != nil {
|
||||
return fmt.Errorf("while loading profiles: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Notifications(c *csconfig.Config) error {
|
||||
if c.ConfigPaths.NotificationDir == "" {
|
||||
return fmt.Errorf("config_paths.notification_dir is not set in crowdsec config")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ import (
|
|||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/version"
|
||||
"github.com/crowdsecurity/go-cs-lib/version"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/apiclient"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
|
||||
|
|
|
@ -18,11 +18,11 @@ import (
|
|||
"github.com/prometheus/prom2json"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/texttheater/golang-levenshtein/levenshtein"
|
||||
"github.com/agext/levenshtein"
|
||||
"golang.org/x/exp/slices"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/trace"
|
||||
"github.com/crowdsecurity/go-cs-lib/trace"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/database"
|
||||
|
@ -90,7 +90,7 @@ func GetDistance(itemType string, itemName string) (*cwhub.Item, int) {
|
|||
}
|
||||
|
||||
for _, s := range allItems {
|
||||
d := levenshtein.DistanceForStrings([]rune(itemName), []rune(s), levenshtein.DefaultOptions)
|
||||
d := levenshtein.Distance(itemName, s, nil)
|
||||
if d < nearestScore {
|
||||
nearestScore = d
|
||||
nearestItem = cwhub.GetItem(itemType, s)
|
||||
|
|
|
@ -5,9 +5,9 @@ ifeq ($(OS), Windows_NT)
|
|||
endif
|
||||
|
||||
# Go parameters
|
||||
GOCMD = go
|
||||
GOBUILD = $(GOCMD) build
|
||||
GOTEST = $(GOCMD) test
|
||||
GO = go
|
||||
GOBUILD = $(GO) build
|
||||
GOTEST = $(GO) test
|
||||
|
||||
CROWDSEC_BIN = crowdsec$(EXT)
|
||||
# names longer than 15 chars break 'pgrep'
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"github.com/pkg/errors"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/trace"
|
||||
"github.com/crowdsecurity/go-cs-lib/trace"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/apiserver"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/csconfig"
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
log "github.com/sirupsen/logrus"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/trace"
|
||||
"github.com/crowdsecurity/go-cs-lib/trace"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/acquisition"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/csconfig"
|
||||
|
|
|
@ -70,6 +70,7 @@ type Flags struct {
|
|||
WinSvc string
|
||||
DisableCAPI bool
|
||||
Transform string
|
||||
OrderEvent bool
|
||||
}
|
||||
|
||||
type labelsMap map[string]string
|
||||
|
@ -87,7 +88,7 @@ func LoadBuckets(cConfig *csconfig.Config) error {
|
|||
buckets = leakybucket.NewBuckets()
|
||||
|
||||
log.Infof("Loading %d scenario files", len(files))
|
||||
holders, outputEventChan, err = leakybucket.LoadBuckets(cConfig.Crowdsec, files, &bucketsTomb, buckets)
|
||||
holders, outputEventChan, err = leakybucket.LoadBuckets(cConfig.Crowdsec, files, &bucketsTomb, buckets, flags.OrderEvent)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("scenario loading failed: %v", err)
|
||||
|
@ -110,7 +111,7 @@ func LoadAcquisition(cConfig *csconfig.Config) error {
|
|||
|
||||
dataSources, err = acquisition.LoadAcquisitionFromDSN(flags.OneShotDSN, flags.Labels, flags.Transform)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to configure datasource for %s: %w", flags.OneShotDSN, err)
|
||||
return errors.Wrapf(err, "failed to configure datasource for %s", flags.OneShotDSN)
|
||||
}
|
||||
} else {
|
||||
dataSources, err = acquisition.LoadAcquisitionFromFile(cConfig.Crowdsec)
|
||||
|
@ -164,6 +165,7 @@ func (f *Flags) Parse() {
|
|||
flag.BoolVar(&f.DisableAgent, "no-cs", false, "disable crowdsec agent")
|
||||
flag.BoolVar(&f.DisableAPI, "no-api", false, "disable local API")
|
||||
flag.BoolVar(&f.DisableCAPI, "no-capi", false, "disable communication with Central API")
|
||||
flag.BoolVar(&f.OrderEvent, "order-event", false, "enforce event ordering with significant performance cost")
|
||||
if runtime.GOOS == "windows" {
|
||||
flag.StringVar(&f.WinSvc, "winsvc", "", "Windows service Action: Install, Remove etc..")
|
||||
}
|
||||
|
@ -247,13 +249,13 @@ func LoadConfig(configFile string, disableAgent bool, disableAPI bool, quiet boo
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if !flags.DisableAgent {
|
||||
if !cConfig.DisableAgent {
|
||||
if err := cConfig.LoadCrowdsec(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if !flags.DisableAPI {
|
||||
if !cConfig.DisableAPI {
|
||||
if err := cConfig.LoadAPIServer(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -288,7 +290,7 @@ func LoadConfig(configFile string, disableAgent bool, disableAPI bool, quiet boo
|
|||
cConfig.API.Server.OnlineClient = nil
|
||||
}
|
||||
/*if the api is disabled as well, just read file and exit, don't daemonize*/
|
||||
if flags.DisableAPI {
|
||||
if cConfig.DisableAPI {
|
||||
cConfig.Common.Daemonize = false
|
||||
}
|
||||
log.Infof("single file mode : log_media=%s daemonize=%t", cConfig.Common.LogMedia, cConfig.Common.Daemonize)
|
||||
|
@ -322,7 +324,7 @@ func main() {
|
|||
}
|
||||
|
||||
// some features can require configuration or command-line options,
|
||||
// so wwe need to parse them asap. we'll load from feature.yaml later.
|
||||
// so we need to parse them asap. we'll load from feature.yaml later.
|
||||
if err := csconfig.LoadFeatureFlagsEnv(log.StandardLogger()); err != nil {
|
||||
log.Fatalf("failed to set feature flags from environment: %s", err)
|
||||
}
|
||||
|
|
|
@ -9,8 +9,8 @@ import (
|
|||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/trace"
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/version"
|
||||
"github.com/crowdsecurity/go-cs-lib/trace"
|
||||
"github.com/crowdsecurity/go-cs-lib/version"
|
||||
|
||||
waf "github.com/crowdsecurity/crowdsec/pkg/acquisition/modules/waf"
|
||||
v1 "github.com/crowdsecurity/crowdsec/pkg/apiserver/controllers/v1"
|
||||
|
|
|
@ -8,10 +8,9 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/pkg/errors"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/version"
|
||||
"github.com/crowdsecurity/go-cs-lib/version"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/apiclient"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/csconfig"
|
||||
|
@ -73,16 +72,16 @@ func runOutput(input chan types.Event, overflow chan types.Event, buckets *leaky
|
|||
|
||||
scenarios, err := cwhub.GetInstalledScenariosAsString()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "loading list of installed hub scenarios: %s", err)
|
||||
return fmt.Errorf("loading list of installed hub scenarios: %w", err)
|
||||
}
|
||||
|
||||
apiURL, err := url.Parse(apiConfig.URL)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "parsing api url ('%s'): %s", apiConfig.URL, err)
|
||||
return fmt.Errorf("parsing api url ('%s'): %w", apiConfig.URL, err)
|
||||
}
|
||||
papiURL, err := url.Parse(apiConfig.PapiURL)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "parsing polling api url ('%s'): %s", apiConfig.PapiURL, err)
|
||||
return fmt.Errorf("parsing polling api url ('%s'): %w", apiConfig.PapiURL, err)
|
||||
}
|
||||
password := strfmt.Password(apiConfig.Password)
|
||||
|
||||
|
@ -97,7 +96,7 @@ func runOutput(input chan types.Event, overflow chan types.Event, buckets *leaky
|
|||
UpdateScenario: cwhub.GetInstalledScenariosAsString,
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "new client api: %s", err)
|
||||
return fmt.Errorf("new client api: %w", err)
|
||||
}
|
||||
authResp, _, err := Client.Auth.AuthenticateWatcher(context.Background(), models.WatcherAuthRequest{
|
||||
MachineID: &apiConfig.Login,
|
||||
|
|
|
@ -10,8 +10,8 @@ import (
|
|||
log "github.com/sirupsen/logrus"
|
||||
"github.com/sirupsen/logrus/hooks/writer"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/trace"
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/version"
|
||||
"github.com/crowdsecurity/go-cs-lib/trace"
|
||||
"github.com/crowdsecurity/go-cs-lib/version"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/csconfig"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/database"
|
||||
|
|
|
@ -6,8 +6,8 @@ import (
|
|||
log "github.com/sirupsen/logrus"
|
||||
"golang.org/x/sys/windows/svc"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/trace"
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/version"
|
||||
"github.com/crowdsecurity/go-cs-lib/trace"
|
||||
"github.com/crowdsecurity/go-cs-lib/version"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/csconfig"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/database"
|
||||
|
|
|
@ -10,8 +10,8 @@ import (
|
|||
log "github.com/sirupsen/logrus"
|
||||
"gopkg.in/tomb.v2"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/csdaemon"
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/trace"
|
||||
"github.com/crowdsecurity/go-cs-lib/csdaemon"
|
||||
"github.com/crowdsecurity/go-cs-lib/trace"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/csconfig"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/database"
|
||||
|
@ -344,7 +344,7 @@ func Serve(cConfig *csconfig.Config, apiReady chan bool, agentReady chan bool) e
|
|||
}
|
||||
|
||||
if flags.TestMode {
|
||||
log.Infof("test done")
|
||||
log.Infof("Configuration test done")
|
||||
pluginBroker.Kill()
|
||||
os.Exit(0)
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ After=syslog.target network.target remote-fs.target nss-lookup.target
|
|||
[Service]
|
||||
Type=notify
|
||||
Environment=LC_ALL=C LANG=C
|
||||
ExecStartPre=/usr/local/bin/crowdsec -c /etc/crowdsec/config.yaml -t
|
||||
ExecStartPre=/usr/local/bin/crowdsec -c /etc/crowdsec/config.yaml -t -error
|
||||
ExecStart=/usr/local/bin/crowdsec -c /etc/crowdsec/config.yaml
|
||||
#ExecStartPost=/bin/sleep 0.1
|
||||
ExecReload=/bin/kill -HUP $MAINPID
|
||||
|
|
1
debian/install
vendored
1
debian/install
vendored
|
@ -10,3 +10,4 @@ plugins/notifications/slack/slack.yaml etc/crowdsec/notifications/
|
|||
plugins/notifications/http/http.yaml etc/crowdsec/notifications/
|
||||
plugins/notifications/splunk/splunk.yaml etc/crowdsec/notifications/
|
||||
plugins/notifications/email/email.yaml etc/crowdsec/notifications/
|
||||
plugins/notifications/sentinel/sentinel.yaml etc/crowdsec/notifications/
|
||||
|
|
1
debian/rules
vendored
1
debian/rules
vendored
|
@ -29,6 +29,7 @@ override_dh_auto_install:
|
|||
install -m 551 plugins/notifications/http/notification-http debian/crowdsec/usr/lib/crowdsec/plugins/
|
||||
install -m 551 plugins/notifications/splunk/notification-splunk debian/crowdsec/usr/lib/crowdsec/plugins/
|
||||
install -m 551 plugins/notifications/email/notification-email debian/crowdsec/usr/lib/crowdsec/plugins/
|
||||
install -m 551 plugins/notifications/sentinel/notification-sentinel debian/crowdsec/usr/lib/crowdsec/plugins/
|
||||
|
||||
cp cmd/crowdsec/crowdsec debian/crowdsec/usr/bin
|
||||
cp cmd/crowdsec-cli/cscli debian/crowdsec/usr/bin
|
||||
|
|
|
@ -243,7 +243,7 @@ if istrue "$DISABLE_ONLINE_API"; then
|
|||
fi
|
||||
|
||||
# registration to online API for signal push
|
||||
if isfalse "$DISABLE_ONLINE_API" ; then
|
||||
if isfalse "$DISABLE_LOCAL_API" && isfalse "$DISABLE_ONLINE_API" ; then
|
||||
CONFIG_DIR=$(conf_get '.config_paths.config_dir')
|
||||
export CONFIG_DIR
|
||||
config_exists=$(conf_get '.api.server.online_client | has("credentials_path")')
|
||||
|
@ -255,7 +255,7 @@ if isfalse "$DISABLE_ONLINE_API" ; then
|
|||
fi
|
||||
|
||||
# Enroll instance if enroll key is provided
|
||||
if isfalse "$DISABLE_ONLINE_API" && [ "$ENROLL_KEY" != "" ]; then
|
||||
if isfalse "$DISABLE_LOCAL_API" && isfalse "$DISABLE_ONLINE_API" && [ "$ENROLL_KEY" != "" ]; then
|
||||
enroll_args=""
|
||||
if [ "$ENROLL_INSTANCE_NAME" != "" ]; then
|
||||
enroll_args="--name $ENROLL_INSTANCE_NAME"
|
||||
|
@ -273,13 +273,14 @@ fi
|
|||
# crowdsec sqlite database permissions
|
||||
if [ "$GID" != "" ]; then
|
||||
if istrue "$(conf_get '.db_config.type == "sqlite"')"; then
|
||||
chown ":$GID" "$(conf_get '.db_config.db_path')"
|
||||
echo "sqlite database permissions updated"
|
||||
# don't fail if the db is not there yet
|
||||
chown -f ":$GID" "$(conf_get '.db_config.db_path')" 2>/dev/null \
|
||||
&& echo "sqlite database permissions updated" \
|
||||
|| true
|
||||
fi
|
||||
fi
|
||||
|
||||
# XXX only with LAPI
|
||||
if istrue "$USE_TLS"; then
|
||||
if isfalse "$DISABLE_LOCAL_API" && istrue "$USE_TLS"; then
|
||||
agents_allowed_yaml=$(csv2yaml "$AGENTS_ALLOWED_OU")
|
||||
export agents_allowed_yaml
|
||||
bouncers_allowed_yaml=$(csv2yaml "$BOUNCERS_ALLOWED_OU")
|
||||
|
@ -358,7 +359,7 @@ shopt -s nullglob extglob
|
|||
for BOUNCER in /run/secrets/@(bouncer_key|BOUNCER_KEY)* ; do
|
||||
KEY=$(cat "${BOUNCER}")
|
||||
NAME=$(echo "${BOUNCER}" | awk -F "/" '{printf $NF}' | cut -d_ -f2-)
|
||||
if [[ -n $KEY ]] && [[ -n $NAME ]]; then
|
||||
if [[ -n $KEY ]] && [[ -n $NAME ]]; then
|
||||
register_bouncer "$NAME" "$KEY"
|
||||
fi
|
||||
done
|
||||
|
@ -369,6 +370,12 @@ shopt -u nullglob extglob
|
|||
conf_set_if "$CAPI_WHITELISTS_PATH" '.api.server.capi_whitelists_path = strenv(CAPI_WHITELISTS_PATH)'
|
||||
conf_set_if "$METRICS_PORT" '.prometheus.listen_port=env(METRICS_PORT)'
|
||||
|
||||
if istrue "$DISABLE_LOCAL_API"; then
|
||||
conf_set '.api.server.enable=false'
|
||||
else
|
||||
conf_set '.api.server.enable=true'
|
||||
fi
|
||||
|
||||
ARGS=""
|
||||
if [ "$CONFIG_FILE" != "" ]; then
|
||||
ARGS="-c $CONFIG_FILE"
|
||||
|
@ -390,10 +397,6 @@ if istrue "$DISABLE_AGENT"; then
|
|||
ARGS="$ARGS -no-cs"
|
||||
fi
|
||||
|
||||
if istrue "$DISABLE_LOCAL_API"; then
|
||||
ARGS="$ARGS -no-api"
|
||||
fi
|
||||
|
||||
if istrue "$LEVEL_TRACE"; then
|
||||
ARGS="$ARGS -trace"
|
||||
fi
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
[packages]
|
||||
pytest-dotenv = "*"
|
||||
pytest-xdist = "*"
|
||||
pytest-dotenv = "0.5.2"
|
||||
pytest-xdist = "3.3.1"
|
||||
pytest-cs = {ref = "0.7.16", git = "https://github.com/crowdsecurity/pytest-cs.git"}
|
||||
|
||||
[dev-packages]
|
||||
gnureadline = "*"
|
||||
ipdb = "*"
|
||||
gnureadline = "8.1.2"
|
||||
ipdb = "0.13.13"
|
||||
|
||||
[requires]
|
||||
python_version = "*"
|
||||
|
|
348
docker/test/Pipfile.lock
generated
348
docker/test/Pipfile.lock
generated
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "7e91f125d4ad0d1f1b5da7ef441d75baf4f28788c791803a216cb6956b131ea9"
|
||||
"sha256": "78f693678e411b7bdb5dd0280b7d6f8d9880069b331d44d96d32ba697275e30d"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
|
@ -18,11 +18,11 @@
|
|||
"default": {
|
||||
"certifi": {
|
||||
"hashes": [
|
||||
"sha256:0f0d56dc5a6ad56fd4ba36484d6cc34451e1c6548c61daad8c320169f91eddc7",
|
||||
"sha256:c6c2e98f5c7869efca1f8916fed228dd91539f9f1b444c314c06eef02980c716"
|
||||
"sha256:539cc1d13202e33ca466e88b2807e29f4c13049d6d87031a3c110744495cb082",
|
||||
"sha256:92d6037539857d8206b8f6ae472e8b77db8058fec5937a1ef3f54304089edbb9"
|
||||
],
|
||||
"markers": "python_version >= '3.6'",
|
||||
"version": "==2023.5.7"
|
||||
"version": "==2023.7.22"
|
||||
},
|
||||
"cffi": {
|
||||
"hashes": [
|
||||
|
@ -95,125 +95,129 @@
|
|||
},
|
||||
"charset-normalizer": {
|
||||
"hashes": [
|
||||
"sha256:04afa6387e2b282cf78ff3dbce20f0cc071c12dc8f685bd40960cc68644cfea6",
|
||||
"sha256:04eefcee095f58eaabe6dc3cc2262f3bcd776d2c67005880894f447b3f2cb9c1",
|
||||
"sha256:0be65ccf618c1e7ac9b849c315cc2e8a8751d9cfdaa43027d4f6624bd587ab7e",
|
||||
"sha256:0c95f12b74681e9ae127728f7e5409cbbef9cd914d5896ef238cc779b8152373",
|
||||
"sha256:0ca564606d2caafb0abe6d1b5311c2649e8071eb241b2d64e75a0d0065107e62",
|
||||
"sha256:10c93628d7497c81686e8e5e557aafa78f230cd9e77dd0c40032ef90c18f2230",
|
||||
"sha256:11d117e6c63e8f495412d37e7dc2e2fff09c34b2d09dbe2bee3c6229577818be",
|
||||
"sha256:11d3bcb7be35e7b1bba2c23beedac81ee893ac9871d0ba79effc7fc01167db6c",
|
||||
"sha256:12a2b561af122e3d94cdb97fe6fb2bb2b82cef0cdca131646fdb940a1eda04f0",
|
||||
"sha256:12d1a39aa6b8c6f6248bb54550efcc1c38ce0d8096a146638fd4738e42284448",
|
||||
"sha256:1435ae15108b1cb6fffbcea2af3d468683b7afed0169ad718451f8db5d1aff6f",
|
||||
"sha256:1c60b9c202d00052183c9be85e5eaf18a4ada0a47d188a83c8f5c5b23252f649",
|
||||
"sha256:1e8fcdd8f672a1c4fc8d0bd3a2b576b152d2a349782d1eb0f6b8e52e9954731d",
|
||||
"sha256:20064ead0717cf9a73a6d1e779b23d149b53daf971169289ed2ed43a71e8d3b0",
|
||||
"sha256:21fa558996782fc226b529fdd2ed7866c2c6ec91cee82735c98a197fae39f706",
|
||||
"sha256:22908891a380d50738e1f978667536f6c6b526a2064156203d418f4856d6e86a",
|
||||
"sha256:3160a0fd9754aab7d47f95a6b63ab355388d890163eb03b2d2b87ab0a30cfa59",
|
||||
"sha256:322102cdf1ab682ecc7d9b1c5eed4ec59657a65e1c146a0da342b78f4112db23",
|
||||
"sha256:34e0a2f9c370eb95597aae63bf85eb5e96826d81e3dcf88b8886012906f509b5",
|
||||
"sha256:3573d376454d956553c356df45bb824262c397c6e26ce43e8203c4c540ee0acb",
|
||||
"sha256:3747443b6a904001473370d7810aa19c3a180ccd52a7157aacc264a5ac79265e",
|
||||
"sha256:38e812a197bf8e71a59fe55b757a84c1f946d0ac114acafaafaf21667a7e169e",
|
||||
"sha256:3a06f32c9634a8705f4ca9946d667609f52cf130d5548881401f1eb2c39b1e2c",
|
||||
"sha256:3a5fc78f9e3f501a1614a98f7c54d3969f3ad9bba8ba3d9b438c3bc5d047dd28",
|
||||
"sha256:3d9098b479e78c85080c98e1e35ff40b4a31d8953102bb0fd7d1b6f8a2111a3d",
|
||||
"sha256:3dc5b6a8ecfdc5748a7e429782598e4f17ef378e3e272eeb1340ea57c9109f41",
|
||||
"sha256:4155b51ae05ed47199dc5b2a4e62abccb274cee6b01da5b895099b61b1982974",
|
||||
"sha256:49919f8400b5e49e961f320c735388ee686a62327e773fa5b3ce6721f7e785ce",
|
||||
"sha256:53d0a3fa5f8af98a1e261de6a3943ca631c526635eb5817a87a59d9a57ebf48f",
|
||||
"sha256:5f008525e02908b20e04707a4f704cd286d94718f48bb33edddc7d7b584dddc1",
|
||||
"sha256:628c985afb2c7d27a4800bfb609e03985aaecb42f955049957814e0491d4006d",
|
||||
"sha256:65ed923f84a6844de5fd29726b888e58c62820e0769b76565480e1fdc3d062f8",
|
||||
"sha256:6734e606355834f13445b6adc38b53c0fd45f1a56a9ba06c2058f86893ae8017",
|
||||
"sha256:6baf0baf0d5d265fa7944feb9f7451cc316bfe30e8df1a61b1bb08577c554f31",
|
||||
"sha256:6f4f4668e1831850ebcc2fd0b1cd11721947b6dc7c00bf1c6bd3c929ae14f2c7",
|
||||
"sha256:6f5c2e7bc8a4bf7c426599765b1bd33217ec84023033672c1e9a8b35eaeaaaf8",
|
||||
"sha256:6f6c7a8a57e9405cad7485f4c9d3172ae486cfef1344b5ddd8e5239582d7355e",
|
||||
"sha256:7381c66e0561c5757ffe616af869b916c8b4e42b367ab29fedc98481d1e74e14",
|
||||
"sha256:73dc03a6a7e30b7edc5b01b601e53e7fc924b04e1835e8e407c12c037e81adbd",
|
||||
"sha256:74db0052d985cf37fa111828d0dd230776ac99c740e1a758ad99094be4f1803d",
|
||||
"sha256:75f2568b4189dda1c567339b48cba4ac7384accb9c2a7ed655cd86b04055c795",
|
||||
"sha256:78cacd03e79d009d95635e7d6ff12c21eb89b894c354bd2b2ed0b4763373693b",
|
||||
"sha256:80d1543d58bd3d6c271b66abf454d437a438dff01c3e62fdbcd68f2a11310d4b",
|
||||
"sha256:830d2948a5ec37c386d3170c483063798d7879037492540f10a475e3fd6f244b",
|
||||
"sha256:891cf9b48776b5c61c700b55a598621fdb7b1e301a550365571e9624f270c203",
|
||||
"sha256:8f25e17ab3039b05f762b0a55ae0b3632b2e073d9c8fc88e89aca31a6198e88f",
|
||||
"sha256:9a3267620866c9d17b959a84dd0bd2d45719b817245e49371ead79ed4f710d19",
|
||||
"sha256:a04f86f41a8916fe45ac5024ec477f41f886b3c435da2d4e3d2709b22ab02af1",
|
||||
"sha256:aaf53a6cebad0eae578f062c7d462155eada9c172bd8c4d250b8c1d8eb7f916a",
|
||||
"sha256:abc1185d79f47c0a7aaf7e2412a0eb2c03b724581139193d2d82b3ad8cbb00ac",
|
||||
"sha256:ac0aa6cd53ab9a31d397f8303f92c42f534693528fafbdb997c82bae6e477ad9",
|
||||
"sha256:ac3775e3311661d4adace3697a52ac0bab17edd166087d493b52d4f4f553f9f0",
|
||||
"sha256:b06f0d3bf045158d2fb8837c5785fe9ff9b8c93358be64461a1089f5da983137",
|
||||
"sha256:b116502087ce8a6b7a5f1814568ccbd0e9f6cfd99948aa59b0e241dc57cf739f",
|
||||
"sha256:b82fab78e0b1329e183a65260581de4375f619167478dddab510c6c6fb04d9b6",
|
||||
"sha256:bd7163182133c0c7701b25e604cf1611c0d87712e56e88e7ee5d72deab3e76b5",
|
||||
"sha256:c36bcbc0d5174a80d6cccf43a0ecaca44e81d25be4b7f90f0ed7bcfbb5a00909",
|
||||
"sha256:c3af8e0f07399d3176b179f2e2634c3ce9c1301379a6b8c9c9aeecd481da494f",
|
||||
"sha256:c84132a54c750fda57729d1e2599bb598f5fa0344085dbde5003ba429a4798c0",
|
||||
"sha256:cb7b2ab0188829593b9de646545175547a70d9a6e2b63bf2cd87a0a391599324",
|
||||
"sha256:cca4def576f47a09a943666b8f829606bcb17e2bc2d5911a46c8f8da45f56755",
|
||||
"sha256:cf6511efa4801b9b38dc5546d7547d5b5c6ef4b081c60b23e4d941d0eba9cbeb",
|
||||
"sha256:d16fd5252f883eb074ca55cb622bc0bee49b979ae4e8639fff6ca3ff44f9f854",
|
||||
"sha256:d2686f91611f9e17f4548dbf050e75b079bbc2a82be565832bc8ea9047b61c8c",
|
||||
"sha256:d7fc3fca01da18fbabe4625d64bb612b533533ed10045a2ac3dd194bfa656b60",
|
||||
"sha256:dd5653e67b149503c68c4018bf07e42eeed6b4e956b24c00ccdf93ac79cdff84",
|
||||
"sha256:de5695a6f1d8340b12a5d6d4484290ee74d61e467c39ff03b39e30df62cf83a0",
|
||||
"sha256:e0ac8959c929593fee38da1c2b64ee9778733cdf03c482c9ff1d508b6b593b2b",
|
||||
"sha256:e1b25e3ad6c909f398df8921780d6a3d120d8c09466720226fc621605b6f92b1",
|
||||
"sha256:e633940f28c1e913615fd624fcdd72fdba807bf53ea6925d6a588e84e1151531",
|
||||
"sha256:e89df2958e5159b811af9ff0f92614dabf4ff617c03a4c1c6ff53bf1c399e0e1",
|
||||
"sha256:ea9f9c6034ea2d93d9147818f17c2a0860d41b71c38b9ce4d55f21b6f9165a11",
|
||||
"sha256:f645caaf0008bacf349875a974220f1f1da349c5dbe7c4ec93048cdc785a3326",
|
||||
"sha256:f8303414c7b03f794347ad062c0516cee0e15f7a612abd0ce1e25caf6ceb47df",
|
||||
"sha256:fca62a8301b605b954ad2e9c3666f9d97f63872aa4efcae5492baca2056b74ab"
|
||||
"sha256:04e57ab9fbf9607b77f7d057974694b4f6b142da9ed4a199859d9d4d5c63fe96",
|
||||
"sha256:09393e1b2a9461950b1c9a45d5fd251dc7c6f228acab64da1c9c0165d9c7765c",
|
||||
"sha256:0b87549028f680ca955556e3bd57013ab47474c3124dc069faa0b6545b6c9710",
|
||||
"sha256:1000fba1057b92a65daec275aec30586c3de2401ccdcd41f8a5c1e2c87078706",
|
||||
"sha256:1249cbbf3d3b04902ff081ffbb33ce3377fa6e4c7356f759f3cd076cc138d020",
|
||||
"sha256:1920d4ff15ce893210c1f0c0e9d19bfbecb7983c76b33f046c13a8ffbd570252",
|
||||
"sha256:193cbc708ea3aca45e7221ae58f0fd63f933753a9bfb498a3b474878f12caaad",
|
||||
"sha256:1a100c6d595a7f316f1b6f01d20815d916e75ff98c27a01ae817439ea7726329",
|
||||
"sha256:1f30b48dd7fa1474554b0b0f3fdfdd4c13b5c737a3c6284d3cdc424ec0ffff3a",
|
||||
"sha256:203f0c8871d5a7987be20c72442488a0b8cfd0f43b7973771640fc593f56321f",
|
||||
"sha256:246de67b99b6851627d945db38147d1b209a899311b1305dd84916f2b88526c6",
|
||||
"sha256:2dee8e57f052ef5353cf608e0b4c871aee320dd1b87d351c28764fc0ca55f9f4",
|
||||
"sha256:2efb1bd13885392adfda4614c33d3b68dee4921fd0ac1d3988f8cbb7d589e72a",
|
||||
"sha256:2f4ac36d8e2b4cc1aa71df3dd84ff8efbe3bfb97ac41242fbcfc053c67434f46",
|
||||
"sha256:3170c9399da12c9dc66366e9d14da8bf7147e1e9d9ea566067bbce7bb74bd9c2",
|
||||
"sha256:3b1613dd5aee995ec6d4c69f00378bbd07614702a315a2cf6c1d21461fe17c23",
|
||||
"sha256:3bb3d25a8e6c0aedd251753a79ae98a093c7e7b471faa3aa9a93a81431987ace",
|
||||
"sha256:3bb7fda7260735efe66d5107fb7e6af6a7c04c7fce9b2514e04b7a74b06bf5dd",
|
||||
"sha256:41b25eaa7d15909cf3ac4c96088c1f266a9a93ec44f87f1d13d4a0e86c81b982",
|
||||
"sha256:45de3f87179c1823e6d9e32156fb14c1927fcc9aba21433f088fdfb555b77c10",
|
||||
"sha256:46fb8c61d794b78ec7134a715a3e564aafc8f6b5e338417cb19fe9f57a5a9bf2",
|
||||
"sha256:48021783bdf96e3d6de03a6e39a1171ed5bd7e8bb93fc84cc649d11490f87cea",
|
||||
"sha256:4957669ef390f0e6719db3613ab3a7631e68424604a7b448f079bee145da6e09",
|
||||
"sha256:5e86d77b090dbddbe78867a0275cb4df08ea195e660f1f7f13435a4649e954e5",
|
||||
"sha256:6339d047dab2780cc6220f46306628e04d9750f02f983ddb37439ca47ced7149",
|
||||
"sha256:681eb3d7e02e3c3655d1b16059fbfb605ac464c834a0c629048a30fad2b27489",
|
||||
"sha256:6c409c0deba34f147f77efaa67b8e4bb83d2f11c8806405f76397ae5b8c0d1c9",
|
||||
"sha256:7095f6fbfaa55defb6b733cfeb14efaae7a29f0b59d8cf213be4e7ca0b857b80",
|
||||
"sha256:70c610f6cbe4b9fce272c407dd9d07e33e6bf7b4aa1b7ffb6f6ded8e634e3592",
|
||||
"sha256:72814c01533f51d68702802d74f77ea026b5ec52793c791e2da806a3844a46c3",
|
||||
"sha256:7a4826ad2bd6b07ca615c74ab91f32f6c96d08f6fcc3902ceeedaec8cdc3bcd6",
|
||||
"sha256:7c70087bfee18a42b4040bb9ec1ca15a08242cf5867c58726530bdf3945672ed",
|
||||
"sha256:855eafa5d5a2034b4621c74925d89c5efef61418570e5ef9b37717d9c796419c",
|
||||
"sha256:8700f06d0ce6f128de3ccdbc1acaea1ee264d2caa9ca05daaf492fde7c2a7200",
|
||||
"sha256:89f1b185a01fe560bc8ae5f619e924407efca2191b56ce749ec84982fc59a32a",
|
||||
"sha256:8b2c760cfc7042b27ebdb4a43a4453bd829a5742503599144d54a032c5dc7e9e",
|
||||
"sha256:8c2f5e83493748286002f9369f3e6607c565a6a90425a3a1fef5ae32a36d749d",
|
||||
"sha256:8e098148dd37b4ce3baca71fb394c81dc5d9c7728c95df695d2dca218edf40e6",
|
||||
"sha256:94aea8eff76ee6d1cdacb07dd2123a68283cb5569e0250feab1240058f53b623",
|
||||
"sha256:95eb302ff792e12aba9a8b8f8474ab229a83c103d74a750ec0bd1c1eea32e669",
|
||||
"sha256:9bd9b3b31adcb054116447ea22caa61a285d92e94d710aa5ec97992ff5eb7cf3",
|
||||
"sha256:9e608aafdb55eb9f255034709e20d5a83b6d60c054df0802fa9c9883d0a937aa",
|
||||
"sha256:a103b3a7069b62f5d4890ae1b8f0597618f628b286b03d4bc9195230b154bfa9",
|
||||
"sha256:a386ebe437176aab38c041de1260cd3ea459c6ce5263594399880bbc398225b2",
|
||||
"sha256:a38856a971c602f98472050165cea2cdc97709240373041b69030be15047691f",
|
||||
"sha256:a401b4598e5d3f4a9a811f3daf42ee2291790c7f9d74b18d75d6e21dda98a1a1",
|
||||
"sha256:a7647ebdfb9682b7bb97e2a5e7cb6ae735b1c25008a70b906aecca294ee96cf4",
|
||||
"sha256:aaf63899c94de41fe3cf934601b0f7ccb6b428c6e4eeb80da72c58eab077b19a",
|
||||
"sha256:b0dac0ff919ba34d4df1b6131f59ce95b08b9065233446be7e459f95554c0dc8",
|
||||
"sha256:baacc6aee0b2ef6f3d308e197b5d7a81c0e70b06beae1f1fcacffdbd124fe0e3",
|
||||
"sha256:bf420121d4c8dce6b889f0e8e4ec0ca34b7f40186203f06a946fa0276ba54029",
|
||||
"sha256:c04a46716adde8d927adb9457bbe39cf473e1e2c2f5d0a16ceb837e5d841ad4f",
|
||||
"sha256:c0b21078a4b56965e2b12f247467b234734491897e99c1d51cee628da9786959",
|
||||
"sha256:c1c76a1743432b4b60ab3358c937a3fe1341c828ae6194108a94c69028247f22",
|
||||
"sha256:c4983bf937209c57240cff65906b18bb35e64ae872da6a0db937d7b4af845dd7",
|
||||
"sha256:c4fb39a81950ec280984b3a44f5bd12819953dc5fa3a7e6fa7a80db5ee853952",
|
||||
"sha256:c57921cda3a80d0f2b8aec7e25c8aa14479ea92b5b51b6876d975d925a2ea346",
|
||||
"sha256:c8063cf17b19661471ecbdb3df1c84f24ad2e389e326ccaf89e3fb2484d8dd7e",
|
||||
"sha256:ccd16eb18a849fd8dcb23e23380e2f0a354e8daa0c984b8a732d9cfaba3a776d",
|
||||
"sha256:cd6dbe0238f7743d0efe563ab46294f54f9bc8f4b9bcf57c3c666cc5bc9d1299",
|
||||
"sha256:d62e51710986674142526ab9f78663ca2b0726066ae26b78b22e0f5e571238dd",
|
||||
"sha256:db901e2ac34c931d73054d9797383d0f8009991e723dab15109740a63e7f902a",
|
||||
"sha256:e03b8895a6990c9ab2cdcd0f2fe44088ca1c65ae592b8f795c3294af00a461c3",
|
||||
"sha256:e1c8a2f4c69e08e89632defbfabec2feb8a8d99edc9f89ce33c4b9e36ab63037",
|
||||
"sha256:e4b749b9cc6ee664a3300bb3a273c1ca8068c46be705b6c31cf5d276f8628a94",
|
||||
"sha256:e6a5bf2cba5ae1bb80b154ed68a3cfa2fa00fde979a7f50d6598d3e17d9ac20c",
|
||||
"sha256:e857a2232ba53ae940d3456f7533ce6ca98b81917d47adc3c7fd55dad8fab858",
|
||||
"sha256:ee4006268ed33370957f55bf2e6f4d263eaf4dc3cfc473d1d90baff6ed36ce4a",
|
||||
"sha256:eef9df1eefada2c09a5e7a40991b9fc6ac6ef20b1372abd48d2794a316dc0449",
|
||||
"sha256:f058f6963fd82eb143c692cecdc89e075fa0828db2e5b291070485390b2f1c9c",
|
||||
"sha256:f25c229a6ba38a35ae6e25ca1264621cc25d4d38dca2942a7fce0b67a4efe918",
|
||||
"sha256:f2a1d0fd4242bd8643ce6f98927cf9c04540af6efa92323e9d3124f57727bfc1",
|
||||
"sha256:f7560358a6811e52e9c4d142d497f1a6e10103d3a6881f18d04dbce3729c0e2c",
|
||||
"sha256:f779d3ad205f108d14e99bb3859aa7dd8e9c68874617c72354d7ecaec2a054ac",
|
||||
"sha256:f87f746ee241d30d6ed93969de31e5ffd09a2961a051e60ae6bddde9ec3583aa"
|
||||
],
|
||||
"markers": "python_full_version >= '3.7.0'",
|
||||
"version": "==3.1.0"
|
||||
"version": "==3.2.0"
|
||||
},
|
||||
"cryptography": {
|
||||
"hashes": [
|
||||
"sha256:05dc219433b14046c476f6f09d7636b92a1c3e5808b9a6536adf4932b3b2c440",
|
||||
"sha256:0dcca15d3a19a66e63662dc8d30f8036b07be851a8680eda92d079868f106288",
|
||||
"sha256:142bae539ef28a1c76794cca7f49729e7c54423f615cfd9b0b1fa90ebe53244b",
|
||||
"sha256:3daf9b114213f8ba460b829a02896789751626a2a4e7a43a28ee77c04b5e4958",
|
||||
"sha256:48f388d0d153350f378c7f7b41497a54ff1513c816bcbbcafe5b829e59b9ce5b",
|
||||
"sha256:4df2af28d7bedc84fe45bd49bc35d710aede676e2a4cb7fc6d103a2adc8afe4d",
|
||||
"sha256:4f01c9863da784558165f5d4d916093737a75203a5c5286fde60e503e4276c7a",
|
||||
"sha256:7a38250f433cd41df7fcb763caa3ee9362777fdb4dc642b9a349721d2bf47404",
|
||||
"sha256:8f79b5ff5ad9d3218afb1e7e20ea74da5f76943ee5edb7f76e56ec5161ec782b",
|
||||
"sha256:956ba8701b4ffe91ba59665ed170a2ebbdc6fc0e40de5f6059195d9f2b33ca0e",
|
||||
"sha256:a04386fb7bc85fab9cd51b6308633a3c271e3d0d3eae917eebab2fac6219b6d2",
|
||||
"sha256:a95f4802d49faa6a674242e25bfeea6fc2acd915b5e5e29ac90a32b1139cae1c",
|
||||
"sha256:adc0d980fd2760c9e5de537c28935cc32b9353baaf28e0814df417619c6c8c3b",
|
||||
"sha256:aecbb1592b0188e030cb01f82d12556cf72e218280f621deed7d806afd2113f9",
|
||||
"sha256:b12794f01d4cacfbd3177b9042198f3af1c856eedd0a98f10f141385c809a14b",
|
||||
"sha256:c0764e72b36a3dc065c155e5b22f93df465da9c39af65516fe04ed3c68c92636",
|
||||
"sha256:c33c0d32b8594fa647d2e01dbccc303478e16fdd7cf98652d5b3ed11aa5e5c99",
|
||||
"sha256:cbaba590180cba88cb99a5f76f90808a624f18b169b90a4abb40c1fd8c19420e",
|
||||
"sha256:d5a1bd0e9e2031465761dfa920c16b0065ad77321d8a8c1f5ee331021fda65e9"
|
||||
"sha256:01f1d9e537f9a15b037d5d9ee442b8c22e3ae11ce65ea1f3316a41c78756b711",
|
||||
"sha256:079347de771f9282fbfe0e0236c716686950c19dee1b76240ab09ce1624d76d7",
|
||||
"sha256:182be4171f9332b6741ee818ec27daff9fb00349f706629f5cbf417bd50e66fd",
|
||||
"sha256:192255f539d7a89f2102d07d7375b1e0a81f7478925b3bc2e0549ebf739dae0e",
|
||||
"sha256:2a034bf7d9ca894720f2ec1d8b7b5832d7e363571828037f9e0c4f18c1b58a58",
|
||||
"sha256:342f3767e25876751e14f8459ad85e77e660537ca0a066e10e75df9c9e9099f0",
|
||||
"sha256:439c3cc4c0d42fa999b83ded80a9a1fb54d53c58d6e59234cfe97f241e6c781d",
|
||||
"sha256:49c3222bb8f8e800aead2e376cbef687bc9e3cb9b58b29a261210456a7783d83",
|
||||
"sha256:674b669d5daa64206c38e507808aae49904c988fa0a71c935e7006a3e1e83831",
|
||||
"sha256:7a9a3bced53b7f09da251685224d6a260c3cb291768f54954e28f03ef14e3766",
|
||||
"sha256:7af244b012711a26196450d34f483357e42aeddb04128885d95a69bd8b14b69b",
|
||||
"sha256:7d230bf856164de164ecb615ccc14c7fc6de6906ddd5b491f3af90d3514c925c",
|
||||
"sha256:84609ade00a6ec59a89729e87a503c6e36af98ddcd566d5f3be52e29ba993182",
|
||||
"sha256:9a6673c1828db6270b76b22cc696f40cde9043eb90373da5c2f8f2158957f42f",
|
||||
"sha256:9b6d717393dbae53d4e52684ef4f022444fc1cce3c48c38cb74fca29e1f08eaa",
|
||||
"sha256:9c3fe6534d59d071ee82081ca3d71eed3210f76ebd0361798c74abc2bcf347d4",
|
||||
"sha256:a719399b99377b218dac6cf547b6ec54e6ef20207b6165126a280b0ce97e0d2a",
|
||||
"sha256:b332cba64d99a70c1e0836902720887fb4529ea49ea7f5462cf6640e095e11d2",
|
||||
"sha256:d124682c7a23c9764e54ca9ab5b308b14b18eba02722b8659fb238546de83a76",
|
||||
"sha256:d73f419a56d74fef257955f51b18d046f3506270a5fd2ac5febbfa259d6c0fa5",
|
||||
"sha256:f0dc40e6f7aa37af01aba07277d3d64d5a03dc66d682097541ec4da03cc140ee",
|
||||
"sha256:f14ad275364c8b4e525d018f6716537ae7b6d369c094805cae45300847e0894f",
|
||||
"sha256:f772610fe364372de33d76edcd313636a25684edb94cee53fd790195f5989d14"
|
||||
],
|
||||
"markers": "python_version >= '3.6'",
|
||||
"version": "==40.0.2"
|
||||
"markers": "python_version >= '3.7'",
|
||||
"version": "==41.0.2"
|
||||
},
|
||||
"docker": {
|
||||
"hashes": [
|
||||
"sha256:134cd828f84543cbf8e594ff81ca90c38288df3c0a559794c12f2e4b634ea19e",
|
||||
"sha256:dcc088adc2ec4e7cfc594e275d8bd2c9738c56c808de97476939ef67db5af8c2"
|
||||
"sha256:aa6d17830045ba5ef0168d5eaa34d37beeb113948c413affe1d5991fc11f9a20",
|
||||
"sha256:aecd2277b8bf8e506e484f6ab7aec39abe0038e29fa4a6d3ba86c3fe01844ed9"
|
||||
],
|
||||
"markers": "python_version >= '3.7'",
|
||||
"version": "==6.1.2"
|
||||
"version": "==6.1.3"
|
||||
},
|
||||
"execnet": {
|
||||
"hashes": [
|
||||
"sha256:8f694f3ba9cc92cab508b152dcfe322153975c29bda272e2fd7f3f00f36e47c5",
|
||||
"sha256:a295f7cc774947aac58dde7fdc85f4aa00c42adf5d8f5468fc630c1acf30a142"
|
||||
"sha256:88256416ae766bc9e8895c76a87928c0012183da3cc4fc18016e6f050e025f41",
|
||||
"sha256:cc59bc4423742fd71ad227122eb0dd44db51efb3dc4095b45ac9a08c770096af"
|
||||
],
|
||||
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'",
|
||||
"version": "==1.9.0"
|
||||
"markers": "python_version >= '3.7'",
|
||||
"version": "==2.0.2"
|
||||
},
|
||||
"idna": {
|
||||
"hashes": [
|
||||
|
@ -241,11 +245,11 @@
|
|||
},
|
||||
"pluggy": {
|
||||
"hashes": [
|
||||
"sha256:4224373bacce55f955a878bf9cfa763c1e360858e330072059e10bad68531159",
|
||||
"sha256:74134bbf457f031a36d68416e1509f34bd5ccc019f0bcc952c7b909d06b37bd3"
|
||||
"sha256:c2fd55a7d7a3863cba1a013e4e2414658b1d07b6bc57b3919e0c63c9abb99849",
|
||||
"sha256:d12f0c4b579b15f5e054301bb226ee85eeeba08ffec228092f8defbaa3a4c4b3"
|
||||
],
|
||||
"markers": "python_version >= '3.6'",
|
||||
"version": "==1.0.0"
|
||||
"markers": "python_version >= '3.7'",
|
||||
"version": "==1.2.0"
|
||||
},
|
||||
"psutil": {
|
||||
"hashes": [
|
||||
|
@ -276,11 +280,11 @@
|
|||
},
|
||||
"pytest": {
|
||||
"hashes": [
|
||||
"sha256:3799fa815351fea3a5e96ac7e503a96fa51cc9942c3753cda7651b93c1cfa362",
|
||||
"sha256:434afafd78b1d78ed0addf160ad2b77a30d35d4bdf8af234fe621919d9ed15e3"
|
||||
"sha256:78bf16451a2eb8c7a2ea98e32dc119fd2aa758f1d5d66dbf0a59d69a3969df32",
|
||||
"sha256:b4bf8c45bd59934ed84001ad51e11b4ee40d40a1229d2c79f9c592b0a3f6bd8a"
|
||||
],
|
||||
"markers": "python_version >= '3.7'",
|
||||
"version": "==7.3.1"
|
||||
"version": "==7.4.0"
|
||||
},
|
||||
"pytest-cs": {
|
||||
"git": "https://github.com/crowdsecurity/pytest-cs.git",
|
||||
|
@ -320,49 +324,49 @@
|
|||
},
|
||||
"pyyaml": {
|
||||
"hashes": [
|
||||
"sha256:01b45c0191e6d66c470b6cf1b9531a771a83c1c4208272ead47a3ae4f2f603bf",
|
||||
"sha256:0283c35a6a9fbf047493e3a0ce8d79ef5030852c51e9d911a27badfde0605293",
|
||||
"sha256:055d937d65826939cb044fc8c9b08889e8c743fdc6a32b33e2390f66013e449b",
|
||||
"sha256:07751360502caac1c067a8132d150cf3d61339af5691fe9e87803040dbc5db57",
|
||||
"sha256:0b4624f379dab24d3725ffde76559cff63d9ec94e1736b556dacdfebe5ab6d4b",
|
||||
"sha256:0ce82d761c532fe4ec3f87fc45688bdd3a4c1dc5e0b4a19814b9009a29baefd4",
|
||||
"sha256:1e4747bc279b4f613a09eb64bba2ba602d8a6664c6ce6396a4d0cd413a50ce07",
|
||||
"sha256:213c60cd50106436cc818accf5baa1aba61c0189ff610f64f4a3e8c6726218ba",
|
||||
"sha256:231710d57adfd809ef5d34183b8ed1eeae3f76459c18fb4a0b373ad56bedcdd9",
|
||||
"sha256:277a0ef2981ca40581a47093e9e2d13b3f1fbbeffae064c1d21bfceba2030287",
|
||||
"sha256:2cd5df3de48857ed0544b34e2d40e9fac445930039f3cfe4bcc592a1f836d513",
|
||||
"sha256:40527857252b61eacd1d9af500c3337ba8deb8fc298940291486c465c8b46ec0",
|
||||
"sha256:432557aa2c09802be39460360ddffd48156e30721f5e8d917f01d31694216782",
|
||||
"sha256:473f9edb243cb1935ab5a084eb238d842fb8f404ed2193a915d1784b5a6b5fc0",
|
||||
"sha256:48c346915c114f5fdb3ead70312bd042a953a8ce5c7106d5bfb1a5254e47da92",
|
||||
"sha256:50602afada6d6cbfad699b0c7bb50d5ccffa7e46a3d738092afddc1f9758427f",
|
||||
"sha256:68fb519c14306fec9720a2a5b45bc9f0c8d1b9c72adf45c37baedfcd949c35a2",
|
||||
"sha256:77f396e6ef4c73fdc33a9157446466f1cff553d979bd00ecb64385760c6babdc",
|
||||
"sha256:81957921f441d50af23654aa6c5e5eaf9b06aba7f0a19c18a538dc7ef291c5a1",
|
||||
"sha256:819b3830a1543db06c4d4b865e70ded25be52a2e0631ccd2f6a47a2822f2fd7c",
|
||||
"sha256:897b80890765f037df3403d22bab41627ca8811ae55e9a722fd0392850ec4d86",
|
||||
"sha256:98c4d36e99714e55cfbaaee6dd5badbc9a1ec339ebfc3b1f52e293aee6bb71a4",
|
||||
"sha256:9df7ed3b3d2e0ecfe09e14741b857df43adb5a3ddadc919a2d94fbdf78fea53c",
|
||||
"sha256:9fa600030013c4de8165339db93d182b9431076eb98eb40ee068700c9c813e34",
|
||||
"sha256:a80a78046a72361de73f8f395f1f1e49f956c6be882eed58505a15f3e430962b",
|
||||
"sha256:afa17f5bc4d1b10afd4466fd3a44dc0e245382deca5b3c353d8b757f9e3ecb8d",
|
||||
"sha256:b3d267842bf12586ba6c734f89d1f5b871df0273157918b0ccefa29deb05c21c",
|
||||
"sha256:b5b9eccad747aabaaffbc6064800670f0c297e52c12754eb1d976c57e4f74dcb",
|
||||
"sha256:bfaef573a63ba8923503d27530362590ff4f576c626d86a9fed95822a8255fd7",
|
||||
"sha256:c5687b8d43cf58545ade1fe3e055f70eac7a5a1a0bf42824308d868289a95737",
|
||||
"sha256:cba8c411ef271aa037d7357a2bc8f9ee8b58b9965831d9e51baf703280dc73d3",
|
||||
"sha256:d15a181d1ecd0d4270dc32edb46f7cb7733c7c508857278d3d378d14d606db2d",
|
||||
"sha256:d4b0ba9512519522b118090257be113b9468d804b19d63c71dbcf4a48fa32358",
|
||||
"sha256:d4db7c7aef085872ef65a8fd7d6d09a14ae91f691dec3e87ee5ee0539d516f53",
|
||||
"sha256:d4eccecf9adf6fbcc6861a38015c2a64f38b9d94838ac1810a9023a0609e1b78",
|
||||
"sha256:d67d839ede4ed1b28a4e8909735fc992a923cdb84e618544973d7dfc71540803",
|
||||
"sha256:daf496c58a8c52083df09b80c860005194014c3698698d1a57cbcfa182142a3a",
|
||||
"sha256:dbad0e9d368bb989f4515da330b88a057617d16b6a8245084f1b05400f24609f",
|
||||
"sha256:e61ceaab6f49fb8bdfaa0f92c4b57bcfbea54c09277b1b4f7ac376bfb7a7c174",
|
||||
"sha256:f84fbc98b019fef2ee9a1cb3ce93e3187a6df0b2538a651bfb890254ba9f90b5"
|
||||
"sha256:062582fca9fabdd2c8b54a3ef1c978d786e0f6b3a1510e0ac93ef59e0ddae2bc",
|
||||
"sha256:1635fd110e8d85d55237ab316b5b011de701ea0f29d07611174a1b42f1444741",
|
||||
"sha256:184c5108a2aca3c5b3d3bf9395d50893a7ab82a38004c8f61c258d4428e80206",
|
||||
"sha256:18aeb1bf9a78867dc38b259769503436b7c72f7a1f1f4c93ff9a17de54319b27",
|
||||
"sha256:1d4c7e777c441b20e32f52bd377e0c409713e8bb1386e1099c2415f26e479595",
|
||||
"sha256:1e2722cc9fbb45d9b87631ac70924c11d3a401b2d7f410cc0e3bbf249f2dca62",
|
||||
"sha256:1fe35611261b29bd1de0070f0b2f47cb6ff71fa6595c077e42bd0c419fa27b98",
|
||||
"sha256:28c119d996beec18c05208a8bd78cbe4007878c6dd15091efb73a30e90539696",
|
||||
"sha256:42f8152b8dbc4fe7d96729ec2b99c7097d656dc1213a3229ca5383f973a5ed6d",
|
||||
"sha256:4fb147e7a67ef577a588a0e2c17b6db51dda102c71de36f8549b6816a96e1867",
|
||||
"sha256:50550eb667afee136e9a77d6dc71ae76a44df8b3e51e41b77f6de2932bfe0f47",
|
||||
"sha256:510c9deebc5c0225e8c96813043e62b680ba2f9c50a08d3724c7f28a747d1486",
|
||||
"sha256:5773183b6446b2c99bb77e77595dd486303b4faab2b086e7b17bc6bef28865f6",
|
||||
"sha256:596106435fa6ad000c2991a98fa58eeb8656ef2325d7e158344fb33864ed87e3",
|
||||
"sha256:6965a7bc3cf88e5a1c3bd2e0b5c22f8d677dc88a455344035f03399034eb3007",
|
||||
"sha256:69b023b2b4daa7548bcfbd4aa3da05b3a74b772db9e23b982788168117739938",
|
||||
"sha256:704219a11b772aea0d8ecd7058d0082713c3562b4e271b849ad7dc4a5c90c13c",
|
||||
"sha256:7e07cbde391ba96ab58e532ff4803f79c4129397514e1413a7dc761ccd755735",
|
||||
"sha256:81e0b275a9ecc9c0c0c07b4b90ba548307583c125f54d5b6946cfee6360c733d",
|
||||
"sha256:9046c58c4395dff28dd494285c82ba00b546adfc7ef001486fbf0324bc174fba",
|
||||
"sha256:9eb6caa9a297fc2c2fb8862bc5370d0303ddba53ba97e71f08023b6cd73d16a8",
|
||||
"sha256:a0cd17c15d3bb3fa06978b4e8958dcdc6e0174ccea823003a106c7d4d7899ac5",
|
||||
"sha256:afd7e57eddb1a54f0f1a974bc4391af8bcce0b444685d936840f125cf046d5bd",
|
||||
"sha256:b1275ad35a5d18c62a7220633c913e1b42d44b46ee12554e5fd39c70a243d6a3",
|
||||
"sha256:b786eecbdf8499b9ca1d697215862083bd6d2a99965554781d0d8d1ad31e13a0",
|
||||
"sha256:ba336e390cd8e4d1739f42dfe9bb83a3cc2e80f567d8805e11b46f4a943f5515",
|
||||
"sha256:baa90d3f661d43131ca170712d903e6295d1f7a0f595074f151c0aed377c9b9c",
|
||||
"sha256:bc1bf2925a1ecd43da378f4db9e4f799775d6367bdb94671027b73b393a7c42c",
|
||||
"sha256:bd4af7373a854424dabd882decdc5579653d7868b8fb26dc7d0e99f823aa5924",
|
||||
"sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34",
|
||||
"sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43",
|
||||
"sha256:c8098ddcc2a85b61647b2590f825f3db38891662cfc2fc776415143f599bb859",
|
||||
"sha256:d2b04aac4d386b172d5b9692e2d2da8de7bfb6c387fa4f801fbf6fb2e6ba4673",
|
||||
"sha256:d858aa552c999bc8a8d57426ed01e40bef403cd8ccdd0fc5f6f04a00414cac2a",
|
||||
"sha256:f003ed9ad21d6a4713f0a9b5a7a0a79e08dd0f221aff4525a2be4c346ee60aab",
|
||||
"sha256:f22ac1c3cac4dbc50079e965eba2c1058622631e526bd9afd45fedd49ba781fa",
|
||||
"sha256:faca3bdcf85b2fc05d06ff3fbc1f83e1391b3e724afa3feba7d13eeab355484c",
|
||||
"sha256:fca0e3a251908a499833aa292323f32437106001d436eca0e6e7833256674585",
|
||||
"sha256:fd1592b3fdf65fff2ad0004b5e363300ef59ced41c2e6b3a99d4089fa8c5435d",
|
||||
"sha256:fd66fc5d0da6d9815ba2cebeb4205f95818ff4b79c3ebe268e75d961704af52f"
|
||||
],
|
||||
"markers": "python_version >= '3.6'",
|
||||
"version": "==6.0"
|
||||
"version": "==6.0.1"
|
||||
},
|
||||
"requests": {
|
||||
"hashes": [
|
||||
|
@ -374,27 +378,27 @@
|
|||
},
|
||||
"trustme": {
|
||||
"hashes": [
|
||||
"sha256:1d4f0b0fe28091506edc29c19ad90cca387646add436c3ca66ba7bcc53807f55",
|
||||
"sha256:7a9f82ad494d661cd10c9eed38e0f708154eb59a2e415da6b02af3e5dac53134"
|
||||
"sha256:5375ad7fb427074bec956592e0d4ee2a4cf4da68934e1ba4bcf4217126bc45e6",
|
||||
"sha256:ce105b68fb9f6d7ac7a9ee6e95bb2347a22ce4d3be78ef9a6494d5ef890e1e16"
|
||||
],
|
||||
"markers": "python_version >= '3.7'",
|
||||
"version": "==1.0.0"
|
||||
"markers": "python_version >= '3.8'",
|
||||
"version": "==1.1.0"
|
||||
},
|
||||
"urllib3": {
|
||||
"hashes": [
|
||||
"sha256:61717a1095d7e155cdb737ac7bb2f4324a858a1e2e6466f6d03ff630ca68d3cc",
|
||||
"sha256:d055c2f9d38dc53c808f6fdc8eab7360b6fdbbde02340ed25cfbcd817c62469e"
|
||||
"sha256:8d22f86aae8ef5e410d4f539fde9ce6b2113a001bb4d189e0aed70642d602b11",
|
||||
"sha256:de7df1803967d2c2a98e4b11bb7d6bd9210474c46e8a0401514e3a42a75ebde4"
|
||||
],
|
||||
"markers": "python_version >= '3.7'",
|
||||
"version": "==2.0.2"
|
||||
"version": "==2.0.4"
|
||||
},
|
||||
"websocket-client": {
|
||||
"hashes": [
|
||||
"sha256:c7d67c13b928645f259d9b847ab5b57fd2d127213ca41ebd880de1f553b7c23b",
|
||||
"sha256:f8c64e28cd700e7ba1f04350d66422b6833b82a796b525a51e740b8cc8dab4b1"
|
||||
"sha256:c951af98631d24f8df89ab1019fc365f2227c0892f12fd150e935607c79dd0dd",
|
||||
"sha256:f1f9f2ad5291f0225a49efad77abf9e700b6fef553900623060dad6e26503b9d"
|
||||
],
|
||||
"markers": "python_version >= '3.7'",
|
||||
"version": "==1.5.2"
|
||||
"version": "==1.6.1"
|
||||
}
|
||||
},
|
||||
"develop": {
|
||||
|
@ -470,11 +474,11 @@
|
|||
},
|
||||
"ipython": {
|
||||
"hashes": [
|
||||
"sha256:7dff3fad32b97f6488e02f87b970f309d082f758d7b7fc252e3b19ee0e432dbb",
|
||||
"sha256:ffca270240fbd21b06b2974e14a86494d6d29290184e788275f55e0b55914926"
|
||||
"sha256:1d197b907b6ba441b692c48cf2a3a2de280dc0ac91a3405b39349a50272ca0a1",
|
||||
"sha256:248aca623f5c99a6635bc3857677b7320b9b8039f99f070ee0d20a5ca5a8e6bf"
|
||||
],
|
||||
"markers": "python_version >= '3.11'",
|
||||
"version": "==8.13.2"
|
||||
"version": "==8.14.0"
|
||||
},
|
||||
"jedi": {
|
||||
"hashes": [
|
||||
|
@ -517,11 +521,11 @@
|
|||
},
|
||||
"prompt-toolkit": {
|
||||
"hashes": [
|
||||
"sha256:23ac5d50538a9a38c8bde05fecb47d0b403ecd0662857a86f886f798563d5b9b",
|
||||
"sha256:45ea77a2f7c60418850331366c81cf6b5b9cf4c7fd34616f733c5427e6abbb1f"
|
||||
"sha256:04505ade687dc26dc4284b1ad19a83be2f2afe83e7a828ace0c72f3a1df72aac",
|
||||
"sha256:9dffbe1d8acf91e3de75f3b544e4842382fc06c6babe903ac9acb74dc6e08d88"
|
||||
],
|
||||
"markers": "python_full_version >= '3.7.0'",
|
||||
"version": "==3.0.38"
|
||||
"version": "==3.0.39"
|
||||
},
|
||||
"ptyprocess": {
|
||||
"hashes": [
|
||||
|
|
|
@ -25,7 +25,7 @@ def test_capi_whitelists(crowdsec, tmp_path_factory, flavor,):
|
|||
with crowdsec(flavor=flavor, environment=env, volumes=volumes) as cs:
|
||||
cs.wait_for_log("*Starting processing data*")
|
||||
cs.wait_for_http(8080, '/health', want_status=HTTPStatus.OK)
|
||||
res = cs.cont.exec_run(f'cscli config show-yaml')
|
||||
res = cs.cont.exec_run('cscli config show-yaml')
|
||||
assert res.exit_code == 0
|
||||
stdout = res.output.decode()
|
||||
y = yaml.safe_load(stdout)
|
||||
|
|
|
@ -50,9 +50,11 @@ def test_flavor_content(crowdsec, flavor):
|
|||
assert 'notification-http' not in stdout
|
||||
assert 'notification-slack' not in stdout
|
||||
assert 'notification-splunk' not in stdout
|
||||
assert 'notification-sentinel' not in stdout
|
||||
else:
|
||||
assert x.exit_code == 0
|
||||
assert 'notification-email' in stdout
|
||||
assert 'notification-http' in stdout
|
||||
assert 'notification-slack' in stdout
|
||||
assert 'notification-splunk' in stdout
|
||||
assert 'notification-sentinel' in stdout
|
||||
|
|
89
go.mod
89
go.mod
|
@ -7,6 +7,7 @@ require (
|
|||
github.com/AlecAivazis/survey/v2 v2.2.7
|
||||
github.com/Masterminds/semver/v3 v3.1.1
|
||||
github.com/Masterminds/sprig/v3 v3.2.2
|
||||
github.com/agext/levenshtein v1.2.1
|
||||
github.com/alexliesenfeld/health v0.5.1
|
||||
github.com/antonmedv/expr v1.12.5
|
||||
github.com/appleboy/gin-jwt/v2 v2.8.0
|
||||
|
@ -18,41 +19,41 @@ require (
|
|||
github.com/bluele/gcache v0.0.2
|
||||
github.com/buger/jsonparser v1.1.1
|
||||
github.com/c-robinson/iplib v1.0.3
|
||||
github.com/cespare/xxhash/v2 v2.1.2
|
||||
github.com/cespare/xxhash/v2 v2.2.0
|
||||
github.com/crowdsecurity/dlog v0.0.0-20170105205344-4fb5f8204f26
|
||||
github.com/crowdsecurity/go-cs-lib v0.0.2
|
||||
github.com/crowdsecurity/go-cs-lib v0.0.3
|
||||
github.com/crowdsecurity/grokky v0.2.1
|
||||
github.com/crowdsecurity/machineid v1.0.2
|
||||
github.com/davecgh/go-spew v1.1.1
|
||||
github.com/dghubble/sling v1.3.0
|
||||
github.com/docker/docker v20.10.24+incompatible
|
||||
github.com/docker/docker v24.0.4+incompatible
|
||||
github.com/docker/go-connections v0.4.0
|
||||
github.com/enescakir/emoji v1.0.0
|
||||
github.com/fatih/color v1.15.0
|
||||
github.com/fsnotify/fsnotify v1.6.0
|
||||
github.com/gin-gonic/gin v1.7.7
|
||||
github.com/gin-gonic/gin v1.9.1
|
||||
github.com/go-co-op/gocron v1.17.0
|
||||
github.com/go-openapi/errors v0.20.1
|
||||
github.com/go-openapi/strfmt v0.19.11
|
||||
github.com/go-openapi/swag v0.19.14
|
||||
github.com/go-openapi/swag v0.22.3
|
||||
github.com/go-openapi/validate v0.20.0
|
||||
github.com/go-sql-driver/mysql v1.6.0
|
||||
github.com/goccy/go-yaml v1.9.7
|
||||
github.com/goccy/go-yaml v1.11.0
|
||||
github.com/gofrs/uuid v4.0.0+incompatible
|
||||
github.com/golang-jwt/jwt/v4 v4.2.0
|
||||
github.com/golang-jwt/jwt/v4 v4.4.2
|
||||
github.com/google/go-querystring v1.0.0
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/google/winops v0.0.0-20211216095627-f0e86eb1453b
|
||||
github.com/google/winops v0.0.0-20230712152054-af9b550d0601
|
||||
github.com/goombaio/namegenerator v0.0.0-20181006234301-989e774b106e
|
||||
github.com/hashicorp/go-hclog v1.0.0
|
||||
github.com/hashicorp/go-plugin v1.4.2
|
||||
github.com/hashicorp/go-hclog v1.5.0
|
||||
github.com/hashicorp/go-plugin v1.4.10
|
||||
github.com/hashicorp/go-version v1.2.1
|
||||
github.com/ivanpirog/coloredcobra v1.0.1
|
||||
github.com/jackc/pgx/v4 v4.14.1
|
||||
github.com/jarcoal/httpmock v1.1.0
|
||||
github.com/jszwec/csvutil v1.5.1
|
||||
github.com/lithammer/dedent v1.1.0
|
||||
github.com/mattn/go-isatty v0.0.17
|
||||
github.com/mattn/go-isatty v0.0.19
|
||||
github.com/mattn/go-sqlite3 v1.14.16
|
||||
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
|
||||
github.com/nxadm/tail v1.4.8
|
||||
|
@ -68,16 +69,15 @@ require (
|
|||
github.com/shirou/gopsutil/v3 v3.23.5
|
||||
github.com/sirupsen/logrus v1.9.3
|
||||
github.com/spf13/cobra v1.7.0
|
||||
github.com/stretchr/testify v1.8.3
|
||||
github.com/texttheater/golang-levenshtein/levenshtein v0.0.0-20200805054039-cae8b0eaed6c
|
||||
github.com/stretchr/testify v1.8.4
|
||||
github.com/umahmood/haversine v0.0.0-20151105152445-808ab04add26
|
||||
github.com/wasilibs/go-re2 v0.2.1
|
||||
golang.org/x/crypto v0.11.0
|
||||
github.com/wasilibs/go-re2 v1.3.0
|
||||
golang.org/x/crypto v0.10.0
|
||||
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1
|
||||
golang.org/x/mod v0.11.0
|
||||
golang.org/x/sys v0.10.0
|
||||
google.golang.org/grpc v1.47.0
|
||||
google.golang.org/protobuf v1.28.1
|
||||
google.golang.org/grpc v1.56.1
|
||||
google.golang.org/protobuf v1.30.0
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1
|
||||
gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
|
@ -86,42 +86,44 @@ require (
|
|||
require (
|
||||
github.com/crowdsecurity/coraza/v3 v3.0.0-20230727080316-2348f4b3045f
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
k8s.io/apiserver v0.22.5
|
||||
k8s.io/apiserver v0.27.3
|
||||
)
|
||||
|
||||
require (
|
||||
ariga.io/atlas v0.7.2-0.20220927111110-867ee0cca56a // indirect
|
||||
github.com/Masterminds/goutils v1.1.1 // indirect
|
||||
github.com/Microsoft/go-winio v0.6.1 // indirect
|
||||
github.com/PuerkitoBio/purell v1.1.1 // indirect
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
|
||||
github.com/agext/levenshtein v1.2.1 // indirect
|
||||
github.com/ahmetalpbalkan/dlog v0.0.0-20170105205344-4fb5f8204f26 // indirect
|
||||
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
|
||||
github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/bytedance/sonic v1.9.1 // indirect
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
|
||||
github.com/corazawaf/libinjection-go v0.1.2 // indirect
|
||||
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
|
||||
github.com/creack/pty v1.1.18 // indirect
|
||||
github.com/docker/distribution v2.8.2+incompatible // indirect
|
||||
github.com/docker/go-units v0.4.0 // indirect
|
||||
github.com/docker/go-units v0.5.0 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/go-logr/logr v1.2.3 // indirect
|
||||
github.com/go-ole/go-ole v1.2.6 // indirect
|
||||
github.com/go-openapi/analysis v0.19.16 // indirect
|
||||
github.com/go-openapi/inflect v0.19.0 // indirect
|
||||
github.com/go-openapi/jsonpointer v0.19.5 // indirect
|
||||
github.com/go-openapi/jsonreference v0.19.5 // indirect
|
||||
github.com/go-openapi/jsonpointer v0.19.6 // indirect
|
||||
github.com/go-openapi/jsonreference v0.20.1 // indirect
|
||||
github.com/go-openapi/loads v0.20.0 // indirect
|
||||
github.com/go-openapi/runtime v0.19.24 // indirect
|
||||
github.com/go-openapi/spec v0.20.0 // indirect
|
||||
github.com/go-playground/locales v0.14.0 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.0 // indirect
|
||||
github.com/go-playground/validator/v10 v10.10.0 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/go-playground/validator/v10 v10.14.0 // indirect
|
||||
github.com/go-stack/stack v1.8.0 // indirect
|
||||
github.com/goccy/go-json v0.10.2 // indirect
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/golang/glog v0.0.0-20210429001901-424d2337a529 // indirect
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/golang/glog v1.1.0 // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/google/go-cmp v0.5.9 // indirect
|
||||
github.com/google/gofuzz v1.2.0 // indirect
|
||||
github.com/hashicorp/hcl/v2 v2.13.0 // indirect
|
||||
|
@ -141,10 +143,11 @@ require (
|
|||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
|
||||
github.com/klauspost/compress v1.15.7 // indirect
|
||||
github.com/leodido/go-urn v1.2.1 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
|
||||
github.com/leodido/go-urn v1.2.4 // indirect
|
||||
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
|
||||
github.com/magefile/mage v1.15.0 // indirect
|
||||
github.com/mailru/easyjson v0.7.6 // indirect
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.13 // indirect
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
|
||||
|
@ -154,12 +157,14 @@ require (
|
|||
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/mitchellh/reflectwalk v1.0.2 // indirect
|
||||
github.com/moby/term v0.5.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/morikuni/aec v1.0.0 // indirect
|
||||
github.com/oklog/run v1.0.0 // indirect
|
||||
github.com/opencontainers/go-digest v1.0.0 // indirect
|
||||
github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
|
||||
github.com/petar-dambovaliev/aho-corasick v0.0.0-20230725210150-fb29fc3c913e // indirect
|
||||
github.com/pierrec/lz4/v4 v4.1.15 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
|
@ -173,33 +178,37 @@ require (
|
|||
github.com/shopspring/decimal v1.2.0 // indirect
|
||||
github.com/spf13/cast v1.3.1 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/tetratelabs/wazero v1.0.0-rc.2 // indirect
|
||||
github.com/tetratelabs/wazero v1.2.1 // indirect
|
||||
github.com/tidwall/gjson v1.14.4 // indirect
|
||||
github.com/tidwall/match v1.1.1 // indirect
|
||||
github.com/tidwall/pretty v1.2.1 // indirect
|
||||
github.com/tklauser/go-sysconf v0.3.11 // indirect
|
||||
github.com/tklauser/numcpus v0.6.0 // indirect
|
||||
github.com/ugorji/go/codec v1.2.6 // indirect
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
|
||||
github.com/yusufpapurcu/wmi v1.2.3 // indirect
|
||||
github.com/zclconf/go-cty v1.8.0 // indirect
|
||||
go.mongodb.org/mongo-driver v1.9.4 // indirect
|
||||
golang.org/x/arch v0.3.0 // indirect
|
||||
golang.org/x/net v0.11.0 // indirect
|
||||
golang.org/x/sync v0.1.0 // indirect
|
||||
golang.org/x/term v0.10.0 // indirect
|
||||
golang.org/x/text v0.11.0 // indirect
|
||||
golang.org/x/tools v0.6.0 // indirect
|
||||
golang.org/x/time v0.2.0 // indirect
|
||||
golang.org/x/tools v0.7.0 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/genproto v0.0.0-20220502173005-c8bf987b8c21 // indirect
|
||||
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
|
||||
gopkg.in/inf.v0 v0.9.1 // indirect
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
|
||||
k8s.io/api v0.25.2 // indirect
|
||||
k8s.io/apimachinery v0.25.2 // indirect
|
||||
k8s.io/klog/v2 v2.70.1 // indirect
|
||||
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed // indirect
|
||||
gotest.tools/v3 v3.5.0 // indirect
|
||||
k8s.io/api v0.27.3 // indirect
|
||||
k8s.io/apimachinery v0.27.3 // indirect
|
||||
k8s.io/klog/v2 v2.90.1 // indirect
|
||||
k8s.io/utils v0.0.0-20230209194617-a36077c30491 // indirect
|
||||
rsc.io/binaryregexp v0.2.0 // indirect
|
||||
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
|
||||
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
|
||||
)
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ import (
|
|||
tomb "gopkg.in/tomb.v2"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/trace"
|
||||
"github.com/crowdsecurity/go-cs-lib/trace"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/acquisition/configuration"
|
||||
cloudwatchacquisition "github.com/crowdsecurity/crowdsec/pkg/acquisition/modules/cloudwatch"
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
tomb "gopkg.in/tomb.v2"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/cstest"
|
||||
"github.com/crowdsecurity/go-cs-lib/cstest"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/acquisition/configuration"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/csconfig"
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/cstest"
|
||||
"github.com/crowdsecurity/go-cs-lib/cstest"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/cstest"
|
||||
"github.com/crowdsecurity/go-cs-lib/cstest"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/types"
|
||||
dockerTypes "github.com/docker/docker/api/types"
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"io"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
|
@ -22,7 +21,7 @@ import (
|
|||
"gopkg.in/tomb.v2"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/trace"
|
||||
"github.com/crowdsecurity/go-cs-lib/trace"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/acquisition/configuration"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/types"
|
||||
|
@ -371,12 +370,13 @@ func (f *FileSource) monitorNewFiles(out chan types.Event, t *tomb.Tomb) error {
|
|||
matched := false
|
||||
for _, pattern := range f.config.Filenames {
|
||||
logger.Debugf("Matching %s with %s", pattern, event.Name)
|
||||
matched, err = path.Match(pattern, event.Name)
|
||||
matched, err = filepath.Match(pattern, event.Name)
|
||||
if err != nil {
|
||||
logger.Errorf("Could not match pattern : %s", err)
|
||||
continue
|
||||
}
|
||||
if matched {
|
||||
logger.Debugf("Matched %s with %s", pattern, event.Name)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
"gopkg.in/tomb.v2"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/cstest"
|
||||
"github.com/crowdsecurity/go-cs-lib/cstest"
|
||||
|
||||
fileacquisition "github.com/crowdsecurity/crowdsec/pkg/acquisition/modules/file"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/types"
|
||||
|
@ -260,7 +260,7 @@ func TestLiveAcquisition(t *testing.T) {
|
|||
// if we do not have access to the file
|
||||
permDeniedFile = `C:\Windows\System32\config\SAM`
|
||||
permDeniedError = `unable to read C:\Windows\System32\config\SAM : open C:\Windows\System32\config\SAM: The process cannot access the file because it is being used by another process`
|
||||
testPattern = `test_files\\*.log` // the \ must be escaped for the yaml config
|
||||
testPattern = `test_files\*.log`
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
"gopkg.in/tomb.v2"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/trace"
|
||||
"github.com/crowdsecurity/go-cs-lib/trace"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/acquisition/configuration"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/types"
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/cstest"
|
||||
"github.com/crowdsecurity/go-cs-lib/cstest"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/types"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
|
|
@ -16,7 +16,7 @@ import (
|
|||
"gopkg.in/tomb.v2"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/trace"
|
||||
"github.com/crowdsecurity/go-cs-lib/trace"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/acquisition/configuration"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/types"
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
"gopkg.in/tomb.v2"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/cstest"
|
||||
"github.com/crowdsecurity/go-cs-lib/cstest"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/types"
|
||||
)
|
||||
|
|
|
@ -18,7 +18,7 @@ import (
|
|||
"gopkg.in/tomb.v2"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/trace"
|
||||
"github.com/crowdsecurity/go-cs-lib/trace"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/acquisition/configuration"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/types"
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/cstest"
|
||||
"github.com/crowdsecurity/go-cs-lib/cstest"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
"gopkg.in/yaml.v2"
|
||||
"k8s.io/apiserver/pkg/apis/audit"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/trace"
|
||||
"github.com/crowdsecurity/go-cs-lib/trace"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/acquisition/configuration"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/types"
|
||||
|
|
|
@ -433,7 +433,7 @@ func (s *S3Source) readFile(bucket string, key string) error {
|
|||
l.Time = time.Now().UTC()
|
||||
l.Process = true
|
||||
l.Module = s.GetName()
|
||||
l.Src = bucket
|
||||
l.Src = bucket + "/" + key
|
||||
var evt types.Event
|
||||
if !s.Config.UseTimeMachine {
|
||||
evt = types.Event{Line: l, Process: true, Type: types.LOG, ExpectMode: types.LIVE}
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/cstest"
|
||||
"github.com/crowdsecurity/go-cs-lib/cstest"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
"gopkg.in/tomb.v2"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/trace"
|
||||
"github.com/crowdsecurity/go-cs-lib/trace"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/acquisition/configuration"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/acquisition/modules/syslog/internal/parser/rfc3164"
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/cstest"
|
||||
"github.com/crowdsecurity/go-cs-lib/cstest"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/types"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
|
|
@ -17,7 +17,7 @@ import (
|
|||
"github.com/crowdsecurity/crowdsec/pkg/acquisition/configuration"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/types"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/waf"
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/trace"
|
||||
"github.com/crowdsecurity/go-cs-lib/trace"
|
||||
"github.com/google/uuid"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
|
|
@ -17,7 +17,7 @@ import (
|
|||
"gopkg.in/tomb.v2"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/trace"
|
||||
"github.com/crowdsecurity/go-cs-lib/trace"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/acquisition/configuration"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/types"
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/version"
|
||||
"github.com/crowdsecurity/go-cs-lib/version"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/models"
|
||||
)
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
log "github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/version"
|
||||
"github.com/crowdsecurity/go-cs-lib/version"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/models"
|
||||
)
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/version"
|
||||
"github.com/crowdsecurity/go-cs-lib/version"
|
||||
)
|
||||
|
||||
func TestNewRequestInvalid(t *testing.T) {
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
log "github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/version"
|
||||
"github.com/crowdsecurity/go-cs-lib/version"
|
||||
)
|
||||
|
||||
/*this is a ripoff of google/go-github approach :
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
"github.com/pkg/errors"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/ptr"
|
||||
"github.com/crowdsecurity/go-cs-lib/ptr"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/models"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/modelscapi"
|
||||
|
|
|
@ -12,8 +12,8 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/ptr"
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/version"
|
||||
"github.com/crowdsecurity/go-cs-lib/ptr"
|
||||
"github.com/crowdsecurity/go-cs-lib/version"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/models"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/modelscapi"
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
log "github.com/sirupsen/logrus"
|
||||
tomb "gopkg.in/tomb.v2"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/trace"
|
||||
"github.com/crowdsecurity/go-cs-lib/trace"
|
||||
)
|
||||
|
||||
type HeartBeatService service
|
||||
|
|
|
@ -18,9 +18,9 @@ import (
|
|||
"golang.org/x/exp/slices"
|
||||
"gopkg.in/tomb.v2"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/ptr"
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/trace"
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/version"
|
||||
"github.com/crowdsecurity/go-cs-lib/ptr"
|
||||
"github.com/crowdsecurity/go-cs-lib/trace"
|
||||
"github.com/crowdsecurity/go-cs-lib/version"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/apiclient"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/csconfig"
|
||||
|
@ -84,7 +84,7 @@ func (a *apic) FetchScenariosListFromDB() ([]string, error) {
|
|||
scenarios := make([]string, 0)
|
||||
machines, err := a.dbClient.ListMachines()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "while listing machines")
|
||||
return nil, fmt.Errorf("while listing machines: %w", err)
|
||||
}
|
||||
//merge all scenarios together
|
||||
for _, v := range machines {
|
||||
|
@ -189,16 +189,16 @@ func NewAPIC(config *csconfig.OnlineApiClientCfg, dbClient *database.Client, con
|
|||
password := strfmt.Password(config.Credentials.Password)
|
||||
apiURL, err := url.Parse(config.Credentials.URL)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "while parsing '%s'", config.Credentials.URL)
|
||||
return nil, fmt.Errorf("while parsing '%s': %w", config.Credentials.URL, err)
|
||||
}
|
||||
papiURL, err := url.Parse(config.Credentials.PapiURL)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "while parsing '%s'", config.Credentials.PapiURL)
|
||||
return nil, fmt.Errorf("while parsing '%s': %w", config.Credentials.PapiURL, err)
|
||||
}
|
||||
|
||||
ret.scenarioList, err = ret.FetchScenariosListFromDB()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "while fetching scenarios from db")
|
||||
return nil, fmt.Errorf("while fetching scenarios from db: %w", err)
|
||||
}
|
||||
ret.apiClient, err = apiclient.NewClient(&apiclient.Config{
|
||||
MachineID: config.Credentials.Login,
|
||||
|
@ -211,14 +211,14 @@ func NewAPIC(config *csconfig.OnlineApiClientCfg, dbClient *database.Client, con
|
|||
UpdateScenario: ret.FetchScenariosListFromDB,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "while creating api client")
|
||||
return nil, fmt.Errorf("while creating api client: %w", err)
|
||||
}
|
||||
|
||||
// The watcher will be authenticated by the RoundTripper the first time it will call CAPI
|
||||
// Explicit authentication will provoke an useless supplementary call to CAPI
|
||||
scenarios, err := ret.FetchScenariosListFromDB()
|
||||
if err != nil {
|
||||
return ret, errors.Wrapf(err, "get scenario in db: %s", err)
|
||||
return ret, fmt.Errorf("get scenario in db: %w", err)
|
||||
}
|
||||
|
||||
authResp, _, err := ret.apiClient.Auth.AuthenticateWatcher(context.Background(), models.WatcherAuthRequest{
|
||||
|
@ -227,11 +227,11 @@ func NewAPIC(config *csconfig.OnlineApiClientCfg, dbClient *database.Client, con
|
|||
Scenarios: scenarios,
|
||||
})
|
||||
if err != nil {
|
||||
return ret, errors.Wrapf(err, "authenticate watcher (%s)", config.Credentials.Login)
|
||||
return ret, fmt.Errorf("authenticate watcher (%s): %w", config.Credentials.Login, err)
|
||||
}
|
||||
|
||||
if err := ret.apiClient.GetClient().Transport.(*apiclient.JWTTransport).Expiration.UnmarshalText([]byte(authResp.Expire)); err != nil {
|
||||
return ret, errors.Wrap(err, "unable to parse jwt expiration")
|
||||
return ret, fmt.Errorf("unable to parse jwt expiration: %w", err)
|
||||
}
|
||||
|
||||
ret.apiClient.GetClient().Transport.(*apiclient.JWTTransport).Token = authResp.Token
|
||||
|
@ -375,7 +375,7 @@ func (a *apic) CAPIPullIsOld() (bool, error) {
|
|||
alerts = alerts.Where(alert.CreatedAtGTE(time.Now().UTC().Add(-time.Duration(1*time.Hour + 30*time.Minute)))) //nolint:unconvert
|
||||
count, err := alerts.Count(a.dbClient.CTX)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "while looking for CAPI alert")
|
||||
return false, fmt.Errorf("while looking for CAPI alert: %w", err)
|
||||
}
|
||||
if count > 0 {
|
||||
log.Printf("last CAPI pull is newer than 1h30, skip.")
|
||||
|
@ -401,11 +401,11 @@ func (a *apic) HandleDeletedDecisions(deletedDecisions []*models.Decision, delet
|
|||
|
||||
dbCliRet, _, err := a.dbClient.SoftDeleteDecisionsWithFilter(filter)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "deleting decisions error")
|
||||
return 0, fmt.Errorf("deleting decisions error: %w", err)
|
||||
}
|
||||
dbCliDel, err := strconv.Atoi(dbCliRet)
|
||||
if err != nil {
|
||||
return 0, errors.Wrapf(err, "converting db ret %d", dbCliDel)
|
||||
return 0, fmt.Errorf("converting db ret %d: %w", dbCliDel, err)
|
||||
}
|
||||
updateCounterForDecision(delete_counters, decision.Origin, decision.Scenario, dbCliDel)
|
||||
nbDeleted += dbCliDel
|
||||
|
@ -431,11 +431,11 @@ func (a *apic) HandleDeletedDecisionsV3(deletedDecisions []*modelscapi.GetDecisi
|
|||
|
||||
dbCliRet, _, err := a.dbClient.SoftDeleteDecisionsWithFilter(filter)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "deleting decisions error")
|
||||
return 0, fmt.Errorf("deleting decisions error: %w", err)
|
||||
}
|
||||
dbCliDel, err := strconv.Atoi(dbCliRet)
|
||||
if err != nil {
|
||||
return 0, errors.Wrapf(err, "converting db ret %d", dbCliDel)
|
||||
return 0, fmt.Errorf("converting db ret %d: %w", dbCliDel, err)
|
||||
}
|
||||
updateCounterForDecision(delete_counters, ptr.Of(types.CAPIOrigin), nil, dbCliDel)
|
||||
nbDeleted += dbCliDel
|
||||
|
@ -575,7 +575,7 @@ func (a *apic) PullTop(forcePull bool) error {
|
|||
|
||||
data, _, err := a.apiClient.Decisions.GetStreamV3(context.Background(), apiclient.DecisionsStreamOpts{Startup: a.startup})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "get stream")
|
||||
return fmt.Errorf("get stream: %w", err)
|
||||
}
|
||||
a.startup = false
|
||||
/*to count additions/deletions across lists*/
|
||||
|
@ -610,12 +610,12 @@ func (a *apic) PullTop(forcePull bool) error {
|
|||
|
||||
err = a.SaveAlerts(alertsFromCapi, add_counters, delete_counters)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "while saving alerts")
|
||||
return fmt.Errorf("while saving alerts: %w", err)
|
||||
}
|
||||
|
||||
// update blocklists
|
||||
if err := a.UpdateBlocklists(data.Links, add_counters); err != nil {
|
||||
return errors.Wrap(err, "while updating blocklists")
|
||||
return fmt.Errorf("while updating blocklists: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -670,7 +670,7 @@ func (a *apic) SaveAlerts(alertsFromCapi []*models.Alert, add_counters map[strin
|
|||
}
|
||||
alertID, inserted, deleted, err := a.dbClient.UpdateCommunityBlocklist(alertsFromCapi[idx])
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "while saving alert from %s", *alertsFromCapi[idx].Source.Scope)
|
||||
return fmt.Errorf("while saving alert from %s: %w", *alertsFromCapi[idx].Source.Scope, err)
|
||||
}
|
||||
log.Printf("%s : added %d entries, deleted %d entries (alert:%d)", *alertsFromCapi[idx].Source.Scope, inserted, deleted, alertID)
|
||||
}
|
||||
|
@ -689,7 +689,7 @@ func (a *apic) ShouldForcePullBlocklist(blocklist *modelscapi.BlocklistLink) (bo
|
|||
log.Debugf("no alert found for %s, force refresh", *blocklist.Name)
|
||||
return true, nil
|
||||
}
|
||||
return false, errors.Wrap(err, "while getting alert")
|
||||
return false, fmt.Errorf("while getting alert: %w", err)
|
||||
}
|
||||
decisionQuery := a.dbClient.Ent.Decision.Query()
|
||||
decisionQuery.Where(decision.HasOwnerWith(alert.IDEQ(alertInstance.ID)))
|
||||
|
@ -699,7 +699,7 @@ func (a *apic) ShouldForcePullBlocklist(blocklist *modelscapi.BlocklistLink) (bo
|
|||
log.Debugf("no decision found for %s, force refresh", *blocklist.Name)
|
||||
return true, nil
|
||||
}
|
||||
return false, errors.Wrap(err, "while getting decision")
|
||||
return false, fmt.Errorf("while getting decision: %w", err)
|
||||
}
|
||||
if firstDecision == nil || firstDecision.Until == nil || firstDecision.Until.Sub(time.Now().UTC()) < (a.pullInterval+15*time.Minute) {
|
||||
log.Debugf("at least one decision found for %s, expire soon, force refresh", *blocklist.Name)
|
||||
|
@ -719,7 +719,7 @@ func (a *apic) UpdateBlocklists(links *modelscapi.GetDecisionsStreamResponseLink
|
|||
// we can use the same baseUrl as the urls are absolute and the parse will take care of it
|
||||
defaultClient, err := apiclient.NewDefaultClient(a.apiClient.BaseURL, "", "", nil)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "while creating default client")
|
||||
return fmt.Errorf("while creating default client: %w", err)
|
||||
}
|
||||
for _, blocklist := range links.Blocklists {
|
||||
if blocklist.Scope == nil {
|
||||
|
@ -732,19 +732,19 @@ func (a *apic) UpdateBlocklists(links *modelscapi.GetDecisionsStreamResponseLink
|
|||
}
|
||||
forcePull, err := a.ShouldForcePullBlocklist(blocklist)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "while checking if we should force pull blocklist %s", *blocklist.Name)
|
||||
return fmt.Errorf("while checking if we should force pull blocklist %s: %w", *blocklist.Name, err)
|
||||
}
|
||||
blocklistConfigItemName := fmt.Sprintf("blocklist:%s:last_pull", *blocklist.Name)
|
||||
var lastPullTimestamp *string
|
||||
if !forcePull {
|
||||
lastPullTimestamp, err = a.dbClient.GetConfigItem(blocklistConfigItemName)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "while getting last pull timestamp for blocklist %s", *blocklist.Name)
|
||||
return fmt.Errorf("while getting last pull timestamp for blocklist %s: %w", *blocklist.Name, err)
|
||||
}
|
||||
}
|
||||
decisions, has_changed, err := defaultClient.Decisions.GetDecisionsFromBlocklist(context.Background(), blocklist, lastPullTimestamp)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "while getting decisions from blocklist %s", *blocklist.Name)
|
||||
return fmt.Errorf("while getting decisions from blocklist %s: %w", *blocklist.Name, err)
|
||||
}
|
||||
if !has_changed {
|
||||
if lastPullTimestamp == nil {
|
||||
|
@ -756,7 +756,7 @@ func (a *apic) UpdateBlocklists(links *modelscapi.GetDecisionsStreamResponseLink
|
|||
}
|
||||
err = a.dbClient.SetConfigItem(blocklistConfigItemName, time.Now().UTC().Format(http.TimeFormat))
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "while setting last pull timestamp for blocklist %s", *blocklist.Name)
|
||||
return fmt.Errorf("while setting last pull timestamp for blocklist %s: %w", *blocklist.Name, err)
|
||||
}
|
||||
if len(decisions) == 0 {
|
||||
log.Infof("blocklist %s has no decisions", *blocklist.Name)
|
||||
|
@ -770,7 +770,7 @@ func (a *apic) UpdateBlocklists(links *modelscapi.GetDecisionsStreamResponseLink
|
|||
|
||||
err = a.SaveAlerts(alertsFromCapi, add_counters, nil)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "while saving alert from blocklist %s", *blocklist.Name)
|
||||
return fmt.Errorf("while saving alert from blocklist %s: %w", *blocklist.Name, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -7,9 +7,9 @@ import (
|
|||
log "github.com/sirupsen/logrus"
|
||||
"golang.org/x/exp/slices"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/ptr"
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/trace"
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/version"
|
||||
"github.com/crowdsecurity/go-cs-lib/ptr"
|
||||
"github.com/crowdsecurity/go-cs-lib/trace"
|
||||
"github.com/crowdsecurity/go-cs-lib/version"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/models"
|
||||
)
|
||||
|
@ -81,7 +81,7 @@ func (a *apic) SendMetrics(stop chan (bool)) {
|
|||
const checkInt = 20 * time.Second
|
||||
|
||||
// intervals must always be > 0
|
||||
metInts := []time.Duration{1, a.metricsIntervalFirst, a.metricsInterval}
|
||||
metInts := []time.Duration{1*time.Millisecond, a.metricsIntervalFirst, a.metricsInterval}
|
||||
|
||||
log.Infof("Start send metrics to CrowdSec Central API (interval: %s once, then %s)",
|
||||
metInts[1].Round(time.Second), metInts[2])
|
||||
|
@ -94,8 +94,6 @@ func (a *apic) SendMetrics(stop chan (bool)) {
|
|||
return metInts[count]
|
||||
}
|
||||
|
||||
// store the list of machine IDs to compare
|
||||
// with the next list
|
||||
machineIDs := []string{}
|
||||
|
||||
reloadMachineIDs := func() {
|
||||
|
@ -107,6 +105,10 @@ func (a *apic) SendMetrics(stop chan (bool)) {
|
|||
machineIDs = ids
|
||||
}
|
||||
|
||||
// store the list of machine IDs to compare
|
||||
// with the next list
|
||||
reloadMachineIDs()
|
||||
|
||||
checkTicker := time.NewTicker(checkInt)
|
||||
metTicker := time.NewTicker(nextMetInt())
|
||||
|
||||
|
@ -121,9 +123,10 @@ func (a *apic) SendMetrics(stop chan (bool)) {
|
|||
reloadMachineIDs()
|
||||
if !slices.Equal(oldIDs, machineIDs) {
|
||||
log.Infof("capi metrics: machines changed, immediate send")
|
||||
metTicker.Reset(1)
|
||||
metTicker.Reset(1*time.Millisecond)
|
||||
}
|
||||
case <-metTicker.C:
|
||||
metTicker.Stop()
|
||||
metrics, err := a.GetMetrics()
|
||||
if err != nil {
|
||||
log.Errorf("unable to get metrics (%s), will retry", err)
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/version"
|
||||
"github.com/crowdsecurity/go-cs-lib/version"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/apiclient"
|
||||
)
|
||||
|
@ -26,15 +26,15 @@ func TestAPICSendMetrics(t *testing.T) {
|
|||
}{
|
||||
{
|
||||
name: "basic",
|
||||
duration: time.Millisecond * 30,
|
||||
metricsInterval: time.Millisecond * 5,
|
||||
duration: time.Millisecond * 60,
|
||||
metricsInterval: time.Millisecond * 10,
|
||||
expectedCalls: 5,
|
||||
setUp: func(api *apic) {},
|
||||
},
|
||||
{
|
||||
name: "with some metrics",
|
||||
duration: time.Millisecond * 30,
|
||||
metricsInterval: time.Millisecond * 5,
|
||||
duration: time.Millisecond * 60,
|
||||
metricsInterval: time.Millisecond * 10,
|
||||
expectedCalls: 5,
|
||||
setUp: func(api *apic) {
|
||||
api.dbClient.Ent.Machine.Delete().ExecX(context.Background())
|
||||
|
|
|
@ -20,9 +20,9 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
"gopkg.in/tomb.v2"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/cstest"
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/ptr"
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/version"
|
||||
"github.com/crowdsecurity/go-cs-lib/cstest"
|
||||
"github.com/crowdsecurity/go-cs-lib/ptr"
|
||||
"github.com/crowdsecurity/go-cs-lib/version"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/apiclient"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/csconfig"
|
||||
|
|
|
@ -21,7 +21,7 @@ import (
|
|||
"gopkg.in/natefinch/lumberjack.v2"
|
||||
"gopkg.in/tomb.v2"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/trace"
|
||||
"github.com/crowdsecurity/go-cs-lib/trace"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/apiclient"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/apiserver/controllers"
|
||||
|
@ -106,7 +106,7 @@ func NewServer(config *csconfig.LocalApiServerCfg) (*APIServer, error) {
|
|||
var flushScheduler *gocron.Scheduler
|
||||
dbClient, err := database.NewClient(config.DbConfig)
|
||||
if err != nil {
|
||||
return &APIServer{}, errors.Wrap(err, "unable to init database client")
|
||||
return &APIServer{}, fmt.Errorf("unable to init database client: %w", err)
|
||||
}
|
||||
|
||||
if config.DbConfig.Flush != nil {
|
||||
|
@ -129,7 +129,7 @@ func NewServer(config *csconfig.LocalApiServerCfg) (*APIServer, error) {
|
|||
|
||||
if config.TrustedProxies != nil && config.UseForwardedForHeaders {
|
||||
if err := router.SetTrustedProxies(*config.TrustedProxies); err != nil {
|
||||
return &APIServer{}, errors.Wrap(err, "while setting trusted_proxies")
|
||||
return &APIServer{}, fmt.Errorf("while setting trusted_proxies: %w", err)
|
||||
}
|
||||
router.ForwardedByClientIP = true
|
||||
} else {
|
||||
|
@ -140,7 +140,7 @@ func NewServer(config *csconfig.LocalApiServerCfg) (*APIServer, error) {
|
|||
clog := log.New()
|
||||
|
||||
if err := types.ConfigureLogger(clog); err != nil {
|
||||
return nil, errors.Wrap(err, "while configuring gin logger")
|
||||
return nil, fmt.Errorf("while configuring gin logger: %w", err)
|
||||
}
|
||||
if config.LogLevel != nil {
|
||||
clog.SetLevel(*config.LogLevel)
|
||||
|
@ -305,7 +305,7 @@ func (s *APIServer) GetTLSConfig() (*tls.Config, error) {
|
|||
log.Infof("(tls) Client Auth Type set to %s", clientAuthType.String())
|
||||
caCert, err = os.ReadFile(s.TLS.CACertPath)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Error opening cert file")
|
||||
return nil, fmt.Errorf("while opening cert file: %w", err)
|
||||
}
|
||||
caCertPool, err = x509.SystemCertPool()
|
||||
if err != nil {
|
||||
|
@ -330,7 +330,7 @@ func (s *APIServer) Run(apiReady chan bool) error {
|
|||
defer trace.CatchPanic("lapi/runServer")
|
||||
tlsCfg, err := s.GetTLSConfig()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "while creating TLS config")
|
||||
return fmt.Errorf("while creating TLS config: %w", err)
|
||||
}
|
||||
s.httpServer = &http.Server{
|
||||
Addr: s.URL,
|
||||
|
@ -448,7 +448,7 @@ func (s *APIServer) Shutdown() error {
|
|||
}
|
||||
s.httpServerTomb.Kill(nil)
|
||||
if err := s.httpServerTomb.Wait(); err != nil {
|
||||
return errors.Wrap(err, "while waiting on httpServerTomb")
|
||||
return fmt.Errorf("while waiting on httpServerTomb: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -461,7 +461,7 @@ func (s *APIServer) InitController() error {
|
|||
|
||||
err := s.controller.Init()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "controller init")
|
||||
return fmt.Errorf("controller init: %w", err)
|
||||
}
|
||||
if s.TLS != nil {
|
||||
var cacheExpiration time.Duration
|
||||
|
@ -477,7 +477,7 @@ func (s *APIServer) InitController() error {
|
|||
"type": "agent",
|
||||
}))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "while creating TLS auth for agents")
|
||||
return fmt.Errorf("while creating TLS auth for agents: %w", err)
|
||||
}
|
||||
s.controller.HandlerV1.Middlewares.APIKey.TlsAuth, err = v1.NewTLSAuth(s.TLS.AllowedBouncersOU, s.TLS.CRLPath,
|
||||
cacheExpiration,
|
||||
|
@ -486,7 +486,7 @@ func (s *APIServer) InitController() error {
|
|||
"type": "bouncer",
|
||||
}))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "while creating TLS auth for bouncers")
|
||||
return fmt.Errorf("while creating TLS auth for bouncers: %w", err)
|
||||
}
|
||||
}
|
||||
return err
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/version"
|
||||
"github.com/crowdsecurity/go-cs-lib/version"
|
||||
|
||||
middlewares "github.com/crowdsecurity/crowdsec/pkg/apiserver/middlewares/v1"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/models"
|
||||
|
|
|
@ -8,7 +8,10 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/trace"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"gopkg.in/tomb.v2"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/trace"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/apiclient"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/csconfig"
|
||||
|
@ -16,9 +19,6 @@ import (
|
|||
"github.com/crowdsecurity/crowdsec/pkg/longpollclient"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/models"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/types"
|
||||
"github.com/pkg/errors"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"gopkg.in/tomb.v2"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -103,7 +103,7 @@ func NewPAPI(apic *apic, dbClient *database.Client, consoleConfig *csconfig.Cons
|
|||
})
|
||||
|
||||
if err != nil {
|
||||
return &Papi{}, errors.Wrap(err, "failed to create PAPI client")
|
||||
return &Papi{}, fmt.Errorf("failed to create PAPI client: %w", err)
|
||||
}
|
||||
|
||||
channels := &OperationChannels{
|
||||
|
@ -231,7 +231,7 @@ func (p *Papi) Pull() error {
|
|||
if lastTimestampStr == nil {
|
||||
binTime, err := lastTimestamp.MarshalText()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to marshal last timestamp")
|
||||
return fmt.Errorf("failed to marshal last timestamp: %w", err)
|
||||
}
|
||||
if err := p.DBClient.SetConfigItem(PapiPullKey, string(binTime)); err != nil {
|
||||
p.Logger.Errorf("error setting papi pull last key: %s", err)
|
||||
|
@ -240,7 +240,7 @@ func (p *Papi) Pull() error {
|
|||
}
|
||||
} else {
|
||||
if err := lastTimestamp.UnmarshalText([]byte(*lastTimestampStr)); err != nil {
|
||||
return errors.Wrap(err, "failed to unmarshal last timestamp")
|
||||
return fmt.Errorf("failed to unmarshal last timestamp: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -251,7 +251,7 @@ func (p *Papi) Pull() error {
|
|||
newTime := time.Now().UTC()
|
||||
binTime, err := newTime.MarshalText()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to marshal last timestamp")
|
||||
return fmt.Errorf("failed to marshal last timestamp: %w", err)
|
||||
}
|
||||
|
||||
err = p.handleEvent(event, false)
|
||||
|
@ -261,7 +261,7 @@ func (p *Papi) Pull() error {
|
|||
}
|
||||
|
||||
if err := p.DBClient.SetConfigItem(PapiPullKey, string(binTime)); err != nil {
|
||||
return errors.Wrap(err, "failed to update last timestamp")
|
||||
return fmt.Errorf("failed to update last timestamp: %w", err)
|
||||
} else {
|
||||
logger.Debugf("set last timestamp to %s", newTime)
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/ptr"
|
||||
"github.com/crowdsecurity/go-cs-lib/ptr"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/apiclient"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/models"
|
||||
|
|
|
@ -12,8 +12,8 @@ import (
|
|||
log "github.com/sirupsen/logrus"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/ptr"
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/yamlpatch"
|
||||
"github.com/crowdsecurity/go-cs-lib/ptr"
|
||||
"github.com/crowdsecurity/go-cs-lib/yamlpatch"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/apiclient"
|
||||
)
|
||||
|
@ -234,6 +234,21 @@ func (c *Config) LoadAPIServer() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
if c.API.Server.Enable == nil {
|
||||
// if the option is not present, it is enabled by default
|
||||
c.API.Server.Enable = ptr.Of(true)
|
||||
}
|
||||
|
||||
if !*c.API.Server.Enable {
|
||||
log.Warning("crowdsec local API is disabled because 'enable' is set to false")
|
||||
c.DisableAPI = true
|
||||
return nil
|
||||
}
|
||||
|
||||
if c.DisableAPI {
|
||||
return nil
|
||||
}
|
||||
|
||||
//inherit log level from common, then api->server
|
||||
var logLevel log.Level
|
||||
if c.API.Server.LogLevel != nil {
|
||||
|
@ -253,9 +268,11 @@ func (c *Config) LoadAPIServer() error {
|
|||
return fmt.Errorf("loading online client credentials: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if c.API.Server.OnlineClient == nil || c.API.Server.OnlineClient.Credentials == nil {
|
||||
log.Printf("push and pull to Central API disabled")
|
||||
}
|
||||
|
||||
if err := c.LoadDBConfig(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -268,55 +285,37 @@ func (c *Config) LoadAPIServer() error {
|
|||
log.Infof("loaded capi whitelist from %s: %d IPs, %d CIDRs", c.API.Server.CapiWhitelistsPath, len(c.API.Server.CapiWhitelists.Ips), len(c.API.Server.CapiWhitelists.Cidrs))
|
||||
}
|
||||
|
||||
if c.API.Server.Enable == nil {
|
||||
// if the option is not present, it is enabled by default
|
||||
c.API.Server.Enable = ptr.Of(true)
|
||||
}
|
||||
|
||||
if !*c.API.Server.Enable {
|
||||
log.Warning("crowdsec local API is disabled because 'enable' is set to false")
|
||||
c.DisableAPI = true
|
||||
return nil
|
||||
}
|
||||
|
||||
if c.DisableAPI {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := c.LoadCommon(); err != nil {
|
||||
return fmt.Errorf("loading common configuration: %s", err)
|
||||
}
|
||||
|
||||
c.API.Server.LogDir = c.Common.LogDir
|
||||
c.API.Server.LogMedia = c.Common.LogMedia
|
||||
c.API.Server.CompressLogs = c.Common.CompressLogs
|
||||
c.API.Server.LogMaxSize = c.Common.LogMaxSize
|
||||
c.API.Server.LogMaxAge = c.Common.LogMaxAge
|
||||
c.API.Server.LogMaxFiles = c.Common.LogMaxFiles
|
||||
|
||||
if c.API.Server.UseForwardedForHeaders && c.API.Server.TrustedProxies == nil {
|
||||
c.API.Server.TrustedProxies = &[]string{"0.0.0.0/0"}
|
||||
}
|
||||
|
||||
if c.API.Server.TrustedProxies != nil {
|
||||
c.API.Server.UseForwardedForHeaders = true
|
||||
}
|
||||
|
||||
if err := c.API.Server.LoadProfiles(); err != nil {
|
||||
return fmt.Errorf("while loading profiles for LAPI: %w", err)
|
||||
}
|
||||
|
||||
if c.API.Server.ConsoleConfigPath == "" {
|
||||
c.API.Server.ConsoleConfigPath = DefaultConsoleConfigFilePath
|
||||
}
|
||||
|
||||
if err := c.API.Server.LoadConsoleConfig(); err != nil {
|
||||
return fmt.Errorf("while loading console options: %w", err)
|
||||
}
|
||||
|
||||
if c.API.Server.OnlineClient != nil && c.API.Server.OnlineClient.CredentialsFilePath != "" {
|
||||
if err := c.API.Server.OnlineClient.Load(); err != nil {
|
||||
return fmt.Errorf("loading online client credentials: %w", err)
|
||||
}
|
||||
}
|
||||
if c.API.Server.OnlineClient == nil || c.API.Server.OnlineClient.Credentials == nil {
|
||||
log.Printf("push and pull to Central API disabled")
|
||||
}
|
||||
|
||||
if c.API.CTI != nil {
|
||||
if err := c.API.CTI.Load(); err != nil {
|
||||
return fmt.Errorf("loading CTI configuration: %w", err)
|
||||
|
|
|
@ -11,8 +11,8 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/cstest"
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/ptr"
|
||||
"github.com/crowdsecurity/go-cs-lib/cstest"
|
||||
"github.com/crowdsecurity/go-cs-lib/ptr"
|
||||
)
|
||||
|
||||
func TestLoadLocalApiClientCfg(t *testing.T) {
|
||||
|
@ -234,6 +234,7 @@ func TestLoadAPIServer(t *testing.T) {
|
|||
DisableAPI: false,
|
||||
},
|
||||
expected: &LocalApiServerCfg{
|
||||
Enable: ptr.Of(true),
|
||||
PapiLogLevel: &logLevel,
|
||||
},
|
||||
expectedErr: "no database configuration provided",
|
||||
|
|
|
@ -8,9 +8,9 @@ import (
|
|||
log "github.com/sirupsen/logrus"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/csstring"
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/ptr"
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/yamlpatch"
|
||||
"github.com/crowdsecurity/go-cs-lib/csstring"
|
||||
"github.com/crowdsecurity/go-cs-lib/ptr"
|
||||
"github.com/crowdsecurity/go-cs-lib/yamlpatch"
|
||||
)
|
||||
|
||||
// defaultConfigDir is the base path to all configuration files, to be overridden in the Makefile */
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/cstest"
|
||||
"github.com/crowdsecurity/go-cs-lib/cstest"
|
||||
)
|
||||
|
||||
func TestNormalLoad(t *testing.T) {
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
log "github.com/sirupsen/logrus"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/ptr"
|
||||
"github.com/crowdsecurity/go-cs-lib/ptr"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/fflag"
|
||||
)
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
log "github.com/sirupsen/logrus"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/ptr"
|
||||
"github.com/crowdsecurity/go-cs-lib/ptr"
|
||||
)
|
||||
|
||||
var DataDir string // FIXME: find a better way to pass this to the waf
|
||||
|
|
|
@ -5,8 +5,8 @@ import (
|
|||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/cstest"
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/ptr"
|
||||
"github.com/crowdsecurity/go-cs-lib/cstest"
|
||||
"github.com/crowdsecurity/go-cs-lib/ptr"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"entgo.io/ent/dialect"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/ptr"
|
||||
"github.com/crowdsecurity/go-cs-lib/ptr"
|
||||
)
|
||||
|
||||
var DEFAULT_MAX_OPEN_CONNS = 100
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/ptr"
|
||||
"github.com/crowdsecurity/go-cs-lib/ptr"
|
||||
)
|
||||
|
||||
func TestLoadDBConfig(t *testing.T) {
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/yamlpatch"
|
||||
"github.com/crowdsecurity/go-cs-lib/yamlpatch"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/models"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
|
|
@ -3,7 +3,7 @@ package csconfig
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/cstest"
|
||||
"github.com/crowdsecurity/go-cs-lib/cstest"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/yamlpatch"
|
||||
"github.com/crowdsecurity/go-cs-lib/yamlpatch"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/cstest"
|
||||
"github.com/crowdsecurity/go-cs-lib/cstest"
|
||||
)
|
||||
|
||||
func TestSimulationLoading(t *testing.T) {
|
||||
|
|
|
@ -19,8 +19,8 @@ import (
|
|||
"gopkg.in/tomb.v2"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/csstring"
|
||||
"github.com/crowdsecurity/go-cs-lib/pkg/slicetools"
|
||||
"github.com/crowdsecurity/go-cs-lib/csstring"
|
||||
"github.com/crowdsecurity/go-cs-lib/slicetools"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/csconfig"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/models"
|
||||
|
@ -323,7 +323,7 @@ func (pb *PluginBroker) pushNotificationsToPlugin(pluginName string, alerts []*m
|
|||
return nil
|
||||
}
|
||||
|
||||
message, err := formatAlerts(pb.pluginConfigByName[pluginName].Format, alerts)
|
||||
message, err := FormatAlerts(pb.pluginConfigByName[pluginName].Format, alerts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -407,7 +407,7 @@ func getHandshake() (plugin.HandshakeConfig, error) {
|
|||
return handshake, nil
|
||||
}
|
||||
|
||||
func formatAlerts(format string, alerts []*models.Alert) (string, error) {
|
||||
func FormatAlerts(format string, alerts []*models.Alert) (string, error) {
|
||||
template, err := template.New("").Funcs(sprig.TxtFuncMap()).Funcs(funcMap()).Parse(format)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
|
@ -43,7 +43,7 @@ func (s *PluginSuite) SetupSuite() {
|
|||
s.buildDir, err = os.MkdirTemp("", "cs_plugin_test_build")
|
||||
require.NoError(t, err)
|
||||
|
||||
s.builtBinary = path.Join(s.buildDir, "notification-dummy")
|
||||
s.builtBinary = filepath.Join(s.buildDir, "notification-dummy")
|
||||
|
||||
if runtime.GOOS == "windows" {
|
||||
s.builtBinary += ".exe"
|
||||
|
@ -101,15 +101,15 @@ func (s *PluginSuite) SetupSubTest() {
|
|||
s.runDir, err = os.MkdirTemp("", "cs_plugin_test")
|
||||
require.NoError(t, err)
|
||||
|
||||
s.pluginDir = path.Join(s.runDir, "bin")
|
||||
err = os.MkdirAll(path.Join(s.runDir, "bin"), 0o755)
|
||||
s.pluginDir = filepath.Join(s.runDir, "bin")
|
||||
err = os.MkdirAll(filepath.Join(s.runDir, "bin"), 0o755)
|
||||
require.NoError(t, err, "while creating bin dir")
|
||||
|
||||
s.notifDir = path.Join(s.runDir, "config")
|
||||
s.notifDir = filepath.Join(s.runDir, "config")
|
||||
err = os.MkdirAll(s.notifDir, 0o755)
|
||||
require.NoError(t, err, "while creating config dir")
|
||||
|
||||
s.pluginBinary = path.Join(s.pluginDir, "notification-dummy")
|
||||
s.pluginBinary = filepath.Join(s.pluginDir, "notification-dummy")
|
||||
|
||||
if runtime.GOOS == "windows" {
|
||||
s.pluginBinary += ".exe"
|
||||
|
@ -120,7 +120,7 @@ func (s *PluginSuite) SetupSubTest() {
|
|||
err = os.Chmod(s.pluginBinary, 0o744)
|
||||
require.NoError(t, err, "chmod 0744 %s", s.pluginBinary)
|
||||
|
||||
s.pluginConfig = path.Join(s.notifDir, "dummy.yaml")
|
||||
s.pluginConfig = filepath.Join(s.notifDir, "dummy.yaml")
|
||||
err = copyFile("testdata/dummy.yaml", s.pluginConfig)
|
||||
require.NoError(t, err, "while copying plugin config")
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue