创建角色

具有平台角色权限的用户可以根据实际使用场景,创建权限小于或等于自身角色权限的自定义角色。创建角色时,可以配置:

  • 平台功能模块操作权限
  • 用户自定义资源(Kubernetes CRD)的访问权限

目录

通过控制台创建角色

基本信息配置

  1. 在左侧导航栏,点击 用户 > 角色
  2. 点击 创建角色
  3. 配置角色的基本信息:

角色类型

为用户分配角色时,权限范围将根据角色类型进行限制:

  • 平台角色:展示所有平台权限
  • 项目角色:展示以下权限:
    • 项目管理
    • 容器平台
    • 服务网格
    • DevOps
    • 中间件
  • 命名空间角色:展示以下权限:
    • 项目管理
    • 容器平台
    • 服务网格
    • DevOps
    • 中间件
  1. 点击 下一步

视图配置

在视图配置部分,您可以控制该角色访问指定视图的权限。未选中的视图不会在拥有该角色的用户顶部导航中显示。

NOTE
  1. 您账号的角色权限限制了您可以配置的视图卡片。例如:

    • 如果您的账号没有 项目管理 视图权限
    • 创建角色时,项目管理 视图卡片将呈灰色不可选
    • 您只能创建权限等于或低于自身角色的角色
  2. 视图入口状态:

    • 如果在 产品 功能中关闭了某视图的 显示入口
    • 该视图在 权限配置 中的权限仍然生效
    • 视图将暂时不可访问,直到入口被启用
    • 启用后,之前选择的权限将正常生效

权限配置

  1. 点击页面左上角的 添加自定义权限
  2. 配置角色对自定义资源(Kubernetes CRD)的操作权限:
参数说明
分组名称权限分组名称。分组会按照添加顺序显示在权限模块下方。
资源名称资源名称。按回车键可添加多个自定义资源名称。
操作权限对资源的操作权限。
  1. 点击 创建

通过 yaml 创建角色

您可以在 global 集群提交以下 YAML 来创建角色

apiVersion: auth.alauda.io/v1beta1
kind: RoleTemplate
metadata:
  annotations:
    cpaas.io/description: "" ## Role description
    cpaas.io/display-name: Project Manager ## Role display name
  labels:
    auth.cpaas.io/roletemplate.level: project  ## Role level: platform, project, namespace
  name: project-admin-system-copy212
spec:
  customRules: ## Custom rules based on Kubernetes ClusterRole PolicyRule fields
    - apiGroups: ## APIGroups is the name of the APIGroup that contains the resources. If multiple API groups are specified, any action requested against one of the enumerated resources in any API group will be allowed. "" represents the core API group and "*" represents all API groups.
        - "" ## Core API group
        - apps ## Apps API group
      resources: ## Resources is a list of resources this rule applies to. "*" represents all resources.
        - "*" ## All resources
      resourceNames: ## ResourceNames is an optional white list of names that the rule applies to. An empty set means that everything is allowed. Omit this field to allow all resource names.
        - "example-resource" ## Optional: specific resource names
      verbs: ## Verbs is a list of Verbs that apply to ALL the ResourceKinds contained in this rule. "*" represents all verbs. Common verbs include: get, list, watch, create, update, patch, delete, deletecollection.
        - get ## Get a specific resource
        - list ## List resources
        - watch ## Watch resources for changes
        - create ## Create new resources
        - update ## Update existing resources
        - patch ## Partially update resources
        - delete ## Delete resources
        - deletecollection ## Delete collections of resources
    - apiGroups: ## Example: Additional rule for non-resource URLs (only applicable for ClusterRoles)
        - ""
      nonResourceURLs: ## NonResourceURLs is a set of partial urls that a user should have access to. "*" are allowed, but only as the full, final step in the path. Since non-resource URLs are not namespaced, this field is only applicable for ClusterRoles referenced from a ClusterRoleBinding. Rules can either apply to API resources or non-resource URL paths, but not both.
        - "/api"
        - "/api/*"
        - "/apis"
        - "/apis/*"
      verbs:
        - get
        - list