如需详细了解员工身份联合,请参阅 员工身份联合。
如需了解 Secure Source Manager 中员工身份联合的限制,请参阅 身份联合:产品和限制。
Secure Source Manager 是一项单租户服务。除非有合同关系的多家公司需要使用单个实例进行协作,否则单个 Secure Source Manager 实例应仅包含来自一个 Google Cloud 客户的用户。
如果您与多家公司合作,并希望与他们协作处理源代码,建议您为每家公司创建一个单独的实例。
准备工作
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
Enable the Secure Source Manager API, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
Install the Google Cloud CLI.
-
Configure the gcloud CLI to use your federated identity.
For more information, see Sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
数据加密
默认情况下, Google Cloud 会自动使用 对静态数据进行加密 Google-owned and Google-managed encryption keys。如果您有与保护数据的密钥相关的合规性或监管 要求,则可以创建 使用 客户管理的加密密钥 (CMEK)加密的 Secure Source Manager 实例。
请勿在实例 ID 或标签键值对中存储敏感数据,因为它们不会使用 CMEK 进行加密。
如果您要在项目中创建第一个 Secure Source Manager 实例,则必须运行以下命令手动创建 Secure Source Manager 服务代理:
gcloud beta services identity create \
--service=securesourcemanager.googleapis.com \
--project=PROJECT_ID
其中,PROJECT_ID 是您在其中创建 Secure Source Manager 实例的项目的项目 ID。
创建 Secure Source Manager 服务代理后,您必须向主体
service-PROJECT-NUMBER@gcp-sa-sourcemanager.
授予
Secure Source Manager Service Agent 角色
(roles/securesourcemanager.serviceAgent),否则实例创建将失败。
设置员工身份联合
在创建实例之前,您必须设置员工身份联合池和提供方。
创建实例
gcloud
在使用以下任何命令数据之前, 请进行以下替换:
- INSTANCE_ID:您要创建的实例的名称。
- LOCATION:您要在其中创建实例的区域。如需了解支持的位置,请参阅位置。
- PROJECT_ID:您要在其中创建实例的项目的项目 ID。
执行以下命令:
Linux、macOS 或 Cloud Shell
gcloud source-manager instances create INSTANCE_ID --region=LOCATION --project=PROJECT_ID --enable-workforce-identity-federation
Windows (PowerShell)
gcloud source-manager instances create INSTANCE_ID --region=LOCATION --project=PROJECT_ID --enable-workforce-identity-federation
Windows (cmd.exe)
gcloud source-manager instances create INSTANCE_ID --region=LOCATION --project=PROJECT_ID --enable-workforce-identity-federation
这会开始一个长时间运行的创建实例操作。输出如下所示:
Create request issued for [my-instance].
done: false
metadata:
'@type': type.googleapis.com/google.cloud.securesourcemanager.v1.OperationMetadata
apiVersion: v1
createTime: '2023-02-27T20:57:52.315609549Z'
requestedCancellation: false
target: projects/my-project/locations/us-central1/instances/my-instance
verb: create
name: projects/my-project/locations/us-central1/operations/operation-1234567894561-5ec69948c0f2b-60dd727f-a9b97a2e
其中,projects/my-project/locations/us-central1/operations/operation-1234567894561-5ec69948c0f2b-60dd727f-a9b97a2e 是 OPERATION_NAME。
请记录 OPERATION_NAME,因为您需要使用它来检查操作的状态。
创建实例最多需要 60 分钟。
API
在运行此命令之前,请替换以下值:
- INSTANCE_ID:您要创建的 实例的名称。
- LOCATION:您要在其中创建实例的区域。如需了解支持的位置,请参阅 位置。
- PROJECT_ID:您要在其中创建实例的项目的项目 ID。
运行以下命令:
curl \
-X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
https://securesourcemanager.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/instances?instance_id=INSTANCE_ID \
-H "Content-Type: application/json" \
-d "{workforce_identity_federation_config: {enabled: true}}"
这会开始一个长时间运行的创建实例操作。输出将类似以下内容:
{
"name": "OPERATION_NAME",
"metadata": {
"@type": "type.googleapis.com/google.cloud.securesourcemanager.v1.OperationMetadata",
"createTime": "2022-11-01T14:31:32.420469714Z",
"target": "projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID",
"verb": "create",
"requestedCancellation": false,
"apiVersion": "v1"
},
"done": false
}
此示例输出包含以下值:
OPERATION_NAME:操作名称,例如projects/my-project/locations/us-central1/operations/operation-1234567894561-5ec69948c0f2b-60dd727f-a9b97a2e。PROJECT_ID: Google Cloud 项目。LOCATION:实例所在的区域。
请记录 OPERATION_NAME,因为您需要使用它来检查操作的状态。
创建实例最多需要 60 分钟。
Terraform
以下示例会创建一个启用了员工身份联合的 Secure Source Manager 实例:
resource "google_secure_source_manager_instance" "instance" {
instance_id = "INSTANCE_ID"
location = "LOCATION"
project = "PROJECT_ID"
workforce_identity_federation_config {
enabled = true
}
}
查看操作状态
gcloud
在使用以下任何命令数据之前, 请进行以下替换:
- OPERATION_NAME:创建 命令响应中的操作名称。
- LOCATION:实例区域。
执行以下命令:
Linux、macOS 或 Cloud Shell
gcloud source-manager operations describe OPERATION_NAME --region=LOCATION
Windows (PowerShell)
gcloud source-manager operations describe OPERATION_NAME --region=LOCATION
Windows (cmd.exe)
gcloud source-manager operations describe OPERATION_NAME --region=LOCATION
实例准备就绪后,响应将类似于以下内容:
"name": "projects/my-project/locations/us-central1/operations/operation-123456789012-5ec69948c0f2b-60dd727f-a9b97a2e",
"metadata": {
"@type": "type.googleapis.com/google.cloud.securesourcemanager.v1.OperationMetadata",
"createTime": "2022-11-01T14:31:32.420469714Z",
"endTime": "2022-11-01T14:48:34.140378114Z",
"target": "projects/my-project/locations/us-central1/instances/my-instance",
"verb": "create",
"requestedCancellation": false,
"apiVersion": "v1"
},
"done": true,
"response": {
"@type": "type.googleapis.com/google.cloud.securesourcemanager.v1.Instance",
"name": "projects/my-project/locations/us-central1/instances/my-instance",
"createTime": "2022-11-01T14:31:32.416413630Z",
"updateTime": "2022-11-01T14:31:32.416413630Z",
"labels": {
"ldap": "user",
"source": "manual"
},
"state": "ACTIVE",
"hostConfig": {
"html": "my-instance-098765432109.us-central1.sourcemanager.dev",
"api": "my-instance-098765432109-api.us-central1.sourcemanager.dev",
"gitHttp": "my-instance-098765432109-git.us-central1.sourcemanager.dev"
}
}
其中,my-instance-098765432109.us-central1.sourcemanager.dev 是实例 HTML 网址。
API
在使用任何请求数据之前, 请进行以下替换:
- OPERATION_NAME:创建 命令响应中的操作名称。
HTTP 方法和网址:
GET https://securesourcemanager.googleapis.com/v1/OPERATION_NAME
如需发送您的请求,请展开以下选项之一:
实例准备就绪后,响应将类似于以下内容:
"name": "projects/my-project/locations/us-central1/operations/operation-123456789012-5ec69948c0f2b-60dd727f-a9b97a2e",
"metadata": {
"@type": "type.googleapis.com/google.cloud.securesourcemanager.v1.OperationMetadata",
"createTime": "2024-10-28T15:37:39.009812863Z",
"endTime": "2024-10-28T16:10:58.416640259Z",
"target": "projects/my-project/locations/us-central1/instances/my-instance",
"verb": "create",
"requestedCancellation": false,
"apiVersion": "v1"
},
"done": true,
"response": {
"@type": "type.googleapis.com/google.cloud.securesourcemanager.v1.Instance",
"name": "projects/my-project/locations/us-central1/instances/my-instance",
"createTime": "2024-10-28T15:37:39.004550840Z",
"updateTime": "2024-10-28T15:37:39.867857246Z",
"state": "ACTIVE",
"hostConfig": {
"html": "my-instance-326202322590.us-central1.sourcemanager.dev",
"api": "my-instance-326202322590-api.us-central1.sourcemanager.dev",
"gitHttp": "my-instance-326202322590-git.us-central1.sourcemanager.dev",
"gitSsh": "my-instance-326202322590-ssh.us-central1.sourcemanager.dev"
},
"workforceIdentityFederationConfig": {
"enabled": true
}
}
其中,my-instance-098765432109.us-central1.sourcemanager.dev 是实例 HTML 网址。
从成功的检查状态响应中复制 HTML 网址。您需要此网址才能通过网页界面访问实例。
访问实例
创建实例后,您可以使用浏览器通过网页界面访问该实例。
-
如需通过网页界面访问 Secure Source Manager 实例,请将以下网址复制到浏览器地址栏中。
INSTANCE_ID-PROJECT_NUMBER.LOCATION.sourcemanager.dev请替换以下内容:
- 将 INSTANCE_ID 替换为实例名称。
- 将 PROJECT_NUMBER 替换为实例的 Google Cloud 项目编号。如需了解如何标识项目,请参阅 标识项目。
- 将 LOCATION 替换为实例的区域。
系统会显示 OAuth 界面,要求您提供提供方名称。
输入员工身份提供方的名称,格式如下:
locations/global/workforcePools/POOL_ID/providers/PROVIDER_ID请替换以下内容:
- 将
POOL_ID替换为员工身份联合池 ID。 - 将
PROVIDER_ID替换为员工身份联合提供方 ID。
如需详细了解员工身份联合池和提供方,请参阅 管理员工身份联合身份池和提供方。
系统会提示您使用提供方凭据登录。
- 将
使用提供方凭据登录。
Secure Source Manager 网页界面随即打开。您可以在此处创建和查看代码库、问题和拉取请求。
员工身份联合池中的会话时长 过期后,您必须通过网页界面重新登录。
创建 gcloud CLI 登录配置
如需使用 gcloud CLI 命令或 Git 命令通过员工身份池凭据向 Secure Source Manager 实例进行身份验证,您必须使用员工身份池创建登录配置。
如需创建员工身份池登录配置,请按照 获取员工身份联合的短期令牌中的说明操作,以 使用 gcloud CLI 创建基于浏览器的登录。
完成身份验证后,您可以使用 Git 命令与 Secure Source Manager 实例进行交互。如需开始使用 Git,请参阅使用 Git 源代码管理。