当前位置: 首页 > news >正文

aws eks 配置授权额外的用户和角色访问集群

参考资料

  • https://github.com/kubernetes-sigs/aws-iam-authenticator#full-configuration-format
  • https://docs.amazonaws.cn/zh_cn/eks/latest/userguide/add-user-role.html

众所周知,aws eks使用 Authenticator 或者 aws 命令来进行账户级别的用户和角色的授权。

kubernetes和aws服务的认证是通过控制平面的webhook来进行转换的。对于x509认证的集群,有如下对应信息

  • CN(common name):对应集群中的user
  • Organization:对应集群中的group

对于新建的eks集群,则只有创建集群的用户有权限访问集群。之后如果需要将额外的用户或角色授权访问eks集群,需要进行额外配置

需要注意

  • 如果新建的集群,并且没有节点组,则不会创建名为aws-authconfigmap

查看eksctl的相关参数,可以分别对account和arn进行配置

Usage: eksctl create iamidentitymapping [flags]IAMIdentityMapping flags:--account string        Account ID to automatically map to its username--arn string            ARN of the IAM role or user to create--username string       User name within Kubernetes to map to IAM role--group strings         Groups within Kubernetes to which IAM role is mapped--service-name string   Service name; valid value: emr-containers--namespace string      Namespace in which to create RBAC resources--no-duplicate-arns     Throw error when an aws-auth record already exists

节点角色

在configmap中有如下配置,表明只有节点实例角色才有权访问集群

  • 在创建新的节点组并指定新的节点角色时,该角色会自动写入configmap
mapRoles: |
- groups:- system:bootstrappers- system:nodesrolearn: arn:aws:iam::111122223333:role/my-node-roleusername: system:node:{{EC2PrivateDNSName}}

特定用户

可以使用eksctl配置用户加入集群,或者手动配置。这里授予admin权限,可以按需修改

eksctl create iamidentitymapping \--cluster testcluster  \--region=cn-north-1 \--arn arn:aws-cn:iam::111122223333:user/test-user \--group system:masters \--no-duplicate-arns

在configmap中有如下配置,表明对应用户能够使用集群中user和group的权限

 mapRoles: |                                                                  - groups:                                                                  - system:masters                                                         rolearn: arn:aws-cn:iam::111122223333:role/test-role  

特定角色

可以使用eksctl配置角色加入集群,或者手动配置。这里授予admin权限,可以按需修改

eksctl create iamidentitymapping \--cluster testcluster \--region=cn-north-1 \--arn arn:aws-cn:iam::111122223333:role/service-role/test-role \--group system:masters \--no-duplicate-arns

在configmap中有如下配置,表明对应角色能够使用集群中user和group的权限

mapUsers: |                                                        - groups:                                                        - system:masters                                               userarn: arn:aws-cn:iam::111122223333:user/test-user

特定账户

可以使用eksctl配置账户映射,根据会将账户级别资源映射为指定的username

  • 这里只能配置账户id,不能指定group和username字段,否则会报错Error: account cannot be configured with any other options
eksctl create iamidentitymapping \--cluster test124 \--account 442337510176 \--region=cn-north-1 \--username test

在configmap中有如下配置

mapAccounts: |     - "442337510176" 

由于该字段并未指定user和group,因此只是将该账户下的user和role映射为集群中可以识别的主体,但是并没有授予相应的权限。之后如果需要对该账户授权,需要手动创建clusterrolebinding。例如以下

# read权限
kubectl create clusterrolebinding test-account-role --clusterrole=view --user="arn:aws-cn:iam::111122223333:role/111"  --group=test-group
# 为所有鉴权主体授权admin权限
kubectl create clusterrolebinding account-admin --clusterrole=cluster-admin --group=system:authenticated

这里和前3种方式相比特殊的地方在于,这里无法通过aws命令更新kubeconfig凭证。

可以通过手动生成带profile的凭证之后,再修改到目标profile

apiVersion: v1
clusters:
- cluster:certificate-authority-data: dxxxxxxxxxxxxxxCg==server: https://C96x9B.yl4.cn-north-1.eks.amazonaws.com.cnname: arn:aws-cn:eks:cn-north-1:111122223333:cluster/test-cluster
contexts:
- context:cluster: arn:aws-cn:eks:cn-north-1:111122223333:cluster/test-clusteruser: arn:aws-cn:eks:cn-north-1:111122223333:cluster/test-clustername: arn:aws-cn:eks:cn-north-1:111122223333:cluster/test-cluster
current-context: arn:aws-cn:eks:cn-north-1:111122223333:cluster/test-cluster
kind: Config
preferences: {}
users:
- name: arn:aws-cn:eks:cn-north-1:111122223333:cluster/test-clusteruser:exec:apiVersion: client.authentication.k8s.io/v1beta1args:- --region- cn-north-1- eks- get-token- --cluster-name- test124command: awsenv:- name: AWS_PROFILEvalue: test-account
http://www.lryc.cn/news/42188.html

相关文章:

  • MagicalCoder可视化开发平台:轻松搭建业务系统,为企业创造更多价值
  • 8个不能错过的程序员必备网站,惊艳到我了!!!
  • Mybatis(二):实现“增删改查”
  • Faster RCNN 对血液细胞目标检测
  • 【数据结构】Java实现栈
  • 【数据结构】排序
  • 过拟合、验证集、交叉验证
  • 原力计划来了【协作共赢 成就未来】
  • 一文了解Jackson注解@JsonFormat及失效解决
  • webpack——使用、分析打包代码
  • libvirt零知识学习5 —— libvirt源码编译安装(3)
  • Nmap 的使用教程
  • async与await异步编程
  • 移动应用架构设计:如何转变开发流程
  • NX二次开发 图层函数总结
  • windows微服务部署
  • Java四种内部类(看这一篇就够了)
  • 蓝桥杯刷题第二十天
  • 如何通过命令行查看CentOS版本信息和linux系统信息
  • oracle查询表空间大小以及每个表所占空间的大小
  • C语言通讯录应用程序:从设计到实现
  • 银河麒麟v10sp2安装nginx
  • 华为笔试题OD
  • Win10+Anconda安装.whl文件到指定环境——以pycocotools为例
  • 全自动托盘四向穿梭车|拥有输送系统提升机AGV的托盘四向穿梭车立体库的软硬件配置系统
  • 【Linux】进程概念二
  • 如何用C语言实现渣男通讯录
  • 【从零开始的C语言】操作符详解
  • 黑马在线教育数仓实战1
  • python中pandas模块数据处理小案例