Skip to content

Commit

Permalink
Add a tool to list all security group rules in an account
Browse files Browse the repository at this point in the history
  • Loading branch information
rjw1 committed Feb 21, 2024
1 parent d284a59 commit 8222479
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions bin/util/list-security-group-rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
#

usage() {
echo "List all the open ports in all security groups in the account"
echo "Usage: $(basename "$0") [OPTIONS] <command>" 1>&2
echo " -h - help"
echo " -i <infrastructure> - infrastructure name OPTIONAL defaults to main dalmatian account"
exit 1
}

while getopts "ih" opt; do
case $opt in
i)
INFRASTRUCTURE_NAME=$OPTARG
;;
h)
usage
;;
*)
usage
;;
esac
done

aws ec2 describe-security-groups | jq -r '.SecurityGroups[] | .GroupName as $group | .IpPermissions[] | .FromPort as $fromPort | .ToPort as $toPort | ([.IpRanges[]?.CidrIp, .UserIdGroupPairs[]?.GroupId, .Ipv6Ranges[]?.CidrIpv6] | map(select(. != null)) | .[] | "\($group),\($fromPort)-\($toPort),\(.)")'

0 comments on commit 8222479

Please sign in to comment.