Skip to content

Commit 9674301

Browse files
Revert "[Backport 2.x] Remove static metaFields list and get version-specific values from core" (#4474)
Signed-off-by: Darshit Chanpura <[email protected]>
1 parent cdc792c commit 9674301

File tree

6 files changed

+19
-124
lines changed

6 files changed

+19
-124
lines changed

build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,6 @@ dependencies {
722722
exclude(group: 'org.hamcrest', module: 'hamcrest')
723723
}
724724
integrationTestImplementation 'com.unboundid:unboundid-ldapsdk:4.0.14'
725-
integrationTestImplementation "org.opensearch.plugin:mapper-size:${opensearch_version}"
726725
integrationTestImplementation "org.apache.httpcomponents:httpclient-cache:4.5.14"
727726
integrationTestImplementation "org.apache.httpcomponents:httpclient:4.5.14"
728727
integrationTestImplementation "org.apache.httpcomponents:fluent-hc:4.5.14"

release-notes/opensearch-security.release-notes-2.15.0.0.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Compatible with OpenSearch and OpenSearch Dashboards version 2.15.0
99
* Refactor ActionGroup REST API test and partial fix #4166 ([#4371](https://github.com/opensearch-project/security/pull/4371))
1010
* Support multiple audience for jwt authentication ([#4363](https://github.com/opensearch-project/security/pull/4363))
1111
* Configure masking algorithm default ([#4345](https://github.com/opensearch-project/security/pull/4345))
12-
* Remove static metaFields list and get version-specific values from core ([#4412](https://github.com/opensearch-project/security/pull/4412))
1312

1413
### Bug Fixes
1514
* Add cat/alias support for DNFOF ([#4440](https://github.com/opensearch-project/security/pull/4440))

src/integrationTest/java/org/opensearch/security/FlsAndFieldMaskingTests.java

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.junit.runner.RunWith;
2828

2929
import org.opensearch.action.admin.indices.alias.IndicesAliasesRequest;
30-
import org.opensearch.action.admin.indices.create.CreateIndexRequest;
3130
import org.opensearch.action.fieldcaps.FieldCapabilitiesRequest;
3231
import org.opensearch.action.fieldcaps.FieldCapabilitiesResponse;
3332
import org.opensearch.action.get.GetRequest;
@@ -44,15 +43,10 @@
4443
import org.opensearch.action.search.SearchScrollRequest;
4544
import org.opensearch.client.Client;
4645
import org.opensearch.client.RestHighLevelClient;
47-
import org.opensearch.index.mapper.SourceFieldMapper;
48-
import org.opensearch.index.mapper.size.SizeFieldMapper;
49-
import org.opensearch.index.query.MatchAllQueryBuilder;
5046
import org.opensearch.index.query.QueryBuilder;
5147
import org.opensearch.index.query.QueryBuilders;
52-
import org.opensearch.plugin.mapper.MapperSizePlugin;
5348
import org.opensearch.search.aggregations.Aggregation;
5449
import org.opensearch.search.aggregations.metrics.ParsedAvg;
55-
import org.opensearch.search.builder.SearchSourceBuilder;
5650
import org.opensearch.search.sort.SortOrder;
5751
import org.opensearch.test.framework.TestSecurityConfig;
5852
import org.opensearch.test.framework.cluster.ClusterManager;
@@ -61,7 +55,6 @@
6155

6256
import static org.hamcrest.MatcherAssert.assertThat;
6357
import static org.hamcrest.Matchers.allOf;
64-
import static org.hamcrest.Matchers.containsString;
6558
import static org.hamcrest.Matchers.everyItem;
6659
import static org.hamcrest.Matchers.greaterThan;
6760
import static org.hamcrest.Matchers.instanceOf;
@@ -101,7 +94,6 @@
10194
import static org.opensearch.test.framework.matcher.SearchResponseMatchers.isSuccessfulSearchResponse;
10295
import static org.opensearch.test.framework.matcher.SearchResponseMatchers.numberOfTotalHitsIsEqualTo;
10396
import static org.opensearch.test.framework.matcher.SearchResponseMatchers.searchHitContainsFieldWithValue;
104-
import static org.opensearch.test.framework.matcher.SearchResponseMatchers.searchHitDoesContainField;
10597
import static org.opensearch.test.framework.matcher.SearchResponseMatchers.searchHitDoesNotContainField;
10698
import static org.opensearch.test.framework.matcher.SearchResponseMatchers.searchHitsContainDocumentWithId;
10799

@@ -220,7 +212,6 @@ public class FlsAndFieldMaskingTests {
220212
.nodeSettings(
221213
Map.of("plugins.security.restapi.roles_enabled", List.of("user_" + ADMIN_USER.getName() + "__" + ALL_ACCESS.getName()))
222214
)
223-
.plugin(MapperSizePlugin.class)
224215
.authc(AUTHC_HTTPBASIC_INTERNAL)
225216
.users(
226217
ADMIN_USER,
@@ -435,10 +426,6 @@ public void flsEnabledFieldsAreHiddenForNormalUsers() throws IOException {
435426

436427
private static List<String> createIndexWithDocs(String indexName, Song... songs) {
437428
try (Client client = cluster.getInternalNodeClient()) {
438-
client.admin()
439-
.indices()
440-
.create(new CreateIndexRequest(indexName).mapping(Map.of("_size", Map.of("enabled", true))))
441-
.actionGet();
442429
return Stream.of(songs).map(song -> {
443430
IndexResponse response = client.index(new IndexRequest(indexName).setRefreshPolicy(IMMEDIATE).source(song.asMap()))
444431
.actionGet();
@@ -482,14 +469,6 @@ private static void assertSearchHitsDoNotContainField(SearchResponse response, S
482469
.forEach(index -> assertThat(response, searchHitDoesNotContainField(index, excludedField)));
483470
}
484471

485-
private static void assertSearchHitsDoContainField(SearchResponse response, String includedField) {
486-
assertThat(response, isSuccessfulSearchResponse());
487-
assertThat(response.getHits().getHits().length, greaterThan(0));
488-
IntStream.range(0, response.getHits().getHits().length)
489-
.boxed()
490-
.forEach(index -> assertThat(response, searchHitDoesContainField(index, includedField)));
491-
}
492-
493472
@Test
494473
public void searchForDocuments() throws IOException {
495474
// FIELD MASKING
@@ -832,28 +811,4 @@ public void getFieldCapabilities() throws IOException {
832811
}
833812
}
834813

835-
@Test
836-
public void flsWithIncludesRulesIncludesFieldMappersFromPlugins() throws IOException {
837-
String indexName = "fls_includes_index";
838-
TestSecurityConfig.Role userRole = new TestSecurityConfig.Role("fls_include_stars_reader").clusterPermissions(
839-
"cluster_composite_ops_ro"
840-
).indexPermissions("read").fls(FIELD_STARS).on("*");
841-
TestSecurityConfig.User user = createUserWithRole("fls_includes_user", userRole);
842-
List<String> docIds = createIndexWithDocs(indexName, SONGS[0], SONGS[1]);
843-
844-
try (RestHighLevelClient restHighLevelClient = cluster.getRestHighLevelClient(user)) {
845-
SearchRequest searchRequest = new SearchRequest(indexName);
846-
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
847-
MatchAllQueryBuilder matchAllQueryBuilder = QueryBuilders.matchAllQuery();
848-
searchSourceBuilder.storedFields(List.of(SizeFieldMapper.NAME, SourceFieldMapper.NAME));
849-
searchSourceBuilder.query(matchAllQueryBuilder);
850-
searchRequest.source(searchSourceBuilder);
851-
SearchResponse searchResponse = restHighLevelClient.search(searchRequest, DEFAULT);
852-
853-
assertSearchHitsDoContainField(searchResponse, FIELD_STARS);
854-
assertThat(searchResponse.toString(), containsString(SizeFieldMapper.NAME));
855-
assertSearchHitsDoNotContainField(searchResponse, FIELD_ARTIST);
856-
}
857-
}
858-
859814
}

src/integrationTest/java/org/opensearch/test/framework/matcher/SearchHitDoesContainFieldMatcher.java

Lines changed: 0 additions & 62 deletions
This file was deleted.

src/integrationTest/java/org/opensearch/test/framework/matcher/SearchResponseMatchers.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ public static Matcher<SearchResponse> searchHitDoesNotContainField(int hitIndex,
4444
return new SearchHitDoesNotContainFieldMatcher(hitIndex, fieldName);
4545
}
4646

47-
public static Matcher<SearchResponse> searchHitDoesContainField(int hitIndex, String fieldName) {
48-
return new SearchHitDoesContainFieldMatcher(hitIndex, fieldName);
49-
}
50-
5147
public static Matcher<SearchResponse> searchHitsContainDocumentWithId(int hitIndex, String indexName, String documentId) {
5248
return new SearchHitsContainDocumentWithIdMatcher(hitIndex, indexName, documentId);
5349
}

src/main/java/org/opensearch/security/configuration/SecurityFlsDlsIndexSearcherWrapper.java

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
package org.opensearch.security.configuration;
1313

1414
import java.io.IOException;
15-
import java.util.Arrays;
16-
import java.util.Collections;
1715
import java.util.HashSet;
1816
import java.util.Map;
1917
import java.util.Set;
@@ -28,7 +26,7 @@
2826
import org.opensearch.common.settings.Settings;
2927
import org.opensearch.core.index.shard.ShardId;
3028
import org.opensearch.index.IndexService;
31-
import org.opensearch.index.mapper.SeqNoFieldMapper;
29+
import org.opensearch.index.mapper.IgnoredFieldMapper;
3230
import org.opensearch.index.query.QueryShardContext;
3331
import org.opensearch.index.shard.ShardUtils;
3432
import org.opensearch.security.auditlog.AuditLog;
@@ -40,9 +38,24 @@
4038

4139
public class SecurityFlsDlsIndexSearcherWrapper extends SecurityIndexSearcherWrapper {
4240

43-
private final Set<String> metaFields;
44-
public static final Set<String> META_FIELDS_BEFORE_7DOT8 = Collections.unmodifiableSet(
45-
new HashSet<>(Arrays.asList("_timestamp", "_ttl", "_type"))
41+
// TODO: the list is outdated. It is necessary to change how meta fields are handled in the near future.
42+
// We may consider using MapperService.isMetadataField() instead of relying on the static set or
43+
// (if it is too costly or does not meet requirements) use IndicesModule.getBuiltInMetadataFields()
44+
// for OpenSearch version specific Set of meta fields
45+
private static final Set<String> metaFields = Sets.newHashSet(
46+
"_source",
47+
"_version",
48+
"_field_names",
49+
"_seq_no",
50+
"_primary_term",
51+
"_id",
52+
IgnoredFieldMapper.NAME,
53+
"_index",
54+
"_routing",
55+
"_size",
56+
"_timestamp",
57+
"_ttl",
58+
"_type"
4659
);
4760
private final ClusterService clusterService;
4861
private final IndexService indexService;
@@ -62,11 +75,6 @@ public SecurityFlsDlsIndexSearcherWrapper(
6275
final Salt salt
6376
) {
6477
super(indexService, settings, adminDNs, evaluator);
65-
Set<String> metadataFieldsCopy = new HashSet<>(indexService.mapperService().getMetadataFields());
66-
SeqNoFieldMapper.SequenceIDFields sequenceIDFields = SeqNoFieldMapper.SequenceIDFields.emptySeqID();
67-
metadataFieldsCopy.add(sequenceIDFields.primaryTerm.name());
68-
metadataFieldsCopy.addAll(META_FIELDS_BEFORE_7DOT8);
69-
metaFields = metadataFieldsCopy;
7078
ciol.setIs(indexService);
7179
this.clusterService = clusterService;
7280
this.indexService = indexService;

0 commit comments

Comments
 (0)