Commit graph

196 commits

Author SHA1 Message Date
Frank Hassanabad
4bdc17039b
[Security Solutions] end to end tests, adds more console logging, removes 200 expect statements (#116987)
## Summary

e2e tests are still seeing flake with conflicts and it looks like it _might_ be with querying and not with inserting data. Hard to tell. This PR:

* Adds more console logging when the response is not a 200
* Removes the 200 expect statement and hopes for the best but should blow up if it's not 200 in a different way and we will get the console logging statements.
* Fixes one other flake with the matrix histogram having different counts. We have encountered this before and are applying the same fix which is to just have it check > 0.
* This does fix the timeouts seen where 1 in every 1k rule runs, a rule will not fire until _after_ the 5 minute mark. The timeouts were seen when running the flake runner.


Flake failures around `conflict`:
https://github.com/elastic/kibana/issues/116926
https://github.com/elastic/kibana/issues/116904
https://github.com/elastic/kibana/issues/116231

Not saying this is going to fix those yet, but it's the last 200 ok's we did an expect on, so it might if we are ignoring the conflict. If it fails again I am hopeful beyond hope that we get the body message and line number within the utilities to determine where/why we are getting these from time to time. It does look to fix the timeouts when a rule misfires and slows down the rate at which we continuously query for rule results.

Failure around matrix histogram (The error messages are slightly different on CI each time):
https://github.com/elastic/kibana/issues/97365

Ran this with the flake runner across groups 11 and 12 100 times each and did not see the conflict crop up:
https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/128
https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/129

The 1 failure in each of those runs were due to something on startup that prevented it from running.

### Checklist

Delete any items that are not applicable to this PR.

- [x] [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
2021-11-02 08:28:48 -06:00
Devin W. Hurley
6817a02e0d
[Security Solution] [Platform] Fix critical bug when migrating action within update route (#116512)
* WIP - need to figure out how to delete old siem-detection action SO's after each test

* WIP - adds some fixes for the update rules utility that differ from patch rules utility

* fix type checks

* cleanup

* remove commented out code

* rename const to use capital snake case

* naming integration tests, adds expect for disabled rules that get migrated, adds expect for pre-migrated rules
2021-10-29 22:05:55 -04:00
Frank Hassanabad
347c138bc0
Fixes flake seen on CI by sorting the results (#116846)
## Summary

Sorting fix for flake test. Fixes: https://github.com/elastic/kibana/issues/116691

### Checklist

- [x] [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
2021-10-29 23:08:13 +01:00
Frank Hassanabad
023d668e13
[Security Solutions] Adds e2e tests for the legacy notification system (#116531)
## Summary

Adds e2e tests for the legacy notification system for:
* Exporting rules
* Reading rules
* Finding rules

Also adds missing e2e tests for the non-legacy actions where they previously did not have e2e tests.

These tests ensure that the legacy notifications system will run for a while.

- [x] [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
2021-10-29 14:02:52 -06:00
Frank Hassanabad
29ac5583b7
[Security Solutions] Critical bug fix to make error messages about missing connections clearer for the end user. (#116490)
## Summary

Fixes issue see on this comment:
https://github.com/elastic/kibana/issues/116336#issuecomment-952159636

* Removes legacy toaster component
* Adds newer toaster component
* Removes issue with the deps array within ReactJS
* Adds utility to give a better network error message to the end user.
* This does effect the timeline component since it shares the same import common component.
* Adds a count of how many rules/timeline items have failed imports
* These error toasters mimic Kibana core's error toaster error message and UI/UX
* Adds e2e tests for imports with actions and error messages for them.

## Rules import error messages now

Before for small toaster:
<img width="417" alt="Screen Shot 2021-10-26 at 6 03 25 PM" src="https://user-images.githubusercontent.com/1151048/139132586-3cf77c73-53ac-4066-b01f-2e91ef2da111.png">

After for small toaster for different error conditions:
<img width="358" alt="Screen Shot 2021-10-26 at 6 00 24 PM" src="https://user-images.githubusercontent.com/1151048/139132679-2eeb1ed3-9f6e-4766-a8ed-8804ce3e6963.png">

<img width="396" alt="Screen Shot 2021-10-26 at 6 01 00 PM" src="https://user-images.githubusercontent.com/1151048/139132742-750cd937-f401-44e8-9a10-c21410073b5d.png">

<img width="379" alt="Screen Shot 2021-10-26 at 6 02 29 PM" src="https://user-images.githubusercontent.com/1151048/139132766-21b58bea-7f46-43a6-a0e9-f01632958eab.png">

Before for when you click "See the full error":
<img width="817" alt="Screen Shot 2021-10-26 at 5 58 47 PM" src="https://user-images.githubusercontent.com/1151048/139132980-de1942d6-7b03-4c08-b34a-1fc4a22d5207.png">

After for when you click "See the full error":
<img width="838" alt="Screen Shot 2021-10-27 at 1 48 16 PM" src="https://user-images.githubusercontent.com/1151048/139136581-af1e331e-ed77-4338-8fb0-c2457acd135f.png">

<img width="802" alt="Screen Shot 2021-10-27 at 1 26 31 PM" src="https://user-images.githubusercontent.com/1151048/139135083-9ca56940-30a8-4f83-9355-312307172834.png">

## timeline

Before:
<img width="441" alt="Screen Shot 2021-10-27 at 1 19 00 PM" src="https://user-images.githubusercontent.com/1151048/139136614-8360d6a6-d182-413e-b5d9-b18e3d70dc24.png">

<img width="827" alt="Screen Shot 2021-10-27 at 1 19 08 PM" src="https://user-images.githubusercontent.com/1151048/139136637-f9203ac2-0eea-4a77-9c53-ac2c20ab32e0.png">

After:
<img width="408" alt="Screen Shot 2021-10-27 at 1 49 45 PM" src="https://user-images.githubusercontent.com/1151048/139136758-7532a8ba-6d73-45e2-adbb-6756ee997289.png">

<img width="820" alt="Screen Shot 2021-10-27 at 1 49 50 PM" src="https://user-images.githubusercontent.com/1151048/139136774-26d4a8a2-caf0-4c6f-94d3-a6cd92b79f5f.png">

### Checklist

- [x] [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
2021-10-29 11:44:38 -06:00
Marshall Main
a68f3ffd06
[Security Solution] Only apply field aliases to legacy .siem-signals indices (#115290)
* Only apply field aliases to legacy .siem-signals indices

* Fix unit test mocks

* Add new function for special index existence check

* Actually add new function for special index existence check

* Undo getIndexVersion change

* Add basic integration tests for field alias logic

* Add back create_index to test list

* Add missing markdown to readme

* Revert change to delete_index_route

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2021-10-29 13:19:54 -04:00
Frank Hassanabad
b2f4c821f3
[Security Solutions] Adds console logging and relaxes the 200 checks in a 2 areas of the e2e tests (#116548)
## Summary

Adds console logging and relaxes a few 200 checks in the end to end tests in two areas of:
* createExceptionListItem
* importFile

As recently the tests are failing around these parts and possibly we can get information on the next failures if it is from these two areas or if it's from somewhere else we are not expecting.

Also outputs the body message so if it fails in these areas we can see the message with the conflict that might help us see where the issue is arising.

### Checklist

- [x] [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
2021-10-28 15:27:45 +02:00
Frank Hassanabad
3424f94fb4
Unskips tests and fixes a few of them. (#116469)
## Summary

* For the test of `create_endpoint_exceptions.ts` code was changed to try to reduce/remove flake. I put the code back to where it was and with the sorting introduced it all should pass
* Added `await waitForSignalsToBePresent(supertest, 1, [id]);` to areas of code that were missing.
* The `.flat` should be an added layer of protection for flakes.


### Checklist

- [x] [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
2021-10-27 21:31:18 -06:00
Madison Caldwell
117efdf87f
[RAC][Security Solution] Adds migration to new SecuritySolution rule types (#112113)
* Initial commit

* Properly handle signal history

* Fix #95258 - cardinality sort bug

* Init threshold rule

* Create working threshold rule

* Fix threshold signal generation

* Fix tests

* Update mappings

* ALERT_TYPE_ID => RULE_TYPE_ID

* Add tests

* Fix types

* Adds RAC rule type migration

* Fix threshold tests (remove outputIndex)

* Add threshold rule type to ruleTypeMappings

* Add kbn-securitysolution-rules package for sharing with alerting framework

* Fix type errors

* Fix find_rules tests

* First round of test fixes

* Fix issues from merge conflicts

* Use ruleDataClient getReader() for reading

* Fixes to 'generating_signals' tests

* Remove more refs to legacy schema

* Linting

* Quick type fix

* Bug fixes

* Add saved query rule type

* Linting

* Fix types

* Signal generation tests

* Test updates

* Update some more refs

* build_alert tests

* Cleanup

* Ref updates

* Revert "Ref updates"

This reverts commit 4d1473d6b0.

* Update status field

* Test fixes

* Another test

* Got a little too aggressive with search/replace

* let's see where we're at

* Fix

* Test fixes

* cleanup

* Fix cases API integration test config, flaky DE tests

* Move flattenWithPrefix to package / skip signal migration tests

* Fix unit tests

* Use new schema for bulk rule creation

* event: { kind } => event.kind

* Fix signal migration API tests

* Fix ml integration test

* Fix threat match integration tests

* Fix ML rule type tests and add correct producer to all rule types

* Update threat match API integration test

* Remove dupe properties

* Type fix

* Fix ML producer in functional test

* Fix generating_signals tests

* Remove usage of RuleDataClient-based execution log client

* Don't check output index version if rule registry enabled

* Fix bulk duplicate rule

* Fix duplicate rule test

* Fix readPrivileges and timestamp check logic

* Fixes for eql and exceptions tests... disable open_close_signals

* Type fixes / keyword test fixes

* Additional test fixes

* Unit test fixes + signal -> kibana.alert

* Test fixes for exceptions

* Fix read_resolve_rules test

* Various test fixes with marshallmain

* Sort search results

* Fix create_rules tests

* Disable writer cache for integration tests

* Disable writer cache for cases integration tests

* Fix types in rule_data_plugin_service

* Fix ordering in exceptions tests

* Remove rule_registry.enabled flag

* Fix signals migration tests

* Don't check signals index before creation

* Fix cypress config

* Fix type error

* create_migrations tests

* Skip flaky test

* Helpful comment

* Fixes from merge conflicts

* Pretend that signals index exists

* Fix type errors

* Skip flaky tests

* Fix threat matching test

* Clean up

* Reverting default ruleRegistry experimental flag (breaks unit tests)

* Reenable rule registry experimental feature by default

* Execute DE rule migration in 8.0

Co-authored-by: Marshall Main <marshall.main@elastic.co>
2021-10-26 16:56:40 -04:00
Mikhail Shustov
3c8fa527a7
[ES] Upgrade client to v8.0 (#113950)
* bump to a pre-8.0 version

* export KibanaClient from /lib sub-folder

* workaround the problem of the absence of estypes

* update es client usage in pacakges

* export estypes from another path

* import errors from root

* import errors from root 2

* update transport import

* update import path for /api/types

* update import path for /api/types

* import errors from top export

* use TransportResult instead if ApiResponse

* fix errors in client_config

* fix src/core/server/saved_objects/migrationsv2/actions/integration_tests/actions.test.ts

* use KibanaClient in mock. we dont export the original Client

* fix client mocks

* fix errors on SO

* fix remaining core errors

* update estype import path

* fix errors in data plugin

* fix data_views

* fix es_ui_shared

* fix errors in interactive_setup

* fix errors in ./test folder

* add @elastic/transport to the runtime deps

* fix errors in packages

* fix erros in src/core

* fix errors in test/

* fix an error in actions plugin

* woraround and fix errors in APM plugin

* fix errors in canvas

* fix errors in event_log

* fix errors in fleet

* fix errors in ILM

* fix errors in infra

* fix errors in ingest_pipeline

* fix errors in lens

* fix errors in license_management

* fix errors in licensing

* fix errors in logstash

* fix errors in ml

* fix errors in monitoring

* fix errors in observability

* fix errors in rule_registry

* fix errors in reporting

* fix errors in rule_registry

* fix errors in security

* fix errors in security_solution

* fix errors in snapshot_restore

* fix errors in transform

* fix errors in UA

* fix errors in uptime

* fix errors in x-pack/test

* fix eslint errors

* fix new errors

* use default HTTP Connection. Undici does not support agent config options keepAlive and maxSockets

* create does not accept require_alias option

* update deps

* use transport types exported from ES client package

* fix ErrorCause | string errors

* do not use enum

* fix errors in data plugin

* update x-pack code

* fix transport

* fix apm search request

* do not crash on reporting

* fix kbn-test build

* mute reporting error to start

* fix ftr build

* another attempt

* update import path

* address or mute new errors

* REMOVE me. pin transport version temporarily.

* remove deep imports from transport package

* fix jest crash

* fix product check tests

* remove unnecessary ts-expect-error

* fix a few failed unit tests

* bump to canary 24

* remove unnecessary ts-expect-error

* remove dependency on transport

* fix types in tests

* mute errors in xpack tests

* product check doesn;t  spam in logs anymore

* filterPath --> filter_path

* ignoreUnavailable --> ignore_unavailable

* ignoreUnavailable --> ignore_unavailable

* trackScores --> track_scores

* trackTotalHits --> track_total_hits

* fix es-arcives

* fix data plugin crashes

* fix watcher test utils

* rollback unnecessary changes

* fix another problem in es-archiver

* fix scroll. for whatever reason scroll fails when request scroll_id in body

* add meta: true in kbn-securitysolution-es-utils

* bump client to canary 25

* fix errors in accordance with the es client spec

* update securityscolution-es-utils

* unify scroll api in reporting and fix tests

* fix unit tests in watcher

* refactor APM to abort request with AbortController API

* fix missing es client calls in tests

* fix missing meta in detection engine FTR tests

* fix another bunch of errors in js tests

* fix wrong coercion

* remove test-grep pattern

* fix apm unit test

* rename terminateAfter to terminate_after in infra plugin

* rename terminateAfter to terminate_after in uptime plugin

* rename terminateAfter to terminate_after in apm plugin

* fix security roles FTR tests

* fix reference

* fix post_privilidges test

* fix post_privilidges

* bump client to 26

* add meta for index_management test helpers

* remove ts-expect-error caused by bad type in reason

* bump client to 27

* REMOVE me. workaround until fixed in the es client

* fix incorrect type casting

* swtich from camelCase params

* use `HttpConnection` for FTR-related clients

* bump client to 29

* Revert "REMOVE me. workaround until fixed in the es client"

This reverts commit c038850c09.

* fix new util

* revert repository changes

* do not crash if cannot store event_loop data

* fix new estypes imports

* fix more types

* fix security test types and add ts-ignore for custom ES client

* fix more estypes imports

* yet more ts violations

* line by line fixing is hard

* adapt `evaluateAlert` from infra as it's also used from FTR tests

* use convertToKibanaClient in FTR test instead of meta:true in plugin code

* migrate from deprecated API in fleet

* fix intergration tests

* fix fleet tests

* fix another fleet test

* fix more tests

* let's call it a day

* Removes custom header check on 404 responses, includes es client ProductNotSupportedError in EsUnavailableError conditional (#116029)

* Removes custom header check on 404 responses, includes es client ProductNotSupportedError in EsUnavailableError conditional

* Updates proxy response integration test

* disable APM until compatible with client v8

* skip async_search FTR test

* use kbnClient in integration tests

* bump version to 29

* bump to 30

* have configureClient return a KibanaClient instead of Client, remove resolved violations.

* bump to 31

* bump to 31

* Revert "bump to 31"

This reverts commit 5ac713e640.

* trigger stop to unusubscribe

* update generated docs

* remove obsolete test

* put "as" back

* cleanup

* skip test

* remove new type errors in apm package

* remove ErrorCause casting

* update a comment

* bump version to 32

* remove unnecessary ts-expect-error in apm code

* update comments

* update to client v33

* remove outdated type definition

* bump to 34 without params mutation

* unskip the test that should not fail anymore

* remove unnecessary ts-expect-error comments

* update to v35. body can be string

* move `sort` to body and use body friendly syntax

* fix a failing test. maps register the same SO that has been already registered by home

Co-authored-by: pgayvallet <pierre.gayvallet@gmail.com>
Co-authored-by: Christiane (Tina) Heiligers <christiane.heiligers@elastic.co>
2021-10-26 14:08:22 +02:00
Frank Hassanabad
9ca48d05f3
Adds one time conflict retry and cleans up the exception lists to use the REST API (#115848)
## Summary

Improves FTR/e2e conflict retries with exception lists and security rules.

Fixes:
https://github.com/elastic/kibana/issues/115734
https://github.com/elastic/kibana/issues/115769
https://github.com/elastic/kibana/issues/115715
https://github.com/elastic/kibana/issues/115702
https://github.com/elastic/kibana/issues/115701

This past week we have been seeing increasing flake across tests involving `exception_lists` involving a `409 conflict` on our tests. Looking at each of the tests above and the flake it looks like we were calling Elasticsearch directly within the `.kibana` index to delete the exception list and list items as a shortcut:

```
export const deleteAllExceptions = async (es: KibanaClient): Promise<void> => {
  return countDownES(async () => {
    return es.deleteByQuery({
      index: '.kibana',
      q: 'type:exception-list or type:exception-list-agnostic',
      wait_for_completion: true,
      refresh: true,
      body: {},
    });
  }, 'deleteAllExceptions');
};
```

Although I think we did everything correctly `wait_for_completion: true` and  `refresh: true` within the tests there might be a slight race condition where the delete by query does not immediately happen for us. Since we should prefer to use direct REST API's where we can instead of calling into `.kibana` I changed this to using the exception list API:

```
export const deleteAllExceptions = async (
  supertest: SuperTest.SuperTest<SuperTest.Test>
): Promise<void> => {
  await countDownTest(
    async () => {
      const { body } = await supertest
        .get(`${EXCEPTION_LIST_URL}/_find?per_page=9999`)
        .set('kbn-xsrf', 'true')
        .send();

      const ids: string[] = body.data.map((exception: ExceptionList) => exception.id);
      for await (const id of ids) {
        await supertest.delete(`${EXCEPTION_LIST_URL}?id=${id}`).set('kbn-xsrf', 'true').send();
      }
      const { body: finalCheck } = await supertest
        .get(`${EXCEPTION_LIST_URL}/_find`)
        .set('kbn-xsrf', 'true')
        .send();
      return finalCheck.data.length === 0;
    },
    'deleteAllExceptions',
    50,
    1000
  );
};
```

The additional final check above should ensure it sees that the data has been deleted before returning. Otherwise it will loop around again and keep trying.

I also improve both the `createRules` and `createExceptionList` by introducing a one-time, "detect if in conflict" and then "remove if in conflict" within those tests. This should help safe guard against flake if the above does not fix it. I also added more logging statements in case we do encounter this again on the CI system we can further trouble shoot it and add additional retry logic/fix logic.

A good side effect is if now you kill your tests half way through and restart them, the additional "detect if conflict" will recover your test for you as a developer. So 👍 that is an added benefit.

Example error message you would get (but not test failure) if you remove one of the cleanup sections in the `afterEach` or if you kill a test half way through and then restart it as an engineer:

```
└-: "is" operator
             └-> "before all" hook for "should find all the text from the data set when no exceptions are set on the rule"
             └-> should find all the text from the data set when no exceptions are set on the rule
               └-> "before each" hook: global before each for "should find all the text from the data set when no exceptions are set on the rule"
               └-> "before each" hook for "should find all the text from the data set when no exceptions are set on the rule"
When creating a rule found an unexpected conflict (409), will attempt a cleanup and one time re-try. This usually indicates a bad cleanup or race condition within the tests: {"message":"rule_id: \"rule-1\" already exists","status_code":409}
               └- ✓ pass  (7.9s)
```

### Checklist

- [x] [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
2021-10-20 16:25:33 -06:00
Ece Özalp
b12e21d9aa
[Security Solution][CTI] Rule Preview backend update (introduces /preview endpoint) (#112441)
Co-authored-by: Davis Plumlee <davis.plumlee@elastic.co>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2021-10-20 12:06:50 -04:00
Yara Tercero
6a2b7fe3d3
[Security Solution][Platform] - Export exceptions with rule (#115144)
### Summary

Introduces exports of exception lists with rules. Import of exception lists not yet supported.
2021-10-20 01:17:08 -04:00
Frank Hassanabad
a01165ab30
[Security Solutions] Fixes 11 different flakey FTR/e2e tests and scenarios (#115688)
## Summary

Fixes flakes across tests that have either been skipped or have been a source of flake in the categories of:
* Sorting fixes because Elasticsearch can return hits/arrays back in different orders
* Flat array fixes because Elasticsearch can sometimes return `[]` or `[[]]` in-deterministically in some cases 🤷 , so we just flatten the array out completely and test for `[]` within those tests.
* `waitForSignalsToBePresent` was missing in a test and sometimes we would get an empty array response which would fail CI.

Also I audited other tests for `[[]]` and `waitForSignalsToBePresent` and fixed them where they were present or if the `waitForSignalsToBePresent` count was incorrect. This should give us more stability when the CI is under pressure.

Sorting fixes:
https://github.com/elastic/kibana/issues/115554
https://github.com/elastic/kibana/issues/115321
https://github.com/elastic/kibana/issues/115319
https://github.com/elastic/kibana/issues/114581


Flat array fixes:
https://github.com/elastic/kibana/issues/89052
https://github.com/elastic/kibana/issues/115315
https://github.com/elastic/kibana/issues/115308
https://github.com/elastic/kibana/issues/115304
https://github.com/elastic/kibana/issues/115313
https://github.com/elastic/kibana/issues/113418

Missing additional check for "waitForSignalsToBePresent" or incorrect number of signals to wait for fixes:
https://github.com/elastic/kibana/issues/115310


### Checklist

- [x] [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
2021-10-20 00:42:35 -04:00
Marshall Main
ba20ea1630
[Security Solution] Improve rule statuses if user has no permissions to source index (#115114)
* Prevent error in field_caps from silencing privilege errors

* Fix threshold bug and fix privileges in new executor

* Fix unit tests

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2021-10-19 22:40:26 -04:00
Ryland Herrick
32e1fc2396
[Security Solution][Rules] Halt Indicator Match execution after interval has passed (#115288)
* Throw an error to stop execution if IM rule has exceeded its interval

* Extract and unit test our timeout validation

* Add integration test around timeout behavior

Configures a very slow rule to trigger a timeout and assert the
corresponding failure.

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2021-10-19 04:23:27 -04:00
Georgii Gorbachev
5e58fbded0
[Security Solution][Detections] Fix a bug in siem-detection-engine-rule-status Saved Object migration to SO references (#115355)
**Ticket:** https://github.com/elastic/kibana/issues/107068
**Follow-up after:** https://github.com/elastic/kibana/pull/114585

## Summary

The existing migration function `legacyMigrateRuleAlertIdSOReferences` that migrates `alertId` fields to SO references array did not include all the other attributes of a `siem-detection-engine-rule-status` doc being migrated to the resulting doc.

This PR includes a fix and an integration test for that.

## Run the test

To run the test, in one terminal execute:

```
cd ${KIBANA_HOME} && node scripts/functional_tests_server --config x-pack/test/detection_engine_api_integration/security_and_spaces/config.ts
```

In another terminal execute:

```
cd ${KIBANA_HOME} && node scripts/functional_test_runner --config x-pack/test/detection_engine_api_integration/security_and_spaces/config.ts --include=x-pack/test/detection_engine_api_integration/security_and_spaces/tests/migrations.ts
```

### Checklist

- [x] [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
2021-10-18 18:29:14 -06:00
Tiago Costa
ee317b0417
skip flaky suite (#115315) 2021-10-18 15:19:12 +01:00
Tiago Costa
e93765eb07
skip flaky suite (#115310) 2021-10-18 15:15:21 +01:00
Garrett Spong
fe979e4932
[Security Solution] Migrates siem-detection-engine-rule-status alertId to saved object references array (#114585)
## Summary

Resolves (a portion of) https://github.com/elastic/kibana/issues/107068 for the `siem-detection-engine-rule-status` type by migrating the `alertId` to be within the `SO references[]`. Based on: https://github.com/elastic/kibana/pull/113577

* Migrates the legacy `siem-detection-engine-rule-status` `alertId` to saved object references array
* Adds an e2e test for `siem-detection-engine-rule-status` 
* Breaks out `siem-detection-engine-rule-status` & `security-rule` SO's to their own dedicated files/directories, and cleaned up typings/imports


Before migration you can observe the existing data structure of `siem-detection-engine-rule-status` via Dev tools as follows:

```
GET .kibana/_search
{
  "size": 10000, 
  "query": {
    "term": {
      "type": {
        "value": "siem-detection-engine-rule-status"
      }
    }
  }
}
```

``` JSON
{
  "_index" : ".kibana-spong_8.0.0_001",
  "_id" : "siem-detection-engine-rule-status:d580f1a0-2afe-11ec-8621-8d6bfcdfd75e",
  "_score" : 2.150102,
  "_source" : {
    "siem-detection-engine-rule-status" : {
      "alertId" : "d62d2980-27c4-11ec-92b0-f7b47106bb35", <-- alertId which we want in the references array and removed
      "statusDate" : "2021-10-12T01:50:52.898Z",
      "status" : "failed",
      "lastFailureAt" : "2021-10-12T01:50:52.898Z",
      "lastSuccessAt" : "2021-10-12T01:18:29.195Z",
      "lastFailureMessage" : "6 minutes (385585ms) were not queried between this rule execution and the last execution, so signals may have been missed. Consider increasing your look behind time or adding more Kibana instances. name: \"I am the Host who Names!\" id: \"d62d2980-27c4-11ec-92b0-f7b47106bb35\" rule id: \"214ccef6-e98e-493a-98c5-5bcc2d497b79\" signals index: \".siem-signals-spong-default\"",
      "lastSuccessMessage" : "succeeded",
      "gap" : "6 minutes",
      "lastLookBackDate" : "2021-10-07T23:43:27.961Z"
    },
    "type" : "siem-detection-engine-rule-status",
    "references" : [ ],
    "coreMigrationVersion" : "7.14.0",
    "updated_at" : "2021-10-12T01:50:53.404Z"
  }
}
```

Post migration the data structure should be updated as follows:

``` JSON
{
  "_index": ".kibana-spong_8.0.0_001",
  "_id": "siem-detection-engine-rule-status:d580f1a0-2afe-11ec-8621-8d6bfcdfd75e",
  "_score": 2.1865466,
  "_source": {
    "siem-detection-engine-rule-status": {
      "statusDate": "2021-10-12T01:50:52.898Z", <-- alertId is no more!
      "status": "failed",
      "lastFailureAt": "2021-10-12T01:50:52.898Z",
      "lastSuccessAt": "2021-10-12T01:18:29.195Z",
      "lastFailureMessage": "6 minutes (385585ms) were not queried between this rule execution and the last execution, so signals may have been missed. Consider increasing your look behind time or adding more Kibana instances. name: \"I am the Host who Names!\" id: \"d62d2980-27c4-11ec-92b0-f7b47106bb35\" rule id: \"214ccef6-e98e-493a-98c5-5bcc2d497b79\" signals index: \".siem-signals-spong-default\"",
      "lastSuccessMessage": "succeeded",
      "gap": "6 minutes",
      "lastLookBackDate": "2021-10-07T23:43:27.961Z"
    },
    "type": "siem-detection-engine-rule-status",
    "references": [
      {
        "id": "d62d2980-27c4-11ec-92b0-f7b47106bb35", <-- previous alertId has been converted to references[]
        "type": "alert",
        "name": "alert_0"
      }
    ],
    "migrationVersion": {
      "siem-detection-engine-rule-status": "7.16.0"
    },
    "coreMigrationVersion": "8.0.0",
    "updated_at": "2021-10-12T01:50:53.406Z"
  }
},
```

#### Manual testing
---
There are e2e tests but for any manual testing or verification you can do the following:

##### Manual upgrade test

If you have a 7.15.0 system and can migrate it forward that is the most straight forward way to ensure this does migrate correctly. You should see that the `Rule Monitoring` table and Rule Details `Failure History` table continue to function without error.

##### Downgrade via script and test migration on kibana reboot
If you have a migrated `Rule Status SO` and want to test the migration, you can run the below script to downgrade the status SO then restart Kibana and observe the migration on startup. 

Note: Since this PR removes the mapping, you would need to [update the SO mapping](https://github.com/elastic/kibana/pull/114585/files#r729386126) to include `alertId` again else you will receive a strict/dynamic mapping error.

```json
# Replace id w/ correct Rule Status SO id of existing migrated object
POST .kibana/_update/siem-detection-engine-rule-status:d580ca91-2afe-11ec-8621-8d6bfcdfd75e
{
  "script" : {
    "source": """
    ctx._source.migrationVersion['siem-detection-engine-rule-status'] = "7.15.0";
    ctx._source['siem-detection-engine-rule-status'].alertId = ctx._source.references[0].id;
    ctx._source.references.remove(0);
    """,
    "lang": "painless"
  }
}
```

Restart Kibana and now it should be migrated correctly and you shouldn't see any errors in your console.  You should also see that the `Rule Monitoring` table and Rule Details `Failure History` table continue to function without error.




### Checklist

Delete any items that are not applicable to this PR.

- [ ] ~[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials~
- [X] [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

### For maintainers

- [x] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)


Co-authored-by: Georgii Gorbachev <georgii.gorbachev@elastic.co>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2021-10-18 14:20:40 +02:00
Jonathan Budzenski
63a615f1f1 skip flaky tests. #115308, #115313 2021-10-17 14:45:48 -05:00
Luke Elmers
94aa791a49
[Breaking] Remove deprecated enabled settings from plugins. (#113495) 2021-10-17 16:54:30 +01:00
Jonathan Budzenski
06e66ca284 skip flaky tests. #89052, #113418, #115304 2021-10-16 22:33:29 -05:00
Frank Hassanabad
95e412b4a1
Fixes migration bug where I was deleting attributes (#115098)
## Summary

During the work here: https://github.com/elastic/kibana/pull/113577

I accidentally have introduced a bug where on migration I was deleting the attributes of `ruleThrottle` and `alertThrottle` because I was not using splat correctly.

Added unit and e2e tests to fix this.

### Checklist
- [x] [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
2021-10-15 18:37:36 -06:00
Devin W. Hurley
103869509c
[Security Solution] [Platform] Utilize SO resolve api for reading rules by id (#112478)
* added outcome to backend routes

* adds so resolved property alias_target_id to response

* adds UI portion

* working URL redirect on aliasMatch - todo -> update rule details page refresh button to use SO resolve.

* cleanup

* fix integration tests

* fix jest tests

* cleanup types

* fix eslint.. I think vs code formatted this

* WIP - undo me, working index.test.ts function

* WIP - also undo me, probably

* working test for aliasMatch, need to add test for outcome = conflict

* add conflict callout when SO resolve yields conflict outcome

* code cleanup

* fix type issues

* small cleanup, fix jest test after undoing changes for getFailingRuleStatus

* cleanup tests

* add alias_target_id to response validation too

* unit test changes

* update tests again

* add all dependencies to useEffect and prefer useMemo

* add type cast

* adds integration tests for different outcomes after mocking a migrated rule leading to an aliasMatch and a migrated rule + accidental inserted rule to lead to a conflict. Also removes the outcome property if it is an exactMatch

* remove unused import

* fix test

* functional WIP

* cleanup

* cleanup

* finishing touches to address PR review comments

* remove console.error

* fix bug where spaces was not typed correctly in the plugin start method here https://github.com/elastic/kibana/pull/113983
2021-10-12 12:12:34 -04:00
Frank Hassanabad
3237a746ae
[Security Solution] Migrates siem-detection-engine-rule-actions ruleAlertId and actions to saved object references array (#113577)
## Summary

Fixes https://github.com/elastic/kibana/issues/113278

* Migrates the legacy `siem-detection-engine-rule-actions` `ruleAlertId` and `actions` to saved object references arrays
* Adds an e2e test for `siem-detection-engine-rule-actions`
* Updates the types to work with the migrations and the new and old data structures.
* Decouples and removes reliance on alerting within the types since we do not want development of alerting to get in the way of legacy things and have migration changes by accident.
* Updates the REST interface and code to produce post migration data structures. Removes some types and code where w can since those parts are no longer needed/used.
* Adds `actionRef` to the mapping

Before migration you should see data structures like this if you query:
```json
GET .kibana/_search
{
  "query": {
    "term": {
      "type": {
        "value": "siem-detection-engine-rule-actions"
      }
    }
  }
}
```

```json
{
  "siem-detection-engine-rule-actions": {
    "ruleAlertId": "fb1046a0-0452-11ec-9b15-d13d79d162f3", <-- ruleAlertId which we want in the references array and removed
    "actions": [
      {
        "action_type_id": ".slack",
        "id": "f6e64c00-0452-11ec-9b15-d13d79d162f3", <-- id which we want in the references array and removed
        "params": {
          "message": "Hourly\nRule {{context.rule.name}} generated {{state.signals_count}} alerts"
        },
        "group": "default"
      }
    ],
    "ruleThrottle": "7d",
    "alertThrottle": "7d"
  },
  "type": "siem-detection-engine-rule-actions",
  "references": [], <-- Array is empty which instead needs the id's of alerts and actions
  "migrationVersion": {
    "siem-detection-engine-rule-actions": "7.11.2"
  },
  "coreMigrationVersion": "7.14.0",
  "updated_at": "2021-09-15T22:18:48.369Z"
}
```

After migration you should see data structures like this:
```json
{
  "siem-detection-engine-rule-actions": {
    "actions": [
      {
        "action_type_id": ".slack",
        "actionRef" : "action_0", <-- We use the name and "actionRef" to be consistent with kibana alerting
        "params": {
          "message": "Hourly\nRule {{context.rule.name}} generated {{state.signals_count}} alerts"
        },
        "group": "default"
      }
    ],
    "ruleThrottle": "7d",
    "alertThrottle": "7d"
  },
  "type": "siem-detection-engine-rule-actions",
  "references" : [
    {
      "name" : "alert_0", <-- Name is "alert_0"
      "id" : "fb1046a0-0452-11ec-9b15-d13d79d162f3", <-- Alert id is now here
      "type" : "alert" <-- Type should be "alert"
    },
    {
      "name" : "action_0", <-- Name is "action_0" and should be the same as kibana alerting names theirs for consistencty
      "id" : "f6e64c00-0452-11ec-9b15-d13d79d162f3", <-- Id of the action is now here.
      "type" : "action" <-- Type should be "action"
    }
  ],  
  "migrationVersion": {
    "siem-detection-engine-rule-actions": "7.16.0"
  },
  "coreMigrationVersion": "8.0.0",
  "updated_at": "2021-09-15T22:18:48.369Z"
}
```

Manual testing
---
There are e2e tests but for any manual testing or verification you can do the following:

If you have a 7.14.0 system and can migrate it forward that is the most straight forward way to ensure this does migrate correctly and forward. You should see that the legacy notification system still operates as expected.

If you are a developer off of master and want to test different scenarios then this section is for below as it is more involved and harder to do but goes into more depth:

* Create a rule and activate it normally within security_solution
* Do not add actions to the rule at this point as we are exercising the older legacy system. However, you want at least one action configured such as a slack notification.
* Within dev tools do a query for all your actions and grab one of the `_id` of them without their prefix:

```json
# See all your actions
GET .kibana/_search
{
  "query": {
    "term": {
      "type": "action"
    }
  }
}
```

Mine was `"_id" : "action:879e8ff0-1be1-11ec-a722-83da1c22a481"`, so I will be copying the ID of `879e8ff0-1be1-11ec-a722-83da1c22a481`

Go to the file `detection_engine/scripts/legacy_notifications/one_action.json` and add this id to the file. Something like this:

```json
{
  "name": "Legacy notification with one action",
  "interval": "1m",  <--- You can use whatever you want. Real values are "1h", "1d", "1w". I use "1m" for testing purposes.
  "actions": [
    {
      "id": "879e8ff0-1be1-11ec-a722-83da1c22a481", <--- My action id
      "group": "default",
      "params": {
        "message": "Hourly\nRule {{context.rule.name}} generated {{state.signals_count}} alerts"
      },
      "actionTypeId": ".slack" <--- I am a slack action id type.
    }
  ]
}
```

Query for an alert you want to add manually add back a legacy notification to it. Such as:

```json
# See all your siem.signals alert types and choose one
GET .kibana/_search
{
  "query": {
    "term": {
      "alert.alertTypeId": "siem.signals"
    }
  }
}
```

Grab the `_id` without the alert prefix. For mine this was `933ca720-1be1-11ec-a722-83da1c22a481`

Within the directory of detection_engine/scripts execute the script:

```json
./post_legacy_notification.sh 933ca720-1be1-11ec-a722-83da1c22a481
{
  "ok": "acknowledged"
}
```

which is going to do a few things. See the file `detection_engine/routes/rules/legacy_create_legacy_notification.ts` for the definition of the route and what it does in full, but we should notice that we have now:

Created a legacy side car action object of type `siem-detection-engine-rule-actions` you can see in dev tools:

```json
# See the actions "side car" which are part of the legacy notification system.
GET .kibana/_search
{
  "query": {
    "term": {
      "type": {
        "value": "siem-detection-engine-rule-actions"
      }
    }
  }
}
```

Take note that this actually creates the rule migrated since this PR updated the code to produce new side cars. So we have to use some scripting to change the actions to utilize the old format.  However, before continuing you should verify that this does fire correctly and that the new format is working as expected. After that replace the structure with the older structure like so below and downgrade the migration version so that we can restart Kibana and ensure that this does migrate correctly forward:

```json
# Get your id of your rules side car above and then use this script to downgrade the data structure
POST .kibana/_update/siem-detection-engine-rule-actions:210f4c90-2233-11ec-98c6-ed2574588902
{
  "script" : {
    "source": """
    ctx._source.migrationVersion['siem-detection-engine-rule-actions'] = "7.15.0";
    ctx._source['siem-detection-engine-rule-actions'].actions[0].id = ctx._source.references[1].id;
    ctx._source['siem-detection-engine-rule-actions'].actions[0].remove('actionRef');
    ctx._source['siem-detection-engine-rule-actions'].ruleAlertId = ctx._source.references[0].id;
    ctx._source.references.remove(0);
    ctx._source.references.remove(0);
    """,
    "lang": "painless"
  }
}
```

Restart Kibana and now it should be migrated correctly and the system should fire the notifications as expected. You shouldn't see any errors in your console.

In the scripts folder execute the `find_rules.sh` and expect to see actions like so in the rule with the `id` still in the REST interface and we shouldn't see `actionRef` within the actions:

```json
"actions": [{
  "id": "42534430-2092-11ec-99a6-05d79563c01a",
  "group": "default",
  "params": {
    "message": "Hourly\nRule {{context.rule.name}} generated {{state.signals_count}} alerts"
  },
  "action_type_id": ".slack"
}],
```

Take the rule id and query that as well using `./get_rule_by_id.sh`  and verify that the action also looks the same and is present within the rule.

You can also verify all of this within the UI's as well for rules to ensure the action is still present and as we expect it to be and work.

### Checklist

Delete any items that are not applicable to this PR.

- [x] [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
2021-10-06 17:52:28 -04:00
Brian Seeders
9d7290d9ad
[CI] Balance CI Groups (#112836) 2021-09-22 15:42:01 -04:00
Tyler Smalley
4681a80317
[DX] Upgrade prettier to v2.4.0 (#112359)
Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>
2021-09-19 22:34:30 -07:00
Marshall Main
caf5fe3fb6
[Security Solution] Add host.os.name.caseless mapping and runtime field (#111455)
* Add host.os.name.caseless field and runtime field

* Tests

* Only add backwards compatibility mappings to old indices by version

* Always update aliases_version field even if there are no compat mappings

* Add test for newest index version

* More comments

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2021-09-10 10:48:05 -04:00
Frank Hassanabad
9a459806ad
[Security Solutions][Detection Engine] Adds ability to ignore fields during alert indexing and a workaround for an EQL bug (#110927)
## Summary

Adds a workaround for EQL bug: https://github.com/elastic/elasticsearch/issues/77152
Adds the safety feature mentioned here: https://github.com/elastic/kibana/issues/110802

Adds the ability to ignore particular [fields](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-fields.html#search-fields-param) when the field is merged with [_source](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-fields.html#source-filtering). Also fixes an EQL bug where EQL is introducing the meta field of `_ignored` within the fields and causing documents to not be indexable when we merge with the fields from EQL. 

Alerting document creation uses the fields API to get [runtime field](https://www.elastic.co/guide/en/elasticsearch/reference/current/runtime.html),  [constant keyword](https://www.elastic.co/guide/en/elasticsearch/reference/master/keyword.html#constant-keyword-field-type), etc... that are only available within the [fields API](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-fields.html#search-fields-param) and then merges the field values not found within the `_source` document with the `_source` document and then finally indexes this merged document as an alert document.

This fix/ability is a "safety feature" in that if a problematic [runtime field](https://www.elastic.co/guide/en/elasticsearch/reference/current/runtime.html), [constant keyword](https://www.elastic.co/guide/en/elasticsearch/reference/master/keyword.html#constant-keyword-field-type) is discovered or another bug along the stack we can set a `kibana.yml` key/value pair to ignore the problematic field.

This _WILL NOT_ remove problematic fields from the `_source` document. This will only ignore problematic constant keyword, runtime fields, aliases, or anything else found in the fields API that is causing merge issues.

This PR:
  * Adds a `alertIgnoreFields` `kibana.yml` array key with a default of an empty array if not specified. 
  * Plumbs the `alertIgnoreFields` through the stack and into the fields/_source merge strategies of `missingFields` and `allFields`
  * Adds a temporary `isEqlBug77152` where it hard codes an ignore of `_ignored` until the EQL problem is fixed and then we will remove the workaround
  * Adds unit tests
  * Adds e2e tests which covers the described use cases above.

The `alertIgnoreFields` key/value within `kibana.yml` if set should be an array of strings of each field you want to ignore. This can also contain regular expressions as long as they are of the form, `"/regex/"` in the array.

Example if you want to ignore fields that are problematic called "host.name" and then one in which you want to ignore all fields that start with "user." using a regular expression:

```yml
xpack.securitySolution.alertIgnoreFields: ['host.name', '/user\..*/']
``` 

Although there are e2e tests which exercise the use cases...

If you want to manual test the EQL bug fix you would add these documents in dev tools:

```json
# Delete and add a mapping with a small ignore_above.
DELETE eql-issue-ignore-fields-delme
PUT eql-issue-ignore-fields-delme
{
  "mappings" : {
    "dynamic": "strict",
    "properties" : {
      "@timestamp": {
        "type": "date"
      },
      "some_keyword" : {
        "ignore_above": 5, 
        "type" : "keyword"
      },
      "other_keyword" : {
        "ignore_above": 10, 
        "type" : "keyword"
      }
    }
  }
}

# Add a single document with one field that will be truncated and a second that will not.
PUT eql-issue-ignore-fields-delme/_doc/1
{
  "@timestamp": "2021-09-02T04:13:05.626Z",
  "some_keyword": "longer than normal",
  "other_keyword": "normal"
}
```

Then create an alert which queries everything from it:
<img width="1155" alt="Screen Shot 2021-09-01 at 10 15 06 PM" src="https://user-images.githubusercontent.com/1151048/131781042-faa424cf-65a5-4ebb-b801-3f188940c81d.png">

and ensure signals are created:
<img width="2214" alt="Screen Shot 2021-09-01 at 10 30 18 PM" src="https://user-images.githubusercontent.com/1151048/131782069-b9ab959c-f22d-44d5-baf0-561fe349c037.png">

To test the manual exclusions of any other problematic fields, create any index which has runtime fields or `constant keywords` but does not have anything within the `_source` document using dev tools. For example you can use `constant keyword` like so

```json
PUT constant-keywords-deleme
{
  "mappings": {
    "dynamic": "strict",
    "properties": {
      "@timestamp": {
        "type": "date"
      },
      "testing_ignored": {
        "properties": {
          "constant": {
            "type": "constant_keyword",
            "value": "constant_value"
          }
        }
      },
      "testing_regex": {
        "type": "constant_keyword",
        "value": "constant_value"
      },
      "normal_constant": {
        "type": "constant_keyword",
        "value": "constant_value"
      },
      "small_field": {
        "type": "keyword",
        "ignore_above": 10
      }
    }
  }
}

PUT constant-keywords-deleme/_doc/1
{
  "@timestamp": "2021-09-02T04:20:01.760Z"
}
```

Set in your `kibana.yml` the key/value of:

```yml
xpack.securitySolution.alertIgnoreFields: ['testing_ignored.constant', '/.*_regex/']
```

Setup a rule to run:
<img width="1083" alt="Screen Shot 2021-09-01 at 10 23 23 PM" src="https://user-images.githubusercontent.com/1151048/131781696-fea0d421-836f-465c-9be6-5289fbb622a4.png">

Once it runs you should notice that the constant values for testing are not on the signals table since it only typically exists in the fields API:
<img width="1166" alt="Screen Shot 2021-09-01 at 10 26 16 PM" src="https://user-images.githubusercontent.com/1151048/131781782-1684fb1d-bed9-4cf0-be9a-0abe1f0f34d1.png">

But the normal one still exists:
<img width="1136" alt="Screen Shot 2021-09-01 at 10 26 31 PM" src="https://user-images.githubusercontent.com/1151048/131781827-5450c693-de9e-4285-b082-9f7a2cbd5d07.png">

If you change the `xpack.securitySolution.alertIgnoreFields` by removing it and re-generate the signals you will see these values added back.

### Checklist

Delete any items that are not applicable to this PR.

- [x] [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
- [x] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/master/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
2021-09-03 08:41:28 -06:00
Michael Olorunnisola
3dda4dafa0
[Security Solution][RAC] - Update reason field text (#110308) 2021-09-02 13:52:10 -04:00
Xavier Mouligneau
16af3e95cb
[RAC] Remove rbac on security solution side (#110472)
* wip to remove rbac

* Revert "[Cases] Include rule registry client for updating alert statuses (#108588)"

This reverts commit 1fd7038b34.

This leaves the rule registry mock changes

* remove rbac on Trend/Count alert

* update detection api for status

* remove @kbn-alerts packages

* fix leftover

* Switching cases to leverage update by query for alert status

* Adding missed files

* fix bad logic

* updating tests for use_alerts_privileges

* remove index alias/fields

* fix types

* fix plugin to get the right index names

* left over of alis on template

* forget to use current user for create/read route index

* updated alerts page to not show table when no privileges and updates to tests

* fix bug when switching between o11y and security solution

* updates tests and move to use privileges page when user tries to access alerts without proper access

* updating jest tests

* pairing with yara

* bring back kbn-alerts after discussion with the team

* fix types

* fix index field for o11y

* fix bug with updating index priv state

* fix i18n issue and update api docs

* fix refresh on alerts

* fix render view on alerts

* updating tests and checking for null in alerts page to not show no privileges page before load

* fix details rules

Co-authored-by: Jonathan Buttner <jonathan.buttner@elastic.co>
Co-authored-by: Yara Tercero <yara.tercero@elastic.co>
2021-09-01 04:23:44 -04:00
Frank Hassanabad
35b59cd757
Changes the loading of indexes in tests from beforeEach() to before() (#110340)
## Summary

Changes the loading of indexes in tests from beforeEach() to before()

Hoping this fixes some flake we have seen recently. If it doesn't, at least tests should run faster and be less flake overall. If these two below do begin acting up again I will then probably resort to wrapping the individual tests around retry blocks or removing the tests.

Also found one area within `x-pack/test/detection_engine_api_integration/security_and_spaces/tests/generating_signals.ts` where we do a `load` twice but I fixed it to the `load`/`unload` pattern.

Issues this should fix:
* https://github.com/elastic/kibana/issues/107911
* https://github.com/elastic/kibana/issues/107856

### 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
2021-08-26 16:53:01 -06:00
Frank Hassanabad
ad01057f90
[Security Solutions][Detection Engine] Removes side car actions object and side car notifications (Part 1) (#109722)
## Summary

Removes the "side car" actions object and side car notification (Part 1). Part 1 makes it so that newly created rules and editing existing rules will update them to using the new side car notifications. Part 2 in a follow up PR will be the migrations to move the existing data. 

The saved object side we are removing usages of is:
```
siem-detection-engine-rule-actions
```

The alerting side car notification system we are removing is:
```
siem.notifications
```

* Removes the notification files and types
* Adds transform to and from alerting concepts of `notityWhen` and our `throttle`
* Adds unit tests for utilities and pure functions created 
* Updates unit tests to have more needed jest mock
* Adds business rules and logic for the different states of `notifyWhen`, and `throttle` on each of the REST routes to determine when we should `muteAll` vs. not muting using secondary API call from client alerting
* Adds e2e tests for the throttle conditions and how they are to interact with the kibana-alerting `throttle` and `notifyWhen`

A behavioral change under the hood is that we now support the state changes of `muteAll` from the UI/UX of [stack management](https://www.elastic.co/guide/en/kibana/master/create-and-manage-rules.html#controlling-rules). Whenever the `security_solution` ["Perform no actions"](https://www.elastic.co/guide/en/security/current/rules-api-create.html
) is selected we do a `muteAll`. However, we do not change the state if all individual actions are muted within the rule. Instead we only maintain the state of `muteAll`:

<img width="2299" alt="ui_state_change" src="https://user-images.githubusercontent.com/1151048/130823045-48a9f34b-db23-44e3-b9ed-cbbb57edc3d6.png">

<img width="1163" alt="no_actions_state_change" src="https://user-images.githubusercontent.com/1151048/130823056-3f8953fa-9433-4973-a2d3-6e11263b9619.png">

Ref:
* Issue and PR where notifyWhen was added to kibna-alerting
  * https://github.com/elastic/kibana/pull/82969
  * https://github.com/elastic/kibana/issues/50077  

### Checklist

Delete any items that are not applicable to this PR.

- [x] [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
2021-08-26 13:39:57 -04:00
Spencer
238152287d
[tests] prevent unhandled rejection (#109560)
Co-authored-by: spalger <spalger@users.noreply.github.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2021-08-23 14:38:01 -04:00
Michael Olorunnisola
d49519149b
[Security Solution][RAC] - Remove timestamp from reason field (#109492)
* remove timestamp from reason

* fix test type errors

* update tests
2021-08-23 11:31:34 -04:00
Yara Tercero
9fa41d1aef
[Security Solution] - Updating UI to work with new kibana privileges abstraction on alerts (#108961)
## Summary

Holy moly. 

What is happening in this PR? 🤷🏽‍♀️ Let's break it down:
- Added a package `@kbn/alerts` - another one?! ...yes
  - This is meant to add shared hooks and components around alerts as data
  - `useGetUserAlertsPermissions` - accepts the Kibana capabilities object and returns whether the user has `read` and `crud` alerts privileges
  - `AlertsFeatureNoPermissions` - component displayed when user does not have alerts privileges
- UI changes for user with NO alerts privileges
  - `Alerts` tab hidden in security solution side navigation
  - `Alerts` tab hidden in rule details page  
- UI changes for user with alerts READ ONLY privileges
  - alerts checkboxes hidden in alerts table
  - alerts bulk actions hidden in alerts table
2021-08-18 14:48:31 -04:00
Davis Plumlee
fc1a2bbd1b
[Security Solution][Detection Alerts] Changes in-progress status to acknowledged (#107972) 2021-08-18 02:12:16 -04:00
Devin W. Hurley
c3ccda942a
[RAC] [RBAC] working find route for alerts as data client (#107982)
Addition of a find api to the alerts client to authorize requests using RBAC, updates alerts histograms to use new API on alerts page, updates new alerts aggs data table on alerts page, and updates alerts histogram on overview page.
2021-08-17 22:54:01 -04:00
Tyler Smalley
689d974729
Removes supertest-as-promised dependency (#100486)
Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>
2021-08-16 18:01:34 -07:00
Ryland Herrick
a9844db461
[Security Solution][CTI] Update legacy CTI signals to latest ECS threat fields (#107988)
* WIP: Adding integration test

* Replace threat.indicator mappings with threat.enrichments mappings

The nested threat.indicator mappings were experimental, and replaced by
threat.enrichmentsin ECS 1.10. While these fields are also experimental,
they fix the conflict between CTI data's normal threat.indicator
mappings.

* Add threat.enrichments mappings to our signals template mappings

event.* is no longer nested within here; it was determined that event
fields were not relevant to enrichment. All relevant ECS fieldsets
(file, pe, etc) are now nested under threat.enrichments.

* Update snapshot with newest threat.enrichments mappings

This test is a snapshot of the actual mappings applied by our templates. Looks good to me!

* Update ECS types to match latest

We now have two threat fields we care about for CTI, for legacy and
official ECS.

* Add a basic test for behavior of legacy enriched signals.

They're still queryable by threat.indicator, meaning that any existing
dashboards will still work.

* WIP: First pass at a data migration for CTI signals

* Defines reindex script to move things around
* Adds integration tests to make sure the migration and new mappings
  work
* Need to test a few more things and verify corner cases
* Need to extract some helpers from tests

* Bump our template version to ensure devs roll over

Marshall bumped to 55, giving us 10 versions for 7.14.x updates.
However, devs would not otherwise roll over and get my mapping updates
without destroying their signals index and rebuilding (which is also not
the same thing, exactly), so this trades having one higher signals
version for a more streamlined dev workflow.

* More robust guard against data migration

We only attempt to migrate legacy enrichments if the document:

* is a signal from an indicator match rule
* has a `threat.indicator` field
* does not have a `threat.enrichments` field

* Minor reorder of operations to make logic clearer

* Add more assertions around our signals data migration

Tests a few more pieces of the resulting document, giving more
confidence that it's the correct transformation (and mappings).

This also modifies/anonymizes the data that was originally generated on
a work machine.

* Remove outdated note

This was for when these tests were driven via the UI; the API is more
responsive and now synchronization is currently needed here, beyond the
200 responses.

* Fix typo in comment

These fields are in ECS 1.11.

* Update snapshot test

We bumped the version previously, causing this test to become outdated.

* Update ECS typings in timelines plugin

These were copied from the security_solution plugin. I updated those,
but neglected to update these.

Until there's a better mechanism for deduplication here, I'm going to
kick the can and update both for now.

* Update enrichments logic to read/write from threat.enrichments

* indicator match rule logic
  * we now simply copy from the specified indicator path, and place that
    in `threat.enrichments.indicator`
* event enrichment API logic
  * We were previously returning fields from `indicator.*`, we now
    include the `indicator.*` suffix in order to be more consistent with
    the sibling `matched.*` fields
* row renderer logic
  * removal of dataset
  * updates relevant to API changes above

* Fix logical error in generating links from indicator fields

We want to link the reference field, not a `first_seen` field.

* Always include the indicator prefix in first-party indicator fields

Prior to this change we would display e.g. `threatintel.indicator.foo`
for investigation enrichment fields. Now that the structure has changed
slightly and we return both `indicator.*` and `matched.*` fields for
existing enrichents, we want to display investigation enrichment
similarly.

* Update indicator match rule integration tests

Now that we've updated our enrichment logic, we need to update our
enrichment tests.

* Remove unused translation

* Update example row renderer data for enriched alerts

* Update parallel CTI constants to get our CTI row renderer working

We were not requesting the necessary fields for our row renderer, since
these constants (specifically CTI_ROW_RENDERER_FIELDS) now exist in both
security_solution and the timelines plugin. I had updated the former,
but only the latter is actually used.

* Update CTI enrichment UI tests

* Update prepackaged threat timeline template with new threat fields

Also bumps the timelineTemplateVersion.

* Update Indicator Match rule tests

These needed three things:

* Update to timeline template (see previous commit)
* Changing expectations from `threat.indicator` to `threat.enrichments`
* Update row renderer expectation to exclude dataset

* Update mock data with newest CTI enrichment fields

* Fix assertion on our threat details

These fields are prefixed with `indicator` now because:

1. This data pertains to the indicator, not the match per se
2. The actual field is prefixed with indicator (or, it at least
   specifies an indicator in the case of a custom threat index (via
   threat_indicator_path))

* Update test data and tests for our field parsing helpers

* Update more event-parsing tests

Ths one involved updating a mock in another package.

* Modify our helper function to support old filebeat indicators

When we query indicators for enrichment matches, the current expectation
is that we'll be querying 7.14 filebeat modules, which have an indicator
path of 'threatintel.indicator'. The only place that matters on the UI
is on the threat intel panel, where these indicators come back with such
a prefix.

This change has one behavior: it brings back the `provider` field on the
Alert summary tab for queried enrichments from filebeat modules.

* Update variable and method names to be more consistent with internal terminology

Indicators come from a CTI index. Enrichments are the application of
indicator data to other documents, and contain both indicator fields and
matched context.

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2021-08-14 01:57:23 -04:00
Sergi Massaneda
a7661a553c
[TGrid] Alerts status update use RAC api (#108092)
Co-authored-by: Devin Hurley <devin.hurley@elastic.co>
2021-08-13 22:11:53 -04:00
spalger
31b8a8229c skip flaky suite (#107911) 2021-08-11 17:37:36 -07:00
Michael Olorunnisola
09470dcccf
[Security Solution][RAC] - Add reason field (#107532) 2021-08-11 17:18:04 -04:00
Paul Tavares
a3119a5541
[Security Solution][Roles] Add Read-Only Endpoint indexes to the (Detections) role creation scripts + FTR improvements (#107086)
* Add needed indexes to the role scripts
* Moved/renamed detection engine roles and user utility to `x-pack/test/common/security_solution`
* removed duplicate code in rule_registry and instead exported same methods from `common/services/security_solution`
* new endpoint FTR service that includes methods for loading and unloading data (uses existing data indexer methods)
* Transforms: Added additional methods to the FTR Test service
2021-08-09 16:24:58 -04:00
Tiago Costa
4fb20e71e1
skip flaky suite (#107856) 2021-08-09 13:02:51 +01:00
Ryland Herrick
8665f36cf3
[Security Solution, Lists] Replace legacy imports from 'elasticsearch' package (#107226)
* Remove legacy imports from 'elasticsearch' package

This prefers the newer types from '@elastic/elasticsearch'.

There was one instance where mock data was insufficient to satisfy the
newer analogous types; in all other cases this was just a find/replace.

* Fix type errors with a null guard

We know that this mock has hits with _source values, but we cannot
convey this to typescript as null assertions are disabled within this
project. This seems like the next best solution, preferable to a
@ts-expect-error.

* Fix a few more type errors

* Replace legacy type imports in integration tests

* refactors destructuring due to _source being properly declared as
  conditional

* Update more integration tests to account for our optional _source

Changes here fall into one of two categories:

* If the test was making an assertion on a value from _source, we simply
null chain and continue to assert on a possibly undefined value.

* If the test logic depends on _source being present, we first assert that
presence, and exit the test early if absent.

* Fix more type errors

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2021-08-05 15:36:44 -04:00
Frank Hassanabad
0a5c96b117
[Security Solutions] Fixes exception lists to be able to filter on os type (#106494)
## Summary

Fixes https://github.com/elastic/kibana/issues/102613, and targets `7.14.0` as a blocker/critical

Previously we never fully finished the plumbing for using the `os_types` (operating system type) in the exception lists to be able to filter out values based on this type. With the endpoint exceptions now having specific selections for os_type we have to filter it with exceptions and basically make it work.

Some caveats is that the endpoints utilize `host.os.name.casless` for filtering against os_type, while agents such as auditbeat, winlogbeat, etc... use `host.os.type`. Really `host.os.type` is the correct ECS field to use, but to retain compatibility with the current version of endpoint agents I support both in one query to where if either of these two matches, then that will trigger the exceptions.

* Adds e2e tests
* Enhances the e2e tooling to do endpoint exception testing with `os_types`.
* Adds the logic to handle os_type
* Updates the unit tests

### Checklist

Delete any items that are not applicable to this PR.

- [x] [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
2021-07-22 12:54:40 -06:00
Ece Özalp
14ca699c48
[CTI] adds performance improvements to threat match event query (#106150) 2021-07-22 11:52:03 -04:00
Frank Hassanabad
773b5b5d48
[Security Solutions][Detection Engine] Removes EQL timestamp workaround and reduces test boiler plating (#105483)
## Summary

Removes EQL timestamp workaround we introduced earlier when we found the bug https://github.com/elastic/kibana/pull/103771 now that it has been fixed with the fields API https://github.com/elastic/elasticsearch/issues/74582

* Fixes the EQL timestamp issue by removing the workaround
* Introduces EQL timestamps being formatted as ISO8601 like we do with KQL
* Adds e2e tests for the EQL timestamps
* Removes some boiler plating around our e2e tests by adding two utilities of `getEqlRuleForSignalTesting` and `getThresholdRuleForSignalTesting` and reducing those e2e code areas.   

### Checklist

- [x] [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
2021-07-13 17:42:16 -04:00