Skip to content

Commit

Permalink
[docs] Document new role description field (#108422)
Browse files Browse the repository at this point in the history
This commit updates Role API docs to include new description field 
(introduced in #107088) and adds descriptions for all built-in roles.
  • Loading branch information
slobodanadamovic authored May 14, 2024
1 parent 0b1d71e commit 77ce605
Show file tree
Hide file tree
Showing 8 changed files with 250 additions and 50 deletions.
1 change: 1 addition & 0 deletions docs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -1752,6 +1752,7 @@ setups['setup-snapshots'] = setups['setup-repository'] + '''
name: "my_admin_role"
body: >
{
"description": "Grants full access to all management features within the cluster.",
"cluster": ["all"],
"indices": [
{"names": ["index1", "index2" ], "privileges": ["all"], "field_security" : {"grant" : [ "title", "body" ]}}
Expand Down
4 changes: 4 additions & 0 deletions docs/reference/rest-api/security/create-roles.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ privilege or action.
`cluster`:: (list) A list of cluster privileges. These privileges define the
cluster level actions that users with this role are able to execute.

`description`:: (string) A description of the role.
The maximum length is `1000` chars.

`global`:: (object) An object defining global privileges. A global privilege is
a form of cluster privilege that is request-aware. Support for global privileges
is currently limited to the management of application privileges.
Expand Down Expand Up @@ -104,6 +107,7 @@ The following example adds a role called `my_admin_role`:
--------------------------------------------------
POST /_security/role/my_admin_role
{
"description": "Grants full access to all management features within the cluster.",
"cluster": ["all"],
"indices": [
{
Expand Down
1 change: 1 addition & 0 deletions docs/reference/rest-api/security/get-roles.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ GET /_security/role/my_admin_role
--------------------------------------------------
{
"my_admin_role": {
"description": "Grants full access to all management features within the cluster.",
"cluster" : [ "all" ],
"indices" : [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ static RoleDescriptor kibanaAdminUser(String name, Map<String, Object> metadata)
null,
null,
metadata,
null
null,
null,
null,
null,
"Grants access to all features in Kibana."
);
}

Expand Down Expand Up @@ -408,7 +412,13 @@ static RoleDescriptor kibanaSystem(String name) {
getRemoteIndicesReadPrivileges("traces-apm-*") },
null,
null,
null
"Grants access necessary for the Kibana system user to read from and write to the Kibana indices, "
+ "manage index templates and tokens, and check the availability of the Elasticsearch cluster. "
+ "It also permits activating, searching, and retrieving user profiles, "
+ "as well as updating user profile data for the kibana-* namespace. "
+ "Additionally, this role grants read access to the .monitoring-* indices "
+ "and read and write access to the .reporting-* indices. "
+ "Note: This role should not be assigned to users as the granted permissions may change between releases."
);
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2673,7 +2673,9 @@ public void testUpdateApiKeysAutoUpdatesLegacySuperuserRoleDescriptor() throws E
// raw document has the legacy superuser role descriptor
expectRoleDescriptorsForApiKey("limited_by_role_descriptors", legacySuperuserRoleDescriptor, getApiKeyDocument(apiKeyId));

final Set<RoleDescriptor> currentSuperuserRoleDescriptors = Set.of(ReservedRolesStore.SUPERUSER_ROLE_DESCRIPTOR);
final Set<RoleDescriptor> currentSuperuserRoleDescriptors = ApiKeyService.removeUserRoleDescriptorDescriptions(
Set.of(ReservedRolesStore.SUPERUSER_ROLE_DESCRIPTOR)
);
// The first request is not a noop because we are auto-updating the legacy role descriptors to 8.x role descriptors
assertSingleUpdate(
apiKeyId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,13 @@ && hasRemoteIndices(request.getRoleDescriptors())) {
}
}

private Set<RoleDescriptor> removeUserRoleDescriptorDescriptions(Set<RoleDescriptor> userRoleDescriptors) {
/**
* This method removes description from the given user's (limited-by) role descriptors.
* The description field is not supported for API key role descriptors hence storing limited-by roles with descriptions
* would be inconsistent and require handling backwards compatibility.
* Hence why we have to remove them before create/update of API key roles.
*/
static Set<RoleDescriptor> removeUserRoleDescriptorDescriptions(Set<RoleDescriptor> userRoleDescriptors) {
return userRoleDescriptors.stream().map(roleDescriptor -> {
if (roleDescriptor.hasDescription()) {
return new RoleDescriptor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,9 @@ private static Tuple<Map<String, Object>, Map<String, Object>> newApiKeyDocument
getFastStoredHashAlgoForTests().hash(new SecureString(key.toCharArray())),
"test",
authentication,
type == ApiKey.Type.CROSS_CLUSTER ? Set.of() : Collections.singleton(SUPERUSER_ROLE_DESCRIPTOR),
type == ApiKey.Type.CROSS_CLUSTER
? Set.of()
: ApiKeyService.removeUserRoleDescriptorDescriptions(Set.of(SUPERUSER_ROLE_DESCRIPTOR)),
Instant.now(),
Instant.now().plus(expiry),
keyRoles,
Expand Down Expand Up @@ -1316,22 +1318,6 @@ public void testParseRoleDescriptorsMap() throws Exception {
assertThat(roleDescriptors, hasSize(1));
assertThat(roleDescriptors.get(0), equalTo(roleARoleDescriptor));

Map<String, Object> superUserRdMap;
try (XContentBuilder builder = JsonXContent.contentBuilder()) {
superUserRdMap = XContentHelper.convertToMap(
XContentType.JSON.xContent(),
BytesReference.bytes(SUPERUSER_ROLE_DESCRIPTOR.toXContent(builder, ToXContent.EMPTY_PARAMS, true)).streamInput(),
false
);
}
roleDescriptors = service.parseRoleDescriptors(
apiKeyId,
Map.of(SUPERUSER_ROLE_DESCRIPTOR.getName(), superUserRdMap),
randomApiKeyRoleType()
);
assertThat(roleDescriptors, hasSize(1));
assertThat(roleDescriptors.get(0), equalTo(SUPERUSER_ROLE_DESCRIPTOR));

final Map<String, Object> legacySuperUserRdMap;
try (XContentBuilder builder = JsonXContent.contentBuilder()) {
legacySuperUserRdMap = XContentHelper.convertToMap(
Expand Down Expand Up @@ -1812,7 +1798,10 @@ public void testApiKeyDocCache() throws IOException, ExecutionException, Interru
RoleReference.ApiKeyRoleType.LIMITED_BY
);
assertEquals(1, limitedByRoleDescriptors.size());
assertEquals(SUPERUSER_ROLE_DESCRIPTOR, limitedByRoleDescriptors.get(0));
RoleDescriptor superuserWithoutDescription = ApiKeyService.removeUserRoleDescriptorDescriptions(Set.of(SUPERUSER_ROLE_DESCRIPTOR))
.iterator()
.next();
assertEquals(superuserWithoutDescription, limitedByRoleDescriptors.get(0));
if (metadata == null) {
assertNull(cachedApiKeyDoc.metadataFlattened);
} else {
Expand Down

0 comments on commit 77ce605

Please sign in to comment.