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

Use CloudTrail's regionalized policy templates #1167

Merged
merged 5 commits into from
Feb 25, 2015

Conversation

danielgtaylor
Copy link
Contributor

This change switches away from always using an S3 bucket in us-west-2
to fetch CloudTrail policy information for S3 and SNS when setting up
new buckets/topics and instead uses the awscloudtrail-policy-REGION
regionalized buckets. It also updates the policy version to use the
most recent release.

Tests are updated and a couple new ones make sure the regionalized
buckets are used.

cc @jamesls @kyleknap

Note: this code still needs to be updated to use clients, but that seems
like it should be a separate task.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 91.91% when pulling 99ca9a6 on cloudtrail-regional-policy into b9c2900 on develop.

@kyleknap
Copy link
Contributor

LGTM 🚢 I agree it would be nice if you could update to clients. But, at this time it will not be feasible for you until region_name is exposed in clients for the reason you need the region name to determine the bucket to search in and setting the bucket configuration. It is the same problem that I am running into with the s3 commands.

@@ -204,8 +206,9 @@ def setup_new_bucket(self, bucket, prefix, policy_url=None):
if policy_url:
policy = requests.get(policy_url).text
else:
data = self.s3.GetObject(bucket='awscloudtrail',
key=S3_POLICY_TEMPLATE)
data = self.s3.GetObject(
Copy link
Member

Choose a reason for hiding this comment

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

It might be nice to provide a better error message if a policy hasn't been copied over to a specific region now that this is a new possible failure mode.

@jamesls
Copy link
Member

jamesls commented Feb 20, 2015

Overall looks good. Just a small comment on the new failure mode.

@danielgtaylor
Copy link
Contributor Author

@jamesls code has been refactored/updated to log an error message, then pass-through the underlying exception. If we want to expose a custom exception just for this case then I'm not opposed, but it's unclear to me which Botocore exceptions might happen during the operation.call(...) method.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.11%) to 92.02% when pulling 8baecb2 on cloudtrail-regional-policy into b9c2900 on develop.

' region %s: %s', self.region_name, key_name)
raise

return data['Body'].read().decode('utf-8')
Copy link
Member

Choose a reason for hiding this comment

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

This should probably be moved inside the try/except because we can still hit timeout/connection errors when we try to read the response body.

@jamesls
Copy link
Member

jamesls commented Feb 23, 2015

It would be good to add a test for this new code.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.05%) to 91.86% when pulling b58c019 on cloudtrail-regional-policy into b9c2900 on develop.

@danielgtaylor
Copy link
Contributor Author

@jamesls please take another look. The coverage decrease seems like a false alarm because I only added tests.

data = self.s3.GetObject(
bucket='awscloudtrail-policy-' + self.region_name,
key=key_name)
policy = data['Body'].read().decode('utf-8')
Copy link
Member

Choose a reason for hiding this comment

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

You can just return data['Body'].read().decode('utf-8') instead of needing the return policy on line 200.

@jamesls
Copy link
Member

jamesls commented Feb 23, 2015

Why not raise a specific exception and just use assertRaises() in your test? Simple code, simpler test, no LOG patching required.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.12%) to 92.02% when pulling 8b6344b on cloudtrail-regional-policy into b9c2900 on develop.

@jamesls
Copy link
Member

jamesls commented Feb 24, 2015

:shipit: Thanks! Don't forget to update the changelog.

This change switches away from always using an S3 bucket in `us-west-2`
to fetch CloudTrail policy information for S3 and SNS when setting up
new buckets/topics and instead uses the `awscloudtrail-policy-REGION`
regionalized buckets. It also updates the policy version to use the
most recent release.

Tests are updated and a couple new ones make sure the regionalized
buckets are used.
@danielgtaylor danielgtaylor force-pushed the cloudtrail-regional-policy branch from 8b6344b to f549785 Compare February 25, 2015 18:12
danielgtaylor added a commit that referenced this pull request Feb 25, 2015
Use CloudTrail's regionalized policy templates
@danielgtaylor danielgtaylor merged commit 706ff5d into develop Feb 25, 2015
@danielgtaylor danielgtaylor deleted the cloudtrail-regional-policy branch February 25, 2015 18:12
thoward-godaddy pushed a commit to thoward-godaddy/aws-cli that referenced this pull request Feb 12, 2022
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.

4 participants