Skip to content

Instantly share code, notes, and snippets.

@peterneave
Last active February 5, 2020 14:24
Show Gist options
  • Save peterneave/c752313974ad33609622c1c875703617 to your computer and use it in GitHub Desktop.
Save peterneave/c752313974ad33609622c1c875703617 to your computer and use it in GitHub Desktop.
Setup Linux UFW Firewall to accept Atlassian IP addresses only
#!/usr/bin/env bash
> allowed_ranges
#Bamboo Triggers
echo '18.205.93.0/25' >> allowed_ranges
echo '18.234.32.128/25' >> allowed_ranges
echo '13.52.5.0/25' >> allowed_ranges
#Atlassian IP Addresses
curl -s https://ip-ranges.atlassian.com/ | jq -r '.items[] | .cidr' >> allowed_ranges
echo Allowed Ranges file generated
#!/usr/bin/env bash
read -p "This will delete the iptables and reset based on ufw. Are you sure? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
ufw disable
iptables -F
iptables -X
ufw enable
fi
#!/usr/bin/env bash
if [ ! -f allowed_ranges ]; then
echo Generating allowed ranges
. generate_allowed_list.sh
else
echo Using allowed ranges file
fi
ufw reset
#Always allow local subnet
ufw allow from 192.168.0.0/16
xargs -a allowed_ranges -n 1 -I % ufw allow from % to any port 443
ufw default deny incoming
ufw default allow outgoing
echo
echo Presenting new rules for review
sleep 1
less /lib/ufw/user.rules
read -p "Would you like to apply the rules now? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
ufw enable
ufw status verbose
fi
read -p "Would you like to delete the old rules now? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
rm /lib/ufw/user{,6}.rules.*
rm /etc/ufw/before{,6}.rules.*
rm /etc/ufw/after{,6}.rules.*
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment