fix log level propagation + log requests to the appsec engine
This commit is contained in:
parent
f7c5726a0a
commit
169e39a4a9
|
@ -97,11 +97,6 @@ func (wc *AppsecSource) UnmarshalConfig(yamlConfig []byte) error {
|
||||||
return errors.Wrap(err, "Cannot parse appsec configuration")
|
return errors.Wrap(err, "Cannot parse appsec configuration")
|
||||||
}
|
}
|
||||||
|
|
||||||
if wc.config.LogLevel == nil {
|
|
||||||
level := new(log.Level)
|
|
||||||
*level = log.InfoLevel
|
|
||||||
wc.config.LogLevel = level
|
|
||||||
}
|
|
||||||
if wc.config.ListenAddr == "" {
|
if wc.config.ListenAddr == "" {
|
||||||
wc.config.ListenAddr = "127.0.0.1:7422"
|
wc.config.ListenAddr = "127.0.0.1:7422"
|
||||||
}
|
}
|
||||||
|
@ -152,7 +147,6 @@ func (w *AppsecSource) Configure(yamlConfig []byte, logger *log.Entry) error {
|
||||||
return errors.Wrap(err, "unable to parse appsec configuration")
|
return errors.Wrap(err, "unable to parse appsec configuration")
|
||||||
}
|
}
|
||||||
w.logger = logger
|
w.logger = logger
|
||||||
w.logger.Logger.SetLevel(*w.config.LogLevel)
|
|
||||||
|
|
||||||
w.logger.Tracef("Appsec configuration: %+v", w.config)
|
w.logger.Tracef("Appsec configuration: %+v", w.config)
|
||||||
|
|
||||||
|
@ -222,7 +216,6 @@ func (w *AppsecSource) Configure(yamlConfig []byte, logger *log.Entry) error {
|
||||||
|
|
||||||
//We don´t use the wrapper provided by coraza because we want to fully control what happens when a rule match to send the information in crowdsec
|
//We don´t use the wrapper provided by coraza because we want to fully control what happens when a rule match to send the information in crowdsec
|
||||||
w.mux.HandleFunc(w.config.Path, w.appsecHandler)
|
w.mux.HandleFunc(w.config.Path, w.appsecHandler)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,6 +309,9 @@ func (w *AppsecSource) IsAuth(apiKey string) bool {
|
||||||
|
|
||||||
// should this be in the runner ?
|
// should this be in the runner ?
|
||||||
func (w *AppsecSource) appsecHandler(rw http.ResponseWriter, r *http.Request) {
|
func (w *AppsecSource) appsecHandler(rw http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
w.logger.Debugf("Received request from '%s' on %s", r.RemoteAddr, r.URL.Path)
|
||||||
|
|
||||||
apiKey := r.Header.Get(appsec.APIKeyHeaderName)
|
apiKey := r.Header.Get(appsec.APIKeyHeaderName)
|
||||||
clientIP := r.Header.Get(appsec.IPHeaderName)
|
clientIP := r.Header.Get(appsec.IPHeaderName)
|
||||||
remoteIP := r.RemoteAddr
|
remoteIP := r.RemoteAddr
|
||||||
|
|
|
@ -157,10 +157,10 @@ func (wc *AppsecConfig) LoadByPath(file string) error {
|
||||||
return fmt.Errorf("name cannot be empty")
|
return fmt.Errorf("name cannot be empty")
|
||||||
}
|
}
|
||||||
if wc.LogLevel == nil {
|
if wc.LogLevel == nil {
|
||||||
lvl := log.InfoLevel
|
lvl := wc.Logger.Logger.GetLevel()
|
||||||
wc.LogLevel = &lvl
|
wc.LogLevel = &lvl
|
||||||
}
|
}
|
||||||
wc.Logger = wc.Logger.WithField("name", wc.Name)
|
wc.Logger = wc.Logger.Dup().WithField("name", wc.Name)
|
||||||
wc.Logger.Logger.SetLevel(*wc.LogLevel)
|
wc.Logger.Logger.SetLevel(*wc.LogLevel)
|
||||||
if wc.DefaultRemediation == "" {
|
if wc.DefaultRemediation == "" {
|
||||||
return fmt.Errorf("default_remediation cannot be empty")
|
return fmt.Errorf("default_remediation cannot be empty")
|
||||||
|
|
Loading…
Reference in a new issue