aws / aws/aws-cdk

(dynamodb): grant calls no longer working when passed a ManagedPolicy

Open
#32,795 16 comments 0 reactions 1 assignee Claimed by @QuantumNeuralCoder View on GitHub
@aws-cdk/aws-dynamodb bug p3 potential-regression
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
1d 19h
Merged PRs (30d)
74

Description

### Describe the bug

Previously, it's been possible to use `.grant` functions on dynamoDB tables and pass them a `ManagedPolicy` (which is allowed by the type system since `ManagedPolicy` implements `IGrantable`).

Under 2.174.0, that results in an error:

`Cannot use a ManagedPolicy as the 'Principal' or 'NotPrincipal' in an IAM Policy`.

This is a change in behaviour, and it's also inconsistent with e.g. S3 where it's still possible to call `bucket.grantReadWrite(managedPolicy);`

### Regression Issue

- [x] Select this option if this issue appears to be a regression.

### Last Known Working CDK Version

2.131.0

### Expected Behavior

`.grant` functions for dynamo tables work when passed a `ManagedPolicy` and add the appropriate policy statements.

### Current Behavior

Error thrown: Cannot use a ManagedPolicy as the 'Principal' or 'NotPrincipal' in an IAM Policy

### Reproduction Steps

```ts
const table = TableV2.fromTableArn(
this,
'Table',
arnForTable,
);
table.grantReadWriteData(managedPolicy);
```

Error is visible in CDK unit tests which verify the managed policy composition.

### Possible Solution

_No response_

### Additional Information/Context

I'm not sure if the new behaviour is correct in that a ManagedPolicy is not in fact a Principal, and hence the previous behaviour shouldn't have been allowed, but it should be consistent and obvious from documentation where you can and can't use the convenience `grant` functions. At present they work in this scenario for other library areas e.g. S3.

### CDK CLI Version

2.174.0

### Framework Version

_No response_

### Node.js Version

18

### OS

Mac OS

### Language

TypeScript

### Language Version

5.x

### Other information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.