Skip to content

Commit 8704184

Browse files
authored
Add premission to copy ami (#136)
1 parent d4c3cbb commit 8704184

File tree

1 file changed

+59
-1
lines changed
  • modules/scanning-delegate-role

1 file changed

+59
-1
lines changed

modules/scanning-delegate-role/main.tf

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ data "aws_iam_policy_document" "scanning_orchestrator_policy_document" {
2121
resources = [
2222
"arn:${data.aws_partition.current.partition}:ec2:*:*:volume/*",
2323
"arn:${data.aws_partition.current.partition}:ec2:*:*:snapshot/*",
24+
"arn:${data.aws_partition.current.partition}:ec2:*:*:image/*",
2425
]
2526
// Allow specifying tags when creating snapshots or volumes
2627
condition {
2728
test = "StringEquals"
2829
variable = "ec2:CreateAction"
29-
values = ["CreateSnapshot", "CreateVolume", "CopySnapshot"]
30+
values = ["CreateSnapshot", "CreateVolume", "CopySnapshot", "CopyImage"]
3031
}
3132
}
3233

@@ -114,6 +115,50 @@ data "aws_iam_policy_document" "scanning_orchestrator_policy_document" {
114115
}
115116
}
116117

118+
statement {
119+
sid = "DatadogAgentlessScannerCopyImage"
120+
effect = "Allow"
121+
actions = [
122+
"ec2:CopyImage"
123+
]
124+
resources = [
125+
"arn:${data.aws_partition.current.partition}:ec2:*:*:image/*",
126+
"arn:${data.aws_partition.current.partition}:ec2:*:*:snapshot/*",
127+
]
128+
// Enforcing created image has DatadogAgentlessScanner tag
129+
condition {
130+
test = "StringEquals"
131+
variable = "aws:RequestTag/DatadogAgentlessScanner"
132+
values = ["true"]
133+
}
134+
// Enforcing created image has only tags with DatadogAgentlessScanner* prefix
135+
condition {
136+
test = "ForAllValues:StringLike"
137+
variable = "aws:TagKeys"
138+
values = ["DatadogAgentlessScanner*"]
139+
}
140+
}
141+
142+
statement {
143+
sid = "DatadogAgentlessScannerImageCleanup"
144+
effect = "Allow"
145+
actions = [
146+
// Allow deleting created images
147+
"ec2:DeregisterImage",
148+
]
149+
resources = [
150+
"arn:${data.aws_partition.current.partition}:ec2:*:*:image/*",
151+
]
152+
153+
// Enforce that any of these actions can be performed on images
154+
// that have the DatadogAgentlessScanner tag.
155+
condition {
156+
test = "StringEquals"
157+
variable = "aws:ResourceTag/DatadogAgentlessScanner"
158+
values = ["true"]
159+
}
160+
}
161+
117162
statement {
118163
sid = "DatadogAgentlessScannerDescribeSnapshots"
119164
effect = "Allow"
@@ -140,6 +185,19 @@ data "aws_iam_policy_document" "scanning_orchestrator_policy_document" {
140185
]
141186
}
142187

188+
statement {
189+
sid = "DatadogAgentlessScannerDescribeImages"
190+
effect = "Allow"
191+
actions = [
192+
// Required to be able to wait for image completion and cleanup. It
193+
// cannot be restricted.
194+
"ec2:DescribeImages",
195+
]
196+
resources = [
197+
"*",
198+
]
199+
}
200+
143201
statement {
144202
sid = "DatadogAgentlessScannerCopyEncryptedSnapshotGrantKey"
145203
effect = "Allow"

0 commit comments

Comments
 (0)