【问题标题】:List of Kubernetes RBAC rule verbsKubernetes RBAC 规则动词列表
【发布时间】:2019-12-30 20:33:47
【问题描述】:

我想为我的应用程序提供有限的访问权限,以获取不同状态集(可能还有部署)的副本,并在必要时扩大或缩小它们。

我为此创建了 ServiceAccount、Rolebinding 和 Role,但我找不到规则动词(“get”、“watch”、“list”、“update”)的完整列表以及它们的限制,例如我可以使用update 进行缩放还是需要另一个动词?我在哪里可以找到描述这些动词的列表或表格?

我的 yaml 文件:

kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: scaler-role
  namespace: {{ .Release.Namespace  | quote }}
rules:
- apiGroups: ["apps"]
  resources: ["statefulset"]
  verbs: ["get", "watch", "list", "update"]

【问题讨论】:

    标签: kubernetes service-accounts rbac


    【解决方案1】:

    Here 是 RBAC 动词列表:

    对于扩展,我认为您需要写入权限(createupdatepatch)以及读取权限(getlistwatch)。

    【讨论】:

    • 感谢您的回答,但奇怪的是没有实际的表格清楚详细地描述所有这些动词。
    【解决方案2】:

    最好的办法是

    kubectl api-resources --sort-by name -o wide
    

    上面的api-resources 命令是明确的并且易于grep。可以这样获得可能的动词的完整列表:

    $ kubectl api-resources --no-headers --sort-by name -o wide | sed 's/.*\[//g' | tr -d "]" | tr " " "\n" | sort | uniq
    create
    delete
    deletecollection
    get
    list
    patch
    update
    watch
    

    API 参考文档(例如 https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/)的 Resource Operations 部分谈到了它们,但没有提到 deletecollection(顺便说一句:请参阅 interesting info about deletecollection;建议无论何时您给delete,如果资源支持,你也应该给deletecollection权限。

    Authorization OverviewDetermine the Request Verb 部分确实简要提到了deletecollection,以及六个更多的动词(例如@RoryMcCune 正确指出的escalate),不幸的是,这些动词没有出现在kubectl api-resources -o wide 命令的输出中。

    顺便说一句,api-resources 命令还列出了命令的短名称,例如 svc 代表 services

    【讨论】:

    • 值得注意的是,该命令似乎无法捕获仅在某些 API 中有效的动词(例如 RBAC 中的升级动词)
    • @RoryMcCune 感谢您指出我扩展了答案
    【解决方案3】:

    动词列表可以在这里找到https://kubernetes.io/docs/reference/access-authn-authz/authorization/#review-your-request-attributes

    可以在这里找到简要说明https://kubernetes.io/docs/reference/access-authn-authz/authorization/#determine-the-request-verb

    我有一个角色,用于更新部署的 docker 映像标签,看起来像这样(我不使用我的来创建部署,只是修补映像标签)

    kind: ClusterRole
    apiVersion: rbac.authorization.k8s.io/v1beta1
    metadata:
      name: deployer
    rules:
    - apiGroups: ["apps"]
      resources: ["deployments"]
      verbs: ["get", "patch"]
    
    

    【讨论】:

      【解决方案4】:

      在 Linux/Mac/WSL/等上。

      1. 运行:kubectl 代理 &
      2. 运行:curl http://127.0.0.1:8001 -k | grep -v '路径' | grep '"' | sed -e 's/"//g' -e 's/,//g' |排序 |而读线;做 kubectl get --raw ${line} ;完成 | jq |少
      3. 在less中搜索你需要的api来查看动词。

      【讨论】:

      • 为什么要对 HTTP(非 SSL)请求执行“curl -k”?我建议使用“curl -s”,以避免 curl 打印的额外消息。
      猜你喜欢
      • 2019-11-11
      • 1970-01-01
      • 2020-01-23
      • 2019-11-24
      • 1970-01-01
      • 2016-06-09
      • 1970-01-01
      • 2021-09-30
      • 2019-04-07
      相关资源
      最近更新 更多