For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/cloudformation-aws-elb-with-security-group-without-outbound-rules.md.
A documentation index is available at /llms.txt.
Load balancers that are attached to security groups with no outbound rules, or without explicitly defined egress, may be unable to reach backend targets, perform health checks, or connect to logging and monitoring services. This can cause availability and operational failures.
For load balancer resources (AWS::ElasticLoadBalancing::LoadBalancer and AWS::ElasticLoadBalancingV2::LoadBalancer), examine each security group referenced in the resource’s SecurityGroups list and validate the corresponding AWS::EC2::SecurityGroup defines the SecurityGroupEgress property. Resources missing SecurityGroupEgress or with SecurityGroupEgress set to an empty list will be flagged. The SecurityGroupEgress list must contain at least one egress rule that permits the required outbound traffic and should use narrow CIDRs, ports, or security-group destinations rather than broad 0.0.0.0/0 when possible.
Secure example with an explicit outbound rule allowing HTTPS egress:
MySecurityGroup:Type:AWS::EC2::SecurityGroupProperties:GroupDescription:Allow load balancer outbound HTTPS to targetsVpcId:vpc-01234567SecurityGroupEgress:- IpProtocol:tcpFromPort:443ToPort:443CidrIp:10.0.0.0/16
Compliant Code Examples
AWSTemplateFormatVersion:2010-09-09Resources:sgwithegress:Type:AWS::EC2::SecurityGroupProperties:GroupDescription:Limits security group egress trafficSecurityGroupEgress:- IpProtocol:tcpFromPort:80ToPort:80CidrIp:0.0.0.0/0MyLoadBalancer:Type:AWS::ElasticLoadBalancing::LoadBalancerProperties:SecurityGroups:- sgwithegress
{"AWSTemplateFormatVersion":"2010-09-09T00:00:00Z","Resources":{"sgwithegress":{"Properties":{"GroupDescription":"Limits security group egress traffic","SecurityGroupEgress":[{"IpProtocol":"tcp","FromPort":80,"ToPort":80,"CidrIp":"0.0.0.0/0"}]},"Type":"AWS::EC2::SecurityGroup"},"MyLoadBalancer":{"Type":"AWS::ElasticLoadBalancing::LoadBalancer","Properties":{"SecurityGroups":["sgwithegress"]}}}}
Non-Compliant Code Examples
AWSTemplateFormatVersion:2010-09-09Resources:sgwithoutegress:Type:AWS::EC2::SecurityGroupProperties:GroupDescription:Limits security group egress trafficMyLoadBalancer:Type:AWS::ElasticLoadBalancing::LoadBalancerProperties:SecurityGroups:- sgwithoutegress
{"AWSTemplateFormatVersion":"2010-09-09T00:00:00Z","Resources":{"sgwithoutegress":{"Type":"AWS::EC2::SecurityGroup","Properties":{"GroupDescription":"Limits security group egress traffic"}},"MyLoadBalancer":{"Type":"AWS::ElasticLoadBalancing::LoadBalancer","Properties":{"SecurityGroups":["sgwithoutegress"]}}}}
1
2
rulesets:- CloudFormation / AWS # Rules to enforce / AWS.
Request a personalized demo
Get Started with Datadog
Ask AI
AI-generated responses may be inaccurate. Verify important info.