gpt4 book ai didi

amazon-web-services - 库伯内斯 RBAC : can't get cronjob even though user seems to have the needed permissons

转载 作者:行者123 更新时间:2023-12-02 11:46:42 27 4
gpt4 key购买 nike

问候各位修补匠!

我的问题是什么?

简而言之,用户 toto 不能“获得”一个 cronjob,即使权限看起来不错。更准确地说:

$> kubectl get cronjob/test -n my_namespace
Error from server (Forbidden): cronjobs.batch "test" is forbidden: User "toto" cannot get resource "cronjobs" in API group "batch" in the namespace "my_namespace"
$> kubectl auth can-i get cronjob/test -n my_namespace
no

甚至艰难:

$> kubectl auth can-i get cronjobs -n my_namespace
yes
$> kubectl auth can-i --list -n my_namespace
Resources Non-Resource URLs Resource Names Verbs
...
cronjobs.batch [] [] [get list watch list watch get]
...
$> kubectl get cronjobs -n my_namespace
NAME SCHEDULE ... AGE
test */5 * * * * 2d21h

另请注意,当由管理员级别的用户(来自组 system:masters)执行时,或者如果我将 toto 添加到组 system:masters 时,该命令工作正常。

我尝试了什么?

我添加了对所有命名空间中所有资源的完全权限,添加到 toto 所属的组(我们称它为 my_group)。事实上它甚至没有工作,这让我认为我的问题可能不是由权限引起的,而是由另一种 k8s 机制引起的。

附加信息

根据要求,这里有一些额外的信息:

$> kubectl version
Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.2", GitCommit:"c97fe5036ef3df2967d086711e6c0c405941e14b", GitTreeState:"clean", BuildDate:"2019-10-15T23:41:55Z", GoVersion:"go1.12.10", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"14+", GitVersion:"v1.14.9-eks-c0eccc", GitCommit:"c0eccca51d7500bb03b2f163dd8d534ffeb2f7a2", GitTreeState:"clean", BuildDate:"2019-12-22T23:14:11Z", GoVersion:"go1.12.12", Compiler:"gc", Platform:"linux/amd64"}

集群使用 EKS 服务托管在 AWS 上,因此:

  • 上下文使用 aws-iam-authenticator 二进制文件对用户进行动态身份验证
  • 如 EKS 文档所述,我们将用户添加到 aws-auth ConfigMap 中的组
  • 然后我们定义一些 clusterroles + rolebindings,针对上述那些群体。

对于后两点,转换为以下 yaml 文件:

---
apiVersion: v1
kind: ConfigMap
metadata:
name: aws-auth
namespace: kube-system
data:
...
mapUsers: |
...
- userarn: arn:aws:iam::xxxxxxxxxxxx:user/toto
username: toto
groups:
- system:basic-user
- my_group
...

---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: my_role
rules:
...
- apiGroups: ["batch"]
resources: ["cronjobs"]
resourceNames: [""]
verbs: ["list", "watch", "get"]
...
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: my_rolebinding
namespace: my_namespace
subjects:
- kind: Group
name: my_group
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: ClusterRole
name: my_role
apiGroup: rbac.authorization.k8s.io

最佳答案

如果我没记错的话,API 组是 batch,资源是 cronjobs 而不是 cronjobs.batch

Kubernetes cluster-roles.yaml和 Kubernetes API 的文档 cronjob .

yaml 角色应该如下所示:

kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
namespace: my_namespace
name: toto
rules:
- apiGroups: ["", "batch"]
resources: ["cronjobs"]
verbs: ["get", "list", "watch", "list", "watch"]

关于amazon-web-services - 库伯内斯 RBAC : can't get cronjob even though user seems to have the needed permissons,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60094996/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com