Last active
April 20, 2022 18:00
-
-
Save devops-adeel/486d7a4a186c02e23ad7be9e1a6fa264 to your computer and use it in GitHub Desktop.
Minimal AWS IAM permissions on S3 for raft auto-snapshot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data "aws_kms_key" "auto_unseal" { | |
key_id = "alias/my-key" | |
} | |
data "aws_iam_policy_document" "auto_unseal" { | |
version = "2012-10-17" | |
statement { | |
effect = "Allow" | |
actions = [ | |
"kms:DescribeKey", | |
"kms:Encrypt", | |
"kms:Decrypt", | |
"kms:EnableKeyRotation" | |
] | |
resources = [ | |
data.aws_kms_key.auto_unseal.arn | |
] | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data "aws_iam_policy_document" "raft_auto_join" { | |
version = "2012-10-17" | |
statement { | |
sid = "ListInstancesWithTags" | |
effect = "Allow" | |
actions = [ | |
"ec2:DescribeInstances", | |
] | |
resources = [ | |
"*" | |
] | |
condition { | |
test = "StringEquals" | |
variable = "ec2:ResourceTag/app" | |
values = [ | |
"vault", | |
] | |
} | |
} | |
} | |
data "aws_iam_policy_document" "default" { | |
source_policy_documents = [ | |
data.aws_iam_policy_document.raft_auto_join.json, | |
] | |
} | |
resource "aws_iam_policy" "default" { | |
name = "vault_server_policy" | |
path = "/" | |
policy = data.aws_iam_policy_document.default.json | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data "aws_s3_bucket" "default" { | |
bucket = var.bucket_name | |
} | |
data "aws_iam_policy_document" "raft_snapshot" { | |
version = "2012-10-17" | |
statement { | |
sid = "ListObjectsInBucket" | |
effect = "Allow" | |
actions = ["s3:ListBucket"] | |
resources = [data.aws_s3_bucket.default.arn] | |
} | |
statement { | |
sid = "AllObjectActions" | |
effect = "Allow" | |
actions = ["s3:*Object"] | |
resources = [data.aws_s3_bucket.default.arn] | |
} | |
} | |
data "aws_iam_policy_document" "default" { | |
source_policy_documents = [data.aws_iam_policy_document.raft_snapshot.json] | |
} | |
resource "aws_s3_bucket_policy" "default" { | |
bucket = data.aws_s3_bucket.default.id | |
policy = data.aws_iam_policy_document.default.json | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment