【问题标题】:Unable to perform config:PutEvaluations due to the lack of permissions on the role由于缺少角色权限,无法执行 config:PutEvaluations
【发布时间】:2021-03-06 08:15:58
【问题描述】:

您好,我正在尝试在 Terraform 中添加 AWS Config。我已经像这样设置了以下策略附件:

resource aws_iam_policy policy {
    name = "test-policy"
    policy = <<POLICY
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": [
        "config:PutEvaluations",
        "config:PutConfigRule",
        "config:DeleteConfigRule",
        "config:GetComplianceDetailsByConfigRule",
        "config:DescribeConfigRuleEvaluationStatus"
      ],
      "Effect": "Allow",
      "Resource": [
        "arn:aws:config:*:*:config-rule/aws-service-rule/*securityhub*"
      ]
    }
  ]
}
POLICY
}

我已验证 AWS 中的策略与上述策略附件相匹配。但是,当我在控制台中访问 AWS Config 服务时,我的每个配置规则都会出现以下错误:

Unable to perform config:PutEvaluations due to the lack of permissions on the role.

我在这个问题上没有找到任何好的资源。我一直在四处搜寻,但什么都没有出现。我只看到这篇文章:https://aws.amazon.com/premiumsupport/knowledge-center/config-error-security-hub/。对此问题的任何帮助将不胜感激。作为参考,我将策略附加到 IAM 角色,如下所示:

resource aws_iam_role_policy_attachment "test-attach" {
    role = aws_iam_role.config.name
    policy_arn = aws_iam_policy.policy.arn
}

resource aws_iam_role config {
  name = "myconfig"

  assume_role_policy = <<POLICY
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": "sts:AssumeRole",
      "Principal": {
        "Service": "config.amazonaws.com"
      },
      "Effect": "Allow",
      "Sid": ""
    }
  ]
}
POLICY
}

【问题讨论】:

  • config:PutEvaluations 不能被资源限制。有关更多信息,请参阅docs.aws.amazon.com/service-authorization/latest/reference/…。您需要将您的语句一分为二,其中一个不受资源限制的语句至少具有该操作,然后在一个可以适当限制的语句中的其他操作。
  • 你能举个例子吗?

标签: amazon-web-services terraform amazon-iam terraform-provider-aws aws-config


【解决方案1】:

config:PutEvaluations 不幸的是不能被资源限制。请参阅the AWS user guide on IAM permissions 了解更多信息。该指南提到以下内容:

资源类型列指示每个操作是否支持资源级权限。如果此列没有值,则必须在策略声明的 Resource 元素中指定所有资源 ("*")。如果该列包含资源类型,则您可以在具有该操作的语句中指定该类型的 ARN。所需资源在表中标有星号 (*)。如果您在使用此操作的语句中指定资源级权限 ARN,则它必须属于此类型。一些操作支持多种资源类型。如果资源类型是可选的(未指明为必填),那么您可以选择使用其中一种而不使用另一种。

但在撰写本文时,PutEvaluations 操作在 Resource types 列中没有条目。

正如上面引用中提到的,您需要将您的语句一分为二,其中一个不受资源限制的语句至少具有该操作,然后在一个可以适当限制的语句中的其他操作。

以下应该有效:

resource "aws_iam_policy" "policy" {
    name = "test-policy"
    policy = <<POLICY
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": [
        "config:PutEvaluations"
      ],
      "Effect": "Allow",
      "Resource": [
        "*"
      ]
    },
    {
      "Action": [
        "config:PutConfigRule",
        "config:DeleteConfigRule",
        "config:GetComplianceDetailsByConfigRule",
        "config:DescribeConfigRuleEvaluationStatus"
      ],
      "Effect": "Allow",
      "Resource": [
        "arn:aws:config:*:*:config-rule/aws-service-rule/*securityhub*"
      ]
    }
  ]
}
POLICY
}

【讨论】:

  • 我已经回答了这个问题。请删除此回复,因为它没有回答问题。
  • 您是说使用上述策略仍然会出现同样的错误吗?我希望该特定错误会消失,但以后可能会出现其他 IAM 问题。您的自我回答使用了更广泛的 IAM 策略,当您使用 AWS 服务而不是用户指定但不适合所有用户的东西时,这通常很好。
  • 是的,错误是:由于缺少角色权限,无法执行 config:PutEvaluations。
【解决方案2】:

我能够解决我自己的问题

resource aws_iam_role_policy_attachment "test-attach" {
    role = aws_iam_role.config.name
    policy_arn = "arn:aws:iam::aws:policy/service-role/AWSConfigRole"
}

我使用了本文档https://docs.aws.amazon.com/config/latest/developerguide/iamrole-permissions.html

IAM Role Policy for Getting Configuration Details中列出的策略

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多