Sign in
agent:
Auto Exec

AWS S3 Bucket Encryption Enforcement

There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.

This runbook is designed to enforce encryption protocols on Amazon Simple Storage Service (S3) buckets to secure data, focusing primarily on older S3 buckets that might not have encryption enabled by default. While AWS currently provides Server-Side Encryption (SSE) for all new S3 buckets, older buckets might still lack these security measures. The runbook identifies all S3 buckets, singles out those that are unencrypted, and then applies appropriate encryption methods like SSE-S3, SSE-KMS, or SSE-C. This process is vital for safeguarding data against unauthorized access and for compliance with various data protection standards and regulations. By proactively enforcing encryption on all S3 buckets, organizations ensure a robust security posture for their AWS S3 storage infrastructure, thereby preventing sensitive data exposure and meeting stringent regulatory requirements.

  1. 1

    List All AWS S3 Buckets

    There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.

    This task involves retrieving and displaying a comprehensive list of all Amazon S3 buckets within an AWS account. This step is crucial as it provides a clear overview of all the storage resources available, serving as a starting point for various management and security tasks, such as enforcing encryption or implementing access policies. By generating a list of all S3 buckets, users can easily identify and manage their storage resources, ensuring effective organization and security compliance within their AWS environment.

    import boto3 from botocore.exceptions import BotoCoreError, NoCredentialsError, PartialCredentialsError creds = _get_creds(cred_label)['creds'] access_key = creds['username'] secret_key = creds['password'] def list_all_s3_buckets(): try: # Creating a Boto3 S3 client s3 = boto3.client('s3',aws_access_key_id=access_key,aws_secret_access_key=secret_key) # Sending a request to list S3 buckets response = s3.list_buckets() # Extracting bucket names from the response all_buckets = [bucket['Name'] for bucket in response['Buckets']] return all_buckets except NoCredentialsError: # Handle the exception when credentials are not found print("Error: AWS credentials not found") return None except PartialCredentialsError: # Handle the exception when provided credentials are incomplete print("Error: Incomplete AWS credentials") return None except BotoCoreError as e: # Handle other Boto3 core exceptions print(f"Error: AWS SDK for Python (Boto3) core error occurred - {e}") return None except Exception as e: # Handle any other general exceptions print(f"Unexpected error: {e}") return None # Main block buckets = list_all_s3_buckets() if buckets is not None: if buckets: print("Found the following S3 buckets:") for bucket in buckets: print(bucket) else: print("No S3 buckets found.") else: print("Error occurred while trying to list S3 buckets.") # Use Create S3 bucket task if you need to create a S3 bucket for CloudTrail logging context.skip_sub_tasks = True
    copied
    1
  2. 2

    Filter out Unencrypted AWS S3 Buckets

    There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.

    This task selectively identifies and lists all Amazon S3 buckets that lack encryption within an AWS account. In the context of security and compliance, it's crucial to pinpoint these unencrypted buckets as they are vulnerable to unauthorized data access and potential data breaches. With this list, organizations can immediately recognize and address security risks by applying necessary encryption, ensuring that data stored in these S3 buckets is protected and compliant with data privacy standards and regulations.

    import boto3 from botocore.exceptions import BotoCoreError, NoCredentialsError, PartialCredentialsError creds = _get_creds(cred_label)['creds'] access_key = creds['username'] secret_key = creds['password'] def filter_unencrypted_buckets(all_buckets): unencrypted_buckets = [] try: # Creating a Boto3 S3 client s3 = boto3.client('s3',aws_access_key_id=access_key,aws_secret_access_key=secret_key) for bucket in all_buckets: try: # Attempting to get the encryption configuration of a bucket response = s3.get_bucket_encryption(Bucket=bucket) except s3.exceptions.ClientError as e: # Handling specific error when the encryption configuration is not found if e.response['Error']['Code'] == 'ServerSideEncryptionConfigurationNotFoundError': unencrypted_buckets.append(bucket) else: print(f"Unexpected error getting encryption status for bucket {bucket}: {e}") except Exception as e: # Handling general exceptions print(f"Unexpected error getting encryption status for bucket {bucket}: {e}") return unencrypted_buckets except NoCredentialsError: print("Error: AWS credentials not found") return None except PartialCredentialsError: print("Error: Incomplete AWS credentials") return None except BotoCoreError as e: print(f"Boto3 core error: {e}") return None except Exception as e: print(f"Unexpected error: {e}") return None # Main block ''' # Example list of buckets all_buckets = ['aws-cost-usage-redshift-quicksight-gzip-csv-type-file', 'backup-large-files-from-ec2-instances-filesystem', 'cost-usage-test-redshift', 'encryption-test-bucket-789', 'ssm-session-logging-123'] ''' # buckets received from parent task all_buckets = buckets unencrypted_buckets = filter_unencrypted_buckets(all_buckets) if unencrypted_buckets is not None: if unencrypted_buckets: print("Found the following unencrypted S3 buckets:") for bucket in unencrypted_buckets: print(bucket) else: print("No unencrypted S3 buckets found.") else: print("Error occurred while trying to filter unencrypted S3 buckets.") context.proceed=False
    copied
    2
  3. 3

    Encrypt AWS S3 Buckets

    There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.

    This task is dedicated to applying encryption mechanisms to unencrypted Amazon S3 buckets. Encryption is a critical security measure used to protect data stored in S3 buckets from unauthorized access and breaches. The task programmatically applies AWS-supported encryption methods, like SSE-S3, SSE-KMS, or SSE-C, to each identified unencrypted bucket, thus enhancing the security of stored data. While AWS applies encryption to new S3 buckets by default, this task is particularly crucial for securing previously created buckets that might still be unencrypted.

    import boto3 from botocore.exceptions import BotoCoreError, NoCredentialsError, PartialCredentialsError creds = _get_creds(cred_label)['creds'] access_key = creds['username'] secret_key = creds['password'] def encrypt_unencrypted_buckets(unencrypted_buckets): try: # Creating a Boto3 S3 client s3 = boto3.client('s3',aws_access_key_id=access_key,aws_secret_access_key=secret_key) for bucket in unencrypted_buckets: try: # Attempting to apply AES256 server-side encryption to an unencrypted bucket s3.put_bucket_encryption( Bucket=bucket, ServerSideEncryptionConfiguration={ 'Rules': [{ 'ApplyServerSideEncryptionByDefault': { 'SSEAlgorithm': 'AES256' } }] } ) print(f"Bucket {bucket} is now encrypted with AES256.") except s3.exceptions.ClientError as e: # Handling specific client error exceptions print(f"Client error encrypting bucket {bucket}: {e}") except Exception as e: # Handling general exceptions print(f"Unexpected error encrypting bucket {bucket}: {e}") except NoCredentialsError: print("Error: AWS credentials not found") except PartialCredentialsError: print("Error: Incomplete AWS credentials") except BotoCoreError as e: print(f"Boto3 core error: {e}") except Exception as e: print(f"Unexpected error: {e}") # Main block ''' # Example list of unencrypted buckets unencrypted_buckets = ['your-unencrypted-bucket-1', 'your-unencrypted-bucket-2'] ''' if unencrypted_buckets: # unencrypted_buckets received from parent task encrypt_unencrypted_buckets(unencrypted_buckets) else: print("No Unencrypted Buckets were provided")
    copied
    3