cloudtools / cloudtools/troposphere

weird error with s3 bucket policy / iam policy

Open
#370 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
4.9k
Forks
1.4k
PR merge metrics
No merged PRs in 30d

Description

Hi,

I have the following code:

```
self.uploadBucketAnonUploadPolicy = t.add_resource(BucketPolicy(
"uploadBucketAnonUploadPolicy",
Bucket=Ref(self.uploadBucket),
PolicyDocument={
"Version": "2012-10-17",
"Statement": [
{
"Action": "s3:PutObject",
"Effect": "Allow",
"Resource": [
Join("", ["arn:aws:s3:::", Ref(self.uploadBucket), "/*"]),
],
"Principal": "*",
},
{
"Action": "s3:*",
"Effect": "Allow",
"Resource": [
Join("", ["arn:aws:s3:::", Ref(self.uploadBucket), "/*"]),
],
"Principal": {
"AWS": [ Ref("AWS::AccountId"), ]
},
},
]
}
))
```

the output of that fragment is:

```
"uploadBucketAnonUploadPolicy": {
"Properties": {
"Bucket": {
"Ref": "uploadbucket"
},
"PolicyDocument": {
"Statement": [
{
"Action": "s3:PutObject",
"Effect": "Allow",
"Principal": "*",
"Resource": [
{
"Fn::Join": [
"",
[
"arn:aws:s3:::",
{
"Ref": "uploadbucket"
},
"/*"
]
]
}
]
},
{
"Action": "s3:*",
"Effect": "Allow",
"Principal": {
"AWS": [
{
"Ref": "AWS::AccountId"
}
]
},
"Resource": [
{
"Fn::Join": [
"",
[
"arn:aws:s3:::",
{
"Ref": "uploadbucket"
},
"/*"
]
]
}
]
}
],
"Version": "2012-10-17"
}
},
"Type": "AWS::S3::BucketPolicy"
},
```

The resulting policy should look like:

```
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::uploadbucket-bla/*"
},
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"AWS": [ "arn:aws:iam::accountidnumber:root" ]
},
"Action": "s3:*",
"Resource": "arn:aws:s3:::uploadbucket-bla/*"
}
]
}
```

however, the resulting policy looks like this:

```
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::uploadbucket-bla/*"
},
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::accountidnumber:root"
},
"Action": "s3:*",
"Resource": "arn:aws:s3:::uploadbucket-bla/*"
}
]
}
```

Note the missing array in the principal (with the array the policy does what is supposed to)

is this a cloudformation bug? Am I doing something wrong here?

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.