aws / aws/aws-cdk

aws-codepipeline: cross region support creates huge inline policy document for the pipeline role

Open
#16,244 22 comments 11 reactions 0 assignees View on GitHub
@aws-cdk/aws-codepipeline bug effort/large in-progress p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

We have a code pipeline setup with cross region support. The pipeline creates replication buckets in cross regions and pipeline internally adds permissions for these s3 buckets in the pipeline role [here](https://github.com/aws/aws-cdk/blob/ae34d4a69a5073d8f0175b5282fa8bf92139fab5/packages/%40aws-cdk/aws-codepipeline/lib/pipeline.ts#L552).

Something like this for each cross region:
```
{
"Action": [
"s3:GetObject*",
"s3:GetBucket*",
"s3:List*",
"s3:DeleteObject*",
"s3:PutObject*",
"s3:Abort*"
],
"Resource": [
"arn:aws:s3:::",
"arn:aws:s3:::/*"
],
"Effect": "Allow"
},
```
Since an `addAction` is called for each region, we add a new policy statement every time with the same permissions, which is causing the pipeline role inline policy to exceed the iam policy size limit causing below error.

```
Maximum policy size of 10240 bytes exceeded for role
```
Similar issue is seen for the `sts:AssumeRole` permissions added [here](https://github.com/aws/aws-cdk/blob/ae34d4a69a5073d8f0175b5282fa8bf92139fab5/packages/%40aws-cdk/aws-codepipeline/lib/pipeline.ts#L669).

### Reproduction Steps
Create a codepipeline with multiple stages and ~ 15 regions.

### What did you expect to happen?
The role that pipeline created should be reduced / compacted. Since there are many duplicate actions for each resource, we can have a single policy statement with all resources.

We were adding new stages and regions in our pipeline when we observed this.

### What actually happened?

Got this error when deploying the stack.

```
Maximum policy size of 10240 bytes exceeded for role
```

### Environment

- **CDK CLI Version :** 1.23, I think the latest version has this bug too.
- **Framework Version:** 1.23
- **Node.js Version:** 12.x
- **OS :** MacOS
- **Language (Version):** TypeScript (3.8.3)

---

This is :bug: Bug Report

Contributor guide

Open the contributing guide

Research direction

Start with the linked sections of packages/@aws-cdk/aws-codepipeline/lib/pipeline.ts, especially the addAction call around line 552 and the sts:AssumeRole permissions around line 669. Reproduce the issue with a pipeline containing multiple stages across about 15 regions, then verify that the generated pipeline role policy stays within the IAM size limit while retaining the required permissions.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cloud, devops, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.