Skip to content

Commit 4333d8c

Browse files
committed
Suppress AWS managed policy usage in BucketNotificationsHandler
1 parent aadd837 commit 4333d8c

File tree

1 file changed

+33
-21
lines changed

1 file changed

+33
-21
lines changed

packages/cdk/nagSuppressions.ts

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -214,28 +214,40 @@ export const nagSuppressions = (stack: Stack) => {
214214
]
215215
)
216216

217-
// Suppress Lambda function public access for API Gateway permissions
218-
safeAddNagSuppression(
219-
stack,
220-
"/EpsAssistMeStack/Apis/EpsAssistApiGateway/ApiGateway/Default/slack/ask-eps/POST/ApiPermission.EpsAssistMeStackApisEpsAssistApiGateway1E1CF19C.POST..slack.ask-eps",
221-
[
222-
{
223-
id: "LAMBDA_FUNCTION_PUBLIC_ACCESS_PROHIBITED",
224-
reason: "API Gateway service principal access is required for API Gateway to invoke Lambda function."
225-
}
226-
]
227-
)
228-
229-
safeAddNagSuppression(
230-
stack,
231-
"/EpsAssistMeStack/Apis/EpsAssistApiGateway/ApiGateway/Default/slack/ask-eps/POST/ApiPermission.Test.EpsAssistMeStackApisEpsAssistApiGateway1E1CF19C.POST..slack.ask-eps",
232-
[
233-
{
234-
id: "LAMBDA_FUNCTION_PUBLIC_ACCESS_PROHIBITED",
235-
reason: "API Gateway service principal access is required for API Gateway to invoke Lambda function."
236-
}
237-
]
217+
// Suppress AWS managed policy usage in BucketNotificationsHandler (wildcard for any hash)
218+
const bucketNotificationHandlers = stack.node.findAll().filter(node =>
219+
node.node.id.startsWith('BucketNotificationsHandler')
238220
)
221+
222+
bucketNotificationHandlers.forEach(handler => {
223+
safeAddNagSuppression(
224+
stack,
225+
`${handler.node.path}/Role/Resource`,
226+
[
227+
{
228+
id: "AwsSolutions-IAM4",
229+
reason: "Auto-generated CDK role uses AWS managed policy for basic Lambda execution.",
230+
appliesTo: [
231+
"Policy::arn:<AWS::Partition>:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
232+
]
233+
}
234+
]
235+
)
236+
237+
safeAddNagSuppression(
238+
stack,
239+
`${handler.node.path}/Role/DefaultPolicy/Resource`,
240+
[
241+
{
242+
id: "AwsSolutions-IAM5",
243+
reason: "Auto-generated CDK role requires wildcard permissions for S3 bucket notifications.",
244+
appliesTo: [
245+
"Resource::*"
246+
]
247+
}
248+
]
249+
)
250+
})
239251
}
240252

241253
const safeAddNagSuppression = (stack: Stack, path: string, suppressions: Array<NagPackSuppression>) => {

0 commit comments

Comments
 (0)