3.9. 管理身份和授权
本节论述了管理 Red Hat OpenShift Dev Spaces 的身份和授权的不同方面。
3.9.1. 为 Git 供应商配置 OAuth
您可以在 OpenShift Dev Spaces 和 Git 供应商之间配置 OAuth,允许用户使用远程 Git 存储库:
3.9.1.1. 为 GitHub 配置 OAuth 2.0
允许用户使用 GitHub 上托管的远程 Git 存储库:
- 设置 GitHub OAuth 应用程序(OAuth 2.0)。
- 应用 GitHub OAuth App Secret。
3.9.1.1.1. 设置 GitHub OAuth 应用程序
使用 OAuth 2.0 设置 GitHub OAuth 应用程序。
先决条件
- 已登陆到 GitHub。
-
base64
安装在您正在使用的操作系统中。
流程
- 进入 https://github.com/settings/applications/new。
输入以下值:
-
应用程序名称 :
OpenShift Dev Spaces
-
主页 URL:
https://devspaces- <openshift_deployment_name>. <domain_name>/
-
授权回调 URL:
https://devspaces- <openshift_deployment_name>.<domain_name> /api/oauth/callback
-
应用程序名称 :
- 点击 Register application。
- 点 Generate new client secret。
复制 GitHub OAuth 客户端 ID,并将其编码到 Base64 中,以便在应用 GitHub OAuth App Secret 时要使用的:
$ echo -n '<github_oauth_client_id>' | base64
复制 GitHub OAuth 客户端 Secret,并将其编码到 Base64 中,以便在应用 GitHub OAuth App Secret 时要使用的:
$ echo -n '<github_oauth_client_secret>' | base64
3.9.1.1.2. 应用 GitHub OAuth 应用程序 Secret
准备并应用 GitHub OAuth App Secret。
先决条件
- 设置 GitHub OAuth 应用程序已完成。
准备好设置 GitHub OAuth App 时生成的 Base64 编码值:
- GitHub OAuth 客户端 ID
- GitHub OAuth 客户端 Secret
-
一个活跃的
oc
会话,它具有到目标 OpenShift 集群的管理权限。请参阅开始使用 CLI。
流程
准备 Secret:
kind: Secret apiVersion: v1 metadata: name: github-oauth-config namespace: openshift-devspaces 1 labels: app.kubernetes.io/part-of: che.eclipse.org app.kubernetes.io/component: oauth-scm-configuration annotations: che.eclipse.org/oauth-scm-server: github che.eclipse.org/scm-server-endpoint: <github_server_url> 2 type: Opaque data: id: <Base64_GitHub_OAuth_Client_ID> 3 secret: <Base64_GitHub_OAuth_Client_Secret> 4
应用 Secret:
$ oc apply -f - <<EOF <Secret_prepared_in_the_previous_step> EOF
- 验证在 Secret 是否已创建的输出中。
3.9.1.2. 为 GitLab 配置 OAuth 2.0
允许用户使用 GitLab 实例托管的远程 Git 存储库:
- 设置 GitLab 授权应用(OAuth 2.0)。
- 应用 GitLab 授权应用程序 Secret。
3.9.1.2.1. 设置 GitLab 授权应用程序
使用 OAuth 2.0 设置 GitLab 授权应用程序。
先决条件
- 已登陆到 GitLab。
-
base64
安装在您正在使用的操作系统中。
流程
-
点您的 avatar,再进入
。 - 输入 OpenShift Dev Spaces 作为 Name。
-
输入
https://devspaces- <openshift_deployment_name> .<domain_name> /api/oauth/callback
作为 Redirect URI。 - 选中 Confidential 和 Expire 访问令牌 复选框。
-
在 Scopes 下,选中
api
、write_repository
和openid
复选框。 - 点 Save application。
复制 GitLab 应用程序 ID,并将其编码到 Base64 中,以便在应用 GitLab-authorized 应用程序 Secret 时要使用的:
$ echo -n '<gitlab_application_id>' | base64
复制 GitLab 客户端 Secret,并将其编码到 Base64 中,以便在应用 GitLab-authorized 应用程序 Secret 时要使用的:
$ echo -n '<gitlab_client_secret>' | base64
其他资源
3.9.1.2.2. 应用 GitLab-authorized 应用程序 Secret
准备并应用 GitLab-authorized 应用程序 Secret。
先决条件
- 设置 GitLab 授权应用程序已完成。
准备好在设置 GitLab 授权应用程序时生成的 Base64 编码值:
- GitLab 应用程序 ID
- GitLab Client Secret
-
一个活跃的
oc
会话,它具有到目标 OpenShift 集群的管理权限。请参阅开始使用 CLI。
流程
准备 Secret:
kind: Secret apiVersion: v1 metadata: name: gitlab-oauth-config namespace: openshift-devspaces 1 labels: app.kubernetes.io/part-of: che.eclipse.org app.kubernetes.io/component: oauth-scm-configuration annotations: che.eclipse.org/oauth-scm-server: gitlab che.eclipse.org/scm-server-endpoint: <gitlab_server_url> 2 type: Opaque data: id: <Base64_GitLab_Application_ID> 3 secret: <Base64_GitLab_Client_Secret> 4
应用 Secret:
$ oc apply -f - <<EOF <Secret_prepared_in_the_previous_step> EOF
- 验证在 Secret 是否已创建的输出中。
3.9.1.3. 为 Bitbucket 服务器配置 OAuth 1.0
允许用户使用在 Bitbucket 服务器上托管的远程 Git 存储库:
- 在 Bitbucket 服务器上设置应用链接(OAuth 1.0)。
- 为 Bitbucket 服务器应用应用链接 Secret。
3.9.1.3.1. 在 Bitbucket 服务器上设置应用程序链接
在 Bitbucket 服务器上为 OAuth 1.0 设置应用链接。
流程
在命令行中运行命令,为后续步骤创建必要的文件,并在应用应用程序链接 Secret 时使用:
$ openssl genrsa -out private.pem 2048 && \ openssl pkcs8 -topk8 -inform pem -outform pem -nocrypt -in private.pem -out privatepkcs8.pem && \ cat privatepkcs8.pem | sed 's/-----BEGIN PRIVATE KEY-----//g' | sed 's/-----END PRIVATE KEY-----//g' | tr -d '\n' | base64 | tr -d '\n' > privatepkcs8-stripped.pem && \ openssl rsa -in private.pem -pubout > public.pub && \ cat public.pub | sed 's/-----BEGIN PUBLIC KEY-----//g' | sed 's/-----END PUBLIC KEY-----//g' | tr -d '\n' > public-stripped.pub && \ openssl rand -base64 24 > bitbucket-consumer-key && \ openssl rand -base64 24 > bitbucket-shared-secret
-
前往
。 -
在 URL 字段中输入
https://devspaces- <openshift_deployment_name > . <domain_name> /
,然后点击 Create new link。 - 在提供的 Application URL 下, 选中 Use this URL 复选框,然后单击 Continue。
- 输入 OpenShift Dev Spaces 作为 Application Name。
- 选择 Generic Application 作为 Application Type。
- 输入 OpenShift Dev Spaces 作为 Service Provider Name。
-
将
bitbucket-consumer-key
文件的内容粘贴为 Consumer 密钥。 -
将
bitbucket-shared-secret
文件的内容粘贴为 Shared secret。 -
输入
<bitbucket_server_url> /plugins/servlet/oauth/request-token
作为 Request Token URL。 -
输入
<bitbucket_server_url>/plugins/servlet/oauth/access-token
作为 Access token URL。 -
输入
<bitbucket_server_url> /plugins/servlet/oauth/authorize
作为 Authorize URL。 - 选中 Create incoming link 复选框,再点 Continue。
-
将
bitbucket-consumer-key
文件的内容粘贴为 Consumer Key。 - 输入 OpenShift Dev Spaces 作为 Consumer 名称。
-
将
public-stripped.pub
文件的内容粘贴为 公钥,然后单击 Continue。
3.9.1.3.2. 为 Bitbucket 服务器应用应用程序链接 Secret
为 Bitbucket 服务器准备并应用应用链接 Secret。
先决条件
- 应用程序链接已在 Bitbucket 服务器上设置。
准备在设置应用程序链接时创建的以下文件:
-
privatepkcs8-stripped.pem
-
bitbucket-consumer-key
-
bitbucket-shared-secret
-
-
一个活跃的
oc
会话,它具有到目标 OpenShift 集群的管理权限。请参阅开始使用 CLI。
流程
将
bitbucket-consumer-key
文件的内容编码为 Base64 :$ echo -n '<bitbucket-consumer-key file content>' | base64
将
bitbucket-shared-secret
文件的内容编码为 Base64 :$ echo -n '<bitbucket-shared-secret file content>' | base64
准备 Secret:
kind: Secret apiVersion: v1 metadata: name: bitbucket-oauth-config namespace: openshift-devspaces 1 labels: app.kubernetes.io/component: oauth-scm-configuration app.kubernetes.io/part-of: che.eclipse.org annotations: che.eclipse.org/oauth-scm-server: bitbucket che.eclipse.org/scm-server-endpoint: <bitbucket_server_url> 2 type: Opaque data: private.key: <Base64_content_of_privatepkcs8-stripped.pem> 3 consumer.key: <Base64_content_of_bitbucket-consumer-key> 4 shared_secret: <Base64_content_of_bitbucket-shared-secret> 5
应用 Secret:
$ oc apply -f - <<EOF <Secret_prepared_in_the_previous_step> EOF
- 验证在 Secret 是否已创建的输出中。
3.9.1.4. 为 Bitbucket 云配置 OAuth 2.0
您可以允许用户使用托管在 Bitbucket 云中的远程 Git 存储库:
- 在 Bitbucket 云中设置 OAuth 使用者(OAuth 2.0)。
- 为 Bitbucket 云应用 OAuth 使用者 Secret。
3.9.1.4.1. 在 Bitbucket 云中设置 OAuth 使用者
在 Bitbucket 云中为 OAuth 2.0 设置 OAuth 使用者。
先决条件
- 您已登录到 Bitbucket 云。
-
base64
安装在您正在使用的操作系统中。
流程
- 点您的 avatar,再进入 All workspaces 页面。
- 选择一个工作区并点它。
-
前往
。 - 输入 OpenShift Dev Spaces 作为 Name。
-
输入
https://devspaces- <openshift_deployment_name> .<domain_name> /api/oauth/callback
作为 回调 URL。 - 在 Permissions 下,选中所有 帐户 和存储库 复选框,然后单击 Save。
展开添加的消费者,然后复制 Key 值并将其编码为 Base64,以便在应用 Bitbucket OAuth 消费者 Secret 时使用:
$ echo -n '<bitbucket_oauth_consumer_key>' | base64
复制 Secret 值并将其以 Base64 进行编码,以便在应用 Bitbucket OAuth 消费者 Secret 时使用:
$ echo -n '<bitbucket_oauth_consumer_secret>' | base64
3.9.1.4.2. 为 Bitbucket 云应用 OAuth 使用者 Secret
为 Bitbucket 云准备并应用 OAuth 使用者机密。
先决条件
- OAuth 使用者在 Bitbucket 云中设置。
准备好在设置 Bitbucket OAuth 使用者时生成的 Base64 编码值:
- Bitbucket OAuth 使用者密钥
- Bitbucket OAuth 使用者 Secret
-
一个活跃的
oc
会话,它具有到目标 OpenShift 集群的管理权限。请参阅开始使用 CLI。
流程
准备 Secret:
kind: Secret apiVersion: v1 metadata: name: bitbucket-oauth-config namespace: openshift-devspaces 1 labels: app.kubernetes.io/part-of: che.eclipse.org app.kubernetes.io/component: oauth-scm-configuration annotations: che.eclipse.org/oauth-scm-server: bitbucket type: Opaque data: id: <Base64_Bitbucket_Oauth_Consumer_Key> 2 secret: <Base64_Bitbucket_Oauth_Consumer_Secret> 3
应用 Secret:
$ oc apply -f - <<EOF <Secret_prepared_in_the_previous_step> EOF
- 验证在 Secret 是否已创建的输出中。
3.9.1.5. 为 Microsoft Azure DevOps 服务配置 OAuth 2.0
用户可以使用托管在 Microsoft Azure Repo 上的远程 Git 存储库:
- 设置 Microsoft Azure DevOps 服务 OAuth 应用程序(OAuth 2.0)。
- 应用 Microsoft Azure DevOps Services OAuth App Secret。
3.9.1.5.1. 设置 Microsoft Azure DevOps 服务 OAuth 应用程序
使用 OAuth 2.0 设置 Microsoft Azure DevOps 服务 OAuth 应用程序。
先决条件
- 您已登录到 Microsoft Azure DevOps Services。
- 第三方应用程序可以通过 OAuth 访问机构中的资源。请参阅管理安全和应用程序访问策略。
-
base64
安装在您正在使用的操作系统中。
流程
- Visit https://app.vsaex.visualstudio.com/app/register/.
输入以下值:
-
公司名称 :
OpenShift Dev Spaces
-
应用程序名称 :
OpenShift Dev Spaces
-
应用程序网站:
https://devspaces- <openshift_deployment_name>. <domain_name>/
-
授权回调 URL:
https://devspaces- <openshift_deployment_name>.<domain_name> /api/oauth/callback
-
公司名称 :
- 在 Select Authorized ranges 中,选择 Code (读取和写入)。
- 点 Create application。
复制 App ID,并将其编码到 Base64 中,以便在应用 Microsoft Azure DevOps Services OAuth App Secret 时使用:
$ echo -n '<microsoft_azure_devops_services_oauth_app_id>' | base64
- 单击 Show 以显示 客户端 Secret。
复制 客户端 Secret,并将其编码到 Base64 中,以便在应用 Microsoft Azure DevOps Services OAuth App Secret 时使用:
$ echo -n '<microsoft_azure_devops_services_oauth_client_secret>' | base64
3.9.1.5.2. 应用 Microsoft Azure DevOps Services OAuth App Secret
准备并应用 Microsoft Azure DevOps Services Secret。
先决条件
- 设置 Microsoft Azure DevOps 服务 OAuth 应用程序已完成。
准备好在设置 Microsoft Azure DevOps Services OAuth App 时生成以 Base64 编码的值:
- 应用程序 ID
- Client Secret
-
一个活跃的
oc
会话,它具有到目标 OpenShift 集群的管理权限。请参阅开始使用 CLI。
流程
准备 Secret:
kind: Secret apiVersion: v1 metadata: name: azure-devops-oauth-config namespace: openshift-devspaces1 labels: app.kubernetes.io/part-of: che.eclipse.org app.kubernetes.io/component: oauth-scm-configuration annotations: che.eclipse.org/oauth-scm-server: azure-devops type: Opaque data: id: <Base64_Microsoft_Azure_DevOps_Services_OAuth_App_ID>2 secret: <Base64_Microsoft_Azure_DevOps_Services_OAuth_Client_Secret>3
应用 Secret:
$ oc apply -f - <<EOF <Secret_prepared_in_the_previous_step> EOF
- 验证在 Secret 是否已创建的输出中。
3.9.2. 配置管理用户
要执行需要在 OpenShift Dev Spaces 服务器上需要管理特权的操作,如删除用户数据,激活具有管理特权的用户。默认安装为 admin
用户启用管理特权,无论 OpenShift 中存在它。
流程
配置
CheCluster
自定义资源,以设置具有管理特权的 & lt;admin > 用户。请参阅 第 3.1.2 节 “使用 CLI 配置 CheCluster 自定义资源”。spec: components: cheServer: extraProperties: CHE_SYSTEM_ADMIN__NAME: '<admin>'
3.9.3. 删除用户数据以遵守 GDPR
您可以删除用户数据符合 General Data Protection Regulation (GDPR),以强制个人的个人数据被清除。
按如下所示删除用户数据是不可逆的!所有删除的数据都会被删除并无法恢复!
先决条件
- 具有 OpenShift Dev Spaces 管理权限的活动会话。请参阅 第 3.9.2 节 “配置管理用户”。
-
具有 OpenShift 集群的管理权限的活跃的
oc
会话。请参阅开始使用 OpenShift CLI。
流程
如果 OpenShift Dev Spaces 实例已升级,因为以前的版本中用户数据存储在 PostgreSQL 数据库中,则首先使用已弃用的端点:
-
进入
https://devspaces- <openshift_deployment_name>.<domain_name> /swagger/rhcs/user/find_1
。 -
选择 Try it out
name:<username > Execute 来获取用户 ID。 在 Response body 中查找 id 值。
如果响应是 404,这表示用户不在数据库中,请跳至第 2 步。
-
进入
https://devspaces- <openshift_deployment_name>.<domain_name> /swagger/rhcs/user/remove
。 -
选择 Try it out
id : & lt;id> Execute 以删除由 OpenShift Dev Spaces 服务器管理的用户数据。 - 验证您是否得到 204 响应。
-
进入
删除用户项目,以删除绑定到用户的所有 OpenShift 资源,如工作区、Secret 和 ConfigMap。
$ oc delete namespace <username>-devspaces