Secure Source Manager 支持所有 Git SCM 客户端命令,并内置了拉取请求和问题跟踪功能。它同时支持 HTTPS 和 SSH 身份验证 。
所需角色
如需获得使用 Git 与 Secure Source Manager 代码库进行交互所需的权限,请让您的管理员为您授予以下 IAM 角色:
- Secure Source Manager 实例的 Secure Source Manager Instance Accessor (
roles/securesourcemanager.instanceAccessor) -
如需克隆代码库:
Secure Source Manager Repo Reader (
roles/securesourcemanager.repoReader) 代码库的 -
如需推送到代码库:
代码库的 Secure Source Manager Repo Writer (
roles/securesourcemanager.repoWriter)
如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限。
您也可以通过自定义 角色或其他预定义 角色来获取所需的权限。
如需了解如何授予 Secure Source Manager 角色, 请参阅 使用 IAM 进行访问权限控制 和 向用户授予实例访问权限。
安装 Git 和 Google Cloud CLI
安装 Git。
如果 Git 安装程序提示您选择凭证帮助程序 ,请选择无(不使用凭证帮助程序) 。
如需将 Git 与 HTTPS 搭配使用,您需要使用 gcloud CLI 版本
395.0.0或更高版本。如需检查 gcloud CLI 版本,请运行以下命令:gcloud --version如需更新 gcloud CLI,请运行以下命令。
gcloud components update更新后,运行
gcloud init以 初始化 gcloud CLI。如需了解详情,请参阅有关 更新组件 的 gcloud CLI 文档。
设置凭据
如果您使用第三方身份 提供方和员工身份联合向 Secure Source Manager 进行身份验证,则无需完成本 部分内容,而是必须 创建员工身份池登录配置。
运行以下命令,将 Secure Source Manager 身份验证帮助程序添加到全局 Git 配置:
Linux
git config --global credential.'https://*.*.sourcemanager.dev'.helper gcloud.sh
早期版本的 Git 可能不支持通配符。如需添加不带通配符的身份验证帮助程序,请运行以下命令:
git config --global credential.'https://INSTANCE_ID-PROJECT_NUMBER-git.LOCATION.sourcemanager.dev'.helper gcloud.sh
替换以下内容:
Windows
git config --global credential.https://*.*.sourcemanager.dev.helper gcloud.cmd
早期版本的 Git 可能不支持通配符。如需添加不带通配符的身份验证帮助程序,请运行以下命令:
git config --global credential.https://INSTANCE_ID-PROJECT_NUMBER-git.LOCATION.sourcemanager.dev.helper gcloud.cmd
替换以下内容:
使用 Secure Source Manager 执行 Git 命令时,身份验证帮助程序会使用 gcloud CLI 来提取您的 Google Cloud 凭据。
如需在初始凭据设置后重新进行身份验证,请运行以下 gcloud CLI 命令:
gcloud auth login
使用服务帐号通过 Compute Engine 虚拟机进行身份验证
您可以使用关联的服务帐号通过 Compute Engine 虚拟机 (VM) 进行身份验证。
配置虚拟机和服务帐号
如果您使用 Compute Engine 默认服务帐号,请使用所需的 OAuth 范围创建虚拟机:
gcloud compute instances create VM_NAME \
--project=PROJECT_ID \
--zone=ZONE \
--scopes=openid,https://www.googleapis.com/auth/userinfo.profile,https://www.googleapis.com/auth/userinfo.email,https://www.googleapis.com/auth/cloud-platform
替换以下内容:
VM_NAME:虚拟机的名称。PROJECT_ID:您的 Google Cloud 项目 ID。ZONE:虚拟机的可用区。
如果您使用自定义服务帐号,请先创建服务帐号,然后再创建虚拟机。
创建服务帐号:
gcloud iam service-accounts create SA_NAME --project=PROJECT_ID将
SA_NAME替换为服务帐号的名称。授予使用服务帐号的权限。如需使用服务 账号创建虚拟机,您需要拥有该服务帐号的 Service Account User 角色 (
roles/iam.serviceAccountUser)。将此角色授予创建虚拟机的主账号:gcloud iam service-accounts add-iam-policy-binding SA_NAME@PROJECT_ID.iam.gserviceaccount.com \ --member="user:USER_EMAIL" \ --role="roles/iam.serviceAccountUser"将
USER_EMAIL替换为创建虚拟机的用户的电子邮件地址。创建虚拟机:
gcloud compute instances create VM_NAME \ --project=PROJECT_ID \ --zone=ZONE \ --scopes=openid,https://www.googleapis.com/auth/userinfo.profile,https://www.googleapis.com/auth/userinfo.email,https://www.googleapis.com/auth/cloud-platform \ --service-account=SA_NAME@PROJECT_ID.iam.gserviceaccount.com
向服务帐号授予 IAM 角色
向服务帐号授予对 Secure Source Manager 实例和代码库的访问权限:
授予实例访问权限:
SA_EMAIL=$(gcloud compute instances describe VM_NAME --project=PROJECT_ID --zone=ZONE --format="get(serviceAccounts[0].email)") gcloud projects add-iam-policy-binding PROJECT_ID \ --member="serviceAccount:$SA_EMAIL" \ --role=roles/securesourcemanager.instanceAccessor授予代码库读取权限。
如需授予对特定代码库的读取权限,请运行以下命令: