-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: CloudFrontDistributionHttpsViewerNoOutdatedSSL rule (#717)
* feat: CloudFrontDistributionHttpsViewerNoOutdatedSSL rule (#716) * chore: update imports for v2 * chore: update improper import * chore: self mutation Signed-off-by: github-actions <[email protected]> Co-authored-by: github-actions <[email protected]>
- Loading branch information
Showing
6 changed files
with
217 additions
and
67 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
54 changes: 54 additions & 0 deletions
54
src/rules/cloudfront/CloudFrontDistributionHttpsViewerNoOutdatedSSL.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,54 @@ | ||
/* | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import { parse } from 'path'; | ||
import { CfnResource, Stack } from 'aws-cdk-lib'; | ||
import { CfnDistribution } from 'aws-cdk-lib/aws-cloudfront'; | ||
import { NagRuleCompliance } from '../../nag-rules'; | ||
|
||
/** | ||
* CloudFront distributions use a security policy with minimum TLSv1.1 or TLSv1.2 and appropriate security ciphers for HTTPS viewer connections | ||
* @param node the CfnResource to check | ||
*/ | ||
export default Object.defineProperty( | ||
(node: CfnResource): NagRuleCompliance => { | ||
if (node instanceof CfnDistribution) { | ||
const distributionConfig = Stack.of(node).resolve( | ||
node.distributionConfig | ||
); | ||
const viewerCertificate = Stack.of(node).resolve( | ||
distributionConfig.viewerCertificate | ||
); | ||
if (viewerCertificate === undefined) { | ||
return NagRuleCompliance.NON_COMPLIANT; | ||
} | ||
const minimumProtocolVersion = Stack.of(node).resolve( | ||
viewerCertificate.minimumProtocolVersion | ||
); | ||
const sslSupportMethod = Stack.of(node).resolve( | ||
viewerCertificate.sslSupportMethod | ||
); | ||
const cloudFrontDefaultCertificate = Stack.of(node).resolve( | ||
viewerCertificate.cloudFrontDefaultCertificate | ||
); | ||
const outdatedProtocols = ['SSLv3', 'TLSv1', 'TLSv1_2016']; | ||
if ( | ||
cloudFrontDefaultCertificate === true || | ||
sslSupportMethod === undefined || | ||
sslSupportMethod.toLowerCase() === 'vip' || | ||
minimumProtocolVersion === undefined || | ||
outdatedProtocols | ||
.map((x) => x.toLowerCase()) | ||
.includes(minimumProtocolVersion.toLowerCase()) | ||
) { | ||
return NagRuleCompliance.NON_COMPLIANT; | ||
} | ||
return NagRuleCompliance.COMPLIANT; | ||
} else { | ||
return NagRuleCompliance.NOT_APPLICABLE; | ||
} | ||
}, | ||
'name', | ||
{ value: parse(__filename).name } | ||
); |
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
Oops, something went wrong.