Skip to content
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

(BucketDeployment): Generates IAM policy not approved by CDK Nag #27210

Open
markusl opened this issue Sep 20, 2023 · 4 comments
Open

(BucketDeployment): Generates IAM policy not approved by CDK Nag #27210

markusl opened this issue Sep 20, 2023 · 4 comments
Labels
@aws-cdk/aws-iam Related to AWS Identity and Access Management effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2

Comments

@markusl
Copy link
Contributor

markusl commented Sep 20, 2023

Describe the bug

Using the BucketDeployment construct generates an IAM policy which is not approved by CDK Nag tool.

Expected Behavior

Compliant policy should be generated by default or alternatively explain the reasoning in the documentation and document steps to suppress the warning.

Current Behavior

[Error at /stack/Custom::CDKBucketDeployment8693BB64968944B69AAFB0CC9EB8756C/ServiceRole/Resource] AwsSolutions-IAM4[Policy::arn:<AWS::Partition>:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole]: The IAM user, role, or group uses AWS managed policies. An AWS managed policy is a standalone policy that is created and administered by AWS. Currently, many AWS managed policies do not restrict resource scope. Replace AWS managed policies with system specific (customer) managed policies.This is a granular rule that returns individual findings that can be suppressed with 'appliesTo'. The findings are in the format 'Policy::<policy>' for AWS managed policies. Example: appliesTo: ['Policy::arn:<AWS::Partition>:iam::aws:policy/foo'].

Reproduction Steps

    new s3deploy.BucketDeployment(this, 'IncomingData', {
      destinationBucket: bucket,
      sources: [s3deploy.Source.asset('./example-data')],
      retainOnDelete: false,
    });

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.96.2

Framework Version

No response

Node.js Version

18

OS

all

Language

Typescript

Language Version

No response

Other information

No response

@markusl markusl added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 20, 2023
@github-actions github-actions bot added the @aws-cdk/aws-iam Related to AWS Identity and Access Management label Sep 20, 2023
@peterwoodworth
Copy link
Contributor

You can read about suppressing rules with nag in the cdk-nag repo. We don't claim to be compliant with nag so I don't believe any explanation is necessary. If you have a way to scope down the policy to still make it work for all use cases its designed for then we could look at that as a feature request

@peterwoodworth peterwoodworth added feature-request A feature should be added or improved. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 20, 2023
@markusl
Copy link
Contributor Author

markusl commented Sep 21, 2023

@peterwoodworth Yes, we don't claim to be compliant, but i's not great developer experience. I think it would be a good goal if the built-in functionality would be compliant with best practices enforced with cdk-nag. In this case I do believe BucketDeployment functionality can be implemented with specific IAM policies instead of using AWSLambdaBasicExecutionRole.

@peterwoodworth peterwoodworth added p2 effort/small Small work item – less than a day of effort labels Sep 21, 2023
@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Sep 21, 2023
@KhushbooKaul2002
Copy link

KhushbooKaul2002 commented Jun 12, 2024

Hi @markusl @peterwoodworth : I faced the same issue while trying to now using Python 3_12 as my Lambda Runtime.
CDK Nag would NOT allow me to complete the synth, as the Lambda Runtime still is 3.9 in the CFN template.
My package json looks like this -

{
"name": "cdk",
"version": "0.1.0",
"bin": {
"cdk": "bin/cdk.js"
},
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"test": "jest",
"cdk": "cdk"
},
"devDependencies": {
"@types/jest": "^29.5.1",
"@types/node": "20.1.7",
"aws-cdk": "^2.145.0",
"jest": "^29.5.0",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"typescript": "~5.1.3"
},
"dependencies": {
"aws-cdk-lib": "^2.145.0",
"cdk-nag": "^2.28.141",
"constructs": "^10.0.0",
"source-map-support": "^0.5.21",
"update": "^0.7.4"
}
}

@meniluca
Copy link

meniluca commented Jun 18, 2024

I don't manage to find a way but to NagSuppressions the entire stack. I have tried with suppressing by path, which works only for IAM-5 when declaring a role, but not with L1. I have also tried suppressing the stack using regex with appliesTo, but the regex does not work even when putting a plain string. Any other idea?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-iam Related to AWS Identity and Access Management effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

No branches or pull requests

4 participants