Skip to content

Commit 3600c98

Browse files
authored
Reintroduce system index APIs for Kibana (#54935)
This change reintroduces the system index APIs for Kibana without the changes made for marking what system indices could be accessed using these APIs. In essence, this is a partial revert of #53912. The changes for marking what system indices should be allowed access will be handled in a separate change. The APIs introduced here are wrapped versions of the existing REST endpoints. A new setting is also introduced since the Kibana system indices' names are allowed to be changed by a user in case multiple instances of Kibana use the same instance of Elasticsearch. Relates #52385 Backport of #54858
1 parent 8d6d7b8 commit 3600c98

File tree

18 files changed

+569
-22
lines changed

18 files changed

+569
-22
lines changed

modules/kibana/build.gradle

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
esplugin {
21+
description 'Plugin exposing APIs for Kibana system indices'
22+
classname 'org.elasticsearch.kibana.KibanaPlugin'
23+
}
24+
25+
dependencies {
26+
compile project(path: ':modules:reindex', configuration: 'runtime')
27+
}
28+
29+
testClusters.integTest {
30+
module file(project(':modules:reindex').tasks.bundlePlugin.archiveFile)
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.kibana;
21+
22+
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
23+
import org.elasticsearch.cluster.node.DiscoveryNodes;
24+
import org.elasticsearch.common.settings.ClusterSettings;
25+
import org.elasticsearch.common.settings.IndexScopedSettings;
26+
import org.elasticsearch.common.settings.Setting;
27+
import org.elasticsearch.common.settings.Setting.Property;
28+
import org.elasticsearch.common.settings.Settings;
29+
import org.elasticsearch.common.settings.SettingsFilter;
30+
import org.elasticsearch.index.reindex.RestDeleteByQueryAction;
31+
import org.elasticsearch.indices.SystemIndexDescriptor;
32+
import org.elasticsearch.plugins.Plugin;
33+
import org.elasticsearch.plugins.SystemIndexPlugin;
34+
import org.elasticsearch.rest.BaseRestHandler;
35+
import org.elasticsearch.rest.RestController;
36+
import org.elasticsearch.rest.RestHandler;
37+
import org.elasticsearch.rest.action.admin.indices.RestCreateIndexAction;
38+
import org.elasticsearch.rest.action.admin.indices.RestGetAliasesAction;
39+
import org.elasticsearch.rest.action.admin.indices.RestGetIndicesAction;
40+
import org.elasticsearch.rest.action.admin.indices.RestIndexPutAliasAction;
41+
import org.elasticsearch.rest.action.admin.indices.RestRefreshAction;
42+
import org.elasticsearch.rest.action.admin.indices.RestUpdateSettingsAction;
43+
import org.elasticsearch.rest.action.document.RestBulkAction;
44+
import org.elasticsearch.rest.action.document.RestDeleteAction;
45+
import org.elasticsearch.rest.action.document.RestGetAction;
46+
import org.elasticsearch.rest.action.document.RestIndexAction;
47+
import org.elasticsearch.rest.action.document.RestIndexAction.AutoIdHandler;
48+
import org.elasticsearch.rest.action.document.RestIndexAction.CreateHandler;
49+
import org.elasticsearch.rest.action.document.RestMultiGetAction;
50+
import org.elasticsearch.rest.action.document.RestUpdateAction;
51+
import org.elasticsearch.rest.action.search.RestClearScrollAction;
52+
import org.elasticsearch.rest.action.search.RestSearchAction;
53+
import org.elasticsearch.rest.action.search.RestSearchScrollAction;
54+
55+
import java.util.Arrays;
56+
import java.util.Collection;
57+
import java.util.Collections;
58+
import java.util.List;
59+
import java.util.function.Function;
60+
import java.util.function.Supplier;
61+
import java.util.stream.Collectors;
62+
63+
public class KibanaPlugin extends Plugin implements SystemIndexPlugin {
64+
65+
public static final Setting<List<String>> KIBANA_INDEX_NAMES_SETTING = Setting.listSetting(
66+
"kibana.system_indices",
67+
Collections.unmodifiableList(Arrays.asList(".kibana*", ".reporting")),
68+
Function.identity(),
69+
Property.NodeScope
70+
);
71+
72+
@Override
73+
public Collection<SystemIndexDescriptor> getSystemIndexDescriptors(Settings settings) {
74+
return Collections.unmodifiableList(
75+
KIBANA_INDEX_NAMES_SETTING.get(settings)
76+
.stream()
77+
.map(pattern -> new SystemIndexDescriptor(pattern, "System index used by kibana"))
78+
.collect(Collectors.toList())
79+
);
80+
}
81+
82+
@Override
83+
public List<RestHandler> getRestHandlers(
84+
Settings settings,
85+
RestController restController,
86+
ClusterSettings clusterSettings,
87+
IndexScopedSettings indexScopedSettings,
88+
SettingsFilter settingsFilter,
89+
IndexNameExpressionResolver indexNameExpressionResolver,
90+
Supplier<DiscoveryNodes> nodesInCluster
91+
) {
92+
// TODO need to figure out what subset of system indices Kibana should have access to via these APIs
93+
return Collections.unmodifiableList(
94+
Arrays.asList(
95+
// Based on https://github.com/elastic/kibana/issues/49764
96+
// apis needed to perform migrations... ideally these will go away
97+
new KibanaWrappedRestHandler(new RestCreateIndexAction()),
98+
new KibanaWrappedRestHandler(new RestGetAliasesAction()),
99+
new KibanaWrappedRestHandler(new RestIndexPutAliasAction()),
100+
new KibanaWrappedRestHandler(new RestRefreshAction()),
101+
102+
// apis needed to access saved objects
103+
new KibanaWrappedRestHandler(new RestGetAction()),
104+
new KibanaWrappedRestHandler(new RestMultiGetAction(settings)),
105+
new KibanaWrappedRestHandler(new RestSearchAction()),
106+
new KibanaWrappedRestHandler(new RestBulkAction(settings)),
107+
new KibanaWrappedRestHandler(new RestDeleteAction()),
108+
new KibanaWrappedRestHandler(new RestDeleteByQueryAction()),
109+
110+
// api used for testing
111+
new KibanaWrappedRestHandler(new RestUpdateSettingsAction()),
112+
113+
// apis used specifically by reporting
114+
new KibanaWrappedRestHandler(new RestGetIndicesAction()),
115+
new KibanaWrappedRestHandler(new RestIndexAction()),
116+
new KibanaWrappedRestHandler(new CreateHandler()),
117+
new KibanaWrappedRestHandler(new AutoIdHandler(nodesInCluster)),
118+
new KibanaWrappedRestHandler(new RestUpdateAction()),
119+
new KibanaWrappedRestHandler(new RestSearchScrollAction()),
120+
new KibanaWrappedRestHandler(new RestClearScrollAction())
121+
)
122+
);
123+
124+
}
125+
126+
@Override
127+
public List<Setting<?>> getSettings() {
128+
return Collections.singletonList(KIBANA_INDEX_NAMES_SETTING);
129+
}
130+
131+
static class KibanaWrappedRestHandler extends BaseRestHandler.Wrapper {
132+
133+
KibanaWrappedRestHandler(BaseRestHandler delegate) {
134+
super(delegate);
135+
}
136+
137+
@Override
138+
public String getName() {
139+
return "kibana_" + super.getName();
140+
}
141+
142+
@Override
143+
public List<Route> routes() {
144+
return Collections.unmodifiableList(
145+
super.routes().stream()
146+
.map(route -> new Route(route.getMethod(), "/_kibana" + route.getPath()))
147+
.collect(Collectors.toList())
148+
);
149+
}
150+
}
151+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.kibana;
21+
22+
import org.elasticsearch.common.settings.Settings;
23+
import org.elasticsearch.indices.SystemIndexDescriptor;
24+
import org.elasticsearch.test.ESTestCase;
25+
26+
import java.util.Arrays;
27+
import java.util.Collections;
28+
import java.util.List;
29+
import java.util.stream.Collectors;
30+
31+
import static org.hamcrest.Matchers.contains;
32+
import static org.hamcrest.Matchers.is;
33+
34+
public class KibanaPluginTests extends ESTestCase {
35+
36+
public void testKibanaIndexNames() {
37+
assertThat(new KibanaPlugin().getSettings(), contains(KibanaPlugin.KIBANA_INDEX_NAMES_SETTING));
38+
assertThat(
39+
new KibanaPlugin().getSystemIndexDescriptors(Settings.EMPTY)
40+
.stream()
41+
.map(SystemIndexDescriptor::getIndexPattern)
42+
.collect(Collectors.toList()),
43+
contains(".kibana*", ".reporting")
44+
);
45+
final List<String> names = Collections.unmodifiableList(Arrays.asList("." + randomAlphaOfLength(4), "." + randomAlphaOfLength(6)));
46+
final List<String> namesFromDescriptors = new KibanaPlugin().getSystemIndexDescriptors(
47+
Settings.builder().putList(KibanaPlugin.KIBANA_INDEX_NAMES_SETTING.getKey(), names).build()
48+
).stream().map(SystemIndexDescriptor::getIndexPattern).collect(Collectors.toList());
49+
assertThat(namesFromDescriptors, is(names));
50+
}
51+
}

0 commit comments

Comments
 (0)