ack-virtual-node组件权限说明与自定义指南

ACK One注册集群通过ack-virtual-node实现Kubernetes与云上Serverless算力的无缝连接。在ACK One注册集群中,ack-virtual-node组件需要通过KubernetesServiceAccountClusterRole配置权限,实现与Kubernetes集群API的交互和资源管理。本文将为您介绍ack-virtual-node组件权限及自定义方式。

默认ClusterRole权限定义

ACK One注册集群中,ack-virtual-node组件默认的ClusterRole包含以下权限:

展开查看默认权限

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: ack-virtual-node-clusterrole
rules:
  - apiGroups:
      - ''
    resources:
      - pods
    verbs:
      - get
      - list
      - watch
      - patch
      - delete
  - apiGroups:
      - ''
    resources:
      - pods/status
    verbs:
      - update
      - patch
  - apiGroups:
      - ''
    resources:
      - pods/binding
    verbs:
      - create
  - apiGroups:
      - ''
    resources:
      - nodes
    verbs:
      - get
      - list
      - watch
      - create
      - delete
      - update
      - patch
  - apiGroups:
      - certificates.k8s.io
    resources:
      - certificatesigningrequests
    verbs:
      - get
      - list
      - watch
      - create
      - delete
  - apiGroups:
      - certificates.k8s.io
    resources:
      - certificatesigningrequests/approval
      - certificatesigningrequests/signerName
      - certificatesigningrequests/status
    verbs:
      - update
      - patch
  - apiGroups:
      - admissionregistration.k8s.io
    resourceNames:
      - vk-webhook
    resources:
      - mutatingwebhookconfigurations
    verbs:
      - get
      - list
      - watch
      - delete
      - patch
  - apiGroups:
      - admissionregistration.k8s.io
    resources:
      - mutatingwebhookconfigurations
    verbs:
      - create
  - apiGroups:
      - rbac.authorization.k8s.io
    resources:
      - clusterroles
      - clusterrolebindings
      - roles
      - rolebindings
    verbs:
      - get
      - list
      - watch
      - create
      - delete
      - update
  - apiGroups:
      - apps
    resources:
      - deployments
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - ''
    resources:
      - namespaces
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - coordination.k8s.io
    resourceNames:
      - vk-scaler-leader
      - vk-store
    resources:
      - leases
    verbs:
      - get
      - patch
      - update
      - list
  - apiGroups:
      - coordination.k8s.io
    resources:
      - leases
    verbs:
      - create
  - apiGroups:
      - eci.alibabacloud.com
    resources:
      - imagecaches
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - eci.alibabacloud.com
    resources:
      - imagecaches/status
    verbs:
      - update
  - apiGroups:
      - ''
      - discovery.k8s.io
    resources:
      - endpoints
      - endpointslices
      - services
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - ''
    resources:
      - events
    verbs:
      - create
      - patch
      - update
  - apiGroups:
      - events.k8s.io
    resources:
      - events
    verbs:
      - create
      - patch
      - update
  - apiGroups:
      - apiextensions.k8s.io
    resources:
      - customresourcedefinitions
    verbs:
      - get
      - list
      - watch
      - update
      - create
  - apiGroups:
      - apps.kruise.io
    resources:
      - sidecarsets
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - sidecarset.alibabacloud.com
    resources:
      - sidecarsetresourcebindings
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - storage.k8s.io
    resources:
      - csinodes
    verbs:
      - get
      - create
  - apiGroups:
      - apps.kruise.io
    resources:
      - containerrecreaterequests
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - apps.kruise.io
    resources:
      - containerrecreaterequests/status
    verbs:
      - update
  - apiGroups:
      - ''
    resourceNames:
      - default
    resources:
      - serviceaccounts/token
    verbs:
      - create
  - apiGroups:
      - authentication.k8s.io
    resources:
      - tokenreviews
    verbs:
      - create
  - apiGroups:
      - authorization.k8s.io
    resources:
      - subjectaccessreviews
    verbs:
      - create
  - apiGroups:
      - ''
    resources:
      - persistentvolumeclaims
      - persistentvolumes
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - storage.k8s.io
    resources:
      - storageclasses
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - ''
    resources:
      - nodes/status
    verbs:
      - update
      - patch
  - apiGroups:
      - ''
    resources:
      - nodes/proxy
    verbs:
      - create
  - apiGroups:
      - ''
    resources:
      - nodes/log
      - nodes/metrics
      - nodes/status
    verbs:
      - get
      - list
      - watch
  - apiGroups: 
      - storage.alibabacloud.com
    resources: 
      - containernetworkfilesystems
    verbs: 
      - get
      - list
      - watch 
   - apiGroups: 
      - monitoring.coreos.com
    resources: 
      - podmonitors
    verbs: 
      - get
      - list
      - watch 
  - apiGroups:
      - ''
    resources:
      - secrets
      - configmaps
    verbs:
      - create
  - apiGroups:
      - ''
    resources:
      - secrets
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - ''
    resources:
      - configmaps
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - ''
    resourceNames:
      - eci-profile
    resources:
      - configmaps
    verbs:
      - get
      - patch
      - watch
      - update

自定义ClusterRole

默认情况下,ack-virtual-node组件需要对Secret资源具备get/list/watch权限,以支持业务应用挂载并使用这些资源。

但如果已明确业务应用所依赖的Secret名称,可将权限收敛到指定的资源名称,实现最小化权限控制。

操作步骤

  1. 登录容器服务管理控制台,在左侧导航栏选择集群列表

  2. 集群列表页面,单击目标集群名称,然后在左侧导航栏,单击组件管理

  3. 在组件管理页面,您可以搜索并定位ack-virtual-node组件,在组件卡片上按需进行安装、卸载、升级、修改组件参数等操作。image

    配置项

    说明

    示例值

    ACKVirtualNodeAllowLWResources

    用于设置虚拟节点是否允许以list-watch方式访问指定名称的Secret 资源。默认值为 false。

    true

    ACKVirtualNodeAllowLWSecrets

    用于指定可通过list-watch方式访问的Secret资源名称,多个名称之间以英文逗号分隔。

    secret1,secret2

验证权限是否生效

  1. 执行以下命令,检查ClusterRoleBinding,可以查看绑定的ClusterRole相关信息。

    kubectl get clusterrolebinding ack-virtual-node-clusterrolebinding   -o yaml
  2. 执行以下命令,模拟API请求测试。

    kubectl auth can-i get secrets --as=system:serviceaccount:kube-system:ack-virtual-node

    如果ack-virtual-node组件具备对应的权限,则输出为yes。若无权限,则为no