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

[Backport 2.x] add filter to list ioc api to fetch only from available and refreshing apis. null check for alias of ioc indices #1153

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ public void checkAndEnsureThreatIntelMonitorsDeleted(
public void getIocTypeToIndices(ActionListener<Map<String, List<String>>> listener) {
SearchRequest searchRequest = new SearchRequest(SecurityAnalyticsPlugin.JOB_INDEX_NAME);

String stateFieldName = String.format("%s.%s", SOURCE_CONFIG_FIELD, STATE_FIELD);
String stateFieldName = getStateFieldName();
BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery()
.should(QueryBuilders.matchQuery(stateFieldName, AVAILABLE.toString()));
queryBuilder.should(QueryBuilders.matchQuery(stateFieldName, REFRESHING));
Expand Down Expand Up @@ -523,4 +523,8 @@ public void getIocTypeToIndices(ActionListener<Map<String, List<String>>> listen
}
));
}

public static String getStateFieldName() {
return String.format("%s.%s", SOURCE_CONFIG_FIELD, STATE_FIELD);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
import java.util.concurrent.atomic.AtomicReference;

import static org.opensearch.securityanalytics.services.STIX2IOCFeedStore.getIocIndexAlias;
import static org.opensearch.securityanalytics.threatIntel.common.TIFJobState.AVAILABLE;
import static org.opensearch.securityanalytics.threatIntel.common.TIFJobState.REFRESHING;
import static org.opensearch.securityanalytics.threatIntel.service.SATIFSourceConfigService.getStateFieldName;

public class TransportListIOCsAction extends HandledTransportAction<ListIOCsActionRequest, ListIOCsActionResponse> implements SecureTransportAction {
private static final Logger log = LogManager.getLogger(TransportListIOCsAction.class);
Expand Down Expand Up @@ -116,8 +119,11 @@ void start() {
List<String> iocIndices = new ArrayList<>();
for (SearchHit hit : searchResponse.getHits().getHits()) {
String iocIndexAlias = getIocIndexAlias(hit.getId());
String writeIndex = IndexUtils.getWriteIndex(iocIndexAlias, clusterService.state());
iocIndices.add(writeIndex);
if (IndexUtils.isAlias(iocIndexAlias, clusterService.state())) {
String writeIndex = IndexUtils.getWriteIndex(iocIndexAlias, clusterService.state());
if (writeIndex != null)
iocIndices.add(writeIndex);
}
}
if (iocIndices.isEmpty()) {
log.info("No ioc indices found to query for given threat intel source filtering criteria {}", String.join(",", configIds));
Expand Down Expand Up @@ -263,7 +269,10 @@ private SearchSourceBuilder getFeedsSearchSourceBuilder(List<String> configIds)
}
return new SearchSourceBuilder().query(queryBuilder).size(9999);
} else {
return new SearchSourceBuilder().query(QueryBuilders.matchAllQuery()).size(9999);
BoolQueryBuilder stateQueryBuilder = QueryBuilders.boolQuery()
.should(QueryBuilders.matchQuery(getStateFieldName(), REFRESHING.toString()))
.should(QueryBuilders.matchQuery(getStateFieldName(), AVAILABLE.toString()));
return new SearchSourceBuilder().query(stateQueryBuilder).size(9999);
}
}
}
Loading