-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #268 from Skyscanner/bump_pycfmodel
Bump pycfmodel and fix KMSKeyWildcardPrincipalRule
- Loading branch information
Showing
12 changed files
with
157 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,6 @@ version-resolver: | |
- 'patch' | ||
default: patch | ||
template: | | ||
## Changes | ||
## Changes | ||
$CHANGES |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
VERSION = (1, 15, 3) | ||
VERSION = (1, 15, 4) | ||
|
||
__version__ = ".".join(map(str, VERSION)) |
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 |
---|---|---|
@@ -1,22 +1,49 @@ | ||
# import pytest | ||
# | ||
# from cfripper.rules.KMSKeyWildcardPrincipal import KMSKeyWildcardPrincipal | ||
# from cfripper.model.result import Result | ||
# from tests.utils import get_cfmodel_from | ||
|
||
# TODO Implement check if this is needed as GenericWildcardPrincipal rule seems to include this one | ||
# @pytest.fixture() | ||
# def abcdef(): | ||
# return get_cfmodel_from("rules/KMSKeyWildcardPrincipal/abcdef.json").resolve() | ||
# | ||
# | ||
# def test_abcdef(abcdef): | ||
# result = Result() | ||
# rule = KMSKeyWildcardPrincipal(None, result) | ||
# rule.invoke(abcdef) | ||
# | ||
# assert not result.valid | ||
# assert len(result.failed_rules) == 1 | ||
# assert len(result.failed_monitored_rules) == 0 | ||
# assert result.failed_rules[0].rule == "KMSKeyWildcardPrincipal" | ||
# assert result.failed_rules[0].reason == "KMS Key policy {} should not allow wildcard principals" | ||
import pytest | ||
|
||
from cfripper.model.result import Failure | ||
from cfripper.rules import KMSKeyWildcardPrincipalRule | ||
from tests.utils import compare_lists_of_failures, get_cfmodel_from | ||
|
||
|
||
@pytest.fixture() | ||
def kms_key_with_wildcard_policy(): | ||
return get_cfmodel_from("rules/KMSKeyWildcardPrincipalRule/kms_key_with_wildcard_resource.json").resolve() | ||
|
||
|
||
@pytest.fixture() | ||
def kms_key_without_policy(): | ||
return get_cfmodel_from("rules/KMSKeyWildcardPrincipalRule/kms_key_without_policy.yml").resolve() | ||
|
||
|
||
def test_kms_key_with_wildcard_resource_not_allowed_is_flagged(kms_key_with_wildcard_policy): | ||
rule = KMSKeyWildcardPrincipalRule(None) | ||
rule._config.stack_name = "stack3" | ||
rule.all_cf_actions = set() | ||
result = rule.invoke(kms_key_with_wildcard_policy) | ||
|
||
assert result.valid is False | ||
assert compare_lists_of_failures( | ||
result.failures, | ||
[ | ||
Failure( | ||
granularity="RESOURCE", | ||
reason="KMS Key policy myKey should not allow wildcard principals", | ||
risk_value="MEDIUM", | ||
rule="KMSKeyWildcardPrincipalRule", | ||
rule_mode="BLOCKING", | ||
actions=None, | ||
resource_ids={"myKey"}, | ||
resource_types=None, | ||
) | ||
], | ||
) | ||
|
||
|
||
def test_kms_key_without_policy_is_not_flagged(kms_key_without_policy): | ||
rule = KMSKeyWildcardPrincipalRule(None) | ||
rule._config.stack_name = "stack3" | ||
rule.all_cf_actions = set() | ||
result = rule.invoke(kms_key_without_policy) | ||
|
||
assert result.valid | ||
assert compare_lists_of_failures(result.failures, []) |
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
9 changes: 9 additions & 0 deletions
9
tests/test_templates/rules/CrossAccountTrustRule/kms_key_without_policy.yml
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,9 @@ | ||
--- | ||
AWSTemplateFormatVersion: "2010-09-09" | ||
|
||
Resources: | ||
MyKey: | ||
Type: "AWS::KMS::Key" | ||
Properties: | ||
EnableKeyRotation: true | ||
Enabled: true |
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
9 changes: 9 additions & 0 deletions
9
tests/test_templates/rules/KMSKeyWildcardPrincipalRule/kms_key_without_policy.yml
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,9 @@ | ||
--- | ||
AWSTemplateFormatVersion: "2010-09-09" | ||
|
||
Resources: | ||
MyKey: | ||
Type: "AWS::KMS::Key" | ||
Properties: | ||
EnableKeyRotation: true | ||
Enabled: true |