-
Notifications
You must be signed in to change notification settings - Fork 0
/
retriever-poc-iam.tf
88 lines (72 loc) · 2.31 KB
/
retriever-poc-iam.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# Cloud items required for the retriever proof of concept.
# https://github.com/redhatcloudx/cloud-image-retriever
# IAM policy document for managing JSON content in the bucket.
data "aws_iam_policy_document" "publish_image_data" {
statement {
sid = "PublishImageData"
effect = "Allow"
actions = [
"s3:DeleteObject",
"s3:DeleteObjectTagging",
"s3:PutObject",
"s3:GetObject",
"s3:GetObjectAttributes",
"s3:GetObjectTagging",
"s3:ListBucket",
"s3:PutObjectTagging",
"s3:PutObjectAcl"
]
resources = [
"arn:aws:s3:::${aws_s3_bucket.cloudx_json_bucket.bucket}",
"arn:aws:s3:::${aws_s3_bucket.cloudx_json_bucket.bucket}/*"
]
}
}
# Load the IAM policy document into a policy that we can use with a role.
resource "aws_iam_policy" "publish_image_data" {
name = "publish_data"
policy = data.aws_iam_policy_document.publish_image_data.json
}
# IAM policy document that allows actions in the cloud-image-retriever repo to
# assume the role.
data "aws_iam_policy_document" "github_cloud_image_retriever" {
statement {
sid = "GitHubActionsWebIdentityPolicy"
effect = "Allow"
actions = ["sts:AssumeRoleWithWebIdentity"]
principals {
type = "Federated"
identifiers = [aws_iam_openid_connect_provider.github_actions.arn]
}
condition {
test = "ForAnyValue:StringEquals"
variable = "token.actions.githubusercontent.com:aud"
values = ["sts.amazonaws.com"]
}
condition {
test = "ForAnyValue:StringLike"
variable = "token.actions.githubusercontent.com:sub"
values = ["repo:redhatcloudx/cloud-image-retriever:*"]
}
}
}
data "aws_iam_policy_document" "get_image_data" {
statement {
sid = "GetImageData"
effect = "Allow"
actions = [
"ec2:DescribeImages",
"ec2:DescribeRegions"
]
resources = ["*"]
}
}
resource "aws_iam_policy" "get_image_data" {
name = "get_image_data"
policy = data.aws_iam_policy_document.get_image_data.json
}
resource "aws_iam_role" "github_actions_image_retriever" {
name = "github_actions_image_retriever"
managed_policy_arns = [aws_iam_policy.get_image_data.arn, aws_iam_policy.publish_image_data.arn]
assume_role_policy = data.aws_iam_policy_document.github_cloud_image_retriever.json
}