如何解决Kubernetes角色应授予对所有资源的访问权限,但它会忽略某些资源
角色namespace-limited
应该具有对名称空间内(指定API组的)所有资源的完全访问权限。我的角色清单如下所示:
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: namespace-limited
namespace: restricted-xample
rules:
- apiGroups:
- core
- apps
- batch
- networking.k8s.io
resources: ["*"] # asterisk to grant access to all resources of the specified api groups
verbs: ["*"]
我使用RoleBinding将角色与ServiceAccount关联,但是不幸的是,该ServiceAccount无法访问Pod
,Service
,Secret
,ConfigMap
和Endpoint
资源。这些资源都是core
API组的一部分。所有其他常见工作负载都可以工作。为什么呢?
解决方法
核心组(也称为旧版组)位于REST路径/api/v1
上,并使用apiVersion: v1
您需要将""
用于核心API组。
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: restricted-xample
name: namespace-limited
rules:
- apiGroups: ["","apps","batch","networking.k8s.io"] # "" indicates the core API group
resources: ["*"]
verbs: ["*"]
要测试服务帐户的权限,请使用以下命令
kubectl auth can-i get pods --as=system:serviceaccount:restricted-xample:default -n restricted-xample
kubectl auth can-i get secrets --as=system:serviceaccount:restricted-xample:default -n restricted-xample
kubectl auth can-i get configmaps --as=system:serviceaccount:restricted-xample:default -n restricted-xample
kubectl auth can-i get endpoints --as=system:serviceaccount:restricted-xample:default -n restricted-xample
,
只需弄清楚,当我省略core关键字时,它就可以工作,例如this示例中。以下角色清单起作用:
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: namespace-limited
namespace: restricted-xample
rules:
- apiGroups: ["","networking.k8s.io"]
resources: ["*"]
verbs: ["*"]
但是,如果我指定core
API组为何不起作用,这对我来说还是个谜。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。