-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Security Solution] Remaining bug in bulk editing index patterns of rules with a data view #138383
Comments
Pinging @elastic/security-detections-response (Team:Detections and Resp) |
Pinging @elastic/security-solution (Team: SecuritySolution) |
…or (elastic#138448) ## Summary Addresses [bug](elastic#138383) found where even when `overwrite_data_views` was false, the rule's `index` property was being modified. Please see added integration tests to understand desired behavior of changes. There is one edge case which is a bit weird, but I think too late to address in 8.4. If a user uses bulk delete on a rule with a data view and _no_ index patterns defined and `overwrite_data_views = true`, both data view and index will be set to `undefined`. Per our current behavior, a rule with no data source defaults to using the default index patterns. Not sure this is ideal, but it is in line with the behavior that already exists for a rule. (cherry picked from commit 9e8b5b9)
…or (elastic#138448) ## Summary Addresses [bug](elastic#138383) found where even when `overwrite_data_views` was false, the rule's `index` property was being modified. Please see added integration tests to understand desired behavior of changes. There is one edge case which is a bit weird, but I think too late to address in 8.4. If a user uses bulk delete on a rule with a data view and _no_ index patterns defined and `overwrite_data_views = true`, both data view and index will be set to `undefined`. Per our current behavior, a rule with no data source defaults to using the default index patterns. Not sure this is ideal, but it is in line with the behavior that already exists for a rule.
…or (elastic#138448) (elastic#138466) ## Summary Addresses [bug](elastic#138383) found where even when `overwrite_data_views` was false, the rule's `index` property was being modified. Please see added integration tests to understand desired behavior of changes. There is one edge case which is a bit weird, but I think too late to address in 8.4. If a user uses bulk delete on a rule with a data view and _no_ index patterns defined and `overwrite_data_views = true`, both data view and index will be set to `undefined`. Per our current behavior, a rule with no data source defaults to using the default index patterns. Not sure this is ideal, but it is in line with the behavior that already exists for a rule. (cherry picked from commit 9e8b5b9) Co-authored-by: Yara Tercero <[email protected]>
@banderror , @yctercero, @dhurley14 is this something that we still would like to implement, given changes in #138448, where in some of the tests, rules have both index patterns and data view ? If we still would like to enforce invariant on index and data view, I think it should be enforced somewhere on rule schema level if possible. So, that would prevent, creating rule with both index and data view in the first place, or update rule in a way: it would have both properties |
No objections to having added XOR validations. However, I think this would be considered a breaking change, so it may require review? We unfortunately don't have resources to do this work. So may be up to @peluja1012 to prioritize? |
@vitaliidm Great catch. We have this test, but there shouldn't be rules containing both index patterns and data_view_id, because:
If that is true (@yctercero please correct me if it's not), users should not end up having any rules with both
Enforcing the same invariant at the schema level would probably require much more effort. If we want to go that path, I think we should open a separate ticket for that. |
changes in this PR prevents edit that creates both index and data view properties by calling bulk API.
But, it still possible to have rule with both properties by using create/update API. Here is a simple example(similarly you can see it in test itself) curl --location --request POST 'http://localhost:5601/kbn/api/detection_engine/rules' \
--header 'kbn-xsrf: kibana' \
--header 'Authorization: Basic ZWxhc3RpYzpjaGFuZ2VtZQ==' \
--header 'Content-Type: application/json' \
--data-raw '{
"type": "query",
"filters": [],
"language": "kuery",
"query": "*:*",
"data_view_id": "logs-*",
"author": [],
"false_positives": [],
"references": [],
"risk_score": 21,
"risk_score_mapping": [],
"severity": "low",
"severity_mapping": [],
"threat": [],
"name": "test-123",
"description": "test-123",
"tags": [],
"license": "",
"interval": "5m",
"from": "now-360s",
"to": "now",
"meta": {
"from": "1m",
"kibana_siem_app_url": "http://localhost:5601/kbn/app/security"
},
"actions": [],
"enabled": false,
"throttle": "no_actions",
"index": ["test-*"]
}' So, the proper fix would be to change update/create API, so it won't allow having 2 properties at the same time. As bulk edit already doesn't allow you to do it, unless you had these properties prior to editing. See the same test I mentioned, where rule is created with both properties. I think we need to enforce it for all APIs, if it's not considered a breaking change.
|
++ what @vitaliidm mentioned. There is nothing API side preventing a user from creating a rule with both data view and index pattern. Making the change, we'd have to file it as breaking unfortunately as it breaks the existing contract in that a user submitting a rule with both (who I'm not sure why they would be doing this) would now start getting an error back. |
@vitaliidm I generally agree with your comments, that makes sense to me 👍 The first step would be to disallow creating a rule with both
I'm leaning towards the 2nd option. Users in theory could have already created some rules with both If this is done, we could additionally call Enforcing it further in the schema (e.g. in the rule "read" schema) might be not an easy thing to do -- I'd wait with making decisions on that until the issues above are resolved.
@yctercero I'm not sure I'm on board with that. Firstly, if we go with the 2nd option above, the API won't start returning errors. Secondly, even if it will, have we explicitly stated in the docs that the user can create a rule with both |
@banderror I'm going off of what core considers to be breaking here - https://docs.elastic.dev/kibana-dev-docs/standards#what-constitutes-a-breaking-change . Reading that, I would consider it breaking as the same inputs would result in a different output now. 🤷♀️ I don't know if there's any consideration given to whether or not it was documented or how "fresh" the change is. I think prior to core efforts to be more strict on breaking changes, this wouldn't of mattered, but if we're going by the book, it might be. |
Related to: #136006
Docs: elastic/security-docs#1832 (comment)
Summary
There's a leftover bug in bulk editing index patterns of rules with a data view, and the logic of
applyBulkActionEditToRuleParams
and validation that we do invalidateMutatedParams
is not entirely correct and not full. Also, this does not correspond to how we're going to document theoverwrite_data_views
parameter in elastic/security-docs#1832 (comment):This is not how it works in the code right now, and you can verify this with the following steps:
logs-*
data view.foo-*
andlogs-*
index patterns to it withoverwrite_data_views = false
.logs-*
data view and the['foo-*', 'logs-*']
index patterns. This does not correspond to the statement thatIf overwrite_data_views is set to false - no updates or changes will be made to rules using data views
logs-*
index pattern from the rule.If you have selected rules which depend on a data view this action will not have any effect on those rules.
.foo-*
index pattern from the rule.Mutated params invalid: Index patterns can't be empty
error although this is a rule with a data view and we saidIf you have selected rules which depend on a data view this action will not have any effect on those rules.
.Proposed fix
The behavior described above is caused by the fact that a rule Saved Object can have both a non-empty data view and a non-empty array of index patterns at the same time, for instance:
I think we need to enforce the following invariants in the code:
overwrite_data_views: true
).The following places in the codebase should be updated:
applyBulkActionEditToRuleParams
functionvalidateMutatedParams
of all our rule types:validateIndexPatterns(mutatedRuleParams.index)
should be changed to something likevalidateDataSource(mutatedRuleParams.index, mutatedRuleParams.dataViewId)
The text was updated successfully, but these errors were encountered: