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

ASF GitHub Bot commented on DRILL-7573:
---------------------------------------

dobesv commented on pull request #1977: DRILL-7573: Support htpasswd based 
authentication
URL: https://github.com/apache/drill/pull/1977#discussion_r378675855
 
 

 ##########
 File path: 
exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestHtpasswdFileUserAuthenticator.java
 ##########
 @@ -0,0 +1,154 @@
+/*
+ * 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.drill.exec.rpc.user.security;
+
+import org.apache.drill.common.config.DrillProperties;
+import org.apache.drill.exec.ExecConstants;
+import org.apache.drill.test.ClientFixture;
+import org.apache.drill.test.ClusterFixture;
+import org.apache.drill.test.ClusterTest;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+public class TestHtpasswdFileUserAuthenticator extends ClusterTest {
+  private File tempPasswdFile;
+
+
+  private void setupCluster(String passwdContent) throws IOException {
+    tempPasswdFile = new File(dirTestWatcher.getTmpDir(), "htpasswd." + 
System.currentTimeMillis());
+    Files.write(tempPasswdFile.toPath(), passwdContent.getBytes());
+
+    cluster = ClusterFixture.bareBuilder(dirTestWatcher)
+      .clusterSize(3)
+      .configProperty(ExecConstants.ALLOW_LOOPBACK_ADDRESS_BINDING, true)
+      .configProperty(ExecConstants.USER_AUTHENTICATION_ENABLED, true)
+      .configProperty(ExecConstants.USER_AUTHENTICATOR_IMPL, "htpasswd")
+      .configProperty(ExecConstants.HTPASSWD_AUTHENTICATOR_PATH, 
tempPasswdFile.toString())
+      .build();
+  }
+
+
+  @Test
+  public void passwordChecksGiveCorrectResults() throws Exception {
+    String passwdContent = "alice:pass1\n" +
+      "bob:buzzkill\n" +
+      "jane:$apr1$PrwDfXy9$ajkhotQW6RFnoVQtPKoW4/\n" +
+      "john:$apr1$UxZgBU8k$K4UzdubNa741TnWAZY2QV0\n";
+    setupCluster(passwdContent);
+
+
+    assertTrue(true);
+
+    tryCredentials("alice", "pass1", cluster, true);
+    tryCredentials("bob", "buzzkill", cluster, true);
+    tryCredentials("notalice", "pass1", cluster, false);
+    tryCredentials("notbob", "buzzkill", cluster, false);
+    tryCredentials("alice", "wrong", cluster, false);
+    tryCredentials("bob", "incorrect", cluster, false);
+    tryCredentials("jane", "pass", cluster, true);
+    tryCredentials("john", "foobar", cluster, true);
+    tryCredentials("jane", "wrong", cluster, false);
+    tryCredentials("john", "incorrect1", cluster, false);
+  }
+
+  @Test
+  public void rejectsLoginsWhenHtpasswdFileMissing() throws Exception {
+    cluster = ClusterFixture.bareBuilder(dirTestWatcher)
+      .clusterSize(3)
+      .configProperty(ExecConstants.ALLOW_LOOPBACK_ADDRESS_BINDING, true)
+      .configProperty(ExecConstants.USER_AUTHENTICATION_ENABLED, true)
+      .configProperty(ExecConstants.USER_AUTHENTICATOR_IMPL, "htpasswd")
+      .configProperty(ExecConstants.HTPASSWD_AUTHENTICATOR_PATH, 
"/nonexistant-file")
+      .build();
+    tryCredentials("bob", "bob", cluster, false);
+  }
+
+  @Test
+  public void detectsChanges() throws Exception {
+    String passwdContent = "alice:pass1\nbob:buzzkill\n";
+    setupCluster(passwdContent);
+
+    tryCredentials("alice", "pass1", cluster, true);
+    tryCredentials("alice", "pass2", cluster, false);
+    tryCredentials("bob", "buzzkill", cluster, true);
+    tryCredentials("bob", "yolo", cluster, false);
+
+    String passwdContent2 = "alice:pass2\nbob:yolo\n";
+    Files.write(tempPasswdFile.toPath(), passwdContent2.getBytes());
+    Thread.sleep(10);
+
+    tryCredentials("alice", "pass1", cluster, false);
+    tryCredentials("alice", "pass2", cluster, true);
+    tryCredentials("bob", "buzzkill", cluster, false);
+    tryCredentials("bob", "yolo", cluster, true);
+
+    // Invalid file is treated as empty
+    String passwdContent3 = "invalid file";
+    Files.write(tempPasswdFile.toPath(), passwdContent3.getBytes());
+    Thread.sleep(10);
+
+    tryCredentials("alice", "pass1", cluster, false);
+    tryCredentials("alice", "pass2", cluster, false);
 
 Review comment:
   A bit of googling turns up a lack of subsecond precision in Java 1.8 and 
below, so I've added a 1 second delay in those versions
 
----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Support text file for user authentication instead of using PAM
> --------------------------------------------------------------
>
>                 Key: DRILL-7573
>                 URL: https://issues.apache.org/jira/browse/DRILL-7573
>             Project: Apache Drill
>          Issue Type: Improvement
>          Components:  Server, Web Server
>    Affects Versions: 1.17.0
>            Reporter: Dobes Vandermeer
>            Assignee: Dobes Vandermeer
>            Priority: Major
>             Fix For: 1.18.0
>
>
> Currently plain login using PAM as its user database.  However, in a 
> containerized or server environment the passwd file is generally kept static, 
> so some other mechanism for managing users is preferred.  Also, pam does not 
> by default come with an easy to way to check passwords other than via the 
> passwd/shadow files.
>  It would be great if there was another authentication method included in 
> drill that was easier to use in a containerized environment.
> Reading the usernames and password from a specific file would probably be the 
> simplest mechanism.
>  
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to