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

fix(dynamodb): Support iampolicy minimize credential #21673

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions packages/@aws-cdk/aws-dynamodb/lib/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1583,14 +1583,11 @@ export class Table extends TableBase {

const provider = ReplicaProvider.getOrCreate(this, { timeout });

// Documentation at https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/V2gt_IAM.html
// is currently incorrect. AWS Support recommends `dynamodb:*` in both source and destination regions

const onEventHandlerPolicy = new SourceTableAttachedPolicy(this, provider.onEventHandler.role!);
const isCompleteHandlerPolicy = new SourceTableAttachedPolicy(this, provider.isCompleteHandler.role!);

// Permissions in the source region
this.grant(onEventHandlerPolicy, 'dynamodb:*');
this.grant(onEventHandlerPolicy, 'dynamodb:DescribeTable', 'dynamodb:UpdateTable');
this.grant(isCompleteHandlerPolicy, 'dynamodb:DescribeTable');

let previousRegion: CustomResource | undefined;
Expand Down Expand Up @@ -1662,7 +1659,7 @@ export class Table extends TableBase {
// Permissions in the destination regions (outside of the loop to
// minimize statements in the policy)
onEventHandlerPolicy.grantPrincipal.addToPrincipalPolicy(new iam.PolicyStatement({
actions: ['dynamodb:*'],
actions: ['dynamodb:DescribeTable', 'dynamodb:UpdateTable'],
resources: this.regionalArns,
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
"PolicyDocument": {
"Statement": [
{
"Action": "dynamodb:*",
"Action": [
"dynamodb:DescribeTable",
"dynamodb:UpdateTable"
],
"Effect": "Allow",
"Resource": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@
"policyDocument": {
"Statement": [
{
"Action": "dynamodb:*",
"Action": [
"dynamodb:DescribeTable",
"dynamodb:UpdateTable"
],
"Effect": "Allow",
"Resource": [
{
Expand Down Expand Up @@ -188,7 +191,10 @@
"policyDocument": {
"Statement": [
{
"Action": "dynamodb:DescribeTable",
"Action": [
"dynamodb:DescribeTable",
"dynamodb:UpdateTable"
],
"Effect": "Allow",
"Resource": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@
"PolicyDocument": {
"Statement": [
{
"Action": "dynamodb:*",
"Action": [
"dynamodb:DescribeTable",
"dynamodb:UpdateTable"
],
"Effect": "Allow",
"Resource": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@
"policyDocument": {
"Statement": [
{
"Action": "dynamodb:*",
"Action": [
"dynamodb:DescribeTable",
"dynamodb:UpdateTable"
],
"Effect": "Allow",
"Resource": [
{
Expand Down Expand Up @@ -250,7 +253,7 @@
{
"Fn::GetAtt": [
"awscdkawsdynamodbReplicaProviderNestedStackawscdkawsdynamodbReplicaProviderNestedStackResource18E3F12D",
"Outputs.cdkdynamodbglobal20191121awscdkawsdynamodbReplicaProviderIsCompleteHandlerServiceRole2F936EC4Ref"
"Outputs.cdkdynamodbglobal20191121awscdkawsdynamodbReplicaProviderIsCompleteHandlerServiceRole3E8625F3Ref"
]
}
]
Expand Down Expand Up @@ -1525,9 +1528,9 @@
"version": "0.0.0"
}
},
"cdkdynamodbglobal20191121awscdkawsdynamodbReplicaProviderIsCompleteHandlerServiceRole2F936EC4Ref": {
"id": "cdkdynamodbglobal20191121awscdkawsdynamodbReplicaProviderIsCompleteHandlerServiceRole2F936EC4Ref",
"path": "cdk-dynamodb-global-20191121/@aws-cdk--aws-dynamodb.ReplicaProvider/cdkdynamodbglobal20191121awscdkawsdynamodbReplicaProviderIsCompleteHandlerServiceRole2F936EC4Ref",
"cdkdynamodbglobal20191121awscdkawsdynamodbReplicaProviderIsCompleteHandlerServiceRole3E8625F3Ref": {
"id": "cdkdynamodbglobal20191121awscdkawsdynamodbReplicaProviderIsCompleteHandlerServiceRole3E8625F3Ref",
"path": "cdk-dynamodb-global-20191121/@aws-cdk--aws-dynamodb.ReplicaProvider/cdkdynamodbglobal20191121awscdkawsdynamodbReplicaProviderIsCompleteHandlerServiceRole3E8625F3Ref",
"constructInfo": {
"fqn": "@aws-cdk/core.CfnOutput",
"version": "0.0.0"
Expand Down