自动扫描 Python 软件包

本文档介绍了如何启用 Container Scanning API、将映像推送到 Artifact Registry,以及查看映像中发现的漏洞列表。

Artifact Analysis 会将漏洞信息存储为备注。Container Analysis 会为与映像相关联的备注的每个实例创建一个发生实例。如需了解详情,请参阅概览价格文档。

准备工作

  1. 登录您的 Google Cloud 账号。如果您是 Google Cloud新手,请 创建一个账号来评估我们的产品在实际场景中的表现。新客户还可获享 $300 赠金,用于运行、测试和部署工作负载。
  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 Artifact Registry and Container Scanning APIs.

    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 APIs

  5. 安装 Google Cloud CLI。

  6. 如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI

  7. 如需初始化 gcloud CLI,请运行以下命令:

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

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

  10. Enable the Artifact Registry and Container Scanning APIs.

    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 APIs

  11. 安装 Google Cloud CLI。

  12. 如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI

  13. 如需初始化 gcloud CLI,请运行以下命令:

    gcloud init
  14. 在 Artifact Registry 中创建 Docker 代码库,并将包含 Python 代码的容器映像推送到该代码库。如果您不熟悉 Artifact Registry,请参阅 Docker 快速入门

    如需了解如何使用 Cloud Build 构建 Python 应用并将其容器化,请参阅 构建、测试和容器化 Python 应用

查看映像漏洞

Artifact Analysis 会在新映像上传到 Artifact Registry 时扫描这些映像。此扫描可提取有关容器中软件包的信息。

您可以使用 Google Cloud 控制台、Google Cloud CLI 或 Container Analysis API 查看 Artifact Registry 中映像的漏洞事件。如果某个映像存在漏洞,您就可以获取详细信息。

只要映像和软件包是在过去 30 天内拉取的,Artifact Analysis 就会继续扫描它们。30 天后,扫描的映像和软件包的元数据将不再更新,并且结果将过时。

Artifact Analysis 会归档过时超过 90 天的元数据。只有使用 API 才能评估此归档的元数据。 您可以拉取包含过时或归档元数据的映像,以重新扫描该映像。 刷新元数据最多可能需要 24 小时。无法重新扫描具有过时或已归档元数据的软件包。

在 Google Cloud 控制台中查看出现次数

如需查看映像中的漏洞,请执行以下操作:

  1. 获取代码库列表。

    打开“代码库”页面

  2. 在代码库列表中,点击一个代码库。

  3. 在映像列表中,点击映像名称。

    每个映像摘要的漏洞总数将显示在漏洞列中。

    存在漏洞的扫描映像

  4. 如需查看映像的漏洞列表,请点击漏洞列中的链接。

    扫描结果部分会显示扫描的软件包类型、漏洞总数、有修复的漏洞、无修复的漏洞以及有效严重程度的摘要。

    “扫描结果”页面,其中列出了漏洞、修复和有效严重程度

    漏洞表格会列出发现的每个漏洞的常见漏洞和披露 (CVE) 名称、有效严重程度、通用漏洞评分系统 (CVSS) 评分、修复(如有)、包含漏洞的软件包的名称以及软件包类型。

    Google Cloud 控制台会在该表格中显示每个页面最多 1,200 个漏洞。您可以过滤和排序这些文件,以按文件扩展名检查特定文件、目录、图层或文件类型。

  5. 如需详细了解特定 CVE,请点击 CVE 名称。

  6. 如需查看漏洞出现详情(例如版本号和受影响的位置),请在包含漏洞名称的行中点击查看查看已修复。对于没有修复的漏洞,链接文字为查看;对于已应用修复的漏洞,链接文字为查看已修复

查看特定层中的漏洞

Artifact Analysis 提供特定于层的元数据,可帮助您确定哪个软件包包含漏洞,以及哪个 Docker build 命令引入了该层。

如需在 Google Cloud 控制台中查看基于层的漏洞元数据,请执行以下操作:

  1. 在 Artifact Registry 中,打开您的代码库列表。

    打开“代码库”页面

  2. 代码库页面中,点击一个代码库。

  3. 代码库详情页面中,点击某个映像。