Skip to content

Commit bf07614

Browse files
authored
Move KMS validation for SSESpecification on Tables (#3700)
* Remove rule E3640 and move to standard schemas
1 parent 25b5930 commit bf07614

File tree

11 files changed

+161
-51
lines changed

11 files changed

+161
-51
lines changed

scripts/update_schemas_manually.py

+12
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,14 @@
641641
},
642642
path="/",
643643
),
644+
Patch(
645+
values={"enum": ["KMS"]},
646+
path="/definitions/SSESpecification/properties/SSEType",
647+
),
648+
Patch(
649+
values={"dependentRequired": {"KMSMasterKeyId": ["SSEType"]}},
650+
path="/definitions/SSESpecification",
651+
),
644652
],
645653
),
646654
ResourcePatch(
@@ -670,6 +678,10 @@
670678
},
671679
path="/",
672680
),
681+
Patch(
682+
values={"enum": ["AES256", "KMS"]},
683+
path="/definitions/SSESpecification/properties/SSEType",
684+
),
673685
],
674686
),
675687
ResourcePatch(

scripts/update_snapshot_results.sh

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ cfn-lint test/fixtures/templates/integration/availability-zones.yaml -e -c I --f
88
cfn-lint test/fixtures/templates/integration/aws-ec2-networkinterface.yaml -e -c I --format json > test/fixtures/results/integration/aws-ec2-networkinterface.json
99
cfn-lint test/fixtures/templates/integration/aws-ec2-instance.yaml -e -c I --format json > test/fixtures/results/integration/aws-ec2-instance.json
1010
cfn-lint test/fixtures/templates/integration/aws-ec2-launchtemplate.yaml -e -c I --format json > test/fixtures/results/integration/aws-ec2-launchtemplate.json
11+
cfn-lint test/fixtures/templates/integration/aws-dynamodb-table.yaml -e -c I --format json > test/fixtures/results/integration/aws-dynamodb-table.json
1112

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

src/cfnlint/data/schemas/extensions/aws_dynamodb_table/ssespecification_kms.json

-20
This file was deleted.

src/cfnlint/data/schemas/patches/extensions/all/aws_dynamodb_globaltable/manual.json

+8
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,13 @@
2323
}
2424
}
2525
]
26+
},
27+
{
28+
"op": "add",
29+
"path": "/definitions/SSESpecification/properties/SSEType/enum",
30+
"value": [
31+
"AES256",
32+
"KMS"
33+
]
2634
}
2735
]

src/cfnlint/data/schemas/patches/extensions/all/aws_dynamodb_table/manual.json

+16
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,21 @@
2929
}
3030
}
3131
]
32+
},
33+
{
34+
"op": "add",
35+
"path": "/definitions/SSESpecification/properties/SSEType/enum",
36+
"value": [
37+
"KMS"
38+
]
39+
},
40+
{
41+
"op": "add",
42+
"path": "/definitions/SSESpecification/dependentRequired",
43+
"value": {
44+
"KMSMasterKeyId": [
45+
"SSEType"
46+
]
47+
}
3248
}
3349
]

src/cfnlint/data/schemas/providers/us_east_1/aws-dynamodb-globaltable.json

+4
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,10 @@
421421
"type": "boolean"
422422
},
423423
"SSEType": {
424+
"enum": [
425+
"AES256",
426+
"KMS"
427+
],
424428
"type": "string"
425429
}
426430
},

src/cfnlint/data/schemas/providers/us_east_1/aws-dynamodb-table.json

