-
Notifications
You must be signed in to change notification settings - Fork 0
/
iamAttachments2PoliciesList.py
55 lines (44 loc) · 1.31 KB
/
iamAttachments2PoliciesList.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python3
"""
Simple script to list all entities a list of policies is attached to
"""
import sys
import boto3
import colorama
from colorama import Fore, Style
#declare variables
profile = 'default'
policy_list_file = 'sqs_policies.txt'
#read role file
policies_file_FH = open(policy_list_file, "r")
if policies_file_FH.mode == 'r':
policies = policies_file_FH.readlines()
#create boto session and client
session = boto3.Session(profile_name = profile)
iam_client = session.client('iam', region_name='us-east-1')
for i in policies:
policyarn = "arn:aws:iam::600690756780:policy/{}".format(i).rstrip('\r|\n')
try:
response = iam_client.list_entities_for_policy(PolicyArn = policyarn)
except Exception as e:
print(e)
else:
print("\n", Fore.GREEN, i, Style.RESET_ALL)
#print groups
for j in response['PolicyGroups']:
try:
print('Group:', j['GroupName'])
except:
pass
#print roles
for x in response['PolicyRoles']:
try:
print('Role:', x['RoleName'])
except:
pass
#print users
for y in response['PolicyUsers']:
try:
print('User:', y['UserName'])
except:
pass