Skip to content

Alert params and action config will merge sub attributes on update if not explicitly nulled #67290

@mikecote

Description

@mikecote

Problem

Relates to #64870
Relates to #50256

If an alert type's params schema doesn't set default values of null to all it's optional properties, it is possible for an alert to fail validation of AAD when running. All someone would have to do is to create an alert with an optional value set, call the update API without the optional value set and the alert will fail running.

The same applies for action type's config schema (and possibly secrets?).

The issue happens with the following index mappings in the Elasticsearch:

"params": {
  "enabled": false,
  "type": "object"
},

The scenario can be reproduced in Elasticsearch by doing the following:
Screen Shot 2020-05-25 at 12 02 10 PM
As you can see, foo.bar didn't get cleared out after the update, it got merged.

Solutions

  1. Change update to create w/ overwrite: true

We would lose OCC (optimistic concurrency control) if there's any version conflicts but would solve the problem by replacing the existing document in elasticsearch (delete then insert). To use this solution, we'll need encrypted saved objects to support this by allowing custom ids.

  1. Stringify the params and config in Elasticsearch

Doesn't feel right but it would work.

  1. Custom code to nullify sub attributes

Since we load the alert / action on update, we could write a function that does a diff on these sub properties and sets them as null in the update params when missing.

  1. Change object structure to array

I noticed the alert's actions[x].params attribute doesn't have this problem. There is a possibility that storing alert params and action configs into an array structure would solve this problem and possibly also make them searchable.

The params value structure could be something like the following:

[
  {
    "name": "index",
    "value": "foo"
  },
  {
    "name": "timeField",
    "value": "@timestamp"
  }
]

This would allow a consistent mapping of name and value where value can be enabled: false but won't be impacted by this issue (due to being within an array). This would also require a saved object migration.

  1. Have clear documentation that optional properties must have default values

Maybe there's a way to validate this programatically.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions