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

[Spaces and Roles] Fix rules on showing Permissions tab #196442

Merged
merged 12 commits into from
Oct 18, 2024

Conversation

tsullivan
Copy link
Member

@tsullivan tsullivan commented Oct 15, 2024

Summary

Some deployment types don't have custom roles. This PR hides the Permissions tab in Spaces Management for projects without role management enabled. The solution uses the isRoleManagementEnabled function from the security plugin’s authz service for this.

@tsullivan tsullivan added release_note:skip Skip the PR/issue when compiling release notes v8.16.0 backport:version Backport to applied version labels Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! labels Oct 15, 2024
@@ -92,7 +93,11 @@ export const getTabs = ({
},
];

if (canUserViewRoles) {
const canUserViewRoles = Boolean(capabilities?.roles?.view);
const isRoleManagementEnabled = authz && authz.isRoleManagementEnabled() !== false;
Copy link
Contributor

@jeramysoucy jeramysoucy Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const isRoleManagementEnabled = authz && authz.isRoleManagementEnabled() !== false;
const isRoleManagementEnabled = authz && authz.isRoleManagementEnabled();

or

Suggested change
const isRoleManagementEnabled = authz && authz.isRoleManagementEnabled() !== false;
const isRoleManagementEnabled = authz && authz.isRoleManagementEnabled() === true;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeramysoucy I think we examined this further in Slack, and agreed that the config.roleManagementEnabled is only available in serverless, which makes the authz.isRoleManagementEnabled() return undefined in stateful, when it actually should be interpreted as being enabled.

So how about:

  /*
   * config.roleManagementEnabled is an offering-based config. In serverless, the value will be true or false.
   * In stateful, role management is enabled but the config setting is expected to be undefined.
   */
  const isRoleManagementEnabled =
    authz &&
    (typeof authz.isRoleManagementEnabled() === 'undefined' || authz.isRoleManagementEnabled());

Alternatively, we could update the implementation of authz.isRoleManagementEnabled in

const isRoleManagementEnabled = () => config.roleManagementEnabled;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this logic to x-pack/plugins/spaces/public/management/edit_space/provider/edit_space_provider.tsx

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Tim! Sorry for the confusion.

Copy link
Contributor

@eokoneyo eokoneyo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some nit comments

x-pack/plugins/spaces/tsconfig.json Outdated Show resolved Hide resolved
@tsullivan tsullivan force-pushed the spaces/use-role-management-flag branch from 85247fd to db8c2f9 Compare October 16, 2024 16:37
@tsullivan tsullivan force-pushed the spaces/use-role-management-flag branch from 4e26ce3 to eeb43a8 Compare October 16, 2024 19:43
@tsullivan tsullivan marked this pull request as ready for review October 16, 2024 19:51
@tsullivan tsullivan requested a review from a team as a code owner October 16, 2024 19:51
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-security (Team:Security)

jeramysoucy
jeramysoucy previously approved these changes Oct 17, 2024
Copy link
Contributor

@jeramysoucy jeramysoucy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just one nit/suggestion to add a unit test case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: we could a test here to confirm that the Permissions tab does not render when getIsRoleManagementEnabled resolves false.

@jeramysoucy jeramysoucy dismissed their stale review October 17, 2024 07:59

Wanted to avoid merge before feedback is reviewed.

@tsullivan
Copy link
Member Author

@jeramysoucy I have addressed the feedback by adding tests to unit tests that deal with the permissions tab.

I have also updated the code because the original fix didn't account for an HTTP request that results in a 404 when role management is disabled: 3795630

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
spaces 256.2KB 256.4KB +234.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
spaces 33.7KB 34.1KB +347.0B

History

Copy link
Contributor

@jeramysoucy jeramysoucy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@tsullivan tsullivan merged commit 4ed9e51 into elastic:main Oct 18, 2024
24 checks passed
@tsullivan tsullivan deleted the spaces/use-role-management-flag branch October 18, 2024 15:40
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.16, 8.x

https://github.com/elastic/kibana/actions/runs/11406746377

@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.16 Backport failed because of merge conflicts
8.x Backport failed because of merge conflicts

Manual backport

To create the backport manually run:

node scripts/backport --pr 196442

Questions ?

Please refer to the Backport tool documentation

tsullivan added a commit to tsullivan/kibana that referenced this pull request Oct 18, 2024
…6442)

## Summary

Some deployment types don't have custom roles. This PR hides the
`Permissions` tab in Spaces Management for projects without role
management enabled. The solution uses the isRoleManagementEnabled
function from the security plugin’s authz service for this.

---------

Co-authored-by: kibanamachine <[email protected]>
(cherry picked from commit 4ed9e51)
tsullivan added a commit to tsullivan/kibana that referenced this pull request Oct 18, 2024
…6442)

## Summary

Some deployment types don't have custom roles. This PR hides the
`Permissions` tab in Spaces Management for projects without role
management enabled. The solution uses the isRoleManagementEnabled
function from the security plugin’s authz service for this.

---------

Co-authored-by: kibanamachine <[email protected]>
(cherry picked from commit 4ed9e51)
@tsullivan
Copy link
Member Author

💚 All backports created successfully

Status Branch Result
8.x
8.16

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:version Backport to applied version labels release_note:skip Skip the PR/issue when compiling release notes Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! v8.16.0 v8.17.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants