Skip to content

Commit

Permalink
Move KMS validation for SSESpecification on Tables (#3700)
Browse files Browse the repository at this point in the history
* Remove rule E3640 and move to standard schemas
  • Loading branch information
kddejong authored Sep 19, 2024
1 parent 25b5930 commit bf07614
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 51 deletions.
12 changes: 12 additions & 0 deletions scripts/update_schemas_manually.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,14 @@
},
path="/",
),
Patch(
values={"enum": ["KMS"]},
path="/definitions/SSESpecification/properties/SSEType",
),
Patch(
values={"dependentRequired": {"KMSMasterKeyId": ["SSEType"]}},
path="/definitions/SSESpecification",
),
],
),
ResourcePatch(
Expand Down Expand Up @@ -670,6 +678,10 @@
},
path="/",
),
Patch(
values={"enum": ["AES256", "KMS"]},
path="/definitions/SSESpecification/properties/SSEType",
),
],
),
ResourcePatch(
Expand Down
1 change: 1 addition & 0 deletions scripts/update_snapshot_results.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ cfn-lint test/fixtures/templates/integration/availability-zones.yaml -e -c I --f
cfn-lint test/fixtures/templates/integration/aws-ec2-networkinterface.yaml -e -c I --format json > test/fixtures/results/integration/aws-ec2-networkinterface.json
cfn-lint test/fixtures/templates/integration/aws-ec2-instance.yaml -e -c I --format json > test/fixtures/results/integration/aws-ec2-instance.json
cfn-lint test/fixtures/templates/integration/aws-ec2-launchtemplate.yaml -e -c I --format json > test/fixtures/results/integration/aws-ec2-launchtemplate.json
cfn-lint test/fixtures/templates/integration/aws-dynamodb-table.yaml -e -c I --format json > test/fixtures/results/integration/aws-dynamodb-table.json

# public/
cfn-lint test/fixtures/templates/public/lambda-poller.yaml -e -c I --format json > test/fixtures/results/public/lambda-poller.json
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,13 @@
}
}
]
},
{
"op": "add",
"path": "/definitions/SSESpecification/properties/SSEType/enum",
"value": [
"AES256",
"KMS"
]
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,21 @@
}
}
]
},
{
"op": "add",
"path": "/definitions/SSESpecification/properties/SSEType/enum",
"value": [
"KMS"
]
},
{
"op": "add",
"path": "/definitions/SSESpecification/dependentRequired",
"value": {
"KMSMasterKeyId": [
"SSEType"
]
}
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,10 @@
"type": "boolean"
},
"SSEType": {
"enum": [
"AES256",
"KMS"
],
"type": "string"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,11 @@
},
"SSESpecification": {
"additionalProperties": false,
"dependentRequired": {
"KMSMasterKeyId": [
"SSEType"
]
},
"properties": {
"KMSMasterKeyId": {
"anyOf": [
Expand Down Expand Up @@ -388,6 +393,9 @@
"type": "boolean"
},
"SSEType": {
"enum": [
"KMS"
],
"type": "string"
}
},
Expand Down
31 changes: 0 additions & 31 deletions src/cfnlint/rules/resources/dynamodb/TableSseSpecification.py

This file was deleted.

61 changes: 61 additions & 0 deletions test/fixtures/results/integration/aws-dynamodb-table.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
[
{
"Filename": "test/fixtures/templates/integration/aws-dynamodb-table.yaml",
"Id": "9853e961-d150-10b3-4728-32a621c7fbf6",
"Level": "Error",
"Location": {
"End": {
"ColumnNumber": 23,
"LineNumber": 22
},
"Path": [
"Resources",
"Table1",
"Properties",
"SSESpecification"
],
"Start": {
"ColumnNumber": 7,
"LineNumber": 22
}
},
"Message": "'SSEType' is a dependency of 'KMSMasterKeyId'",
"ParentId": null,
"Rule": {
"Description": "When certain properties are specified it results in other properties to be required",
"Id": "E3021",
"ShortDescription": "Validate that when a property is specified that other properties should be included",
"Source": "https://github.com/aws-cloudformation/cfn-lint/blob/main/docs/cfn-schema-specification.md#dependentrequired"
}
},
{
"Filename": "test/fixtures/templates/integration/aws-dynamodb-table.yaml",
"Id": "ecae4565-1f41-0f11-949a-c27038ed5a02",
"Level": "Error",
"Location": {
"End": {
"ColumnNumber": 16,
"LineNumber": 44
},
"Path": [
"Resources",
"Table2",
"Properties",
"SSESpecification",
"SSEType"
],
"Start": {
"ColumnNumber": 9,
"LineNumber": 44
}
},
"Message": "'AES256' is not one of ['KMS']",
"ParentId": null,
"Rule": {
"Description": "Check if properties have a valid value in case of an enumator",
"Id": "E3030",
"ShortDescription": "Check if properties have a valid value",
"Source": "https://github.com/aws-cloudformation/cfn-lint/blob/main/docs/cfn-schema-specification.md#enum"
}
}
]
44 changes: 44 additions & 0 deletions test/fixtures/templates/integration/aws-dynamodb-table.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

Resources:
KMS:
Type: AWS::KMS::Key
UpdateReplacePolicy: Retain
DeletionPolicy: Retain
Table1:
UpdateReplacePolicy: Retain
DeletionPolicy: Retain
Type: AWS::DynamoDB::Table
Properties:
TableName: table1
AttributeDefinitions:
- AttributeName: id
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
SSESpecification:
KMSMasterKeyId: !GetAtt KMS.Arn
SSEEnabled: true
# SSEType: KMS # to provide an error
Table2:
UpdateReplacePolicy: Retain
DeletionPolicy: Retain
Type: AWS::DynamoDB::Table
Properties:
TableName: table2
AttributeDefinitions:
- AttributeName: id
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
SSESpecification:
KMSMasterKeyId: !GetAtt KMS.Arn
SSEEnabled: true
SSEType: AES256
7 changes: 7 additions & 0 deletions test/integration/test_integration_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ class TestQuickStartTemplates(BaseCliTestCase):
),
"exit_code": 2,
},
{
"filename": ("test/fixtures/templates/integration/aws-dynamodb-table.yaml"),
"results_filename": (
"test/fixtures/results/integration/aws-dynamodb-table.json"
),
"exit_code": 2,
},
]

def test_templates(self):
Expand Down

0 comments on commit bf07614

Please sign in to comment.