-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New application logging (zerolog) & error handling #75
Conversation
Now processing error returns immediately as SPOA error instead of SPOE/SPOP timeout error. |
@@ -32,6 +37,14 @@ type Application struct { | |||
TransactionActiveLimit int `yaml:"transaction_active_limit"` | |||
} | |||
|
|||
// Log is used to manage the SPOA logging. | |||
type Log struct { | |||
Level string `yaml:"level"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should provide two ways to do login in a connector. Can we stick to tx's logger?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we need application (coraza-spoa
) logging. We need to log all initialization stuff as well as request/response before transaction is created.
fileEncoder := zapcore.NewJSONEncoder(pe) | ||
|
||
pe.EncodeTime = zapcore.ISO8601TimeEncoder | ||
wafConf := coraza.NewWAFConfig(). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer we get the platform logging and plug into an implementation coraza can use. For example we use the zap logger created by caddy and plug into coraza https://github.com/corazawaf/coraza-caddy/blob/main/coraza.go#L54
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH, I had tried it before pushed the PR. It doesn't suit well.
Thanks for raising this PR. I think in general I'd prefer we use the logger provided by the platform (in this case spoe) and inject it into coraza config to use a single/consistent logger. This will also prevent us from deviating on the log destination among connector and coraza itself. See for example what we do in caddy https://github.com/corazawaf/coraza-caddy/blob/main/coraza.go#L54 where we reuse the logger produced by caddy and make it pluggable to coraza's interface hence we reduce the configuration. |
To sum up, |
# Conflicts: # docker/haproxy/haproxy.cfg # internal/spoa.go
{
"level": "error",
"error": "invalid WAF config from string: failed to parse string: failed to compile the directive \"secrule\": there is a another rule with id 10102",
"app": "test",
"time": "2023-07-29T14:42:14Z",
"message": "Unable to create WAF instance"
}
{
"level": "fatal",
"error": "invalid WAF config from string: failed to parse string: failed to compile the directive \"secrule\": there is a another rule with id 10102",
"time": "2023-07-29T14:42:14Z",
"message": "Can't initialize SPOA"
} How about we just log out the first line and not
|
@@ -40,10 +40,14 @@ frontend test_frontend | |||
http-request silent-drop if { var(txn.coraza.action) -m str drop } | |||
http-response silent-drop if { var(txn.coraza.action) -m str drop } | |||
|
|||
# Deny in case of an error, when processing with the Coraza SPOA | |||
# Deny in case of an error, when processing with the Coraza SPOE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SPOE is the Haproxy part which talks to the SPOA. So I think this as correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HAProxy talks about SPOE/SPOP only.
There are txn.coraza.err_code
and txn.coraza.err_msg
for SPOA errors now.
# Conflicts: # config.yaml.default # go.mod
Fixed.
HAProxy doesn't run if there is error in config, doesn't matter if error is in only one backend and others work. So, I would stick with this behavior.
As I sad
As I use Coraza's DebugLog with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really don't see the need to have zerolog and logrus in here. Do we need both and also a log
package? I would prefer to use coraza logger (embedded in the transaction) and std logger for those cases where it is not possible and from there explore the possibility of retrieving the logger from the WAF object or do a recommendation. The reason is this is the only connector where I see we need to introduce new loggers.
Rewrite does use zerolog. Closed via #103 |
Closes #70
err_code
anderr_msg
- SPOA errorserror
used for SPOE/SPOP errors