Description

Ensure that every Application Load Balancer accepts only encrypted traffic from clients. Either the load balancer has no HTTP listener, or each HTTP listener has a rule (any rule, not only the default rule) whose action redirects requests to HTTPS. Network and Gateway Load Balancers are not evaluated.

Rationale

An HTTP listener that forwards requests lets traffic travel in plaintext between clients and the load balancer. This allows interception, credential theft, session hijacking and response tampering, especially on public or shared networks. All traffic should use HTTPS listeners with a strong TLS security policy and managed certificates, and any HTTP listener should only redirect to HTTPS. HTTP Strict Transport Security (HSTS) can further prevent browsers from using HTTP.

Impact

  • Ensures client traffic to the load balancer is encrypted

  • Clients that connect over HTTP are redirected to HTTPS; clients that cannot follow redirects or use TLS stop working

  • Requires an HTTPS listener with a valid TLS certificate for the load balancer's domain name

Default Value

There is no default listener protocol. An Application Load Balancer has the listeners and rules that were configured when it was created or added later.

Pre-Requisites

  • IAM permissions: elasticloadbalancing:DescribeLoadBalancers, elasticloadbalancing:DescribeListeners, elasticloadbalancing:DescribeRules, elasticloadbalancing:CreateListener and elasticloadbalancing:ModifyListener

  • A TLS certificate in AWS Certificate Manager (ACM) for the load balancer's domain name, if no HTTPS listener exists yet

Test Plan

Console:

  1. Sign in to the AWS Management Console at https://console.aws.amazon.com.

  2. Open the Amazon EC2 console and select Load Balancers under Load Balancing.

  3. Select each load balancer of type application and open the Listeners and rules tab.

  4. For each listener with protocol HTTP, check whether its rules redirect to HTTPS.

  5. Repeat for each region in use.

  6. If an HTTP listener does not redirect to HTTPS, follow the implementation steps.

CLI:

List the Application Load Balancers in a region:

aws elbv2 describe-load-balancers --region <REGION> --query "LoadBalancers[?Type=='application'].[LoadBalancerName,LoadBalancerArn]" --output table

List the listeners of a load balancer:

aws elbv2 describe-listeners --load-balancer-arn <LOAD_BALANCER_ARN> --region <REGION> --query "Listeners[].[ListenerArn,Protocol,Port]" --output table

Show the actions of each rule of an HTTP listener:

aws elbv2 describe-rules --listener-arn <LISTENER_ARN> --region <REGION> --query "Rules[].[Priority,Actions[].Type,Actions[].RedirectConfig.Protocol]"

A load balancer fails if it has an HTTP listener and none of that listener's rules (the default rule or any other rule) has a redirect action with protocol HTTPS; a load balancer with no HTTP listener passes.

Implementation Steps

Console:

  1. Sign in to the AWS Management Console at https://console.aws.amazon.com.

  2. Open the Amazon EC2 console and select Load Balancers under Load Balancing.

  3. Select the Application Load Balancer and open the Listeners and rules tab.

  4. If there is no HTTPS listener, choose Add listener, select protocol HTTPS (port 443), set the default action to forward to the target group and select the TLS certificate, then choose Add.

  5. Select the HTTP listener and choose to edit it.

  6. Set the default action to Redirect to URL with protocol HTTPS, port 443 and status code 301.

  7. Save the changes.

  8. Repeat for each affected load balancer in each region in use.

CLI:

Add an HTTPS listener if the load balancer does not have one:

aws elbv2 create-listener --load-balancer-arn <LOAD_BALANCER_ARN> --protocol HTTPS --port 443 --certificates CertificateArn=<CERTIFICATE_ARN> --default-actions Type=forward,TargetGroupArn=<TARGET_GROUP_ARN> --region <REGION>

Change the HTTP listener to redirect all requests to HTTPS:

aws elbv2 modify-listener --listener-arn <LISTENER_ARN> --default-actions '[{"Type":"redirect","RedirectConfig":{"Protocol":"HTTPS","Port":"443","StatusCode":"HTTP_301"}}]' --region <REGION>

Backout Plan

Before making changes, save the current listener configuration:

aws elbv2 describe-listeners --load-balancer-arn <LOAD_BALANCER_ARN> --region <REGION> > alb-listeners-backup.json

To roll back:

  1. Sign in to the AWS Management Console at https://console.aws.amazon.com.

  2. Open the Amazon EC2 console and select Load Balancers.

  3. Select the Application Load Balancer and open the Listeners and rules tab.

  4. Edit the HTTP listener and set the default action back to the value in the saved backup (for example, forward to the target group).

  5. Save the changes.

CLI:

aws elbv2 modify-listener --listener-arn <LISTENER_ARN> --default-actions Type=forward,TargetGroupArn=<TARGET_GROUP_ARN> --region <REGION>

Note: rolling back allows clients to send traffic in plaintext again.

Reference