From 0fab675e95f181503a6fa547ad02a1577156a7ec Mon Sep 17 00:00:00 2001 From: Jay Modi Date: Wed, 21 Oct 2020 12:11:10 -0600 Subject: [PATCH] Correct system index names in Kibana module (#64011) This commit updates the list of system index names to be complete and correct for Kibana and APM. The pattern `.kibana*` is too inclusive for system indices and actually includes the `.kibana-event-log-${version}-${int}` pattern for the Kibana event log, which should only be hidden and not a system index. Additionally, the `.apm-custom-link` index was not included in the list of system indices. Finally, the reporting pattern has been updated to match that of the permissions given to the kibana_system role. Backport of #63950 --- .../org/elasticsearch/kibana/KibanaSystemIndexIT.java | 7 ++++--- .../java/org/elasticsearch/kibana/KibanaPlugin.java | 10 ++++++---- .../org/elasticsearch/kibana/KibanaPluginTests.java | 11 +++++++++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/modules/kibana/src/javaRestTest/java/org/elasticsearch/kibana/KibanaSystemIndexIT.java b/modules/kibana/src/javaRestTest/java/org/elasticsearch/kibana/KibanaSystemIndexIT.java index 92a4ee7d5b4..51af77c4565 100644 --- a/modules/kibana/src/javaRestTest/java/org/elasticsearch/kibana/KibanaSystemIndexIT.java +++ b/modules/kibana/src/javaRestTest/java/org/elasticsearch/kibana/KibanaSystemIndexIT.java @@ -47,9 +47,10 @@ public class KibanaSystemIndexIT extends ESRestTestCase { public static Iterable data() { return Arrays.asList( new Object[] { ".kibana" }, - new Object[] { ".kibana-1" }, - new Object[] { ".reporting" }, - new Object[] { ".apm-agent-configuration" } + new Object[] { ".kibana_1" }, + new Object[] { ".reporting-1" }, + new Object[] { ".apm-agent-configuration" }, + new Object[] { ".apm-custom-link" } ); } diff --git a/modules/kibana/src/main/java/org/elasticsearch/kibana/KibanaPlugin.java b/modules/kibana/src/main/java/org/elasticsearch/kibana/KibanaPlugin.java index b3d10513793..0918e03ad07 100644 --- a/modules/kibana/src/main/java/org/elasticsearch/kibana/KibanaPlugin.java +++ b/modules/kibana/src/main/java/org/elasticsearch/kibana/KibanaPlugin.java @@ -60,18 +60,20 @@ import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; +import static java.util.Collections.unmodifiableList; + public class KibanaPlugin extends Plugin implements SystemIndexPlugin { public static final Setting> KIBANA_INDEX_NAMES_SETTING = Setting.listSetting( "kibana.system_indices", - Collections.unmodifiableList(Arrays.asList(".kibana*", ".reporting", ".apm-agent-configuration")), + unmodifiableList(Arrays.asList(".kibana", ".kibana_*", ".reporting-*", ".apm-agent-configuration", ".apm-custom-link")), Function.identity(), Property.NodeScope ); @Override public Collection getSystemIndexDescriptors(Settings settings) { - return Collections.unmodifiableList( + return unmodifiableList( KIBANA_INDEX_NAMES_SETTING.get(settings) .stream() .map(pattern -> new SystemIndexDescriptor(pattern, "System index used by kibana")) @@ -90,7 +92,7 @@ public class KibanaPlugin extends Plugin implements SystemIndexPlugin { Supplier nodesInCluster ) { // TODO need to figure out what subset of system indices Kibana should have access to via these APIs - return Collections.unmodifiableList( + return unmodifiableList( Arrays.asList( // Based on https://github.com/elastic/kibana/issues/49764 // apis needed to perform migrations... ideally these will go away @@ -146,7 +148,7 @@ public class KibanaPlugin extends Plugin implements SystemIndexPlugin { @Override public List routes() { - return Collections.unmodifiableList( + return unmodifiableList( super.routes().stream() .map(route -> new Route(route.getMethod(), "/_kibana" + route.getPath())) .collect(Collectors.toList()) diff --git a/modules/kibana/src/test/java/org/elasticsearch/kibana/KibanaPluginTests.java b/modules/kibana/src/test/java/org/elasticsearch/kibana/KibanaPluginTests.java index 234813fce88..f7e450a426b 100644 --- a/modules/kibana/src/test/java/org/elasticsearch/kibana/KibanaPluginTests.java +++ b/modules/kibana/src/test/java/org/elasticsearch/kibana/KibanaPluginTests.java @@ -40,12 +40,19 @@ public class KibanaPluginTests extends ESTestCase { .stream() .map(SystemIndexDescriptor::getIndexPattern) .collect(Collectors.toList()), - contains(".kibana*", ".reporting", ".apm-agent-configuration") + contains(".kibana", ".kibana_*", ".reporting-*", ".apm-agent-configuration", ".apm-custom-link") ); - final List names = Collections.unmodifiableList(Arrays.asList("." + randomAlphaOfLength(4), "." + randomAlphaOfLength(6))); + final List names = Collections.unmodifiableList(Arrays.asList("." + randomAlphaOfLength(4), "." + randomAlphaOfLength(5))); final List namesFromDescriptors = new KibanaPlugin().getSystemIndexDescriptors( Settings.builder().putList(KibanaPlugin.KIBANA_INDEX_NAMES_SETTING.getKey(), names).build() ).stream().map(SystemIndexDescriptor::getIndexPattern).collect(Collectors.toList()); assertThat(namesFromDescriptors, is(names)); + + assertThat( + new KibanaPlugin().getSystemIndexDescriptors(Settings.EMPTY) + .stream() + .anyMatch(systemIndexDescriptor -> systemIndexDescriptor.matchesIndexPattern(".kibana-event-log-7-1")), + is(false) + ); } }