我设置了一个角色为"view"的协作者帐户。我现在想授予此用户使用oc tag
标记图像的能力。
按照这些说明,我有:
oc get clusterrole view -o yaml > role_edittags.yaml
# 1. Update kind: ClusterRole to kind: Role
# 2. Update name: view to name: edittags
# 3. Remove resourceVersion, selfLink, uid, and creationTimestamp
# 4. split up the section with {imagestreamimages,imagestreammappings,imagestreams,imagestreamtags} into two sections:
- apiGroups:
- image.openshift.io
- ""
attributeRestrictions: null
resources:
- imagestreamimages
- imagestreammappings
- imagestreams
verbs:
- get
- list
- watch
- apiGroups:
- image.openshift.io
- ""
attributeRestrictions: null
resources:
- imagestreamtags
verbs:
- get
- list
- watch
- create
- update
- patch
- deletecollection
然后,我oc project
到要授予角色的项目,并使用以下命令导入它:
$ oc create -f role_edittags.yaml
role "edittags" created
当我尝试将其授予用户时,出现错误:
$ oc policy add-role-to-user edittags myuser
Error from server (NotFound): rolebindings.authorization.openshift.io "edittags" not found
如何向用户授予oc tag
权限?
谢谢!
更新:
我发现registry-editor
上面链接的"示例 1"中列出了一个预先存在的角色来完成这项工作:
$ oc policy add-role-to-user registry-editor myuser
role "registry-editor" added: "myuser"
我仍然很好奇,如果没有现成的角色,我该如何创建自定义角色。再次感谢!
请参阅 OpenShift 文档 如何创建本地角色。
具体而言,要将用户绑定到本地角色,您需要指定oc policy add-role-to-user
命令的--role-namespace
。
在 openshift 的 Helm 模板中有一个很好的例子,它授予对配置映射的写入访问权限。所有默认角色都以oc describe clusterPolicy default
显示,这是一个很好的起点,编写类似于现有角色的新角色。就我而言,现有的角色registry-editor
是我需要通过标记映像并从 RedHat 容器目录中提取上游补丁来自动化促销。
更新:
下面介绍如何创建可以启动 openshift 构建的本地角色:
oc create role buildinstantiate --verb=create --resource=buildconfigs.build.openshift.io/instantiate -n hubot
oc adm policy add-role-to-user buildinstantiate myuser --role-namespace=hubot -n hubot