From 3c86e60933b4ffc9538e7af1199503de0fc6727c Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 24 Dec 2024 04:21:13 +1100 Subject: [PATCH] [8.17] [Security Solution] Fix prebuilt rules bootstrap endpoint (#205060) (#205100) # Backport This will backport the following commits from `main` to `8.17`: - [[Security Solution] Fix prebuilt rules bootstrap endpoint (#205060)](https://github.com/elastic/kibana/pull/205060) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Georgii Gorbachev --- .../install_prebuilt_rules_package.ts | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/prebuilt_rules/api/install_prebuilt_rules_and_timelines/install_prebuilt_rules_package.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/prebuilt_rules/api/install_prebuilt_rules_and_timelines/install_prebuilt_rules_package.ts index 23bcc654eb780..768a0deeeaa2b 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/prebuilt_rules/api/install_prebuilt_rules_and_timelines/install_prebuilt_rules_package.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/prebuilt_rules/api/install_prebuilt_rules_and_timelines/install_prebuilt_rules_package.ts @@ -22,7 +22,12 @@ export async function installPrebuiltRulesPackage( config: ConfigType, context: SecuritySolutionApiRequestHandlerContext ) { - const pkgVersion = await findLatestPackageVersion(config, context, PREBUILT_RULES_PACKAGE_NAME); + let pkgVersion = config.prebuiltRulesPackageVersion; + + if (!pkgVersion) { + // Find latest package if the version isn't specified in the config + pkgVersion = await findLatestPackageVersion(context, PREBUILT_RULES_PACKAGE_NAME); + } return context .getInternalFleetServices() @@ -33,7 +38,7 @@ export async function installEndpointPackage( config: ConfigType, context: SecuritySolutionApiRequestHandlerContext ) { - const pkgVersion = await findLatestPackageVersion(config, context, ENDPOINT_PACKAGE_NAME); + const pkgVersion = await findLatestPackageVersion(context, ENDPOINT_PACKAGE_NAME); return context.getInternalFleetServices().packages.ensureInstalledPackage({ pkgName: ENDPOINT_PACKAGE_NAME, @@ -42,25 +47,21 @@ export async function installEndpointPackage( } async function findLatestPackageVersion( - config: ConfigType, context: SecuritySolutionApiRequestHandlerContext, packageName: string ) { - let pkgVersion = config.prebuiltRulesPackageVersion; + const securityAppClient = context.getAppClient(); + const packageClient = context.getInternalFleetServices().packages; - // Find latest package if the version isn't specified in the config - if (!pkgVersion) { - const securityAppClient = context.getAppClient(); - // Use prerelease versions in dev environment - const isPrerelease = - securityAppClient.getBuildFlavor() === 'traditional' && - (securityAppClient.getKibanaVersion().includes('-SNAPSHOT') || - securityAppClient.getKibanaBranch() === 'main'); + // Use prerelease versions in dev environment + const isPrerelease = + securityAppClient.getBuildFlavor() === 'traditional' && + (securityAppClient.getKibanaVersion().includes('-SNAPSHOT') || + securityAppClient.getKibanaBranch() === 'main'); - const result = await context - .getInternalFleetServices() - .packages.fetchFindLatestPackage(packageName, { prerelease: isPrerelease }); - pkgVersion = result.version; - } - return pkgVersion; + const result = await packageClient.fetchFindLatestPackage(packageName, { + prerelease: isPrerelease, + }); + + return result.version; }