grafana/pkg/services/ngalert/notifier
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
..
channels_config Alerting: Update in app documentation for customizing message and subject (#70367) 2023-06-20 12:20:01 +02:00
alertmanager_config.go Alerting: Fix Alertmanager change detection for receivers with secure settings (#71307) 2023-07-11 08:23:07 +02:00
alertmanager_test.go Alerting: Template Testing API (#67450) 2023-04-28 15:56:59 +01:00
alertmanager.go Alerting: Bump grafana/alerting and refactor the ImageStore/Provider to provide image URL/bytes (#70182) 2023-06-21 20:53:30 -03:00
alerts.go Alerting: Update to alerting 20230203015918-0e4e2675d7aa (after refactoring) (#62823) 2023-02-03 11:36:49 -05:00
compat_test.go Alerting: Update alerting module to 20230418161049-5f374e58cb32 + refactoring (#66622) 2023-04-25 13:39:46 -04:00
compat.go Alerting: Update alerting module to 20230418161049-5f374e58cb32 + refactoring (#66622) 2023-04-25 13:39:46 -04:00
config_test.go Alerting: Fix provisioned templates being ignored by alertmanager (#69485) 2023-06-02 15:47:43 -04:00
config.go Alerting: Fix provisioned templates being ignored by alertmanager (#69485) 2023-06-02 15:47:43 -04:00
crypto.go Alerting: Fix Alertmanager change detection for receivers with secure settings (#71307) 2023-07-11 08:23:07 +02:00
email_test.go Alerting: Bump grafana/alerting and refactor the ImageStore/Provider to provide image URL/bytes (#70182) 2023-06-21 20:53:30 -03:00
file_store_test.go Handle ioutil deprecations (#53526) 2022-08-10 15:37:51 +02:00
file_store.go Alerting: Improve log messages (#67688) 2023-05-25 18:55:01 +03:00
images_test.go Alerting: Bump grafana/alerting and refactor the ImageStore/Provider to provide image URL/bytes (#70182) 2023-06-21 20:53:30 -03:00
images.go Alerting: Bump grafana/alerting and refactor the ImageStore/Provider to provide image URL/bytes (#70182) 2023-06-21 20:53:30 -03:00
log.go Alerting: Update alerting module to 20230418161049-5f374e58cb32 + refactoring (#66622) 2023-04-25 13:39:46 -04:00
multiorg_alertmanager_test.go Alerting: Add endpoint to revert to a previous alertmanager configuration (#65751) 2023-04-05 14:10:03 -04:00
multiorg_alertmanager.go Alerting: Improve log messages (#67688) 2023-05-25 18:55:01 +03:00
receivers_test.go Alerting: Update alerting module to 20230418161049-5f374e58cb32 + refactoring (#66622) 2023-04-25 13:39:46 -04:00
receivers.go Alerting: Update alerting module to 20230418161049-5f374e58cb32 + refactoring (#66622) 2023-04-25 13:39:46 -04:00
redis_channel_test.go Alerting: Add support for running HA using Redis (#65267) 2023-04-19 17:05:26 +02:00
redis_channel.go Alerting: Add support for running HA using Redis (#65267) 2023-04-19 17:05:26 +02:00
redis_peer.go Alerting: Fix HA alerting membership sync (#70607) 2023-06-26 17:12:10 +01:00
sender.go Alerting: Update alerting module to 20230418161049-5f374e58cb32 + refactoring (#66622) 2023-04-25 13:39:46 -04:00
silences.go Alerting: Update to alerting 20230203015918-0e4e2675d7aa (after refactoring) (#62823) 2023-02-03 11:36:49 -05:00
status.go Alerting: Use alerting.GrafanaAlertmanager instead of initialising Alertmanager components directly (#61230) 2023-01-13 12:54:38 -04:00
templates_test.go Alerting: Template Testing API (#67450) 2023-04-28 15:56:59 +01:00
templates.go Alerting: Repurpose rule testing endpoint to return potential alerts (#69755) 2023-06-08 18:59:54 -04:00
testing.go Alerting: Bump grafana/alerting and refactor the ImageStore/Provider to provide image URL/bytes (#70182) 2023-06-21 20:53:30 -03:00