You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2022/04/20 14:57:07 UTC

[GitHub] [ozone] symious commented on a diff in pull request #3252: HDDS-6525. Add audit log for S3Gateway

symious commented on code in PR #3252:
URL: https://github.com/apache/ozone/pull/3252#discussion_r854240209


##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/ClientIpFilter.java:
##########
@@ -0,0 +1,69 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.ozone.s3;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Priority;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.container.PreMatching;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.ext.Provider;
+import java.io.IOException;
+
+/**
+ * Filter used to get ClientIP from HttpServletRequest.
+ */
+
+@Provider
+@PreMatching
+@Priority(ClientIpFilter.PRIORITY)
+public class ClientIpFilter implements ContainerRequestFilter {
+
+  public static final int PRIORITY = 200;
+
+  public static final String CLIENT_IP_HEADER = "client_ip";
+
+  private static final Logger LOG = LoggerFactory.getLogger(
+      ClientIpFilter.class);
+
+  @Context
+  private HttpServletRequest httpServletRequest;
+
+  @Override
+  public void filter(ContainerRequestContext request) throws IOException {
+    String clientIp = httpServletRequest.getHeader("x-real-ip");
+
+    if (clientIp == null || clientIp.isEmpty()) {
+      // extract from forward ips
+      String ipForwarded = httpServletRequest.getHeader("x-forwarded-for");

Review Comment:
   Tried to find some comparisions, but can not find any definite answers:
   1. https://github.com/akka/akka-http/issues/1670#issue-283565704. 
   >It seems that even though the leftmost value of X-Forwarded-For is generally the original client IP address, [this is not universally so](http://totaluptime.com/kb/prevent-x-forwarded-for-spoofing-or-manipulation/), and there exist modules for at least Apache and Nginx web servers to provide the correct resolution of the client IP address and setting it as the X-Real-IP value.
   2. https://onefeed.xyz/posts/x-forwarded-for-vs-x-real-ip.html
   >It denpends on how much you know the network between the client and the server, and how much you trust these headers. 
   >However, since any proxy can modify/add these headers freely, there is no guarantee the IP is of a real client.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org