【发布时间】:2018-06-16 17:19:30
【问题描述】:
我无法使用 IAM 用户连接到我的 RDS 数据库。
数据库用户名:master
IAM 用户:api-user
我已为用户分配了编程访问权限并向用户添加了以下策略:
自定义的rds-permission定义为:https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.IAMDBAuth.IAMPolicy.html
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"rds-db:connect"
],
"Resource": [
"arn:aws:rds-db:REGION:ACCOUNT-ID:USER:dbi-resource-id/DB_ACCOUNT_NAME"
]
}
]
}
奇怪的是,即使我已经完全按照文档中的要求定义了我的自定义权限,它也无法识别:
当我尝试使用身份验证令牌(通过 golang)进行连接时,出现以下错误:
error: ERROR: Error 1045: Access denied for user 'master'@'x.x.x.189' (using password: YES)
我的政策似乎不起作用!
尽管这无关紧要,但这是我通过 IAM 用户进行连接的方式:
//Yes Env vars are available
//creating new credentials from environment variables
//AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
awsCreds := credentials.NewEnvCredentials()
//creating authentication token for the database connection
authToken, err := rdsutils.BuildAuthToken(dbEndpoint, awsRegion, dbUser, awsCreds)
if err != nil {
Logger.LogFatal("Unable to build Authentication Token")
log.Fatal("Unable to build Authentication Token") //todo remove
}
//setting up TLS
mysql.RegisterTLSConfig("custom", &tls.Config{
InsecureSkipVerify: true,
})
// Creating the MySQL DNS string for the DB connection
// user:password@protocol(endpoint)/dbname?<params>
dnsStr := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s allowCleartextPasswords=true&tls=custom",
dbUser, authToken, dbEndpoint,dbPort, dbName,
)
rootCertPool := x509.NewCertPool() //NewCertPool returns a new, empty CertPool.
pem, err := ioutil.ReadFile("rds-ca-bundle.pem") //reading the provided pem
if err != nil {
log.Fatal("! Could not read certificates")
}
fmt.Println("Loading certificate seems to work")
//AppendCertsFromPEM attempts to parse a series of PEM encoded certificates.
//pushing in the pem
if ok := rootCertPool.AppendCertsFromPEM(pem); !ok {
log.Fatal("Failed to append PEM.")
}
fmt.Println("Appending certificate seems to work too")
//setting up TLS
//we dont need a client ca?
mysql.RegisterTLSConfig("custom", &tls.Config{
RootCAs: rootCertPool,
InsecureSkipVerify: true,
})
database, err = sql.Open("mysql", dnsStr)
【问题讨论】:
-
想必您已将RDS实例配置为允许IAM DB Authentication (docs.aws.amazon.com/AmazonRDS/latest/UserGuide/…)?
-
您好!是的,我做到了。 - 我没有人可以帮助我,我已经坐了 4 天了。求你帮忙
-
@JulieNoobie 政策声明的资源显示您使用的是“us-west-2c”,它是 AZ。您能否将其修改为“us-east-2”,即您的 RDS 资源所在的区域,然后重试?
-
您是否为您的 RDS 实例启用 IAM 身份验证?
-
@abigperson 这些标志可用于 CLI 而不是编程访问。
标签: amazon-web-services go amazon-rds