Skip to main content

More Info:

Identifies principals carrying permissions in inline policies rather than managed ones. An inline policy exists only on the identity it is attached to - it cannot be reused, it is invisible to anyone reviewing shared policies, and it disappears silently when the identity is deleted. Move these permissions into managed policies so grants can be reviewed and versioned in one place.

Risk Level

High

Address

Security

Compliance Standards

  • AWS Startup Security Baseline
  • AWS Well Architected Framework

Triage and Remediation

Remediation

Using Console

None

To remediate the misconfiguration of principals with inline policies in AWS IAM using AWS CLI, follow these steps:
  1. Identify the principals with inline policies:
    • Run the following AWS CLI command to list all IAM users with inline policies:
    • Run the following AWS CLI command to list all IAM roles with inline policies:
  2. Create managed policies for the inline policies:
    • For each IAM user with inline policies, create a managed policy using the following AWS CLI command:
      Replace <policy-name> with a suitable name for the policy and <policy-document.json> with the JSON document containing the inline policy.
    • For each IAM role with inline policies, create a managed policy using the same AWS CLI command.
  3. Attach the managed policies to the principals:
    • For each IAM user, attach the managed policy using the following AWS CLI command:
      Replace <user-name> with the IAM user’s name and <policy-arn> with the ARN of the managed policy.
    • For each IAM role, attach the managed policy using the same AWS CLI command.
  4. Verify the remediation:
    • Run the following AWS CLI command to list all IAM users and their associated managed policies:
    • Run the following AWS CLI command to list all IAM roles and their associated managed policies:
By following these steps, you will remediate the misconfiguration of principals with inline policies in AWS IAM using AWS CLI.
To remediate the misconfiguration of principals with inline policies in AWS IAM using Python, follow these steps:
  1. Identify the principals with inline policies:
    • Use the AWS Identity and Access Management (IAM) service to list all the IAM users, groups, and roles.
    • For each principal, check if they have any inline policies attached.
  2. Create managed policies:
    • Analyze the inline policies and identify their permissions and resources.
    • Create managed policies in AWS IAM using the boto3 Python library.
    • Assign the appropriate permissions and resources to the managed policies.
  3. Detach inline policies:
    • For each principal with inline policies, use the boto3 library to detach the inline policies.
    • Keep track of the detached inline policies to later attach them as managed policies.
  4. Attach managed policies:
    • For each principal, attach the corresponding managed policies created in step 2 using the boto3 library.
    • Ensure that the managed policies provide the necessary permissions and resources required by the principals.
  5. Update your code or infrastructure-as-code templates:
    • If you have any code or infrastructure-as-code templates that reference the inline policies, update them to use the managed policies instead.
    • Replace the inline policy references with the corresponding managed policy ARNs.
  6. Test and validate:
    • Test the remediated IAM configurations thoroughly to ensure that the intended permissions and resources are still accessible.
    • Validate the permissions and resources for each principal to ensure they align with the desired access levels.
  7. Monitor and enforce best practices:
    • Regularly monitor your AWS IAM configurations to identify any new instances of principals with inline policies.
    • Enforce best practices by using managed policies instead of inline policies wherever possible.
By following these steps, you can successfully remediate the misconfiguration of principals with inline policies in AWS IAM using Python.
This change does not force replacement of the IAM user itself; it destroys the inline policy resource and creates a managed policy plus an attachment.For verification, terraform plan should show:
  • aws_iam_user_policy resources for that user being destroyed.
  • A new aws_iam_policy being created.
  • A new aws_iam_user_policy_attachment being created.