-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds new test for cross-account roles requiring MFA (#97)
* Initial pass at test for admin roles requiring MFA * Fixed filename and added new policies needed * Added disclaimers/notes about potential for false positives/negatives
- Loading branch information
Showing
5 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import pytest | ||
|
||
from aws.iam.resources import iam_admin_roles | ||
|
||
|
||
@pytest.mark.iam | ||
@pytest.mark.parametrize( | ||
'iam_admin_role', | ||
iam_admin_roles(), | ||
ids=lambda role: role['RoleName']) | ||
def test_iam_cross_account_admin_roles_require_mfa(iam_admin_role): | ||
"""Test that all IAM Roles that include admin policies and have cross account | ||
trust relationships require MFA. | ||
Note: Due to the naive mechanism for determing what an "admin" is, this test | ||
can easily have both false positives and (more likely) false negatives. | ||
""" | ||
for statement in iam_admin_role["AssumeRolePolicyDocument"]["Statement"]: | ||
if statement["Action"].startswith("sts") and "AWS" in statement["Principal"]: | ||
assert 'Condition' in statement | ||
assert 'aws:MultiFactorAuthPresent' in statement['Condition']['Bool'] | ||
assert statement['Condition']['Bool']['aws:MultiFactorAuthPresent'] == 'true' |