-
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): add Cloudtrail checks (#313)
* feat(HIPAAA-Security): Add Cloudtrail checks. closes #166, closes #168, closes #169 * fix syntax error in 'Commit and push changes (if changed) stage * ci: fix syntax error in 'Commit and push changes (if changed) stage' * ci: fix syntax error in 'Commit and push changes (if changed) stage' * Update rule IDs and alphabetize in RULES.md Co-authored-by: Taylor Ondrey <ondreyt@amazon.com> Co-authored-by: Arun Donti <dontirun@gmail.com>
- Loading branch information
1 parent
db08dda
commit 97883ae
Showing
9 changed files
with
290 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
21 changes: 21 additions & 0 deletions
21
src/HIPAA-Security/rules/cloudtrail/hipaaSecurityCloudTrailCloudWatchLogsEnabled.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,21 @@ | ||
/* | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import { CfnTrail } from '@aws-cdk/aws-cloudtrail'; | ||
import { IConstruct, Stack } from '@aws-cdk/core'; | ||
|
||
/** | ||
* CloudTrail trails have CloudWatch logs enabled - (Control IDs: 164.308(a)(3)(ii)(A), 164.312(b)) | ||
* @param node the CfnResource to check | ||
*/ | ||
export default function (node: IConstruct): boolean { | ||
if (node instanceof CfnTrail) { | ||
const cloudWatch = Stack.of(node).resolve(node.cloudWatchLogsLogGroupArn); | ||
|
||
if (cloudWatch == undefined) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} |
21 changes: 21 additions & 0 deletions
21
src/HIPAA-Security/rules/cloudtrail/hipaaSecurityCloudTrailEncryptionEnabled.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,21 @@ | ||
/* | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import { CfnTrail } from '@aws-cdk/aws-cloudtrail'; | ||
import { IConstruct, Stack } from '@aws-cdk/core'; | ||
|
||
/** | ||
* CloudTrail trails have encryption enabled - (Control ID: 164.312(a)(2)(iv), 164.312(e)(2)(ii)) | ||
* @param node the CfnResource to check | ||
*/ | ||
export default function (node: IConstruct): boolean { | ||
if (node instanceof CfnTrail) { | ||
const keyID = Stack.of(node).resolve(node.kmsKeyId); | ||
|
||
if (keyID == undefined) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} |
21 changes: 21 additions & 0 deletions
21
src/HIPAA-Security/rules/cloudtrail/hipaaSecurityCloudTrailLogFileValidationEnabled.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,21 @@ | ||
/* | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import { CfnTrail } from '@aws-cdk/aws-cloudtrail'; | ||
import { IConstruct, Stack } from '@aws-cdk/core'; | ||
|
||
/** | ||
* CloudTrail trails have log file validation enabled - (Control ID: 164.312(c)(1), 164.312(c)(2)) | ||
* @param node the CfnResource to check | ||
*/ | ||
export default function (node: IConstruct): boolean { | ||
if (node instanceof CfnTrail) { | ||
const enabled = Stack.of(node).resolve(node.enableLogFileValidation); | ||
|
||
if (enabled != true) { | ||
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,160 @@ | ||
/* | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import { SynthUtils } from '@aws-cdk/assert'; | ||
import { Trail } from '@aws-cdk/aws-cloudtrail'; | ||
import { Key } from '@aws-cdk/aws-kms'; | ||
import { LogGroup } from '@aws-cdk/aws-logs'; | ||
|
||
import { Aspects, Stack } from '@aws-cdk/core'; | ||
import { HIPAASecurityChecks } from '../../src'; | ||
|
||
describe('HIPAA Security CloudTrail Compliance Checks', () => { | ||
describe('AWS CloudTrail', () => { | ||
test('HIPAA.Security-CloudTrailCloudWatchLogsEnabled: CloudTrail trails have CloudWatch logs enabled', () => { | ||
const nonCompliant = new Stack(); | ||
Aspects.of(nonCompliant).add(new HIPAASecurityChecks()); | ||
|
||
const trail = new Trail(nonCompliant, 'rTrail'); | ||
trail.logAllLambdaDataEvents(); | ||
|
||
const messages1 = SynthUtils.synthesize(nonCompliant).messages; | ||
expect(messages1).toContainEqual( | ||
expect.objectContaining({ | ||
entry: expect.objectContaining({ | ||
data: expect.stringContaining( | ||
'HIPAA.Security-CloudTrailCloudWatchLogsEnabled:' | ||
), | ||
}), | ||
}) | ||
); | ||
|
||
const activeCompliant = new Stack(); | ||
Aspects.of(activeCompliant).add(new HIPAASecurityChecks()); | ||
|
||
const myLogs = new LogGroup(activeCompliant, 'rLogGroup'); | ||
|
||
const trail2 = new Trail(activeCompliant, 'rTrail', { | ||
cloudWatchLogGroup: myLogs, | ||
sendToCloudWatchLogs: true, | ||
}); | ||
|
||
trail2.logAllLambdaDataEvents(); | ||
|
||
const messages2 = SynthUtils.synthesize(activeCompliant).messages; | ||
expect(messages2).not.toContainEqual( | ||
expect.objectContaining({ | ||
entry: expect.objectContaining({ | ||
data: expect.stringContaining( | ||
'HIPAA.Security-CloudTrailCloudWatchLogsEnabled:' | ||
), | ||
}), | ||
}) | ||
); | ||
}); | ||
|
||
test('HIPAA.Security-CloudTrailEncryptionEnabled: CloudTrail trails have encryption enabled', () => { | ||
const nonCompliant = new Stack(); | ||
Aspects.of(nonCompliant).add(new HIPAASecurityChecks()); | ||
|
||
const myLogs = new LogGroup(nonCompliant, 'rLogGroup'); | ||
|
||
const trail = new Trail(nonCompliant, 'rTrail', { | ||
cloudWatchLogGroup: myLogs, | ||
sendToCloudWatchLogs: true, | ||
}); | ||
|
||
trail.stack; | ||
|
||
const messages1 = SynthUtils.synthesize(nonCompliant).messages; | ||
expect(messages1).toContainEqual( | ||
expect.objectContaining({ | ||
entry: expect.objectContaining({ | ||
data: expect.stringContaining( | ||
'HIPAA.Security-CloudTrailEncryptionEnabled:' | ||
), | ||
}), | ||
}) | ||
); | ||
|
||
const activeCompliant = new Stack(); | ||
Aspects.of(activeCompliant).add(new HIPAASecurityChecks()); | ||
|
||
const myLogs2 = new LogGroup(activeCompliant, 'rLogGroup'); | ||
|
||
const myKey = new Key(activeCompliant, 'rKey'); | ||
|
||
const trail2 = new Trail(activeCompliant, 'rTrail', { | ||
cloudWatchLogGroup: myLogs2, | ||
sendToCloudWatchLogs: true, | ||
kmsKey: myKey, | ||
}); | ||
|
||
trail2.logAllLambdaDataEvents(); | ||
|
||
const messages2 = SynthUtils.synthesize(activeCompliant).messages; | ||
expect(messages2).not.toContainEqual( | ||
expect.objectContaining({ | ||
entry: expect.objectContaining({ | ||
data: expect.stringContaining( | ||
'HIPAA.Security-CloudTrailEncryptionEnabled:' | ||
), | ||
}), | ||
}) | ||
); | ||
}); | ||
|
||
test('HIPAA.Security-CloudTrailLogFileValidationEnabled: Cloud Trails have log file validation enabled', () => { | ||
const nonCompliant = new Stack(); | ||
Aspects.of(nonCompliant).add(new HIPAASecurityChecks()); | ||
|
||
const myLogs = new LogGroup(nonCompliant, 'rLogGroup'); | ||
|
||
const trail = new Trail(nonCompliant, 'rTrail', { | ||
cloudWatchLogGroup: myLogs, | ||
sendToCloudWatchLogs: true, | ||
enableFileValidation: false, | ||
}); | ||
|
||
trail.stack; | ||
|
||
const messages1 = SynthUtils.synthesize(nonCompliant).messages; | ||
expect(messages1).toContainEqual( | ||
expect.objectContaining({ | ||
entry: expect.objectContaining({ | ||
data: expect.stringContaining( | ||
'HIPAA.Security-CloudTrailLogFileValidationEnabled:' | ||
), | ||
}), | ||
}) | ||
); | ||
|
||
const activeCompliant = new Stack(); | ||
Aspects.of(activeCompliant).add(new HIPAASecurityChecks()); | ||
|
||
const myLogs2 = new LogGroup(activeCompliant, 'rLogGroup'); | ||
|
||
const myKey = new Key(activeCompliant, 'rKey'); | ||
|
||
const trail2 = new Trail(activeCompliant, 'rTrail', { | ||
cloudWatchLogGroup: myLogs2, | ||
sendToCloudWatchLogs: true, | ||
kmsKey: myKey, | ||
}); | ||
|
||
trail2.logAllLambdaDataEvents(); | ||
|
||
const messages2 = SynthUtils.synthesize(activeCompliant).messages; | ||
expect(messages2).not.toContainEqual( | ||
expect.objectContaining({ | ||
entry: expect.objectContaining({ | ||
data: expect.stringContaining( | ||
'HIPAA.Security-CloudTrailLogFileValidationEnabled:' | ||
), | ||
}), | ||
}) | ||
); | ||
}); | ||
}); | ||
}); |