Kubernetes RBAC:即使用户似乎具有所需的权限也无法获得cronjob

问题描述 投票:2回答:2

问候修补匠!

我的问题是什么?

简而言之,即使权限看起来不错,用户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中的组中>
  • 然后,我们定义了一些针对上述人群的集群+角色绑定。
  • 对于后两点,将转换为以下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

问候修补匠!我的问题是什么?简而言之,即使权限看起来很好,用户toto也无法“获得” cronjob。更精确地说:$> kubectl get cronjob / test -n my_namespace ...

amazon-web-services kubernetes rbac
2个回答
0
投票

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


0
投票

确定。知道了问题是参数resourceNames。当指定此参数时,还需要指定您所指的特定资源名称。

© www.soinside.com 2019 - 2024. All rights reserved.