我问,因为我不想在我的开发环境(使用terraform或云形成)中存储明文密码,而是由相应的AWS组件透明地解密的加密值.
解决方法:
如果您想使用CLI执行此操作,则始终可以使用KMS密钥加密密码,然后运行两个命令来解密密码并创建数据库.
所以像这样的东西可能有效:
aws rds create-instance ... \
--master-username admin-user \
--master-user-password `aws kms decrypt --ciphertext-blob fileb://path/to/kms/encrypted/file/with/password --output text --query Plaintext | base64 --decode`
如果您仍想使用Terraform创建数据库实例,那么我就是previously answered a question along similar lines.虽然这个问题更关注数据库存储在远程状态文件中.
同样,您可以使用aws_kms_secret data source动态解密密码.这会将密码泄露给日志和状态文件,但:
$echo -n 'master-password' > plaintext-password
$aws kms encrypt \
> --key-id ab123456-c012-4567-890a-deadbeef123 \
> --plaintext fileb://plaintext-example \
> --encryption-context foo=bar \
> --output text --query CiphertextBlob
AQECAHgaPa0J8WadplGCqqVAr4HNvDaFSQ+NaiwIBhmm6qDSFwAAAGIwYAYJKoZIhvcNAQcGoFMwUQIBADBMBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDI+LoLdvYv8l41OhAAIBEIAfx49FFJCLeYrkfMfAw6XlnxP23MmDBdqP8dPp28OoAQ==
然后在Terraform中:
data "aws_kms_secret" "db" {
secret {
name = "master_password"
payload = "AQECAHgaPa0J8WadplGCqqVAr4HNvDaFSQ+NaiwIBhmm6qDSFwAAAGIwYAYJKoZIhvcNAQcGoFMwUQIBADBMBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDI+LoLdvYv8l41OhAAIBEIAfx49FFJCLeYrkfMfAw6XlnxP23MmDBdqP8dPp28OoAQ=="
context {
foo = "bar"
}
}
}
resource "aws_rds_cluster" "rds" {
master_username = "root"
master_password = "${data.aws_kms_secret.db.master_password}"
# ...
}
标签:terraform,mysql,amazon-web-services,amazon-rds,amazon-kms
来源: https://codeday.me/bug/20190828/1753198.html