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

Consider resources (naive approach) #16

Closed
wants to merge 2 commits into from
Closed
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
9 changes: 8 additions & 1 deletion cloudtracker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ def get_actions_from_statement(self, stmt):

return actions

def get_resources_from_statement(self, stmt):
"""Figures out what resources have been referenced in a statement"""
return make_list(stmt.get('Resource', []))

def determine_allowed(self):
"""After statements have been added from IAM policiies, find all the allowed API calls"""
actions = {}
Expand All @@ -107,8 +111,10 @@ def determine_allowed(self):
for stmt in self.stmts:
if stmt['Effect'] == 'Deny':
stmt_actions = self.get_actions_from_statement(stmt)
stmt_resources = self.get_resources_from_statement(stmt)
for action in stmt_actions:
if action in actions:
# You can really only consider an action denied if it applies to _all_ resources
if action in actions and '*' in stmt_resources:
del actions[action]

return list(actions)
Expand Down Expand Up @@ -452,3 +458,4 @@ def run(args, config, start, end):
printfilter['show_used'] = args.show_used

print_diff(performed_actions, allowed_actions, printfilter, use_color)
print("len(allowed_actions) => {0}; len(performed_actions) => {1}".format(len(allowed_actions), len(performed_actions)))