-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[SecuritySolution] Check user permissions before initialising entity engine #198661
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
63b9346
Create privileges API for the Entity Store
machadoum 18cf5fa
Add entity store priveleges callout to Entity Store page
machadoum 65f119b
Add Entity Store privileges check to Dashboard
machadoum 686d467
Self code-review
machadoum b5c049b
Merge branch 'main' into siem-ea-10926
machadoum d3e0c49
Add LineClamp to privileges callout
machadoum 89dfa05
Fix type
machadoum 43d7a75
Fix i18n
machadoum 6129833
Fix i18n
machadoum 6997f3d
Fix tests
machadoum c252a80
Make LineClamp component more generic
machadoum File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is outside the scope of this ticket but it's weird to me that we're using OpenAPI to type the privileges object, when we already have TS types for it on kibana side, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but from what I know, we can't reuse TS types inside OpenAPi schemas. 😞