Skip to content

Commit 7ac998d

Browse files
committed
changed to let index management be the responsibility of ES
1 parent 189b85c commit 7ac998d

File tree

6 files changed

+75
-29
lines changed

6 files changed

+75
-29
lines changed

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/store/ReservedRolesStoreTests.java

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -936,32 +936,6 @@ public void testKibanaSystemRole() {
936936
".fleet-fileds"
937937
).forEach(index -> assertAllIndicesAccessAllowed(kibanaRole, index));
938938

939-
// Knowledge base. Fleet creates, manages, and uses this index to store knowledge base documents to be consumed by AI assistants.
940-
Arrays.asList(".integration_knowledge" + randomAlphaOfLength(randomIntBetween(0, 13))).forEach((index) -> {
941-
final IndexAbstraction indexAbstraction = mockIndexAbstraction(index, IndexAbstraction.Type.CONCRETE_INDEX);
942-
assertThat(kibanaRole.indices().allowedIndicesMatcher("indices:foo").test(indexAbstraction), is(false));
943-
assertThat(kibanaRole.indices().allowedIndicesMatcher("indices:bar").test(indexAbstraction), is(false));
944-
assertThat(
945-
kibanaRole.indices().allowedIndicesMatcher(TransportDeleteIndexAction.TYPE.name()).test(indexAbstraction),
946-
is(false)
947-
);
948-
assertThat(kibanaRole.indices().allowedIndicesMatcher(GetIndexAction.NAME).test(indexAbstraction), is(true));
949-
assertThat(kibanaRole.indices().allowedIndicesMatcher(TransportCreateIndexAction.TYPE.name()).test(indexAbstraction), is(true));
950-
assertThat(kibanaRole.indices().allowedIndicesMatcher(TransportIndexAction.NAME).test(indexAbstraction), is(true));
951-
assertThat(kibanaRole.indices().allowedIndicesMatcher(TransportDeleteAction.NAME).test(indexAbstraction), is(true));
952-
assertThat(kibanaRole.indices().allowedIndicesMatcher(TransportSearchAction.TYPE.name()).test(indexAbstraction), is(true));
953-
assertThat(kibanaRole.indices().allowedIndicesMatcher(TransportMultiSearchAction.TYPE.name()).test(indexAbstraction), is(true));
954-
assertThat(kibanaRole.indices().allowedIndicesMatcher(TransportGetAction.TYPE.name()).test(indexAbstraction), is(true));
955-
assertThat(kibanaRole.indices().allowedIndicesMatcher(READ_CROSS_CLUSTER_NAME).test(indexAbstraction), is(false));
956-
assertThat(
957-
kibanaRole.indices().allowedIndicesMatcher(TransportUpdateSettingsAction.TYPE.name()).test(indexAbstraction),
958-
is(false)
959-
);
960-
// In the future, this PutMappingAction check will be false but the BWC check is giving the privilege for all indices with 'write' access
961-
assertThat(kibanaRole.indices().allowedIndicesMatcher(TransportPutMappingAction.TYPE.name()).test(indexAbstraction), is(true));
962-
assertThat(kibanaRole.indices().allowedIndicesMatcher(RolloverAction.NAME).test(indexAbstraction), is(false));
963-
});
964-
965939
final IndexAbstraction dotFleetSecretsIndex = mockIndexAbstraction(".fleet-secrets");
966940
assertThat(kibanaRole.indices().allowedIndicesMatcher("indices:foo").test(dotFleetSecretsIndex), is(false));
967941
assertThat(kibanaRole.indices().allowedIndicesMatcher("indices:bar").test(dotFleetSecretsIndex), is(false));

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/test/TestRestrictedIndices.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ public class TestRestrictedIndices {
103103
SystemIndexDescriptorUtils.createUnmanaged(".fleet-policies-[0-9]+*", "fleet policies"),
104104
SystemIndexDescriptorUtils.createUnmanaged(".fleet-policies-leader*", "fleet policies leader"),
105105
SystemIndexDescriptorUtils.createUnmanaged(".fleet-servers*", "fleet servers"),
106-
SystemIndexDescriptorUtils.createUnmanaged(".fleet-artifacts*", "fleet artifacts")
106+
SystemIndexDescriptorUtils.createUnmanaged(".fleet-artifacts*", "fleet artifacts"),
107+
SystemIndexDescriptorUtils.createUnmanaged(".integration_knowledge*", "integration knowledge")
107108
),
108109
List.of(
109110
new SystemDataStreamDescriptor(
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"settings": {
3+
"auto_expand_replicas": "0-1",
4+
"index.hidden": true
5+
},
6+
"mappings": {
7+
"_doc": {
8+
"dynamic": false,
9+
"_meta": {
10+
"version": "${fleet.version}",
11+
"managed_index_mappings_version": "${fleet.managed.index.version}",
12+
"description": "Integration package knowledge base content storage",
13+
"managed": true
14+
},
15+
"properties": {
16+
"filename": {
17+
"type": "keyword"
18+
},
19+
"content": {
20+
"type": "semantic_text"
21+
},
22+
"version": {
23+
"type": "version"
24+
},
25+
"package_name": {
26+
"type": "keyword"
27+
},
28+
"installed_at": {
29+
"type": "date"
30+
}
31+
}
32+
}
33+
}
34+
}

x-pack/plugin/fleet/src/javaRestTest/java/org/elasticsearch/xpack/fleet/FleetSystemIndicesIT.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,4 +293,20 @@ public void verifyFileDeliveryDataILMPolicyExists() throws Exception {
293293
assertThat(policyMap.size(), equalTo(2));
294294
});
295295
}
296+
297+
public void testCreationOfIntegrationKnowledge() throws Exception {
298+
Request request = new Request("PUT", ".integration-knowledge");
299+
Response response = client().performRequest(request);
300+
assertEquals(200, response.getStatusLine().getStatusCode());
301+
302+
request = new Request("GET", ".integration-knowledge/_mapping");
303+
response = client().performRequest(request);
304+
String responseBody = EntityUtils.toString(response.getEntity());
305+
assertThat(responseBody, containsString("knowledge_content"));
306+
307+
request = new Request("GET", ".integration-knowledge-7/_mapping");
308+
response = client().performRequest(request);
309+
responseBody = EntityUtils.toString(response.getEntity());
310+
assertThat(responseBody, containsString("knowledge_content"));
311+
}
296312
}

