如果您与多家公司合作,并希望与他们协作处理源代码,建议您为每家公司创建一个单独的实例。
如需创建已启用 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
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.-
安装 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
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.-
安装 Google Cloud CLI。
-
如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI。
-
如需初始化 gcloud CLI,请运行以下命令:
gcloud init
所需的角色
如需获得创建 Secure Source Manager 实例所需的权限,请让管理员向您授予 Google Cloud 项目的 Secure Source Manager Instance Owner (roles/securesourcemanager.instanceOwner) IAM 角色。
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。
创建 Secure Source Manager 服务代理后,您必须向正文 service-PROJECT-NUMBER@gcp-sa-sourcemanager.iam.gserviceaccount.com授予 Secure Source Manager 服务代理角色 (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 网址。您将需要此网址才能通过实例的网页界面访问该实例。
Terraform
如需使用 Terraform 创建 Secure Source Manager 实例,请使用 google_secure_source_manager_instance 资源。
访问实例
创建实例后,您可以使用浏览器通过其网页界面访问该实例。
如需在实例中创建代码库,您需要在实例项目上拥有 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 界面创建和查看代码库以及所有相关问题和拉取请求。