Cloudwatch: use shared library for aws auth (#29550)

* use sdk for handling auth

* fix broken test

* lint fixes

Co-authored-by: Erik Sundell <erik.sundell87@gmail.com>
This commit is contained in:
Ryan McKinley
2021-03-12 14:30:21 +01:00
committed by GitHub
co-authored by Erik Sundell
parent 8404d54277
commit 9dd1d5f553
16 changed files with 151 additions and 489 deletions
+15 -3
View File
@@ -12,12 +12,14 @@ import (
"os"
"path"
"path/filepath"
"strconv"
"strings"
"time"
"github.com/prometheus/common/model"
ini "gopkg.in/ini.v1"
"github.com/grafana/grafana-aws-sdk/pkg/awsds"
"github.com/grafana/grafana/pkg/components/gtime"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/util"
@@ -876,7 +878,7 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error {
}
cfg.readLDAPConfig()
cfg.readAWSConfig()
cfg.handleAWSConfig()
cfg.readSessionConfig()
cfg.readSmtpSettings()
cfg.readQuotaSettings()
@@ -940,10 +942,10 @@ func (cfg *Cfg) readLDAPConfig() {
cfg.LDAPAllowSignup = LDAPAllowSignup
}
func (cfg *Cfg) readAWSConfig() {
func (cfg *Cfg) handleAWSConfig() {
awsPluginSec := cfg.Raw.Section("aws")
cfg.AWSAssumeRoleEnabled = awsPluginSec.Key("assume_role_enabled").MustBool(true)
allowedAuthProviders := awsPluginSec.Key("allowed_auth_providers").String()
allowedAuthProviders := awsPluginSec.Key("allowed_auth_providers").MustString("default,keys,credentials")
for _, authProvider := range strings.Split(allowedAuthProviders, ",") {
authProvider = strings.TrimSpace(authProvider)
if authProvider != "" {
@@ -951,6 +953,16 @@ func (cfg *Cfg) readAWSConfig() {
}
}
cfg.AWSListMetricsPageLimit = awsPluginSec.Key("list_metrics_page_limit").MustInt(500)
// Also set environment variables that can be used by core plugins
err := os.Setenv(awsds.AssumeRoleEnabledEnvVarKeyName, strconv.FormatBool(cfg.AWSAssumeRoleEnabled))
if err != nil {
cfg.Logger.Error(fmt.Sprintf("could not set environment variable '%s'", awsds.AssumeRoleEnabledEnvVarKeyName), err)
}
err = os.Setenv(awsds.AllowedAuthProvidersEnvVarKeyName, allowedAuthProviders)
if err != nil {
cfg.Logger.Error(fmt.Sprintf("could not set environment variable '%s'", awsds.AllowedAuthProvidersEnvVarKeyName), err)
}
}
func (cfg *Cfg) readSessionConfig() {