只允许使用Kubernetes RBAC列出资源



我只允许列出资源,而不允许清单内容。

示例,

NAME                                 READY   STATUS    RESTARTS   AGE
airflow-redis-0                      1/1     Running   0          32h
airflow-postgresql-0                 1/1     Running   0          32h
airflow-scheduler-9416ddfd6f-n7jcr   2/2     Running   0          32h
airflow-webserver-9bf7f3c95c-kf1fx   1/1     Running   0          32h
airflow-worker-0                     2/2     Running   0          4h8m

有了GET权限,用户可以单独查看pod的清单。例如,kubectl describe pod airflow-worker-0 -n airflow

类似地,使用LIST权限,用户可以使用-kubectl get pod --output=json等命令查看所有pod的清单

是否可以限制清单访问,只允许在K8 RBAC中列出资源?

使用任何RBAC请求谓词都不可能只显示资源列表而不显示对象内容。

list不能使用。它提供了列表,但也允许访问完整的对象内容。

如果您想限制用户只能列出资源,您应该使用get谓词创建一个角色
官方文件中的角色示例很好地展示了

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: default
name: pod-reader
rules:
- apiGroups: [""] # "" indicates the core API group
resources: ["pods"]
verbs: ["get", "watch", "list"]

因此,限制为例如仅get pods-将verbs更改为

verbs: ["get"]

如果您还想允许列出,例如部署-将resources更改为

resources: ["pods", "deployments"]

正如您已经注意到的,list允许完整的对象内容。