个人资料和命名空间
什么是 Kubeflow Profile?
Kubeflow Profile 是 Kubeflow 引入的 Kubernetes CRD,它封装了一个 Kubernetes 命名空间(Namespace)。Profile 由单个用户拥有,可以有多个贡献者(具有查看或修改权限)。Profile 的所有者可以添加和移除贡献者(集群管理员也可以执行此操作)。
Profile 及其子命名空间由 Kubeflow Profile Controller 协调,贡献者(非所有者)由 Kubeflow Access Management API (KFAM) 管理。
中央仪表盘中的 Profile
在 Kubeflow 中央仪表盘的顶部栏中找到下拉菜单,选择活动的 Profile。大多数 Kubeflow 组件使用活动的 Profile 来确定要显示哪些资源以及授予哪些权限。
用户只能看到他们拥有所有者、贡献者(读 + 写)或查看者(只读)权限的 Profile。
自动创建 Profile
Kubeflow 支持首次登录 Kubeflow 的用户自动创建 Profile。
central-dashboard Deployment 上的 CD_REGISTRATION_FLOW
环境变量控制是否启用自动创建 Profile。默认情况下,自动创建 Profile 是禁用的。当 CD_REGISTRATION_FLOW
为 true
时,如果用户登录 Kubeflow 且尚不是 Profile 所有者,则会提示他们创建一个 Profile。
警告
自动创建 Profile 可能不适用于所有用例。
用户将成为自动创建 Profile 的所有者,因此可以添加/移除贡献者。
集群管理员可以选择禁用自动创建 Profile,并为用户和/或团队手动创建 Profile。通常在这种情况下,用户只被授予对 Profile 的查看或修改权限(而非所有者权限)。
以下是自动创建 Profile 的流程示例
- 新用户首次登录 Kubeflow
- 用户可以命名其 Profile 并点击完成
Profile 资源
为每个 Profile 创建以下资源
- 一个与 Profile 名称相同的 Kubernetes 命名空间。
- 针对用户的 Kubernetes RBAC
- 对于 Profile 所有者,一个名为
namespaceAdmin
的RoleBinding
,指向ClusterRole/kubeflow-admin
- 对于每个贡献者,一个名为
user-{EMAIL}-clusterrole-{ROLE}
的RoleBinding
,指向ClusterRole/kubeflow-{ROLE}
{EMAIL}
是贡献者的电子邮件,特殊字符替换为-
,并转换为小写。{ROLE}
是贡献者的角色,可以是edit
或view
- 对于 Profile 所有者,一个名为
- 针对 ServiceAccounts 的 Kubernetes RBAC
- 对于
ServiceAcount/default-editor
,一个名为default-editor
的RoleBinding
,指向ClusterRole/kubeflow-edit
- 对于
ServiceAcount/default-viewer
,一个名为default-viewer
的RoleBinding
,指向ClusterRole/kubeflow-view
- 对于
- Istio AuthorizationPolicies
- 对于 Profile 所有者,一个名为
ns-owner-access-istio
的AuthorizationPolicy
- 对于每个贡献者,一个名为
user-{EMAIL}-clusterrole-{ROLE}
的AuthorizationPolicy
{EMAIL}
是贡献者的电子邮件,特殊字符替换为-
,并转换为小写{ROLE}
是贡献者的角色,可以是edit
或view
- 对于 Profile 所有者,一个名为
管理 Profile
因为 Profile 是一个 Kubernetes CRD,集群管理员可以使用 kubectl
命令管理 Profile。
创建 Profile
集群管理员可以使用 kubectl
命令创建一个新的 Profile。
首先,创建一个名为 my-profile.yaml
的文件,其结构如下
apiVersion: kubeflow.org/v1
kind: Profile
metadata:
## the profile name will be the namespace name
## WARNING: unexpected behavior may occur if the namespace already exists
name: my-profile
spec:
## the owner of the profile
## NOTE: you may wish to make a global super-admin the owner of all profiles
## and only give end-users view or modify access to profiles to prevent
## them from adding/removing contributors
owner:
kind: User
name: admin@example.com
## plugins extend the functionality of the profile
## https://github.com/kubeflow/kubeflow/tree/master/components/profile-controller#plugins
plugins: []
## optionally create a ResourceQuota for the profile
## https://github.com/kubeflow/kubeflow/tree/master/components/profile-controller#resourcequotaspec
## https://kubernetes.ac.cn/docs/reference/kubernetes-api/policy-resources/resource-quota-v1/#ResourceQuotaSpec
resourceQuotaSpec: {}
接下来,运行以下命令创建 Profile
kubectl apply -f my-profile.yaml
列出所有 Profile
集群管理员可以使用以下命令列出现有 Profile
kubectl get profiles
描述 Profile
集群管理员可以使用以下命令描述特定的 Profile
kubectl describe profile MY_PROFILE_NAME
删除 Profile
集群管理员可以使用以下命令删除现有 Profile
kubectl delete profile MY_PROFILE_NAME
警告
删除 Profile 也会从集群中删除相应的命名空间。Profile 命名空间中创建的所有资源都将被删除。
管理 Profile 贡献者
Profile 贡献者由 Profile 命名空间中特定 RoleBinding
和 AuthorizationPolicy
资源的**存在**来定义。
通过中央仪表盘管理贡献者
Profile 的**所有者**可以使用 Kubeflow 中央仪表盘中的**管理贡献者**选项卡来添加或移除贡献者。
贡献者通过“您的命名空间的贡献者”字段进行管理。
手动管理贡献者
管理员可以通过在 Profile 命名空间中创建所需的 RoleBinding
和 AuthorizationPolicy
资源来手动向现有 Profile 添加贡献者。
创建贡献者 RoleBinding
授予用户访问 Profile 的 RoleBinding
结构如下
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: user-<SAFE_USER_EMAIL>-clusterrole-<USER_ROLE>
namespace: <PROFILE_NAME>
annotations:
role: <USER_ROLE>
user: <RAW_USER_EMAIL>
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: kubeflow-<USER_ROLE>
subjects:
- apiGroup: rbac.authorization.k8s.io
kind: User
name: <RAW_USER_EMAIL>
以下变量将替换为适当的值
<RAW_USER_EMAIL>
用户的电子邮件(区分大小写)<SAFE_USER_EMAIL>
用户的电子邮件(特殊字符替换为-
,并转换为小写)<USER_ROLE>
用户的角色,可以是edit
或view
<PROFILE_NAME>
Profile 的名称
创建贡献者 AuthorizationPolicy
授予用户访问 Profile 的 AuthorizationPolicy
结构如下
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
name: user-<SAFE_USER_EMAIL>-clusterrole-<USER_ROLE>
namespace: <PROFILE_NAME>
annotations:
role: <USER_ROLE>
user: <RAW_USER_EMAIL>
spec:
rules:
- from:
- source:
## for more information see the KFAM code:
## https://github.com/kubeflow/kubeflow/blob/v1.8.0/components/access-management/kfam/bindings.go#L79-L110
principals:
## required for kubeflow notebooks
## TEMPLATE: "cluster.local/ns/<ISTIO_GATEWAY_NAMESPACE>/sa/<ISTIO_GATEWAY_SERVICE_ACCOUNT>"
- "cluster.local/ns/istio-system/sa/istio-ingressgateway-service-account"
## required for kubeflow pipelines
## TEMPLATE: "cluster.local/ns/<KUBEFLOW_NAMESPACE>/sa/<KFP_UI_SERVICE_ACCOUNT>"
- "cluster.local/ns/kubeflow/sa/ml-pipeline-ui"
when:
- key: request.headers[kubeflow-userid]
values:
- <RAW_USER_EMAIL>
以下变量将替换为适当的值
<RAW_USER_EMAIL>
用户的电子邮件(区分大小写)<SAFE_USER_EMAIL>
用户的电子邮件(特殊字符替换为-
,并转换为小写)<USER_ROLE>
用户的角色,可以是edit
或view
<PROFILE_NAME>
Profile 的名称<KUBEFLOW_NAMESPACE>
安装 Kubeflow 的命名空间<KFP_UI_SERVICE_ACCOUNT>
ml-pipeline-ui
Pod 使用的 ServiceAccount 名称<ISTIO_GATEWAY_NAMESPACE>
包含 Istio Gateway Deployment 的命名空间<ISTIO_GATEWAY_SERVICE_ACCOUNT>
Istio Gateway Pod 使用的 ServiceAccount 名称