-
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?
Changes from all commits
f331f0f
8879aa8
e9b7ba4
5a59165
04eb391
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -18,13 +18,15 @@ | |||||
| // | ||||||
| package org.apache.cloudstack; | ||||||
|
|
||||||
| import com.cloud.api.ApiServlet; | ||||||
| import com.cloud.utils.StringUtils; | ||||||
| import org.eclipse.jetty.server.NCSARequestLog; | ||||||
| import org.eclipse.jetty.server.Request; | ||||||
| import org.eclipse.jetty.server.Response; | ||||||
| import org.eclipse.jetty.util.DateCache; | ||||||
| import org.eclipse.jetty.util.component.LifeCycle; | ||||||
|
|
||||||
| import java.net.InetAddress; | ||||||
| import java.util.Locale; | ||||||
| import java.util.TimeZone; | ||||||
|
|
||||||
|
|
@@ -51,9 +53,8 @@ public void log(Request request, Response response) { | |||||
| StringBuilder sb = buffers.get(); | ||||||
| sb.setLength(0); | ||||||
|
|
||||||
| sb.append(request.getHttpChannel().getEndPoint() | ||||||
| .getRemoteAddress().getAddress() | ||||||
| .getHostAddress()) | ||||||
| InetAddress remoteAddress = ApiServlet.getClientAddress(request); | ||||||
| sb.append(remoteAddress) | ||||||
|
||||||
| sb.append(remoteAddress) | |
| sb.append(remoteAddress != null ? remoteAddress.getHostAddress() : "-") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,15 +24,12 @@ | |
| import java.io.InputStream; | ||
| import java.lang.management.ManagementFactory; | ||
| import java.net.URL; | ||
| import java.util.Arrays; | ||
| import java.util.Properties; | ||
|
|
||
| import com.cloud.api.ApiServer; | ||
| import org.apache.commons.daemon.Daemon; | ||
| import org.apache.commons.daemon.DaemonContext; | ||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.eclipse.jetty.jmx.MBeanContainer; | ||
| import org.eclipse.jetty.server.ForwardedRequestCustomizer; | ||
| import org.eclipse.jetty.server.HttpConfiguration; | ||
| import org.eclipse.jetty.server.HttpConnectionFactory; | ||
| import org.eclipse.jetty.server.RequestLog; | ||
|
|
@@ -193,7 +190,6 @@ public void start() throws Exception { | |
| httpConfig.setResponseHeaderSize(8192); | ||
| httpConfig.setSendServerVersion(false); | ||
| httpConfig.setSendDateHeader(false); | ||
| addForwardingCustomiser(httpConfig); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to remove this? |
||
|
|
||
| // HTTP Connector | ||
| createHttpConnector(httpConfig); | ||
|
|
@@ -216,21 +212,6 @@ public void start() throws Exception { | |
| server.join(); | ||
| } | ||
|
|
||
| /** | ||
| * Adds a ForwardedRequestCustomizer to the HTTP configuration to handle forwarded headers. | ||
| * The header used for forwarding is determined by the ApiServer.listOfForwardHeaders property. | ||
| * Only non empty headers are considered and only the first of the comma-separated list is used. | ||
| * @param httpConfig the HTTP configuration to which the customizer will be added | ||
| */ | ||
| private static void addForwardingCustomiser(HttpConfiguration httpConfig) { | ||
| ForwardedRequestCustomizer customiser = new ForwardedRequestCustomizer(); | ||
| String header = Arrays.stream(ApiServer.listOfForwardHeaders.value().split(",")).findFirst().orElse(null); | ||
| if (com.cloud.utils.StringUtils.isNotEmpty(header)) { | ||
| customiser.setForwardedForHeader(header); | ||
| } | ||
| httpConfig.addCustomizer(customiser); | ||
| } | ||
|
|
||
| @Override | ||
| public void stop() throws Exception { | ||
| server.stop(); | ||
|
|
||
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.