forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SecuritySolution] Check user permissions before initialising entity …
…engine (elastic#198661) ## Summary * Create privileges API for the Entity Store * Create missing privileges callout * Add missing Entity Store privileges callout to Entity Store * Add missing Entity Store privileges callout to Dashboard ![Screenshot 2024-11-04 at 15 57 15](https://github.com/user-attachments/assets/ed013571-4f0d-4605-bd2a-faa5ad3ac3e6) ![Screenshot 2024-11-04 at 16 16 03](https://github.com/user-attachments/assets/4cf6cf7d-a8c1-4c96-8fd1-2bf8be9f785e) https://github.com/user-attachments/assets/30cdb096-24cd-4a1c-a20b-abbbece865d7 ### Update: I added a "Line clamp" and "Read More" button as requested by Mark: ![Screenshot 2024-11-05 at 13 15 51](https://github.com/user-attachments/assets/42fbec93-e258-49af-8acc-ae18314be442) ### Checklist - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- Loading branch information
Showing
27 changed files
with
565 additions
and
42 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
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
22 changes: 22 additions & 0 deletions
22
...s/security_solution/common/api/entity_analytics/entity_store/engine/get_privileges.gen.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,22 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/* | ||
* NOTICE: Do not edit this file manually. | ||
* This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. | ||
* | ||
* info: | ||
* title: Get Entity Store Privileges Schema | ||
* version: 1 | ||
*/ | ||
|
||
import type { z } from '@kbn/zod'; | ||
|
||
import { EntityAnalyticsPrivileges } from '../../common/common.gen'; | ||
|
||
export type EntityStoreGetPrivilegesResponse = z.infer<typeof EntityStoreGetPrivilegesResponse>; | ||
export const EntityStoreGetPrivilegesResponse = EntityAnalyticsPrivileges; |
19 changes: 19 additions & 0 deletions
19
...urity_solution/common/api/entity_analytics/entity_store/engine/get_privileges.schema.yaml
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,19 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: Get Entity Store Privileges Schema | ||
version: '1' | ||
paths: | ||
/internal/entity_store/privileges: | ||
get: | ||
x-labels: [ess, serverless] | ||
x-internal: true | ||
x-codegen-enabled: true | ||
operationId: EntityStoreGetPrivileges | ||
summary: Get Entity Store Privileges | ||
responses: | ||
'200': | ||
description: Successful response | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '../../common/common.schema.yaml#/components/schemas/EntityAnalyticsPrivileges' |
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
101 changes: 101 additions & 0 deletions
101
x-pack/plugins/security_solution/common/entity_analytics/privileges.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,101 @@ | ||
/* | ||
* 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 { getAllMissingPrivileges } from './privileges'; | ||
import type { EntityAnalyticsPrivileges } from '../api/entity_analytics'; | ||
|
||
describe('getAllMissingPrivileges', () => { | ||
it('should return all missing privileges for elasticsearch and kibana', () => { | ||
const privileges: EntityAnalyticsPrivileges = { | ||
privileges: { | ||
elasticsearch: { | ||
index: { | ||
'logs-*': { read: true, view_index_metadata: true }, | ||
'auditbeat-*': { read: false, view_index_metadata: false }, | ||
}, | ||
cluster: { | ||
manage_enrich: false, | ||
manage_ingest_pipelines: true, | ||
}, | ||
}, | ||
kibana: { | ||
'saved_object:entity-engine-status/all': false, | ||
'saved_object:entity-definition/all': true, | ||
}, | ||
}, | ||
has_all_required: false, | ||
has_read_permissions: false, | ||
has_write_permissions: false, | ||
}; | ||
|
||
const result = getAllMissingPrivileges(privileges); | ||
|
||
expect(result).toEqual({ | ||
elasticsearch: { | ||
index: [{ indexName: 'auditbeat-*', privileges: ['read', 'view_index_metadata'] }], | ||
cluster: ['manage_enrich'], | ||
}, | ||
kibana: ['saved_object:entity-engine-status/all'], | ||
}); | ||
}); | ||
|
||
it('should return empty lists if all privileges are true', () => { | ||
const privileges: EntityAnalyticsPrivileges = { | ||
privileges: { | ||
elasticsearch: { | ||
index: { | ||
'logs-*': { read: true, view_index_metadata: true }, | ||
}, | ||
cluster: { | ||
manage_enrich: true, | ||
}, | ||
}, | ||
kibana: { | ||
'saved_object:entity-engine-status/all': true, | ||
}, | ||
}, | ||
has_all_required: true, | ||
has_read_permissions: true, | ||
has_write_permissions: true, | ||
}; | ||
|
||
const result = getAllMissingPrivileges(privileges); | ||
|
||
expect(result).toEqual({ | ||
elasticsearch: { | ||
index: [], | ||
cluster: [], | ||
}, | ||
kibana: [], | ||
}); | ||
}); | ||
|
||
it('should handle empty privileges object', () => { | ||
const privileges: EntityAnalyticsPrivileges = { | ||
privileges: { | ||
elasticsearch: { | ||
index: {}, | ||
cluster: {}, | ||
}, | ||
kibana: {}, | ||
}, | ||
has_all_required: false, | ||
has_read_permissions: false, | ||
has_write_permissions: false, | ||
}; | ||
|
||
const result = getAllMissingPrivileges(privileges); | ||
|
||
expect(result).toEqual({ | ||
elasticsearch: { | ||
index: [], | ||
cluster: [], | ||
}, | ||
kibana: [], | ||
}); | ||
}); | ||
}); |
30 changes: 30 additions & 0 deletions
30
x-pack/plugins/security_solution/common/entity_analytics/privileges.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 type { EntityAnalyticsPrivileges } from '../api/entity_analytics'; | ||
|
||
export const getAllMissingPrivileges = (privilege: EntityAnalyticsPrivileges) => { | ||
const esPrivileges = privilege.privileges.elasticsearch; | ||
const kbnPrivileges = privilege.privileges.kibana; | ||
|
||
const index = Object.entries(esPrivileges.index ?? {}) | ||
.map(([indexName, indexPrivileges]) => ({ | ||
indexName, | ||
privileges: filterUnauthorized(indexPrivileges), | ||
})) | ||
.filter(({ privileges }) => privileges.length > 0); | ||
|
||
return { | ||
elasticsearch: { index, cluster: filterUnauthorized(esPrivileges.cluster) }, | ||
kibana: filterUnauthorized(kbnPrivileges), | ||
}; | ||
}; | ||
|
||
const filterUnauthorized = (obj: Record<string, boolean> | undefined) => | ||
Object.entries(obj ?? {}) | ||
.filter(([_, authorized]) => !authorized) | ||
.map(([privileges, _]) => privileges); |
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.