kubernetes 使用IAM角色从EC2示例使用kubectl访问EKS

yqkkidmi  于 2022-12-22  发布在  Kubernetes
关注(0)|答案(1)|浏览(155)

我正在尝试在EC2示例中配置kubectl,该示例具有附加的IAM角色,但没有附加到AWS cli的凭据。我已编辑了kubectl的配置Map,并添加了以下规则以包括假定角色。

- rolearn: arn:aws:sts::<account-id>:assumed-role/EC2WorkstationRole/<ec2-instanceid>
      username: system:node:{{EC2PrivateDNSName}}
      groups:
        - system:masters
    

I get the below error on running kubectl get pods:

An error occurred (AccessDenied) when calling the AssumeRole operation: User: 
arn:aws:sts::<account-id>:assumed-role/EC2WorkstationRole/<ec2-instanceid> is not 
authorized to perform: sts:AssumeRole on resource: 
arn:aws:sts::<account-id>:assumed-role/EC2WorkstationRole/<ec2-instanceid>
dfddblmv

dfddblmv1#

我认为您只需要修复aws-auth配置Map,使其允许IAM角色本质上是一个管理员,它应该如下所示:

- rolearn: arn:aws:iam::${accountid}:role/EC2WorkstationRole
  username: EC2WorkstationRole
  groups:
    - system:masters

此外,请确保附加到IAM角色的信任策略具有sts:AssumeRole权限。

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": { "Service": "ec2.amazonaws.com"},
      "Action": "sts:AssumeRole"
    }
  ]
}

相关问题