Skip to content

Commit d78cc3e

Browse files
committed
DLS
1 parent 4590f04 commit d78cc3e

File tree

1 file changed

+87
-14
lines changed

1 file changed

+87
-14
lines changed

x-pack/plugin/security/qa/security-trial/src/javaRestTest/java/org/elasticsearch/xpack/security/failurestore/FailureStoreSecurityRestIT.java

Lines changed: 87 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,7 @@ public void setup() throws IOException {
9797
}
9898

9999
public void testGetUserPrivileges() throws IOException {
100-
Request userRequest = new Request("PUT", "/_security/user/user");
101-
userRequest.setJsonEntity("""
102-
{
103-
"password": "x-pack-test-password",
104-
"roles": ["role"]
105-
}
106-
""");
107-
assertOK(adminClient().performRequest(userRequest));
100+
createUser("user", PASSWORD, "role");
108101

109102
upsertRole("""
110103
{
@@ -184,6 +177,40 @@ public void testGetUserPrivileges() throws IOException {
184177
"applications": [],
185178
"run_as": []
186179
}""");
180+
181+
upsertRole("""
182+
{
183+
"cluster": ["all"],
184+
"indices": [
185+
{
186+
"names": ["*"],
187+
"privileges": ["read", "read_failure_store"]
188+
},
189+
{
190+
"names": ["*"],
191+
"privileges": ["write", "manage_failure_store"]
192+
}
193+
]
194+
}
195+
""", "role");
196+
expectUserPrivilegesResponse("""
197+
{
198+
"cluster": ["all"],
199+
"global": [],
200+
"indices": [
201+
{
202+
"names": ["*"],
203+
"privileges": ["read", "write"],
204+
"allow_restricted_indices": false
205+
},
206+
{
207+
"names": ["*"],
208+
"privileges": ["manage_failure_store", "read_failure_store"],
209+
"allow_restricted_indices": false
210+
}],
211+
"applications": [],
212+
"run_as": []
213+
}""");
187214
}
188215

189216
public void testRoleWithSelectorInIndexPattern() throws Exception {
@@ -1084,7 +1111,7 @@ public void testFailureStoreAccessWithApiKeys() throws Exception {
10841111
expectUsingApiKey(apiKey, new Search("test1"), 403);
10851112
}
10861113

1087-
public void testFlsDls() throws IOException {
1114+
public void testDlsFls() throws Exception {
10881115
createTemplates();
10891116
populateDataStream();
10901117

@@ -1184,6 +1211,56 @@ public void testFlsDls() throws IOException {
11841211
performRequest(user, new Search("test1::failures").toSearchRequest()),
11851212
Map.of(failureIndexName, Set.of("@timestamp", "document", "error"))
11861213
);
1214+
1215+
// DLS
1216+
String dataIndexDocId = "1";
1217+
upsertRole("""
1218+
{
1219+
"cluster": ["all"],
1220+
"indices": [
1221+
{
1222+
"names": ["test*"],
1223+
"privileges": ["read", "read_failure_store"],
1224+
"query":{"term":{"name":{"value":"not-jack"}}}
1225+
}
1226+
]
1227+
}""", role);
1228+
// DLS applies and no docs match the query
1229+
expect(user, new Search("test1"));
1230+
expect(user, new Search("test1::failures"));
1231+
1232+
upsertRole("""
1233+
{
1234+
"cluster": ["all"],
1235+
"indices": [
1236+
{
1237+
"names": ["test*"],
1238+
"privileges": ["read", "read_failure_store"],
1239+
"query":{"term":{"name":{"value":"jack"}}}
1240+
}
1241+
]
1242+
}""", role);
1243+
// DLS applies and doc matches the query
1244+
expect(user, new Search("test1"), dataIndexDocId);
1245+
expect(user, new Search("test1::failures"));
1246+
1247+
upsertRole("""
1248+
{
1249+
"cluster": ["all"],
1250+
"indices": [
1251+
{
1252+
"names": ["test*"],
1253+
"privileges": ["read"],
1254+
"query":{"term":{"name":{"value":"not-jack"}}}
1255+
},
1256+
{
1257+
"names": ["test*"],
1258+
"privileges": ["read_failure_store"]
1259+
}
1260+
]
1261+
}""", role);
1262+
// DLS does not apply because there is a section without DLS
1263+
expect(user, new Search("test1"), dataIndexDocId);
11871264
}
11881265

11891266
private static void expectThrows(ThrowingRunnable runnable, int statusCode) {
@@ -1390,11 +1467,7 @@ private static Response performRequestWithApiKey(String apiKey, Request request)
13901467

13911468
private static void expectUserPrivilegesResponse(String userPrivilegesResponse) throws IOException {
13921469
Request request = new Request("GET", "/_security/user/_privileges");
1393-
request.setOptions(
1394-
request.getOptions()
1395-
.toBuilder()
1396-
.addHeader("Authorization", basicAuthHeaderValue("user", new SecureString("x-pack-test-password".toCharArray())))
1397-
);
1470+
request.setOptions(request.getOptions().toBuilder().addHeader("Authorization", basicAuthHeaderValue("user", PASSWORD)));
13981471
Response response = client().performRequest(request);
13991472
assertOK(response);
14001473
assertThat(responseAsMap(response), equalTo(mapFromJson(userPrivilegesResponse)));

0 commit comments

Comments
 (0)