EKS worker 可以承担先前存在的 IAM 角色吗?
Can EKS workers assume preexisting IAM role?
我们 运行 一个 EKS 集群,它是根据以编程方式构建的 Cloudformation 模板构建的。目前工作人员模板接近 https://github.com/awslabs/amazon-eks-ami/blob/master/amazon-eks-nodegroup.yaml,但我们的 Resources.NodeInstanceRole.ManagedPolicyArns 有一些额外的用户制定的政策。
我们不想将托管策略添加到此列表,而是想创建一个附加任何策略的 IAM 角色,然后让 EKS 工作人员担任此角色。问题是我们无法在 Cloudformation 模板中找到执行此操作的方法。
我认为模板的相关部分如下:
NodeInstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Path: "/"
Roles:
- !Ref NodeInstanceRole
NodeInstanceRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service: ec2.amazonaws.com
Action: sts:AssumeRole
Path: "/"
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy
- arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy
- arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly
我想应该有一种方法可以在 NodeInstanceProfile 中引用现有角色的 ARN,而不是构建一个新的 IAM::Role (NodeInstanceRole)。尝试以下列方式更改 NodeInstanceProfile 会导致以下错误:
NodeInstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Path: "/"
Roles:
- "arn:aws:iam::xxx:role/yyy"
The specified value for roleName is invalid. It must contain only alphanumeric characters and/or the following: +=,.@_- (Service: AmazonIdentityManagement; Status Code: 400; Error Code: ValidationError; Request ID: xxx)
事实证明,解决方案非常简单:NodeInstanceProfile 需要角色名称,而不是 ARN。所以在 Cloudformation 模板的最终版本中,我引用的代码块被缩减为:
NodeInstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Path: "/"
Roles:
- yyy
我们 运行 一个 EKS 集群,它是根据以编程方式构建的 Cloudformation 模板构建的。目前工作人员模板接近 https://github.com/awslabs/amazon-eks-ami/blob/master/amazon-eks-nodegroup.yaml,但我们的 Resources.NodeInstanceRole.ManagedPolicyArns 有一些额外的用户制定的政策。
我们不想将托管策略添加到此列表,而是想创建一个附加任何策略的 IAM 角色,然后让 EKS 工作人员担任此角色。问题是我们无法在 Cloudformation 模板中找到执行此操作的方法。
我认为模板的相关部分如下:
NodeInstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Path: "/"
Roles:
- !Ref NodeInstanceRole
NodeInstanceRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service: ec2.amazonaws.com
Action: sts:AssumeRole
Path: "/"
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy
- arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy
- arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly
我想应该有一种方法可以在 NodeInstanceProfile 中引用现有角色的 ARN,而不是构建一个新的 IAM::Role (NodeInstanceRole)。尝试以下列方式更改 NodeInstanceProfile 会导致以下错误:
NodeInstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Path: "/"
Roles:
- "arn:aws:iam::xxx:role/yyy"
The specified value for roleName is invalid. It must contain only alphanumeric characters and/or the following: +=,.@_- (Service: AmazonIdentityManagement; Status Code: 400; Error Code: ValidationError; Request ID: xxx)
事实证明,解决方案非常简单:NodeInstanceProfile 需要角色名称,而不是 ARN。所以在 Cloudformation 模板的最终版本中,我引用的代码块被缩减为:
NodeInstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Path: "/"
Roles:
- yyy