[8.13] Fix upgrade assistant warning for optional roles and roleTemplate properties (#179818) (#180234)

# Backport

This will backport the following commits from `main` to `8.13`:
- [Fix upgrade assistant warning for optional roles and roleTemplate
properties (#179818)](https://github.com/elastic/kibana/pull/179818)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT
[{"author":{"name":"Sid","email":"siddharthmantri1@gmail.com"},"sourceCommit":{"committedDate":"2024-04-06T16:20:25Z","message":"Fix
upgrade assistant warning for optional roles and roleTemplate properties
(#179818)\n\nCloses
https://github.com/elastic/kibana/issues/177065\r\n\r\n##
Summary\r\nUpgrade assistant in cloud shows a warning when trying to
upgrade due to\r\nmutually exclusive `roles` and `roleTemplates`
property in the `Get Role\r\nMappings` API from ES. This PR fixes that
by introducing conditional\r\nchecks for where we check for the `roles`
property.\r\n\r\n\r\n## Release notes\r\nFix warning displayed in
Upgrade Assistant regarding `roles` and\r\n`roleTemplate` properties
when checking response from Get Role
Mappings\r\nAPI.\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>\r\nCo-authored-by:
Kurt
<kc13greiner@users.noreply.github.com>","sha":"597ab88d9ee5e66e44d459a32bb5a3f7461646a5","branchLabelMapping":{"^v8.14.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Security","backport:all-open","v8.13.0","v7.17.17","v8.14.0"],"title":"Fix
upgrade assistant warning for optional roles and roleTemplate
properties","number":179818,"url":"https://github.com/elastic/kibana/pull/179818","mergeCommit":{"message":"Fix
upgrade assistant warning for optional roles and roleTemplate properties
(#179818)\n\nCloses
https://github.com/elastic/kibana/issues/177065\r\n\r\n##
Summary\r\nUpgrade assistant in cloud shows a warning when trying to
upgrade due to\r\nmutually exclusive `roles` and `roleTemplates`
property in the `Get Role\r\nMappings` API from ES. This PR fixes that
by introducing conditional\r\nchecks for where we check for the `roles`
property.\r\n\r\n\r\n## Release notes\r\nFix warning displayed in
Upgrade Assistant regarding `roles` and\r\n`roleTemplate` properties
when checking response from Get Role
Mappings\r\nAPI.\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>\r\nCo-authored-by:
Kurt
<kc13greiner@users.noreply.github.com>","sha":"597ab88d9ee5e66e44d459a32bb5a3f7461646a5"}},"sourceBranch":"main","suggestedTargetBranches":["8.13","7.17"],"targetPullRequestStates":[{"branch":"8.13","label":"v8.13.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"7.17","label":"v7.17.17","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.14.0","branchLabelMappingKey":"^v8.14.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/179818","number":179818,"mergeCommit":{"message":"Fix
upgrade assistant warning for optional roles and roleTemplate properties
(#179818)\n\nCloses
https://github.com/elastic/kibana/issues/177065\r\n\r\n##
Summary\r\nUpgrade assistant in cloud shows a warning when trying to
upgrade due to\r\nmutually exclusive `roles` and `roleTemplates`
property in the `Get Role\r\nMappings` API from ES. This PR fixes that
by introducing conditional\r\nchecks for where we check for the `roles`
property.\r\n\r\n\r\n## Release notes\r\nFix warning displayed in
Upgrade Assistant regarding `roles` and\r\n`roleTemplate` properties
when checking response from Get Role
Mappings\r\nAPI.\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>\r\nCo-authored-by:
Kurt
<kc13greiner@users.noreply.github.com>","sha":"597ab88d9ee5e66e44d459a32bb5a3f7461646a5"}}]}]
BACKPORT-->

Co-authored-by: Sid <siddharthmantri1@gmail.com>
This commit is contained in:
Kibana Machine 2024-04-10 06:17:02 -04:00 committed by GitHub
parent aba8b3ccb4
commit cf54f09473
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 3 additions and 3 deletions

View file

@ -211,7 +211,7 @@ async function getRoleMappingsDeprecations(
const roleMappingsWithReportingRole: string[] = Object.entries(roleMappings).reduce(
(roleSet, current) => {
const [roleName, role] = current;
const foundMapping = role.roles.find((roll) => deprecatedRoles.includes(roll));
const foundMapping = role.roles?.find((roll) => deprecatedRoles.includes(roll));
if (foundMapping) {
roleSet.push(`${roleName}[${foundMapping}]`);
}

View file

@ -156,7 +156,7 @@ async function getRoleMappingsDeprecations(
}
const roleMappingsWithKibanaUserRole = Object.entries(roleMappings)
.filter(([, roleMapping]) => roleMapping.roles.includes(KIBANA_USER_ROLE_NAME))
.filter(([, roleMapping]) => roleMapping.roles?.includes(KIBANA_USER_ROLE_NAME))
.map(([mappingName]) => mappingName);
if (roleMappingsWithKibanaUserRole.length === 0) {
return [];

View file

@ -100,7 +100,7 @@ export function defineKibanaUserRoleDeprecationRoutes({ router, logger }: RouteD
}
const roleMappingsWithKibanaUserRole = Object.entries(roleMappings).filter(([, mapping]) =>
mapping.roles.includes(KIBANA_USER_ROLE_NAME)
mapping.roles?.includes(KIBANA_USER_ROLE_NAME)
);
if (roleMappingsWithKibanaUserRole.length === 0) {