Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[Security Solution][Endpoint] Cypress test to validate that Endpoint can stream alerts to ES/Kibana #155455

Conversation

paul-tavares
Copy link
Contributor

@paul-tavares paul-tavares commented Apr 20, 2023

Summary

  • Adds cypress test that stands up a real endpoint and validates that it can trigger alerts and send those to ES/Kbn and that they show up on the Alerts list

Testing

The test was added to a Test Suite that is not currently running under CI. To run it manually:

  • First, ensure that you have Docker and Multipass installed
  • Ensure that you have Kibana Running locally with Fleet setup with Fleet-server (Tip: you can execute the run_endpoint_agent.js script, which will setup fleet server locally with Docker)
  • Run tests (see command below. Adjust env. variable values if values are different in your local env.)
cd x-pack/plugins/security_solution

CYPRESS_BASE_URL=http://localhost:5601 \
CYPRESS_KIBANA_URL=http://localhost:5601 \
CYPRESS_ELASTICSEARCH_USERNAME=elastic \
CYPRESS_ELASTICSEARCH_PASSWORD=changeme \
CYPRESS_ELASTICSEARCH_URL=http://localhost:9200 yarn cypress:dw:endpoint:open

…py of version found in run endpoint host utility)
@paul-tavares paul-tavares added release_note:skip Skip the PR/issue when compiling release notes Team:Defend Workflows “EDR Workflows” sub-team of Security Solution v8.8.0 labels Apr 20, 2023
@paul-tavares paul-tavares self-assigned this Apr 20, 2023
@paul-tavares paul-tavares marked this pull request as ready for review April 20, 2023 20:54
@paul-tavares paul-tavares requested review from a team as code owners April 20, 2023 20:54
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-defend-workflows (Team:Defend Workflows)

@paul-tavares paul-tavares requested review from dasansol92 and removed request for joeypoon April 20, 2023 20:54
paul-tavares and others added 4 commits April 23, 2023 12:36
…endpoint-sends-alert-events

# Conflicts:
#	x-pack/plugins/security_solution/public/management/cypress/cypress.d.ts
#	x-pack/plugins/security_solution/public/management/cypress/support/data_loaders.ts
…s-alert-events' into task/olm-6030-test-endpoint-sends-alert-events
@kibana-ci
Copy link
Collaborator

kibana-ci commented Apr 24, 2023

💔 Build Failed

Failed CI Steps

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 9.1MB 9.1MB +8.0B
Unknown metric groups

ESLint disabled line counts

id before after diff
enterpriseSearch 17 19 +2
securitySolution 395 399 +4
total +6

Total ESLint disabled count

id before after diff
enterpriseSearch 18 20 +2
securitySolution 475 479 +4
total +6

History

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

cc @paul-tavares

* NOTE: This is tno the same as the alerts that populate the Alerts list. To check for
* those types of alerts, use `waitForDetectionAlerts()`
*/
export const waitForEndpointAlerts = (
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I have not

Copy link
Contributor Author

Choose a reason for hiding this comment

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

looks like its available in package.json from kibana. Are you proposing that be used instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Going to merge this in, but if you still have feedback, feel free to post it here on the PR and I'll come back around and follow up on it.

Copy link
Contributor

@dasansol92 dasansol92 left a comment

Choose a reason for hiding this comment

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

Left a suggestion but other than that, this LGTM

body: {
query: {
query_string: {
query: queryString,
Copy link
Contributor

Choose a reason for hiding this comment

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

Not needed now, but perhaps we could do this query more accurate to avoid removing extra things.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, I played around with that as well (see a sample query below), but found that as more/other data is added, we are likely to miss it. I wanted to truly try to remove all records that reference the agent ID so that our tests (especially those that use a Real endpoint) clean up properly after themselves.

Here is the query I initially came up with:

# List all indexes where the agent id has data
GET */_search
{
  "query": {
    "bool": {
      "filter": [
        {
          "bool": {
            "should": [
              {
                "match": {
                  "agent.id": "180f5edb-2f48-4d4b-af97-2434775a0bb9"
                }
              },
              {
                "match": {
                  "agent_id": "180f5edb-2f48-4d4b-af97-2434775a0bb9"
                }
              },
              {
                "match": {
                  "EndpointActions.action_id": "180f5edb-2f48-4d4b-af97-2434775a0bb9"
                }
              },
              {
                "match": {
                  "agents": "180f5edb-2f48-4d4b-af97-2434775a0bb9"
                }
              },
              {
                "match": {
                  "_id": "180f5edb-2f48-4d4b-af97-2434775a0bb9"
                }
              }
            ],
            "minimum_should_match": 1
          }
        }
      ]
    }
  },
  "_source": false,
  "size": 0,
  "aggs": {
    "unique_indexes": {
      "terms": {
        "field": "_index",
        "size": 10000
      }
    }
  }
}

@paul-tavares paul-tavares merged commit 96fcd5a into elastic:main Apr 25, 2023
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Apr 25, 2023
@paul-tavares paul-tavares deleted the task/olm-6030-test-endpoint-sends-alert-events branch April 25, 2023 13:16
paul-tavares added a commit that referenced this pull request Apr 27, 2023
…nt_agent.js` CLI tool (#155730)

## Summary

As a follow up to PR #155455 : 

- `run_endpoint_agent` CLI: Removed internal code that handles the
creation of a VM and the enrollment of the agent with fleet and replaced
it with use of methods now found in `endpoint_host_services`
- created new service for managing agent download cache on local system
- enhanced `run_endpoint_agent` to use cached version of agent download,
and thus increase the performance of this tool
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:Defend Workflows “EDR Workflows” sub-team of Security Solution v8.8.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants