Alerting: Store sensitive settings encrypted for OpsGenie notifier (#27074)

* encrypt OpsGenie API key

* make whitespace consistent

* update docs
This commit is contained in:
Will Browne 2020-08-20 16:05:48 +02:00 committed by GitHub
parent 6b2d44416d
commit 9f2386a219
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 34 deletions

View File

@ -511,12 +511,12 @@ The following sections detail the supported settings and secure settings for eac
#### Alert notification `opsgenie` #### Alert notification `opsgenie`
| Name | | Name | Secure setting |
| ---------------- | | ---------------- | - |
| apiKey | | apiKey | yes |
| apiUrl | | apiUrl | |
| autoClose | | autoClose | |
| overridePriority | | overridePriority | |
#### Alert notification `telegram` #### Alert notification `telegram`

View File

@ -19,33 +19,46 @@ func init() {
Heading: "OpsGenie settings", Heading: "OpsGenie settings",
Factory: NewOpsGenieNotifier, Factory: NewOpsGenieNotifier,
OptionsTemplate: ` OptionsTemplate: `
<h3 class="page-heading">OpsGenie settings</h3> <h3 class="page-heading">OpsGenie settings</h3>
<div class="gf-form"> <div class="gf-form">
<span class="gf-form-label width-14">API Key</span> <label class="gf-form-label max-width-14">API Key</label>
<input type="text" required class="gf-form-input max-width-22" ng-model="ctrl.model.settings.apiKey" placeholder="OpsGenie API Key"></input> <div class="gf-form gf-form--grow" ng-if="!ctrl.model.secureFields.apiKey">
</div> <input type="text"
<div class="gf-form"> required
<span class="gf-form-label width-14">Alert API Url</span> class="gf-form-input max-width-22"
<input type="text" required class="gf-form-input max-width-22" ng-model="ctrl.model.settings.apiUrl" placeholder="https://api.opsgenie.com/v2/alerts"></input> ng-init="ctrl.model.secureSettings.apiKey = ctrl.model.settings.apiKey || null; ctrl.model.settings.apiKey = null;"
</div> ng-model="ctrl.model.secureSettings.apiKey"
<div class="gf-form"> placeholder="OpsGenie API Key"
<gf-form-switch data-placement="right">
class="gf-form" </input>
label="Auto close incidents" </div>
label-class="width-14" <div class="gf-form" ng-if="ctrl.model.secureFields.apiKey">
checked="ctrl.model.settings.autoClose" <input type="text" class="gf-form-input max-width-18" disabled="disabled" value="configured" />
tooltip="Automatically close alerts in OpsGenie once the alert goes back to ok."> <a class="btn btn-secondary gf-form-btn" href="#" ng-click="ctrl.model.secureFields.apiKey = false">reset</a>
</gf-form-switch> </div>
</div> </div>
<div class="gf-form"> <div class="gf-form">
<gf-form-switch <span class="gf-form-label width-14">Alert API Url</span>
class="gf-form" <input type="text" required class="gf-form-input max-width-22" ng-model="ctrl.model.settings.apiUrl" placeholder="https://api.opsgenie.com/v2/alerts"></input>
label="Override priority" </div>
label-class="width-14" <div class="gf-form">
checked="ctrl.model.settings.overridePriority" <gf-form-switch
tooltip="Allow the alert priority to be set using the og_priority tag"> class="gf-form"
</gf-form-switch> label="Auto close incidents"
</div> label-class="width-14"
checked="ctrl.model.settings.autoClose"
tooltip="Automatically close alerts in OpsGenie once the alert goes back to ok.">
</gf-form-switch>
</div>
<div class="gf-form">
<gf-form-switch
class="gf-form"
label="Override priority"
label-class="width-14"
checked="ctrl.model.settings.overridePriority"
tooltip="Allow the alert priority to be set using the og_priority tag">
</gf-form-switch>
</div>
`, `,
Options: []alerting.NotifierOption{ Options: []alerting.NotifierOption{
{ {
@ -87,7 +100,7 @@ var (
func NewOpsGenieNotifier(model *models.AlertNotification) (alerting.Notifier, error) { func NewOpsGenieNotifier(model *models.AlertNotification) (alerting.Notifier, error) {
autoClose := model.Settings.Get("autoClose").MustBool(true) autoClose := model.Settings.Get("autoClose").MustBool(true)
overridePriority := model.Settings.Get("overridePriority").MustBool(true) overridePriority := model.Settings.Get("overridePriority").MustBool(true)
apiKey := model.Settings.Get("apiKey").MustString() apiKey := model.DecryptedValue("apiKey", model.Settings.Get("apiKey").MustString())
apiURL := model.Settings.Get("apiUrl").MustString() apiURL := model.Settings.Get("apiUrl").MustString()
if apiKey == "" { if apiKey == "" {
return nil, alerting.ValidationError{Reason: "Could not find api key property in settings"} return nil, alerting.ValidationError{Reason: "Could not find api key property in settings"}