120. 如何为给定用户列出角色绑定

张开发
2026/6/12 7:34:37 15 分钟阅读
120. 如何为给定用户列出角色绑定
Situation 地理位置Need to list the roles bound for a given user需要列出给特定用户绑定的角色Resolution 结局Two options available for listing the rolebindings are to use kubectl to get the rolebindings or use a plugin such asrbac-lookup.列出角色绑定有两种选择使用 kubectl 获取绑定或者使用像rbac-lookup这样的插件。Kubectl Commands to get JSON outputKubectl 命令获取 JSON 输出Run the following where $USERID is the ID seen in the Rancher UI as u-xxxx :运行以下程序其中$USERID 是牧场主界面中显示的 ID即 u-xxxx span stylecolor:#000000span stylebackground-color:#ffffffspan stylebackground-color:#f3f3f3$ kubectl get rolebinding,clusterrolebinding --all-namespaces -o jsonpath{range .items[?(.subjects[0].name$USERID)]}[{.roleRef.kind},{.a>This should provide a list of all rolebindings associated with the $USERID in an output like the following:这应当提供与$USERID 相关的所有角色绑定列表输出如下span stylecolor:#000000span stylebackground-color:#ffffffspan stylebackground-color:#f3f3f3[Role,user-global-catalog][Role,r-cluster-local-view][Role,project-member][Role,p-qq8hd-projectmember][Role,edit][Role,project-member][ClusterRole,cattle-globalrole-user][ClusterRole,project-member-promoted][ClusterRole,p-qq8hd-namespaces-edit][ClusterRole,create-ns][ClusterRole,local-clustermember][ClusterRole,u-dlns5-view]/span/span/span3rd Party Plugin: rback-lookup第三方插件rback-lookupTherbac-lookupplugin can be installed using a plugin manager like krew.rbac-lookup插件可以使用像 krew 这样的插件管理器安装。NOTE: This pugin is not created or maintaiened by us and so is not supported. This is provided as an exampe only and your mileage may vary so use at your descretion.注意本布吉安并非由我们创建或维护因此不予支持。这只是一个例子效果可能不同建议按你的需求使用。See related sites: 参见相关网站https://github.com/FairwindsOps/rbac-lookuphttps://rbac-lookup.docs.fairwinds.com/usage/#flags-supportedhttps://github.com/kubernetes-sigs/krewhttps://krew.sigs.k8s.io/Once installed the plugin can be run to retrieve roles as seen in the following example (whereu-xis the Rancher user ID):安装后插件可以运行以获取角色如下例所示其中 u-x是 Rancher 用户 IDspan stylecolor:#000000span stylebackground-color:#ffffffspan stylebackground-color:#f3f3f3rootbox:~# kubectl rbac-lookup u-x SUBJECT SCOPE ROLE u-x cattle-global-data Role/user-global-catalog u-x c-m-zbsdgsk9 Role/p-x5msl-projectmember u-x c-m-zbsdgsk9 Role/project-member u-x p-x5msl Role/project-member u-x p-x5msl Role/edit u-x fleet-default Role/r-cluster-quickstart-do-custom-view u-x cluster-wide ClusterRole/u-3uvr4kfrim-view u-x cluster-wide ClusterRole/cattle-globalrole-user u-x cluster-wide ClusterRole/c-m-zbsdgsk9-clustermember/span/span/span访问Rancher-K8S解决方案博主企业合作伙伴 https://blog.csdn.net/lidw2009

更多文章