HIGH
Source
Trivy
Frameworks

CIS AWS 1.4

ID
AVD-AWS-0057

IAM policy should avoid use of wildcards and instead apply the principle of least privilege

You should use the principle of least privilege when defining your IAM policies. This means you should specify each exact permission required without using wildcards, as this could cause the granting of access to certain undesired actions, resources and principals.

Impact

Overly permissive policies may grant access to sensitive resources

Follow the appropriate remediation steps below to resolve the issue.

Specify the exact permissions required, and to which resources they should apply instead of using wildcards.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
AWSTemplateFormatVersion: 2010-09-09
Description: Good example of policy
Resources:
  GoodPolicy:
    Type: 'AWS::IAM::Policy'
    Properties:
      PolicyName: CFNUsers
      PolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: Allow
            Action:
              - 's3:ListBuckets'
            Resource: 'specific-bucket'

  1. Perform the following to detach the policy that has full administrative privileges:
  2. Sign in to the AWS Management Console and open the IAM console at https://console.aws.amazon.com/iam/.
  3. In the navigation pane, click Policies and then search for the policy name found in the audit step.
  4. Select the policy that needs to be deleted.
  5. In the policy action menu, select first Detach
  6. Select all Users, Groups, Roles that have this policy attached
  7. Click Detach Policy
  8. In the policy action menu, select Detach.

Specify the exact permissions required, and to which resources they should apply instead of using wildcards.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
 resource "aws_iam_role_policy" "test_policy" {
 	name = "test_policy"
 	role = aws_iam_role.test_role.id
 
 	policy = data.aws_iam_policy_document.s3_policy.json
 }
 
 resource "aws_iam_role" "test_role" {
 	name = "test_role"
 	assume_role_policy = jsonencode({
 		Version = "2012-10-17"
 		Statement = [
 		{
 			Action = "sts:AssumeRole"
 			Effect = "Allow"
 			Sid    = ""
 			Principal = {
 			Service = "s3.amazonaws.com"
 			}
 		},
 		]
 	})
 }
 
 data "aws_iam_policy_document" "s3_policy" {
   statement {
     principals {
       type        = "AWS"
       identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"]
     }
     actions   = ["s3:GetObject"]
     resources = [aws_s3_bucket.example.arn]
   }
 }