【问题标题】:How to get admin access to multiple namespaces on Kubernetes?如何获得对 Kubernetes 上多个命名空间的管理员访问权限?
【发布时间】:2021-11-07 00:20:47
【问题描述】:

我有一个包含两部分的应用程序:一个部署程序和应用程序运行时环境。部署者需要能够访问不同的命名空间才能启动、编辑和删除应用程序部署、svc、configmaps 等。

我首先通过 helm chart 启动部署程序,然后部署程序公开一些 API 来管理应用程序(启动、编辑、删除)。

我的问题是如何为我的部署者编写ClusterRole,该部署者只能访问一组预先创建的命名空间,而没有授予它完全集群访问权限(部署者不应该能够创建、编辑或删除命名空间)。或者我必须为每个命名空间创建一个Role,然后在安装之前将它们添加到部署者的 Helm 图表中?

【问题讨论】:

    标签: kubernetes namespaces rbac


    【解决方案1】:

    您可以创建一个ClusterRole 来描述该角色可以做什么。然后在您希望角色用户拥有特权的每个命名空间中创建一个RoleBinding。这是来自documentation 的一个很好的例子:

    RoleBinding 还可以引用 ClusterRole,以将在该 ClusterRole 中定义的权限授予 RoleBinding 命名空间内的资源。这种引用允许您在整个集群中定义一组通用角色,然后在多个命名空间中重用它们。

    例如,即使以下 RoleBinding 引用 ClusterRole,“dave”(主题,区分大小写)将只能读取“development”命名空间中的 Secret,因为 RoleBinding 的命名空间(在其元数据中)是“发展”。

    apiVersion: rbac.authorization.k8s.io/v1
    # This role binding allows "dave" to read secrets in the "development" namespace.
    # You need to already have a ClusterRole named "secret-reader".
    kind: RoleBinding
    metadata:
      name: read-secrets
      #
      # The namespace of the RoleBinding determines where the permissions are granted.
      # This only grants permissions within the "development" namespace.
      namespace: development
    subjects:
    - kind: User
      name: dave # Name is case sensitive
      apiGroup: rbac.authorization.k8s.io
    roleRef:
      kind: ClusterRole
      name: secret-reader
      apiGroup: rbac.authorization.k8s.io
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-23
      • 2011-07-31
      • 2020-06-12
      • 2021-01-29
      相关资源
      最近更新 更多