Skip to content

Commit a650b02

Browse files
trautMikaayenson
andauthored
Bumping number of versions per rule to 4 in total (#4451)
* Bumping number of versions per rule to 4 in total * Add explicit caps * Simpler comment * Renaming constants * Drop to 8.17 again * Clearer constants * Drop if condition and extend the comment * Shorten the lines * Version bump --------- Co-authored-by: Mika Ayenson <[email protected]>
1 parent 27e8b85 commit a650b02

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

detection_rules/devtools.py

+18-10
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,13 @@
6363
f'[![ATT&CK navigator coverage](https://img.shields.io/badge/ATT&CK-Navigator-red.svg)]({NAVIGATOR_URL})'
6464
)
6565
RULES_CONFIG = parse_rules_config()
66-
# The base package version that we will start to include all versions of historical rules
67-
BASE_PKG_VERSION = Version(major=8, minor=17, patch=0)
66+
67+
# The rule diff feature is available in 8.18 but needs to be tested in pre-release versions
68+
MIN_DIFF_FEATURE_VERSION = Version(major=8, minor=17, patch=0)
69+
70+
# The caps for the historical versions of the rules
71+
MAX_HISTORICAL_VERSIONS_FOR_DIFF = 3
72+
MAX_HISTORICAL_VERSIONS_PRE_DIFF = 1
6873

6974

7075
def get_github_token() -> Optional[str]:
@@ -131,14 +136,17 @@ def build_release(ctx: click.Context, config_file, update_version_lock: bool, ge
131136
# Version 8.17.0-beta.1 is considered lower than 8.17.0
132137
current_pkg_version_no_prerelease = Version(major=current_pkg_version.major,
133138
minor=current_pkg_version.minor, patch=current_pkg_version.patch)
134-
if current_pkg_version_no_prerelease >= BASE_PKG_VERSION:
135-
click.echo(f'[+] Adding all historical rule versions in our release package for version \
136-
{current_pkg_version_no_prerelease}')
137-
limited_historical_rules = historical_rules
138-
else:
139-
click.echo(f'[+] Limit historical rule versions in our release package for version \
140-
{current_pkg_version_no_prerelease}')
141-
limited_historical_rules = sde.keep_latest_versions(historical_rules)
139+
140+
hist_versions_num = (
141+
MAX_HISTORICAL_VERSIONS_FOR_DIFF
142+
if current_pkg_version_no_prerelease >= MIN_DIFF_FEATURE_VERSION
143+
else MAX_HISTORICAL_VERSIONS_PRE_DIFF
144+
)
145+
click.echo(
146+
'[+] Limit historical rule versions in the release package for '
147+
f'version {current_pkg_version_no_prerelease}: {hist_versions_num} versions')
148+
limited_historical_rules = sde.keep_latest_versions(historical_rules, num_versions=hist_versions_num)
149+
142150
package.add_historical_rules(limited_historical_rules, registry_data['version'])
143151
click.echo(f'[+] Adding historical rules from {previous_pkg_version} package')
144152

detection_rules/integrations.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from .schemas import definitions
2727

2828
MANIFEST_FILE_PATH = get_etc_path('integration-manifests.json.gz')
29-
NUM_LATEST_RULE_VERSIONS = 1
29+
DEFAULT_MAX_RULE_VERSIONS = 1
3030
SCHEMA_FILE_PATH = get_etc_path('integration-schemas.json.gz')
3131
_notified_integrations = set()
3232

@@ -417,7 +417,7 @@ def load_integration_assets(self, package_version: Version) -> dict:
417417
for x in asset_file_names}
418418
return assets
419419

420-
def keep_latest_versions(self, assets: dict, num_versions: int = NUM_LATEST_RULE_VERSIONS) -> dict:
420+
def keep_latest_versions(self, assets: dict, num_versions: int = DEFAULT_MAX_RULE_VERSIONS) -> dict:
421421
"""Keeps only the latest N versions of each rule to limit historical rule versions in our release package."""
422422

423423
# Dictionary to hold the sorted list of versions for each base rule ID

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "detection_rules"
3-
version = "0.4.8"
3+
version = "0.4.9"
44
description = "Detection Rules is the home for rules used by Elastic Security. This repository is used for the development, maintenance, testing, validation, and release of rules for Elastic Security’s Detection Engine."
55
readme = "README.md"
66
requires-python = ">=3.12"

0 commit comments

Comments
 (0)