Skip to content

Commit

Permalink
[8.17] [Security Solution] Fix prebuilt rules bootstrap endpoint (#20…
Browse files Browse the repository at this point in the history
…5060) (#205100)

# Backport

This will backport the following commits from `main` to `8.17`:
- [[Security Solution] Fix prebuilt rules bootstrap endpoint
(#205060)](#205060)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Georgii
Gorbachev","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-23T15:27:46Z","message":"[Security
Solution] Fix prebuilt rules bootstrap endpoint (#205060)\n\n**Fixes:
https://github.com/elastic/kibana/issues/203471**\r\n\r\n##
Summary\r\n\r\nThe `xpack.securitySolution.prebuiltRulesPackageVersion`
config setting\r\nnow only affects the version of the prebuilt rules
package. The\r\nbootstrap endpoint always installs the latest version of
the
`endpoint`\r\npackage.\r\n\r\n```yaml\r\nxpack.securitySolution.prebuiltRulesPackageVersion:
8.16.2-beta.1\r\n```\r\n\r\n<img width=\"2557\"
alt=\"Screenshot_2024-12-20_at_20_58_53\"\r\nsrc=\"https://github.com/user-attachments/assets/a2a1eaad-e842-47d3-9b94-692aabfb97cc\"\r\n/>\r\n\r\n\r\n###
Checklist\r\n\r\n- [ ] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests
changed","sha":"de1064e10363203fbf58ff9c479d40c0cb5b2c23","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","impact:low","v9.0.0","Team:Detections
and Resp","Team: SecuritySolution","Team:Detection Rule
Management","Feature:Prebuilt Detection
Rules","backport:version","v8.18.0","v8.16.3","v8.17.1"],"title":"[Security
Solution] Fix prebuilt rules bootstrap
endpoint","number":205060,"url":"https://github.com/elastic/kibana/pull/205060","mergeCommit":{"message":"[Security
Solution] Fix prebuilt rules bootstrap endpoint (#205060)\n\n**Fixes:
https://github.com/elastic/kibana/issues/203471**\r\n\r\n##
Summary\r\n\r\nThe `xpack.securitySolution.prebuiltRulesPackageVersion`
config setting\r\nnow only affects the version of the prebuilt rules
package. The\r\nbootstrap endpoint always installs the latest version of
the
`endpoint`\r\npackage.\r\n\r\n```yaml\r\nxpack.securitySolution.prebuiltRulesPackageVersion:
8.16.2-beta.1\r\n```\r\n\r\n<img width=\"2557\"
alt=\"Screenshot_2024-12-20_at_20_58_53\"\r\nsrc=\"https://github.com/user-attachments/assets/a2a1eaad-e842-47d3-9b94-692aabfb97cc\"\r\n/>\r\n\r\n\r\n###
Checklist\r\n\r\n- [ ] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests
changed","sha":"de1064e10363203fbf58ff9c479d40c0cb5b2c23"}},"sourceBranch":"main","suggestedTargetBranches":["8.x","8.16","8.17"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/205060","number":205060,"mergeCommit":{"message":"[Security
Solution] Fix prebuilt rules bootstrap endpoint (#205060)\n\n**Fixes:
https://github.com/elastic/kibana/issues/203471**\r\n\r\n##
Summary\r\n\r\nThe `xpack.securitySolution.prebuiltRulesPackageVersion`
config setting\r\nnow only affects the version of the prebuilt rules
package. The\r\nbootstrap endpoint always installs the latest version of
the
`endpoint`\r\npackage.\r\n\r\n```yaml\r\nxpack.securitySolution.prebuiltRulesPackageVersion:
8.16.2-beta.1\r\n```\r\n\r\n<img width=\"2557\"
alt=\"Screenshot_2024-12-20_at_20_58_53\"\r\nsrc=\"https://github.com/user-attachments/assets/a2a1eaad-e842-47d3-9b94-692aabfb97cc\"\r\n/>\r\n\r\n\r\n###
Checklist\r\n\r\n- [ ] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests
changed","sha":"de1064e10363203fbf58ff9c479d40c0cb5b2c23"}},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.16","label":"v8.16.3","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.17","label":"v8.17.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Georgii Gorbachev <[email protected]>
  • Loading branch information
kibanamachine and banderror authored Dec 23, 2024
1 parent 6d9d1a8 commit 3c86e60
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 3c86e60

Please sign in to comment.