Skip to content

Commit

Permalink
throw error when no iocs are stored due to incompatible ioc types fro…
Browse files Browse the repository at this point in the history
…m S3 downloaded iocs file (#1129)

Signed-off-by: Surya Sashank Nistala <[email protected]>
(cherry picked from commit 5d3dbca)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] committed Jul 8, 2024
1 parent 1cd9fb0 commit 2b4bc6c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.opensearch.OpenSearchStatusException;
import org.opensearch.core.rest.RestStatus;
import org.opensearch.securityanalytics.commons.model.IOC;
import org.opensearch.securityanalytics.commons.model.STIX2;
import org.opensearch.securityanalytics.commons.model.UpdateAction;
Expand Down Expand Up @@ -43,6 +45,10 @@ public void accept(final STIX2 ioc) {
// TODO hurneyt refactor once the enum values are updated
// If the IOC received is not a type listed for the config, do not add it to the queue
if (!feedStore.getSaTifSourceConfig().getIocTypes().contains(stix2IOC.getType().name())) {
log.error("{} is not a supported Ioc type for tif source config {}. Skipping IOC {}: of type {} value {}",
stix2IOC.getType().name(), feedStore.getSaTifSourceConfig().getId(),
stix2IOC.getId(), stix2IOC.getType(), stix2IOC.getValue()

Check warning on line 50 in src/main/java/org/opensearch/securityanalytics/services/STIX2IOCConsumer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/services/STIX2IOCConsumer.java#L48-L50

Added lines #L48 - L50 were not covered by tests
);
return;
}

Expand All @@ -56,7 +62,7 @@ public void accept(final STIX2 ioc) {

public void flushIOCs() {
if (queue.isEmpty()) {
return;
throw new OpenSearchStatusException("No compatible Iocs were downloaded for config " + feedStore.getSaTifSourceConfig().getName(), RestStatus.BAD_REQUEST);

Check warning on line 65 in src/main/java/org/opensearch/securityanalytics/services/STIX2IOCConsumer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/services/STIX2IOCConsumer.java#L65

Added line #L65 was not covered by tests
}

final List<STIX2IOC> iocsToFlush = new ArrayList<>(queue.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,12 @@ public void createIocAndTIFSourceConfig(
saTifSourceConfigService.deleteTIFSourceConfig(indexSaTifSourceConfigResponse, ActionListener.wrap(
deleteResponse -> {
log.debug("Successfully deleted threat intel source config [{}]", indexSaTifSourceConfigResponse.getId());
listener.onFailure(new OpenSearchException("Successfully deleted threat intel source config [{}]", indexSaTifSourceConfigResponse.getId()));
listener.onFailure(e);

Check warning on line 167 in src/main/java/org/opensearch/securityanalytics/threatIntel/service/SATIFSourceConfigManagementService.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/threatIntel/service/SATIFSourceConfigManagementService.java#L167

Added line #L167 was not covered by tests
}, ex -> {
log.error("Failed to delete threat intel source config [{}]", indexSaTifSourceConfigResponse.getId());
listener.onFailure(ex);
}
));
listener.onFailure(e);
})
);
}, e -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ protected void doExecute(Task task, GetIocFindingsRequest request, ActionListene
List<String> findingIds = request.getFindingIds();

if (findingIds != null && !findingIds.isEmpty()) {
queryBuilder.filter(QueryBuilders.termsQuery("id", findingIds));
BoolQueryBuilder findingIdsFilter = QueryBuilders.boolQuery();
findingIds.forEach(it -> findingIdsFilter.should(QueryBuilders.matchQuery("_id", it)));
queryBuilder.filter(findingIdsFilter);

Check warning on line 115 in src/main/java/org/opensearch/securityanalytics/threatIntel/transport/TransportGetIocFindingsAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/threatIntel/transport/TransportGetIocFindingsAction.java#L113-L115

Added lines #L113 - L115 were not covered by tests
}

List<String> iocIds = request.getIocIds();
Expand Down

0 comments on commit 2b4bc6c

Please sign in to comment.