Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a tool to list all security group rules in an account #248

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
log_info -l "Open Ports in the ${INFRASTRUCTURE_NAME} account"
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),\(.)")'