-
Notifications
You must be signed in to change notification settings - Fork 46
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
feat: ✨ Add caddy client_ip variable parsing #184
Conversation
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.
Thanks for your contribution!
Is there a simple way to add tests on this change?
@fzipi |
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.
Indentation on this code is bad. Maybe try to run go fmt
?
Also, this might just deserve a new function call instead of adding it here?
@fzipi |
c95c1bc
to
2fe46bc
Compare
I think it is way more clear now. @M4tteoP can you help me with the review? |
2badad2
to
50c5701
Compare
Thanks for this @adrienyhuel. I think the unit tests here aren't enough to cover this. Any chance you can create an integration test using |
@jcchavezs I added a simple integration test, is it sufficient ? |
Please fix the lint and we can merge it. |
@jcchavezs my bad, I always forget to lint as my IDE always replace tabs with 4 spaces... |
Maybe adding an |
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.
Sorry, I'm a bit late, I'm finally taking a look. Overall looks good to me!
@@ -3,6 +3,9 @@ | |||
debug | |||
auto_https off | |||
order coraza_waf first | |||
servers { | |||
trusted_proxies static private_ranges |
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.
Would it be possible to add a comment on why this line is needed? Also, is it then something that is strictly required to have the client_ip properly working? If so, should we document it in the readme: https://github.com/corazawaf/coraza-caddy?tab=readme-ov-file#plugin-syntax?
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.
@M4tteoP
This line is needed is you want Caddy to populate client_ip from X-Forwarded-For header, in the case Caddy is behind a reverse proxy.
If you don't provide this config, Caddy will populate client_ip from request.RemoteAddr :
- If client connect directly, it will be the real IP
- if client connect through another proxy (like Cloudflare, or an Ingress in K8s), it will the proxy IP
See : https://caddyserver.com/docs/caddyfile/options#trusted-proxies
I think all users who want real client IP in their access logs know that config.
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.
Awesome, thanks for the explanation!
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.
Btw, with this pull request, coraza-caddy will use client_ip variable provided by caddy to use in WAF rules and in WAF logs, regardless of how Caddy populate this variable.
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.
@adrienyhuel please add this explanation as a comment in the config.
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.
@jcchavezs done :)
|
Resolve #150