@@ -68,9 +68,10 @@ type AWSSettings struct {
6868type MicrosoftAuthType string
6969
7070const (
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
7475)
7576
7677type MicrosoftCloudType string
@@ -81,10 +82,20 @@ const (
8182 MicrosoftCloudUSGovernment MicrosoftCloudType = azsettings .AzureUSGovernment
8283)
8384
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+
8492type 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"`
8899}
89100
90101type ProxyType string
@@ -165,6 +176,42 @@ func (s *InfinitySettings) Validate() error {
165176 }
166177 return nil
167178 }
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+ }
168215 if s .AuthenticationMethod != AuthenticationMethodNone && len (s .AllowedHosts ) < 1 {
169216 return errors .New ("configure allowed hosts in the authentication section" )
170217 }
@@ -212,7 +259,6 @@ type InfinitySettingsJson struct {
212259 ProxyType ProxyType `json:"proxy_type,omitempty"`
213260 ProxyUrl string `json:"proxy_url,omitempty"`
214261 AllowedHosts []string `json:"allowedHosts,omitempty"`
215-
216262 ReferenceData []RefData `json:"refData,omitempty"`
217263 CustomHealthCheckEnabled bool `json:"customHealthCheckEnabled,omitempty"`
218264 CustomHealthCheckUrl string `json:"customHealthCheckUrl,omitempty"`
@@ -312,6 +358,9 @@ func LoadSettings(ctx context.Context, config backend.DataSourceInstanceSettings
312358 if val , ok := config .DecryptedSecureJSONData ["azureBlobAccountKey" ]; ok {
313359 settings .AzureBlobAccountKey = val
314360 }
361+ if val , ok := config .DecryptedSecureJSONData ["microsoftClientSecret" ]; ok {
362+ settings .MicrosoftSettings .ClientSecret = val
363+ }
315364 settings .CustomHeaders = GetSecrets (config , "httpHeaderName" , "httpHeaderValue" )
316365 settings .SecureQueryFields = GetSecrets (config , "secureQueryName" , "secureQueryValue" )
317366 settings .OAuth2Settings .EndpointParams = GetSecrets (config , "oauth2EndPointParamsName" , "oauth2EndPointParamsValue" )
0 commit comments