Python Forum
Cant find S3 Read or Write access from Python code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cant find S3 Read or Write access from Python code
#1
Hi
First off I am communicating with AWS with python boto3(Pycharm),So my question is i have created
8 buckets in which 4 buckets Read access and other 4 are Write access problem while executing i can all the buckets which Read and Write my task is to show only Read access and write access in other programme kindly help me out to sort this problem.

------->>>Here is the code what i wrote------------------>:
s3_bucket_public_read_prohibited(self):
    result = True
    failReason = ""
    control = "4.2"
    description = "No Public read access for S3 Buckets"
    scored = False
    offenders = []
    s3_client = boto3.client('s3')
    buckets = s3_client.list_buckets()
    public_access = False

    for bucket in buckets['Buckets']:
        print(bucket)
        acl_bucket = s3_client.get_bucket_acl(Bucket=bucket['Name'])
        print(yaml.dump(acl_bucket))
        for grantee in acl_bucket['Grants']:
            if len(grantee['Grantee']) > 0:
                print(grantee['Grantee'])
                for uri in (grantee['Grantee'].keys()):
                    if uri == 'URI':
                        if grantee['Grantee']['URI'] == 'http://acs.amazonaws.com/groups/global/AllUsers':
                            public_access = True
                            print(public_access)
        if public_access == True:
            offenders.append(bucket['Name'])
        public_access = False
    if len(offenders) > 0:
        result = False
        failReason = "These S3 Buckets available with Public Read Access"
    return {'Result': result, 'failReason': failReason, 'Offenders': offenders, 'ScoredControl': scored,'Description': description, 'ControlId': control}
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  write code that resides in parent directory franklin97355 0 50 9 hours ago
Last Post: franklin97355
  needing some help to write some code for a game calculator rymdaksel 1 357 Jan-02-2024, 09:56 AM
Last Post: deanhystad
  python Read each xlsx file and write it into csv with pipe delimiter mg24 4 1,314 Nov-09-2023, 10:56 AM
Last Post: mg24
Question Special Characters read-write Prisonfeed 1 582 Sep-17-2023, 08:26 PM
Last Post: Gribouillis
  Pytest Installed, but VS Code Won’t Access Pytest AstralWeeks 9 2,893 Sep-13-2023, 03:00 PM
Last Post: AstralWeeks
Question in this code, I input Key_word, it can not find although all data was exact Help me! duchien04x4 3 972 Aug-31-2023, 05:36 PM
Last Post: deanhystad
  How do I read and write a binary file in Python? blackears 6 6,016 Jun-06-2023, 06:37 PM
Last Post: rajeshgk
  Read text file, modify it then write back Pavel_47 5 1,501 Feb-18-2023, 02:49 PM
Last Post: deanhystad
  how to read txt file, and write into excel with multiply sheet jacklee26 14 9,523 Jan-21-2023, 06:57 AM
Last Post: jacklee26
  read a text file, find all integers, append to list oldtrafford 12 3,372 Aug-11-2022, 08:23 AM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020