CloudWatch Logs destination policy grants excessive access

Allow only the senders and actions needed for log subscriptions.

Description

Review who can attach a subscription filter to your CloudWatch Logs destination. Check the principals, allowed actions and policy conditions together.

Potential impact

An unapproved sender can introduce unwanted logs and increase processing costs if it can attach a subscription.

Remediation

Limit the policy to approved sender accounts or your organization. Grant only logs:PutSubscriptionFilter on the destination ARN. Attach the policy to the destination and verify that logs arrive from the approved sender’s subscription. Manage access to read stored logs separately.

Examples

The first policy allows logs:* for the current account. The second names the sender and a single action. Replace 123456789012 with the intended sender’s account ID.

Before

hcl
data "aws_iam_policy_document" "example" {
  statement {
    effect = "Allow"

    principals {
      type = "AWS"
      identifiers = [data.aws_caller_identity.current.id]
    }

    actions = [
      "logs:*",
    ]

    resources = [
      aws_cloudwatch_log_destination.test_destination.arn,
    ]
  }
}

After

hcl
data "aws_iam_policy_document" "example" {
  statement {
    effect = "Allow"

    principals {
      type = "AWS"
      identifiers = [
        "123456789012",
      ]
    }

    actions = [
      "logs:PutSubscriptionFilter",
    ]

    resources = [
      aws_cloudwatch_log_destination.test_destination.arn,
    ]
  }
}

References