-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Description
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:

As you can see, foo.bar didn't get cleared out after the update, it got merged.
Solutions
- 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.
- Stringify the params and config in Elasticsearch
Doesn't feel right but it would work.
- 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.
- 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.
- Have clear documentation that optional properties must have default values
Maybe there's a way to validate this programatically.