【问题标题】:IAM Policy with action: autoscaling:AttachLoadBalancerTargetGroups, Filters access based on the ARN of a target group is not working具有操作的 IAM 策略:自动缩放:AttachLoadBalancerTargetGroups,基于目标组的 ARN 过滤访问不起作用
【发布时间】:2022-01-23 00:32:18
【问题描述】:

我们有一个包含 2 个目标组的自动扩缩组。我们希望允许团队分离/附加这些目标组之一,并防止他们分离/附加另一个目标组。所以我们构建了这个 IAM 政策声明:

{
        "Sid": "AsgPolicy",
        "Effect": "Allow",
        "Action": [
            "autoscaling:AttachLoadBalancerTargetGroups",
            "autoscaling:DetachLoadBalancerTargetGroups"
        ],
        "Resource": "arn:aws:autoscaling:*:${account}:autoScalingGroup:*:autoScalingGroupName/app-${env}-frontend",
        "Condition": {
            "StringLike": {
                "autoscaling:TargetGroupARNs": "arn:aws:elasticloadbalancing:*:${account}:targetgroup/app-${env}-target/*"
            }
        }
    }

即使一切看起来都正确,但每当我使用具有此策略的角色来分离/附加目标组时,我都会收到此错误:

Detaching target groups failed
User: arn:aws:sts::11111111111:assumed-role/role-name/username is not authorized to perform: autoscaling:DetachLoadBalancerTargetGroups on resource: arn:aws:autoscaling:eu-west-1:11111111111:autoScalingGroup:ad6d28fa-b472-44e9-9ec4-e39bab5cd364:autoScalingGroupName/app-dev-frontend because no identity-based policy allows the autoscaling:DetachLoadBalancerTargetGroups action

我不明白问题出在哪里。 条件很重要,因为应该只更新一个目标,而不是另一个目标。

谢谢

【问题讨论】:

    标签: json amazon-web-services aws-auto-scaling


    【解决方案1】:

    为了使权限声明正常工作,指定的“资源”资源类型应由“操作”下列出的操作支持。并非每个操作都可以指定每种资源类型。如果您指定的资源对该操作无效,则使用该操作的任何请求都会失败,并且该语句的效果不适用。

    在您的情况下,操作“autoscaling:AttachLoadBalancerTargetGroups”和“autoscaling:DetachLoadBalancerTargetGroups”不支持资源级权限(在Actions Table 的“资源类型”列下的操作表中显示为空白)并且您必须指定所有政策中的资源(“*”)。

    你可以试试这个政策:

    {
        "Sid": "AsgPolicy",
        "Effect": "Allow",
        "Action": [
            "autoscaling:AttachLoadBalancerTargetGroups",
            "autoscaling:DetachLoadBalancerTargetGroups"
        ],
        "Resource": "*",
        "Condition": {
            "StringLike": {
                "autoscaling:TargetGroupARNs": "arn:aws:elasticloadbalancing:*:${account}:targetgroup/app-${env}-target/*"
            }
        }
    }
    

    【讨论】:

    • 刚刚试过了,还是不行:(谢谢
    【解决方案2】:

    这是这个问题的解决方案,效果很好:

    {
        "Sid": "AsgDetach",
        "Effect": "Allow",
        "Action": [
            "autoscaling:AttachLoadBalancerTargetGroups",
            "autoscaling:DetachLoadBalancerTargetGroups"
        ],
        "Resource": "*",
        "Condition": {
            "ForAnyValue:StringLike": {
                "autoscaling:TargetGroupARNs": "arn:aws:elasticloadbalancing:*:*xxx"
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2020-07-21
      • 2013-04-05
      • 1970-01-01
      • 2021-09-03
      • 1970-01-01
      • 2019-07-07
      • 2023-03-16
      • 2014-07-05
      • 2016-01-17
      相关资源
      最近更新 更多