如果您与多家公司合作,并希望与他们协作处理源代码,建议您为每家公司创建一个单独的实例。
如需创建启用了 VPC Service Controls 的实例,请参阅 在 VPC Service Controls 边界内配置 Secure Source Manager。
准备工作
-
登录您的 Google 账号。
如果您还没有 Google 账号,请 注册新账号。
-
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.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
安装 Google Cloud CLI。
-
如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI。
-
如需初始化 gcloud CLI,请运行以下命令:
gcloud init -
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.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
安装 Google Cloud CLI。
-
如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI。
-
如需初始化 gcloud CLI,请运行以下命令:
gcloud init
所需角色
如需获得创建 Secure Source Manager 实例所需的权限,请让您的管理员为您授予项目的 Secure Source Manager Instance Owner (roles/securesourcemanager.instanceOwner) IAM 角色。 Google Cloud
Secure Source Manager 角色在授予给正文之前不会显示在 Google Cloud 控制台中,直到 它们被授予给正文。如需首次授予 Secure Source Manager 角色 ,请参阅 授予和撤消 IAM 角色。
数据加密
默认情况下, Google Cloud 会使用 Google 管理的加密密钥自动加密静态数据。如果您有与保护数据的密钥相关的合规性或监管 要求,则可以创建 使用 客户管理的加密密钥 (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。
创建按产品、按项目服务帐号 (P4SA) 后,您必须向正文 service-PROJECT-NUMBER@gcp-sa-sourcemanager.iam.gserviceaccount.com授予 Secure Source Manager Service Agent 角色 (roles/securesourcemanager.serviceAgent),否则实例创建将失败。
创建实例
如需创建实例,请执行以下操作:
gcloud CLI
运行以下命令以创建实例。系统可能会要求您向 gcloud CLI 进行身份验证。
gcloud source-manager instances create INSTANCE_ID \ --region=LOCATION \ --project=PROJECT_ID \ --kms-key=projects/KEY_PROJECT/locations/KEY_LOCATION/keyRings/KEYRING_NAME/cryptoKeys/KEY其中:
INSTANCE_ID是实例的永久 ID。 该 ID 只能使用小写字母、数字和连字符,必须以字母开头,并且在创建后无法更改。LOCATION是您要在其中创建实例的区域。如需了解受支持的位置,请参阅 位置。PROJECT_ID是您要在其中创建实例的项目的项目 ID。-kms-key是一个可选标志。如果您想使用自己的客户管理的加密密钥 (CMEK) 来创建实例,请添加此标志。CMEK 密钥必须与您创建实例的位置相同,但可以位于不同的项目中。如果您想使用 Google 默认加密,请省略此标志。如果您想使用 CMEK 加密数据 ,请替换以下内容:- 将
KEY_PROJECT替换为您在其中创建密钥的项目。 - 将
KEY_LOCATION替换为密钥的位置。 - 将
KEYRING_NAME替换为您的密钥环名称。 - 将
KEY替换为您的密钥名称。
- 将
系统会启动一项长时间运行的创建实例操作。输出内容如下所示:
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。创建实例最多需要 60 分钟。
请记下
OPERATION_NAME,因为您需要使用它来检查操作的状态。运行以下命令检查
create操作的状态:gcloud source-manager operations describe OPERATION_NAME \ --region=LOCATION替换以下内容:
- 将
OPERATION_NAME替换为创建命令响应中的操作名称。 - 将
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/test", "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/test", "createTime": "2022-11-01T14:31:32.416413630Z", "updateTime": "2022-11-01T14:31:32.416413630Z", "labels": { "ldap": "user", "source": "manual" }, "state": "ACTIVE", "hostConfig": { "html": "test-098765432109.us-central1.sourcemanager.dev", "api": "test-098765432109-api.us-central1.sourcemanager.dev", "gitHttp": "test-098765432109-git.us-central1.sourcemanager.dev" } } }其中,
test-098765432109.us-central1.sourcemanager.dev是实例 HTML 网址。- 将
从成功创建的检查状态命令中复制 HTML 网址。您需要使用此网址通过实例的网页界面访问该实例。
API
运行以下命令以创建实例。系统可能会要求您向 gcloud CLI 进行身份验证。
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 '{ "kms_key":"projects/KEY_PROJECT/locations/KEY_LOCATION/keyRings/KEYRING_NAME/cryptoKeys/KEY"}'其中:
INSTANCE_ID是实例的永久 ID。 该 ID 只能使用小写字母、数字和连字符,并且必须以字母开头。LOCATION是您要在其中创建实例的区域。 如需了解受支持的位置,请参阅 位置。PROJECT_ID是您要在其中创建实例的项目的项目 ID。-d是一个可选的 HTTP POST 数据标志,可用于指定 CMEK 密钥来加密实例。如果您想使用 Google 默认加密,请省略此标志。如果您想使用 CMEK 加密数据 ,请替换以下内容:- 将
KEY_PROJECT替换为您在其中创建密钥的项目。 - 将
KEY_LOCATION替换为密钥的位置。 - 将
KEYRING_NAME替换为您的密钥环名称。 - 将
KEY替换为您的密钥名称。
- 将
系统会启动一项长时间运行的创建实例操作。输出内容如下所示:
{ "name": "projects/my-project/locations/us-central1/operations/operation-1234567894561-5ec69948c0f2b-60dd727f-a9b97a2e", "metadata": { "@type": "type.googleapis.com/google.cloud.securesourcemanager.v1.OperationMetadata", "createTime": "2022-11-01T14:31:32.420469714Z", "target": "projects/my-project/locations/us-central1/instances/test", "verb": "create", "requestedCancellation": false, "apiVersion": "v1" }, "done": false }其中,
projects/my-project/locations/us-central1/operations/operation-1234567894561-5ec69948c0f2b-60dd727f-a9b97a2e是OPERATION_NAME。创建实例最多需要 60 分钟。
复制
OPERATION_NAME。运行以下命令检查创建操作的状态:
curl \ -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ https://securesourcemanager.googleapis.com/v1/OPERATION_NAME其中,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": "2022-11-01T14:31:32.420469714Z", "endTime": "2022-11-01T14:48:34.140378114Z", "target": "projects/my-project/locations/us-central1/instances/test", "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/test", "createTime": "2022-11-01T14:31:32.416413630Z", "updateTime": "2022-11-01T14:31:32.416413630Z", "labels": { "ldap": "user", "source": "manual" }, "state": "ACTIVE", "hostConfig": { "html": "test-098765432109.us-central1.sourcemanager.dev", "api": "test-098765432109-api.us-central1.sourcemanager.dev", "gitHttp": "test-098765432109-git.us-central1.sourcemanager.dev" } } }其中,
test-098765432109.us-central1.sourcemanager.dev是实例 HTML 网址。从成功创建的检查状态命令中复制 HTML 网址。您需要使用此网址通过实例的网页界面访问该实例。
访问实例
创建实例后,您可以使用浏览器通过其网页界面访问该实例。
如需在实例中创建代码库,您需要拥有实例项目的 Repo Creator 角色 (roles/securesourcemanager.repoCreator) 和 Secure Source Manager 实例的 Instance Repository Creator 角色 (roles/securesourcemanager.instanceRepositoryCreator)。
-
如需通过网页界面访问 Secure Source Manager 实例,请将以下网址复制到浏览器地址栏中。
INSTANCE_ID-PROJECT_NUMBER.LOCATION.sourcemanager.dev替换以下内容:
- 将 INSTANCE_ID 替换为实例名称。
- 将 PROJECT_NUMBER 替换为实例的 Google Cloud 项目编号。如需了解如何标识项目,请参阅 标识项目。
- 将 LOCATION 替换为实例的区域。
系统会显示一个 OAuth 屏幕,询问您是否要向
sourcemanager.dev授予对您的 Google 账号的访问权限。点击允许 按钮。
Secure Source Manager 网页界面随即打开。您可以在 Web 界面中创建和查看代码库以及所有相关问题和拉取请求。