Skip to content

Commit

Permalink
fix security IT failure caused by weak password (#951)
Browse files Browse the repository at this point in the history
Signed-off-by: Yaliang Wu <[email protected]>
  • Loading branch information
ylwu-amzn authored and zane-neo committed Aug 28, 2023
1 parent f93e789 commit b19b713
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 54 deletions.
50 changes: 19 additions & 31 deletions plugin/src/test/java/org/opensearch/ml/rest/MLModelGroupRestIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class MLModelGroupRestIT extends MLCommonsRestTestCase {
public ExpectedException exceptionRule = ExpectedException.none();

private String modelGroupId;
private String password = "IntegTest@MLModelGroupRestIT123";

@Before
public void setup() throws IOException {
Expand All @@ -77,56 +78,43 @@ public void setup() throws IOException {
}
createSearchRole(indexSearchAccessRole, "*");

createUser(mlNoAccessUser, mlNoAccessUser, ImmutableList.of(opensearchBackendRole));
mlNoAccessClient = new SecureRestClientBuilder(
getClusterHosts().toArray(new HttpHost[0]),
isHttps(),
mlNoAccessUser,
mlNoAccessUser
).setSocketTimeout(60000).build();
createUser(mlNoAccessUser, password, ImmutableList.of(opensearchBackendRole));
mlNoAccessClient = new SecureRestClientBuilder(getClusterHosts().toArray(new HttpHost[0]), isHttps(), mlNoAccessUser, password)
.setSocketTimeout(60000)
.build();

createUser(mlReadOnlyUser, mlReadOnlyUser, ImmutableList.of(opensearchBackendRole));
mlReadOnlyClient = new SecureRestClientBuilder(
getClusterHosts().toArray(new HttpHost[0]),
isHttps(),
mlReadOnlyUser,
mlReadOnlyUser
).setSocketTimeout(60000).build();
createUser(mlReadOnlyUser, password, ImmutableList.of(opensearchBackendRole));
mlReadOnlyClient = new SecureRestClientBuilder(getClusterHosts().toArray(new HttpHost[0]), isHttps(), mlReadOnlyUser, password)
.setSocketTimeout(60000)
.build();

createUser(mlFullAccessNoIndexAccessUser, mlFullAccessNoIndexAccessUser, ImmutableList.of(opensearchBackendRole));
createUser(mlFullAccessNoIndexAccessUser, password, ImmutableList.of(opensearchBackendRole));
mlFullAccessNoIndexAccessClient = new SecureRestClientBuilder(
getClusterHosts().toArray(new HttpHost[0]),
isHttps(),
mlFullAccessNoIndexAccessUser,
mlFullAccessNoIndexAccessUser
password
).setSocketTimeout(60000).build();

createUser(mlFullAccessUser, mlFullAccessUser, ImmutableList.of(opensearchBackendRole));
mlFullAccessClient = new SecureRestClientBuilder(
getClusterHosts().toArray(new HttpHost[0]),
isHttps(),
mlFullAccessUser,
mlFullAccessUser
).setSocketTimeout(60000).build();
createUser(mlFullAccessUser, password, ImmutableList.of(opensearchBackendRole));
mlFullAccessClient = new SecureRestClientBuilder(getClusterHosts().toArray(new HttpHost[0]), isHttps(), mlFullAccessUser, password)
.setSocketTimeout(60000)
.build();

createUser(mlNonAdminFullAccessWithoutBackendRoleUser, mlNonAdminFullAccessWithoutBackendRoleUser, ImmutableList.of());
createUser(mlNonAdminFullAccessWithoutBackendRoleUser, password, ImmutableList.of());
mlNonAdminFullAccessWithoutBackendRoleClient = new SecureRestClientBuilder(
getClusterHosts().toArray(new HttpHost[0]),
isHttps(),
mlNonAdminFullAccessWithoutBackendRoleUser,
mlNonAdminFullAccessWithoutBackendRoleUser
password
).setSocketTimeout(60000).build();

createUser(
mlNonOwnerFullAccessWithBackendRoleUser,
mlNonOwnerFullAccessWithBackendRoleUser,
ImmutableList.of(opensearchBackendRole)
);
createUser(mlNonOwnerFullAccessWithBackendRoleUser, password, ImmutableList.of(opensearchBackendRole));
mlNonOwnerFullAccessWithBackendRoleClient = new SecureRestClientBuilder(
getClusterHosts().toArray(new HttpHost[0]),
isHttps(),
mlNonOwnerFullAccessWithBackendRoleUser,
mlNonOwnerFullAccessWithBackendRoleUser
password
).setSocketTimeout(60000).build();

createRoleMapping("ml_read_access", ImmutableList.of(mlReadOnlyUser));
Expand Down
38 changes: 15 additions & 23 deletions plugin/src/test/java/org/opensearch/ml/rest/SecureMLRestIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class SecureMLRestIT extends MLCommonsRestTestCase {
public ExpectedException exceptionRule = ExpectedException.none();

private String modelGroupId;
private String password = "IntegTest@SecureMLRestIT123";

@Before
public void setup() throws IOException, ParseException {
Expand All @@ -77,37 +78,28 @@ public void setup() throws IOException, ParseException {
}
createSearchRole(indexSearchAccessRole, "*");

createUser(mlNoAccessUser, mlNoAccessUser, new ArrayList<>(Arrays.asList(opensearchBackendRole)));
mlNoAccessClient = new SecureRestClientBuilder(
getClusterHosts().toArray(new HttpHost[0]),
isHttps(),
mlNoAccessUser,
mlNoAccessUser
).setSocketTimeout(60000).build();
createUser(mlNoAccessUser, password, new ArrayList<>(Arrays.asList(opensearchBackendRole)));
mlNoAccessClient = new SecureRestClientBuilder(getClusterHosts().toArray(new HttpHost[0]), isHttps(), mlNoAccessUser, password)
.setSocketTimeout(60000)
.build();

createUser(mlReadOnlyUser, mlReadOnlyUser, new ArrayList<>(Arrays.asList(opensearchBackendRole)));
mlReadOnlyClient = new SecureRestClientBuilder(
getClusterHosts().toArray(new HttpHost[0]),
isHttps(),
mlReadOnlyUser,
mlReadOnlyUser
).setSocketTimeout(60000).build();
createUser(mlReadOnlyUser, password, new ArrayList<>(Arrays.asList(opensearchBackendRole)));
mlReadOnlyClient = new SecureRestClientBuilder(getClusterHosts().toArray(new HttpHost[0]), isHttps(), mlReadOnlyUser, password)
.setSocketTimeout(60000)
.build();

createUser(mlFullAccessNoIndexAccessUser, mlFullAccessNoIndexAccessUser, new ArrayList<>(Arrays.asList(opensearchBackendRole)));
createUser(mlFullAccessNoIndexAccessUser, password, new ArrayList<>(Arrays.asList(opensearchBackendRole)));
mlFullAccessNoIndexAccessClient = new SecureRestClientBuilder(
getClusterHosts().toArray(new HttpHost[0]),
isHttps(),
mlFullAccessNoIndexAccessUser,
mlFullAccessNoIndexAccessUser
password
).setSocketTimeout(60000).build();

createUser(mlFullAccessUser, mlFullAccessUser, new ArrayList<>(Arrays.asList(opensearchBackendRole)));
mlFullAccessClient = new SecureRestClientBuilder(
getClusterHosts().toArray(new HttpHost[0]),
isHttps(),
mlFullAccessUser,
mlFullAccessUser
).setSocketTimeout(60000).build();
createUser(mlFullAccessUser, password, new ArrayList<>(Arrays.asList(opensearchBackendRole)));
mlFullAccessClient = new SecureRestClientBuilder(getClusterHosts().toArray(new HttpHost[0]), isHttps(), mlFullAccessUser, password)
.setSocketTimeout(60000)
.build();

createRoleMapping("ml_read_access", new ArrayList<>(Arrays.asList(mlReadOnlyUser)));
createRoleMapping("ml_full_access", new ArrayList<>(Arrays.asList(mlFullAccessNoIndexAccessUser, mlFullAccessUser)));
Expand Down

0 comments on commit b19b713

Please sign in to comment.