(远程)状态文件中的 Terraform 和明文密码 [英] Terraform and cleartext password in (remote) state file

查看:30
本文介绍了(远程)状态文件中的 Terraform 和明文密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Terraform repo 上有很多关于这个问题的 Git 问题,有很多有趣的评论,但到目前为止我仍然没有看到这个问题的解决方案.

There are many Git issues opened on the Terraform repo about this issue, with lots of interesting comments, but as of now I still see no solution to this issue.

Terraform 将纯文本值(包括密码)存储在 tfstate 文件中.

Terraform stores plain text values, including passwords, in tfstate files.

大多数用户需要远程存储它们,以便团队可以在同一基础架构上同时工作,其中大多数用户将状态文件存储在 S3 中.

Most users are required to store them remotely so the team can work concurrently on the same infrastructure with most of them storing the state files in S3.

那么你如何隐藏你的密码呢?

So how do you hide your passwords?

这里有人使用 Terraform 进行生产吗?您是否以纯文本形式保存密码?您是否有特殊的工作流程来删除或隐藏它们?那么当你运行 terraform apply 会发生什么?

Is there anyone here using Terraform for production? Do you keep you passwords in plain text? Do you have a special workflow to remove or hide them? What happens when you run a terraform apply then?

我考虑了以下选项:

  • 将它们存储在 Consul 中 - 我不使用 Consul
  • 从状态文件中删除它们 - 这每次都需要执行另一个进程,我不知道 Terraform 将如何处理密码为空/不可读/无效的资源
  • 存储一个默认密码,然后更改(因此 Terraform 在 tfstate 文件中将有一个无效密码) - 与上述相同
  • 使用 Vault 资源 - 听起来这还不是一个完整的工作流程
  • 使用 git-repo-crypt 将它们存储在 Git 中 - Git 也不是一个选项
  • 全局加密 S3 存储桶 - 如果人们以管理员"级别访问 AWS,这不会阻止人们看到纯文本密码,但这似乎是迄今为止最好的选择

在我看来,这是我希望看到的:

From my point of view, this is what I would like to see:

  • 状态文件不包含密码
  • 状态文件已加密
  • 状态文件中的密码是指向其他资源的指针",例如vault:backend-type:/path/to/password"
  • 每次 Terraform 运行都会从指定的提供者那里收集所需的密码

这只是一个愿望.

但是回到这个问题 - 你如何在生产中使用 Terraform?

But to get back to the question - how do you use Terraform in production?

推荐答案

我想知道如何处理最佳实践,但让我分享一下我的案例,尽管它是 AWS 的有限方式.基本上我不使用 Terraform 管理凭据.

I would like to know what to do about best practice, but let me share about my case, although it is a limited way to AWS. Basically I do not manage credentials with Terraform.

  • 为RDS设置初始密码,忽略与生命周期钩子的区别,稍后再更改.忽略差异的方法如下:

  • Set an initial password for RDS, ignore the difference with lifecycle hook and change it later. The way to ignore the difference is as follows:

 resource "aws_db_instance" "db_instance" {
   ...
   password = "hoge"

   lifecycle {
     ignore_changes = ["password"]
   }
 }

  • IAM 用户由 Terraform 管理,但 IAM 登录配置文件(包括密码)不是.我认为 IAM 密码应该由个人而非管理员管理.

  • IAM users are managed by Terraform, but IAM login profiles including passwords are not. I believe that IAM password should be managed by individuals and not by the administrator.

    应用程序使用的 API 密钥也不由 Terraform 管理.它们使用 AWS KMS(密钥管理服务)加密,加密数据保存在应用程序的 git 存储库或 S3 存储桶中.KMS 加密的优点是可以通过 IAM 角色控制解密权限.无需管理解密密钥.

    API keys used by applications are also not managed by Terraform. They are encrypted with AWS KMS(Key Management Service) and the encrypted data is saved in the application's git repository or S3 bucket. The advantage of KMS encryption is that decryption permissions can be controlled by the IAM role. There is no need to manage keys for decryption.

    虽然我还没有尝试过,但最近我注意到 aws ssm put-parameter --key-id 可以用作支持 KMS 加密的简单键值存储,所以这可能也是一个不错的选择.

    Although I have not tried yet, recently I noticed that aws ssm put-parameter --key-id can be used as a simple key value store supporting KMS encryption, so this might be a good alternative as well.

    希望对你有帮助.

    这篇关于(远程)状态文件中的 Terraform 和明文密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