整合 Assured OSS,確保程式碼安全無虞

Assured Open Source Software (Assured OSS) 進階層級可讓您使用 Google 自家開發人員工作流程所用的 OSS 套件,提升程式碼安全性。使用 Assured OSS 時,開發人員可以運用 Google 用於保護自家開放原始碼依附元件的資安專業知識和經驗。

整合 Assured OSS 與 Security Command Center 後,您可以執行下列操作:

  • 從數千個精選和最熱門的 Java 和 Python 套件中選擇,包括 TensorFlow、Pandas 和 Scikit-learn 等常見的機器學習和人工智慧專案。
  • 設定安全 Proxy,從 Assured OSS 下載所有附有認證的 Java、Python 和 JavaScript 套件,讓 Google 成為您已知且信任的供應商。
  • 使用可信 OSS 中以 SPDX 和 CycloneDX 等業界標準格式提供的 SBOM 和 VEX,進一步瞭解要素。
  • 透過 Google 簽署的防竄改來源,提高您所用套件完整性的可信度。
  • Google 會主動掃描、找出並修正精選套件中的新安全漏洞,因此可降低安全風險。

事前準備

請先完成這些工作,再完成本頁面上的其餘工作。

啟用 Security Command Center Enterprise 級別

確認Security Command Center Enterprise 方案已在機構層級啟用,且您已完成設定指南中的前六個步驟。

設定機構層級的權限

您必須在機構層級和專案層級設定權限。

  1. Make sure that you have the following role or roles on the organization: Security Center Admin, Organization Admin

    Check for the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the organization.
    3. In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.

    4. For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.

    Grant the roles

    1. In the Google Cloud console, go to the IAM page.

      前往「IAM」頁面
    2. 選取機構。
    3. 按一下「授予存取權」
    4. 在「New principals」(新增主體) 欄位中,輸入您的使用者 ID。 這通常是 Google 帳戶的電子郵件地址。

    5. 在「Select a role」(選取角色) 清單中,選取角色。
    6. 如要授予其他角色,請按一下 「新增其他角色」,然後新增每個其他角色。
    7. 按一下 [Save]

    設定專案層級權限

    1. Make sure that you have the following role or roles on the project: Service Usage Admin, Service Account Admin, Project IAM Admin

      Check for the roles

      1. In the Google Cloud console, go to the IAM page.

        Go to IAM
      2. Select the project.
      3. In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.

      4. For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.

      Grant the roles

      1. In the Google Cloud console, go to the IAM page.

        前往「IAM」頁面
      2. 選取專案。
      3. 按一下「授予存取權」
      4. 在「New principals」(新增主體) 欄位中,輸入您的使用者 ID。 這通常是 Google 帳戶的電子郵件地址。

      5. 在「Select a role」(選取角色) 清單中,選取角色。
      6. 如要授予其他角色,請按一下 「新增其他角色」,然後新增每個其他角色。
      7. 按一下 [Save]

      設定 Google Cloud CLI

      In the Google Cloud console, activate Cloud Shell.

      Activate Cloud Shell

      At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.

      設定 Assured OSS

      主控台

      1. 在 Google Cloud 控制台中,前往 Security Command Center 設定指南

        前往設定指南

      2. 確認您正在查看啟用 Security Command Center Enterprise 級別的機構。

      3. 展開「查看安全功能摘要」面板。

      4. 依序點選「程式碼安全防護」>「設定」

      5. 在「設定程式碼安全防護機制」面板中,按一下「AOSS 設定」

      6. 選取新的服務帳戶,或選取要新增 Assured Open Source Software 權限的現有服務帳戶。

      7. 選取要尋找 Assured OSS 資源的 Google Cloud 專案。

      8. 按一下「設定 Assured OSS」

        設定程序會自動完成下列事項:

        • 如果選取這個選項,系統會建立新的服務帳戶 assuredoss@PROJECT_ID.gservicesaccount.com
        • 將 Assured OSS 使用者角色指派給專用服務帳戶,以便搭配 Assured OSS 使用。
        • 將 Assured OSS 管理員角色指派給登入的使用者帳戶,讓該帳戶可以設定服務。
        • 啟用 Assured Open Source Software API,以及 (如果尚未啟用) Artifact Registry API。
        • 在所選專案的 Artifact Registry 執行個體中,設定 Assured OSS Proxy 服務。系統會為每種語言 (Java、Python 和 JavaScript) 提供存放區。這些存放區可以從精選組合自動提取套件。如果套件不屬於精選組合,存放區會將要求重新導向至標準存放區。Proxy 服務僅支援美國區域。
        • 授予您和服務帳戶權限,讓您可以存取 Google 自有專案的套件中繼資料和通知。
      9. 為每個指定的 Assured OSS 服務帳戶建立服務帳戶金鑰,並以 JSON 格式下載金鑰。

      10. 在本機電腦的指令列中,對下載的金鑰檔案執行下列指令,取得經過 Base64 編碼的字串:

        base64 KEY_FILENAME.json
        

        KEY_FILENAME.json 替換為您下載的服務帳戶金鑰名稱。

        設定 Assured OSS 的遠端存放區時,您需要使用 Base64 編碼字串。

      11. 如要下載套件,請使用 Assured OSS 為每種語言佈建的端點。請記下這些端點,以供後續使用。

        • Java:
          https://us-maven.pkg.dev/PROJECT_ID/assuredoss-java
        • Python:
          https://us-python.pkg.dev/PROJECT_ID/assuredoss-python
        • JavaScript:
          https://us-npm.pkg.dev/PROJECT_ID/assuredoss-javascript

        PROJECT_ID 替換為設定 Assured OSS 時選取的專案 ID。

      12. 點選「下一步」使用貴機構的構件存放區管理工具 (例如 JFrog Artifactory 或 Sonatype Nexus) 設定 Assured OSS

      gcloud

      1. 使用要啟用 Assured OSS 的使用者帳戶進行驗證: Google Cloud

        gcloud auth revoke
        gcloud auth application-default revoke
        gcloud auth login
        
      2. 搜尋要尋找 Assured OSS 資源的專案:

        gcloud alpha projects search --query="displayName=PROJECT_NAME"
        

        PROJECT_NAME 替換為專案名稱。

      3. 設定要尋找 Assured OSS 資源的專案:

        gcloud config set project PROJECT_ID
        

        PROJECT_ID 替換為專案 ID。

      4. 將角色授予使用者帳戶,以設定 Assured OSS:

        gcloud projects add-iam-policy-binding PROJECT_ID \
          --member=user:email@domain.com \
          --role=roles/assuredoss.admin
        
        gcloud projects add-iam-policy-binding PROJECT_ID \
          --member=user:email@domain.com \
          --role=roles/serviceusage.serviceUsageAdmin
        
        gcloud projects add-iam-policy-binding PROJECT_ID \
          --member=user:email@domain.com \
          --role=roles/iam.serviceAccountAdmin
        

        其中 email@domain.com 是使用者帳戶的電子郵件地址。

      5. 在專案中啟用 Assured OSS。啟用 Assured OSS 時,系統也會啟用 Artifact Registry API。

        gcloud services enable assuredoss.googleapis.com
        
      6. 如要為 Assured OSS 建立新的服務帳戶,而非使用現有服務帳戶,請完成下列步驟:

        gcloud iam service-accounts create SERVICE_ACCOUNT_NAME \
          --description="Service account for using Assured OSS"
          --display-name="Assured OSS service account"
        

        SERVICE_ACCOUNT_NAME 替換為服務帳戶名稱 (例如 assuredoss)。

      7. 設定 Assured OSS 的服務帳戶:

        gcloud projects add-iam-policy-binding PROJECT_ID \
          --member=serviceAccount:SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com \
          --role roles/assuredoss.user
        

        更改下列內容:

        • SERVICE_ACCOUNT_NAME:服務帳戶的名稱 (例如 assuredoss)。
        • PROJECT_ID:專案 ID。
      8. 建立 Assured OSS 存放區,在 Artifact Registry 執行個體中設定 Assured OSS Proxy 服務。您必須為所有語言建立存放區。供應存放區的 Assured OSS 代理服務僅支援美國地區。

        alias gcurlj='curl -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json" -X'
        
        gcurlj POST https://artifactregistry.googleapis.com/v1/projects/PROJECT_ID/locations/us/repositories\?repositoryId\=assuredoss-java   -d '{"format": "MAVEN", "mode": "AOSS_REPOSITORY"}'
        
        gcurlj POST https://artifactregistry.googleapis.com/v1/projects/PROJECT_ID/locations/us/repositories\?repositoryId\=assuredoss-javascript   -d '{"format": "NPM", "mode": "AOSS_REPOSITORY"}'
        
        gcurlj POST https://artifactregistry.googleapis.com/v1/projects/PROJECT_ID/locations/us/repositories\?repositoryId\=assuredoss-python   -d '{"format": "PYTHON", "mode": "AOSS_REPOSITORY"}'
        

        PROJECT_ID 替換為設定 Assured OSS 時選取的專案 ID。

        這些存放區可以從精選組合自動提取套件。如果套件未納入精選組合,存放區會將要求重新導向至標準存放區。

      9. 為每個 Assured OSS 服務帳戶建立服務帳戶金鑰,並以 JSON 格式下載金鑰。

      10. 在指令列中,對下載的金鑰檔案執行下列指令,取得 base64 編碼字串:

        base64 KEY_FILENAME.json
        

        KEY_FILENAME.json 替換為您下載的服務帳戶金鑰名稱。

        設定 Assured OSS 的遠端存放區時,您需要使用 Base64 編碼字串。

      11. 如要下載套件,請使用 Assured OSS 為各語言佈建的端點。請記下這些端點:

        • Java:
          https://us-maven.pkg.dev/PROJECT_ID/assuredoss-java
        • Python:
          https://us-python.pkg.dev/PROJECT_ID/assuredoss-python
        • JavaScript:
          https://us-npm.pkg.dev/PROJECT_ID/assuredoss-javascript

        PROJECT_ID 替換為設定 Assured OSS 時選取的專案 ID。

      12. 設定 Assured OSS,透過貴機構的構件存放區管理工具 (例如 JFrog Artifactory 或 Sonatype Nexus) 下載套件。

      13. 視需要查看可用的 Java、Python 和 JavaScript 套件:

        gcloud auth revoke
        gcloud auth application-default revoke
        gcloud auth login --cred-file=KEY_FILENAME.json
        

        KEY_FILENAME.json 替換為您下載的服務帳戶金鑰名稱。

        export GOOGLE_APPLICATION_CREDENTIALS=KEY_FILENAME.json
        

        KEY_FILENAME.json 替換為您下載的服務帳戶金鑰名稱。

        gcurlj GET "https://artifactregistry.googleapis.com/v1/projects/PROJECT_ID/locations/us/repositories/assuredoss-java/packages"
        gcurlj GET "https://artifactregistry.googleapis.com/v1/projects/PROJECT_ID/locations/us/repositories/assuredoss-python/packages"
        gcurlj GET "https://artifactregistry.googleapis.com/v1/projects/PROJECT_ID/locations/us/repositories/assuredoss-javascript/packages"
        

        PROJECT_ID 替換為設定 Assured OSS 時選取的專案 ID。

      後續步驟