Skip to content

Commit 0146dbd

Browse files
authored
fix security IT failure caused by weak password (#951)
Signed-off-by: Yaliang Wu <ylwu@amazon.com>
1 parent da5db17 commit 0146dbd

File tree

2 files changed

+34
-54
lines changed

2 files changed

+34
-54
lines changed

plugin/src/test/java/org/opensearch/ml/rest/MLModelGroupRestIT.java

+19-31
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public class MLModelGroupRestIT extends MLCommonsRestTestCase {
5858
public ExpectedException exceptionRule = ExpectedException.none();
5959

6060
private String modelGroupId;
61+
private String password = "IntegTest@MLModelGroupRestIT123";
6162

6263
@Before
6364
public void setup() throws IOException {
@@ -77,56 +78,43 @@ public void setup() throws IOException {
7778
}
7879
createSearchRole(indexSearchAccessRole, "*");
7980

80-
createUser(mlNoAccessUser, mlNoAccessUser, ImmutableList.of(opensearchBackendRole));
81-
mlNoAccessClient = new SecureRestClientBuilder(
82-
getClusterHosts().toArray(new HttpHost[0]),
83-
isHttps(),
84-
mlNoAccessUser,
85-
mlNoAccessUser
86-
).setSocketTimeout(60000).build();
81+
createUser(mlNoAccessUser, password, ImmutableList.of(opensearchBackendRole));
82+
mlNoAccessClient = new SecureRestClientBuilder(getClusterHosts().toArray(new HttpHost[0]), isHttps(), mlNoAccessUser, password)
83+
.setSocketTimeout(60000)
84+
.build();
8785

88-
createUser(mlReadOnlyUser, mlReadOnlyUser, ImmutableList.of(opensearchBackendRole));
89-
mlReadOnlyClient = new SecureRestClientBuilder(
90-
getClusterHosts().toArray(new HttpHost[0]),
91-
isHttps(),
92-
mlReadOnlyUser,
93-
mlReadOnlyUser
94-
).setSocketTimeout(60000).build();
86+
createUser(mlReadOnlyUser, password, ImmutableList.of(opensearchBackendRole));
87+
mlReadOnlyClient = new SecureRestClientBuilder(getClusterHosts().toArray(new HttpHost[0]), isHttps(), mlReadOnlyUser, password)
88+
.setSocketTimeout(60000)
89+
.build();
9590

96-
createUser(mlFullAccessNoIndexAccessUser, mlFullAccessNoIndexAccessUser, ImmutableList.of(opensearchBackendRole));
91+
createUser(mlFullAccessNoIndexAccessUser, password, ImmutableList.of(opensearchBackendRole));
9792
mlFullAccessNoIndexAccessClient = new SecureRestClientBuilder(
9893
getClusterHosts().toArray(new HttpHost[0]),
9994
isHttps(),
10095
mlFullAccessNoIndexAccessUser,
101-
mlFullAccessNoIndexAccessUser
96+
password
10297
).setSocketTimeout(60000).build();
10398

104-
createUser(mlFullAccessUser, mlFullAccessUser, ImmutableList.of(opensearchBackendRole));
105-
mlFullAccessClient = new SecureRestClientBuilder(
106-
getClusterHosts().toArray(new HttpHost[0]),
107-
isHttps(),
108-
mlFullAccessUser,
109-
mlFullAccessUser
110-
).setSocketTimeout(60000).build();
99+
createUser(mlFullAccessUser, password, ImmutableList.of(opensearchBackendRole));
100+
mlFullAccessClient = new SecureRestClientBuilder(getClusterHosts().toArray(new HttpHost[0]), isHttps(), mlFullAccessUser, password)
101+
.setSocketTimeout(60000)
102+
.build();
111103

112-
createUser(mlNonAdminFullAccessWithoutBackendRoleUser, mlNonAdminFullAccessWithoutBackendRoleUser, ImmutableList.of());
104+
createUser(mlNonAdminFullAccessWithoutBackendRoleUser, password, ImmutableList.of());
113105
mlNonAdminFullAccessWithoutBackendRoleClient = new SecureRestClientBuilder(
114106
getClusterHosts().toArray(new HttpHost[0]),
115107
isHttps(),
116108
mlNonAdminFullAccessWithoutBackendRoleUser,
117-
mlNonAdminFullAccessWithoutBackendRoleUser
109+
password
118110
).setSocketTimeout(60000).build();
119111

120-
createUser(
121-
mlNonOwnerFullAccessWithBackendRoleUser,
122-
mlNonOwnerFullAccessWithBackendRoleUser,
123-
ImmutableList.of(opensearchBackendRole)
124-
);
112+
createUser(mlNonOwnerFullAccessWithBackendRoleUser, password, ImmutableList.of(opensearchBackendRole));
125113
mlNonOwnerFullAccessWithBackendRoleClient = new SecureRestClientBuilder(
126114
getClusterHosts().toArray(new HttpHost[0]),
127115
isHttps(),
128116
mlNonOwnerFullAccessWithBackendRoleUser,
129-
mlNonOwnerFullAccessWithBackendRoleUser
117+
password
130118
).setSocketTimeout(60000).build();
131119

132120
createRoleMapping("ml_read_access", ImmutableList.of(mlReadOnlyUser));

plugin/src/test/java/org/opensearch/ml/rest/SecureMLRestIT.java

+15-23
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public class SecureMLRestIT extends MLCommonsRestTestCase {
5757
public ExpectedException exceptionRule = ExpectedException.none();
5858

5959
private String modelGroupId;
60+
private String password = "IntegTest@SecureMLRestIT123";
6061

6162
@Before
6263
public void setup() throws IOException {
@@ -76,37 +77,28 @@ public void setup() throws IOException {
7677
}
7778
createSearchRole(indexSearchAccessRole, "*");
7879

79-
createUser(mlNoAccessUser, mlNoAccessUser, new ArrayList<>(Arrays.asList(opensearchBackendRole)));
80-
mlNoAccessClient = new SecureRestClientBuilder(
81-
getClusterHosts().toArray(new HttpHost[0]),
82-
isHttps(),
83-
mlNoAccessUser,
84-
mlNoAccessUser
85-
).setSocketTimeout(60000).build();
80+
createUser(mlNoAccessUser, password, new ArrayList<>(Arrays.asList(opensearchBackendRole)));
81+
mlNoAccessClient = new SecureRestClientBuilder(getClusterHosts().toArray(new HttpHost[0]), isHttps(), mlNoAccessUser, password)
82+
.setSocketTimeout(60000)
83+
.build();
8684

87-
createUser(mlReadOnlyUser, mlReadOnlyUser, new ArrayList<>(Arrays.asList(opensearchBackendRole)));
88-
mlReadOnlyClient = new SecureRestClientBuilder(
89-
getClusterHosts().toArray(new HttpHost[0]),
90-
isHttps(),
91-
mlReadOnlyUser,
92-
mlReadOnlyUser
93-
).setSocketTimeout(60000).build();
85+
createUser(mlReadOnlyUser, password, new ArrayList<>(Arrays.asList(opensearchBackendRole)));
86+
mlReadOnlyClient = new SecureRestClientBuilder(getClusterHosts().toArray(new HttpHost[0]), isHttps(), mlReadOnlyUser, password)
87+
.setSocketTimeout(60000)
88+
.build();
9489

95-
createUser(mlFullAccessNoIndexAccessUser, mlFullAccessNoIndexAccessUser, new ArrayList<>(Arrays.asList(opensearchBackendRole)));
90+
createUser(mlFullAccessNoIndexAccessUser, password, new ArrayList<>(Arrays.asList(opensearchBackendRole)));
9691
mlFullAccessNoIndexAccessClient = new SecureRestClientBuilder(
9792
getClusterHosts().toArray(new HttpHost[0]),
9893
isHttps(),
9994
mlFullAccessNoIndexAccessUser,
100-
mlFullAccessNoIndexAccessUser
95+
password
10196
).setSocketTimeout(60000).build();
10297

103-
createUser(mlFullAccessUser, mlFullAccessUser, new ArrayList<>(Arrays.asList(opensearchBackendRole)));
104-
mlFullAccessClient = new SecureRestClientBuilder(
105-
getClusterHosts().toArray(new HttpHost[0]),
106-
isHttps(),
107-
mlFullAccessUser,
108-
mlFullAccessUser
109-
).setSocketTimeout(60000).build();
98+
createUser(mlFullAccessUser, password, new ArrayList<>(Arrays.asList(opensearchBackendRole)));
99+
mlFullAccessClient = new SecureRestClientBuilder(getClusterHosts().toArray(new HttpHost[0]), isHttps(), mlFullAccessUser, password)
100+
.setSocketTimeout(60000)
101+
.build();
110102

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

0 commit comments

Comments
 (0)