Commit 67de5ef
[Alerting] Allow alert tags to be modified in bulk (#241883)
Closes #240356
Replaces [this PR](#241051)
## Summary
This pull request introduces a new API route and supporting backend
logic for bulk updating tags on alerts in the rule registry. The main
changes include the addition of a `patchTags` method to the
`AlertsClient`, a new route for bulk patching alert tags, and reusable
scripts for tag updates. These improvements make it possible to
add/remove or replace tags on multiple alerts efficiently, either by IDs
or by query.
### Alerting authorization
The `AlertingAuthorization` class changed to support bulk authorized
multiple rule type IDs and consumers. The `ensureAuthorized` was renamed
to `_ensureAuthorized` and accepts `Array<{ ruleTypeId: string;
consumers: string[] }>;`. The logic is the same as before, but it
constructs all security actions based on the input. This is needed to
avoid having to do one authorization call per `(ruleTypeId, consumer)`
pair. Lastly, a `bulkEnsureAuthorized` is exposed which is a wrapper of
the private `_ensureAuthorized`.
### Alerts client
The code in the `AlertsClient` is pretty outdated. For this reason, I
decided not to use the existing functionality and code from scratch. The
`bulkUpdateTags` is introduced, and it bulk updates the tags of multiple
alerts either by using `alertIds` or by using a KQL `query`. In the
first scenario, an aggregation is made to get the rule type ID and the
consumer of each alert. Then we bulk authorize. If the user has access,
we move forward and update the tags of the alerts. If not, we throw an
error. For the `query` scenario, we apply the authorization filter along
with the `query` to filter out the alerts that the user does not have
access to. Lastly, we audit log only once for the whole bulk operation
and not for each alert found.
### API and Backend Enhancements
* Added a new API route `POST /internal/rac/alerts/tags` for bulk
updating alert tags, supporting add, remove, and replace operations,
with validation and error handling.
[[1]](diffhunk://#diff-00a4668b8046bb9c2d423b91818e04ee9532682eecf426e5a80bce35276b0bd8R1-R113)
[[2]](diffhunk://#diff-0abcdbe7de6b3dc00d522a6673ff7bcd99d0f4bf2d6002c59d475e85747d0970R19-R26)
* Implemented the `bulkUpdateTags` method in `AlertsClient`, enabling
tag updates on alerts by IDs or query, using Elasticsearch scripts for
efficient bulk operations.
### Reusable Update Scripts
* Added reusable Painless scripts for adding, removing, and replacing
alert tags, exported from `alert_client_bulk_update_scripts.ts` and
integrated into the client logic.
[[1]](diffhunk://#diff-7c530f4d6aa0a6b9f0ca63714468130690bc5fa7e33a91591849318c1f380f7dR1-R34)
[[2]](diffhunk://#diff-bbccd80f85af0d00f6eafdbc9e444164e6fee357697dc7be42e978fd376a357cR74-R78)
---------
Co-authored-by: Elastic Machine <[email protected]>
Co-authored-by: Christos Nasikas <[email protected]>
Co-authored-by: kibanamachine <[email protected]>1 parent b4553b6 commit 67de5ef
File tree
26 files changed
+1810
-55
lines changed- x-pack/platform
- test
- fixtures/es_archives/rule_registry/alerts
- rule_registry
- common/lib/helpers
- security_and_spaces/tests/basic
26 files changed
+1810
-55
lines changedLines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
Lines changed: 100 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
439 | 439 | | |
440 | 440 | | |
441 | 441 | | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
442 | 446 | | |
443 | 447 | | |
444 | 448 | | |
445 | 449 | | |
446 | 450 | | |
447 | 451 | | |
448 | 452 | | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
449 | 489 | | |
450 | 490 | | |
451 | 491 | | |
| |||
455 | 495 | | |
456 | 496 | | |
457 | 497 | | |
458 | | - | |
459 | | - | |
460 | | - | |
| 498 | + | |
| 499 | + | |
461 | 500 | | |
462 | 501 | | |
463 | 502 | | |
| |||
477 | 516 | | |
478 | 517 | | |
479 | 518 | | |
480 | | - | |
481 | | - | |
482 | | - | |
| 519 | + | |
| 520 | + | |
483 | 521 | | |
484 | 522 | | |
485 | 523 | | |
| |||
497 | 535 | | |
498 | 536 | | |
499 | 537 | | |
500 | | - | |
501 | | - | |
502 | | - | |
| 538 | + | |
| 539 | + | |
503 | 540 | | |
504 | 541 | | |
505 | 542 | | |
| |||
516 | 553 | | |
517 | 554 | | |
518 | 555 | | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
519 | 594 | | |
520 | 595 | | |
521 | 596 | | |
| |||
531 | 606 | | |
532 | 607 | | |
533 | 608 | | |
534 | | - | |
535 | | - | |
536 | | - | |
| 609 | + | |
| 610 | + | |
537 | 611 | | |
538 | 612 | | |
539 | 613 | | |
| |||
557 | 631 | | |
558 | 632 | | |
559 | 633 | | |
560 | | - | |
561 | | - | |
562 | | - | |
| 634 | + | |
| 635 | + | |
563 | 636 | | |
564 | 637 | | |
565 | 638 | | |
| |||
579 | 652 | | |
580 | 653 | | |
581 | 654 | | |
582 | | - | |
583 | | - | |
584 | | - | |
| 655 | + | |
| 656 | + | |
585 | 657 | | |
586 | 658 | | |
587 | 659 | | |
| |||
600 | 672 | | |
601 | 673 | | |
602 | 674 | | |
603 | | - | |
604 | | - | |
605 | | - | |
| 675 | + | |
| 676 | + | |
606 | 677 | | |
607 | 678 | | |
608 | 679 | | |
| |||
623 | 694 | | |
624 | 695 | | |
625 | 696 | | |
626 | | - | |
627 | | - | |
628 | | - | |
| 697 | + | |
| 698 | + | |
629 | 699 | | |
630 | 700 | | |
631 | 701 | | |
| |||
660 | 730 | | |
661 | 731 | | |
662 | 732 | | |
663 | | - | |
664 | | - | |
665 | | - | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
666 | 737 | | |
667 | 738 | | |
668 | 739 | | |
| |||
681 | 752 | | |
682 | 753 | | |
683 | 754 | | |
684 | | - | |
685 | | - | |
686 | | - | |
| 755 | + | |
| 756 | + | |
687 | 757 | | |
688 | 758 | | |
689 | 759 | | |
| |||
Lines changed: 68 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
30 | 37 | | |
31 | 38 | | |
32 | 39 | | |
| |||
236 | 243 | | |
237 | 244 | | |
238 | 245 | | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
239 | 274 | | |
240 | 275 | | |
241 | | - | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
242 | 280 | | |
243 | 281 | | |
244 | 282 | | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
250 | 291 | | |
251 | 292 | | |
252 | | - | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
253 | 296 | | |
254 | 297 | | |
255 | 298 | | |
256 | 299 | | |
257 | 300 | | |
258 | 301 | | |
259 | 302 | | |
260 | | - | |
| 303 | + | |
261 | 304 | | |
262 | 305 | | |
263 | 306 | | |
264 | | - | |
| 307 | + | |
265 | 308 | | |
266 | | - | |
267 | | - | |
| 309 | + | |
| 310 | + | |
268 | 311 | | |
269 | 312 | | |
270 | 313 | | |
| |||
316 | 359 | | |
317 | 360 | | |
318 | 361 | | |
319 | | - | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
320 | 367 | | |
321 | 368 | | |
322 | 369 | | |
| |||
326 | 373 | | |
327 | 374 | | |
328 | 375 | | |
329 | | - | |
330 | | - | |
| 376 | + | |
331 | 377 | | |
332 | 378 | | |
333 | 379 | | |
| |||
496 | 542 | | |
497 | 543 | | |
498 | 544 | | |
499 | | - | |
500 | | - | |
| 545 | + | |
501 | 546 | | |
502 | 547 | | |
503 | 548 | | |
504 | | - | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
505 | 556 | | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
0 commit comments