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

Expand fleet-server privileges to include restricted indices #77531

Merged
merged 2 commits into from
Sep 10, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ GET /_security/service/elastic/fleet-server
"create_index",
"auto_configure"
],
"allow_restricted_indices": false
"allow_restricted_indices": true
}
],
"applications": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public class ServiceAccountIT extends ESRestTestCase {
+ " \"create_index\",\n"
+ " \"auto_configure\"\n"
+ " ],\n"
+ " \"allow_restricted_indices\": false\n"
+ " \"allow_restricted_indices\": true\n"
+ " }\n"
+ " ],\n"
+ " \"applications\": [],\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ final class ElasticServiceAccounts {
.builder()
.indices(".fleet-*")
.privileges("read", "write", "monitor", "create_index", "auto_configure")
.allowRestrictedIndices(true)
.build()
},
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@
import org.elasticsearch.xpack.core.security.authz.store.ReservedRolesStore;
import org.elasticsearch.xpack.core.security.user.KibanaSystemUser;
import org.elasticsearch.xpack.core.security.user.User;
import org.elasticsearch.xpack.core.security.support.Automatons;
import org.elasticsearch.xpack.security.authc.service.ElasticServiceAccounts.ElasticServiceAccount;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import static org.elasticsearch.xpack.core.security.test.TestRestrictedIndices.RESTRICTED_INDICES_AUTOMATON;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
Expand All @@ -128,8 +128,8 @@ public void testKibanaSystemPrivileges() {
}

public void testElasticFleetPrivileges() {
final Role role =
Role.builder(ElasticServiceAccounts.ACCOUNTS.get("elastic/fleet-server").roleDescriptor(), null, Automatons.EMPTY).build();
final Role role = Role.builder(
ElasticServiceAccounts.ACCOUNTS.get("elastic/fleet-server").roleDescriptor(), null, RESTRICTED_INDICES_AUTOMATON).build();
final Authentication authentication = mock(Authentication.class);
assertThat(role.cluster().check(CreateApiKeyAction.NAME,
new CreateApiKeyRequest(randomAlphaOfLengthBetween(3, 8), null, null), authentication), is(true));
Expand Down Expand Up @@ -162,21 +162,31 @@ public void testElasticFleetPrivileges() {
assertThat(role.indices().allowedIndicesMatcher(UpdateSettingsAction.NAME).test(index), is(false));
});

final String dotFleetIndexName = ".fleet-" + randomAlphaOfLengthBetween(1, 20);
final IndexAbstraction dotFleetIndex = mockIndexAbstraction(dotFleetIndexName);
assertThat(role.indices().allowedIndicesMatcher(DeleteAction.NAME).test(dotFleetIndex), is(true));
assertThat(role.indices().allowedIndicesMatcher(CreateIndexAction.NAME).test(dotFleetIndex), is(true));
assertThat(role.indices().allowedIndicesMatcher(IndexAction.NAME).test(dotFleetIndex), is(true));
assertThat(role.indices().allowedIndicesMatcher(BulkAction.NAME).test(dotFleetIndex), is(true));
assertThat(role.indices().allowedIndicesMatcher(GetAction.NAME).test(dotFleetIndex), is(true));
assertThat(role.indices().allowedIndicesMatcher(MultiGetAction.NAME).test(dotFleetIndex), is(true));
assertThat(role.indices().allowedIndicesMatcher(SearchAction.NAME).test(dotFleetIndex), is(true));
assertThat(role.indices().allowedIndicesMatcher(MultiSearchAction.NAME).test(dotFleetIndex), is(true));
assertThat(role.indices().allowedIndicesMatcher(IndicesStatsAction.NAME).test(dotFleetIndex), is(true));
assertThat(role.indices().allowedIndicesMatcher(DeleteIndexAction.NAME).test(dotFleetIndex), is(false));
assertThat(role.indices().allowedIndicesMatcher(UpdateSettingsAction.NAME).test(dotFleetIndex), is(false));
assertThat(role.indices().allowedIndicesMatcher("indices:foo").test(dotFleetIndex), is(false));
// TODO: more tests when role descriptor is finalised for elastic/fleet-server
List.of(
".fleet-" + randomAlphaOfLengthBetween(1, 20),
".fleet-action" + randomAlphaOfLengthBetween(1, 20),
".fleet-agents" + randomAlphaOfLengthBetween(1, 20),
".fleet-enrollment-api-keys" + randomAlphaOfLengthBetween(1, 20),
".fleet-policies" + randomAlphaOfLengthBetween(1, 20),
".fleet-policies-leader" + randomAlphaOfLengthBetween(1, 20),
".fleet-servers" + randomAlphaOfLengthBetween(1, 20),
".fleet-artifacts" + randomAlphaOfLengthBetween(1, 20),
".fleet-actions-results" + randomAlphaOfLengthBetween(1, 20)
).forEach(index -> {
final IndexAbstraction dotFleetIndex = mockIndexAbstraction(index);
assertThat(role.indices().allowedIndicesMatcher(DeleteAction.NAME).test(dotFleetIndex), is(true));
assertThat(role.indices().allowedIndicesMatcher(CreateIndexAction.NAME).test(dotFleetIndex), is(true));
assertThat(role.indices().allowedIndicesMatcher(IndexAction.NAME).test(dotFleetIndex), is(true));
assertThat(role.indices().allowedIndicesMatcher(BulkAction.NAME).test(dotFleetIndex), is(true));
assertThat(role.indices().allowedIndicesMatcher(GetAction.NAME).test(dotFleetIndex), is(true));
assertThat(role.indices().allowedIndicesMatcher(MultiGetAction.NAME).test(dotFleetIndex), is(true));
assertThat(role.indices().allowedIndicesMatcher(SearchAction.NAME).test(dotFleetIndex), is(true));
assertThat(role.indices().allowedIndicesMatcher(MultiSearchAction.NAME).test(dotFleetIndex), is(true));
assertThat(role.indices().allowedIndicesMatcher(IndicesStatsAction.NAME).test(dotFleetIndex), is(true));
assertThat(role.indices().allowedIndicesMatcher(DeleteIndexAction.NAME).test(dotFleetIndex), is(false));
assertThat(role.indices().allowedIndicesMatcher(UpdateSettingsAction.NAME).test(dotFleetIndex), is(false));
assertThat(role.indices().allowedIndicesMatcher("indices:foo").test(dotFleetIndex), is(false));
});
}

public void testElasticServiceAccount() {
Expand Down