Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security Solution] Add support for Fleet packages with historical rule versions #148643

Merged
merged 1 commit into from
Jan 17, 2023

Conversation

xcrzx
Copy link
Contributor

@xcrzx xcrzx commented Jan 10, 2023

Resolves: #148179

Summary

As a result of this PoC flat package structure was chosen for storing historical detection rules, and this PR adds support for Fleet packages containing multiple historical versions per rule.

Updated API endpoints:

  • Install prepackaged rules (PUT /api/detection_engine/rules/prepackaged)
  • Get prepackaged rules status (GET /api/detection_engine/rules/prepackaged/_status)

The API endpoints can work interchangeably with the current historical rules package structure and the new "flat" structure. Therefore, the API interface has not been changed, and the existing security-rule saved objects are still used.

How to test this PR

To test this PR, you should create a new security_detection_engine package version. See the documentation on how to spin up a local package registry with custom packages.

The package should contain rule saved objects with rule id and version in the name (security_rule/[ruleId]:[ruleVersion].json) with the following content:

{
  "id": "[ruleId]:[ruleVersion]",
  "type": "security-rule",
  "attributes": {
    // Rule attributes
  }
}

You should be able to upgrade the current rules package to the new "flat" and vice-versa.

@xcrzx xcrzx added release_note:skip Skip the PR/issue when compiling release notes Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:Detection Rule Management Security Detection Rule Management Team Feature:Prebuilt Detection Rules Security Solution Prebuilt Detection Rules area v8.7.0 labels Jan 10, 2023
@xcrzx xcrzx self-assigned this Jan 10, 2023
@xcrzx xcrzx changed the title [Security Solution] Add support for a Fleet package with historical rule versions [Security Solution] Add support for Fleet packages with historical rule versions Jan 10, 2023
@xcrzx xcrzx force-pushed the historical-rules-package-support branch 2 times, most recently from eff1969 to 3a42c61 Compare January 11, 2023 13:14
@xcrzx xcrzx marked this pull request as ready for review January 11, 2023 13:38
@xcrzx xcrzx requested review from a team as code owners January 11, 2023 13:38
@xcrzx xcrzx requested a review from banderror January 11, 2023 13:38
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-detections-response (Team:Detections and Resp)

@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

@xcrzx xcrzx force-pushed the historical-rules-package-support branch from 3a42c61 to 56be187 Compare January 13, 2023 14:02
@xcrzx xcrzx removed the request for review from a team January 13, 2023 14:02
@xcrzx xcrzx force-pushed the historical-rules-package-support branch 2 times, most recently from 460ed60 to 65ca509 Compare January 17, 2023 12:51
Copy link
Contributor

@banderror banderror left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Tested locally and reviewed the code.

While testing using the provided instructions, I was able to

  • Build a package with a few historical versions of a selected rule. Run Kibana looking at a local package registry containing this package.
  • Install prebuilt rules from scratch and verify that the latest version out of 3 historical ones gets installed.
  • Install prebuilt rules from a package without historical versions; then upgrade the package; then upgrade the rules and verify that the latest version out of 3 historical ones gets installed.

So both the installation and upgrade workflows work fine.

NOTE: While zooming with @xcrzx, we found a bug in Fleet where, if there's a release package in the package registry + a prerelease package that has a higher version, our calls we do from the UI to install or upgrade the package, will fail. This seems to be a bug we will have in prod in 8.6 once the TRADE team releases a new prerelease package compatible with 8.6. @xcrzx will open a bug for that.

Other than that, thank you for this PR @xcrzx! It's great to see that it was so easy to add this support, flat data model FTW 🙂 I left just a few nits.

options?: Omit<SavedObjectsFindOptions, 'type'>
) => Promise<SavedObjectsFindResponse<IRuleAssetSavedObject>>;
all: () => Promise<IRuleAssetSavedObject[]>;
export interface RuleAssetsClient {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Let's rename it to IRuleAssetsClient. The idea is to start an interface with I for objects with behavior, and have interfaces without I for data. This allows using classes that implement interfaces if needed (yes I remember you don't like classes!).

export class RuleAssetsClient implements IRuleAssetsClient, IAnotherInterface { ... }

Otherwise, it would be Java 😂

export class RuleAssetsClientImpl implements RuleAssetsClient, AnotherInterface { ... }

const finder = savedObjectsClient.createPointInTimeFinder({
perPage: DEFAULT_PAGE_SIZE,
type: ruleAssetSavedObjectType,
fetchLatestVersions: () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally, a real abstraction! 👍

Comment on lines +41 to +45
{
rules: AggregationsMultiBucketAggregateBase<{
latest_version: AggregationsTopHitsAggregate;
}>;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know that it's possible to type aggregations for the find method using some built-in types. Very useful!

@xcrzx
Copy link
Contributor Author

xcrzx commented Jan 17, 2023

NOTE: While zooming with @xcrzx, we found a bug in Fleet where, if there's a release package in the package registry + a prerelease package that has a higher version, our calls we do from the UI to install or upgrade the package, will fail. This seems to be a bug we will have in prod in 8.6 once the TRADE team releases a new prerelease package compatible with 8.6. @xcrzx will open a bug for that.

Here's the issue

@xcrzx xcrzx force-pushed the historical-rules-package-support branch from 65ca509 to 85a05b4 Compare January 17, 2023 17:22
@xcrzx xcrzx enabled auto-merge (squash) January 17, 2023 17:23
@xcrzx xcrzx merged commit 3d843e2 into elastic:main Jan 17, 2023
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Unknown metric groups

ESLint disabled line counts

id before after diff
securitySolution 433 432 -1

Total ESLint disabled count

id before after diff
securitySolution 508 507 -1

History

  • 💚 Build #100690 succeeded 65ca509ada42c9bba8827a42d48001f1f60491b2
  • 💛 Build #100409 was flaky 460ed60c91a19d316b2dd3022965be48e1e15ca9
  • 💔 Build #100147 failed 56be1878f530cfebe2666584642e84f29c532485
  • 💚 Build #99515 succeeded 3a42c61c25a28e13fbf22305cd2b2e802364c739
  • 💔 Build #99482 failed eff19694dd501e0af812d45064f6d4acb03d9874
  • 💔 Build #99203 failed e3b64f12ebb9dc979af13a1f535d833581b516aa

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @xcrzx

@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Jan 17, 2023
@xcrzx xcrzx deleted the historical-rules-package-support branch January 18, 2023 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Prebuilt Detection Rules Security Solution Prebuilt Detection Rules area release_note:skip Skip the PR/issue when compiling release notes Team:Detection Rule Management Security Detection Rule Management Team Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v8.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Security Solution] Add support for Fleet package with historical versions of prebuilt rules
5 participants