本文档介绍了如何启用 Container Scanning API、将映像推送到 Artifact Registry,以及查看映像中发现的漏洞列表。
Artifact Analysis 会将漏洞信息存储为 备注。Container Analysis 会为与映像相关联的备注的每个实例创建一个 发生实例。如需了解详情,请参阅 概览和 价格文档。
准备工作
- 登录您的 Google Cloud 账号。如果您是新手 Google Cloud, 请创建一个账号来评估我们的产品在 实际场景中的表现。新客户还可获享 $300 赠金,用于 运行、测试和部署工作负载。
-
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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
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
serviceusage.services.enablepermission. 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.-
安装 Google Cloud CLI。
-
如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI。
-
如需初始化 gcloud CLI,请运行以下命令:
gcloud init -
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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
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
serviceusage.services.enablepermission. 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.-
安装 Google Cloud CLI。
-
如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI。
-
如需初始化 gcloud CLI,请运行以下命令:
gcloud init - 在 Artifact Registry 中创建 Docker 代码库,并将包含 npm 代码的容器映像推送到该代码库。如果您不熟悉
Artifact Registry,请参阅
Docker 快速入门。
查看映像漏洞
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 控制台中查看发生实例
如需查看映像中的漏洞,请执行以下操作:
获取代码库列表。
在代码库列表中,点击一个代码库。
在映像列表中,点击映像名称。
每个映像摘要的漏洞总数将显示在漏洞 列中。
如需查看映像的漏洞列表,请点击漏洞 列中的链接。
扫描结果 部分会显示扫描的软件包类型、漏洞总数、可修复的漏洞、无法修复的漏洞和有效严重级别的摘要。
漏洞表会列出找到的每个漏洞的常见漏洞和披露 (CVE) 名称、 有效严重级别、 常见漏洞评分系统 (CVSS) 得分、修复(如果可用)、 包含漏洞的软件包的名称以及软件包 类型。
Google Cloud 控制台在此表中每页最多显示 1200 个漏洞。您可以过滤和排序这些文件,以按文件扩展名检查特定文件、目录、层或文件类型。
如需了解特定 CVE 的详细信息,请点击 CVE 名称。
如需查看漏洞发生实例详情(例如版本号和受影响的位置),请在包含漏洞名称的行中,点击查看 或查看已修复 。对于没有修复的漏洞,链接文本为查看 ;对于已应用修复的漏洞,链接文本为查看已修复 。
查看特定层中的漏洞
Artifact Analysis 提供特定于层的元数据,以帮助您确定哪个软件包包含漏洞,以及哪个 Docker 构建命令引入了该层。如需在 Google Cloud 控制台中查看基于层的漏洞元数据,请执行以下操作:
在 Artifact Registry 中,打开您的代码库列表。
在代码库 页面中,点击一个代码库。
在代码库详情 页面中,点击一个映像。
在映像版本列表中,点击一个映像摘要。
在映像摘要详情页面中,点击漏洞 标签页。
当基于层的元数据可用时,Artifact Analysis 会在层 栏中显示可选择的层列表:
如需查看层列表,请点击层下拉菜单。
系统会打开一个下拉列表,其中显示了编号列表的层。第 0 层代表底层,后续每一层均在前一层的基础上构建。系统只会显示已发现漏洞的层。
对于每个层,Artifact Analysis 都会显示用于构建该层的 Docker 命令以及在该层中发现的漏洞数量。
如需详细了解特定层中的漏洞,请从层列表中选择一个层。
漏洞表会更新为仅显示在所选层中发现的漏洞。您可以应用更多过滤条件或调查特定漏洞。
点击漏洞旁边的查看 或查看修复 ,以查看更详细的漏洞信息。
漏洞详情 侧边栏会显示软件包存在漏洞的文件位置。
在文件位置 表中,将鼠标悬停在问号上以打开其他层元数据。
对话框会显示层索引、层构建命令、层摘要和基本映像,您可以在其中修复漏洞。
使用 gcloud 查看发生实例
如需查看 Artifact Registry 中映像的发生实例,请运行
gcloud artifacts docker images list
命令:
gcloud artifacts docker images list --show-occurrences \
LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE_ID
其中:
- LOCATION 是代码库的单区域或多区域 位置。
- PROJECT_ID 是您的 Google Cloud 控制台 项目 ID。
- REPOSITORY 是存储了映像 的代码库的名称。
- IMAGE_ID 是代码库中的映像名称。 您无法使用此命令指定映像标记。
默认情况下,该命令会返回 10 个最新结果。如需显示不同数量的结果,请使用 --show-occurrences-from
标志。
例如,以下命令会返回 25 个最新结果:
gcloud artifacts docker images list --show-occurrences-from=25 \
us-central1-docker.pkg.dev/my-project/my-repo/my-image
输出类似于:
映像输出示例
{
"name": "projects/my-project/locations/us-central1/occurrences/22d3edfb-34f2-4d3f-be08-fd90c549f010",
"resource": {
"uri": "https://us-central1-docker.pkg.dev/my-project/my-repo/golang-nginx@sha256:5b54ef20748417ccdb0b87afedf98c44e699e2f59bd6cv48cbdc1ca2e72c80e3"
},
"noteName": "projects/my-project/locations/us-central1/notes/CVE-2005-2541",
"kind": "VULNERABILITY",
"createTime": "2025-01-21T15:57:01.238832Z",
"updateTime": "2025-01-21T15:57:01.238832Z",
"vulnerability": {
"severity": "CRITICAL",
"cvssScore": 10,
"packageIssue": [
{
"affectedLocation": {
"cpeUri": "cpe:/o:debian:debian_linux:12",
"package": "tar",
"version": {
"name": "1.34+dfsg",
"revision": "1.2+deb12u1",
"kind": "NORMAL"
}
},
"fixedLocation": {
"cpeUri": "cpe:/o:debian:debian_linux:12",
"package": "tar",
"version": {
"kind": "MAXIMUM"
}
},
"packageType": "OS",
"effectiveSeverity": "LOW",
"file_location": [
{
"file_path": "/var/lib/dpkg/status",
"layerDetails": {
"index": 0,
"diffID": "sha256:123",
"buildCommand": "FROM golang:example_sha256",
"BaseImages": [
{
"name": "library/golang",
},
],
},
},
],
}
],
"shortDescription": "CVE-2005-2541",
"longDescription": "NIST vectors: AV:N/AC:L/Au:N/C:C/I:C/A:C",
"relatedUrls": [
{
"url": "https://security-tracker.debian.org/tracker/CVE-2005-2541",
"label": "More Info"
}
],
"effectiveSeverity": "LOW",
"cvssVersion": "CVSS_VERSION_2",
"cvssV2": {
"baseScore": 10,
"attackVector": "ATTACK_VECTOR_NETWORK",
"attackComplexity": "ATTACK_COMPLEXITY_LOW",
"authentication": "AUTHENTICATION_NONE",
"confidentialityImpact": "IMPACT_COMPLETE",
"integrityImpact": "IMPACT_COMPLETE",
"availabilityImpact": "IMPACT_COMPLETE"
}
}
}
过滤漏洞事件
如需过滤漏洞事件,请使用 --occurrence-filter 参数:
gcloud artifacts docker images list --show-occurrences \
LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE_ID \
--occurrence-filter=FILTER_EXPRESSION
其中: