Skip to content

Files

Latest commit

 

History

History
41 lines (32 loc) · 1.14 KB

aws-iam-block-kms-policy-wildcard.md

File metadata and controls

41 lines (32 loc) · 1.14 KB

Pattern: Use of * for AWS IAM KMS policy

Issue: -

Description

IAM policies define which actions an identity (user, group, or role) can perform on which resources. Following security best practices, AWS recommends that you allow least privilege. In other words, you should grant to identities only the kms:Decrypt or kms:ReEncryptFrom permissions and only for the keys that are required to perform a task.

Resolution: Scope down the resources of the IAM policy to specific keys.

Examples

Example of incorrect code:

data "aws_iam_policy_document" "kms_policy" {
  statement {
    principals {
      type        = "AWS"
      identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"]
    }
    actions   = ["kms:*"]
    resources = ["*"]
  }
}

Example of correct code:

data "aws_iam_policy_document" "kms_policy" {
  statement {
    principals {
      type        = "AWS"
      identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"]
    }
    actions   = ["kms:*"]
    resources = [aws_kms_key.main.arn]
  }
}