GCP OAuth 认证
本页面由 PageTurner AI 翻译(测试版)。未经项目官方认可。 发现错误? 报告问题 →
当 Chaos Mesh 部署在 Google Cloud Platform 上时,您可以通过 Google OAuth 登录 Chaos Dashboard。本文档介绍如何启用和配置此功能。
创建 OAuth 客户端
根据设置 OAuth 2.0 创建 GCP OAuth 客户端并获取客户端 ID 和客户端密钥。
-
在项目列表中,选择现有项目或创建新项目。
-
若未自动加载 API 和服务页面,请手动打开控制台左侧菜单并选择 "APIs & services"。
-
点击左侧的 "Credentials"。
-
点击 "Create Credentials",然后选择 "OAuth client ID"。
-
选择应用类型为 "Web Application",并输入附加信息及 Chaos Dashboard 的重定向 URL:
ROOT_URL/api/auth/gcp/callback。其中ROOT_URL是 Chaos Dashboard 的根 URL(如http://localhost:2333),可通过helm的dashboard.rootUrl配置项设置。 -
点击 "Create"。
创建完成后,请保存客户端 ID 和客户端密钥供后续步骤使用。
配置并启动 Chaos Mesh
更新:自 v2.7.0 起,您可通过 Secret 存储客户端 ID 和客户端密钥。建议采用此方法。
此项改进旨在避免将客户端 ID 和客户端密钥暴露于公共环境。早期版本直接在 values 中指定这些凭证的做法通常存在安全隐患。
更多信息请参阅:https://github.com/chaos-mesh/chaos-mesh/issues/4206。
启用此功能需在 Helm Charts 中设置以下配置项:
dashboard:
rootUrl: http://localhost:2333
gcpSecurityMode:
enabled: true
# Old configuration items for compatibility.
clientId: ''
clientSecret: ''
# References existing Kubernetes secret containing `GCP_CLIENT_ID` and `GCP_CLIENT_SECRET`.
existingSecret: ''
若已安装 Chaos Mesh,可通过 helm upgrade 更新配置;若未安装,则通过 helm install 进行部署。
使用 Google 登录
打开 Chaos Dashboard,在认证窗口下方点击 Google 图标。

登录 Google 账户并授予 OAuth 客户端权限后,页面将自动重定向至已登录状态的 Chaos Dashboard。此时您拥有与该 Google 账户相同的集群权限。如需添加其他权限,可通过 RBAC(基于角色的访问控制)进行编辑,例如:
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: chaos-mesh-cluster-manager
rules:
- apiGroups:
- chaos-mesh.org
resources: ['*']
verbs: ['get', 'list', 'watch', 'create', 'delete', 'patch', 'update']
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: cluster-manager-binding
namespace: chaos-mesh
subjects:
- kind: User
name: example@gmail.com
roleRef:
kind: ClusterRole
name: chaos-mesh-cluster-manager
apiGroup: rbac.authorization.k8s.io
通过此配置,用户 example@gmail.com 将获得查看或创建任何混沌实验的权限。