x-pack/plugin/fleet/src/main/java/org/elasticsearch/xpack/fleet/Fleet.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public class Fleet extends Plugin implements SystemIndexPlugin {
8787
private static final int FLEET_SERVERS_MAPPINGS_VERSION = 1;
8888
private static final int FLEET_ARTIFACTS_MAPPINGS_VERSION = 1;
8989
private static final int FLEET_ACTIONS_RESULTS_MAPPINGS_VERSION = 1;
90+
private static final int FLEET_INTEGRATION_KNOWLEDGE_MAPPINGS_VERSION = 1;
9091

9192
@Override
9293
public Collection<?> createComponents(PluginServices services) {
@@ -111,7 +112,8 @@ public Collection<SystemIndexDescriptor> getSystemIndexDescriptors(Settings sett
111112
fleetPoliciesSystemIndexDescriptor(),
112113
fleetPoliciesLeaderSystemIndexDescriptor(),
113114
fleetServersSystemIndexDescriptors(),
114-
fleetArtifactsSystemIndexDescriptors()
115+
fleetArtifactsSystemIndexDescriptors(),
116+
fleetIntegrationKnowledgeSystemIndexDescriptor()
115117
);
116118
}
117119

@@ -267,6 +269,22 @@ private static SystemIndexDescriptor fleetArtifactsSystemIndexDescriptors() {
267269
.build();
268270
}
269271

272+
private static SystemIndexDescriptor fleetIntegrationKnowledgeSystemIndexDescriptor() {
273+
PutIndexTemplateRequest request = new PutIndexTemplateRequest();
274+
request.source(loadTemplateSource("/fleet-integration-knowledge.json", FLEET_INTEGRATION_KNOWLEDGE_MAPPINGS_VERSION), XContentType.JSON);
275+
276+
return SystemIndexDescriptor.builder()
277+
.setType(Type.INTERNAL_MANAGED)
278+
.setOrigin(FLEET_ORIGIN)
279+
.setMappings(request.mappings())
280+
.setSettings(request.settings())
281+
.setPrimaryIndex(".integration_knowledge-" + CURRENT_INDEX_VERSION)
282+
.setIndexPattern(".integration_knowledge*")
283+
.setAliasName(".integration_knowledge")
284+
.setDescription("Integration package knowledge base content storage")
285+
.build();
286+
}
287+
270288
private static SystemDataStreamDescriptor fleetActionsResultsDescriptor() {
271289
final String source = loadTemplateSource("/fleet-actions-results.json", FLEET_ACTIONS_RESULTS_MAPPINGS_VERSION);
272290
try (XContentParser parser = XContentType.JSON.xContent().createParser(XContentParserConfiguration.EMPTY, source)) {

x-pack/plugin/fleet/src/test/java/org/elasticsearch/xpack/fleet/FleetTests.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ public void testFleetIndexNames() {
4545
".fleet-policies-leader*",
4646
".fleet-enrollment-api-keys*",
4747
".fleet-artifacts*",
48-
".fleet-secrets*"
48+
".fleet-secrets*",
49+
".integration_knowledge*"
4950
)
5051
);
5152

@@ -60,6 +61,8 @@ public void testFleetIndexNames() {
6061
assertFalse(fleetDescriptors.stream().anyMatch(d -> d.matchesIndexPattern(".fleet-actions-results")));
6162

6263
assertTrue(fleetDescriptors.stream().anyMatch(d -> d.matchesIndexPattern(".fleet-secrets")));
64+
65+
assertTrue(fleetDescriptors.stream().anyMatch(d -> d.matchesIndexPattern(".integration_knowledge")));
6366
}
6467

6568
public void testFleetFeature() {

0 commit comments

Comments
 (0)