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

bug: CDK NAG Suppression fails for DynamoDB with replication regions for Global Tables #1464

Closed
mssanjay opened this issue Oct 4, 2023 · 2 comments
Labels
guidance Question that needs advice or information.

Comments

@mssanjay
Copy link

mssanjay commented Oct 4, 2023

What is the problem?

Hi,
I have a global table with replication regions specified. When NAGs are applied, the CDK NAG validation fails with below error

@aws-cdk--aws-dynamodb.ReplicaProvider/Provider/waiter-state-machine/Role/DefaultPolicy/Resource] AwsSolutions-IAM5[Resource::<ProviderframeworkonTimeout0B47CA38.Arn>:*]: The IAM entity contains wildcard permissions and does not have a cdk-nag rule suppression with evidence for those permission.

My Global DDB table code is as follows .. if I comment out replicationRegions I dont get any error. What is the problem here?

        const replicationRegions = ['us-east-2'];
        const auditTable = new ddb.Table(this, 'codes-audit-table', {
            partitionKey: { name: 'PK', type: ddb.AttributeType.STRING },
            sortKey: { name: 'SK', type: ddb.AttributeType.STRING },
            billingMode: ddb.BillingMode.PAY_PER_REQUEST,
            tableName: `${id}-codes-audit-table`,
            encryption: ddb.TableEncryption.AWS_MANAGED,
            timeToLiveAttribute: 'expiresAt',
            replicationRegions,
        });

Reproduction Steps

        const replicationRegions = ['us-east-2'];
        const auditTable = new ddb.Table(this, 'codes-audit-table', {
            partitionKey: { name: 'PK', type: ddb.AttributeType.STRING },
            sortKey: { name: 'SK', type: ddb.AttributeType.STRING },
            billingMode: ddb.BillingMode.PAY_PER_REQUEST,
            tableName: `${id}-codes-audit-table`,
            encryption: ddb.TableEncryption.AWS_MANAGED,
            timeToLiveAttribute: 'expiresAt',
            replicationRegions,
        });

What did you expect to happen?

No CDK Nag errors should be reported when below suppressions are added

NagSuppressions.addStackSuppressions(
  dataStack,
  [ 
    { id: 'AwsSolutions-IAM4', reason: 'Allow the use of AWS managed policies.'},
    { id: 'AwsSolutions-IAM5', reason: 'Suppress roles/policies with wildcard permissions since some wildcard permissions are needed.' },
    { id: 'AwsSolutions-S1', reason: 'S3 Server access logs not to be enabled at this time.' },
    { id: 'AwsSolutions-DDB3', reason: 'DDB point-in-time recovery not to be enabled at this time.' }
  ]
);

What actually happened?

I see errors

/@aws-cdk--aws-dynamodb.ReplicaProvider/Provider/waiter-state-machine/Role/DefaultPolicy/Resource] AwsSolutions-IAM5[Resource::<ProviderframeworkonTimeout0B47CA38.Arn>:*]: The IAM entity contains wildcard permissions and does not have a cdk-nag rule suppression with evidence for those permission.

cdk-nag version

2.27.150

Language

Typescript

Other information

No response

@mssanjay mssanjay added bug Something isn't working needs-triage This issue or PR still needs to be triaged. labels Oct 4, 2023
@dontirun
Copy link
Collaborator

dontirun commented Oct 4, 2023

Based on the error message it looks like the CDK is creating a different stack behind the scenes to add some replication resources.

See this comment for suppressing on CDK generated stacks

@dontirun dontirun added guidance Question that needs advice or information. and removed bug Something isn't working needs-triage This issue or PR still needs to be triaged. labels Oct 4, 2023
@mssanjay
Copy link
Author

mssanjay commented Oct 6, 2023

Thanks for the explanation!

@mssanjay mssanjay closed this as completed Oct 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
guidance Question that needs advice or information.
Projects
None yet
Development

No branches or pull requests

2 participants