Skip to content

Commit c77ef4e

Browse files
committed
Enforce metadata v2 + remove unnecessary IAM permissions + add message on the default security group with 0.0.0.0
1 parent a3baf3c commit c77ef4e

File tree

2 files changed

+3
-33
lines changed

2 files changed

+3
-33
lines changed

main.tf

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,9 @@ resource "aws_iam_role_policy_attachment" "custom_policy" {
129129
resource "aws_iam_role_policy" "aws_policy" {
130130
name = "${var.name}-aws-access"
131131
role = aws_iam_role.awsserviceroleforimagebuilder.id
132-
#checkov:skip=CKV_AWS_290:The policy must allow *
133-
#checkov:skip=CKV_AWS_355:The policy must allow *
134132
policy = data.aws_iam_policy_document.aws_policy.json
135133
}
136134

137-
#tfsec:ignore:aws-iam-no-policy-wildcards
138135
data "aws_iam_policy_document" "aws_policy" {
139136

140137
statement {
@@ -143,21 +140,6 @@ data "aws_iam_policy_document" "aws_policy" {
143140
resources = ["arn:aws:iam::*:role/EC2ImageBuilderDistributionCrossAccountRole"]
144141
}
145142

146-
statement {
147-
effect = "Allow"
148-
#checkov:skip=CKV_AWS_111:The policy must allow *
149-
#checkov:skip=CKV_AWS_290:The policy must allow *
150-
#checkov:skip=CKV_AWS_355:The policy must allow *
151-
actions = [
152-
"ec2messages:GetMessages",
153-
"ec2:MetadataHttpEndpoint",
154-
"ec2:MetadataHttpPutResponseHopLimit",
155-
"ec2:MetadataHttpTokens",
156-
"ssm:SendCommand"
157-
]
158-
resources = ["*"]
159-
}
160-
161143
}
162144

163145
# ---------------------------------------------------------------------------------------------------------------------
@@ -175,8 +157,8 @@ resource "aws_imagebuilder_infrastructure_configuration" "imagebuilder_infrastru
175157
subnet_id = var.subnet_id
176158

177159
instance_metadata_options {
178-
http_tokens = var.instance_metadata_http_tokens
179-
http_put_response_hop_limit = var.instance_metadata_http_put_hop_limit
160+
http_tokens = "required"
161+
http_put_response_hop_limit = 2
180162
}
181163

182164
terminate_instance_on_failure = var.terminate_on_failure

variables.tf

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -154,26 +154,14 @@ variable "imagebuilder_image_recipe_kms_key_arn" {
154154
type = string
155155
}
156156

157-
variable "instance_metadata_http_put_hop_limit" {
158-
default = null
159-
description = "The number of hops that an instance can traverse to reach its metadata."
160-
type = number
161-
}
162-
163-
variable "instance_metadata_http_tokens" {
164-
default = "optional"
165-
description = "(Optional) Whether a signed token is required for instance metadata retrieval requests. Valid values: required, optional."
166-
type = string
167-
}
168-
169157
variable "terminate_on_failure" {
170158
default = true
171159
description = "(Optional) Change to false if you want to connect to a builder for debugging after failure"
172160
type = bool
173161
}
174162

175163
variable "create_security_group" {
176-
description = "(Optional) Create security group for EC2 Image Builder instances"
164+
description = "(Optional) Create security group for EC2 Image Builder instances. Please note this security group will be created with default egress rule to 0.0.0.0/0 CIDR Block. In case you want to have a more restrict set of rules, please provide your own security group id on security_group_ids variable"
177165
type = bool
178166
default = true
179167
}

0 commit comments

Comments
 (0)