GuardRails

GuardRails

  • Languages iconEnglish
    • 中文

›Terraform

Overview

  • Introduction
  • What is GuardRails
  • Getting started
  • Findings
  • Vulnerabilities
  • Configuration
  • Custom Engines
  • False Positives
  • Enforce Passing Checks
  • Build Status on Pull Requests
  • FAQ
  • Pricing
  • Glossary
  • Tools & Licenses

API

  • Usage Guide
  • Endpoints

Vulnerabilities

  • Introduction
  • General

    • Overview
    • Hard-Coded Secrets

    Apex

    • Overview
    • Insecure Access Control
    • Insecure Network Communication
    • Insecure Processing of Data
    • Insecure Use of Cryptography
    • Insecure Use of Language/Framework API
    • Insecure Use of SQL Queries

    C/C++

    • Overview
    • Insecure Access Control
    • Insecure File Management
    • Insecure Processing of Data
    • Insecure Use of Cryptography
    • Insecure Use of Dangerous Function

    Dotnet

    • Overview
    • Insecure Access Control
    • Insecure Configuration
    • Insecure File Management
    • Insecure Processing of Data
    • Insecure Use of Cryptography
    • Insecure Use of Dangerous Function
    • Insecure Use of SQL Queries
    • Using Vulnerable Libraries

    Elixir

    • Overview
    • Insecure Configuration
    • Insecure File Management
    • Insecure Processing of Data
    • Insecure Network Communication
    • Insecure Use of Dangerous Function
    • Insecure Use of Language/Framework API
    • Insecure Use of SQL Queries
    • Using Vulnerable Libraries

    Go

    • Overview
    • Insecure File Management
    • Insecure Network Communication
    • Insecure Processing of Data
    • Insecure Use of Cryptography
    • Insecure Use of Dangerous Function
    • Insecure Use of SQL Queries
    • Using Vulnerable Libraries

    Java

    • Overview
    • Using Vulnerable Libraries
    • Insecure Use of SQL Queries
    • Insecure Use of Dangerous Function
    • Insecure Use of Regular Expressions
    • Insecure Authentication
    • Insecure Configuration
    • Insecure File Management
    • Insecure Use of Cryptography
    • Insecure Use of Language/Framework API
    • Insecure Processing of Data
    • Insecure Network Communication

    Javascript/TypeScript

    • Overview
    • Insecure Authentication
    • Insecure Processing of Data
    • Insecure Use of SQL Queries
    • Insecure Use of Regular Expressions
    • Insecure Use of Language/Framework API
    • Insecure Use of Dangerous Function
    • Using Vulnerable Libraries

    Kubernetes

    • Overview
    • Insecure Access Control
    • Insecure Configuration
    • Insecure Network Communication

    PHP

    • Overview
    • Insecure Configuration
    • Insecure File Management
    • Insecure Network Communication
    • Insecure Processing of Data
    • Insecure Use of Dangerous Function
    • Insecure Use of Language/Framework API
    • Insecure Use of Regular Expressions
    • Insecure Use of SQL Queries
    • Using Vulnerable Libraries

    Python

    • Overview
    • Insecure Configuration
    • Insecure Use of Cryptography
    • Insecure Network Communication
    • Insecure Processing of Data
    • Insecure Use of Dangerous Function
    • Insecure Use of SQL Queries
    • Using Vulnerable Libraries

    Ruby

    • Overview
    • Insecure Access Control
    • Insecure Configuration
    • Insecure File Management
    • Insecure Network Communication
    • Insecure Processing of Data
    • Insecure Use of Dangerous Function
    • Insecure Use of Language/Framework API
    • Insecure Use of Regular Expressions
    • Insecure Use of SQL Queries
    • Using Vulnerable Libraries

    Rust

    • Overview
    • Using Vulnerable Libraries

    Solidity

    • Overview
    • Insecure Integer Arithmetic
    • Insecure Use of Low-Level Call
    • Reliance on Insecure Random Numbers
    • State Change After External Call
    • Transaction Order Dependence
    • Unprotected Critical Function
    • Use of Insecure Function
    • Dependence on Predictable Environment Variables
    • Write to Arbitrary Storage Location
    • Call to Untrusted Contract

    Terraform

    • Overview
    • Hard-Coded Secrets
    • Insecure Access Control
    • Insecure Configuration
    • Insecure Network Communication
    • Insecure Use of Cryptography

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:

Insufficient Transport Layer Protection

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:

  • MSK Cluster - Encryption Info Arguments

Option A: Ensure MSK Encryption in Transit

  1. Go through the issues that GuardRails identified.
  2. 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]
  }
}
  1. 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:

  • Kinesis Stream - Encryption Type Arguments

Option A: Ensure Kinesis Stream Encryption in Transit

  1. Go through the issues that GuardRails identified.
  2. 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"
  }
}
  1. Ensure that the aws_kinesis_stream resource includes the encryption_type argument set to KMS.
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

  1. Go through the issues that GuardRails identified.
  2. 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
  }
}
  1. Update the protocol to either HTTPS or TLS.

Option B: Ensure CloudFront is using HTTPS

  1. Go through the issues that GuardRails identified.
  2. 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
  }
  1. If the viewer_protocol_policy is missing or set to allow-all, then change it to either https-only or redirect-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

  1. Go through the issues that GuardRails identified.
  2. 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
  }
}
  1. 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
  1. Test it
  2. Ship it 🚢 and relax 🌴

Option B: Use secure minimum_protocol_version of TLS for CloudFront

  1. Go through the issues that GuardRails identified.
  2. Identify the SSL/TLS related for the aws_cloudfront_distribution.
  3. 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

  1. Go through the issues that GuardRails identified.
  2. Locate the aws_api_gateway_domain_name resource and the security_policy if it exists.
resource "aws_api_gateway_domain_name" "example" {
  domain_name               = "api.example.com"
  regional_certificate_name = "example-api"
  ...
}
  1. Change the security_policy to TLS_1_2.
resource "aws_api_gateway_domain_name" "example" {
  domain_name               = "api.example.com"
  regional_certificate_name = "example-api"
  ...
  security_policy = "TLS_1_2"
}
← Insecure ConfigurationInsecure Use of Cryptography →
  • Why is this important?
  • Unencrypted MSK Broker
    • Option A: Ensure MSK Encryption in Transit
  • Unencrypted Kinesis Stream
    • Option A: Ensure Kinesis Stream Encryption in Transit
  • Ensure Encryption in Transit
    • Option A: Ensure AWS Load Balancer is using HTTPS
    • Option B: Ensure CloudFront is using HTTPS
  • Ensure Secure SSL/TLS Configuration
    • Option A: Use correct SSL/TLS policy for AWS ELB
    • Option B: Use secure minimum_protocol_version of TLS for CloudFront
    • Option C: Use correct security policy for AWS API Gateway
  • Status
  • Help
  • Security
  • Terms
  • Privacy

© 2021 GuardRails