通过terraform创建IAM用户,并上传S3存储桶中的密钥和访问密钥 [英] Creating IAM user via terraform and upload the secret key and access key in S3 bucket

查看:12
本文介绍了通过terraform创建IAM用户,并上传S3存储桶中的密钥和访问密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一个Terraform代码来创建IAM用户,我的要求是将访问密钥和秘密密钥存储在S3存储桶中。我曾尝试通过S3CLI命令实现相同的功能,但帮助不大。如有任何建议,我们将不胜感激

推荐答案

我想指出,如果配置不正确,在S3中存储令牌可能很危险。

确保您已了解AWS中的策略和S3中的访问控制的工作原理!https://docs.aws.amazon.com/IAM/latest/UserGuide/access.html

在此基础上,我得出了以下结论:

# The user to which we will grant access to s3
resource "aws_iam_user" "user" {
  name          = "s3-user"
  path          = "/"
}

# Create the access key
resource "aws_iam_access_key" "key" {
  user = aws_iam_user.user.name
}

# Create the bucket for storing tokens
resource "aws_s3_bucket" "token" {
  bucket = "my_token_bucket"
  acl    = "private"
}

# Create the object inside the token bucket
resource "aws_s3_bucket_object" "tokens" {
  bucket                 = aws_s3_bucket.token.id
  key                    = "keys.txt"
  server_side_encryption = "AES256"
  content_type = "text/plain"
  content = <<EOF
access_id: ${aws_iam_access_key.key.id}
access_secret: ${aws_iam_access_key.key.secret}
EOF
}

我还没有测试过这个。

这篇关于通过terraform创建IAM用户,并上传S3存储桶中的密钥和访问密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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