grafana/pkg/services/ngalert/api
Matthew Jacobson e3787de470
Alerting: Fix Alertmanager change detection for receivers with secure settings (#71307)
* Alerting: Make ApplyAlertmanagerConfiguration only decrypt/encrypt new/changed secure settings

Previously, ApplyAlertmanagerConfiguration would decrypt and re-encrypt all secure settings. However, this caused re-encrypted secure settings to be included in the raw configuration when applied to the embedded alertmanager, resulting in changes to the hash. Consequently, even if no actual modifications were made, saving any alertmanager configuration triggered an apply/restart and created a new historical entry in the database.

To address the issue, this modifies ApplyAlertmanagerConfiguration, which is called by POST `api/alertmanager/grafana/config/api/v1/alerts`, to decrypt and re-encrypt only new and updated secure settings. Unchanged secure settings are loaded directly from the database without alteration.

We determine whether secure settings have changed based on the following (already in-use) assumption: Only new or updated secure settings are provided via the POST `api/alertmanager/grafana/config/api/v1/alerts` request, while existing unchanged settings are omitted.

* Ensure saving a grafana-managed contact point will only send new/changed secure settings

Previously, when saving a grafana-managed contact point, empty string values were transmitted for all unset secure settings. This led to potential backend issues, as it assumed that only newly added or updated secure settings would be provided.

To address this, we now exclude empty ('', null, undefined) secure settings, unless there was a pre-existing entry in secureFields for that specific setting. In essence, this means we only transmit an empty secure setting if a previously configured value was cleared.

* Fix linting

* refactor omitEmptyUnlessExisting

* fixup

---------

Co-authored-by: Gilles De Mey <gilles.de.mey@gmail.com>
2023-07-11 08:23:07 +02:00
..
test-data Expressions: Fixes the issue showing expressions editor (#62510) 2023-01-31 18:50:10 +01:00
tooling Alerting: Fix Alertmanager change detection for receivers with secure settings (#71307) 2023-07-11 08:23:07 +02:00
api_alertmanager_guards_test.go Alerting: Fix provenance guard checks for Alertmanager configuration to not cause panic when compared nested objects (#69009) 2023-05-25 11:41:11 -04:00
api_alertmanager_guards.go Alerting: Fix provenance guard checks for Alertmanager configuration to not cause panic when compared nested objects (#69009) 2023-05-25 11:41:11 -04:00
api_alertmanager_test.go Alerting: Fix Alertmanager change detection for receivers with secure settings (#71307) 2023-07-11 08:23:07 +02:00
api_alertmanager.go RBAC: Remove legacy AC from HasAccess permission check (#68995) 2023-05-30 14:39:09 +01:00
api_configuration_test.go Chore: Rename Id to ID in alerting models (#62777) 2023-02-02 17:22:43 +01:00
api_configuration.go Chore: Remove Result field from datasources (#63048) 2023-02-09 15:49:44 +01:00
api_prometheus_test_fixtures.go Expressions: Fixes the issue showing expressions editor (#62510) 2023-01-31 18:50:10 +01:00
api_prometheus_test.go Alerting: Skip flaky test TestRouteGetRuleStatuses (#69258) 2023-05-30 09:48:02 -05:00
api_prometheus.go RBAC: Remove legacy AC from HasAccess permission check (#68995) 2023-05-30 14:39:09 +01:00
api_provisioning_test.go Fixing typos (#70487) 2023-06-22 09:43:38 +01:00
api_provisioning.go Alerting: Fix misleading status code in provisioning API (#67331) 2023-04-27 09:25:34 +01:00
api_ruler_history.go Alerting: Add limit query parameter to Loki-based ASH api, drop default limit from 5000 to 1000, extend visible time range for new ASH UI (#70769) 2023-06-28 13:32:28 -05:00
api_ruler_test.go Alerting: update rules POST API to validate query and condition only for rules that changed. (#68667) 2023-06-15 13:33:42 -04:00
api_ruler_validation_test.go Alerting: update rules POST API to validate query and condition only for rules that changed. (#68667) 2023-06-15 13:33:42 -04:00
api_ruler_validation.go Alerting: Sort RefIDs in error message returned by api.validateCondition (#70198) 2023-06-15 18:37:30 -03:00
api_ruler.go Alerting: update rules POST API to validate query and condition only for rules that changed. (#68667) 2023-06-15 13:33:42 -04:00
api_testing_test.go Alerting: update rules POST API to validate query and condition only for rules that changed. (#68667) 2023-06-15 13:33:42 -04:00
api_testing.go Alerting: Support concurrent queries for saving alert instances (#70525) 2023-06-23 11:36:07 +01:00
api.go Alerting: Repurpose rule testing endpoint to return potential alerts (#69755) 2023-06-08 18:59:54 -04:00
authorization_test.go Alerting: Template Testing API (#67450) 2023-04-28 15:56:59 +01:00
authorization.go Alerting: Update patch for #865 after #68898 (#890) 2023-06-06 13:38:37 +02:00
compat_test.go Alerting: introduce AlertQuery in definitions package (#63825) 2023-03-27 11:55:13 -04:00
compat.go Alerting: Remove dependency on alerting package in definitions (#65390) 2023-03-29 13:34:59 -04:00
configuration.go Chore: Move ReqContext to contexthandler service (#62102) 2023-01-27 08:50:36 +01:00
errors.go Alerting: Update forking request handlers to use the same errors (#52965) 2022-08-02 09:33:59 -04:00
forking_alertmanager.go Alerting: Template Testing API (#67450) 2023-04-28 15:56:59 +01:00
forking_prometheus.go Chore: Move ReqContext to contexthandler service (#62102) 2023-01-27 08:50:36 +01:00
forking_ruler.go Chore: Move ReqContext to contexthandler service (#62102) 2023-01-27 08:50:36 +01:00
generated_base_api_alertmanager.go Alerting: Template Testing API (#67450) 2023-04-28 15:56:59 +01:00
generated_base_api_configuration.go Alerting: Allow hooking into request handler functions. (#67000) 2023-04-24 18:18:44 +02:00
generated_base_api_history.go Alerting: Allow hooking into request handler functions. (#67000) 2023-04-24 18:18:44 +02:00
generated_base_api_prometheus.go Alerting: Allow hooking into request handler functions. (#67000) 2023-04-24 18:18:44 +02:00
generated_base_api_provisioning.go Alerting: Allow hooking into request handler functions. (#67000) 2023-04-24 18:18:44 +02:00
generated_base_api_ruler.go Alerting: Allow hooking into request handler functions. (#67000) 2023-04-24 18:18:44 +02:00
generated_base_api_testing.go Alerting: Repurpose rule testing endpoint to return potential alerts (#69755) 2023-06-08 18:59:54 -04:00
hooks.go Alerting: Allow hooking into request handler functions. (#67000) 2023-04-24 18:18:44 +02:00
lotex_am.go Caching: Refactor enterprise query caching middleware to a wire service (#65616) 2023-04-12 12:30:33 -04:00
lotex_prom.go Caching: Refactor enterprise query caching middleware to a wire service (#65616) 2023-04-12 12:30:33 -04:00
lotex_ruler_test.go Chore: Rename Id to ID in alerting models (#62777) 2023-02-02 17:22:43 +01:00
lotex_ruler.go Caching: Refactor enterprise query caching middleware to a wire service (#65616) 2023-04-12 12:30:33 -04:00
persist.go RBAC: remove some IsDisabled checks (#69272) 2023-05-31 09:58:57 +01:00
promql_compat_test.go Alerting: Update prometheus version (#65688) 2023-03-31 16:34:35 +02:00
promql_compat.go Alerting: Update prometheus version (#65688) 2023-03-31 16:34:35 +02:00
provisioning.go Alerting: Create endpoints for exporting in provisioning file format (#58623) 2023-01-27 11:39:16 -05:00
ruler_history.go Alerting: Add endpoint for querying state history (#62166) 2023-02-02 11:34:00 -06:00
testing_api.go Alerting: Repurpose rule testing endpoint to return potential alerts (#69755) 2023-06-08 18:59:54 -04:00
testing.go Chore: Fix goimports grouping in alerting (#62424) 2023-01-30 09:55:35 +01:00
util_test.go Alerting: update rules POST API to validate query and condition only for rules that changed. (#68667) 2023-06-15 13:33:42 -04:00
util.go RBAC: remove some IsDisabled checks (#69272) 2023-05-31 09:58:57 +01:00