From d3c05a08ccd940dec1e1cf027e85bddbffc56829 Mon Sep 17 00:00:00 2001 From: shashank-elastic <91139415+shashank-elastic@users.noreply.github.com> Date: Tue, 3 Dec 2024 23:36:32 +0530 Subject: [PATCH] Add all historical versions for v8.17.0 and above packages (#4279) --- detection_rules/devtools.py | 16 +++++++++++++++- pyproject.toml | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/detection_rules/devtools.py b/detection_rules/devtools.py index 0df0fe10c..69377a884 100644 --- a/detection_rules/devtools.py +++ b/detection_rules/devtools.py @@ -63,6 +63,8 @@ NAVIGATOR_BADGE = ( f'[![ATT&CK navigator coverage](https://img.shields.io/badge/ATT&CK-Navigator-red.svg)]({NAVIGATOR_URL})' ) RULES_CONFIG = parse_rules_config() +# The base package version that we will start to include all versions of historical rules +BASE_PKG_VERSION = Version(major=8, minor=17, patch=0) def get_github_token() -> Optional[str]: @@ -124,7 +126,19 @@ def build_release(ctx: click.Context, config_file, update_version_lock: bool, ge registry_data['conditions']['kibana.version'].strip("^")) sde = SecurityDetectionEngine() historical_rules = sde.load_integration_assets(previous_pkg_version) - limited_historical_rules = sde.keep_latest_versions(historical_rules) + current_pkg_version = Version.parse(registry_data['version']) + # pre-release versions are not included in the version comparison + # Version 8.17.0-beta.1 is considered lower than 8.17.0 + current_pkg_version_no_prerelease = Version(major=current_pkg_version.major, + minor=current_pkg_version.minor, patch=current_pkg_version.patch) + if current_pkg_version_no_prerelease >= BASE_PKG_VERSION: + click.echo(f'[+] Adding all historical rule versions in our release package for version \ + {current_pkg_version_no_prerelease}') + limited_historical_rules = historical_rules + else: + click.echo(f'[+] Limit historical rule versions in our release package for version \ + {current_pkg_version_no_prerelease}') + limited_historical_rules = sde.keep_latest_versions(historical_rules) package.add_historical_rules(limited_historical_rules, registry_data['version']) click.echo(f'[+] Adding historical rules from {previous_pkg_version} package') diff --git a/pyproject.toml b/pyproject.toml index 6e8a158f2..ad459c11c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "detection_rules" -version = "0.2.1" +version = "0.3.0" 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." readme = "README.md" requires-python = ">=3.12"