如果您与多家公司合作,并希望与他们协作处理源代码,建议您为每家公司创建一个单独的实例。
如需创建启用 VPC Service Controls 的实例,请参阅在 VPC Service Controls 边界内配置 Secure Source Manager。
准备工作
-
Sign in to your Google Account.
If you don't already have one, sign up for a new account.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Enable the Secure Source Manager API.
-
Install the 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.
-
Enable the Secure Source Manager API.
-
Install the Google Cloud CLI.
-
如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI。
-
如需初始化 gcloud CLI,请运行以下命令:
gcloud init
- 安装 `beta` Google Cloud CLI 组件:
gcloud components install beta
运行以下命令以创建实例。系统可能会要求您向 gcloud CLI 进行身份验证。
gcloud beta 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
是要创建的实例的名称。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 beta 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 网址。您将需要此网址才能通过网页界面访问实例。
运行以下命令以创建实例。系统可能会要求您向 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
是要创建的实例的名称。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 网址。您将需要此网址才能通过实例的网页界面访问该实例。
-
如需通过网页界面访问 Secure Source Manager 实例,请将以下网址复制到浏览器地址栏中。
INSTANCE_ID-PROJECT_NUMBER.LOCATION.sourcemanager.dev
替换以下内容:
- 将 INSTANCE_ID 替换为实例名称。
- 将 PROJECT_NUMBER 替换为实例的 Google Cloud项目编号。如需了解如何标识项目,请参阅标识项目。
- 将 LOCATION 替换为实例的区域。
系统会显示一个 OAuth 屏幕,询问您是否要向
sourcemanager.dev
授予对您 Google 账号的访问权限。点击允许按钮。
系统会打开 Secure Source Manager 网页界面。您可以通过网页界面创建和查看代码库以及所有相关问题和拉取请求。
所需的角色
如需获得创建 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
是您将创建安全源代码管理器的项目的项目 ID。
创建每个产品、每个项目的服务账号 (P4SA) 后,您必须向正文 service-PROJECT-NUMBER@gcp-sa-sourcemanager.iam.gserviceaccount.com授予 Secure Source Manager 服务代理角色 (roles/securesourcemanager.serviceAgent
),否则实例创建会失败。
创建实例
要创建实例,请执行以下操作:
gcloud CLI
API
访问实例
创建实例后,您可以使用浏览器通过其网页界面访问该实例。
如需在实例中创建代码库,您需要在实例项目上拥有 Repo Creator 角色 (roles/securesourcemanager.repoCreator
),并在 Secure Source Manager 实例上拥有 Instance Repository Creator 角色 (roles/securesourcemanager.instanceRepositoryCreator
)。