This commit is contained in:
Sebastien Blot 2023-11-10 17:56:04 +01:00
parent d6f9bbc0c3
commit 07d463f4f0
No known key found for this signature in database
GPG key ID: DFC2902F40449F6A
5 changed files with 12 additions and 28 deletions

View file

@ -34,7 +34,7 @@ func initCrowdsec(cConfig *csconfig.Config, hub *cwhub.Hub) (*parser.Parsers, er
return nil, fmt.Errorf("while loading scenarios: %w", err)
}
if err := waf.LoadWaapRules(); err != nil {
if err := waf.LoadWaapRules(hub); err != nil {
return nil, fmt.Errorf("while loading waap rules: %w", err)
}

View file

@ -7,7 +7,6 @@ import (
"net/http"
"github.com/crowdsecurity/crowdsec/pkg/acquisition/configuration"
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
"github.com/crowdsecurity/crowdsec/pkg/types"
"github.com/crowdsecurity/crowdsec/pkg/waf"
"github.com/crowdsecurity/go-cs-lib/trace"
@ -159,12 +158,6 @@ func (w *WaapSource) Configure(yamlConfig []byte, logger *log.Entry) error {
w.WaapRunners = make([]WaapRunner, w.config.Routines)
hub, err := cwhub.GetHub()
if err != nil {
return fmt.Errorf("unable to load hub : %s", err)
}
for nbRoutine := 0; nbRoutine < w.config.Routines; nbRoutine++ {
wafUUID := uuid.New().String()
@ -178,7 +171,7 @@ func (w *WaapSource) Configure(yamlConfig []byte, logger *log.Entry) error {
}),
WaapRuntime: &wrt,
}
err := runner.Init(hub.GetDataDir())
err := runner.Init(waapCfg.GetDataDir())
if err != nil {
return fmt.Errorf("unable to initialize runner : %s", err)
}

View file

@ -11,11 +11,11 @@ import (
var waapRules map[string]WaapCollectionConfig = make(map[string]WaapCollectionConfig) //FIXME: would probably be better to have a struct for this
func LoadWaapRules() error {
hub, err := cwhub.GetHub()
if err != nil {
return fmt.Errorf("unable to load hub : %s", err)
}
var hub *cwhub.Hub //FIXME: this is a temporary hack to make the hub available in the package
func LoadWaapRules(hubInstance *cwhub.Hub) error {
hub = hubInstance
for _, hubWafRuleItem := range hub.GetItemMap(cwhub.WAAP_RULES) {
//log.Infof("loading %s", hubWafRuleItem.LocalPath)

View file

@ -149,11 +149,6 @@ func (wc *WaapConfig) LoadByPath(file string) error {
}
func (wc *WaapConfig) Load(configName string) error {
hub, err := cwhub.GetHub()
if err != nil {
return fmt.Errorf("unable to load hub : %s", err)
}
waapConfigs := hub.GetItemMap(cwhub.WAAP_CONFIGS)
for _, hubWaapConfigItem := range waapConfigs {
@ -164,7 +159,7 @@ func (wc *WaapConfig) Load(configName string) error {
continue
}
wc.Logger.Infof("loading %s", hubWaapConfigItem.LocalPath)
err = wc.LoadByPath(hubWaapConfigItem.LocalPath)
err := wc.LoadByPath(hubWaapConfigItem.LocalPath)
if err != nil {
return fmt.Errorf("unable to load waap-config %s : %s", hubWaapConfigItem.LocalPath, err)
}
@ -174,6 +169,10 @@ func (wc *WaapConfig) Load(configName string) error {
return fmt.Errorf("no waap-config found for %s", configName)
}
func (wc *WaapConfig) GetDataDir() string {
return hub.GetDataDir()
}
func (wc *WaapConfig) Build() (*WaapRuntimeConfig, error) {
ret := &WaapRuntimeConfig{}
ret.Name = wc.Name

View file

@ -1,13 +1,11 @@
package waf
import (
"fmt"
"os"
"path/filepath"
"strings"
corazatypes "github.com/crowdsecurity/coraza/v3/types"
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
"github.com/crowdsecurity/crowdsec/pkg/waf/waap_rule"
log "github.com/sirupsen/logrus"
@ -48,12 +46,6 @@ type RulesDetails struct {
var WaapRulesDetails = make(map[int]RulesDetails)
func LoadCollection(pattern string) ([]WaapCollection, error) {
hub, err := cwhub.GetHub()
if err != nil {
return nil, fmt.Errorf("unable to load hub : %s", err)
}
ret := make([]WaapCollection, 0)
for _, waapRule := range waapRules {