Back to Checks
Security group does not allow ingress from 0.0.0.0/0 or ::/0 to TCP port 9092 (Kafka)
ec2_securitygroup_allow_ingress_from_internet_to_tcp_port_kafka_9092
Service: ec2Severity: high
OfficialBuilt-inVerified
Categories:internet-exposed
Resource Type:AwsEc2SecurityGroup
EC2 security groups are evaluated for ingress rules that expose Kafka on TCP 9092 to the Internet via 0.0.0.0/0 or ::/0
Risk
Public Kafka 9092 access allows arbitrary clients to connect, enabling topic enumeration, data exfiltration, and producer/consumer impersonation (C/I). Brokers can be flooded or exploited, disrupting clusters (A). Exposure gives attackers a foothold for lateral movement inside the VPC.
Run this check with Prowler
Run in Prowler CloudRun
prowler aws --checks ec2_securitygroup_allow_ingress_from_internet_to_tcp_port_kafka_9092Recommendation
Apply least privilege: restrict 9092 to required subnets or IPs; avoid 0.0.0.0/0 and ::/0. Place brokers on private networks and use peering or VPN for access. Enforce mutual TLS/SASL and topic ACLs, and add defense in depth with segmentation and NACLs.
Remediation
CLI
aws ec2 revoke-security-group-ingress --group-id <SECURITY_GROUP_ID> --ip-permissions '[{"IpProtocol":"tcp","FromPort":9092,"ToPort":9092,"IpRanges":[{"CidrIp":"0.0.0.0/0"}],"Ipv6Ranges":[{"CidrIpv6":"::/0"}]}]'Terraform
# Restrict Kafka (9092) from Internet
resource "aws_security_group" "<example_resource_name>" {
name = "<example_resource_name>"
vpc_id = "<example_resource_id>"
ingress {
from_port = 9092
to_port = 9092
protocol = "tcp"
cidr_blocks = ["10.0.0.0/8"] # Critical: not 0.0.0.0/0; restricts access to avoid Internet exposure
}
}NativeIaC
# CloudFormation: restrict Kafka (9092) from Internet
Resources:
<example_resource_name>:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Restrict Kafka 9092
VpcId: <example_resource_id>
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 9092
ToPort: 9092
CidrIp: 10.0.0.0/8 # Critical: not 0.0.0.0/0; restricts access to private range to avoid Internet exposureOther
1In AWS Console, go to EC2 > Security Groups
2Select the group attached to the resource
3Inbound rules > Edit inbound rules
4Find any rule for TCP port 9092 with Source 0.0.0.0/0 or ::/0
5Delete the rule or change Source to a specific trusted CIDR or security group
6Save rules
Check Code
from prowler.lib.check.models import Check, Check_Report_AWS
from prowler.providers.aws.services.ec2.ec2_client import ec2_client
from prowler.providers.aws.services.ec2.ec2_securitygroup_allow_ingress_from_internet_to_all_ports import (
ec2_securitygroup_allow_ingress_from_internet_to_all_ports,
)
from prowler.providers.aws.services.ec2.lib.security_groups import check_security_group
from prowler.providers.aws.services.vpc.vpc_client import vpc_client
class ec2_securitygroup_allow_ingress_from_internet_to_tcp_port_kafka_9092(Check):
def execute(self):
findings = []
check_ports = [9092]
for security_group_arn, security_group in ec2_client.security_groups.items():
# Check if ignoring flag is set and if the VPC and the SG is in use
if ec2_client.provider.scan_unused_services or (
security_group.vpc_id in vpc_client.vpcs
and vpc_client.vpcs[security_group.vpc_id].in_use
and len(security_group.network_interfaces) > 0
):
report = Check_Report_AWS(
metadata=self.metadata(), resource=security_group
)
report.resource_details = security_group.name
report.status = "PASS"
report.status_extended = f"Security group {security_group.name} ({security_group.id}) does not have Kafka port 9092 open to the Internet."
# only proceed if check "..._to_all_ports" did not run or did not FAIL to avoid to report open ports twice
if not ec2_client.is_failed_check(
ec2_securitygroup_allow_ingress_from_internet_to_all_ports.__name__,
security_group_arn,
):
# Loop through every security group's ingress rule and check it
for ingress_rule in security_group.ingress_rules:
if check_security_group(
ingress_rule, "tcp", check_ports, any_address=True
):
report.status = "FAIL"
report.status_extended = f"Security group {security_group.name} ({security_group.id}) has Kafka port 9092 open to the Internet."
break
else:
report.status_extended = f"Security group {security_group.name} ({security_group.id}) has all ports open to the Internet and therefore was not checked against the specific Kafka port 9092."
findings.append(report)
return findings