Skip to content

Commit

Permalink
fix(dynamodb): grant*Data() methods are missing the `dynamodb:Descr…
Browse files Browse the repository at this point in the history
…ibeTable` permission (#19129)

Fixes #18773

This allows the high level dynamodb clients to function correctly

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
chris-smith-zocdoc authored Feb 25, 2022
1 parent 59ef06a commit 4a44a65
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,8 @@
"dynamodb:BatchWriteItem",
"dynamodb:PutItem",
"dynamodb:UpdateItem",
"dynamodb:DeleteItem"
"dynamodb:DeleteItem",
"dynamodb:DescribeTable"
],
"Effect": "Allow",
"Resource": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@
"dynamodb:BatchWriteItem",
"dynamodb:PutItem",
"dynamodb:UpdateItem",
"dynamodb:DeleteItem"
"dynamodb:DeleteItem",
"dynamodb:DescribeTable"
],
"Effect": "Allow",
"Resource": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
"dynamodb:BatchWriteItem",
"dynamodb:PutItem",
"dynamodb:UpdateItem",
"dynamodb:DeleteItem"
"dynamodb:DeleteItem",
"dynamodb:DescribeTable"
],
"Effect": "Allow",
"Resource": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@
"dynamodb:BatchWriteItem",
"dynamodb:PutItem",
"dynamodb:UpdateItem",
"dynamodb:DeleteItem"
"dynamodb:DeleteItem",
"dynamodb:DescribeTable"
],
"Effect": "Allow",
"Resource": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
"dynamodb:BatchWriteItem",
"dynamodb:PutItem",
"dynamodb:UpdateItem",
"dynamodb:DeleteItem"
"dynamodb:DeleteItem",
"dynamodb:DescribeTable"
],
"Effect": "Allow",
"Resource": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@
"dynamodb:BatchWriteItem",
"dynamodb:PutItem",
"dynamodb:UpdateItem",
"dynamodb:DeleteItem"
"dynamodb:DeleteItem",
"dynamodb:DescribeTable"
],
"Effect": "Allow",
"Resource": [
Expand Down Expand Up @@ -360,7 +361,8 @@
"dynamodb:BatchWriteItem",
"dynamodb:PutItem",
"dynamodb:UpdateItem",
"dynamodb:DeleteItem"
"dynamodb:DeleteItem",
"dynamodb:DescribeTable"
],
"Effect": "Allow",
"Resource": [
Expand Down Expand Up @@ -752,7 +754,8 @@
"dynamodb:BatchWriteItem",
"dynamodb:PutItem",
"dynamodb:UpdateItem",
"dynamodb:DeleteItem"
"dynamodb:DeleteItem",
"dynamodb:DescribeTable"
],
"Effect": "Allow",
"Resource": [
Expand Down
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-dynamodb/lib/perms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ export const READ_STREAM_DATA_ACTIONS = [
'dynamodb:GetRecords',
'dynamodb:GetShardIterator',
];

export const DESCRIBE_TABLE = 'dynamodb:DescribeTable';
14 changes: 8 additions & 6 deletions packages/@aws-cdk/aws-dynamodb/lib/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -679,15 +679,16 @@ abstract class TableBase extends Resource implements ITable {

/**
* Permits an IAM principal all data read operations from this table:
* BatchGetItem, GetRecords, GetShardIterator, Query, GetItem, Scan.
* BatchGetItem, GetRecords, GetShardIterator, Query, GetItem, Scan, DescribeTable.
*
* Appropriate grants will also be added to the customer-managed KMS key
* if one was configured.
*
* @param grantee The principal to grant access to
*/
public grantReadData(grantee: iam.IGrantable): iam.Grant {
return this.combinedGrant(grantee, { keyActions: perms.KEY_READ_ACTIONS, tableActions: perms.READ_DATA_ACTIONS });
const tableActions = perms.READ_DATA_ACTIONS.concat(perms.DESCRIBE_TABLE);
return this.combinedGrant(grantee, { keyActions: perms.KEY_READ_ACTIONS, tableActions });
}

/**
Expand Down Expand Up @@ -724,30 +725,31 @@ abstract class TableBase extends Resource implements ITable {

/**
* Permits an IAM principal all data write operations to this table:
* BatchWriteItem, PutItem, UpdateItem, DeleteItem.
* BatchWriteItem, PutItem, UpdateItem, DeleteItem, DescribeTable.
*
* Appropriate grants will also be added to the customer-managed KMS key
* if one was configured.
*
* @param grantee The principal to grant access to
*/
public grantWriteData(grantee: iam.IGrantable): iam.Grant {
const tableActions = perms.WRITE_DATA_ACTIONS.concat(perms.DESCRIBE_TABLE);
const keyActions = perms.KEY_READ_ACTIONS.concat(perms.KEY_WRITE_ACTIONS);
return this.combinedGrant(grantee, { keyActions, tableActions: perms.WRITE_DATA_ACTIONS });
return this.combinedGrant(grantee, { keyActions, tableActions });
}

/**
* Permits an IAM principal to all data read/write operations to this table.
* BatchGetItem, GetRecords, GetShardIterator, Query, GetItem, Scan,
* BatchWriteItem, PutItem, UpdateItem, DeleteItem
* BatchWriteItem, PutItem, UpdateItem, DeleteItem, DescribeTable
*
* Appropriate grants will also be added to the customer-managed KMS key
* if one was configured.
*
* @param grantee The principal to grant access to
*/
public grantReadWriteData(grantee: iam.IGrantable): iam.Grant {
const tableActions = perms.READ_DATA_ACTIONS.concat(perms.WRITE_DATA_ACTIONS);
const tableActions = perms.READ_DATA_ACTIONS.concat(perms.WRITE_DATA_ACTIONS).concat(perms.DESCRIBE_TABLE);
const keyActions = perms.KEY_READ_ACTIONS.concat(perms.KEY_WRITE_ACTIONS);
return this.combinedGrant(grantee, { keyActions, tableActions });
}
Expand Down
13 changes: 10 additions & 3 deletions packages/@aws-cdk/aws-dynamodb/test/dynamodb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@ testLegacyBehavior('if an encryption key is included, encrypt/decrypt permission
'dynamodb:PutItem',
'dynamodb:UpdateItem',
'dynamodb:DeleteItem',
'dynamodb:DescribeTable',
],
Effect: 'Allow',
Resource: [
Expand Down Expand Up @@ -1919,18 +1920,18 @@ describe('grants', () => {

test('"grantReadData" allows the principal to read data from the table', () => {
testGrant(
['BatchGetItem', 'GetRecords', 'GetShardIterator', 'Query', 'GetItem', 'Scan', 'ConditionCheckItem'], (p, t) => t.grantReadData(p));
['BatchGetItem', 'GetRecords', 'GetShardIterator', 'Query', 'GetItem', 'Scan', 'ConditionCheckItem', 'DescribeTable'], (p, t) => t.grantReadData(p));
});

test('"grantWriteData" allows the principal to write data to the table', () => {
testGrant(
['BatchWriteItem', 'PutItem', 'UpdateItem', 'DeleteItem'], (p, t) => t.grantWriteData(p));
['BatchWriteItem', 'PutItem', 'UpdateItem', 'DeleteItem', 'DescribeTable'], (p, t) => t.grantWriteData(p));
});

test('"grantReadWriteData" allows the principal to read/write data', () => {
testGrant([
'BatchGetItem', 'GetRecords', 'GetShardIterator', 'Query', 'GetItem', 'Scan',
'ConditionCheckItem', 'BatchWriteItem', 'PutItem', 'UpdateItem', 'DeleteItem',
'ConditionCheckItem', 'BatchWriteItem', 'PutItem', 'UpdateItem', 'DeleteItem', 'DescribeTable',
], (p, t) => t.grantReadWriteData(p));
});

Expand Down Expand Up @@ -2092,6 +2093,7 @@ describe('grants', () => {
'dynamodb:GetItem',
'dynamodb:Scan',
'dynamodb:ConditionCheckItem',
'dynamodb:DescribeTable',
],
'Effect': 'Allow',
'Resource': [
Expand Down Expand Up @@ -2244,6 +2246,7 @@ describe('import', () => {
'dynamodb:GetItem',
'dynamodb:Scan',
'dynamodb:ConditionCheckItem',
'dynamodb:DescribeTable',
],
'Effect': 'Allow',
'Resource': [
Expand Down Expand Up @@ -2290,6 +2293,7 @@ describe('import', () => {
'dynamodb:PutItem',
'dynamodb:UpdateItem',
'dynamodb:DeleteItem',
'dynamodb:DescribeTable',
],
'Effect': 'Allow',
'Resource': [
Expand Down Expand Up @@ -2432,6 +2436,7 @@ describe('import', () => {
'dynamodb:GetItem',
'dynamodb:Scan',
'dynamodb:ConditionCheckItem',
'dynamodb:DescribeTable',
],
Resource: [
{
Expand Down Expand Up @@ -2606,6 +2611,7 @@ describe('global', () => {
'dynamodb:GetItem',
'dynamodb:Scan',
'dynamodb:ConditionCheckItem',
'dynamodb:DescribeTable',
],
Effect: 'Allow',
Resource: [
Expand Down Expand Up @@ -2760,6 +2766,7 @@ describe('global', () => {
'dynamodb:GetItem',
'dynamodb:Scan',
'dynamodb:ConditionCheckItem',
'dynamodb:DescribeTable',
],
Effect: 'Allow',
Resource: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,8 @@
"dynamodb:Query",
"dynamodb:GetItem",
"dynamodb:Scan",
"dynamodb:ConditionCheckItem"
"dynamodb:ConditionCheckItem",
"dynamodb:DescribeTable"
],
"Effect": "Allow",
"Resource": [
Expand All @@ -410,7 +411,8 @@
"dynamodb:Query",
"dynamodb:GetItem",
"dynamodb:Scan",
"dynamodb:ConditionCheckItem"
"dynamodb:ConditionCheckItem",
"dynamodb:DescribeTable"
],
"Effect": "Allow",
"Resource": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,8 @@
"dynamodb:Query",
"dynamodb:GetItem",
"dynamodb:Scan",
"dynamodb:ConditionCheckItem"
"dynamodb:ConditionCheckItem",
"dynamodb:DescribeTable"
],
"Effect": "Allow",
"Resource": [
Expand Down Expand Up @@ -533,7 +534,8 @@
"dynamodb:Query",
"dynamodb:GetItem",
"dynamodb:Scan",
"dynamodb:ConditionCheckItem"
"dynamodb:ConditionCheckItem",
"dynamodb:DescribeTable"
],
"Effect": "Allow",
"Resource": [
Expand Down

0 comments on commit 4a44a65

Please sign in to comment.