-
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.
[8.17] [Security Solution] Unlock Prebuil Rules Customization workflo…
…w for rules with missing base version (#201301) (#201656) # Backport This will backport the following commits from `main` to `8.17`: - [[Security Solution] Unlock Prebuil Rules Customization workflow for rules with missing base version (#201301)](#201301) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Maxim Palenov","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-25T17:12:35Z","message":"[Security Solution] Unlock Prebuil Rules Customization workflow for rules with missing base version (#201301)\n\n**Resolves: https://github.com/elastic/kibana/issues/200904**\r\n\r\n## Summary\r\n\r\nThis PR unlocks Prebuilt Rules Customization workflow for rules with missing base version.\r\n\r\n## Details\r\n\r\nEach Prebuilt Rule update contains `version` diff. `version` is a special non-customizable field we use to track prebuilt rule version. It always gets target rule version's value after rule upgrade.\r\n\r\nA generic `numberDiffAlgorithm` algorithm was used for `version` field. It produces a `SOLVABLE` conflict when rule's base version is missing. It blocked the workflow in UI. We check the number of field with conflicts versus resolved conflicts to decide when a rule is ready for upgrade. In case `version` field got a conflict user had no possibility to resolve it.\r\n\r\nThe fix adds a new `forceTargetVersionDiffAlgorithm` diff algorithm applied only for `version` field. It produces a non-conflict diff all the time even when base version is missing. The reason behind is that `version` always gets target rule's version.","sha":"dea9312246554c6af0ce148e2ec967bb5f9cca8a","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","impact:high","v9.0.0","Team:Detections and Resp","Team: SecuritySolution","Team:Detection Rule Management","Feature:Prebuilt Detection Rules","backport:version","v8.17.0","v8.18.0","v8.16.2"],"title":"[Security Solution] Unlock Prebuil Rules Customization workflow for rules with missing base version","number":201301,"url":"https://github.com/elastic/kibana/pull/201301","mergeCommit":{"message":"[Security Solution] Unlock Prebuil Rules Customization workflow for rules with missing base version (#201301)\n\n**Resolves: https://github.com/elastic/kibana/issues/200904**\r\n\r\n## Summary\r\n\r\nThis PR unlocks Prebuilt Rules Customization workflow for rules with missing base version.\r\n\r\n## Details\r\n\r\nEach Prebuilt Rule update contains `version` diff. `version` is a special non-customizable field we use to track prebuilt rule version. It always gets target rule version's value after rule upgrade.\r\n\r\nA generic `numberDiffAlgorithm` algorithm was used for `version` field. It produces a `SOLVABLE` conflict when rule's base version is missing. It blocked the workflow in UI. We check the number of field with conflicts versus resolved conflicts to decide when a rule is ready for upgrade. In case `version` field got a conflict user had no possibility to resolve it.\r\n\r\nThe fix adds a new `forceTargetVersionDiffAlgorithm` diff algorithm applied only for `version` field. It produces a non-conflict diff all the time even when base version is missing. The reason behind is that `version` always gets target rule's version.","sha":"dea9312246554c6af0ce148e2ec967bb5f9cca8a"}},"sourceBranch":"main","suggestedTargetBranches":["8.17","8.x","8.16"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/201301","number":201301,"mergeCommit":{"message":"[Security Solution] Unlock Prebuil Rules Customization workflow for rules with missing base version (#201301)\n\n**Resolves: https://github.com/elastic/kibana/issues/200904**\r\n\r\n## Summary\r\n\r\nThis PR unlocks Prebuilt Rules Customization workflow for rules with missing base version.\r\n\r\n## Details\r\n\r\nEach Prebuilt Rule update contains `version` diff. `version` is a special non-customizable field we use to track prebuilt rule version. It always gets target rule version's value after rule upgrade.\r\n\r\nA generic `numberDiffAlgorithm` algorithm was used for `version` field. It produces a `SOLVABLE` conflict when rule's base version is missing. It blocked the workflow in UI. We check the number of field with conflicts versus resolved conflicts to decide when a rule is ready for upgrade. In case `version` field got a conflict user had no possibility to resolve it.\r\n\r\nThe fix adds a new `forceTargetVersionDiffAlgorithm` diff algorithm applied only for `version` field. It produces a non-conflict diff all the time even when base version is missing. The reason behind is that `version` always gets target rule's version.","sha":"dea9312246554c6af0ce148e2ec967bb5f9cca8a"}},{"branch":"8.17","label":"v8.17.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.16","label":"v8.16.2","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Maxim Palenov <[email protected]>
- Loading branch information
1 parent
ab3a380
commit d6c3ada
Showing
13 changed files
with
156 additions
and
27 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
...built_rules/logic/diff/calculation/algorithms/force_target_version_diff_algorithm.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,78 @@ | ||
/* | ||
* 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 { ThreeVersionsOf } from '../../../../../../../../common/api/detection_engine'; | ||
import { | ||
ThreeWayMergeOutcome, | ||
MissingVersion, | ||
ThreeWayDiffConflict, | ||
} from '../../../../../../../../common/api/detection_engine'; | ||
import { forceTargetVersionDiffAlgorithm } from './force_target_version_diff_algorithm'; | ||
|
||
describe('forceTargetVersionDiffAlgorithm', () => { | ||
describe('when base version exists', () => { | ||
it('returns a NON conflict diff', () => { | ||
const mockVersions: ThreeVersionsOf<number> = { | ||
base_version: 1, | ||
current_version: 1, | ||
target_version: 2, | ||
}; | ||
|
||
const result = forceTargetVersionDiffAlgorithm(mockVersions); | ||
|
||
expect(result).toMatchObject({ | ||
conflict: ThreeWayDiffConflict.NONE, | ||
}); | ||
}); | ||
|
||
it('return merge outcome TARGET', () => { | ||
const mockVersions: ThreeVersionsOf<number> = { | ||
base_version: 1, | ||
current_version: 1, | ||
target_version: 2, | ||
}; | ||
|
||
const result = forceTargetVersionDiffAlgorithm(mockVersions); | ||
|
||
expect(result).toMatchObject({ | ||
has_base_version: true, | ||
merge_outcome: ThreeWayMergeOutcome.Target, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when base version missing', () => { | ||
it('returns a NON conflict diff', () => { | ||
const mockVersions: ThreeVersionsOf<number> = { | ||
base_version: MissingVersion, | ||
current_version: 1, | ||
target_version: 2, | ||
}; | ||
|
||
const result = forceTargetVersionDiffAlgorithm(mockVersions); | ||
|
||
expect(result).toMatchObject({ | ||
conflict: ThreeWayDiffConflict.NONE, | ||
}); | ||
}); | ||
|
||
it('return merge outcome TARGET', () => { | ||
const mockVersions: ThreeVersionsOf<number> = { | ||
base_version: MissingVersion, | ||
current_version: 1, | ||
target_version: 2, | ||
}; | ||
|
||
const result = forceTargetVersionDiffAlgorithm(mockVersions); | ||
|
||
expect(result).toMatchObject({ | ||
has_base_version: false, | ||
merge_outcome: ThreeWayMergeOutcome.Target, | ||
}); | ||
}); | ||
}); | ||
}); |
45 changes: 45 additions & 0 deletions
45
...e/prebuilt_rules/logic/diff/calculation/algorithms/force_target_version_diff_algorithm.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,45 @@ | ||
/* | ||
* 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 { | ||
ThreeVersionsOf, | ||
ThreeWayDiff, | ||
} from '../../../../../../../../common/api/detection_engine/prebuilt_rules'; | ||
import { | ||
MissingVersion, | ||
ThreeWayDiffConflict, | ||
ThreeWayMergeOutcome, | ||
determineDiffOutcome, | ||
} from '../../../../../../../../common/api/detection_engine/prebuilt_rules'; | ||
|
||
/** | ||
* Diff algorithm forcing target version. Useful for special fields like `version`. | ||
*/ | ||
export const forceTargetVersionDiffAlgorithm = <TValue>( | ||
versions: ThreeVersionsOf<TValue> | ||
): ThreeWayDiff<TValue> => { | ||
const { | ||
base_version: baseVersion, | ||
current_version: currentVersion, | ||
target_version: targetVersion, | ||
} = versions; | ||
const hasBaseVersion = baseVersion !== MissingVersion; | ||
const hasUpdate = targetVersion !== currentVersion; | ||
|
||
return { | ||
has_base_version: hasBaseVersion, | ||
base_version: hasBaseVersion ? baseVersion : undefined, | ||
current_version: currentVersion, | ||
target_version: targetVersion, | ||
merged_version: targetVersion, | ||
merge_outcome: ThreeWayMergeOutcome.Target, | ||
|
||
diff_outcome: determineDiffOutcome(baseVersion, currentVersion, targetVersion), | ||
has_update: hasUpdate, | ||
conflict: ThreeWayDiffConflict.NONE, | ||
}; | ||
}; |
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
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
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