k8s RBAC 多租户权限控制实现

本文探讨了两种Kubernetes(RBAC)实现多租户权限控制的方案:方案1利用role和roleBinding,方案2则采用clusterRole与roleBinding的组合,其中推荐使用方案2进行集群级别的权限管理。
摘要由CSDN通过智能技术生成
更多kubernetes文章: k8s专栏目录

访问到权限分两部分

1.Authenticating认证
授权配置由kube-apiserver管理

这里使用的是 Static Password File 方式。
apiserver启动yaml里配置basic-auth-file即可,容器启动apiserver的话要注意这个文件需要是在容器内能访问到的。(可以通过挂载文件,或者在已经挂载的路径里增加配置文件)
basic-auth-file文件格式见官方文档 https://kubernetes.io/docs/admin/authentication/#static-password-file 注意password在第一个,之前没注意被卡了很久。
修改了文件以后需要重启apiserver才能生效。这里kubectl delete 删除pod有问题,使用docker命令查看apiserver容器其实没有重启。解决方案是使用docker kill杀掉容器。自动重启。

[root@tensorflow1 ~]# curl -u admin:admin "https://localhost:6443/api/v1/pods" -k
{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {
    
  },
  "status": "Failure",
  "message": "pods is forbidden: User \"system:anonymous\" cannot list pods at the cluster scope",
  "reason": "Forbidden",
  "details": {
    "kind": "pods"
  },
  "code": 403
}
这个就是没有通过认证的报错


2.Authorization授权

k8s RBAC授权规则

简单来说就是 权限--角色--用户绑定
需要配置两个文件 
一个是role/clusterRole,定义角色以及其权限
一个是roleBinding/clusterRoleBinding,定义用户和角色的关系

{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {
    
  },
  "status": "Failure",
  "message": "pods is forbidden: User \"admin\" cannot list pods at the cluster scope",
  "reason": "Forbidden",
  "details": {
    "kind": "pods"
  },
  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值