Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fleet] Add .fleet-secrets system index #95625

Merged
merged 22 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/changelog/95625.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 95625
summary: "[Fleet] Add `.fleet-secrets` system index"
area: Infra/Plugins
type: feature
issues:
- 95143
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ GET /_security/service/elastic/fleet-server
],
"allow_restricted_indices": false
},
{
"names": [
".fleet-secrets*"
],
"privileges": [
"read",
],
"allow_restricted_indices": true
},
{
"names": [
".fleet-*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,13 @@ public static RoleDescriptor kibanaSystemRoleDescriptor(String name) {
RoleDescriptor.IndicesPrivileges.builder().indices("*").privileges("view_index_metadata", "monitor").build(),
// Endpoint diagnostic information. Kibana reads from these indices to send telemetry
RoleDescriptor.IndicesPrivileges.builder().indices(".logs-endpoint.diagnostic.collection-*").privileges("read").build(),
// Fleet secrets, Kibana can only write ot this index.
// This definition must come before .fleet* below.
RoleDescriptor.IndicesPrivileges.builder()
.indices(".fleet-secrets*")
.privileges("write", "create_index")
.allowRestrictedIndices(true)
.build(),
// Fleet Server indices. Kibana create this indice before Fleet Server use them.
// Fleet Server indices. Kibana read and write to this indice to manage Elastic Agents
RoleDescriptor.IndicesPrivileges.builder().indices(".fleet*").allowRestrictedIndices(true).privileges("all").build(),
Expand Down
19 changes: 19 additions & 0 deletions x-pack/plugin/core/src/main/resources/fleet-secrets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"settings": {
"auto_expand_replicas": "0-1"
},
"mappings": {
"_doc" : {
"dynamic": false,
"_meta": {
"version": "${fleet.version}"
},
"properties": {
"value": {
"type": "keyword",
"index": false
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,22 @@ public void testCreationOfFleetPolicies() throws Exception {
assertThat(responseBody, containsString("coordinator_idx"));
}

public void testCreationOfFleetSecrets() throws Exception {
Request request = new Request("PUT", ".fleet-secrets");
Response response = client().performRequest(request);
assertEquals(200, response.getStatusLine().getStatusCode());

request = new Request("GET", ".fleet-secrets/_mapping");
response = client().performRequest(request);
String responseBody = EntityUtils.toString(response.getEntity());
assertThat(responseBody, containsString("value"));

request = new Request("GET", ".fleet-secrets-7/_mapping");
response = client().performRequest(request);
responseBody = EntityUtils.toString(response.getEntity());
assertThat(responseBody, containsString("value"));
}

public void testCreationOfFleetPoliciesLeader() throws Exception {
Request request = new Request("PUT", ".fleet-policies-leader");
Response response = client().performRequest(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public Collection<SystemIndexDescriptor> getSystemIndexDescriptors(Settings sett
fleetActionsSystemIndexDescriptor(),
fleetAgentsSystemIndexDescriptor(),
fleetEnrollmentApiKeysSystemIndexDescriptor(),
fleetSecretsSystemIndexDescriptor(),
fleetPoliciesSystemIndexDescriptor(),
fleetPoliciesLeaderSystemIndexDescriptor(),
fleetServersSystemIndexDescriptors(),
Expand Down Expand Up @@ -190,6 +191,23 @@ private SystemIndexDescriptor fleetEnrollmentApiKeysSystemIndexDescriptor() {
.build();
}

private SystemIndexDescriptor fleetSecretsSystemIndexDescriptor() {
PutIndexTemplateRequest request = new PutIndexTemplateRequest();
request.source(loadTemplateSource("/fleet-secrets.json"), XContentType.JSON);
return SystemIndexDescriptor.builder()
.setType(Type.EXTERNAL_MANAGED)
.setAllowedElasticProductOrigins(ALLOWED_PRODUCTS)
.setOrigin(FLEET_ORIGIN)
.setVersionMetaKey(VERSION_KEY)
.setMappings(request.mappings())
.setSettings(request.settings())
.setPrimaryIndex(".fleet-secrets-" + CURRENT_INDEX_VERSION)
.setIndexPattern(".fleet-secrets*")
.setAliasName(".fleet-secrets")
.setDescription("Secret values managed by Fleet")
.build();
}

private SystemIndexDescriptor fleetPoliciesSystemIndexDescriptor() {
PutIndexTemplateRequest request = new PutIndexTemplateRequest();
request.source(loadTemplateSource("/fleet-policies.json"), XContentType.JSON);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public void testFleetIndexNames() {
".fleet-actions~(-results*)",
".fleet-policies-leader*",
".fleet-enrollment-api-keys*",
".fleet-artifacts*"
".fleet-artifacts*",
".fleet-secrets*"
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ public class ServiceAccountIT extends ESRestTestCase {
],
"allow_restricted_indices": false
},
{
"names": [
".fleet-secrets*"
],
"privileges": [
"read"
],
"allow_restricted_indices":true
},
{
"names": [
".fleet-*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ final class ElasticServiceAccounts {
.indices("traces-apm.sampled-*")
.privileges("read", "monitor", "maintenance")
.build(),
RoleDescriptor.IndicesPrivileges.builder()
.indices(".fleet-secrets*")
.privileges("read")
.allowRestrictedIndices(true)
.build(),
RoleDescriptor.IndicesPrivileges.builder()
.indices(".fleet-*")
// Fleet Server needs "maintenance" privilege to be able to perform operations with "refresh"
Expand Down