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

瞭解如何建立 Secure Source Manager 執行個體,並透過外部身分識別資訊提供者 (IdP) 使用員工身分聯盟。

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

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

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

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

事前準備

  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. 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.enable permission. 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.

    Enable the API

  4. Install the Google Cloud CLI.

  5. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  6. To initialize the gcloud CLI, run the following command:

    gcloud init
  7. 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

  8. 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.enable permission. 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.

    Enable the API

  9. Install the Google Cloud CLI.

  10. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  11. To initialize the gcloud CLI, run the following command:

    gcloud init

資料加密

根據預設, 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 是您建立 Secure Source Manager 執行個體的專案 ID。

建立 Secure Source Manager 服務代理後,必須將 Secure Source Manager 服務代理角色 (roles/securesourcemanager.serviceAgent) 授予主體 service-PROJECT-NUMBER@gcp-sa-sourcemanager.iam.gserviceaccount.com,否則執行個體建立作業會失敗。

設定員工身分聯盟

建立執行個體前,必須先設定員工身分聯盟集區和提供者。

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

  2. 使用下列屬性對應設定員工身分集區提供者:

    • google.subject
    • google.email

建立執行個體

gcloud

使用下列任何指令資料前,請先替換以下項目:

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

執行下列指令:

Linux、macOS 或 Cloud Shell

gcloud source-manager instances create INSTANCE_ID --region=LOCATION --project=PROJECT_ID --enable-workforce-identity-federation

Windows (PowerShell)

gcloud source-manager instances create INSTANCE_ID --region=LOCATION --project=PROJECT_ID --enable-workforce-identity-federation

Windows (cmd.exe)

gcloud source-manager instances create INSTANCE_ID --region=LOCATION --project=PROJECT_ID --enable-workforce-identity-federation

系統會開始執行長時間的建立執行個體作業。輸出內容如下:

  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。

請記下 OPERATION_NAME,因為您需要使用這項資訊來檢查作業狀態。

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

API

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

  • 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,因為您需要使用該值來檢查作業狀態。

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

Terraform

下列範例會建立已啟用員工身分聯盟的 Secure Source Manager 執行個體:

resource "google_secure_source_manager_instance" "instance" {
  instance_id = "INSTANCE_ID"
  location    = "LOCATION"
  project     = "PROJECT_ID"
  workforce_identity_federation_config {
    enabled = true
  }
}

查看作業狀態

gcloud

使用下列任何指令資料之前,請先替換以下項目:

  • OPERATION_NAME:create 指令回應中的作業名稱。
  • LOCATION:執行個體區域。

執行下列指令:

Linux、macOS 或 Cloud Shell

gcloud source-manager operations describe OPERATION_NAME --region=LOCATION

Windows (PowerShell)

gcloud source-manager operations describe OPERATION_NAME --region=LOCATION

Windows (cmd.exe)

gcloud source-manager operations describe OPERATION_NAME --region=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/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": "2022-11-01T14:31:32.416413630Z",
    "updateTime": "2022-11-01T14:31:32.416413630Z",
    "labels": {
      "ldap": "user",
      "source": "manual"
    },
    "state": "ACTIVE",
    "hostConfig": {
      "html": "my-instance-098765432109.us-central1.sourcemanager.dev",
      "api": "my-instance-098765432109-api.us-central1.sourcemanager.dev",
      "gitHttp": "my-instance-098765432109-git.us-central1.sourcemanager.dev"
    }
  }

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

API

使用任何要求資料之前,請先修改下列項目的值:

  • 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 原始碼管理」。

後續步驟