+8
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,11 @@
360360
},
361361
"SSESpecification": {
362362
"additionalProperties": false,
363+
"dependentRequired": {
364+
"KMSMasterKeyId": [
365+
"SSEType"
366+
]
367+
},
363368
"properties": {
364369
"KMSMasterKeyId": {
365370
"anyOf": [
@@ -388,6 +393,9 @@
388393
"type": "boolean"
389394
},
390395
"SSEType": {
396+
"enum": [
397+
"KMS"
398+
],
391399
"type": "string"
392400
}
393401
},

src/cfnlint/rules/resources/dynamodb/TableSseSpecification.py

-31
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
[
2+
{
3+
"Filename": "test/fixtures/templates/integration/aws-dynamodb-table.yaml",
4+
"Id": "9853e961-d150-10b3-4728-32a621c7fbf6",
5+
"Level": "Error",
6+
"Location": {
7+
"End": {
8+
"ColumnNumber": 23,
9+
"LineNumber": 22
10+
},
11+
"Path": [
12+
"Resources",
13+
"Table1",
14+
"Properties",
15+
"SSESpecification"
16+
],
17+
"Start": {
18+
"ColumnNumber": 7,
19+
"LineNumber": 22
20+
}
21+
},
22+
"Message": "'SSEType' is a dependency of 'KMSMasterKeyId'",
23+
"ParentId": null,
24+
"Rule": {
25+
"Description": "When certain properties are specified it results in other properties to be required",
26+
"Id": "E3021",
27+
"ShortDescription": "Validate that when a property is specified that other properties should be included",
28+
"Source": "https://github.com/aws-cloudformation/cfn-lint/blob/main/docs/cfn-schema-specification.md#dependentrequired"
29+
}
30+
},
31+
{
32+
"Filename": "test/fixtures/templates/integration/aws-dynamodb-table.yaml",
33+
"Id": "ecae4565-1f41-0f11-949a-c27038ed5a02",
34+
"Level": "Error",
35+
"Location": {
36+
"End": {
37+
"ColumnNumber": 16,
38+
"LineNumber": 44
39+
},
40+
"Path": [
41+
"Resources",
42+
"Table2",
43+
"Properties",
44+
"SSESpecification",
45+
"SSEType"
46+
],
47+
"Start": {
48+
"ColumnNumber": 9,
49+
"LineNumber": 44
50+
}
51+
},
52+
"Message": "'AES256' is not one of ['KMS']",
53+
"ParentId": null,
54+
"Rule": {
55+
"Description": "Check if properties have a valid value in case of an enumator",
56+
"Id": "E3030",
57+
"ShortDescription": "Check if properties have a valid value",
58+
"Source": "https://github.com/aws-cloudformation/cfn-lint/blob/main/docs/cfn-schema-specification.md#enum"
59+
}
60+
}
61+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
Resources:
3+
KMS:
4+
Type: AWS::KMS::Key
5+
UpdateReplacePolicy: Retain
6+
DeletionPolicy: Retain
7+
Table1:
8+
UpdateReplacePolicy: Retain
9+
DeletionPolicy: Retain
10+
Type: AWS::DynamoDB::Table
11+
Properties:
12+
TableName: table1
13+
AttributeDefinitions:
14+
- AttributeName: id
15+
AttributeType: S
16+
KeySchema:
17+
- AttributeName: id
18+
KeyType: HASH
19+
ProvisionedThroughput:
20+
ReadCapacityUnits: 1
21+
WriteCapacityUnits: 1
22+
SSESpecification:
23+
KMSMasterKeyId: !GetAtt KMS.Arn
24+
SSEEnabled: true
25+
# SSEType: KMS # to provide an error
26+
Table2:
27+
UpdateReplacePolicy: Retain
28+
DeletionPolicy: Retain
29+
Type: AWS::DynamoDB::Table
30+
Properties:
31+
TableName: table2
32+
AttributeDefinitions:
33+
- AttributeName: id
34+
AttributeType: S
35+
KeySchema:
36+
- AttributeName: id
37+
KeyType: HASH
38+
ProvisionedThroughput:
39+
ReadCapacityUnits: 1
40+
WriteCapacityUnits: 1
41+
SSESpecification:
42+
KMSMasterKeyId: !GetAtt KMS.Arn
43+
SSEEnabled: true
44+
SSEType: AES256

test/integration/test_integration_templates.py

+7
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ class TestQuickStartTemplates(BaseCliTestCase):
7272
),
7373
"exit_code": 2,
7474
},
75+
{
76+
"filename": ("test/fixtures/templates/integration/aws-dynamodb-table.yaml"),
77+
"results_filename": (
78+
"test/fixtures/results/integration/aws-dynamodb-table.json"
79+
),
80+
"exit_code": 2,
81+
},
7582
]
7683

7784
def test_templates(self):

0 commit comments

Comments
 (0)