-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(HIPAA Security): DynamoDB check (#342)
Closes #179 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
5 changed files
with
90 additions
and
9 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
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
25 changes: 25 additions & 0 deletions
25
src/HIPAA-Security/rules/dynamodb/hipaaSecurityDynamoDBPITREnabled.ts
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,25 @@ | ||
/* | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import { CfnTable } from '@aws-cdk/aws-dynamodb'; | ||
import { CfnResource, Stack } from '@aws-cdk/core'; | ||
|
||
/** | ||
* DynamoDB tables have Point-in-time Recovery enabled - (Control IDs: 164.308(a)(7)(i), 164.308(a)(7)(ii)(A), 164.308(a)(7)(ii)(B)) | ||
* @param node the CfnResource to check | ||
*/ | ||
|
||
export default function (node: CfnResource): boolean { | ||
if (node instanceof CfnTable) { | ||
if (node.pointInTimeRecoverySpecification == undefined) { | ||
return false; | ||
} | ||
const pitr = Stack.of(node).resolve(node.pointInTimeRecoverySpecification); | ||
const enabled = Stack.of(node).resolve(pitr.pointInTimeRecoveryEnabled); | ||
if (!enabled) { | ||
return false; | ||
} | ||
} | ||
return 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
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,41 @@ | ||
/* | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import { SynthUtils } from '@aws-cdk/assert'; | ||
import { AttributeType, Table } from '@aws-cdk/aws-dynamodb'; | ||
import { Aspects, Stack } from '@aws-cdk/core'; | ||
import { HIPAASecurityChecks } from '../../src'; | ||
|
||
describe('Amazon DynamoDB', () => { | ||
test('HIPAA.Security-DynamoDBPITREnabled: - DynamoDB tables have point in time recovery enabled - (Control IDs: 164.308(a)(7)(i), 164.308(a)(7)(ii)(A), 164.308(a)(7)(ii)(B)', () => { | ||
const nonCompliant = new Stack(); | ||
Aspects.of(nonCompliant).add(new HIPAASecurityChecks()); | ||
new Table(nonCompliant, 'rTable', { | ||
partitionKey: { name: 'foo', type: AttributeType.STRING }, | ||
}); | ||
const messages = SynthUtils.synthesize(nonCompliant).messages; | ||
expect(messages).toContainEqual( | ||
expect.objectContaining({ | ||
entry: expect.objectContaining({ | ||
data: expect.stringContaining('HIPAA.Security-DynamoDBPITREnabled:'), | ||
}), | ||
}) | ||
); | ||
|
||
const compliant = new Stack(); | ||
Aspects.of(compliant).add(new HIPAASecurityChecks()); | ||
new Table(compliant, 'rTable', { | ||
partitionKey: { name: 'foo', type: AttributeType.STRING }, | ||
pointInTimeRecovery: true, | ||
}); | ||
const messages2 = SynthUtils.synthesize(compliant).messages; | ||
expect(messages2).not.toContainEqual( | ||
expect.objectContaining({ | ||
entry: expect.objectContaining({ | ||
data: expect.stringContaining('HIPAA.Security-DynamoDBPITREnabled:'), | ||
}), | ||
}) | ||
); | ||
}); | ||
}); |