-
Notifications
You must be signed in to change notification settings - Fork 980
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
DRILL-7573: Support htpasswd based authentication #1977
Conversation
b3a3aa9
to
48331f5
Compare
I'm not sure if there's anything I can do about that build failure: https://github.com/apache/drill/pull/1977/checks#step:6:1748 |
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.
Hi @dobesv, thank you for the contribution. Very useful!
There are a few minor comments. To address them, make your changes and push a new commit to your branch. No need to create a new PR. Later, as we get ready to commit, we'll "squash" the commits into one.
...xec/src/main/java/org/apache/drill/exec/rpc/user/security/HtpasswdFileUserAuthenticator.java
Outdated
Show resolved
Hide resolved
...xec/src/main/java/org/apache/drill/exec/rpc/user/security/HtpasswdFileUserAuthenticator.java
Outdated
Show resolved
Hide resolved
...xec/src/main/java/org/apache/drill/exec/rpc/user/security/HtpasswdFileUserAuthenticator.java
Outdated
Show resolved
Hide resolved
...xec/src/main/java/org/apache/drill/exec/rpc/user/security/HtpasswdFileUserAuthenticator.java
Outdated
Show resolved
Hide resolved
...xec/src/main/java/org/apache/drill/exec/rpc/user/security/HtpasswdFileUserAuthenticator.java
Outdated
Show resolved
Hide resolved
...xec/src/main/java/org/apache/drill/exec/rpc/user/security/HtpasswdFileUserAuthenticator.java
Show resolved
Hide resolved
...xec/src/main/java/org/apache/drill/exec/rpc/user/security/HtpasswdFileUserAuthenticator.java
Outdated
Show resolved
Hide resolved
...xec/src/main/java/org/apache/drill/exec/rpc/user/security/HtpasswdFileUserAuthenticator.java
Outdated
Show resolved
Hide resolved
...xec/src/main/java/org/apache/drill/exec/rpc/user/security/HtpasswdFileUserAuthenticator.java
Outdated
Show resolved
Hide resolved
...xec/src/main/java/org/apache/drill/exec/rpc/user/security/HtpasswdFileUserAuthenticator.java
Show resolved
Hide resolved
Thanks for the detailed usage description. In the config file shown in the description consistent with the implementation? Description:
Implementation:
Notice the |
Good catch on the file/path issue in the doc |
@dobesv, the key failures to check for are any checkstyle errors. If anything else fails, it is probably due to problems with the (new) builds or master; we'll have to check. This PR includes no tests. It would be great to add some. Some example test cases:
To test you'll need to first set up the server to enable the web server, which is turned off by default in tests. For testing, we use something called the The config you need is probably something like:
Next you'll need a way to talk to the REST server. There is a You will need a place to create and update the file. The With this, you can test the "happy path":
A bit more work is needed for the other cases. To test this one:
You can put the htpasswd in Finally, checking the error cases is a nice-to-have, but is rather tricky. The errors don't kill the server, they only leave a trace in the log file. So, you can use two other tricks. One is To capture log messages, you can try something like My recommendation is to at least test the "happy path"; add the others only if you feel so inclined. |
I added some tests and cleaned up the logic slightly. I didn't add tests for the REST API, since the password logic is shared between both systems I don't think this requires separate testing. I couldn't figure out a sane way to test the stuff related to the default path and I didn't do anything related to loading the file from the classpath. I think that might be more than I am capable of with the time budget I have for this task right now. I don't think the "default path" is particularly import nor is it particularly prone to regressions. I didn't attempt tests related to logging, it just doesn't seem worth it. I'm not so familiar with the project that I can make a test like that in a reasonable amount of time. Perhaps someone core to the team can add that if it seems important. |
@dobesv, thanks for the updates. I agree with limiting the scope of the tests. Looks like the failure above is due to something in this PR. If you can take a look at the issue, we'll be good to go from my perspective.
|
If I'm interpreting the checks correctly, the code works in Java 11 & 12, but not 1.8? Very strange, I wonder why that would be. |
...src/test/java/org/apache/drill/exec/rpc/user/security/TestHtpasswdFileUserAuthenticator.java
Show resolved
Hide resolved
...xec/src/main/java/org/apache/drill/exec/rpc/user/security/HtpasswdFileUserAuthenticator.java
Outdated
Show resolved
Hide resolved
Excellent! There is also one minor race condition to fix. |
...src/test/java/org/apache/drill/exec/rpc/user/security/TestHtpasswdFileUserAuthenticator.java
Outdated
Show resolved
Hide resolved
@vvysotskyi, in this case the sleep is necessary. As I read it, this code uses the file system for synchronization. We write a file, then make a request that will check the file timestamp. If that request is too fast, the code will not detect the change. Maybe 1 second is too long; maybe 100ms is plenty. But, without the delay, we need some other mechanism for synchronization, which then defeats the purpose of the code and test. You propose changing the file modification timestamp. This can be done, but will not accurately reproduce the use case that we want to test. Are you OK with a shorter delay? |
@paul-rogers, thanks for explanation. I think we cannot specify a shorter delay due to JDK-8177809. Let's leave it as it is (but with passing unit tests). |
d154c55
to
9bbc43b
Compare
FWIW a 1 second delay is required because that version of the JVM only offers 1-second resolution on file timestamps. I've changed it to detect changes based on file size and mod time. That should work when changes are made rapidly in systems where the modification time is rounded to the nearest second. |
In containerized environments, PAM based authentication is not convenient. This provides a simple mechanism for setting up users' passwords that can be managed using docker volume mounts.
9bbc43b
to
411a8cb
Compare
Seems like the failure is in another component now:
Was something related to this merged into master recently? |
I'm working on a PR and encountered the same problem. @vvysotskyi could you take a look? |
@cgivre, sorry, currently I'm running out of time with other tasks, so I can't resolve this issue now. |
@vvysotskyi No worries mate.. When you have time, please take a look as all the PRs are running into the same issue. |
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.
Looks good. Let's get it merged so others can try it.
+1
DRILL-7573: Support htpasswd based authentication
Description
This allows you to specify
htpasswd
as your authentication implementation. In this case, users will be authenticated using usernames and password taken from a text file inhtpasswd
format.This gives some more flexibility compared to the PAM authenticator. For example, in docker / kubernetes you can mount a folder with an htpasswd file and update that file when you want to add/remove users, without any concern about interfering with the contents of /etc/passwd and /etc/shadow.
Documentation
Using a password file for authentication
Apache Drill allows you to store valid usernames and passwords in a text file in the popular "htpasswd" format.
This can be more convenient than using PAM in containerized environments, because you do not have to modify any system files like
passwd
,shadow
, or files inpam.d
. Instead you can mount a volume with thehtpasswd
file in it and tell drill to use that file for authentication.To configure this feature:
Create an htpasswd file and copy/mount it to/on the drillbit machines/containers:
Add the following configuration to the
drill.exec
block in the<DRILL_HOME>/conf/drill-override.conf
file:Restart the drillbit(s)
Now you must use a username/password from the
htpasswd
file when logging into DrillNote: Currently the
crypt
andbcrypt
algorithms are not supported, you should probably use the MD5 hashing algorithm used by default by thehtpasswd
command.Testing
I created an
htpasswd
file usinghtpasswd
, configured the auth mechanism as shown above, and testing logging in with both valid and invalid passwords with MD5, SHA-1, and plantext password hashes in thehtpasswd
files.No automated tests so far, but I'm open to advice on how/where to add them. Still very new to the code base.