Skip to content

Commit

Permalink
Statement: Find all unknown Actions and unknown Prefixes in a Stateme…
Browse files Browse the repository at this point in the history
…nt (#165)

The primary use case of this change is for faster developer feedback.
If there are two typo'd Actions in a single IAM Statement, parliament
will only catch one; the user then makes a fix and then re-runs
parliament to find the second issue. If there is a serious Exception
with the Action syntax, we should still bail out and return False.
However, UnknownAction and UnknownPrefix are recoverable and parliament
should attempt to find all of them.
  • Loading branch information
raghavkaul authored Dec 8, 2020
1 parent 66c6588 commit 3dcf32c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions parliament/statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,7 @@ def analyze_statement(self):

# Expand the actions from s3:Get* to s3:GetObject and others
expanded_actions = []
has_malformed_action = False
for action in actions:

# Handle special case where all actions are allowed
Expand All @@ -785,16 +786,23 @@ def analyze_statement(self):
expanded_actions.extend(expand_action(action.value))
except UnknownActionException as e:
self.add_finding(
"UNKNOWN_ACTION", detail=str(e), location=action,
"UNKNOWN_ACTION",
detail=str(e),
location=action,
)
return False
has_malformed_action = True
continue
except UnknownPrefixException as e:
self.add_finding("UNKNOWN_PREFIX", detail=str(e), location=action)
return False
has_malformed_action = True
continue
except Exception as e:
self.add_finding("EXCEPTION", detail=str(e), location=action)
return False

if has_malformed_action:
return False

# Check the resources are correct formatted correctly
has_malformed_resource = False
for resource in resources:
Expand Down

3 comments on commit 3dcf32c

@siminot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to do a release soon? I really want this feature in my own code.

Thank you! :)

@0xdabbad00
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@siminot Sorry about that. I just put up a PR to bump the version so I can cut a release: #168

@siminot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@0xdabbad00 Thank you!

Please sign in to comment.