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

chore(kms): add multi_region attribute to AWS KMS key class #6794

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions prowler/providers/aws/services/kms/kms_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def _describe_key(self):
key.origin = response["KeyMetadata"]["Origin"]
key.manager = response["KeyMetadata"]["KeyManager"]
key.spec = response["KeyMetadata"]["CustomerMasterKeySpec"]
key.multi_region = response["KeyMetadata"]["MultiRegion"]
except Exception as error:
logger.error(
f"{regional_client.region} -- {error.__class__.__name__}:{error.__traceback__.tb_lineno} -- {error}"
Expand Down Expand Up @@ -121,4 +122,5 @@ class Key(BaseModel):
policy: Optional[dict]
spec: Optional[str]
region: str
multi_region: Optional[bool]
tags: Optional[list] = []
16 changes: 11 additions & 5 deletions tests/providers/aws/services/kms/kms_service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
)


class Test_ACM_Service:
class Test_KMS_Service:

# Test KMS Service
@mock_aws
Expand Down Expand Up @@ -68,6 +68,7 @@ def test_describe_key(self):
kms_client = client("kms", region_name=AWS_REGION_US_EAST_1)
# Create KMS keys
key1 = kms_client.create_key(
MultiRegion=False,
Tags=[
{"TagKey": "test", "TagValue": "test"},
],
Expand All @@ -80,6 +81,7 @@ def test_describe_key(self):
assert kms.keys[0].state == key1["KeyState"]
assert kms.keys[0].origin == key1["Origin"]
assert kms.keys[0].manager == key1["KeyManager"]
assert kms.keys[0].multi_region == key1["MultiRegion"]
assert kms.keys[0].tags == [
{"TagKey": "test", "TagValue": "test"},
]
Expand All @@ -90,8 +92,8 @@ def test_get_key_rotation_status(self):
# Generate KMS Client
kms_client = client("kms", region_name=AWS_REGION_US_EAST_1)
# Create KMS keys
key1 = kms_client.create_key()["KeyMetadata"]
key2 = kms_client.create_key()["KeyMetadata"]
key1 = kms_client.create_key(MultiRegion=False)["KeyMetadata"]
key2 = kms_client.create_key(MultiRegion=False)["KeyMetadata"]
kms_client.enable_key_rotation(KeyId=key2["KeyId"])
# KMS client for this test class
aws_provider = set_mocked_aws_provider([AWS_REGION_US_EAST_1])
Expand Down Expand Up @@ -138,8 +140,12 @@ def test_get_key_policy(self):
# Generate KMS Client
kms_client = client("kms", region_name=AWS_REGION_US_EAST_1)
# Create KMS keys
key1 = kms_client.create_key(Policy=default_policy)["KeyMetadata"]
key2 = kms_client.create_key(Policy=public_policy)["KeyMetadata"]
key1 = kms_client.create_key(MultiRegion=False, Policy=default_policy)[
"KeyMetadata"
]
key2 = kms_client.create_key(MultiRegion=False, Policy=public_policy)[
"KeyMetadata"
]
# KMS client for this test class
aws_provider = set_mocked_aws_provider([AWS_REGION_US_EAST_1])
kms = KMS(aws_provider)
Expand Down