Kubernetes检查serviceaccount的权限

识趣 发表于: 2021-12-27   最后更新时间: 2021-12-27 22:12:28   1,160 游览

当通过Helm Chart部署服务时,由于tiller服务账户不允许创建ServiceMonitor资源,安装失败。

注意:

  • ServiceMonitor是Prometheus Operator定义的CRD,用于自动获取Pod中运行容器的指标。

  • Helm Tiller安装在一个命名空间中,RBAC已经使用Role和RoleBinding进行了设置。

我想验证tiller服务账户的权限。

kubectlauth can-i命令,像这样的查询(见下文)总是返回no

  • kubectl auth can-i list deployment --as=tiller
  • kubectl auth can-i list deployment --as=staging:tiller

检查serviceaccount的权限的正确方法是什么?

如何启用tiller账户来创建ServiceMonitor?

发表于 2021-12-27

正确的命令是:

kubectl auth can-i <verb> <resource> --as=system:serviceaccount:<namespace>:<serviceaccountname> [-n <namespace>]

检查 "tiller"账户是否有权利创建"ServiceMonitor"对象。

kubectl auth can-i create servicemonitor --as=system:serviceaccount:staging:tiller -n staging

注意:为了解决tiller账户问题,我不得不在monitoring.coreos.com apiGroup中为servicemonitors资源增加权限。修改之后,上述命令返回 yes(最终),我们的Helm Chart安装成功了。

更新tiller-manager角色:

kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: tiller-manager
  labels:
    org: ipos
    app: tiller
  annotations:
    description: "Role to give Tiller appropriate access in namespace"
    ref: "https://docs.helm.sh/using_helm/#example-deploy-tiller-in-a-namespace-restricted-to-deploying-resources-only-in-that-namespace"
rules:
- apiGroups: ["", "batch", "extensions", "apps"]
  resources: ["*"]
  verbs: ["*"]
- apiGroups:
    - monitoring.coreos.com
  resources:
    - servicemonitors
  verbs:
    - '*'
你的答案

查看kubernetes相关的其他问题或提一个您自己的问题