Skip to content

Commit

Permalink
[Security Solution] Fix prebuilt rules bootstrap endpoint (#205060)
Browse files Browse the repository at this point in the history
**Fixes: #203471

## Summary

The `xpack.securitySolution.prebuiltRulesPackageVersion` config setting
now only affects the version of the prebuilt rules package. The
bootstrap endpoint always installs the latest version of the `endpoint`
package.

```yaml
xpack.securitySolution.prebuiltRulesPackageVersion: 8.16.2-beta.1
```

<img width="2557" alt="Screenshot_2024-12-20_at_20_58_53"
src="https://github.com/user-attachments/assets/a2a1eaad-e842-47d3-9b94-692aabfb97cc"
/>


### Checklist

- [ ] [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
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
  • Loading branch information
banderror authored Dec 23, 2024
1 parent 19f24b3 commit de1064e
Showing 1 changed file with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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,
Expand All @@ -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;
}

0 comments on commit de1064e

Please sign in to comment.