Created
February 7, 2014 00:53
-
-
Save kjoconnor/8855568 to your computer and use it in GitHub Desktop.
Find security group grants in ElastiCache and EC2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from boto.ec2 import connect_to_region | |
from boto.elasticache import connect_to_region as elasticache_region | |
target = 'sg-name' | |
ec2 = connect_to_region('us-east-1') | |
ec = elasticache_region('us-east-1') | |
sgs = ec2.get_all_security_groups() | |
for sg in sgs: | |
for rule in sg.rules: | |
for grant in rule.grants: | |
if target == getattr(grant, 'cidr_ip', None) \ | |
or target == getattr(grant, 'groupName', None): | |
print 'target found in sg {sg} as {rule}'\ | |
.format(sg=sg.name, rule=rule) | |
ec_sgs = ec.describe_cache_security_groups() | |
for ec_sg in ec_sgs['DescribeCacheSecurityGroupsResponse']['DescribeCacheSecurityGroupsResult']['CacheSecurityGroups']: | |
if len(ec_sg['EC2SecurityGroups']) > 0: | |
for group in ec_sg['EC2SecurityGroups']: | |
if group['EC2SecurityGroupName'] == target: | |
print 'target found in ec sg {sg}'\ | |
.format(sg=ec_sg['CacheSecurityGroupName']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment