-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fix logging of forwarded IPs in logs #11854
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
base: 4.22
Are you sure you want to change the base?
Conversation
|
@blueorangutan package |
|
@abh1sar a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
DaanHoogland
left a comment
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.
clgtm
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 4.22 #11854 +/- ##
============================================
- Coverage 17.59% 17.59% -0.01%
+ Complexity 15600 15597 -3
============================================
Files 5910 5910
Lines 529755 529753 -2
Branches 64724 64723 -1
============================================
- Hits 93228 93226 -2
Misses 426035 426035
Partials 10492 10492
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Packaging result [SF]: ✖️ el8 ✖️ el9 ✖️ debian ✖️ suse15. SL-JID 15485 |
|
@blueorangutan package |
|
@abh1sar a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 15490 |
|
@blueorangutan package |
|
@abh1sar a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✖️ el8 ✖️ el9 ✖️ debian ✖️ suse15. SL-JID 15495 |
|
@blueorangutan package |
|
@abh1sar a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✖️ el8 ✖️ el9 ✖️ debian ✖️ suse15. SL-JID 15496 |
|
@blueorangutan package |
|
@abh1sar a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✖️ el8 ✖️ el9 ✖️ debian ✖️ suse15. SL-JID 15509 |
63ce1c6 to
2ca1e10
Compare
|
@blueorangutan package |
|
@abh1sar a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
DaanHoogland
left a comment
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.
clgtm, tested in Lab
|
@harikrishna-patnala , can you please review? |
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.
Pull request overview
This PR fixes a bug where forwarded client IPs behind a proxy were not being correctly logged in management.log, api.log, and access.log. The root cause was that PR #11386 introduced a ForwardedRequestCustomizer in Jetty that only checked the first header in the configured list and modified the request's remote address, which interfered with proxy CIDR verification.
Changes:
- Removed the Jetty
ForwardedRequestCustomizerapproach in favor of consistently usingApiServlet.getClientAddress()across all logging points - Made several methods in
ApiServletstatic to enable reuse fromACSRequestLog - Updated
ACSRequestLogto useApiServlet.getClientAddress()instead of directly accessing the endpoint's remote address
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| client/src/main/java/org/apache/cloudstack/ServerDaemon.java | Removed addForwardingCustomiser() method and related Jetty customizer configuration, plus removed unused imports |
| client/src/main/java/org/apache/cloudstack/ACSRequestLog.java | Updated to call ApiServlet.getClientAddress() for consistent forwarded IP detection across all logs |
| server/src/main/java/com/cloud/api/ApiServlet.java | Refactored getClientAddress() and related methods to be static with improved early-return logic and updated logging format |
| server/src/test/java/com/cloud/api/ApiServletTest.java | Updated tests to use static method calls and added ConfigDepot mocking infrastructure for testing configuration values |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| .getRemoteAddress().getAddress() | ||
| .getHostAddress()) | ||
| InetAddress remoteAddress = ApiServlet.getClientAddress(request); | ||
| sb.append(remoteAddress) |
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.
| sb.append(remoteAddress) | |
| sb.append(remoteAddress.getHostAddress()) |
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.
Done
| httpConfig.setResponseHeaderSize(8192); | ||
| httpConfig.setSendServerVersion(false); | ||
| httpConfig.setSendDateHeader(false); | ||
| addForwardingCustomiser(httpConfig); |
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.
Why do we need to remove this?
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.
This would modify the request so that getRemoteAddr() returns the forwarded header.
We need the request as is so that the client IP is processed correctly later in getClientAddress() using the configs retrieved by doUseForwardHeaders() and proxyNets().
e9fd76f to
04eb391
Compare
|
@blueorangutan package |
|
@abh1sar a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 16351 |
|
@blueorangutan test |
|
@abh1sar a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests |
Description
This PR fixes a bug due to which forwarded IPs behind a proxy won't be logged in management.log, api.log and access.log.
Access log : addForwardingCustomiser() updates request's remoteAddr to the forwarded client's IP
But ACSRequestLog.log() was looking at getHttpChannel().getEndPoint().getRemoteAddress(), which still returns the proxy's address
AddForwardinfCustomizer would only look at the first header in
proxy.header.names. If the user is sending client IP address via some other header, it won't be detected.Changing the request's remoteAddr by addFOrwardingCustomizer changes the behaviour in ApiServlet.getClientAddress() which expects request.getRemoteAddr() to return the proxy's address, so that it can compare it with the allowed proxy cidrs as set in
proxy.cidrFor the fix, I have removed addForwardingCustomizer and calling ApiServlet.getClientAddress() from ACSRequestLog. This way IPs in all the logs are consistent with each other and use the same method (getClientAddress()) to get the forwarded client's IP address.
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
How Has This Been Tested?
Verified that the forwarded IP is being logged in all the logs.
Also tried the with the script test_forwareded_headers.sh as given here #11386 (review)
Settings used :

The script ./test_forwareded_headers.sh fails without the fix
How did you try to break this feature and the system with this change?