Skip to content

Instantly share code, notes, and snippets.

@random-robbie
Created December 5, 2024 21:48
Show Gist options
  • Save random-robbie/d7ee3f8fe71b28e8a9375ce4176dbbf1 to your computer and use it in GitHub Desktop.
Save random-robbie/d7ee3f8fe71b28e8a9375ce4176dbbf1 to your computer and use it in GitHub Desktop.
Allows Cloudflare IP's to hit port 443 and 80 on your security group.
#!/bin/bash
# Security Group ID
SECURITY_GROUP_ID=sg-05e2bcc947b27e64c
# Fetch Cloudflare IPv4 and IPv6 ranges
IPV4_RANGES=$(curl -s https://www.cloudflare.com/ips-v4/)
# Add IPv4 ranges
for IP in $IPV4_RANGES; do
aws ec2 authorize-security-group-ingress --group-id $SECURITY_GROUP_ID --protocol tcp --port 80 --cidr $IP
aws ec2 authorize-security-group-ingress --group-id $SECURITY_GROUP_ID --protocol tcp --port 443 --cidr $IP
done
echo "Ingress rules for Cloudflare IP ranges added to security group $SECURITY_GROUP_ID."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment