-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Check standard logs in AwsSolutions-CFR3 #1877
base: main
Are you sure you want to change the base?
Changes from all commits
0e4648c
259dcbf
42ef106
25dd43b
a73f1bb
bb16f40
30e092f
123ddb7
b361922
d5090b9
d9709c9
df6639e
5f91662
10472f8
333c5c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ const { awscdk, vscode } = require('projen'); | |
const project = new awscdk.AwsCdkConstructLibrary({ | ||
author: 'Arun Donti', | ||
authorAddress: '[email protected]', | ||
cdkVersion: '2.156.0', | ||
cdkVersion: '2.167.0', | ||
defaultReleaseBranch: 'main', | ||
majorVersion: 2, | ||
npmDistTag: 'latest', | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,9 @@ import { | |
CfnDistribution, | ||
CfnStreamingDistribution, | ||
} from 'aws-cdk-lib/aws-cloudfront'; | ||
import { CfnDelivery, CfnDeliverySource } from 'aws-cdk-lib/aws-logs'; | ||
import { NagRuleCompliance, NagRules } from '../../nag-rules'; | ||
import { flattenCfnReference } from '../../utils/flatten-cfn-reference'; | ||
|
||
/** | ||
* CloudFront distributions have access logging enabled | ||
|
@@ -21,6 +23,44 @@ export default Object.defineProperty( | |
node.distributionConfig | ||
); | ||
if (distributionConfig.logging == undefined) { | ||
const distributionArn = flattenCfnReference( | ||
Stack.of(node).resolve( | ||
Stack.of(node).formatArn({ | ||
service: 'cloudfront', | ||
region: '', | ||
resource: 'distribution', | ||
resourceName: node.attrId, | ||
}) | ||
) | ||
).replace('.Id', ''); | ||
|
||
let deliverySourceName; | ||
for (const child of Stack.of(node).node.findAll()) { | ||
if (child instanceof CfnDeliverySource) { | ||
const deliverySourceArn = flattenCfnReference( | ||
Stack.of(child).resolve(child.resourceArn) | ||
); | ||
const logType = Stack.of(child).resolve(child.logType); | ||
if ( | ||
deliverySourceArn === distributionArn && | ||
logType === 'ACCESS_LOGS' | ||
) { | ||
deliverySourceName = Stack.of(child).resolve(child.name); | ||
} | ||
} | ||
} | ||
|
||
for (const child of Stack.of(node).node.findAll()) { | ||
if (child instanceof CfnDelivery) { | ||
if ( | ||
deliverySourceName === | ||
Stack.of(child).resolve(child.deliverySourceName) | ||
) { | ||
return NagRuleCompliance.COMPLIANT; | ||
} | ||
} | ||
} | ||
Comment on lines
+53
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be a nested for loop. We don't need this to execute if a matching delivery source has not been found |
||
|
||
return NagRuleCompliance.NON_COMPLIANT; | ||
} | ||
return NagRuleCompliance.COMPLIANT; | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't take into account if the stack has multiple delivery sources defined that reference the distribution. If multiple are found then it will always pick the last one