-
Notifications
You must be signed in to change notification settings - Fork 3k
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
User Access in Presto with File-Based Authentication #797
Conversation
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Rupam Kundu.
|
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please submit the signed CLA to [email protected]. For more information, see https://github.com/prestosql/cla. |
1 similar comment
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please submit the signed CLA to [email protected]. For more information, see https://github.com/prestosql/cla. |
0de3905
to
b0413f6
Compare
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please submit the signed CLA to [email protected]. For more information, see https://github.com/prestosql/cla. |
Thanks for the contribution. One initial thought is that we shouldn't support insecure password hashing options. Anything that only hashes the password once is not secure as it is vulnerable to brute force cracking attacks. The primary secure options for password hashing are bcrypt and PBKDF2. The former seems to be more popular, and possibly have a slight security advantage, while the latter is included with the JDK and is a NIST standard. Supporting either or both of these is reasonable. This Java bcrypt implementation looks good. The password file format you chose is good, since it's the same format as the Apache HTTP Server and thus can be generated using the For either of these algorithms, the number of rounds or iterations must be chosen. A larger number means it is more expensive to compute the hash, and thus slows down an attacker that is cracking the password file. We should probably enforce a minimum value for security purposes. The On the flip side, this means it is more expensive for Presto to validate the password, which adds latency to requests and increases CPU load on the coordinator. We will probably want caching, since with the current protocol design, authentication is performed for every request. An unrelated consideration is that we should periodically reload the password file, so that administrators don't need to restart the server when modifying the user list. This is easily accomplished by using a cache with a configurable expiration time (maybe default to |
See how it was implemented for file based access control: |
@electrum I have addressed the other changes and @kokosing thanks a lot for your suggestion. But before I update the PR, I have a question regarding the comment : "We should probably enforce a minimum value for security purposes." for the number of rounds of hashing. Currently, org.apache.commons.codec.digest.Md5Crypt uses by default 1000 rounds, is that enough? |
@rupamk Thanks for updating the PR. Allow me to restate my previous objections:
I'd like to hear other's opinions about minimum iterations. For bcrypt, a work factor of |
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.
While it's good to have product tests, and thanks for adding them, we should also have unit tests for the plugin. The product tests should cover basic end-to-end integration tests, answering the question, does the plugin actually work? While the user tests should cover the full functionality. Unit tests are closer to the code and easier to run.
...cators/src/main/java/io/prestosql/plugin/password/filebasedauthenticator/EncryptionAlgo.java
Outdated
Show resolved
Hide resolved
...rc/main/java/io/prestosql/plugin/password/filebasedauthenticator/FileBasedAuthenticator.java
Outdated
Show resolved
Hide resolved
...rc/main/java/io/prestosql/plugin/password/filebasedauthenticator/FileBasedAuthenticator.java
Outdated
Show resolved
Hide resolved
...rc/main/java/io/prestosql/plugin/password/filebasedauthenticator/FileBasedAuthenticator.java
Outdated
Show resolved
Hide resolved
...d-authenticators/src/main/java/io/prestosql/plugin/password/filebasedauthenticator/User.java
Outdated
Show resolved
Hide resolved
...-authenticators/src/main/java/io/prestosql/plugin/password/filebasedauthenticator/Users.java
Outdated
Show resolved
Hide resolved
...d-authenticators/src/main/java/io/prestosql/plugin/password/filebasedauthenticator/User.java
Outdated
Show resolved
Hide resolved
...tors/src/main/java/io/prestosql/plugin/password/filebasedauthenticator/EncryptionHelper.java
Outdated
Show resolved
Hide resolved
f85acfa
to
1644591
Compare
...d-authenticators/src/main/java/io/prestosql/plugin/password/PasswordAuthenticatorPlugin.java
Outdated
Show resolved
Hide resolved
.../java/io/prestosql/plugin/password/filebasedauthenticator/FileBasedAuthenticationConfig.java
Outdated
Show resolved
Hide resolved
.../java/io/prestosql/plugin/password/filebasedauthenticator/FileBasedAuthenticationConfig.java
Outdated
Show resolved
Hide resolved
...o-password-authenticators/src/test/java/io/prestosql/plugin/password/TestFileAuthConfig.java
Outdated
Show resolved
Hide resolved
...o-password-authenticators/src/test/java/io/prestosql/plugin/password/TestFileAuthConfig.java
Show resolved
Hide resolved
27eeead
to
8c3eb4d
Compare
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.
Just some comments, review in progress...
...tors/src/main/java/io/prestosql/plugin/password/filebasedauthenticator/EncryptionHelper.java
Outdated
Show resolved
Hide resolved
.../java/io/prestosql/plugin/password/filebasedauthenticator/FileBasedAuthenticationConfig.java
Outdated
Show resolved
Hide resolved
...tors/src/main/java/io/prestosql/plugin/password/filebasedauthenticator/EncryptionHelper.java
Outdated
Show resolved
Hide resolved
...tors/src/main/java/io/prestosql/plugin/password/filebasedauthenticator/EncryptionHelper.java
Outdated
Show resolved
Hide resolved
...c/main/java/io/prestosql/plugin/password/filebasedauthenticator/HashedPasswordException.java
Outdated
Show resolved
Hide resolved
...tors/src/main/java/io/prestosql/plugin/password/filebasedauthenticator/HashingAlgorithm.java
Outdated
Show resolved
Hide resolved
...tors/src/main/java/io/prestosql/plugin/password/filebasedauthenticator/EncryptionHelper.java
Outdated
Show resolved
Hide resolved
...tors/src/main/java/io/prestosql/plugin/password/filebasedauthenticator/EncryptionHelper.java
Outdated
Show resolved
Hide resolved
...tors/src/main/java/io/prestosql/plugin/password/filebasedauthenticator/EncryptionHelper.java
Outdated
Show resolved
Hide resolved
...tors/src/main/java/io/prestosql/plugin/password/filebasedauthenticator/EncryptionHelper.java
Outdated
Show resolved
Hide resolved
...tors/src/main/java/io/prestosql/plugin/password/filebasedauthenticator/EncryptionHelper.java
Outdated
Show resolved
Hide resolved
...d-authenticators/src/main/java/io/prestosql/plugin/password/filebasedauthenticator/User.java
Outdated
Show resolved
Hide resolved
...d-authenticators/src/main/java/io/prestosql/plugin/password/filebasedauthenticator/User.java
Outdated
Show resolved
Hide resolved
...-authenticators/src/main/java/io/prestosql/plugin/password/filebasedauthenticator/Users.java
Outdated
Show resolved
Hide resolved
...rc/main/java/io/prestosql/plugin/password/filebasedauthenticator/FileBasedAuthenticator.java
Outdated
Show resolved
Hide resolved
...rc/main/java/io/prestosql/plugin/password/filebasedauthenticator/FileBasedAuthenticator.java
Outdated
Show resolved
Hide resolved
c6ca106
to
4b92c7c
Compare
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.
This is looking much better and is nearly ready to merge. The only major concern is the way refresh is handled in FileBasedAuthenticatorFactory
. Otherwise, lots of minor comments.
...-password-authenticators/src/main/java/io/prestosql/plugin/password/file/EncryptionUtil.java
Outdated
Show resolved
Hide resolved
...-password-authenticators/src/main/java/io/prestosql/plugin/password/file/EncryptionUtil.java
Outdated
Show resolved
Hide resolved
...-password-authenticators/src/main/java/io/prestosql/plugin/password/file/EncryptionUtil.java
Outdated
Show resolved
Hide resolved
presto-product-tests/src/main/java/io/prestosql/tests/cli/PrestoCliFileAuthTests.java
Outdated
Show resolved
Hide resolved
presto-product-tests/src/main/java/io/prestosql/tests/cli/PrestoCliFileAuthTests.java
Outdated
Show resolved
Hide resolved
presto-product-tests/src/main/java/io/prestosql/tests/cli/PrestoCliFileAuthTests.java
Outdated
Show resolved
Hide resolved
presto-product-tests/src/main/java/io/prestosql/tests/cli/PrestoCliFileAuthTests.java
Outdated
Show resolved
Hide resolved
...nticators/src/main/java/io/prestosql/plugin/password/file/FileBasedAuthenticatorFactory.java
Outdated
Show resolved
Hide resolved
@rupamk I notice some of these comments say "done" but I don't see any new commits. Please let me know when the latest changes are pushed. |
431ba9a
to
aae846c
Compare
@electrum I have pushed my changes. |
2b613ba
to
d0424a0
Compare
FileBasedAuthentication Plugin is added where usernames and passwords are provided to Presto through a file which contains user credentials in a standard format and users submitting the query are authenticated using this information. ** Overall changes summary ** 1. Maintain a Supplier for reloading the file auth file after every configurable refresh_period to facilitate modifying /updating the file containing the user:password without restarting the presto server. 2. Maintain an LRU cache for storing the authentication token (to avoid hashing the input password for every request) which is bounded by the lifetime of the FileBasedAuthenticator.class (ideally everytime 1 refreshes 2 gets cleared too) 3. The only two hashing algorithms used are BCRYPT and PBKDF2. 4. Once the Filebasedauthenticator.class gets invoked, it reads the file and creates a Authentication Map containing User objects against a unique username. This map is created as a Supplier so that the user profiles expires after the provided refresh_period. 5. While the User object is getting created, two functionalities are performed: a. hashing algo is determined and stored for that user profile b. hashing restrictions are checked (for eg. for bcrypt password if the cost is < 8 (configaurable value) there will be exceptions and the server will fail, for PBKDF2 the min iterations allowed for password creation is 1000 (configurable value)) 6. During query execution, once the authenticate call is initiated with a set of (username, password), as a first round of checking, the Authentication Map created in step 4 while reading the file is checked to find whether the user name exists, if yes credentials are authenticated to verify the password. 7. Unit Tests added to verify each one of the functionality. 8. Product tests updated to account for the current changes * Recent Changes * 1. Minor changes 2. Refresh Logic is now moved inside FileBasedAuthenticator.class
d0424a0
to
c62927d
Compare
I suggest adding user documentation for this new feature. |
@electrum How should I create the documentation? For example, write it up in a doc and share it here? |
@rupamk You may refer to these: |
Replaced by #1912 |
FileBasedAuthentication is added where usernames and passwords are provided to Presto through a file which contains user credentials in a standard format and users submitting the query are authenticated using this information. More Details
http-server.https.enabled=true
http-server.https.port=8443
http-server.https.keystore.path=<path-to-keystore>/<keystore>
http-server.https.keystore.key=<key>
http-server.authentication.type=PASSWORD
Note: For generating the keystore, refer here
Create: /etc/password-authenticator.properties containing:
password-authenticator.name=file
file.config-file=/usr/lib/presto/etc/file_auth
file.refresh-period=10ms
file.bcrypt.min-cost=8
file.pbkdf2.min-iterations=1000
file.auth-token-cache-max-size=1000
Create a "user:password" in /etc/file_auth containing:
userPBKDF2:1000:5b4240333032306164:f38d165fce8ce42f59d366139ef5d9e1ca1247f0e06e503ee1a611dd9ec40876bb5edb8409f5abe5504aab6628e70cfb3d3a18e99d70357d295002c3d0a308a0
userBCrypt:$2y$10$BqTb8hScP5DfcpmHo5PeyugxHz5Ky/qf3wrpD7SNm8sWuA3VlGqsa
After starting presto server, execute:
presto-cli/target/presto-cli-*-executable.jar --server https://127.0.0.1:8443 --user userBCrypt --password
With correct password, and then “show catalog“ runs without error.
With wrong password, and then “show catalog“ yields:
Error running command: Authentication failed: Access Denied: Invalid credentials
Error running command: Authentication failed: Malformed decoded credentials
presto-product-tests/bin/run_on_docker.sh fileauth -t io.prestosql.tests.cli.PrestoCliFileAuthTests
2019-10-11 06:14:14 INFO: Completed 6 tests
2019-10-11 06:14:14 INFO: 6 SUCCEEDED / 0 FAILED / 0 SKIPPED
2019-10-11 06:14:14 INFO: Tests execution took 1 minutes and 3 seconds
Added Unit tests: TestFileAuthConfig
Modifications in the design:
--> Cache Implementation:
Periodically reload the password file, so that administrators don't need to restart the server when modifying the user list. (configurable - file.refresh-period passed as a parameter in /etc/password-authenticator.properties)
For the encryption algorithms, the number of rounds or iterations must be chosen. A larger number means it is more expensive to compute the hash, and thus slows down an attacker that is cracking the password file. Currently, file.bcrypt-min-cost and file.pbkdf2-min-iterations takes as input the values for enforcing the restriction on the two hashing algorithms used.
LRU cache is implemented to reuse the decoded passwords for a certain period of time (bounded by file.refresh-period, since anyhow they are going to get cleared when the file reloads). Also, since to restrict the LRU cache to explode a size of 1000 is kept fixed and after that least used entries (typically the negative entries) are evicted.
** Overall changes summary **
Addresses part of #1065