Kubernetes Role 应该授予对所有资源的访问权限,但它忽略了一些资源
Kubernetes Role should grant access to all resources but it ignores some resources
角色 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 将 Role 关联到 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: ["", "apps", "batch", "networking.k8s.io"]
resources: ["*"]
verbs: ["*"]
但是为什么我指定 core
API 组它不起作用对我来说是个谜。
角色 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 将 Role 关联到 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: ["", "apps", "batch", "networking.k8s.io"]
resources: ["*"]
verbs: ["*"]
但是为什么我指定 core
API 组它不起作用对我来说是个谜。