自動掃描 OS 套件
瞭解如何啟用自動掃描功能、將容器映像檔推送到 Artifact Registry,以及查看映像檔中發現的安全漏洞清單。
每當映像檔推送至 Artifact Registry 時,Artifact Analysis 就會掃描安全漏洞。平台管理員和應用程式開發人員可以使用這項自動掃描功能,協助找出軟體交付流程中的風險。
本快速入門導覽課程會使用簡單的公開套件,示範其中一種套件掃描類型。根據預設,啟用掃描 API 後,Artifact Analysis 會掃描多種套件類型的安全漏洞。支援的套件類型包括:OS、Go、Java (Maven)、Python 和 Node.js (npm)。
事前準備
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
- 
      Install the Google Cloud CLI. 
- 
          如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI。 
- 
        如要初始化 gcloud CLI,請執行下列指令: gcloud init
- 
  
  
    Create or select 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
      (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
 - 
        Create a Google Cloud project: gcloud projects create PROJECT_ID Replace PROJECT_IDwith a name for the Google Cloud project you are creating.
- 
        Select the Google Cloud project that you created: gcloud config set project PROJECT_ID Replace PROJECT_IDwith your Google Cloud project name.
 
- 
  
    Verify that billing is enabled for your Google Cloud project. 
- 
  
  
    
      Enable the Artifact Registry and Container Scanning APIs: Roles required to enable APIs To enable APIs, you need the Service Usage Admin IAM role ( roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.gcloud services enable containerscanning.googleapis.com artifactregistry.googleapis.com 
- 
      Install the Google Cloud CLI. 
- 
          如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI。 
- 
        如要初始化 gcloud CLI,請執行下列指令: gcloud init
- 
  
  
    Create or select 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
      (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
 - 
        Create a Google Cloud project: gcloud projects create PROJECT_ID Replace PROJECT_IDwith a name for the Google Cloud project you are creating.
- 
        Select the Google Cloud project that you created: gcloud config set project PROJECT_ID Replace PROJECT_IDwith your Google Cloud project name.
 
- 
  
    Verify that billing is enabled for your Google Cloud project. 
- 
  
  
    
      Enable the Artifact Registry and Container Scanning APIs: Roles required to enable APIs To enable APIs, you need the Service Usage Admin IAM role ( roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.gcloud services enable containerscanning.googleapis.com artifactregistry.googleapis.com 
- 在 Google Cloud 控制台中開啟「Repositories」(存放區) 頁面。 
- 點選 [Create Repository] (建立存放區)。 
- 在「Create Repository」(建立存放區) 頁面中,輸入下列設定: - Name (名稱):quickstart-docker-repo
- 格式:Docker
- 模式:標準
- 位置類型:區域
- Region (區域):us-central1
 
- Name (名稱):
- 點選「建立」。 
- 切換至要儲存容器映像檔的目錄。 
- 將圖片複製到本機目錄。舉例來說,您可以使用 Docker 從 Docker Hub 提取最新版 Ubuntu 映像檔。 - docker pull ubuntu:latest
- PROJECT 是您的 Google Cloud
專案 ID。
如果您的專案 ID 包含冒號 (:),請參閱網域範圍專案。
- us-central1是 Artifact Registry 存放區的區域。
- docker.pkg.dev是 Docker 存放區的主機名稱。
- quickstart-image是您要用於存放區的映像檔名稱。 可以使用和本機映像檔不同的名稱。
- tag1是您要新增至 Docker 映像檔的標記。如果您沒有指定標記,Docker 會套用預設標記- latest。
- 在 Artifact Analysis 控制台中開啟 Artifact Registry 存放區清單。 
- 在存放區清單中,按一下存放區。 
- 按一下映像檔名稱。 - 畫面上會顯示圖片的摘要清單。 - 每個映像檔摘要的安全漏洞總數會顯示在「Vulnerabilities」(安全漏洞) 資料欄中。   
- 按一下「Vulnerabilities」(安全漏洞) 欄中連結的安全漏洞總數。 - 系統隨即會顯示安全漏洞清單。   - 安全漏洞清單會顯示這張圖片的掃描次數、安全漏洞嚴重程度、修正可用性、內含安全漏洞的套件名稱和套件類型。 
- 如要深入瞭解安全漏洞來源的特定安全漏洞,請按一下「Name」(名稱) 資料欄中的 CVE 識別碼連結。 
在 Artifact Registry 中建立 Docker 存放區
您必須建立 Docker 存放區,以便儲存本快速入門導覽課程所用的範例映像檔。
畫面會顯示「Repositories」頁面。quickstart-docker-repo 存放區會新增至存放區清單。
設定驗證機制
如要使用 Artifact Registry 推送或提取映像檔,請先設定 Docker,透過 Google Cloud CLI 驗證傳送至 Artifact Registry 的要求。
在 Cloud Shell 或本機殼層中,為 us-central1 區域的 Docker 存放區設定驗證機制:
gcloud auth configure-docker us-central1-docker.pkg.dev
取得套件
使用存放區名稱為套件加上標記
如要將套件推送至 Artifact Registry,您需要設定 docker push 指令,將映像檔推送至特定位置。
執行下列指令,將映像檔標記為 quickstart-image:tag1:
docker tag ubuntu:latest \ us-central1-docker.pkg.dev/PROJECT/quickstart-docker-repo/quickstart-image:tag1
地點
將映像檔推送至 Artifact Registry
將新的映像檔上傳至 Artifact Registry 時,容器分析會自動掃描這些映像檔。
如要將映像檔推送至 Artifact Registry 中的 Docker 存放區,請執行下列指令:
docker push us-central1-docker.pkg.dev/PROJECT/quickstart-docker-repo/quickstart-image:tag1
將 PROJECT 替換為 Google Cloud專案 ID。如果您的專案 ID 包含冒號 (:),請參閱網域範圍專案。
查看安全漏洞掃描結果
如要查看映像檔中的安全漏洞:
查看結果的其他方式
控制台最多會顯示 1200 個安全漏洞。 Google Cloud 如果映像檔有超過 1200 個安全漏洞,請使用 gcloud 或 API 查看完整清單。
清除所用資源
如要避免系統向您的 Google Cloud 帳戶收取本頁面所用資源的費用,請刪除含有這些資源的 Google Cloud 專案。
如果您是為了本指南建立新專案,現在可以刪除該專案。Delete a Google Cloud project:
gcloud projects delete PROJECT_ID