-
Notifications
You must be signed in to change notification settings - Fork 75
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 get mappings view API incorrectly returning ecs path #867
Fix get mappings view API incorrectly returning ecs path #867
Conversation
@@ -356,6 +356,9 @@ private List<FieldMappingDoc> mergeFieldMappings(List<FieldMappingDoc> existingF | |||
)) { | |||
foundFieldMappingDoc = Optional.of(e); | |||
} | |||
// Additional check to see if raw field path + log type combination is already in existingFieldMappings so a new one is not inserted | |||
} else if (e.getId().contains(newFieldMapping.getRawField()) && e.getLogTypes().containsAll(newFieldMapping.getLogTypes())) { |
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.
Wasn't added by you so optional - Maybe existingFieldMapping
instead of e
. e
reads as Exception to me
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.
Is there a possibility of false positives here? Say I have a field with name field2
and then another field with name field
. If field2
is evaluated first, the contains
call would match for field
even though it's an entry for field2
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.
Yeah I agree e
is a bit confusing. I changed it to existingFieldMapping
. Also yes that false positive is a possibility. I changed the logic so that we grab the right side of the ID of the doc which corresponds to the ecs field name when we load in our predefined mappings. That way we can do an equals check instead to ensure that there are no duplicates.
ex. of document from pre-defined mapping
{
"_index": ".opensearch-sap-log-types-config",
"_id": "eventName|aws.cloudtrail.event_name",
"_score": 1,
"_source": {
"raw_field": "eventName",
"ecs": "aws.cloudtrail.event_name",
"ocsf": "api.operation",
"log_types": [
"s3",
"cloudtrail"
]
}
}
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #867 +/- ##
============================================
- Coverage 24.97% 24.79% -0.19%
+ Complexity 1043 1026 -17
============================================
Files 277 277
Lines 12771 12723 -48
Branches 1391 1403 +12
============================================
- Hits 3190 3155 -35
+ Misses 9307 9300 -7
+ Partials 274 268 -6 ☔ View full report in Codecov by Sentry. |
} else { | ||
String id = existingFieldMapping.getId(); | ||
int indexOfPipe = id.indexOf("|"); | ||
if (indexOfPipe != -1) { |
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.
Is this backwards compatible? Wondering if we will have duplicate mappings for a mapping that was generated before the pipe system was introduced (say an upgrade from an older to the current version).
I am also not very familiar with this part of the code though, so if that is not a concern, then I am good to approve.
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.
Backwards compatibility should be fine because the mapping should not have been inserted in the first place but now we're ensuring that it doesn't get generated. If they encounter this bug though I think they may need to delete the log-type-config index so that we can automatically regenerate it with the correct mappings.
@sbcd90 can we change logic to remove the code for adding any new field into this index at all during custom rule creation? |
Signed-off-by: Joanne Wang <jowg@amazon.com>
Signed-off-by: Joanne Wang <jowg@amazon.com>
19ef4e7
to
ff4f63b
Compare
25f6c50
into
opensearch-project:main
* add logic and integ tests to not add duplicate to log-types-config index Signed-off-by: Joanne Wang <jowg@amazon.com> * change naming for existingFieldMapping and change contains to equals Signed-off-by: Joanne Wang <jowg@amazon.com> --------- Signed-off-by: Joanne Wang <jowg@amazon.com> (cherry picked from commit 25f6c50)
…project#867) * add logic and integ tests to not add duplicate to log-types-config index Signed-off-by: Joanne Wang <jowg@amazon.com> * change naming for existingFieldMapping and change contains to equals Signed-off-by: Joanne Wang <jowg@amazon.com> --------- Signed-off-by: Joanne Wang <jowg@amazon.com>
…project#867) * add logic and integ tests to not add duplicate to log-types-config index Signed-off-by: Joanne Wang <jowg@amazon.com> * change naming for existingFieldMapping and change contains to equals Signed-off-by: Joanne Wang <jowg@amazon.com> --------- Signed-off-by: Joanne Wang <jowg@amazon.com>
…project#867) * add logic and integ tests to not add duplicate to log-types-config index Signed-off-by: Joanne Wang <jowg@amazon.com> * change naming for existingFieldMapping and change contains to equals Signed-off-by: Joanne Wang <jowg@amazon.com> --------- Signed-off-by: Joanne Wang <jowg@amazon.com>
* support object fields in aggregation based sigma rules (#789) Signed-off-by: Subhobrata Dey <sbcd90@gmail.com> * Fix duplicate ecs mappings which returns incorrect log index field in mapping view API (#786) (#788) * field mapping changes Signed-off-by: Joanne Wang <jowg@amazon.com> * add integ test Signed-off-by: Joanne Wang <jowg@amazon.com> * turn unmappedfieldaliases as set and add integ test Signed-off-by: Joanne Wang <jowg@amazon.com> * add comments Signed-off-by: Joanne Wang <jowg@amazon.com> * fix integ tests Signed-off-by: Joanne Wang <jowg@amazon.com> * moved logic to method for better readability Signed-off-by: Joanne Wang <jowg@amazon.com> --------- Signed-off-by: Joanne Wang <jowg@amazon.com> * Fix get mappings view API incorrectly returning ecs path (#867) * add logic and integ tests to not add duplicate to log-types-config index Signed-off-by: Joanne Wang <jowg@amazon.com> * change naming for existingFieldMapping and change contains to equals Signed-off-by: Joanne Wang <jowg@amazon.com> --------- Signed-off-by: Joanne Wang <jowg@amazon.com> * fix integ test (#918) Signed-off-by: Joanne Wang <jowg@amazon.com> * get all findings as part of findings API enhancement (#803) * get all findings as part of findings API enhancement Signed-off-by: Riya Saxena <riysaxen@amazon.com> * findingsAPI feature enhancements (address comments to prev PR) Signed-off-by: Riya Saxena <riysaxen@amazon.com> * findingsAPI feature enhancements (address comments to prev PR) Signed-off-by: Riya Saxena <riysaxen@amazon.com> * added support for param in Finding API Signed-off-by: Riya Saxena <riysaxen@amazon.com> * added detectionType as param for Findings API enhancements Signed-off-by: Riya Saxena <riysaxen@amazon.com> * added few tests to validate findings by params Signed-off-by: Riya Saxena <riysaxen@amazon.com> * added test for searchString param in FindingsAPI Signed-off-by: Riya Saxena <riysaxen@amazon.com> * adding addiional params findingIds, startTime and endTime as findings API enhancement Signed-off-by: Riya Saxena <riysaxen@amazon.com> * added params in getFindingsByDetectorId func * changed the startTime and endTime req input format * fix merge conflixt * fix integ test failures in findings API * fix integ tests * fix integ tests for findings Signed-off-by: Subhobrata Dey <sbcd90@gmail.com> --------- Signed-off-by: Riya Saxena <riysaxen@amazon.com> Signed-off-by: Riya <69919272+riysaxen-amzn@users.noreply.github.com> Signed-off-by: Subhobrata Dey <sbcd90@gmail.com> Co-authored-by: Subhobrata Dey <sbcd90@gmail.com> * Feature findings api enhancements (#914) * get all findings as part of findings API enhancement Signed-off-by: Riya Saxena <riysaxen@amazon.com> * findingsAPI feature enhancements (address comments to prev PR) Signed-off-by: Riya Saxena <riysaxen@amazon.com> * findingsAPI feature enhancements (address comments to prev PR) Signed-off-by: Riya Saxena <riysaxen@amazon.com> * added support for param in Finding API Signed-off-by: Riya Saxena <riysaxen@amazon.com> * added detectionType as param for Findings API enhancements Signed-off-by: Riya Saxena <riysaxen@amazon.com> * added few tests to validate findings by params Signed-off-by: Riya Saxena <riysaxen@amazon.com> * added test for searchString param in FindingsAPI Signed-off-by: Riya Saxena <riysaxen@amazon.com> * adding addiional params findingIds, startTime and endTime as findings API enhancement Signed-off-by: Riya Saxena <riysaxen@amazon.com> * added params in getFindingsByDetectorId func * changed the startTime and endTime req input format * fix merge conflixt * fix integ test failures in findings API * fix integ tests * refactored the logic Signed-off-by: Riya Saxena <riysaxen@amazon.com> * remove unused imports * address the pr comments Signed-off-by: Riya Saxena <riysaxen@amazon.com> * address pr comments Signed-off-by: Riya Saxena <riysaxen@amazon.com> * SA integ tests fix * SA integ tests fix * fix integ tests for findings Signed-off-by: Subhobrata Dey <sbcd90@gmail.com> * fix conflixt errors Signed-off-by: Riya Saxena <riysaxen@amazon.com> * fix conflixt errors Signed-off-by: Riya Saxena <riysaxen@amazon.com> * fix conflixt errors Signed-off-by: Riya Saxena <riysaxen@amazon.com> * fix conflixt errors Signed-off-by: Riya Saxena <riysaxen@amazon.com> * fix integ tests Signed-off-by: Riya Saxena <riysaxen@amazon.com> * fix integ tests Signed-off-by: Riya Saxena <riysaxen@amazon.com> * fix integ tests Signed-off-by: Riya Saxena <riysaxen@amazon.com> * fix flaky integ tests Signed-off-by: Riya Saxena <riysaxen@amazon.com> * address pr comments Signed-off-by: Riya Saxena <riysaxen@amazon.com> --------- Signed-off-by: Riya Saxena <riysaxen@amazon.com> Signed-off-by: Riya <69919272+riysaxen-amzn@users.noreply.github.com> Signed-off-by: Subhobrata Dey <sbcd90@gmail.com> Co-authored-by: Subhobrata Dey <sbcd90@gmail.com> * fix findings api integ tests Signed-off-by: Joanne Wang <jowg@amazon.com> --------- Signed-off-by: Subhobrata Dey <sbcd90@gmail.com> Signed-off-by: Joanne Wang <jowg@amazon.com> Signed-off-by: Riya Saxena <riysaxen@amazon.com> Signed-off-by: Riya <69919272+riysaxen-amzn@users.noreply.github.com> Co-authored-by: Subhobrata Dey <sbcd90@gmail.com> Co-authored-by: Riya <69919272+riysaxen-amzn@users.noreply.github.com>
* add logic and integ tests to not add duplicate to log-types-config index Signed-off-by: Joanne Wang <jowg@amazon.com> * change naming for existingFieldMapping and change contains to equals Signed-off-by: Joanne Wang <jowg@amazon.com> --------- Signed-off-by: Joanne Wang <jowg@amazon.com>
* add logic and integ tests to not add duplicate to log-types-config index Signed-off-by: Joanne Wang <jowg@amazon.com> * change naming for existingFieldMapping and change contains to equals Signed-off-by: Joanne Wang <jowg@amazon.com> --------- Signed-off-by: Joanne Wang <jowg@amazon.com>
* Fix duplicate ecs mappings which returns incorrect log index field in mapping view API (#786) (#788) * field mapping changes Signed-off-by: Joanne Wang <jowg@amazon.com> * add integ test Signed-off-by: Joanne Wang <jowg@amazon.com> * turn unmappedfieldaliases as set and add integ test Signed-off-by: Joanne Wang <jowg@amazon.com> * add comments Signed-off-by: Joanne Wang <jowg@amazon.com> * fix integ tests Signed-off-by: Joanne Wang <jowg@amazon.com> * moved logic to method for better readability Signed-off-by: Joanne Wang <jowg@amazon.com> --------- Signed-off-by: Joanne Wang <jowg@amazon.com> * Fix get mappings view API incorrectly returning ecs path (#867) * add logic and integ tests to not add duplicate to log-types-config index Signed-off-by: Joanne Wang <jowg@amazon.com> * change naming for existingFieldMapping and change contains to equals Signed-off-by: Joanne Wang <jowg@amazon.com> --------- Signed-off-by: Joanne Wang <jowg@amazon.com> * fix integ test (#918) Signed-off-by: Joanne Wang <jowg@amazon.com> * fix detector writeTo() method missing fields (#695) * fix detector writeTo() method missing fields Signed-off-by: Surya Sashank Nistala <snistala@amazon.com> * fix test Signed-off-by: Surya Sashank Nistala <snistala@amazon.com> --------- Signed-off-by: Surya Sashank Nistala <snistala@amazon.com> * removing threatIntel related code Signed-off-by: Riya Saxena <riysaxen@amazon.com> * removing threatIntel related code Signed-off-by: Riya Saxena <riysaxen@amazon.com> * ignore flaky tests Signed-off-by: Riya Saxena <riysaxen@amazon.com> --------- Signed-off-by: Joanne Wang <jowg@amazon.com> Signed-off-by: Surya Sashank Nistala <snistala@amazon.com> Signed-off-by: Riya Saxena <riysaxen@amazon.com> Co-authored-by: Joanne Wang <jowg@amazon.com> Co-authored-by: Surya Sashank Nistala <snistala@amazon.com>
Description
Currently the get mappings view api incorrectly returns the ecs path for logs with ocsf or raw field types if a custom rule is created using a raw field. This is because whenever a new rule is created, the rule field(s) gets indexed into
.opensearch-sap-log-types-config
index along with the log_type (ex. below). However, because there are already preset mappings defined for certain log types likecloudtrail
, the raw_field, ecs, and ocsf mappings are already defined in this index. Then when the get Mappings view API is called, the new document from the custom rule overwrites the existing predefined mapping which causes the ecs format to be incorrectly returned.This PR performs additional logic to check whether or not the raw field from the custom rule already exists in the
existingFieldMappings
(i.e. if this is a known mapping that is predefined in the index). If it is defined, then it doesn't add a the new mapping into the.opensearch-sap-log-types-config
index.The integ test ensures that the mappings view API returns the same output before and after a custom rule with a raw field is created to verify that the correct path is returned.
Issues Resolved
#866
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.