Skip to main content

Classic ELB Listener Security Remediation

Triage and Remediation​

Remediation​

Using Console

To remediate the insecure configuration of ELBs in AWS, follow these steps:

  1. Log in to the AWS Management Console.
  2. Navigate to the EC2 dashboard.
  3. Click on the Load Balancers option in the left-hand menu.
  4. Select the ELB that needs to be remediated.
  5. In the bottom panel, click on the Listeners tab.
  6. Review the security protocols and ciphers used in the listener configuration.
  7. Remove any insecure security protocols and ciphers.
  8. Click on the Save button to save the changes.
  9. Repeat these steps for all ELBs that need to be remediated.

Alternatively, you can use AWS CLI to remediate this issue by running the following command:

aws elb describe-load-balancers --load-balancer-names <ELB_NAME> --query 'LoadBalancerDescriptions[].ListenerDescriptions[].Listener' --output text

This command will list all the listeners for the specified ELB, including the security protocols and ciphers used. You can then use the AWS CLI to modify the listeners to remove any insecure configurations.

Using CLI

To remediate an insecure configuration of an Elastic Load Balancer (ELB) in AWS using AWS CLI, you can follow the below steps:

  1. Verify the insecure configuration: Run the below command to get the details of the ELB and verify if it has any insecure configurations:

    aws elb describe-load-balancers --load-balancer-name <ELB-Name>
  2. Update the Security Group: Run the below command to update the security group of the ELB and remove any insecure inbound rules:

    aws elb apply-security-groups-to-load-balancer --load-balancer-name <ELB-Name> --security-groups <Security-Group-ID>

    Note: Replace <ELB-Name> and <Security-Group-ID> with the actual values.

  3. Enable HTTPS: If HTTPS is not enabled, then run the below command to enable it:

    aws elb set-load-balancer-listener-ssl-certificate --load-balancer-name <ELB-Name> --load-balancer-https-port <HTTPS-Port> --ssl-certificate-id <SSL-Certificate-ID>

    Note: Replace <ELB-Name>, <HTTPS-Port> and <SSL-Certificate-ID> with the actual values.

  4. Enable Access Logging: Run the below command to enable access logging for the ELB:

    aws elb create-load-balancer-listeners --load-balancer-name <ELB-Name> --listeners Protocol=HTTP,LoadBalancerPort=<HTTP-Port>,InstanceProtocol=HTTP,InstancePort=<HTTP-Port> --access-log-attributes Enabled=true,S3BucketName=<S3-Bucket-Name>

    Note: Replace <ELB-Name>, <HTTP-Port> and <S3-Bucket-Name> with the actual values.

  5. Verify the remediation: Run the below command to get the details of the ELB and verify if the insecure configurations have been remediated:

    aws elb describe-load-balancers --load-balancer-name <ELB-Name>

By following the above steps, you can remediate the insecure configurations of an Elastic Load Balancer in AWS using AWS CLI.

Using Python

To remediate the ELBs having insecure configurations in AWS using Python, follow these steps:

  1. Install the Boto3 library using pip.
pip install boto3
  1. Create an AWS session using Boto3.
import boto3
session = boto3.Session(
aws_access_key_id='YOUR_ACCESS_KEY',
aws_secret_access_key='YOUR_SECRET_KEY',
region_name='YOUR_REGION'
)
  1. Get the list of all the ELBs in the AWS account.
elbv2_client = session.client('elbv2')
elbs = elbv2_client.describe_load_balancers()
  1. For each ELB, check if it has any insecure configurations.
for elb in elbs['LoadBalancers']:
elb_arn = elb['LoadBalancerArn']
elb_attributes = elbv2_client.describe_load_balancer_attributes(LoadBalancerArn=elb_arn)
for attribute in elb_attributes['Attributes']:
if attribute['Key'] == 'routing.http.drop_invalid_header_fields.enabled' and attribute['Value'] == 'true':
# Remediate the insecure configuration
elbv2_client.modify_load_balancer_attributes(
LoadBalancerArn=elb_arn,
Attributes=[
{
'Key': 'routing.http.drop_invalid_header_fields.enabled',
'Value': 'false'
},
]
)
  1. Finally, re-check if the ELBs now have secure configurations.
elbs = elbv2_client.describe_load_balancers()
for elb in elbs['LoadBalancers']:
elb_arn = elb['LoadBalancerArn']
elb_attributes = elbv2_client.describe_load_balancer_attributes(LoadBalancerArn=elb_arn)
for attribute in elb_attributes['Attributes']:
if attribute['Key'] == 'routing.http.drop_invalid_header_fields.enabled' and attribute['Value'] == 'true':
print(f"Insecure configuration found in ELB {elb_arn}")
else:
print(f"ELB {elb_arn} has a secure configuration")

This will remediate the insecure configuration in all the ELBs in the AWS account using Python.

Using Terraform
resource "aws_elb" "this" {
name = "LOAD_BALANCER_NAME" # replace with your ELB name
subnets = [SUBNET_ID_1, SUBNET_ID_2] # replace with your subnet IDs
security_groups = [SECURITY_GROUP_ID] # replace with your security group IDs
cross_zone_load_balancing = true

# Secure listener (matches the CLI remediation: HTTPS 443 -> HTTP 80 with SSL cert)
listener {
lb_port = 443
lb_protocol = "https"
instance_port = 80 # adjust if your instances use a different port
instance_protocol = "http" # adjust if your instances use a different protocol
ssl_certificate_id = "SSL_CERTIFICATE_ARN" # replace with your valid ACM/IAM certificate ARN
}

# IMPORTANT: remove any insecure listeners (e.g., HTTP:80 or TCP) from Terraform.
# Example of what you SHOULD delete from your configuration:
#
# listener {
# lb_port = 80
# lb_protocol = "http"
# instance_port = 80
# instance_protocol = "http"
# }
}

This change updates the ELB listeners in place: Terraform will add the HTTPS listener (if not present) and remove any HTTP/TCP listeners you delete from the config, which can impact traffic when the insecure listener is removed; ensure the HTTPS listener is healthy before applying.

For verification, terraform plan should show the aws_elb.this resource being updated with:

  • an added listener block using lb_protocol = "https" on port 443 with ssl_certificate_id set, and
  • removed listener blocks for insecure protocols/ports (e.g., lb_protocol = "http" on port 80).