CloudWatch: Add support for EC2 IAM role (#31804)

* add support for iam role auth

* add stubbable func

* fix broken test

* goimports

* pr feedback
This commit is contained in:
Erik Sundell
2021-03-09 20:50:16 +01:00
committed by GitHub
parent d583875a63
commit 13dd9dff50
3 changed files with 57 additions and 1 deletions
+13 -1
View File
@@ -147,6 +147,13 @@ func (e *cloudWatchExecutor) newSession(region string) (*session.Session, error)
})
case authTypeDefault:
plog.Debug("Authenticating towards AWS with default SDK method", "region", dsInfo.Region)
case authTypeEC2IAMRole:
plog.Debug("Authenticating towards AWS with IAM Role", "region", dsInfo.Region)
sess, err := newSession(cfgs...)
if err != nil {
return nil, err
}
cfgs = append(cfgs, &aws.Config{Credentials: newEC2RoleCredentials(sess)})
default:
panic(fmt.Sprintf("Unrecognized authType: %d", dsInfo.AuthType))
}
@@ -396,6 +403,7 @@ const (
authTypeDefault authType = iota
authTypeSharedCreds
authTypeKeys
authTypeEC2IAMRole
)
func (at authType) String() string {
@@ -403,9 +411,11 @@ func (at authType) String() string {
case authTypeDefault:
return "default"
case authTypeSharedCreds:
return "sharedCreds"
return "credentials"
case authTypeKeys:
return "keys"
case authTypeEC2IAMRole:
return "ec2_iam_role"
default:
panic(fmt.Sprintf("Unrecognized auth type %d", at))
}
@@ -432,6 +442,8 @@ func (e *cloudWatchExecutor) getDSInfo(region string) *datasourceInfo {
at = authTypeKeys
case "default":
at = authTypeDefault
case "ec2_iam_role":
at = authTypeEC2IAMRole
case "arn":
at = authTypeDefault
plog.Warn("Authentication type \"arn\" is deprecated, falling back to default")