建立 Secure Source Manager 執行個體,搭配聯合身分使用

本文說明如何使用員工身分聯盟建立 Secure Source Manager 執行個體,以便搭配外部身分識別提供者 (IdP) 使用。

如要進一步瞭解員工身分聯盟,請參閱「員工身分聯盟」。

如要瞭解 Secure Source Manager 中員工身分聯盟的限制,請參閱「身分聯盟:產品和限制」。

Secure Source Manager 是單一租戶服務。除非有多家公司有合約關係,需要使用單一執行個體進行協作,否則單一 Secure Source Manager 執行個體應只包含一個Google Cloud 客戶的使用者。

如果您與多家公司合作,並想與他們共同處理原始碼,建議您為每家公司建立個別的執行個體。

事前準備

  1. Sign in to your Google Account.

    If you don't already have one, sign up for a new account.

  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Enable the Secure Source Manager API.

    Enable the API

  4. Install the Google Cloud CLI.

  5. 如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI

  6. 如要初始化 gcloud CLI,請執行下列指令:

    gcloud init
  7. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  8. Enable the Secure Source Manager API.

    Enable the API

  9. Install the Google Cloud CLI.

  10. 如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI

  11. 如要初始化 gcloud CLI,請執行下列指令:

    gcloud init
  12. 安裝 beta Google Cloud CLI 元件:
    gcloud components install beta
  13. 資料加密

    根據預設, Google Cloud 會自動使用Google-owned and Google-managed encryption keys加密靜態資料。如果您在保護資料的金鑰方面有特定的法規遵循或監管要求,可以建立以客戶自行管理的加密金鑰 (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,您將在該專案中建立 Secure Source Manager 執行個體。

    建立每個產品和專案的服務帳戶 (P4SA) 後,您必須將 Secure Source Manager 服務代理程式角色 (roles/securesourcemanager.serviceAgent) 授予主體 service-PROJECT-NUMBER@gcp-sa-sourcemanager.iam.gserviceaccount.com,否則執行個體建立作業會失敗。

    設定員工身分聯盟

    建立執行個體前,請務必先設定 Workforce Identity Federation 集區和提供者。

    1. 建立員工身分聯盟集區

    2. 設定員工身分識別資訊集區提供者,並使用下列屬性對應

      • google.subject
      • google.email

    建立執行個體

    執行指令前,請先進行下列替換:

    • INSTANCE_ID:要建立的執行個體名稱。
    • LOCATION:要建立執行個體的區域。如要瞭解支援的位置,請參閱「位置」。
    • PROJECT_ID:要在其中建立執行個體的專案 ID。

    執行下列指令:

    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 "{workforce_identity_federation_config: {enabled: true}}"
    
    

    系統會啟動長時間執行的建立執行個體作業。輸出內容如下所示:

    {
    "name": "OPERATION_NAME",
    "metadata": {
      "@type": "type.googleapis.com/google.cloud.securesourcemanager.v1.OperationMetadata",
      "createTime": "2022-11-01T14:31:32.420469714Z",
      "target": "projects/PROJECT_ID/locations/LOCATION/instances/INSTANCE_ID",
      "verb": "create",
      "requestedCancellation": false,
      "apiVersion": "v1"
    },
    "done": false
    }
    

    這個輸出範例包含下列值:

    • OPERATION_NAME:作業名稱,例如 projects/my-project/locations/us-central1/operations/operation-1234567894561-5ec69948c0f2b-60dd727f-a9b97a2e
    • PROJECT_ID: Google Cloud 專案。
    • LOCATION:執行個體所在的區域。

    請記錄 OPERATION_NAME,因為您需要使用這個 ID 檢查作業狀態。

    建立執行個體最多需要 60 分鐘。

    檢查建立作業的狀態

    使用任何要求資料之前,請先替換以下項目:

    • OPERATION_NAME:建立指令回應中的作業名稱。

    HTTP 方法和網址:

    GET https://securesourcemanager.googleapis.com/v1/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": "2024-10-28T15:37:39.009812863Z",
        "endTime": "2024-10-28T16:10:58.416640259Z",
        "target": "projects/my-project/locations/us-central1/instances/my-instance",
        "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/my-instance",
        "createTime": "2024-10-28T15:37:39.004550840Z",
        "updateTime": "2024-10-28T15:37:39.867857246Z",
        "state": "ACTIVE",
        "hostConfig": {
          "html": "my-instance-326202322590.us-central1.sourcemanager.dev",
          "api": "my-instance-326202322590-api.us-central1.sourcemanager.dev",
          "gitHttp": "my-instance-326202322590-git.us-central1.sourcemanager.dev",
          "gitSsh": "my-instance-326202322590-ssh.us-central1.sourcemanager.dev"
        },
        "workforceIdentityFederationConfig": {
          "enabled": true
        }
      }
    

    其中 my-instance-098765432109.us-central1.sourcemanager.dev 是執行個體 HTML 網址。

    從成功建立的檢查狀態回應中複製 HTML 網址。您需要這個網址,才能透過網頁介面存取執行個體。

    存取執行個體

    建立執行個體後,您可以使用瀏覽器透過網頁介面存取該執行個體。

    1. 如要透過網頁介面存取 Secure Source Manager 執行個體,請將下列網址複製到瀏覽器的網址列。

      INSTANCE_ID-PROJECT_NUMBER.LOCATION.sourcemanager.dev

      取代下列項目:

      • INSTANCE_ID 替換為執行個體名稱。
      • PROJECT_NUMBER 換成執行個體的 Google Cloud 專案編號。如要瞭解如何識別專案,請參閱「識別專案」。
      • LOCATION,其中包含執行個體的所在地區。

      系統會顯示 OAuth 畫面,要求您提供供應商名稱。

    2. 請按照以下格式輸入工作團隊身分識別提供者名稱:

      locations/global/workforcePools/POOL_ID/providers/PROVIDER_ID
      

      更改下列內容:

      • POOL_ID,並提供員工身分聯盟集區 ID。
      • PROVIDER_ID 替換為員工身分聯盟提供者 ID。

      如要進一步瞭解員工身分聯盟集區和提供者,請參閱「管理員工身分聯盟身分集區和提供者」。

      系統會提示您使用供應商憑證登入。

    3. 使用供應商憑證登入。

    4. Secure Source Manager 網頁介面隨即開啟。您可以在網頁介面中建立及查看存放區,以及所有相關聯的問題和提取要求。

      在您設定的員工身分聯盟集區工作階段持續時間到期後,您必須透過網頁介面重新登入。

    建立 gcloud CLI 登入設定

    如要使用 gcloud CLI 指令或 Git 指令,透過工作團隊身分識別集區憑證向 Secure Source Manager 執行個體進行驗證,您必須使用工作團隊身分識別集區建立登入設定。

    如要建立工作團隊身分集區登入設定,請按照「取得員工身分聯盟的短期權杖」一文中的操作說明,使用 gcloud CLI 建立瀏覽器型登入程序。

    完成驗證後,您可以使用 Git 指令與 Secure Source Manager 執行個體互動。如要開始使用 Git,請按照「使用 Git 原始碼管理」中的操作說明進行。

    後續步驟