Skip to content

Commit 91e0d98

Browse files
committed
[Fleet] Add index and pipeline to allow fleet agents enrichment
1 parent 9022ccc commit 91e0d98

File tree

6 files changed

+106
-2
lines changed

6 files changed

+106
-2
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/store/KibanaOwnedReservedRoleDescriptors.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ static RoleDescriptor kibanaSystem(String name) {
189189
.privileges("all")
190190
.allowRestrictedIndices(true)
191191
.build(),
192+
RoleDescriptor.IndicesPrivileges.builder()
193+
.indices(".fleet-agent-policies-metadata*")
194+
.privileges("all")
195+
.allowRestrictedIndices(true)
196+
.build(),
192197
RoleDescriptor.IndicesPrivileges.builder()
193198
.indices(".fleet-policies-leader*")
194199
.privileges("all")
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"settings": {
3+
"auto_expand_replicas": "0-1"
4+
},
5+
"mappings": {
6+
"_doc" : {
7+
"dynamic": false,
8+
"_meta": {
9+
"version": "${fleet.version}",
10+
"managed_index_mappings_version": ${fleet.managed.index.version}
11+
},
12+
"properties": {
13+
"policy_id": {
14+
"type": "keyword"
15+
},
16+
"agent_policy": {
17+
"type": "object",
18+
"enabled": false
19+
}
20+
}
21+
}
22+
}
23+
}

x-pack/plugin/core/template-resources/src/main/resources/fleet-agents.json

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"settings": {
3-
"auto_expand_replicas": "0-1"
3+
"auto_expand_replicas": "0-1",
4+
"index": {
5+
"default_pipeline": "fleet-agents@default-pipeline"
6+
}
47
},
58
"mappings": {
69
"_doc": {
@@ -30,6 +33,30 @@
3033
}
3134
}
3235
},
36+
"agent_policy": {
37+
"properties": {
38+
"name": {
39+
"type": "text"
40+
},
41+
"package_policies": {
42+
"properties": {
43+
"name": {
44+
"type": "text"
45+
},
46+
"package": {
47+
"properties": {
48+
"name": {
49+
"type": "keyword"
50+
},
51+
"version": {
52+
"type": "keyword"
53+
}
54+
}
55+
}
56+
}
57+
}
58+
}
59+
},
3360
"default_api_key": {
3461
"type": "keyword"
3562
},
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"processors": [
3+
{
4+
"pipeline": {
5+
"name": "fleet-agents@enrich-agent-policies-pipeline",
6+
"ignore_missing_pipeline": true
7+
}
8+
}
9+
],
10+
"_meta": {
11+
"description": "TODO",
12+
"managed": true
13+
}
14+
}

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public class Fleet extends Plugin implements SystemIndexPlugin {
8484
private static final int FLEET_ENROLLMENT_API_KEYS_MAPPINGS_VERSION = 1;
8585
private static final int FLEET_SECRETS_MAPPINGS_VERSION = 1;
8686
private static final int FLEET_POLICIES_MAPPINGS_VERSION = 1;
87+
private static final int FLEET_POLICIES_METADATA_MAPPINGS_VERSION = 1;
8788
private static final int FLEET_POLICIES_LEADER_MAPPINGS_VERSION = 1;
8889
private static final int FLEET_SERVERS_MAPPINGS_VERSION = 1;
8990
private static final int FLEET_ARTIFACTS_MAPPINGS_VERSION = 1;
@@ -110,6 +111,7 @@ public Collection<SystemIndexDescriptor> getSystemIndexDescriptors(Settings sett
110111
fleetEnrollmentApiKeysSystemIndexDescriptor(),
111112
fleetSecretsSystemIndexDescriptor(),
112113
fleetPoliciesSystemIndexDescriptor(),
114+
fleetPoliciesMetadataSystemIndexDescriptor(),
113115
fleetPoliciesLeaderSystemIndexDescriptor(),
114116
fleetServersSystemIndexDescriptors(),
115117
fleetArtifactsSystemIndexDescriptors()
@@ -217,6 +219,23 @@ private static SystemIndexDescriptor fleetPoliciesSystemIndexDescriptor() {
217219
.build();
218220
}
219221

222+
private static SystemIndexDescriptor fleetPoliciesMetadataSystemIndexDescriptor() {
223+
PutIndexTemplateRequest request = new PutIndexTemplateRequest();
224+
request.source(loadTemplateSource("/fleet-agent-policies-metadata.json", FLEET_POLICIES_METADATA_MAPPINGS_VERSION), XContentType.JSON);
225+
226+
return SystemIndexDescriptor.builder()
227+
.setType(Type.EXTERNAL_MANAGED)
228+
.setAllowedElasticProductOrigins(ALLOWED_PRODUCTS)
229+
.setOrigin(FLEET_ORIGIN)
230+
.setMappings(request.mappings())
231+
.setSettings(request.settings())
232+
.setPrimaryIndex(".fleet-agent-policies-metadata-" + CURRENT_INDEX_VERSION)
233+
.setIndexPattern(".fleet-agent-policies-metadata-[0-9]+*")
234+
.setAliasName(".fleet-agent-policies-metadata")
235+
.setDescription("Fleet Policies metadata for agent enrichment")
236+
.build();
237+
}
238+
220239
private static SystemIndexDescriptor fleetPoliciesLeaderSystemIndexDescriptor() {
221240
PutIndexTemplateRequest request = new PutIndexTemplateRequest();
222241
request.source(loadTemplateSource("/fleet-policies-leader.json", FLEET_POLICIES_LEADER_MAPPINGS_VERSION), XContentType.JSON);

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
import org.elasticsearch.xpack.core.template.IndexTemplateConfig;
1818
import org.elasticsearch.xpack.core.template.IndexTemplateRegistry;
1919
import org.elasticsearch.xpack.core.template.LifecyclePolicyConfig;
20+
import org.elasticsearch.xpack.core.template.IngestPipelineConfig;
21+
import org.elasticsearch.xpack.core.template.JsonIngestPipelineConfig;
2022

2123
import java.util.List;
2224
import java.util.Map;
2325

2426
public class FleetTemplateRegistry extends IndexTemplateRegistry {
2527

26-
public static final int INDEX_TEMPLATE_VERSION = 1;
28+
public static final int INDEX_TEMPLATE_VERSION = 2;
2729

2830
public static final String TEMPLATE_VERSION_VARIABLE = "xpack.fleet.template.version";
2931

@@ -86,4 +88,18 @@ protected List<LifecyclePolicyConfig> getLifecycleConfigs() {
8688
protected Map<String, ComposableIndexTemplate> getComposableTemplateConfigs() {
8789
return COMPOSABLE_INDEX_TEMPLATE_CONFIGS;
8890
}
91+
92+
@Override
93+
protected List<IngestPipelineConfig> getIngestPipelines() {
94+
return INGEST_PIPELINE_CONFIGS;
95+
}
96+
97+
private static final List<IngestPipelineConfig> INGEST_PIPELINE_CONFIGS = List.of(
98+
new JsonIngestPipelineConfig(
99+
"fleet-agents@default-pipeline",
100+
101+
INDEX_TEMPLATE_VERSION,
102+
TEMPLATE_VERSION_VARIABLE
103+
)
104+
);
89105
}

0 commit comments

Comments
 (0)