up
This commit is contained in:
parent
d6f9bbc0c3
commit
07d463f4f0
|
@ -34,7 +34,7 @@ func initCrowdsec(cConfig *csconfig.Config, hub *cwhub.Hub) (*parser.Parsers, er
|
||||||
return nil, fmt.Errorf("while loading scenarios: %w", err)
|
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)
|
return nil, fmt.Errorf("while loading waap rules: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/acquisition/configuration"
|
"github.com/crowdsecurity/crowdsec/pkg/acquisition/configuration"
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
|
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/types"
|
"github.com/crowdsecurity/crowdsec/pkg/types"
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/waf"
|
"github.com/crowdsecurity/crowdsec/pkg/waf"
|
||||||
"github.com/crowdsecurity/go-cs-lib/trace"
|
"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)
|
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++ {
|
for nbRoutine := 0; nbRoutine < w.config.Routines; nbRoutine++ {
|
||||||
|
|
||||||
wafUUID := uuid.New().String()
|
wafUUID := uuid.New().String()
|
||||||
|
@ -178,7 +171,7 @@ func (w *WaapSource) Configure(yamlConfig []byte, logger *log.Entry) error {
|
||||||
}),
|
}),
|
||||||
WaapRuntime: &wrt,
|
WaapRuntime: &wrt,
|
||||||
}
|
}
|
||||||
err := runner.Init(hub.GetDataDir())
|
err := runner.Init(waapCfg.GetDataDir())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to initialize runner : %s", err)
|
return fmt.Errorf("unable to initialize runner : %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
var waapRules map[string]WaapCollectionConfig = make(map[string]WaapCollectionConfig) //FIXME: would probably be better to have a struct for this
|
||||||
|
|
||||||
func LoadWaapRules() error {
|
var hub *cwhub.Hub //FIXME: this is a temporary hack to make the hub available in the package
|
||||||
hub, err := cwhub.GetHub()
|
|
||||||
if err != nil {
|
func LoadWaapRules(hubInstance *cwhub.Hub) error {
|
||||||
return fmt.Errorf("unable to load hub : %s", err)
|
|
||||||
}
|
hub = hubInstance
|
||||||
|
|
||||||
for _, hubWafRuleItem := range hub.GetItemMap(cwhub.WAAP_RULES) {
|
for _, hubWafRuleItem := range hub.GetItemMap(cwhub.WAAP_RULES) {
|
||||||
//log.Infof("loading %s", hubWafRuleItem.LocalPath)
|
//log.Infof("loading %s", hubWafRuleItem.LocalPath)
|
||||||
|
|
|
@ -149,11 +149,6 @@ func (wc *WaapConfig) LoadByPath(file string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wc *WaapConfig) Load(configName 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)
|
waapConfigs := hub.GetItemMap(cwhub.WAAP_CONFIGS)
|
||||||
|
|
||||||
for _, hubWaapConfigItem := range waapConfigs {
|
for _, hubWaapConfigItem := range waapConfigs {
|
||||||
|
@ -164,7 +159,7 @@ func (wc *WaapConfig) Load(configName string) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
wc.Logger.Infof("loading %s", hubWaapConfigItem.LocalPath)
|
wc.Logger.Infof("loading %s", hubWaapConfigItem.LocalPath)
|
||||||
err = wc.LoadByPath(hubWaapConfigItem.LocalPath)
|
err := wc.LoadByPath(hubWaapConfigItem.LocalPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to load waap-config %s : %s", hubWaapConfigItem.LocalPath, err)
|
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)
|
return fmt.Errorf("no waap-config found for %s", configName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (wc *WaapConfig) GetDataDir() string {
|
||||||
|
return hub.GetDataDir()
|
||||||
|
}
|
||||||
|
|
||||||
func (wc *WaapConfig) Build() (*WaapRuntimeConfig, error) {
|
func (wc *WaapConfig) Build() (*WaapRuntimeConfig, error) {
|
||||||
ret := &WaapRuntimeConfig{}
|
ret := &WaapRuntimeConfig{}
|
||||||
ret.Name = wc.Name
|
ret.Name = wc.Name
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
package waf
|
package waf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
corazatypes "github.com/crowdsecurity/coraza/v3/types"
|
corazatypes "github.com/crowdsecurity/coraza/v3/types"
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
|
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/waf/waap_rule"
|
"github.com/crowdsecurity/crowdsec/pkg/waf/waap_rule"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
@ -48,12 +46,6 @@ type RulesDetails struct {
|
||||||
var WaapRulesDetails = make(map[int]RulesDetails)
|
var WaapRulesDetails = make(map[int]RulesDetails)
|
||||||
|
|
||||||
func LoadCollection(pattern string) ([]WaapCollection, error) {
|
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)
|
ret := make([]WaapCollection, 0)
|
||||||
|
|
||||||
for _, waapRule := range waapRules {
|
for _, waapRule := range waapRules {
|
||||||
|
|
Loading…
Reference in a new issue