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

Dont decode S3 Bucket policies #57

Merged
merged 6 commits into from
Mar 21, 2019
Merged

Dont decode S3 Bucket policies #57

merged 6 commits into from
Mar 21, 2019

Conversation

patrobinson
Copy link
Contributor

@patrobinson patrobinson commented Feb 27, 2019

This fixes an issue that was introduced in #13. I can't really figure out why we would want to decode the Policy, it should never be encoded in the first place as far as I can tell.
S3 bucket policies are not URL encoded, while other policies are.
If the bucket policy contains invalid encoding, such as % followed by non-hexadecimal characters, it creates an error such as:

Error decoding policy invalid URL escape "%zz"

Copy link

@IcyWednesdays IcyWednesdays left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Patrick Robinson added 2 commits March 4, 2019 17:14
I'm not quite sure how to ensure the errors get raised appropriately
They're already decoded, as opposed to IAM policies
@@ -126,3 +126,10 @@ Actual: %#v`, nt.description, nt.input, nt.expected, result)
}
}
}

func TestNewPolicyDocumentFromJson(t *testing.T) {
_, err := NewPolicyDocumentFromJson("{\"Version\":\"2012-10-17\",\"Id\":\"AllowPublicRead\",\"Statement\":[{\"Sid\":\"PublicReadBucketObjects\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":\"s3:GetObject\",\"Resource\":\"arn:aws:s3:::example.com/*\",\"Condition\":{\"StringEquals\":{\"aws:Referer\":\"%zz\"}}}]}")
Copy link
Member

@mtibben mtibben Mar 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use backticks for the string here for readability?

iamy/aws.go Outdated
@@ -120,8 +120,11 @@ func (a *AwsFetcher) fetchIamData() error {
}),
},
func(resp *iam.GetAccountAuthorizationDetailsOutput, lastPage bool) bool {
// There's a bug here. This doesn't set the variable outside this function scope
// So IAMY just swallows any errors returned from populateIamData()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm I'm not sure I understand... can you fix or produce a testcase?

Copy link
Contributor Author

@patrobinson patrobinson Mar 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to fix it, but I'm not entirely sure how. I'll pull this out into a seperate WIP PR and see if I can write a failing test.

iamy/policy.go Outdated
log.Printf("Error unmarshalling JSON %s %s", err, jsonString)
return nil, err
}
//log.Printf("Doc %s\nJSON: %s", doc, jsonString)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented out code

iamy/policy.go Outdated
return nil, err
}
//log.Printf("Doc %s\nJSON: %s", doc, jsonString)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented out code

Patrick Robinson added 3 commits March 5, 2019 10:55
Remove commented out code
Will fix in another PR
@patrobinson
Copy link
Contributor Author

Thanks for the review @mtibben I've addressed your feedback and given this a whirl in one of our accounts. Let me know your thoughts

@patrobinson patrobinson changed the title Dont decode policies Dont decode S3 Bucket policies Mar 5, 2019
@patrobinson patrobinson merged commit d00e90f into 99designs:master Mar 21, 2019
@patrobinson patrobinson deleted the dont-decode-policy branch March 21, 2019 01:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants