Skip to content

Commit

Permalink
fix(filemanager): cdk nag warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalenic committed Mar 22, 2024
1 parent 3791c44 commit 50e7d85
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 25 deletions.
10 changes: 4 additions & 6 deletions lib/workload/components/cdk_resource_invoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,10 @@ export class CdkResourceInvoke<P, F extends InvokeFunction> extends Construct {
const role = new Role(this, 'AwsCustomResourceRole', {
assumedBy: new ServicePrincipal('lambda.amazonaws.com'),
});
const lambdaResource = `arn:aws:lambda:${stack.region}:${stack.account}:function:${stackHash}-ResourceInvokeFunction-${props.id}`;
role.addToPolicy(
new PolicyStatement({
resources: [
// This needs to have permissions to run any `ResourceInvokeFunction` because it is deployed as a
// singleton Lambda function.
`arn:aws:lambda:${stack.region}:${stack.account}:function:${stackHash}-ResourceInvokeFunction-*`,
],
resources: [lambdaResource],
actions: ['lambda:InvokeFunction'],
})
);
Expand All @@ -128,11 +125,12 @@ export class CdkResourceInvoke<P, F extends InvokeFunction> extends Construct {

this._customResource = new AwsCustomResource(this, 'AwsCustomResource', {
policy: AwsCustomResourcePolicy.fromSdkCalls({
resources: AwsCustomResourcePolicy.ANY_RESOURCE,
resources: [lambdaResource],
}),
onUpdate: sdkCall,
role: role,
vpc: props.vpc,
installLatestAwsSdk: true,
vpcSubnets: { subnetType: SubnetType.PRIVATE_WITH_EGRESS },
});

Expand Down
3 changes: 2 additions & 1 deletion lib/workload/stateful/event_source/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ export class EventSource extends Construct {
constructor(scope: Construct, id: string, props: EventSourceProps) {
super(scope, id);

this.deadLetterQueue = new Queue(this, 'DeadLetterQueue');
this.deadLetterQueue = new Queue(this, 'DeadLetterQueue', { enforceSSL: true });
this.queue = new Queue(this, 'Queue', {
queueName: props.queueName,
enforceSSL: true,
deadLetterQueue: {
maxReceiveCount: props.maxReceiveCount,
queue: this.deadLetterQueue,
Expand Down
30 changes: 15 additions & 15 deletions lib/workload/stateless/filemanager/Cargo.lock

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
Expand Up @@ -34,8 +34,8 @@ export class IngestFunction extends fn.Function {
});
props.buckets.map((bucket) => {
this.addToPolicy(new PolicyStatement({
actions: ['s3:List*', 's3:Get*'],
resources: [`arn:aws:s3:::${bucket}/*`],
actions: ['s3:ListBucket', 's3:GetObject'],
resources: [`arn:aws:s3:::${bucket}`, `arn:aws:s3:::${bucket}/*`],
}));
})
}
Expand Down
2 changes: 1 addition & 1 deletion test/stateless/cdkResourceInvoke.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ test('Test CdkResourceInvoke', () => {
Resource: {
'Fn::Join': [
'',
Match.arrayWith([`:function:${expectedHash}-ResourceInvokeFunction-*`]),
Match.arrayWith([`:function:${expectedHash}-ResourceInvokeFunction-TestFunction`]),
],
},
},
Expand Down
25 changes: 25 additions & 0 deletions test/stateless/stateless-deployment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ function applyNagSuppression(stackId: string, stack: Stack) {
true
);

NagSuppressions.addStackSuppressions(
stack,
[
{
id: 'AwsSolutions-L1',
reason: "'AwsCustomResource' is out of date",
},
],
true
);

// for each stack specific

switch (stackId) {
Expand All @@ -117,6 +128,20 @@ function applyNagSuppression(stackId: string, stack: Stack) {
);
break;

case 'Filemanager':
NagSuppressions.addResourceSuppressions(
stack,
[
{
id: 'AwsSolutions-IAM5',
reason: "'*' is required to access objects in the indexed bucket by filemanager",
appliesTo: ['Resource::arn:aws:s3:::org.umccr.data.oncoanalyser/*'],
},
],
true
);
break;

default:
break;
}
Expand Down

0 comments on commit 50e7d85

Please sign in to comment.