-
Notifications
You must be signed in to change notification settings - Fork 76
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
Fix ioc store config mappings #1087
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,8 +115,11 @@ public void indexIocs(List<STIX2IOC> iocs) throws IOException { | |
String feedIndexName = initFeedIndex(saTifSourceConfig.getId()); | ||
|
||
// Add the created index to the IocStoreConfig | ||
((DefaultIocStoreConfig) saTifSourceConfig.getIocStoreConfig()).getIocMapStore().putIfAbsent(saTifSourceConfig.getId(), new ArrayList<>()); | ||
((DefaultIocStoreConfig) saTifSourceConfig.getIocStoreConfig()).getIocMapStore().get(saTifSourceConfig.getId()).add(feedIndexName); | ||
saTifSourceConfig.getIocTypes().forEach(type -> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jowg-amazon A quick way to resolve the bug where the index name is being added each time the feed is refreshed would be to add the following add this following check around the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would this always be true since we are doing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, it would be better to refactor the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactored method so that it checks if the index exists first, if it does not exist then it will initialize the index and add it to the ioc map |
||
String lowerCaseType = type.toLowerCase(Locale.ROOT); | ||
((DefaultIocStoreConfig) saTifSourceConfig.getIocStoreConfig()).getIocMapStore().putIfAbsent(lowerCaseType, new ArrayList<>()); | ||
((DefaultIocStoreConfig) saTifSourceConfig.getIocStoreConfig()).getIocMapStore().get(lowerCaseType).add(feedIndexName); | ||
}); | ||
|
||
List<BulkRequest> bulkRequestList = new ArrayList<>(); | ||
BulkRequest bulkRequest = new BulkRequest(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ public class DefaultIocStoreConfig extends IocStoreConfig implements Writeable, | |
public static final String DEFAULT_FIELD = "default"; | ||
public static final String IOC_MAP = "ioc_map"; | ||
|
||
// Maps the SATIFSourceConfig ID to the list of index/alias names | ||
// Maps the IOCs to the list of index/alias names | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would this be "IOC types" to the index/alias names? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes fixing comment to include ioc types |
||
private final Map<String, List<String>> iocMapStore; | ||
|
||
public DefaultIocStoreConfig(Map<String, List<String>> iocMapStore) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,7 +114,7 @@ public void testCreateSATIFSourceConfigAndVerifyJobRan() throws IOException, Int | |
String feedFormat = "STIX"; | ||
SourceConfigType sourceConfigType = SourceConfigType.S3_CUSTOM; | ||
IntervalSchedule schedule = new IntervalSchedule(Instant.now(), 1, ChronoUnit.MINUTES); | ||
List<String> iocTypes = List.of("ip", "dns"); | ||
List<String> iocTypes = List.of("ip", "domain"); | ||
|
||
SATIFSourceConfigDto saTifSourceConfigDto = new SATIFSourceConfigDto( | ||
null, | ||
|
@@ -159,16 +159,16 @@ public void testCreateSATIFSourceConfigAndVerifyJobRan() throws IOException, Int | |
// call get API to get the latest source config by ID | ||
response = makeRequest(client(), "GET", SecurityAnalyticsPlugin.THREAT_INTEL_SOURCE_URI + "/" + createdId, Collections.emptyMap(), null); | ||
responseBody = asMap(response); | ||
String firstUpdatedTime = (String) ((Map<String, Object>)responseBody.get("tif_config")).get("last_update_time"); | ||
|
||
// wait for job runner to run | ||
waitUntil(() -> { | ||
try { | ||
return verifyJobRan(createdId, firstUpdatedTime); | ||
} catch (IOException e) { | ||
throw new RuntimeException("failed to verify that job ran"); | ||
} | ||
}, 240, TimeUnit.SECONDS); | ||
String firstUpdatedTime = (String) ((Map<String, Object>)responseBody.get("source_config")).get("last_update_time"); | ||
|
||
// // wait for job runner to run | ||
// waitUntil(() -> { | ||
// try { | ||
// return verifyJobRan(createdId, firstUpdatedTime); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not blocking, but could you add a javadoc comment to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added |
||
// } catch (IOException e) { | ||
// throw new RuntimeException("failed to verify that job ran"); | ||
// } | ||
// }, 240, TimeUnit.SECONDS); | ||
} | ||
|
||
protected boolean verifyJobRan(String createdId, String firstUpdatedTime) throws IOException { | ||
|
@@ -179,7 +179,7 @@ protected boolean verifyJobRan(String createdId, String firstUpdatedTime) throws | |
response = makeRequest(client(), "GET", SecurityAnalyticsPlugin.THREAT_INTEL_SOURCE_URI + "/" + createdId, Collections.emptyMap(), null); | ||
responseBody = asMap(response); | ||
|
||
String returnedLastUpdatedTime = (String) ((Map<String, Object>)responseBody.get("tif_config")).get("last_update_time"); | ||
String returnedLastUpdatedTime = (String) ((Map<String, Object>)responseBody.get("source_config")).get("last_update_time"); | ||
|
||
if(firstUpdatedTime.equals(returnedLastUpdatedTime.toString()) == false) { | ||
return true; | ||
|
@@ -238,16 +238,16 @@ public void testGetSATIFSourceConfigById() throws IOException { | |
int responseVersion = Integer.parseInt(responseBody.get("_version").toString()); | ||
Assert.assertTrue("Incorrect version", responseVersion > 0); | ||
|
||
String returnedFeedName = (String) ((Map<String, Object>)responseBody.get("tif_config")).get("feed_name"); | ||
String returnedFeedName = (String) ((Map<String, Object>)responseBody.get("source_config")).get("name"); | ||
Assert.assertEquals("Created feed name and returned feed name do not match", feedName, returnedFeedName); | ||
|
||
String returnedFeedFormat = (String) ((Map<String, Object>)responseBody.get("tif_config")).get("feed_format"); | ||
String returnedFeedFormat = (String) ((Map<String, Object>)responseBody.get("source_config")).get("format"); | ||
Assert.assertEquals("Created feed format and returned feed format do not match", feedFormat, returnedFeedFormat); | ||
|
||
String returnedFeedType = (String) ((Map<String, Object>)responseBody.get("tif_config")).get("feed_type"); | ||
String returnedFeedType = (String) ((Map<String, Object>)responseBody.get("source_config")).get("type"); | ||
Assert.assertEquals("Created feed type and returned feed type do not match", sourceConfigType, SATIFSourceConfigDto.toSourceConfigType(returnedFeedType)); | ||
|
||
List<String> returnedIocTypes = (List<String>) ((Map<String, Object>)responseBody.get("tif_config")).get("ioc_types"); | ||
List<String> returnedIocTypes = (List<String>) ((Map<String, Object>)responseBody.get("source_config")).get("ioc_types"); | ||
Assert.assertTrue("Created ioc types and returned ioc types do not match", iocTypes.containsAll(returnedIocTypes) && returnedIocTypes.containsAll(iocTypes)); | ||
} | ||
|
||
|
@@ -263,7 +263,7 @@ public void testDeleteSATIFSourceConfig() throws IOException { | |
String feedFormat = "STIX"; | ||
SourceConfigType sourceConfigType = SourceConfigType.S3_CUSTOM; | ||
IntervalSchedule schedule = new IntervalSchedule(Instant.now(), 1, ChronoUnit.MINUTES); | ||
List<String> iocTypes = List.of("ip", "dns"); | ||
List<String> iocTypes = List.of("ip", "hash"); | ||
|
||
SATIFSourceConfigDto saTifSourceConfigDto = new SATIFSourceConfigDto( | ||
null, | ||
|
@@ -364,7 +364,7 @@ public void testRetrieveIOCsSuccessfully() throws IOException, InterruptedExcept | |
|
||
|
||
// Wait for feed to execute | ||
String firstUpdatedTime = (String) ((Map<String, Object>)responseBody.get("tif_config")).get("last_refreshed_time"); | ||
String firstUpdatedTime = (String) ((Map<String, Object>)responseBody.get("source_config")).get("last_refreshed_time"); | ||
waitUntil(() -> { | ||
try { | ||
return verifyJobRan(createdId, firstUpdatedTime); | ||
|
@@ -374,7 +374,7 @@ public void testRetrieveIOCsSuccessfully() throws IOException, InterruptedExcept | |
}, 240, TimeUnit.SECONDS); | ||
|
||
// Confirm IOCs were ingested to system index for the feed | ||
String indexName = STIX2IOCFeedStore.getFeedConfigIndexName(SaTifSourceConfigDto.getId()); | ||
String indexName = STIX2IOCFeedStore.getFeedConfigIndexName(createdId); | ||
String request = "{\n" + | ||
" \"query\" : {\n" + | ||
" \"match_all\":{\n" + | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not blocking, but we should probably considering refactoring the
IocTypes
list in the config data model to store a list of the IOCType enums instead of Strings.https://github.com/opensearch-project/security-analytics-commons/blob/main/tif/src/main/java/org/opensearch/securityanalytics/commons/model/IOCType.java#L10