in src/cfnlint/rules/resources/iam/Policy.py [0:0]
def _check_policy_statement(self, branch, statement, is_identity_policy, resource_exceptions):
"""Check statements"""
matches = []
statement_valid_keys = [
'Action',
'Condition',
'Effect',
'NotAction',
'NotPrincipal',
'NotResource',
'Principal',
'Resource',
'Sid',
]
for key, _ in statement.items():
if key not in statement_valid_keys:
message = 'IAM Policy statement key %s isn\'t valid' % (key)
matches.append(
RuleMatch(branch[:] + [key], message))
if 'Effect' not in statement:
message = 'IAM Policy statement missing Effect'
matches.append(
RuleMatch(branch[:], message))
else:
for effect, effect_path in statement.get_safe('Effect'):
if isinstance(effect, six.string_types):
if effect not in ['Allow', 'Deny']:
message = 'IAM Policy Effect should be Allow or Deny'
matches.append(
RuleMatch(branch[:] + effect_path, message))
if 'Action' not in statement and 'NotAction' not in statement:
message = 'IAM Policy statement missing Action or NotAction'
matches.append(
RuleMatch(branch[:], message))
if is_identity_policy:
if 'Principal' in statement or 'NotPrincipal' in statement:
message = 'IAM Resource Policy statement shouldn\'t have Principal or NotPrincipal'
matches.append(
RuleMatch(branch[:], message))
else:
if 'Principal' not in statement and 'NotPrincipal' not in statement:
message = 'IAM Resource Policy statement should have Principal or NotPrincipal'
matches.append(
RuleMatch(branch[:] + ['Principal'], message))
if not resource_exceptions:
if 'Resource' not in statement and 'NotResource' not in statement:
message = 'IAM Policy statement missing Resource or NotResource'
matches.append(
RuleMatch(branch[:], message))
resources = statement.get('Resource', [])
if isinstance(resources, six.string_types):
resources = [resources]
for index, resource in enumerate(resources):
if isinstance(resource, dict):
if len(resource) == 1:
for k in resource.keys():
if k not in FUNCTIONS_SINGLE:
message = 'IAM Policy statement Resource incorrectly formatted'
matches.append(
RuleMatch(branch[:] + ['Resource', index], message))
else:
message = 'IAM Policy statement Resource incorrectly formatted'
matches.append(
RuleMatch(branch[:] + ['Resource', index], message))
return(matches)