Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure that field-level security is enforced when using field aliases. #31807

Merged
merged 3 commits into from
Jul 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -83,8 +83,8 @@ protected FieldCapabilitiesIndexResponse shardOperation(final FieldCapabilitiesI
for (String field : fieldNames) {
MappedFieldType ft = mapperService.fullName(field);
if (ft != null) {
FieldCapabilities fieldCap = new FieldCapabilities(field, ft.typeName(), ft.isSearchable(), ft.isAggregatable());
if (indicesService.isMetaDataField(field) || fieldPredicate.test(field)) {
if (indicesService.isMetaDataField(field) || fieldPredicate.test(ft.name())) {
FieldCapabilities fieldCap = new FieldCapabilities(field, ft.typeName(), ft.isSearchable(), ft.isAggregatable());
responseMap.put(field, fieldCap);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,16 @@
import org.elasticsearch.action.fieldcaps.FieldCapabilitiesResponse;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.plugins.MapperPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESIntegTestCase;
import org.junit.Before;

import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Predicate;

import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;

Expand All @@ -47,6 +53,13 @@ public void setUp() throws Exception {
.field("type", "alias")
.field("path", "distance")
.endObject()
.startObject("playlist")
.field("type", "text")
.endObject()
.startObject("secret_soundtrack")
.field("type", "alias")
.field("path", "playlist")
.endObject()
.endObject()
.endObject()
.endObject();
Expand All @@ -68,6 +81,18 @@ public void setUp() throws Exception {
assertAcked(prepareCreate("new_index").addMapping("_doc", newIndexMapping));
}

public static class FieldFilterPlugin extends Plugin implements MapperPlugin {
@Override
public Function<String, Predicate<String>> getFieldFilter() {
return index -> field -> !field.equals("playlist");
}
}

@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return Collections.singleton(FieldFilterPlugin.class);
}

public void testFieldAlias() {
FieldCapabilitiesResponse response = client().prepareFieldCaps().setFields("distance", "route_length_miles")
.execute().actionGet();
Expand Down Expand Up @@ -100,11 +125,27 @@ public void testFieldAlias() {
routeLength.get("double"));
}

public void testFieldAliasWithWildcardField() {
public void testFieldAliasWithWildcard() {
FieldCapabilitiesResponse response = client().prepareFieldCaps().setFields("route*")
.execute().actionGet();

assertEquals(1, response.get().size());
assertTrue(response.get().containsKey("route_length_miles"));
}

public void testFieldAliasFiltering() {
FieldCapabilitiesResponse response = client().prepareFieldCaps().setFields(
"secret-soundtrack", "route_length_miles")
.execute().actionGet();
assertEquals(1, response.get().size());
assertTrue(response.get().containsKey("route_length_miles"));
}

public void testFieldAliasFilteringWithWildcard() {
FieldCapabilitiesResponse response = client().prepareFieldCaps()
.setFields("distance", "secret*")
.execute().actionGet();
assertEquals(1, response.get().size());
assertTrue(response.get().containsKey("distance"));
}
}
Loading