-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Entity Analytics] Restrict management page based on user privileges (#…
…173178) ## Summary Closes #171633 A few changes on the entity analytics management page: - If the user does not have risk engine permissions, disable the Risk engine switch. - If the user does not have risk score read permission, do not show the risk scores preview. - Do not show the risk engine status as "off" while we are loading the status, show "-" instead - Remove privileges accordion from error callout (see below) ### Test steps create a user without risk engine privileges and go to the entity analytics management page. Here is a handy script to create the user `no_risk_engine`, you will need to change your Kibana URL <details> <summary>expand for mkuser.sh</summary> ```bash #!/bin/bash KIBANA_URL="http://elastic:changeme@localhost:5601/mark" curl "$KIBANA_URL/api/security/role/no_risk_engine?createOnly=true" \ -X 'PUT' \ -H 'elastic-api-version: 2023-10-31' \ -H 'kbn-xsrf:hello' \ --user elastic:changeme \ -H 'Content-Type: application/json' \ --data-raw '{"elasticsearch":{"cluster":[],"indices":[{"names":["logs-*"],"privileges":["read"],"field_security":{"grant":["*"],"except":[]}}],"run_as":[]},"kibana":[{"spaces":["*"],"base":[],"feature":{"siem":["all"]}}]}' \ --compressed curl "$KIBANA_URL/internal/security/users/no_risk_engine" \ -X 'POST' \ -H 'elastic-api-version: 2023-10-31' \ -H 'kbn-xsrf:hello' \ --user elastic:changeme \ -H 'Content-Type: application/json' \ --data-raw '{"password":"changeme","username":"no_risk_engine","full_name":"","email":"","roles":["no_risk_engine"]}' \ --compressed% ``` </details> # After <img width="1728" alt="Screenshot 2023-12-13 at 13 51 45" src="https://github.com/elastic/kibana/assets/3315046/9996dfd3-035a-48d9-a331-e60db911a391"> <img width="493" alt="276204977-d808883a-b66b-4f58-9acc-6d977c644741" src="https://github.com/elastic/kibana/assets/3315046/e1cc8971-a66b-48bb-9474-6cc99c9215b4"> # Before <img width="1482" alt="Screenshot 2023-12-13 at 14 08 12" src="https://github.com/elastic/kibana/assets/3315046/85a56a72-4eb8-4677-a55b-8598fec2151d"> --------- Co-authored-by: Jared Burgett <[email protected]> Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Ryland Herrick <[email protected]> Co-authored-by: Pablo Machado <[email protected]>
- Loading branch information
1 parent
1095cb2
commit cd02e8d
Showing
12 changed files
with
258 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
x-pack/plugins/security_solution/public/entity_analytics/common/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export { userHasRiskEngineReadPermissions } from './user_has_risk_engine_read_permissions'; | ||
export * from './utils'; |
57 changes: 57 additions & 0 deletions
57
...ity_solution/public/entity_analytics/common/user_has_risk_engine_read_permissions.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { userHasRiskEngineReadPermissions } from './user_has_risk_engine_read_permissions'; | ||
|
||
describe('userHasRiskEngineReadPermissions', () => { | ||
it('returns false if isLoading is true', () => { | ||
expect(userHasRiskEngineReadPermissions({ isLoading: true })).toEqual(false); | ||
}); | ||
it('returns true if hasAllRequiredPrivileges is true', () => { | ||
expect( | ||
userHasRiskEngineReadPermissions({ isLoading: false, hasAllRequiredPrivileges: true }) | ||
).toEqual(true); | ||
}); | ||
it('returns false if hasAllRequiredPrivileges is false and user is missing read permissions', () => { | ||
expect( | ||
userHasRiskEngineReadPermissions({ | ||
isLoading: false, | ||
hasAllRequiredPrivileges: false, | ||
missingPrivileges: { | ||
clusterPrivileges: [], | ||
indexPrivileges: [['risk-score.risk-score-*', ['read']]], | ||
}, | ||
}) | ||
).toEqual(false); | ||
}); | ||
|
||
it('returns true if hasAllRequiredPrivileges is false and user is missing read permissions for other index', () => { | ||
expect( | ||
userHasRiskEngineReadPermissions({ | ||
isLoading: false, | ||
hasAllRequiredPrivileges: false, | ||
missingPrivileges: { | ||
clusterPrivileges: [], | ||
indexPrivileges: [['other-index.other-index-*', ['read']]], | ||
}, | ||
}) | ||
).toEqual(true); | ||
}); | ||
|
||
it('returns true if hasAllRequiredPrivileges is false and user is not missing read permissions', () => { | ||
expect( | ||
userHasRiskEngineReadPermissions({ | ||
isLoading: false, | ||
hasAllRequiredPrivileges: false, | ||
missingPrivileges: { | ||
clusterPrivileges: [], | ||
indexPrivileges: [['risk-score.risk-score-*', ['write']]], | ||
}, | ||
}) | ||
).toEqual(true); | ||
}); | ||
}); |
30 changes: 30 additions & 0 deletions
30
...security_solution/public/entity_analytics/common/user_has_risk_engine_read_permissions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { RISK_SCORE_INDEX_PATTERN } from '../../../common/entity_analytics/risk_engine'; | ||
import type { RiskEngineMissingPrivilegesResponse } from '../hooks/use_missing_risk_engine_privileges'; | ||
|
||
export const userHasRiskEngineReadPermissions = ( | ||
privileges: RiskEngineMissingPrivilegesResponse | ||
): boolean => { | ||
if (privileges.isLoading) { | ||
return false; | ||
} | ||
|
||
if (privileges.hasAllRequiredPrivileges) { | ||
return true; | ||
} | ||
|
||
const { indexPrivileges: missingIndexPrivileges } = privileges.missingPrivileges; | ||
|
||
const isMissingReadPrivilege = missingIndexPrivileges.find( | ||
([indexName, indexPrivileges]) => | ||
indexName === RISK_SCORE_INDEX_PATTERN && indexPrivileges.includes('read') | ||
); | ||
|
||
return !isMissingReadPrivilege; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.