將 Scout 用於不同構件類型
某些 Docker Scout CLI 命令支援用於指定您要分析的構件位置或類型的前綴。
根據預設,使用 docker scout cves
命令進行映像檔分析的目標是 Docker 引擎本機映像檔存放區中的映像檔。如果映像檔存在於本機,則下列命令一律使用本機映像檔
$ docker scout cves <image>
如果映像檔在本機不存在,Docker 會在執行分析之前提取映像檔。根據預設,再次分析相同的映像檔會使用相同的本機版本,即使儲存庫中的標籤已變更。
透過在映像檔參考中新增 registry://
前綴,您可以強制 Docker Scout 分析映像檔的儲存庫版本
$ docker scout cves registry://<image>
支援的前綴
支援的前綴如下
前綴 | 說明 |
---|---|
image:// (預設) | 使用本機映像檔,或改為查閱儲存庫 |
local:// | 使用本機映像檔存放區中的映像檔 (不要查閱儲存庫) |
registry:// | 使用儲存庫中的映像檔 (不要使用本機映像檔) |
oci-dir:// | 使用 OCI 佈局目錄 |
archive:// | 使用 docker save 建立的壓縮檔 |
fs:// | 使用本機目錄或檔案 |
您可以將前綴與下列命令搭配使用
docker scout compare
docker scout cves
docker scout quickview
docker scout recommendations
docker scout sbom
範例
本節包含一些範例,說明如何使用前綴為 docker scout
命令指定構件。
分析本機專案
fs://
前綴可讓您直接分析本機原始碼,而無需將其建置到容器映像檔中。下列 docker scout quickview
命令提供您目前工作目錄中原始碼的弱點摘要概覽
$ docker scout quickview fs://.
若要檢視在本機原始碼中找到的弱點詳細資訊,您可以使用 docker scout cves --details fs://.
命令。將其與其他旗標組合,以將結果縮小到您感興趣的套件和弱點。
$ docker scout cves --details --only-severity high fs://.
✓ File system read
✓ Indexed 323 packages
✗ Detected 1 vulnerable package with 1 vulnerability
## Overview
│ Analyzed path
────────────────────┼──────────────────────────────
Path │ /Users/david/demo/scoutfs
vulnerabilities │ 0C 1H 0M 0L
## Packages and Vulnerabilities
0C 1H 0M 0L fastify 3.29.0
pkg:npm/fastify@3.29.0
✗ HIGH CVE-2022-39288 [OWASP Top Ten 2017 Category A9 - Using Components with Known Vulnerabilities]
https://scout.docker.com/v/CVE-2022-39288
fastify is a fast and low overhead web framework, for Node.js. Affected versions of
fastify are subject to a denial of service via malicious use of the Content-Type
header. An attacker can send an invalid Content-Type header that can cause the
application to crash. This issue has been addressed in commit fbb07e8d and will be
included in release version 4.8.1. Users are advised to upgrade. Users unable to
upgrade may manually filter out http content with malicious Content-Type headers.
Affected range : <4.8.1
Fixed version : 4.8.1
CVSS Score : 7.5
CVSS Vector : CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
1 vulnerability found in 1 package
LOW 0
MEDIUM 0
HIGH 1
CRITICAL 0
將本機專案與映像檔進行比較
使用 docker scout compare
,您可以比較本機檔案系統上原始碼的分析與容器映像檔的分析。下列範例比較本機原始碼 (fs://.
) 與儲存庫映像檔 registry://docker/scout-cli:latest
。在本例中,比較的基準和目標都使用前綴。
$ docker scout compare fs://. --to registry://docker/scout-cli:latest --ignore-unchanged
WARN 'docker scout compare' is experimental and its behaviour might change in the future
✓ File system read
✓ Indexed 268 packages
✓ SBOM of image already cached, 234 packages indexed
## Overview
│ Analyzed File System │ Comparison Image
─────────────────────────┼────────────────────────────────────────────────┼─────────────────────────────────────────────
Path / Image reference │ /Users/david/src/docker/scout-cli-plugin │ docker/scout-cli:latest
│ │ bb0b01303584
platform │ │ linux/arm64
provenance │ https://github.com/dvdksn/scout-cli-plugin.git │ https://github.com/docker/scout-cli-plugin
│ 6ea3f7369dbdfec101ac7c0fa9d78ef05ffa6315 │ 67cb4ef78bd69545af0e223ba5fb577b27094505
vulnerabilities │ 0C 0H 1M 1L │ 0C 0H 1M 1L
│ │
size │ 7.4 MB (-14 MB) │ 21 MB
packages │ 268 (+34) │ 234
│ │
## Packages and Vulnerabilities
+ 55 packages added
- 21 packages removed
213 packages unchanged
前一個範例為了簡潔起見而截斷。
檢視映像檔壓縮檔的 SBOM
下列範例顯示如何使用 archive://
前綴來取得使用 docker save
建立的映像檔壓縮檔的 SBOM。在本例中,映像檔為 docker/scout-cli:latest
,SBOM 以 SPDX 格式匯出到檔案 sbom.spdx.json
。
$ docker pull docker/scout-cli:latest
latest: Pulling from docker/scout-cli
257973a141f5: Download complete
1f2083724dd1: Download complete
5c8125a73507: Download complete
Digest: sha256:13318bb059b0f8b0b87b35ac7050782462b5d0ac3f96f9f23d165d8ed68d0894
$ docker save docker/scout-cli:latest -o scout-cli.tar
$ docker scout sbom --format spdx -o sbom.spdx.json archive://scout-cli.tar
深入瞭解
在 CLI 參考文件中閱讀有關命令和支援旗標的資訊