【问题标题】:AWS EKS "is not authorized to perform: iam:CreateServiceLinkedRole"AWS EKS“无权执行:iam:CreateServiceLinkedRole”
【发布时间】:2020-08-19 04:00:00
【问题描述】:

我遵循了启动 EKS 集群的文档,该集群说要使用某些策略创建服务角色。

https://docs.aws.amazon.com/eks/latest/userguide/eks-ug.pdf

To create your Amazon EKS service role
1. Open the IAM console at https://console.aws.amazon.com/iam/.
2. Choose Roles, then Create role.
3. Choose EKS from the list of services, then Allows Amazon EKS to manage your clusters on your behalf for your use case, then Next: Permissions.
4. Choose Next: Review.
5. For Role name, enter a unique name for your role, such as eksServiceRole, then choose Create role.

当我创建一个基本的 hello world 应用程序时,它会引发 AccessDenied 错误。

Error creating load balancer (will retry): failed to ensure load balancer for service default/nginx:
AccessDenied: User: arn:aws:sts::*************:assumed-role/eks-service-role/************* is not authorized to perform: iam:CreateServiceLinkedRole on resource: arn:aws:iam::*************:role/aws-service-role/elasticloadbalancing.amazonaws.com/AWSServiceRoleForElasticLoadBalancing

添加的两个策略(AmazonEKSClusterPolicy、AmazonEKSServicePolicy)不允许执行 iam:CreateServiceLinkedRole 操作。我们是否应该将其添加到指南中定义的策略之外?或者这是否应该包含在 EKS 政策中?

【问题讨论】:

  • 您是否偶然尝试使用负载均衡器类型的入口?

标签: amazon-web-services kubernetes kubectl amazon-eks


【解决方案1】:

似乎 EKS 用户指南假定您在创建 EKS 集群之前在您的 AWS 账户中创建了负载均衡器,因此在 AWS IAM 中具有现有的 AWSServiceRoleForElasticLoadBalancing 服务角色。

https://docs.aws.amazon.com/elasticloadbalancing/latest/userguide/elb-service-linked-roles.html#create-service-linked-role中所述

You don't need to manually create the AWSServiceRoleForElasticLoadBalancing role. Elastic Load Balancing creates this role for you when you create a load balancer.

EKS 正在尝试为您执行此操作,导致使用默认策略的访问被拒绝异常。

在创建 EKS 集群之前显式创建服务相关角色的其他选项包括:

AWS CLI

aws iam create-service-linked-role --aws-service-name "elasticloadbalancing.amazonaws.com"

地形

resource "aws_iam_service_linked_role" "elasticloadbalancing" {
  aws_service_name = "elasticloadbalancing.amazonaws.com"
}

或者,从 UI 控制台手动创建负载平衡器。

无论预置选项如何,当您在 AWS IAM 中看到以下角色时,您应该知道一切都会起作用

arn:aws:iam::<ACCOUNT_ID>:role/aws-service-role/elasticloadbalancing.amazonaws.com/AWSServiceRoleForElasticLoadBalancing

【讨论】:

【解决方案2】:

我通过将此策略添加到 EKS 角色来实现它:

    {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Effect": "Allow",
                "Action": "iam:CreateServiceLinkedRole",
                "Resource": "arn:aws:iam::*:role/aws-service-role/*"
            },
            {
                "Effect": "Allow",
                "Action": [
                    "ec2:DescribeAccountAttributes"
                ],
                "Resource": "*"
            }
        ]
    }

【讨论】:

  • 我将此添加为内联策略,并且不再出现错误。我想知道这是否应该包含在用户指南中定义的 EKS 政策中。
  • 我将此策略直接添加到由 EKS terraform 模块 (github.com/terraform-aws-modules/terraform-aws-eks) 生成的 EKS 角色中
猜你喜欢
  • 2015-02-16
  • 1970-01-01
  • 2019-09-24
  • 2022-01-11
  • 2021-12-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-12-18
相关资源
最近更新 更多