-
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
Create TIF Source Config API #1046
Create TIF Source Config API #1046
Conversation
Signed-off-by: Joanne Wang <[email protected]>
Signed-off-by: Joanne Wang <[email protected]>
@@ -103,9 +111,11 @@ public class SecurityAnalyticsPlugin extends Plugin implements ActionPlugin, Map | |||
public static final String FINDINGS_CORRELATE_URI = FINDINGS_BASE_URI + "/correlate"; | |||
public static final String LIST_CORRELATIONS_URI = PLUGINS_BASE_URI + "/correlations"; | |||
public static final String CORRELATION_RULES_BASE_URI = PLUGINS_BASE_URI + "/correlation/rules"; | |||
|
|||
public static final String TIF_CONFIG_URI = PLUGINS_BASE_URI + "/tif"; |
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.
tif source?
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.
updated to /tif/source
Signed-off-by: Joanne Wang <[email protected]>
Signed-off-by: Joanne Wang <[email protected]>
@@ -103,9 +111,12 @@ public class SecurityAnalyticsPlugin extends Plugin implements ActionPlugin, Map | |||
public static final String FINDINGS_CORRELATE_URI = FINDINGS_BASE_URI + "/correlate"; | |||
public static final String LIST_CORRELATIONS_URI = PLUGINS_BASE_URI + "/correlations"; | |||
public static final String CORRELATION_RULES_BASE_URI = PLUGINS_BASE_URI + "/correlation/rules"; | |||
|
|||
public static final String TIF_BASE_URI = PLUGINS_BASE_URI + "/tif"; |
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.
threat_intel?
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.
changed to threat_intel
@@ -103,9 +111,12 @@ public class SecurityAnalyticsPlugin extends Plugin implements ActionPlugin, Map | |||
public static final String FINDINGS_CORRELATE_URI = FINDINGS_BASE_URI + "/correlate"; | |||
public static final String LIST_CORRELATIONS_URI = PLUGINS_BASE_URI + "/correlations"; | |||
public static final String CORRELATION_RULES_BASE_URI = PLUGINS_BASE_URI + "/correlation/rules"; | |||
|
|||
public static final String TIF_BASE_URI = PLUGINS_BASE_URI + "/tif"; | |||
public static final String TIF_SOURCE_CONFIG_URI = PLUGINS_BASE_URI + "/tif/source"; |
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.
threat_intel/source?
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.
changed to threat_intel/source
@@ -129,6 +140,9 @@ public class SecurityAnalyticsPlugin extends Plugin implements ActionPlugin, Map | |||
private BuiltinLogTypeLoader builtinLogTypeLoader; | |||
|
|||
private LogTypeService logTypeService; | |||
|
|||
private SATIFSourceConfigDao satifSourceConfigDao; |
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.
SaTifSourceConfigDao*
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.
fixed
@@ -211,13 +228,14 @@ public List<RestHandler> getRestHandlers(Settings settings, | |||
new RestSearchCorrelationRuleAction(), | |||
new RestIndexCustomLogTypeAction(), | |||
new RestSearchCustomLogTypeAction(), | |||
new RestDeleteCustomLogTypeAction() | |||
new RestDeleteCustomLogTypeAction(), | |||
new RestIndexTIFConfigAction() |
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.
RestIndexTIFSourceConfigAction
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.
fixed
case FEED_SOURCE_CONFIG_FIELD: | ||
return SATIFSourceConfig.parse(xcp, id, null); | ||
default: | ||
log.warn("Unsupported document was indexed"); |
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.
log level should be error
re-word message to make it more descriptive
message should include job parser failed
, $fieldName
(value), in security analytics job registration
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.
reworded error message
xcp.nextToken(); | ||
switch (fieldName) { | ||
case FEED_SOURCE_CONFIG_FIELD: | ||
return SATIFSourceConfig.parse(xcp, id, null); |
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.
why is the third param null
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.
Will address this in a future PR, need to understand what params should be used for parser
public class SAIndexTIFSourceConfigRequest extends ActionRequest implements IndexTIFSourceConfigRequest { | ||
private static final ParameterValidator VALIDATOR = new ParameterValidator(); | ||
private String tifSourceConfigId; | ||
private final WriteRequest.RefreshPolicy refreshPolicy; |
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.
dont accept param. always IMMEDIATE REFRESH
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.
removed param
private final String tifConfigId; | ||
private final Long version; | ||
private final RestStatus status; | ||
private final SATIFSourceConfigDto saTIFConfigDto; |
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.
if a word is an a acronym let's make it liek SaTifSourceConfigDto
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.
fixed
|
||
public void indexTIFSourceConfig(SATIFSourceConfig satifSourceConfig, | ||
TimeValue indexTimeout, | ||
WriteRequest.RefreshPolicy refreshPolicy, |
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.
should always be refresh immediate. remove param
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.
removed
public void indexTIFSourceConfig(SATIFSourceConfig satifSourceConfig, | ||
TimeValue indexTimeout, | ||
WriteRequest.RefreshPolicy refreshPolicy, | ||
final ActionListener<SATIFSourceConfig> actionListener) throws Exception { |
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.
throws Exception is not needed
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.
removed
.source(satifSourceConfig.toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS)) | ||
.timeout(indexTimeout); | ||
log.debug("Indexing tif source config"); | ||
client.index(indexRequest, new ActionListener<>() { |
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.
use only ActionListener.wrap()
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.
changed to ActionListener.wrap()
} | ||
@Override | ||
public void onFailure(Exception e) { | ||
throw new SecurityAnalyticsException("Exception saving the tif source config in index", RestStatus.INTERNAL_SERVER_ERROR, e); |
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.
use listener.onFailure don't re-throw
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.
done
TimeValue indexTimeout, | ||
WriteRequest.RefreshPolicy refreshPolicy, | ||
final ActionListener<SATIFSourceConfig> actionListener) throws Exception { | ||
IndexRequest indexRequest = new IndexRequest(SecurityAnalyticsPlugin.JOB_INDEX_NAME) |
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.
wrap entire logic in try-catch and listener.onFailure + log message in catch block
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.
done
client.index(indexRequest, new ActionListener<>() { | ||
@Override | ||
public void onResponse(IndexResponse response) { | ||
log.debug("TIF source config indexed success."); |
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.
we need to log the document id.
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.
logged id in message
@Override | ||
public void onResponse(IndexResponse response) { | ||
log.debug("TIF source config indexed success."); | ||
satifSourceConfig.setId(response.getId()); |
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.
copy to new object.
} | ||
} catch (IOException e) { | ||
log.error("Runtime exception when getting the threat intel index mapping", e); | ||
throw new SecurityAnalyticsException("Runtime exception when getting the threat intel index mapping", RestStatus.INTERNAL_SERVER_ERROR, e); |
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.
Message can be "Failed to get threat intel index mapping"
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.
Changed message
Signed-off-by: Joanne Wang <[email protected]>
stepListener.onResponse(null); | ||
return; | ||
} | ||
log.error("Failed to create security analytics threat intel job index", e); |
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.
nit: log correct index name in message
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.
Changed to log the index name in error message
|
||
import org.opensearch.core.action.ActionListener; | ||
public interface TIFSourceConfigDao { | ||
IndexTIFSourceConfigResponse indexTIFConfig(IndexTIFSourceConfigRequest request, ActionListener <IndexTIFSourceConfigResponse> listener); |
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.
response would be at transport and rest layer?
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.
Renamed to TIFSourceConfigService and changed to abstract class, will follow up on implementation in future PR.
log.error("failed to release lock", exception); | ||
listener.onFailure(exception); | ||
}); | ||
SaTifSourceConfigDao.createJobIndexIfNotExists(createIndexStepListener); |
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.
this should be done in dao itself before create
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.
moved the function invocation to the dao
Signed-off-by: Joanne Wang <[email protected]>
Signed-off-by: Joanne Wang <[email protected]>
Signed-off-by: Joanne Wang <[email protected]>
@@ -179,7 +179,7 @@ public Collection<Object> createComponents(Client client, | |||
TIFJobParameterService tifJobParameterService = new TIFJobParameterService(client, clusterService); | |||
TIFJobUpdateService tifJobUpdateService = new TIFJobUpdateService(clusterService, tifJobParameterService, threatIntelFeedDataService, builtInTIFMetadataLoader); | |||
TIFLockService threatIntelLockService = new TIFLockService(clusterService, client); | |||
SaTifSourceConfigDao = new SATIFSourceConfigDao(client, clusterService, threadPool); |
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.
what is this lock service??
actionListener.onFailure(e); | ||
} | ||
}, exception -> { | ||
lockService.releaseLock(lock); |
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.
what does this lockservice achieve??
public interface TIFSourceConfigDao { | ||
IndexTIFSourceConfigResponse indexTIFConfig(IndexTIFSourceConfigRequest request, ActionListener <IndexTIFSourceConfigResponse> listener); | ||
public abstract class TIFSourceConfigService { | ||
IndexTIFSourceConfigResponse indexTIFConfig(IndexTIFSourceConfigRequest request, ActionListener <IndexTIFSourceConfigResponse> listener){ |
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.
method should be abstract
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.
plz address comments in followup PR
1935ed2
into
opensearch-project:feature/threat_intel
* create tif source config api implementation Signed-off-by: Joanne Wang <[email protected]> * clean up Signed-off-by: Joanne Wang <[email protected]> * tif/source Signed-off-by: Joanne Wang <[email protected]> * fix uri Signed-off-by: Joanne Wang <[email protected]> * comments Signed-off-by: Joanne Wang <[email protected]> * fix error message Signed-off-by: Joanne Wang <[email protected]> * moved createIndex invocation and other comments Signed-off-by: Joanne Wang <[email protected]> --------- Signed-off-by: Joanne Wang <[email protected]>
* create tif source config api implementation Signed-off-by: Joanne Wang <[email protected]> * clean up Signed-off-by: Joanne Wang <[email protected]> * tif/source Signed-off-by: Joanne Wang <[email protected]> * fix uri Signed-off-by: Joanne Wang <[email protected]> * comments Signed-off-by: Joanne Wang <[email protected]> * fix error message Signed-off-by: Joanne Wang <[email protected]> * moved createIndex invocation and other comments Signed-off-by: Joanne Wang <[email protected]> --------- Signed-off-by: Joanne Wang <[email protected]>
* create tif source config api implementation Signed-off-by: Joanne Wang <[email protected]> * clean up Signed-off-by: Joanne Wang <[email protected]> * tif/source Signed-off-by: Joanne Wang <[email protected]> * fix uri Signed-off-by: Joanne Wang <[email protected]> * comments Signed-off-by: Joanne Wang <[email protected]> * fix error message Signed-off-by: Joanne Wang <[email protected]> * moved createIndex invocation and other comments Signed-off-by: Joanne Wang <[email protected]> --------- Signed-off-by: Joanne Wang <[email protected]>
* create tif source config api implementation Signed-off-by: Joanne Wang <[email protected]> * clean up Signed-off-by: Joanne Wang <[email protected]> * tif/source Signed-off-by: Joanne Wang <[email protected]> * fix uri Signed-off-by: Joanne Wang <[email protected]> * comments Signed-off-by: Joanne Wang <[email protected]> * fix error message Signed-off-by: Joanne Wang <[email protected]> * moved createIndex invocation and other comments Signed-off-by: Joanne Wang <[email protected]> --------- Signed-off-by: Joanne Wang <[email protected]>
* create tif source config api implementation Signed-off-by: Joanne Wang <[email protected]> * clean up Signed-off-by: Joanne Wang <[email protected]> * tif/source Signed-off-by: Joanne Wang <[email protected]> * fix uri Signed-off-by: Joanne Wang <[email protected]> * comments Signed-off-by: Joanne Wang <[email protected]> * fix error message Signed-off-by: Joanne Wang <[email protected]> * moved createIndex invocation and other comments Signed-off-by: Joanne Wang <[email protected]> --------- Signed-off-by: Joanne Wang <[email protected]>
Description
Preliminary architecture and flow for creating a job index and indexing a source config object.
Issues Resolved
[List any issues this PR will resolve]
Check List
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.