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

grant-ing dynamodb table constructs does not allow access to indices #1540

Closed
mipearson opened this issue Jan 14, 2019 · 2 comments · Fixed by #1564
Closed

grant-ing dynamodb table constructs does not allow access to indices #1540

mipearson opened this issue Jan 14, 2019 · 2 comments · Fixed by #1564
Labels
@aws-cdk/aws-dynamodb Related to Amazon DynamoDB bug This issue is a bug.

Comments

@mipearson
Copy link

Saw in my lambda output:

User: arn:aws:sts::REDACTED:assumed-role/REDACTED is not authorized to perform: dynamodb:Query on resource: arn:aws:dynamodb:us-east-1:REDACTED:table/REDACTED/index/uuid

cdk was set up as so:

    const table = new dynamodb.Table(this, "Alerts", {...});
    table.addLocalSecondaryIndex({indexName: "uuid", ...});
    
    const fn = new lambda.Function(...);
    table.grantReadWriteData(fn.role);

Googling found me https://stackoverflow.com/questions/51537795/accessdenied-on-dynamodb-gsi-index

Applied a kind of hacky workaround to replace the .grantReadWrite:

   fn.addToRolePolicy(
      new PolicyStatement()
        .addAction("dynamodb:*")
        .addResources(
          `${table.tableArn}/index/*`,
          table.tableArn,
        )
    );

This resolved the error.

Looking at the source, it looks like the dynamodb construct needs to call addResource once again for the index if one is defined.

@rix0rrr rix0rrr added bug This issue is a bug. @aws-cdk/aws-dynamodb Related to Amazon DynamoDB labels Jan 14, 2019
rix0rrr added a commit that referenced this issue Jan 17, 2019
If a table has an index, the `grant()` methods will give permissions to
the index as well.

Updates the security diff engine to support `AWS::NoValue`.

Fixes #1540.
rix0rrr added a commit that referenced this issue Jan 17, 2019
If a table has an index, the `grant()` methods will give permissions to
the index as well.

Updates the security diff engine to support `AWS::NoValue`.

Fixes #1540.
sam-goodwin pushed a commit that referenced this issue Jan 28, 2019
If a table has an index, the `grant()` methods will give permissions to
the index as well.

Updates the security diff engine to support `AWS::NoValue`.

Fixes #1540.
@aveeday
Copy link

aveeday commented Nov 12, 2020

When I use Table.fromTableArn then there are no access to table indices with grantReadData

@skinny85
Copy link
Contributor

skinny85 commented Nov 12, 2020

@aveeday see #11445

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-dynamodb Related to Amazon DynamoDB bug This issue is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants