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

[SecuritySolution][Endpoint] Add scan response action API #184437

Merged

Conversation

ashokaditya
Copy link
Member

@ashokaditya ashokaditya commented May 29, 2024

Summary

Adds a scan action response route and related server side logic to handle scan action response.

Note: A lot of the changes in the PR are due to test updates that resulted out of adding scan command to list of API commands.

Testing

  1. Add responseActionScanEnabled feature flag to xpack.securitySolution.enableExperimental
  2. Run ES/Kibana
  3. Run node x-pack/plugins/security_solution/scripts/endpoint/run_endpoint_agent.js to start a VM with Elastic Defend installed.
  4. Visit app/security/administration/endpoints and click on the endpoint on the endpoint list.
  5. Copy the endpoint id (selected_endpopint) from the URL.
  6. Use curl to send out a scan request to the endpoint with elastic user. Use the curl command below:
curl curl --location 'http://localhost:5601/api/endpoint/action/scan' \ --header 'kbn-xsrf: test-xsrf' \ --header 'Content-Type: application/json' \ --header 'Authorization: Basic ZWxhc3RpYzpjaGFuZ2VtZQ==' \ --data '{ "endpoint_ids": [ "copied_endpoint_id" ], "parameters": { "path": "/home/ubuntu" } }'
  1. You should see the action created on the response actions history for the endpoint.
  2. Using any other non existing file path will result in a failed action. UX work to address this will follow.
  3. Disabling/removing responseActionScanEnabled feature flag should give you a not found error when accessing the API.

Checklist

@ashokaditya ashokaditya self-assigned this May 29, 2024
@ashokaditya ashokaditya added release_note:skip Skip the PR/issue when compiling release notes Team:Defend Workflows “EDR Workflows” sub-team of Security Solution OLM Sprint v8.15.0 labels May 29, 2024
@ashokaditya
Copy link
Member Author

/ci

@ashokaditya ashokaditya force-pushed the task/dw-scan-response-action-api branch from 4e78e38 to b27d2a8 Compare May 30, 2024 09:43
@ashokaditya
Copy link
Member Author

/ci

@ashokaditya ashokaditya force-pushed the task/dw-scan-response-action-api branch from c339810 to ae882df Compare May 30, 2024 11:14
@ashokaditya
Copy link
Member Author

/ci

@ashokaditya ashokaditya marked this pull request as ready for review May 30, 2024 13:43
@ashokaditya ashokaditya requested a review from a team as a code owner May 30, 2024 13:43
@ashokaditya ashokaditya requested review from pzl and parkiino May 30, 2024 13:43
@elasticmachine
Copy link
Contributor

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

Copy link
Contributor

@paul-tavares paul-tavares left a comment

Choose a reason for hiding this comment

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

Looks great - thank you.

I left a few minor comments, but am 👍 it. Note that i did not run it locally - only did code review

@@ -759,4 +759,6 @@ describe('actions schemas', () => {
}).toThrow('[file]: expected value of type [Stream] but got [Object]');
});
});

describe('ScanActionRequestSchema', () => {});
Copy link
Contributor

Choose a reason for hiding this comment

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

still working on these?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh yeah. I need to add these 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

done c44b3e6

@@ -47,7 +47,10 @@ describe(
});
}

for (const actionName of RESPONSE_ACTION_API_COMMANDS_NAMES) {
// TODO: update tests when `scan` is included in PLIs
Copy link
Contributor

Choose a reason for hiding this comment

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

Remind me: we have an issue tracking that, correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not a separate ticket but the same API ticket has an item in it.

@@ -261,6 +261,8 @@ describe('EndpointActionsClient', () => {
execute: responseActionsClientMock.createExecuteOptions(getCommonResponseActionOptions()),

upload: responseActionsClientMock.createUploadOptions(getCommonResponseActionOptions()),

scan: responseActionsClientMock.createUploadOptions(getCommonResponseActionOptions()),
Copy link
Contributor

Choose a reason for hiding this comment

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

using incorrect mock here. Should create one that is specific for scan (even if the same options as upload are returned). Will prevent issues if we ever enhance one command to add more parameters, but not for the others that maybe reusing the same props

Copy link
Member Author

Choose a reason for hiding this comment

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

Sheesh! Yeah I'll update this as well. Thanks for catching this.

Copy link
Contributor

Choose a reason for hiding this comment

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

FYI: I think that for isolate/release I created two separate functions out of responseActionsClientMock, but internally In that mock file) its actually using the same payload for both. This ensure that consumers of the mock still use the appropriate mock creation function and if we need to ever change them to differ from each other, then only the mock provider internal logic needs to be changed.

Copy link
Member Author

Choose a reason for hiding this comment

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

done 881a8bb

Copy link
Contributor

@tomsonpl tomsonpl left a comment

Choose a reason for hiding this comment

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

Lgtm 👍 added some comments, thanks for considering them :)

@@ -30,7 +30,6 @@ components:
- type: object
required:
- parameters
- file
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this removed on purpose?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes. The file param is redundant. The schema needs a parameters only.

(apiName) => apiName !== 'unisolate'
)) {
(apiName) => apiName !== 'scan'
).filter((apiName) => apiName !== 'unisolate')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand the double .filter() here, what do you think about the following? :

for (const actionName of RESPONSE_ACTION_API_COMMANDS_NAMES.filter(
        (apiName) => apiName !== 'unisolate' && apiName !== 'scan'
 )) {

      

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah that works the same way. I added another filter function just so that it is easier to delete later and not confuse with the logic for excluding release action from tests

@@ -95,6 +95,7 @@ describe('When using `getActionList()', () => {
agentType: 'endpoint',
hosts: { 'agent-a': { name: 'Host-agent-a' } },
command: 'kill-process',
alertIds: undefined,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need these changes?

Copy link
Member Author

Choose a reason for hiding this comment

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

The test needed to be updated as the API command list is now changed resulting in the endpoint action generator (that uses that) now picks the execute command for the tests instead.

@ashokaditya ashokaditya enabled auto-merge (squash) June 3, 2024 13:09
@kibana-ci
Copy link
Collaborator

💚 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 15.3MB 15.3MB +1.0KB
Unknown metric groups

ESLint disabled in files

id before after diff
securitySolution 81 82 +1

Total ESLint disabled count

id before after diff
securitySolution 606 607 +1

History

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

cc @ashokaditya

@ashokaditya ashokaditya merged commit 1203de2 into elastic:main Jun 3, 2024
36 checks passed
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Jun 3, 2024
@ashokaditya ashokaditya deleted the task/dw-scan-response-action-api branch June 3, 2024 21:02
rohanxz pushed a commit to honeyn303/kibana that referenced this pull request Jun 4, 2024
…184437)

## Summary

Adds a `scan` action response route and related server side logic to
handle `scan` action response.

Note: A lot of the changes in the PR are due to test updates that
resulted out of adding `scan` command to list of API commands.

### Testing
1. Add `responseActionScanEnabled` feature flag to
`xpack.securitySolution.enableExperimental`
2. Run ES/Kibana
3. Run `node
x-pack/plugins/security_solution/scripts/endpoint/run_endpoint_agent.js`
to start a VM with Elastic Defend installed.
4. Visit `app/security/administration/endpoints` and click on the
endpoint on the endpoint list.
5. Copy the endpoint id (`selected_endpopint`) from the URL.
6. Use `curl` to send out a `scan` request to the endpoint with
`elastic` user. Use the curl command below:
<details><summary>curl</summary>
<code>
curl --location 'http://localhost:5601/api/endpoint/action/scan' \
--header 'kbn-xsrf: test-xsrf' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic ZWxhc3RpYzpjaGFuZ2VtZQ==' \
--data '{
    "endpoint_ids": [
        "copied_endpoint_id"
    ],
    "parameters": {
        "path": "/home/ubuntu"
    }
}'
</code>
</details> 

7. You should see the action created on the response actions history for
the endpoint.
8. Using any other non existing file path will result in a failed
action. UX work to address this will follow.
9. Disabling/removing `responseActionScanEnabled` feature flag should
give you a not found error when accessing the API.

### Checklist

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [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
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
ashokaditya added a commit to ashokaditya/kibana that referenced this pull request Jun 17, 2024
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 OLM Sprint release_note:skip Skip the PR/issue when compiling release notes Team:Defend Workflows “EDR Workflows” sub-team of Security Solution v8.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants