@@ -68,9 +68,10 @@ type AWSSettings struct {
68
68
type MicrosoftAuthType string
69
69
70
70
const (
71
- MicrosoftAuthTypeManagedIdentity MicrosoftAuthType = azcredentials .AzureAuthManagedIdentity
72
- MicrosoftAuthTypeWorkloadIdentity MicrosoftAuthType = azcredentials .AzureAuthWorkloadIdentity
73
- MicrosoftAuthTypeClientSecret MicrosoftAuthType = azcredentials .AzureAuthClientSecret
71
+ MicrosoftAuthTypeManagedIdentity MicrosoftAuthType = azcredentials .AzureAuthManagedIdentity
72
+ MicrosoftAuthTypeWorkloadIdentity MicrosoftAuthType = azcredentials .AzureAuthWorkloadIdentity
73
+ MicrosoftAuthTypeClientSecret MicrosoftAuthType = azcredentials .AzureAuthClientSecret
74
+ MicrosoftAuthTypeCurrentUserIdentity MicrosoftAuthType = azcredentials .AzureAuthCurrentUserIdentity
74
75
)
75
76
76
77
type MicrosoftCloudType string
@@ -81,10 +82,20 @@ const (
81
82
MicrosoftCloudUSGovernment MicrosoftCloudType = azsettings .AzureUSGovernment
82
83
)
83
84
85
+ var (
86
+ MicrosoftRequiredForClientSecretErrHelp = errors .New (` is required for Microsoft client secret authentication` )
87
+ MicrosoftDisabledAuthErrHelp = errors .New (` is not enabled in the Grafana Azure settings. For more information, please refer to the Grafana documentation at
88
+ https://grafana.com/docs/grafana/latest/setup-grafana/configure-grafana/#azure.
89
+ Additionally, this plugin needs to be added to the grafana.ini setting azure.forward_settings_to_plugins.` )
90
+ )
91
+
84
92
type MicrosoftSettings struct {
85
- Cloud MicrosoftCloudType `json:"cloud"`
86
- AuthType MicrosoftAuthType `json:"auth_type"`
87
- TenantID string `json:"tenant_id"`
93
+ Cloud MicrosoftCloudType `json:"cloud"`
94
+ AuthType MicrosoftAuthType `json:"auth_type"`
95
+ TenantID string `json:"tenant_id"`
96
+ ClientID string `json:"client_id"`
97
+ ClientSecret string
98
+ Scopes []string `json:"scopes,omitempty"`
88
99
}
89
100
90
101
type ProxyType string
@@ -165,6 +176,42 @@ func (s *InfinitySettings) Validate() error {
165
176
}
166
177
return nil
167
178
}
179
+ if s .AuthenticationMethod == AuthenticationMethodMicrosoft {
180
+ azSettings , err := azsettings .ReadFromEnv ()
181
+ if err != nil {
182
+ return err
183
+ }
184
+
185
+ switch s .MicrosoftSettings .AuthType {
186
+ case MicrosoftAuthTypeClientSecret :
187
+ if strings .TrimSpace (s .MicrosoftSettings .TenantID ) == "" {
188
+ return fmt .Errorf ("Tenant ID %w " , MicrosoftRequiredForClientSecretErrHelp )
189
+ }
190
+
191
+ if strings .TrimSpace (s .MicrosoftSettings .ClientID ) == "" {
192
+ return fmt .Errorf ("Client ID %w " , MicrosoftRequiredForClientSecretErrHelp )
193
+ }
194
+
195
+ if strings .TrimSpace (s .MicrosoftSettings .ClientSecret ) == "" {
196
+ return fmt .Errorf ("Client secret %w " , MicrosoftRequiredForClientSecretErrHelp )
197
+ }
198
+ case MicrosoftAuthTypeManagedIdentity :
199
+ if ! azSettings .ManagedIdentityEnabled {
200
+ return errors .New ("managed identity authentication is not enabled in Grafana config. " +
201
+ "Refer https://grafana.com/docs/grafana/latest/setup-grafana/configure-grafana/#azure" )
202
+ }
203
+ case MicrosoftAuthTypeWorkloadIdentity :
204
+ if ! azSettings .WorkloadIdentityEnabled {
205
+ return errors .New ("workload identity authentication is not enabled in Grafana config." +
206
+ "Refer https://grafana.com/docs/grafana/latest/setup-grafana/configure-grafana/#azure" )
207
+ }
208
+ case MicrosoftAuthTypeCurrentUserIdentity :
209
+ if ! azSettings .UserIdentityEnabled {
210
+ return errors .New ("user identity authentication is not enabled in Grafana config." +
211
+ "Refer https://grafana.com/docs/grafana/latest/setup-grafana/configure-grafana/#azure" )
212
+ }
213
+ }
214
+ }
168
215
if s .AuthenticationMethod != AuthenticationMethodNone && len (s .AllowedHosts ) < 1 {
169
216
return errors .New ("configure allowed hosts in the authentication section" )
170
217
}
@@ -212,7 +259,6 @@ type InfinitySettingsJson struct {
212
259
ProxyType ProxyType `json:"proxy_type,omitempty"`
213
260
ProxyUrl string `json:"proxy_url,omitempty"`
214
261
AllowedHosts []string `json:"allowedHosts,omitempty"`
215
-
216
262
ReferenceData []RefData `json:"refData,omitempty"`
217
263
CustomHealthCheckEnabled bool `json:"customHealthCheckEnabled,omitempty"`
218
264
CustomHealthCheckUrl string `json:"customHealthCheckUrl,omitempty"`
@@ -312,6 +358,9 @@ func LoadSettings(ctx context.Context, config backend.DataSourceInstanceSettings
312
358
if val , ok := config .DecryptedSecureJSONData ["azureBlobAccountKey" ]; ok {
313
359
settings .AzureBlobAccountKey = val
314
360
}
361
+ if val , ok := config .DecryptedSecureJSONData ["microsoftClientSecret" ]; ok {
362
+ settings .MicrosoftSettings .ClientSecret = val
363
+ }
315
364
settings .CustomHeaders = GetSecrets (config , "httpHeaderName" , "httpHeaderValue" )
316
365
settings .SecureQueryFields = GetSecrets (config , "secureQueryName" , "secureQueryValue" )
317
366
settings .OAuth2Settings .EndpointParams = GetSecrets (config , "oauth2EndPointParamsName" , "oauth2EndPointParamsValue" )
0 commit comments