如果您與多間公司合作,並想與他們協作原始碼,建議您為每間公司建立個別執行個體。
如要建立已啟用 VPC Service Controls 的執行個體,請參閱「在 VPC Service Controls 範圍內設定 Secure Source Manager」。
事前準備
-
登入 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, 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.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
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, 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.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
必要的角色
如要取得建立 Secure Source Manager 執行個體所需的權限,請要求管理員授予您 Google Cloud 專案的 Secure Source Manager 執行個體擁有者 (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 服務代理後,必須將 Secure Source Manager 服務代理角色 (roles/securesourcemanager.serviceAgent) 授予主體 service-PROJECT-NUMBER@gcp-sa-sourcemanager.iam.gserviceaccount.com,否則執行個體建立作業會失敗。
建立執行個體
若要建立執行個體,請進行以下操作:
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 資源。
存取執行個體
建立執行個體後,您可以使用瀏覽器透過網頁介面存取。
如要在執行個體中建立存放區,您必須具備執行個體專案的存放區建立者角色 (roles/securesourcemanager.repoCreator),以及 Secure Source Manager 執行個體的執行個體存放區建立者角色 (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 網頁介面隨即開啟。您可以透過網頁介面建立及查看存放區,以及所有相關聯的問題和提取要求。