在 Kubernetes 中——授予列出命名空间的权限(仅)
In Kubernetes - grant permissions to list namespaces (only)
我正在尝试解决第三方工具的问题。该工具需要能够确保我告诉它工作的名称空间存在。为此,它 运行s:
kubectl get namespace my-namespace-name-here
我让第三方工具 运行 作为的用户在 my-namespace-name-here
命名空间中具有 edit
权限。 (通过 rolebinding
使用名为 edit
的 clusterrole
命名空间。)
但是编辑权限不足以允许它检查(使用该命令)命名空间是否存在。
理想情况下,我想要一种方法来授予用户权限以仅获取上面的一个命名空间。但是,如果我可以授予仅列出名称空间的权限,而在集群级别没有其他任何新内容,我会感到满意。
如何添加权限以列出命名空间?
我想通了!
我需要创建一个范围为 my-namespace-name-here
的 Role
以授予获取命名空间的能力。然后创建 rolebinding
以将该权限授予我的用户。 运行一个kubectl apply -f ./my-yaml-file-below.yaml
做到了。
这是 yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: namespace-reader
namespace: my-namespace-name-here
rules:
- apiGroups: [""]
resources: ["namespaces"]
verbs: ["get"]
---
apiVersion: "rbac.authorization.k8s.io/v1"
kind: RoleBinding
metadata:
name: my-username-here-namespace-reader
namespace: my-namespace-name-here
roleRef:
apiGroup: "rbac.authorization.k8s.io"
kind: Role
name: namespace-reader
subjects:
- apiGroup: "rbac.authorization.k8s.io"
kind: User
name: "my-username-here@mydomain.com"
这允许用户执行 kubectl get namespace
仅在授予此权限的命名空间。
我正在尝试解决第三方工具的问题。该工具需要能够确保我告诉它工作的名称空间存在。为此,它 运行s:
kubectl get namespace my-namespace-name-here
我让第三方工具 运行 作为的用户在 my-namespace-name-here
命名空间中具有 edit
权限。 (通过 rolebinding
使用名为 edit
的 clusterrole
命名空间。)
但是编辑权限不足以允许它检查(使用该命令)命名空间是否存在。
理想情况下,我想要一种方法来授予用户权限以仅获取上面的一个命名空间。但是,如果我可以授予仅列出名称空间的权限,而在集群级别没有其他任何新内容,我会感到满意。
如何添加权限以列出命名空间?
我想通了!
我需要创建一个范围为 my-namespace-name-here
的 Role
以授予获取命名空间的能力。然后创建 rolebinding
以将该权限授予我的用户。 运行一个kubectl apply -f ./my-yaml-file-below.yaml
做到了。
这是 yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: namespace-reader
namespace: my-namespace-name-here
rules:
- apiGroups: [""]
resources: ["namespaces"]
verbs: ["get"]
---
apiVersion: "rbac.authorization.k8s.io/v1"
kind: RoleBinding
metadata:
name: my-username-here-namespace-reader
namespace: my-namespace-name-here
roleRef:
apiGroup: "rbac.authorization.k8s.io"
kind: Role
name: namespace-reader
subjects:
- apiGroup: "rbac.authorization.k8s.io"
kind: User
name: "my-username-here@mydomain.com"
这允许用户执行 kubectl get namespace
仅在授予此权限的命名空间。