Skip to content

Commit

Permalink
kms key to use default property policy_documents (#93)
Browse files Browse the repository at this point in the history
Co-authored-by: Ramon <[email protected]>
  • Loading branch information
w0rmr1d3r and w0rmr1d3r authored Mar 2, 2022
1 parent 29b0cd8 commit ef2fe97
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Change Log
All notable changes to this project will be documented in this file.

## 0.17.0 - [2022-03-02]
### Additions
- `KMSKey` to use default `policy_documents` property instead of returning an empty list.
### Updates
- Update `CLOUDFORMATION_ACTIONS`.

## 0.16.3 - [2022-02-24]
### Fixes
- Fix `resolve` for `bool`s that can be `str` such as `"true"` or `"false"` or similar, by making `ResolvableBool` to be resolvable to `SemiStrictBool`.
Expand Down
16 changes: 16 additions & 0 deletions pycfmodel/cloudformation_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4547,6 +4547,7 @@
"events:UpdateApiDestination",
"events:UpdateArchive",
"events:UpdateConnection",
"evidently:BatchEvaluateFeature",
"evidently:CreateExperiment",
"evidently:CreateFeature",
"evidently:CreateLaunch",
Expand All @@ -4555,6 +4556,7 @@
"evidently:DeleteFeature",
"evidently:DeleteLaunch",
"evidently:DeleteProject",
"evidently:EvaluateFeature",
"evidently:GetExperiment",
"evidently:GetExperimentResults",
"evidently:GetFeature",
Expand All @@ -4565,6 +4567,7 @@
"evidently:ListLaunches",
"evidently:ListProjects",
"evidently:ListTagsForResource",
"evidently:PutProjectEvents",
"evidently:StartExperiment",
"evidently:StartLaunch",
"evidently:StopExperiment",
Expand Down Expand Up @@ -8297,13 +8300,15 @@
"outposts:CancelOrder",
"outposts:CreateOrder",
"outposts:CreateOutpost",
"outposts:CreatePrivateConnectivityConfig",
"outposts:CreateSite",
"outposts:DeleteOutpost",
"outposts:DeleteSite",
"outposts:GetCatalogItem",
"outposts:GetOrder",
"outposts:GetOutpost",
"outposts:GetOutpostInstanceTypes",
"outposts:GetPrivateConnectivityConfig",
"outposts:GetSite",
"outposts:GetSiteAddress",
"outposts:ListCatalogItems",
Expand Down Expand Up @@ -9636,12 +9641,14 @@
"s3:GetMultiRegionAccessPointPolicyStatus",
"s3:GetObject",
"s3:GetObjectAcl",
"s3:GetObjectAttributes",
"s3:GetObjectLegalHold",
"s3:GetObjectRetention",
"s3:GetObjectTagging",
"s3:GetObjectTorrent",
"s3:GetObjectVersion",
"s3:GetObjectVersionAcl",
"s3:GetObjectVersionAttributes",
"s3:GetObjectVersionForReplication",
"s3:GetObjectVersionTagging",
"s3:GetObjectVersionTorrent",
Expand Down Expand Up @@ -11135,6 +11142,7 @@
"support:RefreshTrustedAdvisorCheck",
"support:ResolveCase",
"support:SearchForCases",
"sustainability:GetCarbonFootprintSummary",
"swf:CancelTimer",
"swf:CancelWorkflowExecution",
"swf:CompleteWorkflowExecution",
Expand Down Expand Up @@ -11270,6 +11278,7 @@
"transcribe:ListLanguageModels",
"transcribe:ListMedicalTranscriptionJobs",
"transcribe:ListMedicalVocabularies",
"transcribe:ListTagsForResource",
"transcribe:ListTranscriptionJobs",
"transcribe:ListVocabularies",
"transcribe:ListVocabularyFilters",
Expand All @@ -11280,6 +11289,8 @@
"transcribe:StartStreamTranscription",
"transcribe:StartStreamTranscriptionWebSocket",
"transcribe:StartTranscriptionJob",
"transcribe:TagResource",
"transcribe:UntagResource",
"transcribe:UpdateCallAnalyticsCategory",
"transcribe:UpdateMedicalVocabulary",
"transcribe:UpdateVocabulary",
Expand Down Expand Up @@ -11340,7 +11351,11 @@
"trustedadvisor:DescribeOrganization",
"trustedadvisor:DescribeOrganizationAccounts",
"trustedadvisor:DescribeReports",
"trustedadvisor:DescribeRisk",
"trustedadvisor:DescribeRiskResources",
"trustedadvisor:DescribeRisks",
"trustedadvisor:DescribeServiceMetadata",
"trustedadvisor:DownloadRisk",
"trustedadvisor:ExcludeCheckItems",
"trustedadvisor:GenerateReport",
"trustedadvisor:IncludeCheckItems",
Expand All @@ -11351,6 +11366,7 @@
"trustedadvisor:SetAccountAccess",
"trustedadvisor:SetOrganizationAccess",
"trustedadvisor:UpdateNotificationPreferences",
"trustedadvisor:UpdateRiskStatus",
"voiceid:CreateDomain",
"voiceid:DeleteDomain",
"voiceid:DeleteFraudster",
Expand Down
6 changes: 0 additions & 6 deletions pycfmodel/model/resources/kms_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from pycfmodel.model.resources.properties.tag import Tag
from pycfmodel.model.resources.resource import Resource
from pycfmodel.model.types import Resolvable, ResolvableBool, ResolvableInt, ResolvableStr
from pycfmodel.model.utils import OptionallyNamedPolicyDocument


class KMSKeyProperties(CustomModel):
Expand Down Expand Up @@ -48,8 +47,3 @@ class KMSKey(Resource):
TYPE_VALUE: ClassVar = "AWS::KMS::Key"
Type: str = TYPE_VALUE
Properties: Resolvable[KMSKeyProperties]

@property
def policy_documents(self) -> List[OptionallyNamedPolicyDocument]:
# Key policies are a bit different than most policies and would raise issues if treated equally
return []
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

setup(
name="pycfmodel",
version="0.16.3",
version="0.17.0",
description="A python model for CloudFormation scripts",
author="Skyscanner Product Security",
author_email="[email protected]",
Expand Down
2 changes: 2 additions & 0 deletions tests/resources/properties/test_policy_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,14 @@ def test_get_allowed_actions(policy_document_not_principal):
"iam:DeleteVirtualMFADevice",
"s3:GetObject",
"s3:GetObjectAcl",
"s3:GetObjectAttributes",
"s3:GetObjectLegalHold",
"s3:GetObjectRetention",
"s3:GetObjectTagging",
"s3:GetObjectTorrent",
"s3:GetObjectVersion",
"s3:GetObjectVersionAcl",
"s3:GetObjectVersionAttributes",
"s3:GetObjectVersionForReplication",
"s3:GetObjectVersionTagging",
"s3:GetObjectVersionTorrent",
Expand Down
50 changes: 49 additions & 1 deletion tests/resources/test_kms_key.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pytest

from pycfmodel.model.resources.kms_key import KMSKey
from pycfmodel.model.resources.properties.policy_document import PolicyDocument
from pycfmodel.model.utils import OptionallyNamedPolicyDocument


@pytest.fixture()
Expand Down Expand Up @@ -115,4 +117,50 @@ def test_actions(kms_key):


def test_kms_policy_documents(kms_key):
assert kms_key.policy_documents == []
assert kms_key.policy_documents == [
OptionallyNamedPolicyDocument(
name=None,
policy_document=PolicyDocument(
**{
"Version": "2012-10-17",
"Id": "key-default-1",
"Statement": [
{
"Sid": "Enable IAM User Permissions",
"Effect": "Allow",
"Principal": {"AWS": "arn:aws:iam::111122223333:root"},
"Action": "kms:*",
"Resource": "*",
},
{
"Sid": "Allow administration of the key",
"Effect": "Allow",
"Principal": {"AWS": "arn:aws:iam::111122223333:role/Admin"},
"Action": [
"kms:Create*",
"kms:Describe*",
"kms:Enable*",
"kms:List*",
"kms:Put*",
"kms:Update*",
"kms:Revoke*",
"kms:Disable*",
"kms:Get*",
"kms:Delete*",
"kms:ScheduleKeyDeletion",
"kms:CancelKeyDeletion",
],
"Resource": "*",
},
{
"Sid": "Allow use of the key",
"Effect": "Allow",
"Principal": {"AWS": "arn:aws:iam::111122223333:role/Developer"},
"Action": ["kms:Sign", "kms:Verify", "kms:DescribeKey"],
"Resource": "*",
},
],
}
),
)
]

0 comments on commit ef2fe97

Please sign in to comment.