ayushtkn commented on code in PR #5552:
URL: https://github.com/apache/hadoop/pull/5552#discussion_r1171843571


##########
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/CallerContext.java:
##########
@@ -47,6 +47,7 @@ public final class CallerContext {
   // field names
   public static final String CLIENT_IP_STR = "clientIp";
   public static final String CLIENT_PORT_STR = "clientPort";
+  public static final String DFSROUTER_PORT_STR = "dfsrouterPort";

Review Comment:
   As of now it is only router that proxies request and in "Hadoop" code, 
anyone can pass the CLIENT_IP_PORT, lets keep the name generic, something 
like``PROXY_USER_PORT``, maybe? or something better



##########
hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestNamenodeAuditlogWithDFSRouterPort.java:
##########
@@ -0,0 +1,91 @@
+/**
+ * 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
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.hdfs.server.federation.router;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hdfs.server.federation.MiniRouterDFSCluster;
+import org.apache.hadoop.hdfs.server.federation.RouterConfigBuilder;
+import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
+import org.apache.hadoop.test.GenericTestUtils;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.regex.Pattern;
+
+import static 
org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_CALLER_CONTEXT_ENABLED_KEY;
+import static 
org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_AUDIT_LOG_WITH_REMOTE_PORT_KEY;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test namenode auditlog log the dfsrouterPort info when the request is form 
dfsrouter.
+ */
+public class TestNamenodeAuditlogWithDFSRouterPort {
+  private static final Logger LOG = LoggerFactory.getLogger(
+      TestNamenodeAuditlogWithDFSRouterPort.class);
+  private static final Pattern AUDIT_WITH_PORT_PATTERN = Pattern.compile(

Review Comment:
   Do you need a new class for this test? No, right?
   
   Explore adding the ``TestRouterRpc``, can derive pointers from 
``testRealUserPropagationInCallerContext``



##########
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java:
##########
@@ -453,15 +453,16 @@ private void logAuditEvent(boolean succeeded,
 
   private void appendClientPortToCallerContextIfAbsent() {
     final CallerContext ctx = CallerContext.getCurrent();
-    if (isClientPortInfoAbsent(ctx)) {
-      String origContext = ctx == null ? null : ctx.getContext();
-      byte[] origSignature = ctx == null ? null : ctx.getSignature();
-      CallerContext.setCurrent(
-          new CallerContext.Builder(origContext, contextFieldSeparator)
-              .append(CallerContext.CLIENT_PORT_STR, 
String.valueOf(Server.getRemotePort()))
-              .setSignature(origSignature)
-              .build());
-    }
+    String origContext = ctx == null ? null : ctx.getContext();
+    byte[] origSignature = ctx == null ? null : ctx.getSignature();
+    //When the request comes from the dfsrouter, origContext must contains 
CLIENT_PORT_STR. See RouterRpcClient.addClientInfoToCallerContext
+    String clientPort = isClientPortInfoAbsent(ctx) ? 
CallerContext.CLIENT_PORT_STR :

Review Comment:
   I don't find this a problem, Even if someone else sends Client port, we are 
just logging his actual port in the audit log,
   
   Though I don't like the name of the config mentioning dfsrouter, let it be 
any client who sends you the client port, if someone sends you a port via 
client port, we just added the actual client port.
   
   At worst if someone finds serious objections on having this in, We can 
consider doing this only if the guy sending the request is configured under 
```dfs.namenode.ip-proxy-users```



-- 
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: common-issues-unsubscr...@hadoop.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org

Reply via email to