-
Notifications
You must be signed in to change notification settings - Fork 324
Adds Argon2 support for password hashing #5441
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
Merged
cwperks
merged 18 commits into
opensearch-project:main
from
aidenlindsay:argon2-feature-to-main
Jul 2, 2025
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
5568e37
first commit on clean branch of old feature changes
aidenlindsay 5e927e8
screwed up import statement removed
aidenlindsay b04dacf
fix: fixed the hash redaction by changing the regex in AuditMessage
aidenlindsay b37dcdd
SpotlessApply to clean up
aidenlindsay 8a45748
removed System.out.println statement
aidenlindsay f0c0085
Made changes to changelog
aidenlindsay 6a05af5
another spotless apply
aidenlindsay 39ccb17
tidy: used the @Parameterized pattern to clean up PasswordHasherTests…
aidenlindsay c632e10
tidy: remove unnecessary legacy JSM code in Argon2, will see if the s…
aidenlindsay 24fef56
tidy: made similar removal changes of legacy JSM code from the other …
aidenlindsay 7fda6bb
fix: use reference to the actual default values from the config file …
aidenlindsay e6cf061
tidy: changed changelog into present tense
aidenlindsay 49fe116
test: added tests for passing an invalid hash, and ensuring that fals…
aidenlindsay 25226c2
fix: changes with config Constants so that they are parsed to the cor…
aidenlindsay ca5a5b0
spent a while trying to find the cause of the unauth error in my test…
aidenlindsay 12bdbf4
bulk integration tests all passed bar the cluster test, trying to get…
aidenlindsay ca937c9
Merge branch 'main' into argon2-feature-to-main
DarshitChanpura 07515fe
Merge branch 'main' into argon2-feature-to-main
aidenlindsay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
src/integrationTest/java/org/opensearch/security/hash/Argon2CustomConfigHashingTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.opensearch.security.hash; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.apache.http.HttpStatus; | ||
import org.awaitility.Awaitility; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import org.opensearch.security.support.ConfigConstants; | ||
import org.opensearch.test.framework.TestSecurityConfig; | ||
import org.opensearch.test.framework.cluster.ClusterManager; | ||
import org.opensearch.test.framework.cluster.LocalCluster; | ||
import org.opensearch.test.framework.cluster.TestRestClient; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.opensearch.test.framework.TestSecurityConfig.AuthcDomain.AUTHC_HTTPBASIC_INTERNAL; | ||
import static org.opensearch.test.framework.TestSecurityConfig.Role.ALL_ACCESS; | ||
|
||
public class Argon2CustomConfigHashingTests extends HashingTests { | ||
|
||
public static LocalCluster cluster; | ||
|
||
private static final String PASSWORD = "top$ecret1234!"; | ||
|
||
private static String type; | ||
private static int memory, iterations, parallelism, length, version; | ||
|
||
@BeforeClass | ||
public static void startCluster() { | ||
|
||
type = randomFrom(List.of("argon2id", "argon2i", "argon2d")); | ||
iterations = randomFrom(List.of(2, 3, 4)); | ||
memory = randomFrom(List.of(65536, 131072)); | ||
parallelism = randomFrom(List.of(1, 2)); | ||
length = randomFrom(List.of(16, 32, 64)); | ||
version = randomFrom(List.of(16, 19)); | ||
|
||
TestSecurityConfig.User ADMIN_USER = new TestSecurityConfig.User("admin").roles(ALL_ACCESS) | ||
.hash(generateArgon2Hash("secret", memory, iterations, parallelism, length, type, version)); | ||
cluster = new LocalCluster.Builder().clusterManager(ClusterManager.SINGLENODE) | ||
.authc(AUTHC_HTTPBASIC_INTERNAL) | ||
.users(ADMIN_USER) | ||
.anonymousAuth(false) | ||
.nodeSettings( | ||
Map.of( | ||
ConfigConstants.SECURITY_RESTAPI_ROLES_ENABLED, | ||
List.of("user_" + ADMIN_USER.getName() + "__" + ALL_ACCESS.getName()), | ||
ConfigConstants.SECURITY_PASSWORD_HASHING_ALGORITHM, | ||
ConfigConstants.ARGON2, | ||
ConfigConstants.SECURITY_PASSWORD_HASHING_ARGON2_MEMORY, | ||
memory, | ||
ConfigConstants.SECURITY_PASSWORD_HASHING_ARGON2_ITERATIONS, | ||
iterations, | ||
ConfigConstants.SECURITY_PASSWORD_HASHING_ARGON2_PARALLELISM, | ||
parallelism, | ||
ConfigConstants.SECURITY_PASSWORD_HASHING_ARGON2_LENGTH, | ||
length, | ||
ConfigConstants.SECURITY_PASSWORD_HASHING_ARGON2_TYPE, | ||
type, | ||
ConfigConstants.SECURITY_PASSWORD_HASHING_ARGON2_VERSION, | ||
version | ||
) | ||
) | ||
.build(); | ||
cluster.before(); | ||
|
||
try (TestRestClient client = cluster.getRestClient(ADMIN_USER.getName(), "secret")) { | ||
Awaitility.await() | ||
.alias("Load default configuration") | ||
.until(() -> client.securityHealth().getTextFromJsonBody("/status"), equalTo("UP")); | ||
} | ||
} | ||
|
||
@Test | ||
public void shouldAuthenticateWithCorrectPassword() { | ||
String hash = generateArgon2Hash(PASSWORD, memory, iterations, parallelism, length, type, version); | ||
createUserWithHashedPassword(cluster, "user_1", hash); | ||
testPasswordAuth(cluster, "user_1", PASSWORD, HttpStatus.SC_OK); | ||
|
||
createUserWithPlainTextPassword(cluster, "user_2", PASSWORD); | ||
testPasswordAuth(cluster, "user_2", PASSWORD, HttpStatus.SC_OK); | ||
} | ||
|
||
@Test | ||
public void shouldNotAuthenticateWithIncorrectPassword() { | ||
String hash = generateArgon2Hash(PASSWORD, memory, iterations, parallelism, length, type, version); | ||
createUserWithHashedPassword(cluster, "user_3", hash); | ||
testPasswordAuth(cluster, "user_3", "wrong_password", HttpStatus.SC_UNAUTHORIZED); | ||
|
||
createUserWithPlainTextPassword(cluster, "user_4", PASSWORD); | ||
testPasswordAuth(cluster, "user_4", "wrong_password", HttpStatus.SC_UNAUTHORIZED); | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
src/integrationTest/java/org/opensearch/security/hash/Argon2DefaultConfigHashingTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.opensearch.security.hash; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.apache.http.HttpStatus; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
|
||
import org.opensearch.security.support.ConfigConstants; | ||
import org.opensearch.test.framework.TestSecurityConfig; | ||
import org.opensearch.test.framework.cluster.ClusterManager; | ||
import org.opensearch.test.framework.cluster.LocalCluster; | ||
|
||
import static org.opensearch.test.framework.TestSecurityConfig.AuthcDomain.AUTHC_HTTPBASIC_INTERNAL; | ||
import static org.opensearch.test.framework.TestSecurityConfig.Role.ALL_ACCESS; | ||
|
||
public class Argon2DefaultConfigHashingTests extends HashingTests { | ||
|
||
private static final TestSecurityConfig.User ADMIN_USER = new TestSecurityConfig.User("admin").roles(ALL_ACCESS) | ||
.hash( | ||
generateArgon2Hash( | ||
"secret", | ||
ConfigConstants.SECURITY_PASSWORD_HASHING_ARGON2_MEMORY_DEFAULT, | ||
ConfigConstants.SECURITY_PASSWORD_HASHING_ARGON2_ITERATIONS_DEFAULT, | ||
ConfigConstants.SECURITY_PASSWORD_HASHING_ARGON2_PARALLELISM_DEFAULT, | ||
ConfigConstants.SECURITY_PASSWORD_HASHING_ARGON2_LENGTH_DEFAULT, | ||
ConfigConstants.SECURITY_PASSWORD_HASHING_ARGON2_TYPE_DEFAULT, | ||
ConfigConstants.SECURITY_PASSWORD_HASHING_ARGON2_VERSION_DEFAULT | ||
) | ||
); | ||
|
||
@ClassRule | ||
public static final LocalCluster cluster = new LocalCluster.Builder().clusterManager(ClusterManager.SINGLENODE) | ||
.authc(AUTHC_HTTPBASIC_INTERNAL) | ||
.users(ADMIN_USER) | ||
.anonymousAuth(false) | ||
.nodeSettings( | ||
Map.of( | ||
ConfigConstants.SECURITY_RESTAPI_ROLES_ENABLED, | ||
List.of("user_" + ADMIN_USER.getName() + "__" + ALL_ACCESS.getName()), | ||
ConfigConstants.SECURITY_PASSWORD_HASHING_ALGORITHM, | ||
ConfigConstants.ARGON2 | ||
) | ||
) | ||
.build(); | ||
|
||
@Test | ||
public void shouldAuthenticateWithCorrectPassword() { | ||
String hash = generateArgon2Hash( | ||
PASSWORD, | ||
ConfigConstants.SECURITY_PASSWORD_HASHING_ARGON2_MEMORY_DEFAULT, | ||
ConfigConstants.SECURITY_PASSWORD_HASHING_ARGON2_ITERATIONS_DEFAULT, | ||
ConfigConstants.SECURITY_PASSWORD_HASHING_ARGON2_PARALLELISM_DEFAULT, | ||
ConfigConstants.SECURITY_PASSWORD_HASHING_ARGON2_LENGTH_DEFAULT, | ||
ConfigConstants.SECURITY_PASSWORD_HASHING_ARGON2_TYPE_DEFAULT, | ||
ConfigConstants.SECURITY_PASSWORD_HASHING_ARGON2_VERSION_DEFAULT | ||
); | ||
createUserWithHashedPassword(cluster, "user_1", hash); | ||
testPasswordAuth(cluster, "user_1", PASSWORD, HttpStatus.SC_OK); | ||
|
||
createUserWithPlainTextPassword(cluster, "user_2", PASSWORD); | ||
testPasswordAuth(cluster, "user_2", PASSWORD, HttpStatus.SC_OK); | ||
} | ||
|
||
@Test | ||
public void shouldNotAuthenticateWithIncorrectPassword() { | ||
String hash = generateArgon2Hash( | ||
PASSWORD, | ||
ConfigConstants.SECURITY_PASSWORD_HASHING_ARGON2_MEMORY_DEFAULT, | ||
ConfigConstants.SECURITY_PASSWORD_HASHING_ARGON2_ITERATIONS_DEFAULT, | ||
ConfigConstants.SECURITY_PASSWORD_HASHING_ARGON2_PARALLELISM_DEFAULT, | ||
ConfigConstants.SECURITY_PASSWORD_HASHING_ARGON2_LENGTH_DEFAULT, | ||
ConfigConstants.SECURITY_PASSWORD_HASHING_ARGON2_TYPE_DEFAULT, | ||
ConfigConstants.SECURITY_PASSWORD_HASHING_ARGON2_VERSION_DEFAULT | ||
); | ||
createUserWithHashedPassword(cluster, "user_3", hash); | ||
testPasswordAuth(cluster, "user_3", "wrongpassword", HttpStatus.SC_UNAUTHORIZED); | ||
|
||
createUserWithPlainTextPassword(cluster, "user_4", PASSWORD); | ||
testPasswordAuth(cluster, "user_4", "wrongpassword", HttpStatus.SC_UNAUTHORIZED); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.