Insecure Network Communication
Why is this important?
Ensuring that the data in transit is secured between users and your application is the most fundamental security requirement. If this security control is not in place then all bets are off and attackers have many ways to attack your users.
Check out this video for a high-level explanation:
Unencrypted MSK Broker
AWS offers a Managed Streaming for Kafka cluster service, which may transmit data in clear-text.
More information can be found here:
Option A: Ensure MSK Encryption in Transit
- Go through the issues that GuardRails identified.
- Locate the
aws_msk_cluster
resource.
resource "aws_msk_cluster" "example" {
cluster_name = "example"
kafka_version = "2.4.1"
number_of_broker_nodes = 3
broker_node_group_info {
instance_type = "kafka.m5.large"
ebs_volume_size = 1000
client_subnets = [
aws_subnet.subnet_az1.id,
aws_subnet.subnet_az2.id,
aws_subnet.subnet_az3.id,
]
security_groups = [aws_security_group.sg.id]
}
}
- Ensure that the aws_msk_cluster resource includes an encryption_info object, for example like shown below.
resource "aws_msk_cluster" "example" {
cluster_name = "example"
...
encryption_info {
encryption_at_rest_kms_key_arn = aws_kms_key.kms.arn
}
}
Unencrypted Kinesis Stream
AWS offers a Kinesis Stream resource, which is a managed service that scales elastically for real-time processing of streaming big data. This service may transmit data in clear-text.
More information can be found here:
Option A: Ensure Kinesis Stream Encryption in Transit
- Go through the issues that GuardRails identified.
- Locate the
aws_kinesis_stream
resource.
resource "aws_kinesis_stream" "test_stream" {
name = "terraform-kinesis-test"
shard_count = 1
retention_period = 48
shard_level_metrics = [
"IncomingBytes",
"OutgoingBytes",
]
tags = {
Environment = "test"
}
}
- Ensure that the
aws_kinesis_stream
resource includes theencryption_type
argument set toKMS
.
resource "aws_kinesis_stream" "test_stream" {
name = "terraform-kinesis-test"
shard_count = 1
retention_period = 48
encryption_type = "KMS"
...
}
Ensure Encryption in Transit
Certain services communicate via HTTP unless configured otherwise.
Option A: Ensure AWS Load Balancer is using HTTPS
- Go through the issues that GuardRails identified.
- Locate the
aws_lb_listener
resource.
resource "aws_lb_listener" "front_end" {
load_balancer_arn = aws_lb.front_end.arn
port = "80"
protocol = "HTTP"
ssl_policy = "ELBSecurityPolicy-2016-08"
certificate_arn = "arn:aws:iam::187416307283:server-certificate/test_cert_rab3wuqwgja25ct3n4jdj2tzu4"
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.front_end.arn
}
}
- Update the protocol to either
HTTPS
orTLS
.
Option B: Ensure CloudFront is using HTTPS
- Go through the issues that GuardRails identified.
- Locate the
aws_cloudfront_distribution
resource.
resource "aws_cloudfront_distribution" "s3_distribution" {
origin {
domain_name = aws_s3_bucket.b.bucket_regional_domain_name
...
}
enabled = true
...
aliases = ["mysite.example.com", "yoursite.example.com"]
default_cache_behavior {
allowed_methods = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"]
cached_methods = ["GET", "HEAD"]
target_origin_id = local.s3_origin_id
forwarded_values {
query_string = false
cookies {
forward = "none"
}
}
viewer_protocol_policy = "allow-all"
min_ttl = 0
default_ttl = 3600
max_ttl = 86400
}
- If the
viewer_protocol_policy
is missing or set toallow-all
, then change it to eitherhttps-only
orredirect-to-https
.
Ensure Secure SSL/TLS Configuration
Even though SSL/TLS is configured for certain services, it may be configured insecurely and as a result increase the risk of getting intercepted.
Option A: Use correct SSL/TLS policy for AWS ELB
- Go through the issues that GuardRails identified.
- Identify the SSL/TLS related for the
aws_lb_listener
.
resource "aws_lb_listener" "front_end" {
load_balancer_arn = aws_lb.front_end.arn
port = "443"
protocol = "HTTPS"
ssl_policy = "ELBSecurityPolicy-2016-08"
certificate_arn = "arn:aws:iam::187416307283:server-certificate/test_cert_rab3wuqwgja25ct3n4jdj2tzu4"
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.front_end.arn
}
}
- Make sure to avoid the following SSL Policies:
ELBSecurityPolicy-2015-05
ELBSecurityPolicy-TLS-1-0-2015-04
ELBSecurityPolicy-2016-08
ELBSecurityPolicy-TLS-1-1-2017-01
Instead, it is recommended to use:
TLS-1-2-2017-01
- Test it
- Ship it 🚢 and relax 🌴
Option B: Use secure minimum_protocol_version of TLS for CloudFront
- Go through the issues that GuardRails identified.
- Identify the SSL/TLS related for the
aws_cloudfront_distribution
. - Ensure that the
viewer_certificate
is configured securely.
viewer_certificate {
...
minimum_protocol_version = TLSv1.2_2019
}
Option C: Use correct security policy for AWS API Gateway
- Go through the issues that GuardRails identified.
- Locate the
aws_api_gateway_domain_name
resource and thesecurity_policy
if it exists.
resource "aws_api_gateway_domain_name" "example" {
domain_name = "api.example.com"
regional_certificate_name = "example-api"
...
}
- Change the
security_policy
toTLS_1_2
.
resource "aws_api_gateway_domain_name" "example" {
domain_name = "api.example.com"
regional_certificate_name = "example-api"
...
security_policy = "TLS_1_2"
}