Skip to main content

More Info:

This rule checks each AWS Identity and Access Management (IAM) resource to see if a policy with the specified Amazon Resource Name (ARN) in the input parameter is attached. The rule is NON_COMPLIANT if the specified policy ARN is attached to the IAM resource.

Risk Level

Medium

Address

Security

Compliance Standards

CBP

Triage and Remediation

How to Prevent

Using Console

To prevent blacklisted IAM policies in AWS using the AWS Management Console, follow these steps:
  1. Review IAM Policies Regularly:
    • Navigate to the IAM Dashboard in the AWS Management Console.
    • Click on “Policies” in the left-hand menu.
    • Regularly review the list of policies to ensure none of them are blacklisted or overly permissive.
  2. Use IAM Access Analyzer:
    • In the IAM Dashboard, select “Access Analyzer” from the left-hand menu.
    • Create an analyzer if you haven’t already.
    • Use the analyzer to identify and review policies that grant access to resources outside your organization or that are overly permissive.
  3. Enable AWS Config Rules:
    • Go to the AWS Config service in the AWS Management Console.
    • Create or use existing AWS Config rules to continuously monitor IAM policies.
    • Enable rules such as IAM_POLICY_NO_STATEMENTS_WITH_ADMIN_ACCESS to detect and alert on blacklisted policies.
  4. Implement Policy Validation:
    • When creating or updating IAM policies, use the policy validation feature.
    • In the IAM policy editor, click on “Validate Policy” to check for any issues or overly permissive permissions.
    • Address any warnings or errors before saving the policy.
By following these steps, you can proactively prevent the use of blacklisted IAM policies in your AWS environment.
To prevent blacklisted IAM policies in AWS using the AWS CLI, you can follow these steps:
  1. List Existing IAM Policies:
    • First, you need to list all the existing IAM policies to identify any that might be blacklisted.
    aws iam list-policies --scope Local
    
  2. Describe IAM Policies:
    • For each policy, describe the policy to get its details and check if it matches any blacklisted criteria.
    aws iam get-policy --policy-arn <policy-arn>
    
  3. Create a Policy with Allowed Actions:
    • Create IAM policies that only include allowed actions and avoid any blacklisted actions.
    aws iam create-policy --policy-name <policy-name> --policy-document file://<policy-document.json>
    
  4. Attach Policies to Users, Groups, or Roles:
    • Ensure that only the approved policies are attached to users, groups, or roles.
    aws iam attach-user-policy --user-name <user-name> --policy-arn <policy-arn>
    aws iam attach-group-policy --group-name <group-name> --policy-arn <policy-arn>
    aws iam attach-role-policy --role-name <role-name> --policy-arn <policy-arn>
    
By following these steps, you can prevent the use of blacklisted IAM policies in your AWS environment using the AWS CLI.
To prevent blacklisted IAM policies in AWS, Azure, and GCP using Python scripts, you can follow these steps:

AWS (Amazon Web Services)

  1. Install Boto3 Library: Ensure you have the Boto3 library installed to interact with AWS services.
    pip install boto3
    
  2. Define Blacklisted Policies: Create a list of blacklisted policies that you want to check against.
    blacklisted_policies = [
        "arn:aws:iam::aws:policy/AdministratorAccess",
        "arn:aws:iam::aws:policy/IAMFullAccess",
        # Add more policies as needed
    ]
    
  3. Check IAM Policies: Write a script to list all IAM policies and check if any of them are blacklisted.
    import boto3
    
    def check_blacklisted_policies():
        iam_client = boto3.client('iam')
        response = iam_client.list_policies(Scope='Local')
        policies = response['Policies']
    
        for policy in policies:
            if policy['Arn'] in blacklisted_policies:
                print(f"Blacklisted policy found: {policy['Arn']}")
    
    check_blacklisted_policies()
    
  4. Automate and Schedule: Automate the script to run at regular intervals using AWS Lambda or a cron job to ensure continuous compliance.

Azure (Microsoft Azure)

  1. Install Azure SDK: Ensure you have the Azure SDK installed to interact with Azure services.
    pip install azure-identity azure-mgmt-authorization
    
  2. Define Blacklisted Policies: Create a list of blacklisted policies that you want to check against.
    blacklisted_policies = [
        "/providers/Microsoft.Authorization/policyDefinitions/Owner",
        "/providers/Microsoft.Authorization/policyDefinitions/UserAccessAdministrator",
        # Add more policies as needed
    ]
    
  3. Check IAM Policies: Write a script to list all IAM policies and check if any of them are blacklisted.
    from azure.identity import DefaultAzureCredential
    from azure.mgmt.authorization import AuthorizationManagementClient
    
    credential = DefaultAzureCredential()
    subscription_id = 'your-subscription-id'
    client = AuthorizationManagementClient(credential, subscription_id)
    
    def check_blacklisted_policies():
        policies = client.policy_definitions.list()
        for policy in policies:
            if policy.id in blacklisted_policies:
                print(f"Blacklisted policy found: {policy.id}")
    
    check_blacklisted_policies()
    
  4. Automate and Schedule: Automate the script to run at regular intervals using Azure Functions or a cron job to ensure continuous compliance.

GCP (Google Cloud Platform)

  1. Install Google Cloud SDK: Ensure you have the Google Cloud SDK installed to interact with GCP services.
    pip install google-auth google-cloud-iam
    
  2. Define Blacklisted Policies: Create a list of blacklisted policies that you want to check against.
    blacklisted_policies = [
        "roles/owner",
        "roles/editor",
        # Add more policies as needed
    ]
    
  3. Check IAM Policies: Write a script to list all IAM policies and check if any of them are blacklisted.
    from google.cloud import iam_v1
    from google.oauth2 import service_account
    
    credentials = service_account.Credentials.from_service_account_file('path-to-your-service-account-file.json')
    client = iam_v1.IAMClient(credentials=credentials)
    
    def check_blacklisted_policies():
        policies = client.list_roles()
        for policy in policies:
            if policy.name in blacklisted_policies:
                print(f"Blacklisted policy found: {policy.name}")
    
    check_blacklisted_policies()
    
  4. Automate and Schedule: Automate the script to run at regular intervals using Google Cloud Functions or a cron job to ensure continuous compliance.
By following these steps, you can prevent the use of blacklisted IAM policies across AWS, Azure, and GCP using Python scripts.