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

set-public-policy command #81

Open
simonw opened this issue Nov 28, 2022 · 5 comments
Open

set-public-policy command #81

simonw opened this issue Nov 28, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Owner

simonw commented Nov 28, 2022

Mainly for if you run s3-credentials create mybucket --create-bucket but forget to add --public and want to add that later.

@simonw simonw added the enhancement New feature or request label Nov 28, 2022
@simonw
Copy link
Owner Author

simonw commented Nov 28, 2022

Relevant code from the create command:

bucket_policy = {}
if public:
bucket_policy = policies.bucket_policy_allow_all_get(bucket)

if bucket_policy:
s3.put_bucket_policy(
Bucket=bucket, Policy=json.dumps(bucket_policy)
)
log("Attached bucket policy allowing public access")

@simonw
Copy link
Owner Author

simonw commented Nov 28, 2022

Here's a prototype:

@cli.command()
@click.argument("bucket")
@common_boto3_options
def set_public_policy(bucket, **boto_options):
    """
    Set public policy for bucket

    This will allow GET requests for anonymous users.

        s3-credentials set-public-policy my-bucket
    """
    s3 = make_client("s3", **boto_options)
    if not bucket_exists(s3, bucket):
        raise click.ClickException("Bucket {} does not exists".format(bucket))
    bucket_policy = policies.bucket_policy_allow_all_get(bucket)
    try:
        s3.put_bucket_policy(Bucket=bucket, Policy=json.dumps(bucket_policy))
    except botocore.exceptions.ClientError as e:
        raise click.ClickException(e)

I built that for:

@simonw
Copy link
Owner Author

simonw commented Nov 28, 2022

Design decision: should this be reversible? If so, what should that command be?

Should there be a way to see if a bucket has this policy or not, or a way to list the bucket policy in general?

Then it needs tests and docs.

@simonw
Copy link
Owner Author

simonw commented Nov 28, 2022

Relevant docs:

https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3-example-bucket-policies.html

A bucket only gets one bucket policy at a time.

@simonw
Copy link
Owner Author

simonw commented Apr 5, 2024

Should there be a way to see if a bucket has this policy or not, or a way to list the bucket policy in general?

I added that here:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant