Skip to content

Commit 5e2df93

Browse files
committed
Reintroduce system index APIs for Kibana
This change reintroduces the system index APIs for Kibana wihtout the changes made for marking what system indices could be accessed using these APIs. In essence, this is a partial revert of elastic#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 elastic#52385
1 parent f088734 commit 5e2df93

File tree

18 files changed

+559
-22
lines changed

18 files changed

+559
-22
lines changed

modules/kibana/build.gradle

Lines changed: 31 additions & 0 deletions
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+
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
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.Collection;
56+
import java.util.List;
57+
import java.util.function.Function;
58+
import java.util.function.Supplier;
59+
import java.util.stream.Collectors;
60+
61+
public class KibanaPlugin extends Plugin implements SystemIndexPlugin {
62+
63+
public static final Setting<List<String>> KIBANA_INDEX_NAMES_SETTING = Setting.listSetting(
64+
"kibana.system_indices",
65+
List.of(".kibana*", ".reporting"),
66+
Function.identity(),
67+
Property.NodeScope
68+
);
69+
70+
@Override
71+
public Collection<SystemIndexDescriptor> getSystemIndexDescriptors(Settings settings) {
72+
return KIBANA_INDEX_NAMES_SETTING.get(settings)
73+
.stream()
74+
.map(pattern -> new SystemIndexDescriptor(pattern, "System index used by kibana"))
75+
.collect(Collectors.toUnmodifiableList());
76+
}
77+
78+
@Override
79+
public List<RestHandler> getRestHandlers(
80+
Settings settings,
81+
RestController restController,
82+
ClusterSettings clusterSettings,
83+
IndexScopedSettings indexScopedSettings,
84+
SettingsFilter settingsFilter,
85+
IndexNameExpressionResolver indexNameExpressionResolver,
86+
Supplier<DiscoveryNodes> nodesInCluster
87+
) {
88+
// TODO need to figure out what subset of system indices Kibana should have access to via these APIs
89+
return List.of(
90+
// Based on https://github.com/elastic/kibana/issues/49764
91+
// apis needed to perform migrations... ideally these will go away
92+
new KibanaWrappedRestHandler(new RestCreateIndexAction()),
93+
new KibanaWrappedRestHandler(new RestGetAliasesAction()),
94+
new KibanaWrappedRestHandler(new RestIndexPutAliasAction()),
95+
new KibanaWrappedRestHandler(new RestRefreshAction()),
96+
97+
// apis needed to access saved objects
98+
new KibanaWrappedRestHandler(new RestGetAction()),
99+
new KibanaWrappedRestHandler(new RestMultiGetAction(settings)),
100+
new KibanaWrappedRestHandler(new RestSearchAction()),
101+
new KibanaWrappedRestHandler(new RestBulkAction(settings)),
102+
new KibanaWrappedRestHandler(new RestDeleteAction()),
103+
new KibanaWrappedRestHandler(new RestDeleteByQueryAction()),
104+
105+
// api used for testing
106+
new KibanaWrappedRestHandler(new RestUpdateSettingsAction()),
107+
108+
// apis used specifically by reporting
109+
new KibanaWrappedRestHandler(new RestGetIndicesAction()),
110+
new KibanaWrappedRestHandler(new RestIndexAction()),
111+
new KibanaWrappedRestHandler(new CreateHandler()),
112+
new KibanaWrappedRestHandler(new AutoIdHandler(nodesInCluster)),
113+
new KibanaWrappedRestHandler(new RestUpdateAction()),
114+
new KibanaWrappedRestHandler(new RestSearchScrollAction()),
115+
new KibanaWrappedRestHandler(new RestClearScrollAction())
116+
);
117+
118+
}
119+
120+
@Override
121+
public List<Setting<?>> getSettings() {
122+
return List.of(KIBANA_INDEX_NAMES_SETTING);
123+
}
124+
125+
static class KibanaWrappedRestHandler extends BaseRestHandler.Wrapper {
126+
127+
KibanaWrappedRestHandler(BaseRestHandler delegate) {
128+
super(delegate);
129+
}
130+
131+
@Override
132+
public String getName() {
133+
return "kibana_" + super.getName();
134+
}
135+
136+
@Override
137+
public List<Route> routes() {
138+
return super.routes().stream()
139+
.map(route -> new Route(route.getMethod(), "/_kibana" + route.getPath()))
140+
.collect(Collectors.toUnmodifiableList());
141+
}
142+
}
143+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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.List;
27+
import java.util.stream.Collectors;
28+
29+
import static org.hamcrest.Matchers.contains;
30+
import static org.hamcrest.Matchers.is;
31+
32+
public class KibanaPluginTests extends ESTestCase {
33+
34+
public void testKibanaIndexNames() {
35+
assertThat(new KibanaPlugin().getSettings(), contains(KibanaPlugin.KIBANA_INDEX_NAMES_SETTING));
36+
assertThat(
37+
new KibanaPlugin().getSystemIndexDescriptors(Settings.EMPTY)
38+
.stream()
39+
.map(SystemIndexDescriptor::getIndexPattern)
40+
.collect(Collectors.toUnmodifiableList()),
41+
contains(".kibana*", ".reporting")
42+
);
43+
final List<String> names = List.of("." + randomAlphaOfLength(4), "." + randomAlphaOfLength(6));
44+
final List<String> namesFromDescriptors = new KibanaPlugin().getSystemIndexDescriptors(
45+
Settings.builder().putList(KibanaPlugin.KIBANA_INDEX_NAMES_SETTING.getKey(), names).build()
46+
).stream().map(SystemIndexDescriptor::getIndexPattern).collect(Collectors.toUnmodifiableList());
47+
assertThat(namesFromDescriptors, is(names));
48+
}
49+
}

0 commit comments

Comments
 (0)