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.
[Security Solution] Fix losing data upon prebuilt rule upgrade to a n…
…ew version in which the rule's type is different (elastic#176421) **Fixes:** elastic#169480 ## Summary This PR fixes losing the following rule data upon prebuilt rule upgrade to a new version in which the rule's type is different - Saved Object id - exceptions list (default and shared) - Timeline id - Timeline title ## Details The problem occurs when user upgrades a prebuilt rule to a newer version which has a different rule type. Checking the code it's not so hard to find [`upgradeRule()`](https://github.com/elastic/kibana/blob/main/x-pack/plugins/security_solution/server/lib/detection_engine/prebuilt_rules/logic/rule_objects/upgrade_prebuilt_rules.ts#L49) function which performs prebuilt rule upgrade. It has the following comment > If we're trying to change the type of a prepackaged rule, we need to delete the old one and replace it with the new rule, keeping the enabled setting, actions, throttle, id, and exception lists from the old rule. Looking below in the code it's clear that only enabled state and actions get restored upon rule upgrade. Missing to restore `exceptions lists` leads to disappearing exceptions upon rule upgrade. On top of this `execution results` and `execution events` also get lost due to missing to restore saved object `id`. Execution log isn't gone anywhere but can't be bound to a new id. Direct links to rule details page won't work neither after upgrade. This PR fixes the problem by restoring rule bound data after upgrade. FTR tests were restructured to accommodate extra tests to cover this bug fix. ### Checklist - [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 (cherry picked from commit ffdcc34) # Conflicts: # x-pack/plugins/security_solution/docs/testing/test_plans/detection_response/prebuilt_rules/installation_and_upgrade.md # x-pack/test/security_solution_api_integration/test_suites/detections_response/default_license/prebuilt_rules/management/install_and_upgrade_prebuilt_rules.ts # x-pack/test/security_solution_api_integration/test_suites/detections_response/default_license/prebuilt_rules/management/install_prebuilt_rules.ts # x-pack/test/security_solution_api_integration/test_suites/detections_response/default_license/prebuilt_rules/management/install_prebuilt_rules_with_historical_versions.ts # x-pack/test/security_solution_api_integration/test_suites/detections_response/default_license/prebuilt_rules/management/upgrade_prebuilt_rules.ts # x-pack/test/security_solution_api_integration/test_suites/detections_response/default_license/prebuilt_rules/management/upgrade_prebuilt_rules_with_historical_versions.ts # x-pack/test/security_solution_api_integration/test_suites/detections_response/rules_management/rule_import_export/trial_license_complete_tier/export_rules.ts
- Loading branch information
Showing
15 changed files
with
1,208 additions
and
520 deletions.
There are no files selected for viewing
253 changes: 253 additions & 0 deletions
253
...esting/test_plans/detection_response/prebuilt_rules/installation_and_upgrade.md
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import { CA_CERT_PATH } from '@kbn/dev-utils'; | ||
import { FtrConfigProviderContext, kbnTestConfig, kibanaTestUser } from '@kbn/test'; | ||
import { services } from '../../../api_integration/services'; | ||
import { PRECONFIGURED_ACTION_CONNECTORS } from '../shared'; | ||
|
||
interface CreateTestConfigOptions { | ||
license: string; | ||
|
@@ -83,20 +84,7 @@ export function createTestConfig(options: CreateTestConfigOptions, testFiles?: s | |
'riskScoringRoutesEnabled', | ||
])}`, | ||
'--xpack.task_manager.poll_interval=1000', | ||
`--xpack.actions.preconfigured=${JSON.stringify({ | ||
'my-test-email': { | ||
actionTypeId: '.email', | ||
name: 'TestEmail#xyz', | ||
config: { | ||
from: '[email protected]', | ||
service: '__json', | ||
}, | ||
secrets: { | ||
user: 'user', | ||
password: 'password', | ||
}, | ||
}, | ||
})}`, | ||
`--xpack.actions.preconfigured=${JSON.stringify(PRECONFIGURED_ACTION_CONNECTORS)}`, | ||
...(ssl | ||
? [ | ||
`--elasticsearch.hosts=${servers.elasticsearch.protocol}://${servers.elasticsearch.hostname}:${servers.elasticsearch.port}`, | ||
|
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
32 changes: 32 additions & 0 deletions
32
x-pack/test/security_solution_api_integration/config/shared.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,32 @@ | ||
/* | ||
* 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 { Connector } from '@kbn/actions-plugin/server/application/connector/types'; | ||
|
||
interface PreconfiguredConnector extends Pick<Connector, 'name' | 'actionTypeId' | 'config'> { | ||
secrets: { | ||
user: string; | ||
password: string; | ||
}; | ||
} | ||
|
||
export const PRECONFIGURED_EMAIL_ACTION_CONNECTOR_ID = 'my-test-email'; | ||
|
||
export const PRECONFIGURED_ACTION_CONNECTORS: Record<string, PreconfiguredConnector> = { | ||
[PRECONFIGURED_EMAIL_ACTION_CONNECTOR_ID]: { | ||
actionTypeId: '.email', | ||
name: 'TestEmail#xyz', | ||
config: { | ||
from: '[email protected]', | ||
service: '__json', | ||
}, | ||
secrets: { | ||
user: 'user', | ||
password: 'password', | ||
}, | ||
}, | ||
}; |
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.