連結至 Secure Source Manager

本頁面說明如何建立 Secure Source Manager 的連線,並連結至 Secure Source Manager 存放區。這項整合功能可讓您使用 Developer Connect 功能,例如查看 Secure Source Manager 存放區的資訊主頁,以及使用 Developer Connect Proxy 執行 git 作業,例如安全讀取作業。

事前準備

  1. 登入 Google 帳戶。

    如果沒有帳戶,請 申請新帳戶

  2. 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Developer Connect API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  5. 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  6. Verify that billing is enabled for your Google Cloud project.

  7. Enable the Developer Connect API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  8. 選用:建立客戶自行管理的加密金鑰 (CMEK),用於加密 Developer Connect 建立的驗證密鑰。
  9. 選用:如要使用本指南中的指令列操作說明,請完成下列步驟:
    1. 安裝 Google Cloud CLI。如果您先前已安裝 gcloud CLI,請執行 gcloud components update,確認您擁有最新版本。
    2. 執行下列指令,建立 Developer Connect 服務帳戶,其中的 PROJECT_ID 是您的Google Cloud 專案 ID
              gcloud beta services identity create \
                  --service=developerconnect.googleapis.com \
                  --project=PROJECT_ID
              

Secure Source Manager 需求條件

  • 確認您已將可運作的 Secure Source Manager 執行個體部署至 Google Cloud 區域。
  • Developer Connect 連線和 Secure Source Manager 執行個體必須位於相同區域。
  • 在 Secure Source Manager 執行個體的專案中,將 roles/securesourcemanager.developerConnectLinker 角色授予 Developer Connect 服務代理人 (P4SA)。

必要的角色

如要取得建立連線和連結所需的權限,請要求管理員授予您下列 IAM 角色:

如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和組織的存取權」。

您或許也能透過自訂角色或其他預先定義的角色,取得必要權限。

建立連線

本節說明如何建立 Developer Connect 與 Secure Source Manager 之間的連線。如果您使用 Google Cloud 控制台,也可以在完成連線設定後,開始將連結新增至存放區。

如要建立新的 Secure Source Manager 連線,請選取下列任一選項:

控制台

  1. 在 Google Cloud 控制台中開啟「Developer Connect」

    前往 Developer Connect

  2. 點選「建立連線」

  3. 選取「Secure Source Manager」做為來源供應商。

  4. 在「Region」(區域) 中,選擇連線的區域。這必須與 Secure Source Manager 執行個體位於相同區域。

  5. 在「Name」(名稱) 部分輸入連線名稱。

  6. 在「執行個體」清單中,選取執行個體。

  7. 按一下「顯示更多」即可查看選用設定。

  8. 選用:如要停用 Developer Connect Proxy,請清除「啟用 Developer Connect Proxy」核取方塊。

  9. 按一下「繼續」

  10. 您可以立即連結至存放區,也可以稍後編輯連線來執行這項操作。如要連結至存放區,請從清單中選取存放區。

  11. 按一下「Link」(連結)

Developer Connect 會建立存放區連結,並顯示在 Google Cloud 控制台中。

gcloud

如要使用 Google Cloud CLI 建立 Developer Connect 連線,請執行下列指令:

gcloud developer-connect connections create CONNECTION_ID \
  --location=REGION \
  --project=CONNECTION_PROJECT_ID \
  --secure-source-manager-instance-config=projects/INSTANCE_PROJECT_ID/locations/REGION/instances/INSTANCE_ID

其中:

  • CONNECTION_ID 是您要建立的 Developer Connect 連線 ID。
  • REGION 是連線的地區。這必須與 Secure Source Manager 執行個體位於相同區域。
  • CONNECTION_PROJECT_ID 是您要建立連線的 Google Cloud 專案 ID。
  • INSTANCE_PROJECT_ID 是 Google Cloud 專案的 ID,Secure Source Manager 執行個體位於該專案中。
  • INSTANCE_ID 是 Secure Source Manager 執行個體的 ID。

curl

如要使用 curl 建立 Developer Connect 連線,請發出下列 API 呼叫:

curl -H "Authorization: Bearer $(gcloud auth print-access-token)" \
https://developerconnect.googleapis.com/v1/projects/CONNECTION_PROJECT_ID/locations/REGION/connections?connection_id=CONNECTION_ID \
-X POST -H "Content-Type: application/json" \
-d '{"secure_source_manager_instance_config":{"instance":"projects/INSTANCE_PROJECT_ID/locations/REGION/instances/INSTANCE_ID"}}'

其中:

  • CONNECTION_ID 是您要建立的 Developer Connect 連線 ID。
  • REGION 是連線的地區。這必須與 Secure Source Manager 執行個體位於相同區域。
  • CONNECTION_PROJECT_ID 是您要建立連線的 Google Cloud 專案 ID。
  • INSTANCE_PROJECT_ID 是 Google Cloud 專案的 ID,Secure Source Manager 執行個體位於該專案中。
  • INSTANCE_ID 是 Secure Source Manager 執行個體的 ID。

建立與 Secure Source Manager 的連線後,即可連結至存放區。之後可以視需要重複這些步驟,連結其他存放區。

如要在現有 Secure Source Manager 連線上建立存放區連結,請選取下列任一選項:

控制台

  1. 在 Google Cloud 控制台中開啟「Repositories」(存放區) 頁面。

    開啟「Repositories」(存放區) 頁面

  2. 按一下「連結存放區」

    「連結 Git 存放區」窗格隨即開啟。

  3. 在連線清單中,選擇 Secure Source Manager 連線。

  4. 按一下「繼續」

  5. 在存放區清單中,選取要連結的存放區。

  6. 點選「建立」

Developer Connect 會建立存放區連結,並顯示在 Google Cloud 控制台中。

gcloud

如要進一步瞭解如何使用 gcloud 管理 Git 存放區連結,請參閱 gcloud developer-connect connections git-repository-links

在 Cloud Build 中使用 Developer Connect Proxy

如要在 Cloud Build 中使用 Developer Connect Proxy,請按照下列步驟操作:

  1. 在 Developer Connect 專案中,將 roles/developerconnect.viewer 角色或任何具有 developerconnect.gitRepositoryLinks.get 權限的角色授予 Secure Source Manager 服務代理。
  2. 將 Secure Source Manager 存放區連結至 Developer Connect gitRepositoryLink。如需操作說明,請參閱「連結至 Secure Source Manager 存放區」。
  3. 在存放區根目錄的 .cloudbuild/trigger.yaml 檔案中,新增指向目標 gitRepositoryLink 資源的項目。

    例如:

    triggers:
    - name: test-trigger
      project: my-project
      configFilePath: cloudbuild.yaml
      eventType: push
      serviceAccount: projects/my-project/serviceAccounts/my-sa@my-project.iam.gserviceaccount.com
      devConnectGitRepositoryLink: projects/my-project/locations/us-central1/connections/my-ssm-connection/gitRepositoryLinks/my-repo-link
    

作業範圍和限制

設定連線後,您可以使用 Developer Connect Proxy URI,對 Secure Source Manager 執行個體執行安全 git 讀取作業,例如 clone

Developer Connect Proxy 不支援 git push 作業。系統會禁止使用 DevConnect P4SA 身分進行寫入作業。

您可以更新連線的其他設定,例如啟用或停用 Developer Connect Proxy,但無法將現有連線指向其他 Secure Source Manager 執行個體。

後續步驟