Skip to content
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

Set ignore_malformed=true on .alerts-* indices #161465

Closed
kobelb opened this issue Jul 7, 2023 · 7 comments · Fixed by #163414 or #165781
Closed

Set ignore_malformed=true on .alerts-* indices #161465

kobelb opened this issue Jul 7, 2023 · 7 comments · Fixed by #163414 or #165781
Assignees
Labels
Feature:Alerting/Alerts-as-Data Issues related to Alerts-as-data and RuleRegistry Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams)

Comments

@kobelb
Copy link
Contributor

kobelb commented Jul 7, 2023

Feature Description

Currently, the .alerts-* indices do not have ignore_malformed set. As a result, alerting rule implementors are responsible for ensuring that the alerts they generate are compatible with the mappings of the associated .alert-* indices. If the alerts aren't compatible, then the alert documents will NOT be created and our users will miss alerts.

The security solution team has had to implement rather complex logic to strip non-compliant fields from their alert documents. By setting ignored_malformed on the alert indices, this would potentially reduce the complexity of the logic stripping alert fields and act as a fallback to ensure that alert documents are created in as many situations as possible.

However, we should be aware of the caveat that ignore_malformed does not work on all data-types, so we should not be solely relying on this setting and alerting rule implementors should still do their absolute best to ensure alerts are compatible with the mappings.

Business Value

Reduce the likelihood of missed alerts.

Definition of Done

  • .alerts-* indices have ignore_malformed set
  • regression testing performed to ensure this setting does not detrimentally alter the behavior of alert creation/updates
@kobelb kobelb added Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) Feature:Alerting/Alerts-as-Data Issues related to Alerts-as-data and RuleRegistry labels Jul 7, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

@mikecote mikecote moved this from Awaiting Triage to Todo in AppEx: ResponseOps - Execution & Connectors Jul 13, 2023
@ymao1 ymao1 self-assigned this Aug 8, 2023
@ymao1 ymao1 moved this from Todo to In Progress in AppEx: ResponseOps - Execution & Connectors Aug 8, 2023
@ymao1 ymao1 moved this from In Progress to In Review in AppEx: ResponseOps - Execution & Connectors Aug 8, 2023
ymao1 added a commit that referenced this issue Aug 9, 2023
…ex template settings (#163414)

Resolves #161465

## Summary

Adds `ignore_malformed: true` to alerts index template settings. This
ignores malformed content globally across all allowed mapping types. For
existing alerts as data indices, the new setting is not applied directly
to the existing concrete indices but will be applied whenever the alias
rolls over and a new concrete index is created.

## Verify

- Verify that after upgrading alerts indices created in an older version
to this branch, alerts continue to be written and read as expected.

---------

Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Vitalii Dmyterko <[email protected]>
bryce-b pushed a commit to bryce-b/kibana that referenced this issue Aug 9, 2023
…ex template settings (elastic#163414)

Resolves elastic#161465

## Summary

Adds `ignore_malformed: true` to alerts index template settings. This
ignores malformed content globally across all allowed mapping types. For
existing alerts as data indices, the new setting is not applied directly
to the existing concrete indices but will be applied whenever the alias
rolls over and a new concrete index is created.

## Verify

- Verify that after upgrading alerts indices created in an older version
to this branch, alerts continue to be written and read as expected.

---------

Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Vitalii Dmyterko <[email protected]>
@ymao1
Copy link
Contributor

ymao1 commented Aug 10, 2023

Reverted due to possible bug with ignore_malformed and datastreams. #163610 . Elasticsearch issue: elastic/elasticsearch#98511

When that issue is fixed, we can revert this revert.

@mbudge
Copy link

mbudge commented Aug 15, 2023

We raised this 2 years ago after seeing indicator_match alerts not being raised because of the user_agent field.

Ignore_malformed sounds like the best way to fix this issue.

@pmuellr
Copy link
Member

pmuellr commented Aug 16, 2023

As a work-around for the problem with ignored_maformed: true on data streams, a solution is to remove @timestamp from the mappings, as data streams will create one automatically if it's not in the mappings. And let you use ignore_malformed: true at the index level.

See elastic/elasticsearch#98511 for more details. Sounds like we might change the way this works in the future to allow the original code to work (using the setting AND having a @timestamp mapping), but TBD.

@mikecote
Copy link
Contributor

@pmuellr thanks for the update, does that mean we're unblocked and we can go forward with the approach you described?

a solution is to remove @timestamp from the mappings, as data streams will create one automatically if it's not in the mappings. And let you use ignore_malformed: true at the index level.

Seems reasonable to me.

@pmuellr
Copy link
Member

pmuellr commented Aug 21, 2023

does that mean we're unblocked and we can go forward with the approach you described?

We are unblocked; but we'll need to change the mappings for serverless to remove the @timestamp field. Suggest we treat this as blocked on #154266, where we'll have structure to make this easy.

@pmuellr
Copy link
Member

pmuellr commented Aug 30, 2023

My original testing for this was broken somehow. I thought it wasn't possible to use an index-level setting for ignore_malformed and then override the setting for just `@timestamp. But apparently you can - now anyway., suggested by felix: elastic/elasticsearch#98511 (comment) .

Not sure if we want to use the same template for data streams / indices, or have them differ just by the @timestamp setting of ignore_malformed. Having them the same is easier, but making them differ won't be hard either.

Here's a complete incantation that works:

PUT _index_template/pmuellr-index-template
{
  "index_patterns": ["pmuellr-data-stream"],
  "data_stream": { },
  "template": {
    "settings": {
      "index.mapping.ignore_malformed": true 
    },
    "mappings": {
      "properties": {
        "@timestamp": {
          "ignore_malformed": false,
          "type": "date"
        },
        "message": {
          "type": "text"
        }
      }      
    }
  }
}

@mikecote mikecote moved this from Blocked / On hold to Todo in AppEx: ResponseOps - Execution & Connectors Sep 1, 2023
@pmuellr pmuellr self-assigned this Sep 1, 2023
@mikecote mikecote moved this from Todo to In Progress in AppEx: ResponseOps - Execution & Connectors Sep 7, 2023
pmuellr added a commit to pmuellr/kibana that referenced this issue Sep 8, 2023
Resolves elastic#161465

This is a re-do of elastic#163414, which
we had to revert since data streams do not support `ignore_malformed`
on the `@timestamp` field.  We now specifically add `ignore_malformed: false`
for that field, and then use `ignore_malformed: true` at the index level.

This ignores malformed content globally across all allowed mapping types.
For existing alerts as data indices, the new setting is not applied
directly to the existing concrete indices but will be applied whenever
the alias rolls over and a new concrete index is created.

- Verify that after upgrading alerts indices created in an older version
to this branch, alerts continue to be written and read as expected.
pmuellr added a commit that referenced this issue Sep 14, 2023
Resolves #161465

This is a re-do of #163414, which
we had to revert since data streams do not support `ignore_malformed` on
the `@timestamp` field. We now specifically add `ignore_malformed:
false` for that field, and then use `ignore_malformed: true` at the
index level.

This ignores malformed content globally across all allowed mapping
types. For existing alerts as data indices, the new setting is not
applied directly to the existing concrete indices but will be applied
whenever the alias rolls over and a new concrete index is created.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Alerting/Alerts-as-Data Issues related to Alerts-as-data and RuleRegistry Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams)
Projects
No open projects
6 participants