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

Implemented ListIOCs API. #1064

Conversation

AWSHurneyt
Copy link
Collaborator

@AWSHurneyt AWSHurneyt commented Jun 11, 2024

Description

Implemented ListIOCs API.

This PR overlaps with PR #1060, so leaving it as a draft for now.

Issues Resolved

[List any issues this PR will resolve]

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

…otFoundException when calling ListIOCs API.

Signed-off-by: AWSHurneyt <[email protected]>

public class ListIOCsAction extends ActionType<ListIOCsActionResponse> {
public static final ListIOCsAction INSTANCE = new ListIOCsAction();
public static final String NAME = "cluster:admin/opensearch/securityanalytics/iocs/list";
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Including #1077 (comment)

should we call this ioc/_search or just cluster:admin/opensearch/securityanalytics/iocs is also good enough i guess

let's standardize all list apis...

@eirsep I believe we plan to have a separate SearchIOCs API which will support receiving a query in the request body (similar to the SearchMonitor API), so I was reserving the _search route for that. iocs/list follows the pattern used by the ListCorrelations API, but we can change this if needed.
https://github.com/opensearch-project/security-analytics/blob/feature/threat_intel/src/main/java/org/opensearch/securityanalytics/action/ListCorrelationsAction.java#L11

Copy link
Member

Choose a reason for hiding this comment

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

we need the search Ioc’s api.. that’s more flexible and if we are starting out with only one of these it should be the search API

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will implement a search IOC API separately.

Comment on lines +28 to +30
private int size;
private SortOrder sortOrder;
private String sortString;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Including #1077 (comment)

we need feedId as a parameter
check with @amsiglan if UX would be better suited to work with a search request rather than params?

@eirsep Added feedId to the request object. I believe @amsiglan mentioned that a list API would be more useful for the UI table, but I'll sync with him to confirm.

Signed-off-by: AWSHurneyt <[email protected]>
Signed-off-by: AWSHurneyt <[email protected]>
Signed-off-by: AWSHurneyt <[email protected]>
…otFoundException when calling ListIOCs API.

Signed-off-by: AWSHurneyt <[email protected]>
Signed-off-by: AWSHurneyt <[email protected]>
# Conflicts:
#	src/main/java/org/opensearch/securityanalytics/SecurityAnalyticsPlugin.java
#	src/main/java/org/opensearch/securityanalytics/model/STIX2IOC.java
#	src/main/java/org/opensearch/securityanalytics/model/STIX2IOCDto.java
#	src/main/java/org/opensearch/securityanalytics/services/STIX2IOCConsumer.java
#	src/main/java/org/opensearch/securityanalytics/services/STIX2IOCFeedStore.java
#	src/main/java/org/opensearch/securityanalytics/services/STIX2IOCFetchService.java
#	src/main/resources/mappings/stix2_ioc_mapping.json
#	src/test/java/org/opensearch/securityanalytics/resthandler/ListIOCsRestApiIT.java
#	src/test/java/org/opensearch/securityanalytics/util/STIX2IOCGenerator.java
Signed-off-by: AWSHurneyt <[email protected]>
Signed-off-by: AWSHurneyt <[email protected]>
@AWSHurneyt AWSHurneyt marked this pull request as ready for review June 17, 2024 23:28
@AWSHurneyt AWSHurneyt requested a review from amsiglan as a code owner June 17, 2024 23:28
Signed-off-by: AWSHurneyt <[email protected]>
int size = request.paramAsInt(ListIOCsActionRequest.SIZE_FIELD, 10);
String sortOrder = request.param(ListIOCsActionRequest.SORT_ORDER_FIELD, ListIOCsActionRequest.SortOrder.asc.toString());
String sortString = request.param(ListIOCsActionRequest.SORT_STRING_FIELD, STIX2.NAME_FIELD);
String search = request.param(ListIOCsActionRequest.SEARCH_FIELD, "");
Copy link
Member

Choose a reason for hiding this comment

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

what is search field?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The search field is used to support the search bar (see screenshot). Currently, it'll search the name, value, severity, create time, and modified time fields of the docs.
Screenshot 2024-06-18 at 4 50 42 PM

QueryBuilders.queryStringQuery(request.getSearch())
.defaultOperator(Operator.OR)
// .field(STIX2_IOC_NESTED_PATH + STIX2IOC.ID_FIELD) // Currently not a column in UX table
.field(STIX2_IOC_NESTED_PATH + STIX2IOC.NAME_FIELD)
Copy link
Member

Choose a reason for hiding this comment

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

can we remove nesting?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

private ListIOCsActionRequest request;
private ActionListener<ListIOCsActionResponse> listener;

private final AtomicReference<Object> response;
Copy link
Member

Choose a reason for hiding this comment

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

what is this for?

@eirsep eirsep merged commit d71579c into opensearch-project:feature/threat_intel Jun 19, 2024
1 check passed
@AWSHurneyt AWSHurneyt deleted the 3.0-threat-intel-list-iocs branch June 19, 2024 19:29
AWSHurneyt added a commit to AWSHurneyt/security-analytics that referenced this pull request Jun 25, 2024
* Removed unused imports. Removed redundant helper function.

Signed-off-by: AWSHurneyt <[email protected]>

* Added note about system index refactoring.

Signed-off-by: AWSHurneyt <[email protected]>

* Implemented draft of IocService.

Signed-off-by: AWSHurneyt <[email protected]>

* Made changes based on PR feedback.

Signed-off-by: AWSHurneyt <[email protected]>

* Fixed test helper function.

Signed-off-by: AWSHurneyt <[email protected]>

* Removed unused imports.

Signed-off-by: AWSHurneyt <[email protected]>

* Adjusted mappings based on PR feedback.

Signed-off-by: AWSHurneyt <[email protected]>

* Continuation of fetch IOC service implementation.

Signed-off-by: AWSHurneyt <[email protected]>

* Implemented ListtIOCs API.

Signed-off-by: AWSHurneyt <[email protected]>

* Removed "enabled" field from ListIOCs API as that will not be configured at the IOC level.

Signed-off-by: AWSHurneyt <[email protected]>

* Renamed response keys.

Signed-off-by: AWSHurneyt <[email protected]>

* Removed "enabled" field mapping as that will not be configured at the IOC level.

Signed-off-by: AWSHurneyt <[email protected]>

* Added feedId as a filter for LiistIOCs API. Added handling for IndexNotFoundException when calling ListIOCs API.

Signed-off-by: AWSHurneyt <[email protected]>

* Implemented ListtIOCs API.

Signed-off-by: AWSHurneyt <[email protected]>

* Removed "enabled" field from ListIOCs API as that will not be configured at the IOC level.

Signed-off-by: AWSHurneyt <[email protected]>

* Renamed response keys.

Signed-off-by: AWSHurneyt <[email protected]>

* Removed unused test suite.

Signed-off-by: AWSHurneyt <[email protected]>

* Added feedId as a filter for LiistIOCs API. Added handling for IndexNotFoundException when calling ListIOCs API.

Signed-off-by: AWSHurneyt <[email protected]>

* Added feedId as a filter for ListIOCs API.

Signed-off-by: AWSHurneyt <[email protected]>

* Fixed merge conflict.

Signed-off-by: AWSHurneyt <[email protected]>

* Removed unused test suite.

Signed-off-by: AWSHurneyt <[email protected]>

* Fixed test case.

Signed-off-by: AWSHurneyt <[email protected]>

* Fixed test index mappings.

Signed-off-by: AWSHurneyt <[email protected]>

---------

Signed-off-by: AWSHurneyt <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants