Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.Maps;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
Expand Down Expand Up @@ -2042,7 +2043,6 @@ public void testDlsFls() throws Exception {
);

// FLS sort of applies to failure store
// TODO this will change with FLS handling
assertSearchResponseContainsExpectedIndicesAndFields(
performRequest(user, new Search("test1::failures").toSearchRequest()),
Map.of(failureIndexName, Set.of("@timestamp"))
Expand All @@ -2062,24 +2062,56 @@ public void testDlsFls() throws Exception {
{
"names": ["test*"],
"privileges": ["read_failure_store"],
"field_security": {
"grant": ["error.type", "error.message"]
}
}
]
}""", "test1"), role);

// FLS applies to regular data stream
assertSearchResponseContainsExpectedIndicesAndFields(
performRequest(user, new Search(randomFrom("test1", "test1::data")).toSearchRequest()),
Map.of(dataIndexName, Set.of("@timestamp", "age"))
);

// FLS applies to failure store
assertSearchResponseContainsExpectedIndicesAndFields(
performRequest(user, new Search("test1::failures").toSearchRequest()),
Map.of(failureIndexName, Set.of("error.type", "error.message"))
);

upsertRole(Strings.format("""
{
"cluster": ["all"],
"indices": [
{
"names": ["%s"],
"privileges": ["read"],
"field_security": {
"grant": ["@timestamp", "age"]
}
},
{
"names": ["test*"],
"privileges": ["read_failure_store"],
"field_security": {
"grant": ["error.type", "error.message"]
}
}
]
}""", randomFrom("test*", "test1")), role);
}""", "test*"), role);

// FLS applies to regular data stream
assertSearchResponseContainsExpectedIndicesAndFields(
performRequest(user, new Search(randomFrom("test1", "test1::data")).toSearchRequest()),
Map.of(dataIndexName, Set.of("@timestamp", "age"))
);

// FLS sort of applies to failure store
// TODO this will change with FLS handling
// FLS applies to failure store
assertSearchResponseContainsExpectedIndicesAndFields(
performRequest(user, new Search("test1::failures").toSearchRequest()),
Map.of(failureIndexName, Set.of("@timestamp"))
Map.of(failureIndexName, Set.of("@timestamp", "error.type", "error.message"))
);

upsertRole("""
Expand All @@ -2105,10 +2137,56 @@ public void testDlsFls() throws Exception {
performRequest(user, new Search(randomFrom("test1", "test1::data")).toSearchRequest()),
Map.of(dataIndexName, Set.of("@timestamp", "age", "name", "email"))
);

assertSearchResponseContainsExpectedIndicesAndFields(
performRequest(user, new Search("test1::failures").toSearchRequest()),
Map.of(failureIndexName, Set.of("@timestamp", "document", "error"))
Map.of(
failureIndexName,
Set.of(
"@timestamp",
"document.id",
"document.index",
"document.source.@timestamp",
"document.source.age",
"document.source.email",
"document.source.name",
"error.message",
"error.stack_trace",
"error.type"
)
)
);

// check that direct read access to backing indices is working
upsertRole(Strings.format("""
{
"cluster": ["all"],
"indices": [
{
"names": ["%s"],
"privileges": ["read"],
"field_security": {
"grant": ["@timestamp", "age"]
}
},
{
"names": ["%s"],
"privileges": ["read"],
"field_security": {
"grant": ["@timestamp", "document.source.name"]
}
}
]
}""", dataIndexName, failureIndexName), role);

// FLS applies to backing data index
assertSearchResponseContainsExpectedIndicesAndFields(
performRequest(user, new Search(randomFrom(dataIndexName, ".ds-*")).toSearchRequest()),
Map.of(dataIndexName, Set.of("@timestamp", "age"))
);
// and backing failure index
assertSearchResponseContainsExpectedIndicesAndFields(
performRequest(user, new Search(randomFrom(failureIndexName, ".fs-*")).toSearchRequest()),
Map.of(failureIndexName, Set.of("@timestamp", "document.source.name"))
);

// DLS
Expand Down Expand Up @@ -2160,6 +2238,21 @@ public void testDlsFls() throws Exception {
}""", role);
// DLS does not apply because there is a section without DLS
expectSearch(user, new Search(randomFrom("test1", "test1::data")), dataIndexDocId);

// DLS is applicable to backing failure store when granted read directly
upsertRole(Strings.format("""
{
"cluster": ["all"],
"indices": [
{
"names": ["%s"],
"privileges": ["read"],
"query":{"term":{"document.source.name":{"value":"jack"}}}
}
]
}""", failureIndexName), role);
expectSearch(user, new Search(randomFrom(".fs-*", failureIndexName)));

}

private static void expectThrows(ThrowingRunnable runnable, int statusCode) {
Expand Down Expand Up @@ -2455,7 +2548,7 @@ protected void assertSearchResponseContainsExpectedIndicesAndFields(
assertThat(searchResult.keySet(), equalTo(expectedIndicesAndFields.keySet()));
for (String index : expectedIndicesAndFields.keySet()) {
Set<String> expectedFields = expectedIndicesAndFields.get(index);
assertThat(searchResult.get(index).keySet(), equalTo(expectedFields));
assertThat(Maps.flatten(searchResult.get(index), false, true).keySet(), equalTo(expectedFields));
}
} finally {
response.decRef();
Expand Down