Commit 9feaa91b by Will Browne Committed by GitHub

Alerting: Store sensitive settings encrypted for Telegram notifier (#27122)

* encrypt bot token

* update docs

* re-add uploadImage to docs
parent e2c7ed4b
...@@ -520,11 +520,11 @@ The following sections detail the supported settings and secure settings for eac ...@@ -520,11 +520,11 @@ The following sections detail the supported settings and secure settings for eac
#### Alert notification `telegram` #### Alert notification `telegram`
| Name | | Name | Secure setting |
| ----------- | | ----------- | - |
| bottoken | | bottoken | yes |
| chatid | | chatid | |
| uploadImage | | uploadImage | |
#### Alert notification `threema` #### Alert notification `threema`
......
...@@ -29,25 +29,35 @@ func init() { ...@@ -29,25 +29,35 @@ func init() {
Heading: "Telegram API settings", Heading: "Telegram API settings",
Factory: NewTelegramNotifier, Factory: NewTelegramNotifier,
OptionsTemplate: ` OptionsTemplate: `
<h3 class="page-heading">Telegram API settings</h3> <h3 class="page-heading">Telegram API settings</h3>
<div class="gf-form"> <div class="gf-form max-width-30">
<span class="gf-form-label width-9">BOT API Token</span> <label class="gf-form-label width-10">BOT API Token</label>
<input type="text" required <div class="gf-form gf-form--grow" ng-if="!ctrl.model.secureFields.bottoken">
class="gf-form-input" <input type="text"
ng-model="ctrl.model.settings.bottoken" required
placeholder="Telegram BOT API Token"></input> class="gf-form-input max-width-30"
</div> ng-init="ctrl.model.secureSettings.bottoken = ctrl.model.settings.bottoken || null; ctrl.model.settings.bottoken = null;"
<div class="gf-form"> ng-model="ctrl.model.secureSettings.bottoken"
<span class="gf-form-label width-9">Chat ID</span> placeholder="Telegram BOT API Token"
<input type="text" required
class="gf-form-input"
ng-model="ctrl.model.settings.chatid"
data-placement="right"> data-placement="right">
</input> </input>
<info-popover mode="right-absolute"> </div>
Integer Telegram Chat Identifier <div class="gf-form" ng-if="ctrl.model.secureFields.bottoken">
</info-popover> <input type="text" class="gf-form-input max-width-18" disabled="disabled" value="configured" />
</div> <a class="btn btn-secondary gf-form-btn" href="#" ng-click="ctrl.model.secureFields.bottoken = false">reset</a>
</div>
</div>
<div class="gf-form max-width-30">
<label class="gf-form-label width-10">Chat ID</label>
<input type="text"
required
class="gf-form-input max-width-30"
ng-model="ctrl.model.settings.chatid"
placeholder="Telegram Chat ID"
data-placement="right">
</input>
<info-popover mode="right-absolute">Integer Telegram Chat Identifier</info-popover>
</div>
`, `,
Options: []alerting.NotifierOption{ Options: []alerting.NotifierOption{
{ {
...@@ -86,7 +96,7 @@ func NewTelegramNotifier(model *models.AlertNotification) (alerting.Notifier, er ...@@ -86,7 +96,7 @@ func NewTelegramNotifier(model *models.AlertNotification) (alerting.Notifier, er
return nil, alerting.ValidationError{Reason: "No Settings Supplied"} return nil, alerting.ValidationError{Reason: "No Settings Supplied"}
} }
botToken := model.Settings.Get("bottoken").MustString() botToken := model.DecryptedValue("bottoken", model.Settings.Get("bottoken").MustString())
chatID := model.Settings.Get("chatid").MustString() chatID := model.Settings.Get("chatid").MustString()
uploadImage := model.Settings.Get("uploadImage").MustBool() uploadImage := model.Settings.Get("uploadImage").MustBool()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment