Skip to content

Instantly share code, notes, and snippets.

@graphaelli
Created November 20, 2015 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save graphaelli/0d5cfb24c4255daab1a5 to your computer and use it in GitHub Desktop.
Save graphaelli/0d5cfb24c4255daab1a5 to your computer and use it in GitHub Desktop.
import troposphere
import troposphere.ec2
import troposphere.iam
from awacs.aws import Allow, Statement, Policy
from awacs.s3 import ARN as S3_ARN
import awacs.s3 as s3
def read_only_bucket_access(bucket_name):
"""IAM policy statements for read-only bucket access."""
return [
Statement(
Effect=Allow,
Action=[s3.ListBucket, s3.GetBucketLocation],
Resource=[S3_ARN(bucket_name)],
),
Statement(
Effect=Allow,
Action=[s3.GetObject],
Resource=[S3_ARN(bucket_name + '/*')],
),
]
def docker_registry_consumer_policy(bucket_name):
"""IAM policy for read-only s3-backed docker registry access."""
return troposphere.iam.Policy(
PolicyName='DockerRegistryConsumerPolicy',
PolicyDocument=Policy(
Statement=[
*read_only_bucket_access(bucket_name),
]
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment