-
Notifications
You must be signed in to change notification settings - Fork 117
Add Support for Multiple Kibana Security Detection Rule Types #1292
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
base: main
Are you sure you want to change the base?
Conversation
💚 CLA has been signed |
Co-authored-by: nick-benoit <[email protected]>
…examples Co-authored-by: nick-benoit <[email protected]>
The trickiest part of this PR is sorting out
The api gives back this error if both are included:
|
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.
Pretty excellent first pass here, added a bunch of comments around using some shared utils and how we've generally tried to structure things but this is looking good.
IMO we should cover all the rule types in this PR, but I could be convinced they can be added in a follow up. We do need to cover them to consider the issue 'done' though.
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) | ||
} | ||
|
||
func (r *securityDetectionRuleResource) buildUpdateProps(ctx context.Context, data SecurityDetectionRuleData) (kbapi.SecurityDetectionsAPIRuleUpdateProps, diag.Diagnostics) { |
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.
Same as above, we should move this to the model.
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 function to be a receiver method toUpdateProps
on the SecurityDetectionRuleData struct in 828ef7a.
Looking at the acceptance test failures: The 7.17 test is failing because an expected index doesn't exist yet. I guess it wouldn't be hard to create another 7.x specific test which also first created the index, but I'm not sure it's worthwhile given it's 7.x. The 8.10 test looks like we're getting a different response from Kibana in that version. Definitely worth investigating, but given 8.10 is 2 years old I don't think it's unreasonable to skip the test in 8.10 and mention in the docs that the resource isn't compatible with 8.10. |
…feedback Co-authored-by: nick-benoit <[email protected]>
@copilot Please support all detection rule types defined in https://www.elastic.co/docs/api/doc/kibana/group/endpoint-security-detections-api This will require adding updating the schema in |
I'm implementing support for all detection rule types. I've updated the schema to support all 8 rule types (query, eql, esql, machine_learning, new_terms, saved_query, threat_match, threshold) with their specific fields, and I'm working on updating the models to handle creation and updates for each type. This is a significant change that requires updating the create, update, and read logic for all rule types. I'll commit the progress once the implementation is complete and tested. |
Co-authored-by: nick-benoit <[email protected]>
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.
I need to do some testing here as well, adding some comments in the meantime.
} | ||
} | ||
|
||
func (d SecurityDetectionRuleData) toUpdateProps(ctx context.Context) (kbapi.SecurityDetectionsAPIRuleUpdateProps, diag.Diagnostics) { |
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.
There's a lot of duplication in the create/update flows. I wonder if it would be simpler if the update code re-used the create model as an interim step. So tfModel -> createModel -> updateModel
.
I don't feel strongly here, and it might end up as more of a mess.
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. I was trying to find a clever way to reuse that logic. In general I think I prefer some duplication over assuming a false equivalence between the types. Especially when zooming out and thinking about applying this pattern with the LLM to other resources. I've been thinking through that lens as I work on this.
I'm not in love with this pattern, but we could also add something like setCommonCreateProps
, but instead of sharing common properties among all createProps it would be for the common props between the update / create for each rule type?
I'll probably think of some other ideas after stewing on it a bit as well.
stringplanmodifier.RequiresReplace(), | ||
}, | ||
}, | ||
"rule_id": schema.StringAttribute{ |
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 this be RequiresReplace
?
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.
I think so 👍
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.
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.
Actually this causes some strange behavior. The API gives us back a value when it is not provided. I made it a computed value to support this. This causes some strange behavior because when it goes from unknown -> the computed value it forces replacement.
I suppose we want something that only replaces for a non-computed value? I'm not quite sure the best way to achieve that.
Co-authored-by: Toby Brain <[email protected]>
resp.Schema = GetSchema() | ||
} | ||
|
||
func GetSchema() schema.Schema { |
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.
A careful look at the docs makes me realize there are some missing fields 😞
At least investigation_fields
, exceptions_list
(actually a bunch of nested types). I suppose maybe copilot just threw its hands in the air with the nested types?
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.
Looking good, it looks like we need to improve the case where read
gets a 404 response.
// Rule was deleted - return empty data to indicate this | ||
return data, diags |
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 isn't really returning empty
data since we initialise the defaults early on. Should the return type be a pointer so we can explicitly return nil
here?
Hmmm, new GH review UX is working well it seems. |
Co-authored-by: Toby Brain <[email protected]>
Just to make sure i'm understanding here. Are you doing something like:
Currently it looks like it then tries to create the resource as if you were creating it from scratch. What do you think the ideal handling is in a case like that? Or also it could be you tested this differently and found something more obviously broken. |
It looks like when I do the following:
It recognizes the resource is gone, and tries to create a new resource as if it never existed in the first place. What do you think the ideal handling is there? Also it could be that you tested it differently and found something more obviously broken. In either case i'm ++ on returning a pointer as you suggest below. |
…vider-elasticstack into copilot/fix-1290-2
…rride_fallback_disabled
Implements comprehensive support for Kibana Security Detection Rules with multiple rule types beyond the initial query rules.
Fixes #523
Changes Made
Core Infrastructure
Multi-Rule Type Support
Rule Type Specific Fields Added
Current Status
This implementation provides a solid foundation for all Kibana Security Detection rule types while maintaining backward compatibility and following established patterns in the codebase.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.