[ 
https://issues.apache.org/jira/browse/HADOOP-18972?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17785852#comment-17785852
 ] 

ASF GitHub Bot commented on HADOOP-18972:
-----------------------------------------

steveloughran commented on code in PR #6272:
URL: https://github.com/apache/hadoop/pull/6272#discussion_r1392431111


##########
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/SaslPropertiesResolver.java:
##########
@@ -82,7 +83,7 @@ public Configuration getConf() {
    * @return sasl Properties
    */
   public Map<String,String> getDefaultProperties() {
-    return properties;
+    return new TreeMap<>(properties);

Review Comment:
   I'd propose having a private cloneProperties() method used in all calls, 
which includes a `requireNonNull()` on the properties...it is null until 
setConf() is called.



##########
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestSaslPropertiesResolver.java:
##########
@@ -0,0 +1,49 @@
+package org.apache.hadoop.security;
+
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import javax.security.sasl.Sasl;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.hadoop.conf.Configuration;
+
+import static 
org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_RPC_PROTECTION;
+import static org.junit.Assert.assertEquals;
+
+public class TestSaslPropertiesResolver {

Review Comment:
   subclass AbstractHadoopTestBase; override it's setup/teardown methods, which 
do things like set the thread name



##########
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestSaslPropertiesResolver.java:
##########
@@ -0,0 +1,49 @@
+package org.apache.hadoop.security;
+
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import javax.security.sasl.Sasl;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.hadoop.conf.Configuration;
+
+import static 
org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_RPC_PROTECTION;
+import static org.junit.Assert.assertEquals;
+
+public class TestSaslPropertiesResolver {
+
+  private static final SaslRpcServer.QualityOfProtection PRIVACY_QOP = 
SaslRpcServer.QualityOfProtection.PRIVACY;
+  private static final SaslRpcServer.QualityOfProtection AUTHENTICATION_QOP = 
SaslRpcServer.QualityOfProtection.AUTHENTICATION;
+  private static final InetAddress LOCALHOST = new 
InetSocketAddress("127.0.0.1", 1).getAddress();
+
+  private SaslPropertiesResolver resolver;
+
+  @Before
+  public void setup() {
+    Configuration conf = new Configuration();
+    conf.set(HADOOP_RPC_PROTECTION, "privacy");
+    resolver = new SaslPropertiesResolver();
+    resolver.setConf(conf);
+  }
+
+  @Test
+  public void testResolverDoesNotMutate() {
+    assertEquals(PRIVACY_QOP.getSaslQop(), 
resolver.getDefaultProperties().get(Sasl.QOP));

Review Comment:
   lot of duplication here; 
   is it possible to factor these out into new assertions? at the very least 
some assertPrivacyQop() which is called all the way down.





> Bug in SaslPropertiesResolver allows mutation of internal state
> ---------------------------------------------------------------
>
>                 Key: HADOOP-18972
>                 URL: https://issues.apache.org/jira/browse/HADOOP-18972
>             Project: Hadoop Common
>          Issue Type: Bug
>            Reporter: Charles Connell
>            Priority: Minor
>              Labels: pull-request-available
>
> When {{SaslDataTransferServer}} or {{SaslDataTranferClient}} want to get a 
> SASL properties map to do a handshake, they call 
> {{SaslPropertiesResolver#getServerProperties()}} or 
> {{SaslPropertiesResolver#getClientProperties()}}, and they get back a 
> {{Map<String, String>}}. Every call gets the same {{Map}} object back, and 
> then the callers sometimes call 
> [put()|https://github.com/apache/hadoop/blob/rel/release-3.3.6/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/datatransfer/sasl/SaslDataTransferServer.java#L385]
>  on it. This means that future users of {{SaslPropertiesResolver}} get back 
> the wrong information.
> I propose that {{SaslPropertiesResolver}} should pass a copy of its internal 
> map, so that users can safety modify them.
> I discovered this problem in my company's testing environment as we began to 
> enable {{dfs.data.transfer.protection}} on our DataNodes, while our NameNodes 
> were using {{IngressPortBasedResolver}} to give out block tokens with 
> different QOPs depending on the port used. The our HDFS client applications 
> became unable to read or write to HDFS because they could not find a QOP in 
> common with the DataNodes during SASL handshake. With multiple threads 
> executing SASL handshakes at the same time, the properties map used in 
> {{SaslDataTransferServer}} in a DataNode could be clobbered during usage, 
> since the same map was used by all threads. Also, future clients that do not 
> have a QOP embedded in their block tokens would connect to a server with the 
> wrong SASL properties map. I think that one or both of these issues explains 
> the problem that I saw. I eliminated this unsafety and saw the problem go 
> away.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to