Skip to content

Commit 16af3e9

Browse files
XavierMjonathan-buttneryctercero
authored
[RAC] Remove rbac on security solution side (#110472)
* wip to remove rbac * Revert "[Cases] Include rule registry client for updating alert statuses (#108588)" This reverts commit 1fd7038. This leaves the rule registry mock changes * remove rbac on Trend/Count alert * update detection api for status * remove @kbn-alerts packages * fix leftover * Switching cases to leverage update by query for alert status * Adding missed files * fix bad logic * updating tests for use_alerts_privileges * remove index alias/fields * fix types * fix plugin to get the right index names * left over of alis on template * forget to use current user for create/read route index * updated alerts page to not show table when no privileges and updates to tests * fix bug when switching between o11y and security solution * updates tests and move to use privileges page when user tries to access alerts without proper access * updating jest tests * pairing with yara * bring back kbn-alerts after discussion with the team * fix types * fix index field for o11y * fix bug with updating index priv state * fix i18n issue and update api docs * fix refresh on alerts * fix render view on alerts * updating tests and checking for null in alerts page to not show no privileges page before load * fix details rules Co-authored-by: Jonathan Buttner <jonathan.buttner@elastic.co> Co-authored-by: Yara Tercero <yara.tercero@elastic.co>
1 parent a9e77fd commit 16af3e9

File tree

77 files changed

+1071
-889
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1071
-889
lines changed

docs/development/core/public/kibana-plugin-core-public.doclinksstart.links.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ readonly links: {
128128
readonly rollupJobs: string;
129129
readonly elasticsearch: Record<string, string>;
130130
readonly siem: {
131+
readonly privileges: string;
131132
readonly guide: string;
132133
readonly gettingStarted: string;
133134
readonly ml: string;

docs/development/core/public/kibana-plugin-core-public.doclinksstart.md

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/core/public/doc_links/doc_links_service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ export class DocLinksService {
204204
siem: {
205205
guide: `${ELASTIC_WEBSITE_URL}guide/en/security/${DOC_LINK_VERSION}/index.html`,
206206
gettingStarted: `${ELASTIC_WEBSITE_URL}guide/en/security/${DOC_LINK_VERSION}/index.html`,
207+
privileges: `${ELASTIC_WEBSITE_URL}guide/en/security/${DOC_LINK_VERSION}/sec-requirements.html`,
207208
ml: `${ELASTIC_WEBSITE_URL}guide/en/security/${DOC_LINK_VERSION}/machine-learning.html`,
208209
ruleChangeLog: `${ELASTIC_WEBSITE_URL}guide/en/security/${DOC_LINK_VERSION}/prebuilt-rules-changelog.html`,
209210
detectionsReq: `${ELASTIC_WEBSITE_URL}guide/en/security/${DOC_LINK_VERSION}/detections-permissions-section.html`,
@@ -569,6 +570,7 @@ export interface DocLinksStart {
569570
readonly rollupJobs: string;
570571
readonly elasticsearch: Record<string, string>;
571572
readonly siem: {
573+
readonly privileges: string;
572574
readonly guide: string;
573575
readonly gettingStarted: string;
574576
readonly ml: string;

src/core/public/public.api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ export interface DocLinksStart {
592592
readonly rollupJobs: string;
593593
readonly elasticsearch: Record<string, string>;
594594
readonly siem: {
595+
readonly privileges: string;
595596
readonly guide: string;
596597
readonly gettingStarted: string;
597598
readonly ml: string;

x-pack/plugins/cases/kibana.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"id":"cases",
1111
"kibanaVersion":"kibana",
1212
"optionalPlugins":[
13-
"ruleRegistry",
1413
"security",
1514
"spaces"
1615
],

x-pack/plugins/cases/server/client/alerts/get.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,19 @@ export const get = async (
1212
{ alertsInfo }: AlertGet,
1313
clientArgs: CasesClientArgs
1414
): Promise<CasesClientGetAlertsResponse> => {
15-
const { alertsService, logger } = clientArgs;
15+
const { alertsService, scopedClusterClient, logger } = clientArgs;
1616
if (alertsInfo.length === 0) {
1717
return [];
1818
}
1919

20-
const alerts = await alertsService.getAlerts({ alertsInfo, logger });
21-
return alerts ?? [];
20+
const alerts = await alertsService.getAlerts({ alertsInfo, scopedClusterClient, logger });
21+
if (!alerts) {
22+
return [];
23+
}
24+
25+
return alerts.docs.map((alert) => ({
26+
id: alert._id,
27+
index: alert._index,
28+
...alert._source,
29+
}));
2230
};

x-pack/plugins/cases/server/client/alerts/types.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,17 @@
77

88
import { CaseStatuses } from '../../../common/api';
99
import { AlertInfo } from '../../common';
10-
import { Alert } from '../../services/alerts/types';
10+
11+
interface Alert {
12+
id: string;
13+
index: string;
14+
destination?: {
15+
ip: string;
16+
};
17+
source?: {
18+
ip: string;
19+
};
20+
}
1121

1222
export type CasesClientGetAlertsResponse = Alert[];
1323

x-pack/plugins/cases/server/client/alerts/update_status.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ export const updateStatus = async (
1616
{ alerts }: UpdateAlertsStatusArgs,
1717
clientArgs: CasesClientArgs
1818
): Promise<void> => {
19-
const { alertsService, logger } = clientArgs;
20-
await alertsService.updateAlertsStatus({ alerts, logger });
19+
const { alertsService, scopedClusterClient, logger } = clientArgs;
20+
await alertsService.updateAlertsStatus({ alerts, scopedClusterClient, logger });
2121
};

x-pack/plugins/cases/server/client/attachments/add.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ import {
4040
} from '../../services/user_actions/helpers';
4141

4242
import { AttachmentService, CasesService, CaseUserActionService } from '../../services';
43-
import { createCaseError, CommentableCase, isCommentRequestTypeGenAlert } from '../../common';
43+
import {
44+
createCaseError,
45+
CommentableCase,
46+
createAlertUpdateRequest,
47+
isCommentRequestTypeGenAlert,
48+
} from '../../common';
4449
import { CasesClientArgs, CasesClientInternal } from '..';
4550

4651
import { decodeCommentRequest } from '../utils';
@@ -190,9 +195,22 @@ const addGeneratedAlerts = async (
190195
user: userDetails,
191196
commentReq: query,
192197
id: savedObjectID,
193-
casesClientInternal,
194198
});
195199

200+
if (
201+
(newComment.attributes.type === CommentType.alert ||
202+
newComment.attributes.type === CommentType.generatedAlert) &&
203+
caseInfo.attributes.settings.syncAlerts
204+
) {
205+
const alertsToUpdate = createAlertUpdateRequest({
206+
comment: query,
207+
status: subCase.attributes.status,
208+
});
209+
await casesClientInternal.alerts.updateStatus({
210+
alerts: alertsToUpdate,
211+
});
212+
}
213+
196214
await userActionService.bulkCreate({
197215
unsecuredSavedObjectsClient,
198216
actions: [
@@ -368,9 +386,19 @@ export const addComment = async (
368386
user: userInfo,
369387
commentReq: query,
370388
id: savedObjectID,
371-
casesClientInternal,
372389
});
373390

391+
if (newComment.attributes.type === CommentType.alert && updatedCase.settings.syncAlerts) {
392+
const alertsToUpdate = createAlertUpdateRequest({
393+
comment: query,
394+
status: updatedCase.status,
395+
});
396+
397+
await casesClientInternal.alerts.updateStatus({
398+
alerts: alertsToUpdate,
399+
});
400+
}
401+
374402
await userActionService.bulkCreate({
375403
unsecuredSavedObjectsClient,
376404
actions: [

x-pack/plugins/cases/server/client/cases/push.ts

Lines changed: 21 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import Boom from '@hapi/boom';
9-
import { SavedObjectsFindResponse, SavedObject, Logger } from 'kibana/server';
9+
import { SavedObjectsFindResponse, SavedObject } from 'kibana/server';
1010

1111
import {
1212
ActionConnector,
@@ -22,16 +22,26 @@ import {
2222
import { buildCaseUserActionItem } from '../../services/user_actions/helpers';
2323

2424
import { createIncident, getCommentContextFromAttributes } from './utils';
25-
import {
26-
AlertInfo,
27-
createCaseError,
28-
flattenCaseSavedObject,
29-
getAlertInfoFromComments,
30-
} from '../../common';
25+
import { createCaseError, flattenCaseSavedObject, getAlertInfoFromComments } from '../../common';
3126
import { CasesClient, CasesClientArgs, CasesClientInternal } from '..';
3227
import { Operations } from '../../authorization';
3328
import { casesConnectors } from '../../connectors';
34-
import { CasesClientGetAlertsResponse } from '../alerts/types';
29+
30+
/**
31+
* Returns true if the case should be closed based on the configuration settings and whether the case
32+
* is a collection. Collections are not closable because we aren't allowing their status to be changed.
33+
* In the future we could allow push to close all the sub cases of a collection but that's not currently supported.
34+
*/
35+
function shouldCloseByPush(
36+
configureSettings: SavedObjectsFindResponse<CasesConfigureAttributes>,
37+
caseInfo: SavedObject<CaseAttributes>
38+
): boolean {
39+
return (
40+
configureSettings.total > 0 &&
41+
configureSettings.saved_objects[0].attributes.closure_type === 'close-by-pushing' &&
42+
caseInfo.attributes.type !== CaseType.collection
43+
);
44+
}
3545

3646
/**
3747
* Parameters for pushing a case to an external system
@@ -96,7 +106,9 @@ export const push = async (
96106

97107
const alertsInfo = getAlertInfoFromComments(theCase?.comments);
98108

99-
const alerts = await getAlertsCatchErrors({ casesClientInternal, alertsInfo, logger });
109+
const alerts = await casesClientInternal.alerts.get({
110+
alertsInfo,
111+
});
100112

101113
const getMappingsResponse = await casesClientInternal.configuration.getMappings({
102114
connector: theCase.connector,
@@ -266,38 +278,3 @@ export const push = async (
266278
throw createCaseError({ message: `Failed to push case: ${error}`, error, logger });
267279
}
268280
};
269-
270-
async function getAlertsCatchErrors({
271-
casesClientInternal,
272-
alertsInfo,
273-
logger,
274-
}: {
275-
casesClientInternal: CasesClientInternal;
276-
alertsInfo: AlertInfo[];
277-
logger: Logger;
278-
}): Promise<CasesClientGetAlertsResponse> {
279-
try {
280-
return await casesClientInternal.alerts.get({
281-
alertsInfo,
282-
});
283-
} catch (error) {
284-
logger.error(`Failed to retrieve alerts during push: ${error}`);
285-
return [];
286-
}
287-
}
288-
289-
/**
290-
* Returns true if the case should be closed based on the configuration settings and whether the case
291-
* is a collection. Collections are not closable because we aren't allowing their status to be changed.
292-
* In the future we could allow push to close all the sub cases of a collection but that's not currently supported.
293-
*/
294-
function shouldCloseByPush(
295-
configureSettings: SavedObjectsFindResponse<CasesConfigureAttributes>,
296-
caseInfo: SavedObject<CaseAttributes>
297-
): boolean {
298-
return (
299-
configureSettings.total > 0 &&
300-
configureSettings.saved_objects[0].attributes.closure_type === 'close-by-pushing' &&
301-
caseInfo.attributes.type !== CaseType.collection
302-
);
303-
}

0 commit comments

Comments
 (0)