Git Product home page Git Product logo

Comments (4)

simonw avatar simonw commented on July 1, 2024

Here's my prototype:

@cli.command()
@click.argument("bucket")
@common_boto3_options
def make_bucket_public(bucket, **boto_options):
    """
    Make a bucket public. All files will be visible to anyone who knows the URL.

       s3-credentials make-bucket-public my-bucket
    """
    s3 = make_client("s3", **boto_options)
    try:
        print("Putting public access block")
        response1 = s3.put_public_access_block(
            Bucket=bucket,
            PublicAccessBlockConfiguration={
                "BlockPublicAcls": False,
                "IgnorePublicAcls": False,
                "BlockPublicPolicy": False,
                "RestrictPublicBuckets": False,
            },
        )
        print("Putting bucket policy")
        response2 = s3.put_bucket_policy(
            Bucket=bucket,
            Policy=json.dumps(policies.bucket_policy_allow_all_get(bucket)),
        )
    except botocore.exceptions.ClientError as ex:
        click.echo(ex.__dict__, err=True)
        raise click.ClickException(ex)
    click.echo(json.dumps(response1, indent=4, default=str))
    click.echo(json.dumps(response2, indent=4, default=str))

from s3-credentials.

simonw avatar simonw commented on July 1, 2024

I think it's possible the s3-credentials create name-of-bucket --create-bucket --public command doesn't work correctly because it doesn't do the s3.put_public_access_block bit.

from s3-credentials.

simonw avatar simonw commented on July 1, 2024

I asked ChatGPT what all of those boolean flags meant and it said:

The PublicAccessBlockConfiguration settings are used to manage public access to your S3 bucket. Each boolean option in this configuration controls a specific aspect of public access:

  1. BlockPublicAcls:

    • When set to True, this setting prevents the application of any new public Access Control Lists (ACLs) to the bucket or its objects. It doesn't change the existing ACLs but blocks any attempt to put a new ACL that grants public access.
    • When set to False, it allows the application of new public ACLs to the bucket and its objects.
  2. IgnorePublicAcls:

    • When set to True, this setting ignores any public ACLs on the bucket and its objects, effectively treating them as private. Even if an object has a public ACL, it won't be publicly accessible.
    • When set to False, it respects the public ACLs on the bucket and its objects, allowing public access if a public ACL is set.
  3. BlockPublicPolicy:

    • When set to True, this setting prevents the application of any new public bucket policies to the bucket. It blocks attempts to put a new bucket policy that grants public access.
    • When set to False, it allows the application of new public bucket policies to the bucket.
  4. RestrictPublicBuckets:

    • When set to True, this setting restricts access to the bucket to only AWS services and authorized users within the bucket owner's account, even if the bucket has a public policy. It effectively blocks public access granted by bucket policies.
    • When set to False, it allows public access granted by bucket policies.

By configuring these settings, you can control the level of public access to your S3 bucket and its objects, enhancing the security of your data. For example, setting all options to True provides the strictest level of access control, ensuring that the bucket and its objects are not publicly accessible under any circumstances.

So I think they should all be False if a bucket is going to serve public files.

from s3-credentials.

simonw avatar simonw commented on July 1, 2024

Related:

from s3-credentials.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.