Skip to content

Commit 677093e

Browse files
upd: update policies 190, 520
Improved accuracy of filters
1 parent c58c6bb commit 677093e

File tree

17 files changed

+700
-392
lines changed

17 files changed

+700
-392
lines changed

policies/ecc-aws-490-ec2_token_hop_limit_check.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ policies:
1616
- type: value
1717
key: State.Name
1818
value: terminated
19+
- type: value
20+
key: MetadataOptions.HttpEndpoint
21+
value: enabled
1922
- not:
2023
- type: value
2124
key: MetadataOptions.HttpPutResponseHopLimit

policies/ecc-aws-520-autoscaling_launch_config_hop_limit.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ policies:
1212
Auto Scaling launch configuration hop limit is greater than 1
1313
resource: launch-config
1414
filters:
15+
- type: value
16+
key: MetadataOptions.HttpEndpoint
17+
value: enabled
1518
- type: value
1619
key: MetadataOptions.HttpPutResponseHopLimit
1720
op: gt

terraform/ecc-aws-490-ec2_token_hop_limit_check/green/ec2.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ resource "aws_instance" "this" {
22
ami = data.aws_ami.this.id
33
instance_type = "t2.micro"
44
metadata_options {
5-
http_endpoint = "enabled"
5+
http_endpoint = "enabled"
66
}
77

88

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
resource "aws_instance" "this" {
2+
ami = data.aws_ami.this.id
3+
instance_type = "t2.micro"
4+
metadata_options {
5+
http_endpoint = "disabled"
6+
# `http_put_response_hop_limit` - Defaults to 1
7+
}
8+
9+
10+
tags = {
11+
Name = "490_instance_green2"
12+
}
13+
}
14+
15+
data "aws_ami" "this" {
16+
most_recent = true
17+
owners = ["amazon"]
18+
filter {
19+
name = "name"
20+
values = ["amzn2-ami-hvm*"]
21+
}
22+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
version = "~> 5"
6+
}
7+
}
8+
}
9+
10+
provider "aws" {
11+
profile = var.profile
12+
region = var.default-region
13+
14+
default_tags {
15+
tags = {
16+
CustodianRule = "ecc-aws-490-ec2_token_hop_limit_check"
17+
ComplianceStatus = "Green2"
18+
}
19+
}
20+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
profile = "c7n"
2+
default-region = "us-east-1"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
variable "default-region" {
2+
type = string
3+
description = "Default region for resources will be created"
4+
}
5+
6+
variable "profile" {
7+
type = string
8+
description = "Profile name configured before running apply"
9+
}

terraform/ecc-aws-490-ec2_token_hop_limit_check/iam/490-policy.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
{
55
"Effect": "Allow",
66
"Action": [
7-
"ec2:DescribeInstances",
8-
"ec2:DescribeTags"
7+
"ec2:DescribeInstances"
98
],
109
"Resource": "*"
1110
}

terraform/ecc-aws-490-ec2_token_hop_limit_check/red/ec2.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ resource "aws_instance" "this" {
33
instance_type = "t2.micro"
44
metadata_options {
55
http_endpoint = "enabled"
6-
http_put_response_hop_limit = 5
6+
http_put_response_hop_limit = 2
77
}
88

99

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
resource "aws_launch_configuration" "this" {
2+
name_prefix = "520_launch_configuration_green2"
3+
image_id = data.aws_ami.this.id
4+
instance_type = "t2.micro"
5+
metadata_options {
6+
http_endpoint = "disabled"
7+
http_tokens = "required"
8+
http_put_response_hop_limit = "5"
9+
}
10+
}
11+
12+
data "aws_ami" "this" {
13+
most_recent = true
14+
owners = ["amazon"]
15+
16+
filter {
17+
name = "name"
18+
values = ["amzn2-ami-hvm*"]
19+
}
20+
}

0 commit comments

Comments
 (0)