Skip to content

[RAM] Adds Bulk Edit API to rulesClient#126904

Merged
vitaliidm merged 141 commits intoelastic:mainfrom
vitaliidm:security-solution/bulk-update-rulesClient
May 11, 2022
Merged

[RAM] Adds Bulk Edit API to rulesClient#126904
vitaliidm merged 141 commits intoelastic:mainfrom
vitaliidm:security-solution/bulk-update-rulesClient

Conversation

@vitaliidm
Copy link
Copy Markdown
Contributor

@vitaliidm vitaliidm commented Mar 4, 2022

Addresses

Summary

  • adds bulkEdit method to rulesClient
  • adds multi_terms bucket aggregations to savedObjectClient
  • adds createPointInTimeFinderAsInternalUser to encryptedSavedObjectClient
  • adds alerting API for bulkEdit
curl --location --request POST 'http://localhost:5601/kbn/internal/alerting/rules/_bulk_edit' \
--header 'kbn-xsrf: reporting' \
--header 'Authorization: Basic ZWxhc3RpYzpjaGFuZ2VtZQ==' \
--header 'Content-Type: application/json' \
--data-raw '{
    "ids": ["4cb80374-b5c7-11ec-8f1e-adaa7d7d57e5"],
    "operations":  [{
        "operation": "add",
        "field": "tags",
        "value": ["foo"]
    }]
}'

Checklist

Delete any items that are not applicable to this PR.

Release note

Adds new bulkEdit method to alerting rulesClient and internal _bulk_edit API, that allow bulk editing of rules.

@vitaliidm
Copy link
Copy Markdown
Contributor Author

@elasticmachine merge upstream

vitaliidm and others added 5 commits April 26, 2022 14:43
…dex.ts

Co-authored-by: Aleh Zasypkin <aleh.zasypkin@gmail.com>
…dex.ts

Co-authored-by: Aleh Zasypkin <aleh.zasypkin@gmail.com>
…ypted_saved_objects_api.ts

Co-authored-by: Aleh Zasypkin <aleh.zasypkin@gmail.com>
…dex.ts

Co-authored-by: Aleh Zasypkin <aleh.zasypkin@gmail.com>
async ({ key: [ruleType, consumer] }) => {
this.ruleTypeRegistry.ensureRuleTypeEnabled(ruleType);

await this.authorization.ensureAuthorized({
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We audit these attempts on individual update. Should we also be auditing this action?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Thank you, I've added audit of the error

// validate schedule interval
if (attributes.schedule.interval) {
const intervalInMs = parseDuration(attributes.schedule.interval as string);
if (intervalInMs < this.minimumScheduleIntervalInMs) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We've updated this logic to add an enforce option, so we throw if enforce = true and log a warning if it's false

if (intervalInMs < this.minimumScheduleIntervalInMs && this.minimumScheduleInterval.enforce) {
      throw Boom.badRequest(
        `Error creating rule: the interval is less than the allowed minimum interval of ${this.minimumScheduleInterval.value}`
      );
}
if (intervalInMs < this.minimumScheduleIntervalInMs && !this.minimumScheduleInterval.enforce) {
      this.logger.warn(
        `Rule schedule interval (${data.schedule.interval}) for "${createdAlert.attributes.alertTypeId}" rule type with ID "${createdAlert.id}" is less than the minimum value (${this.minimumScheduleInterval.value}). Running rules at this interval may impact alerting performance. Set "xpack.alerting.rules.minimumScheduleInterval.enforce" to true to prevent creation of these rules.`
      );
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks for letting know about recent changes in interval validation. I've updated it

Copy link
Copy Markdown
Contributor

@mikecote mikecote left a comment

Choose a reason for hiding this comment

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

Looking good! I finished my first pass to get this PR reviewed. I'll review tests, pull down, etc next time but wanted to get my questions / some feedback out first.

@vitaliidm
Copy link
Copy Markdown
Contributor Author

@elasticmachine merge upstream

Copy link
Copy Markdown
Contributor

@mikecote mikecote left a comment

Choose a reason for hiding this comment

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

Tested locally, changes LGTM!

@vitaliidm
Copy link
Copy Markdown
Contributor Author

Tested locally, changes LGTM!

Thanks, @mikecote
One question from me: I've revisited a bit logic for API keys invalidation

  1. To invalidate newly generated API key even if bulkUpdate operation fails
  2. Not to invalidate old key, if rule wasn't updated due to conflict for example

Here is a commit. Please let me know if it makes sense.
0a34da4

@mikecote
Copy link
Copy Markdown
Contributor

Tested locally, changes LGTM!

Thanks, @mikecote
One question from me: I've revisited a bit logic for API keys invalidation

  1. To invalidate newly generated API key even if bulkUpdate operation fails
  2. Not to invalidate old key, if rule wasn't updated due to conflict for example

Here is a commit. Please let me know if it makes sense.
0a34da4

Yup the change makes sense and looks good 👍 , thanks!

Copy link
Copy Markdown
Contributor

@ymao1 ymao1 left a comment

Choose a reason for hiding this comment

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

LGTM!

@vitaliidm vitaliidm enabled auto-merge (squash) May 11, 2022 17:31
@kibana-ci
Copy link
Copy Markdown

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
alerting 317 330 +13
Unknown metric groups

API count

id before after diff
alerting 326 339 +13
encryptedSavedObjects 48 51 +3
total +16

History

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

cc @vitaliidm

@vitaliidm vitaliidm merged commit e3c47ec into elastic:main May 11, 2022
@vitaliidm vitaliidm deleted the security-solution/bulk-update-rulesClient branch March 4, 2024 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting Feature:Alerting/RulesManagement Issues related to the Rules Management UX release_note:feature Makes this part of the condensed release notes Team:ResponseOps Platform ResponseOps team (formerly the Cases and Alerting teams) t// v8.3.0

Projects

No open projects

Development

Successfully merging this pull request may close these issues.