Skip to content

Conversation

@nick-benoit
Copy link
Contributor

@nick-benoit nick-benoit commented Nov 27, 2025

Adds security exception item resource (docs)

Rel: #1332

@nick-benoit nick-benoit force-pushed the add_security_exception_item branch from 0eb08b1 to 4fc1308 Compare November 27, 2025 19:56
@nick-benoit nick-benoit requested a review from Copilot December 1, 2025 19:10
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new elasticstack_kibana_security_exception_item resource for managing Kibana security exception items. Exception items define specific query conditions to prevent detection rules from generating alerts.

Key Changes

  • New resource implementation with comprehensive CRUD operations
  • Support for multiple entry types (match, match_any, list, exists, nested, wildcard)
  • Extensive validation logic for entry configurations
  • Full test coverage including unit tests for different entry types and validation scenarios

Reviewed changes

Copilot reviewed 38 out of 38 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
provider/plugin_framework.go Registers the new exception item resource in the provider
internal/kibana/security_exception_item/*.go Core implementation files (schema, CRUD operations, models, validation)
internal/kibana/security_exception_item/testdata/* Terraform test configurations for acceptance tests
internal/kibana/security_exception_item/acc_test.go Comprehensive acceptance test suite
examples/resources/elasticstack_kibana_security_exception_item/resource.tf Example usage documentation
CODING_STANDARDS.md Updated with new coding guidelines

@elastic elastic deleted a comment from Copilot AI Dec 1, 2025
@nick-benoit nick-benoit requested a review from tobio December 1, 2025 19:13
@nick-benoit nick-benoit marked this pull request as ready for review December 1, 2025 19:18
},
},
},
"expire_time": schema.StringAttribute{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems there is an issue where if a round second is provided then the go client doesn't send the milliseconds and generates a 400 from kibana

So eg "2027-12-31T23:59:59.001Z" works and "2027-12-31T23:59:59.000Z" does not. Still trying to find an elegant solution to this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Golang will format times as RFC3339 in JSON which isn't strictly compatible with the API spec. I wonder if we should remove the format: date-time from Security_Exceptions_API_ExceptionListItemExpireTime so we can take control of the string formatting ourselves?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think that is probably the best bet

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added that here: 4e4b02d

I added custom serialization that always includes the millis. It seems that since this is a subset of RFC3339 we can still use that for deserialization.

@tobio tobio requested a review from Copilot December 2, 2025 21:02
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 46 out of 48 changed files in this pull request and generated 17 comments.

switch entryType {
case "match", "wildcard":
// 'value' is required (only validate if not unknown)
if entry.Value.IsNull() {
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validation checks only for null values but doesn't check for unknown values. When values are unknown (e.g., references to resources not yet created), they should be skipped from validation. Use utils.IsKnown(entry.Value) instead to properly handle both null and unknown cases, consistent with the pattern used elsewhere in the file (lines 37, 54).

Suggested change
if entry.Value.IsNull() {
if !utils.IsKnown(entry.Value) {
// skip validation if value is unknown
} else if entry.Value.IsNull() {

Copilot uses AI. Check for mistakes.
)
}
// 'operator' is required (only validate if not unknown)
if entry.Operator.IsNull() {
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiple validation checks use IsNull() without checking for unknown values. These should all use utils.IsKnown() instead to properly skip validation when values are unknown (e.g., from resource references). This is critical for Terraform's two-phase execution model where unknown values are common during planning.

Copilot uses AI. Check for mistakes.
Comment on lines +80 to +87
if entry.Values.IsNull() {
diags.AddError(
"Missing Required Field",
fmt.Sprintf("Entry type 'match_any' requires 'values' to be set at %s.", entryPath),
)
}
// 'operator' is required (only validate if not unknown)
if entry.Operator.IsNull() {
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiple validation checks use IsNull() without checking for unknown values. These should all use utils.IsKnown() instead to properly skip validation when values are unknown (e.g., from resource references). This is critical for Terraform's two-phase execution model where unknown values are common during planning.

Suggested change
if entry.Values.IsNull() {
diags.AddError(
"Missing Required Field",
fmt.Sprintf("Entry type 'match_any' requires 'values' to be set at %s.", entryPath),
)
}
// 'operator' is required (only validate if not unknown)
if entry.Operator.IsNull() {
if utils.IsKnown(entry.Values) && entry.Values.IsNull() {
diags.AddError(
"Missing Required Field",
fmt.Sprintf("Entry type 'match_any' requires 'values' to be set at %s.", entryPath),
)
}
// 'operator' is required (only validate if not unknown)
if utils.IsKnown(entry.Operator) && entry.Operator.IsNull() {

Copilot uses AI. Check for mistakes.
)
}
// 'operator' is required (only validate if not unknown)
if entry.Operator.IsNull() {
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiple validation checks use IsNull() without checking for unknown values. These should all use utils.IsKnown() instead to properly skip validation when values are unknown (e.g., from resource references). This is critical for Terraform's two-phase execution model where unknown values are common during planning.

Copilot uses AI. Check for mistakes.

case "list":
// 'list' object is required (only validate if not unknown)
if entry.List.IsNull() {
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiple validation checks use IsNull() without checking for unknown values. These should all use utils.IsKnown() instead to properly skip validation when values are unknown (e.g., from resource references). This is critical for Terraform's two-phase execution model where unknown values are common during planning.

Copilot uses AI. Check for mistakes.
}

// 'operator' is always required for nested entries (only validate if not unknown)
if entry.Operator.IsNull() {
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiple validation checks use IsNull() without checking for unknown values. These should all use utils.IsKnown() instead to properly skip validation when values are unknown (e.g., from resource references). This is critical for Terraform's two-phase execution model where unknown values are common during planning.

Suggested change
if entry.Operator.IsNull() {
if utils.IsKnown(entry.Operator) && entry.Operator.IsNull() {

Copilot uses AI. Check for mistakes.
Copy link
Member

@tobio tobio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good in general.

}

// toUpdateRequest converts the Terraform model to API update request
func (m *ExceptionItemModel) toUpdateRequest(ctx context.Context, resourceId string, client clients.MinVersionEnforceable) (*kbapi.UpdateExceptionListItemJSONRequestBody, diag.Diagnostics) {
Copy link
Member

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 between toCreate and toUpdate. I wonder if we can just build the update request from the create request, or reuse some of the common code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of this approach? a4da71b

This is kind of similar to what we did in security detection rules

nick-benoit and others added 6 commits December 2, 2025 15:36
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Member

@tobio tobio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tobio
Copy link
Member

tobio commented Dec 3, 2025

It looks like the acceptance tests have become pretty flaky with these exception list resources?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants