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

Make host card overview space aware #113983

Merged
merged 6 commits into from
Oct 10, 2021
Merged

Conversation

nkhristinin
Copy link
Contributor

@nkhristinin nkhristinin commented Oct 5, 2021

Summary

Host overview card now is using space value to make requests to this index: ml_host_risk_score_latest_${SPACE}

How to test

  1. Be sure that the Host Overview Card is visible and module is disabled

Screenshot 2021-10-06 at 11 23 18

  1. Make the following requests in Kibana Dev Tools
Create ml_host_risk_score_latest_default index


PUT ml_host_risk_score_latest_default
{
  "mappings": {
    "properties": {
      "@timestamp": {
        "type": "date"
      },
      "host": {
        "properties": {
          "name": {
            "type": "keyword"
           }
         }
       },
      "ingest_timestamp": {
        "type": "date"
      },
      "risk": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "risk_score": {
        "type": "float"
      }
    }
  }
}

Add data to ml_host_risk_score_latest_default index


POST _bulk
{"index":{"_index":"ml_host_risk_score_latest_default"}}
{"@timestamp":"2021-02-23T23:00:00.000Z","risk_score":21,"host":{"name":"ip-10-10-10-121"},"rules":{"Unusual Linux Username":{"average_risk":21,"rule_count":2,"rule_risk":42}},"ingest_timestamp":"2021-07-27T18:02:08.319296053Z","risk":"Low"}
{"index":{"_index":"ml_host_risk_score_latest_default"}}
{"@timestamp":"2021-02-23T23:00:00.000Z","risk_score":21,"host":{"name":"ip-10-10-10-53"},"rules":{"Unusual Linux Username":{"average_risk":21,"rule_count":2,"rule_risk":42}},"ingest_timestamp":"2021-07-27T18:02:08.319484548Z","risk":"Low"}
{"index":{"_index":"ml_host_risk_score_latest_default"}}
{"@timestamp":"2020-08-21T21:00:00.000Z","risk_score":21,"host":{"name":"ip-172-31-44-235"},"rules":{"AWS Access Secret in Secrets Manager":{"average_risk":21,"rule_count":1,"rule_risk":21}},"ingest_timestamp":"2021-07-27T18:02:08.318446811Z","risk":"Low"}
{"index":{"_index":"ml_host_risk_score_latest_default"}}
{"@timestamp":"2021-08-09T00:00:00.000Z","risk_score":21,"host":{"name":"EC2AMAZ-855H8KG"},"rules":{"Unusual Windows Path Activity":{"average_risk":21,"rule_count":1,"rule_risk":21}},"ingest_timestamp":"2021-08-09T01:02:09.209326766Z","risk":"Low"}
{"index":{"_index":"ml_host_risk_score_latest_default"}}
{"@timestamp":"2021-08-11T19:00:00.000Z","risk_score":21,"host":{"name":"skynet-2.skynet.local"},"rules":{"Anomalous Windows Process Creation":{"average_risk":21,"rule_count":1,"rule_risk":21},"Unusual Windows Network Activity":{"average_risk":21,"rule_count":1,"rule_risk":21}},"ingest_timestamp":"2021-08-11T20:02:08.497398786Z","risk":"Low"}
{"index":{"_index":"ml_host_risk_score_latest_default"}}
{"@timestamp":"2021-08-11T19:00:00.000Z","risk_score":21,"host":{"name":"skynet.skynet.local"},"rules":{"Anomalous Windows Process Creation":{"average_risk":21,"rule_count":2,"rule_risk":42}},"ingest_timestamp":"2021-08-11T20:02:08.497783581Z","risk":"Low"}
{"index":{"_index":"ml_host_risk_score_latest_default"}}
{"@timestamp":"2021-08-11T19:00:00.000Z","risk_score":21,"host":{"name":"windows-native.skynet.local"},"rules":{"Anomalous Windows Process Creation":{"average_risk":21,"rule_count":11,"rule_risk":231},"Unusual Windows Network Activity":{"average_risk":21,"rule_count":3,"rule_risk":63}},"ingest_timestamp":"2021-08-11T20:02:08.497874368Z","risk":"Low"}
{"index":{"_index":"ml_host_risk_score_latest_default"}}
{"@timestamp":"2021-08-13T01:00:00.000Z","risk_score":47,"host":{"name":"linux-auditbeat-2"},"rules":{"Unusual Process Execution - Temp":{"average_risk":47,"rule_count":127,"rule_risk":5969}},"ingest_timestamp":"2021-08-13T02:02:08.431822027Z","risk":"Moderate"}
{"index":{"_index":"ml_host_risk_score_latest_default"}}
{"@timestamp":"2021-08-13T14:00:00.000Z","risk_score":47,"host":{"name":"linux-multibeat"},"rules":{"RDP (Remote Desktop Protocol) from the Internet":{"average_risk":47,"rule_count":4,"rule_risk":188}},"ingest_timestamp":"2021-08-13T15:02:08.536780945Z","risk":"Moderate"}

  1. Check that you can see the data with Last year range

Screenshot 2021-10-05 at 20 08 37

  1. Create a new space, and go to security overview. The Host overview card should be visible and module disabled

Screenshot 2021-10-05 at 20 09 10

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@nkhristinin nkhristinin requested a review from a team as a code owner October 5, 2021 18:10
@nkhristinin nkhristinin requested review from rylnd and ecezalp October 6, 2021 09:27
@nkhristinin nkhristinin added Team: CTI Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v7.16.0 v8.0.0 labels Oct 6, 2021
@elasticmachine
Copy link
Contributor

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

@nkhristinin nkhristinin added auto-backport Deprecated - use backport:version if exact versions are needed release_note:feature Makes this part of the condensed release notes release_note:skip Skip the PR/issue when compiling release notes labels Oct 6, 2021
@nkhristinin
Copy link
Contributor Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

merge conflict between base and head

Copy link
Contributor

@rylnd rylnd left a comment

Choose a reason for hiding this comment

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

LGTM! I defer to you on making the space-aware index logic a helper method or not (cc @machadoum).

loginAndWaitForPage(OVERVIEW_URL);
cy.get(
`${OVERVIEW_RISKY_HOSTS_LINKS} ${OVERVIEW_RISKY_HOSTS_LINKS_WARNING_INNER_PANEL}`
).should('not.exist');
cy.get(`${OVERVIEW_RISKY_HOSTS_VIEW_DASHBOARD_BUTTON}`).should('be.disabled');
cy.get(`${OVERVIEW_RISKY_HOSTS_TOTAL_EVENT_COUNT}`).should('have.text', 'Showing: 1 host');

changeSpace(testSpaceName);
Copy link
Contributor

Choose a reason for hiding this comment

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

A++

export const changeSpace = (space: string) => {
cy.get(`${SPACES_BUTTON}`).click();
cy.get(getGoToSpaceMenuItem(space)).click();
cy.get(`[data-test-subj="space-avatar-${space}"]`, { timeout: 120000 });
Copy link
Contributor

Choose a reason for hiding this comment

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

The code as it is currently written will query the page once, and wait up to 2 minutes for a result; adding an assertion here will allow the cy.get to be retried if the assertion fails:

Suggested change
cy.get(`[data-test-subj="space-avatar-${space}"]`, { timeout: 120000 });
cy
.get(`[data-test-subj="space-avatar-${space}"]`})
.should('exist');

Copy link
Contributor

Choose a reason for hiding this comment

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

More to the point: without the assertion, I think there's a potential race condition between the click/page load and this subsequent cy.get.

Copy link
Contributor

@ecezalp ecezalp left a comment

Choose a reason for hiding this comment

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

LGTM, great work 😊

@nkhristinin
Copy link
Contributor Author

@elasticmachine merge upstream

@nkhristinin
Copy link
Contributor Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
securitySolution 4.3MB 4.3MB +57.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
securitySolution 103.8KB 103.8KB +54.0B

History

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

@nkhristinin nkhristinin merged commit 30aeb81 into elastic:master Oct 10, 2021
kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Oct 10, 2021
* Make host card overview space aware

* Add cypress test

* Move getHostRiskIndex to helpers

* Fix cypress test

Co-authored-by: Kibana Machine <[email protected]>
@kibanamachine
Copy link
Contributor

💚 Backport successful

Status Branch Result
7.x

This backport PR will be merged automatically after passing CI.

@@ -67,6 +68,7 @@ export interface StartPlugins {
timelines: TimelinesUIStart;
uiActions: UiActionsStart;
ml?: MlPluginStart;
spaces: SpacesPluginStart;
Copy link
Contributor

@dhurley14 dhurley14 Oct 11, 2021

Choose a reason for hiding this comment

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

@nkhristinin I think this should be optional. Just came across this as a conflict to my PR -> #112478

Suggested change
spaces: SpacesPluginStart;
spaces?: SpacesPluginStart;

Copy link
Contributor

Choose a reason for hiding this comment

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

CC: @rylnd @ecezalp just FYI since I saw you both reviewed this. The security solution has the spaces plugin listed as optional. We should not be assuming this is always present. This could have lead to some not-so-great bugs.

"optionalPlugins": [
"encryptedSavedObjects",
"fleet",
"ml",
"dashboard",
"newsfeed",
"security",
"spaces",
"usageCollection",
"lens",
"lists",
"home",
"telemetry",
"telemetryManagementSection"
],

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for fixing it in your PR!

dhurley14 added a commit to dhurley14/kibana that referenced this pull request Oct 12, 2021
dhurley14 added a commit that referenced this pull request Oct 12, 2021
…es 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 #113983
@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

@kibanamachine kibanamachine added backport missing Added to PRs automatically when the are determined to be missing a backport. and removed backport missing Added to PRs automatically when the are determined to be missing a backport. labels Oct 12, 2021
kibanamachine added a commit that referenced this pull request Oct 12, 2021
* Make host card overview space aware

* Add cypress test

* Move getHostRiskIndex to helpers

* Fix cypress test

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Khristinin Nikita <[email protected]>
dhurley14 added a commit that referenced this pull request Oct 13, 2021
…ng rules by `id` (#112478) (#114683)

* [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 #113983
# Conflicts:
#	x-pack/plugins/security_solution/public/overview/containers/overview_risky_host_links/use_hosts_risk_score.ts
#	x-pack/plugins/security_solution/public/types.ts

* fix eslint

* skip 8.0 integration tests for 7.16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed release_note:feature Makes this part of the condensed release notes release_note:skip Skip the PR/issue when compiling release notes Team: CTI Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v7.16.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants