Skip to content

Klisk/aws infra cornerstone#1

Open
kylelisk wants to merge 16 commits intomainfrom
klisk/aws-infra-cornerstone
Open

Klisk/aws infra cornerstone#1
kylelisk wants to merge 16 commits intomainfrom
klisk/aws-infra-cornerstone

Conversation

@kylelisk
Copy link
Copy Markdown
Owner

@kylelisk kylelisk commented Oct 9, 2025

No description provided.

Comment thread infra/alb.tf Fixed
Comment thread infra/alb.tf Fixed
Comment thread infra/alb.tf Fixed
Comment thread infra/alb.tf Fixed
Comment thread infra/alb.tf Fixed
Comment thread infra/ecs.tf Fixed
Comment thread infra/networking.tf Fixed
Comment thread infra/networking.tf Fixed
Comment thread infra/networking.tf Fixed
Comment thread infra/networking.tf Fixed
Comment thread infra/alb.tf Fixed
Comment thread infra/alb.tf Fixed
Comment thread infra/alb.tf Fixed
Comment thread infra/alb.tf Fixed
Comment thread infra/alb.tf Fixed
Comment thread infra/ecr.tf Fixed
Comment thread infra/ecs.tf Fixed
Comment thread infra/ecs.tf Fixed
Comment thread infra/alb.tf Fixed
Traffic now gets routed to the firewall subnets first and if it passes the checks it is then forwarded into the ALB subnets.
Comment thread infra/network_firewall.tf Fixed
Comment thread infra/network_firewall.tf Fixed
Comment thread infra/network_firewall.tf Fixed
Comment thread infra/network_firewall.tf Fixed
Comment thread infra/network_firewall.tf Fixed
Kyle Lisk added 6 commits October 9, 2025 14:59
- Added the network firewall logic and wired it all up with the routing
- Network firewall logs to cloudwatch logs
- Which then leads to the final piece of allowing cloudwatch logging for the network firewall; reused the ecs kms key for that
… specific CIDR ranges. Also cleaned up the README
1. Circular dependencies of security group rules between ALB and ECS
2. Network security group rules have a peculiar issue with AWS and needed a 'settings' variable
Comment thread infra/alb.tf
Comment on lines +42 to +59
resource "aws_lb" "main" {
#checkov:skip=CKV_AWS_91:Access logs not required for this exercise
#checkov:skip=CKV2_AWS_28:WAF not required for this exercise
#checkov:skip=CKV_AWS_150:ALB deletion protection disabled for easier cleanup in exercise environment
#checkov:skip=CKV_AWS_131:ALB drop invalid HTTP headers not critical for this exercise
name = "${var.project_name}-alb"
internal = false
load_balancer_type = "application"
security_groups = [aws_security_group.alb.id]
subnets = aws_subnet.public[*].id

enable_deletion_protection = false
enable_http2 = true

tags = {
Name = "${var.project_name}-alb"
}
}

Check warning

Code scanning / checkov

Ensure that Load Balancer has deletion protection enabled Warning

Ensure that Load Balancer has deletion protection enabled
Comment thread infra/alb.tf
Comment on lines +42 to +59
resource "aws_lb" "main" {
#checkov:skip=CKV_AWS_91:Access logs not required for this exercise
#checkov:skip=CKV2_AWS_28:WAF not required for this exercise
#checkov:skip=CKV_AWS_150:ALB deletion protection disabled for easier cleanup in exercise environment
#checkov:skip=CKV_AWS_131:ALB drop invalid HTTP headers not critical for this exercise
name = "${var.project_name}-alb"
internal = false
load_balancer_type = "application"
security_groups = [aws_security_group.alb.id]
subnets = aws_subnet.public[*].id

enable_deletion_protection = false
enable_http2 = true

tags = {
Name = "${var.project_name}-alb"
}
}

Check warning

Code scanning / checkov

Ensure that ALB drops HTTP headers Warning

Ensure that ALB drops HTTP headers
Comment thread infra/alb.tf
Comment on lines +42 to +59
resource "aws_lb" "main" {
#checkov:skip=CKV_AWS_91:Access logs not required for this exercise
#checkov:skip=CKV2_AWS_28:WAF not required for this exercise
#checkov:skip=CKV_AWS_150:ALB deletion protection disabled for easier cleanup in exercise environment
#checkov:skip=CKV_AWS_131:ALB drop invalid HTTP headers not critical for this exercise
name = "${var.project_name}-alb"
internal = false
load_balancer_type = "application"
security_groups = [aws_security_group.alb.id]
subnets = aws_subnet.public[*].id

enable_deletion_protection = false
enable_http2 = true

tags = {
Name = "${var.project_name}-alb"
}
}

Check warning

Code scanning / checkov

Ensure the ELBv2 (Application/Network) has access logging enabled Warning

Ensure the ELBv2 (Application/Network) has access logging enabled
Comment thread infra/alb.tf
Comment on lines +42 to +59
resource "aws_lb" "main" {
#checkov:skip=CKV_AWS_91:Access logs not required for this exercise
#checkov:skip=CKV2_AWS_28:WAF not required for this exercise
#checkov:skip=CKV_AWS_150:ALB deletion protection disabled for easier cleanup in exercise environment
#checkov:skip=CKV_AWS_131:ALB drop invalid HTTP headers not critical for this exercise
name = "${var.project_name}-alb"
internal = false
load_balancer_type = "application"
security_groups = [aws_security_group.alb.id]
subnets = aws_subnet.public[*].id

enable_deletion_protection = false
enable_http2 = true

tags = {
Name = "${var.project_name}-alb"
}
}

Check warning

Code scanning / checkov

Ensure public facing ALB are protected by WAF Warning

Ensure public facing ALB are protected by WAF
Comment thread infra/ecr.tf
Comment on lines +1 to +18
resource "aws_ecr_repository" "app" {
#checkov:skip=CKV_AWS_51:Using AES256 encryption instead of KMS for this exercise
#checkov:skip=CKV_AWS_136:AES256 encryption is acceptable for this use case
name = "${var.project_name}-app"
image_tag_mutability = "IMMUTABLE"

image_scanning_configuration {
scan_on_push = true
}

encryption_configuration {
encryption_type = "AES256"
}

tags = {
Name = "${var.project_name}-ecr"
}
}

Check warning

Code scanning / checkov

Ensure that ECR repositories are encrypted using KMS Warning

Ensure that ECR repositories are encrypted using KMS
Comment thread infra/network_firewall.tf
Comment on lines +54 to +78
resource "aws_networkfirewall_firewall_policy" "main" {
#checkov:skip=CKV_AWS_346:Using default encryption for this exercise, CMK not required
name = "${var.project_name}-firewall-policy"

firewall_policy {
stateless_default_actions = ["aws:forward_to_sfe"]
stateless_fragment_default_actions = ["aws:forward_to_sfe"]

stateful_rule_group_reference {
resource_arn = aws_networkfirewall_rule_group.allow_http_https.arn
priority = 1
}

stateful_engine_options {
rule_order = "STRICT_ORDER"
}

# Block all traffic that doesn't match the rules
stateful_default_actions = ["aws:drop_strict"]
}

tags = {
Name = "${var.project_name}-firewall-policy"
}
}

Check warning

Code scanning / checkov

Ensure Network Firewall Policy defines an encryption configuration that uses a customer managed Key (CMK) Warning

Ensure Network Firewall Policy defines an encryption configuration that uses a customer managed Key (CMK)
Comment thread infra/network_firewall.tf
Comment on lines +80 to +99
resource "aws_networkfirewall_firewall" "main" {
#checkov:skip=CKV_AWS_345:Using default encryption for this exercise, CMK not required
#checkov:skip=CKV_AWS_344:Deletion protection disabled for easier cleanup in exercise environment
name = "${var.project_name}-firewall"
firewall_policy_arn = aws_networkfirewall_firewall_policy.main.arn
vpc_id = aws_vpc.main.id
delete_protection = true

# Deploy firewall endpoints in dedicated firewall subnets
dynamic "subnet_mapping" {
for_each = aws_subnet.firewall[*].id
content {
subnet_id = subnet_mapping.value
}
}

tags = {
Name = "${var.project_name}-network-firewall"
}
}

Check warning

Code scanning / checkov

Ensure that Network firewall encryption is via a CMK Warning

Ensure that Network firewall encryption is via a CMK
Comment thread infra/network_firewall.tf
Comment on lines +80 to +99
resource "aws_networkfirewall_firewall" "main" {
#checkov:skip=CKV_AWS_345:Using default encryption for this exercise, CMK not required
#checkov:skip=CKV_AWS_344:Deletion protection disabled for easier cleanup in exercise environment
name = "${var.project_name}-firewall"
firewall_policy_arn = aws_networkfirewall_firewall_policy.main.arn
vpc_id = aws_vpc.main.id
delete_protection = true

# Deploy firewall endpoints in dedicated firewall subnets
dynamic "subnet_mapping" {
for_each = aws_subnet.firewall[*].id
content {
subnet_id = subnet_mapping.value
}
}

tags = {
Name = "${var.project_name}-network-firewall"
}
}

Check warning

Code scanning / checkov

Ensure that Network firewalls have deletion protection enabled Warning

Ensure that Network firewalls have deletion protection enabled
Comment thread infra/network_firewall.tf
Comment on lines +101 to +112
resource "aws_cloudwatch_log_group" "network_firewall" {
#checkov:skip=CKV_AWS_338:7-day retention is sufficient for this exercise
name = "/aws/networkfirewall/${var.project_name}"
retention_in_days = 365
kms_key_id = aws_kms_key.cloudwatch_logs.arn

tags = {
Name = "${var.project_name}-firewall-logs"
}

depends_on = [aws_kms_key_policy.cloudwatch_logs]
}

Check warning

Code scanning / checkov

Ensure CloudWatch log groups retains logs for at least 1 year Warning

Ensure CloudWatch log groups retains logs for at least 1 year
Comment thread infra/networking.tf
Comment on lines +1 to +10
resource "aws_vpc" "main" {
#checkov:skip=CKV2_AWS_11:VPC flow logging not required for this exercise
cidr_block = var.vpc_cidr
enable_dns_hostnames = true
enable_dns_support = true

tags = {
Name = "${var.project_name}-vpc"
}
}

Check warning

Code scanning / checkov

Ensure VPC flow logging is enabled in all VPCs Warning

Ensure VPC flow logging is enabled in all VPCs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants