LoginSignup
2
1

docker scoutでimageの脆弱性診断をしたりダッシュボードにアクセスしたり

Last updated at Posted at 2024-03-21

こんにちは。
株式会社クラスアクト インフラストラクチャ事業部の大塚です。

今回はdocker scoutを触れる環境を作っていきたいと思います。
本当は1つの記事ですべてやり切りたかったのですが、ちょっと長くなりそうでかつ夜にやり始めてすこぶる眠いので、この記事ではdocker scoutでdocker imageの脆弱性を診断し、Webダッシュボードにアクセスするところまでをやっていきたいと思います。脆弱性を修正するみたいな話もあるようなのでそれは後日確認していきます。

※2024/3/24
imageの修正方法を確認しました。

docker scoutとは?

公式ドキュメントには以下のように記載されております。
基本的に何を言っているのか全然わからないので、触ったほうが理解が進みそうです汗
ただ、他のサイトをざっと調べてみた感じdocker imageの脆弱性診断的なことができるようです。

コンテナ イメージはレイヤーとソフトウェア パッケージで構成されており、脆弱性の影響を受けやすくなります。これらの脆弱性により、コンテナーやアプリケーションのセキュリティが侵害される可能性があります。

Docker Scout は、ソフトウェア サプライ チェーンのセキュリティをプロアクティブに強化するためのソリューションです。Docker Scout はイメージを分析することにより、ソフトウェア部品表 (SBOM) とも呼ばれるコンポーネントのインベントリを作成します。SBOM は継続的に更新される脆弱性データベースと照合され、セキュリティの弱点を正確に特定します。

ここで記載されているSBOMとはSoftware Bill of Materialsの略らしく、これはソフトウェア製品/システムに含まれるコンポーネントや依存関係を文書化するためのフォーマットの様です。
docker imageはレイヤという概念?があるのですが、そこと関係があるのかなと思っています。

実際にChatGPTにヒアリングをしてみると以下のような回答をしてきます。

Docker イメージのレイヤーと SBOM は、どちらもソフトウェアの構成に関する情報を提供しますが、異なる観点からの情報を提供します。Docker イメージのレイヤーは、イメージの構築方法とファイルシステムの状態を表現しますが、SBOM はソフトウェアのコンポーネントや依存関係を文書化し、セキュリティやライセンスの側面に焦点を当てます。

参考サイト

構築には以下公式サイトを参考にしています。

構築

scout検証用のdocker imageをbuildしてhubにpushする

※docker及びdocker swarmが動作可能な環境の上にscout用の環境を作っていきます。

まずgithubからクローンしてディレクトリを移動します。

root@ohtsuka-swarm01:~# git clone https://github.com/docker/scout-demo-service.git
root@ohtsuka-swarm01:~# ls
scout-demo-service  snap
root@ohtsuka-swarm01:~# cd scout-demo-service/
root@ohtsuka-swarm01:~/scout-demo-service#

今回はCUI環境ですのでdocker loignをします
Login Succeededとなることを確認します。

root@ohtsuka-swarm01:~/scout-demo-service# docker login
Log in with your Docker ID or email address to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com/ to create one.
You can log in with your password or a Personal Access Token (PAT). Using a limited-scope PAT grants better security and is required for organizations using SSO. Learn more at https://docs.docker.com/go/access-tokens/

Username:●●●●
Password:●●●●
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

docker buildを実行してscoutのdemo imageをhubにpushします。
私の名前(shotaohtsuka)になっている部分は皆さんの環境に依ります。

root@ohtsuka-swarm01:~/scout-demo-service# docker build --push -t shotaohtsuka/scout-demo:v1 .
[+] Building 47.9s (12/12) FINISHED                            docker:default
 => [internal] load build definition from Dockerfile                     0.2s
 => => transferring dockerfile: 480B                                     0.0s
 => [internal] load metadata for docker.io/library/alpine:3.14@sha256:e  2.3s
 => [auth] library/alpine:pull token for registry-1.docker.io            0.0s
 => [internal] load .dockerignore                                        0.1s
 => => transferring context: 52B                                         0.0s
 => [internal] load build context                                        0.2s
 => => transferring context: 119.50kB                                    0.0s
 => [1/5] FROM docker.io/library/alpine:3.14@sha256:eb3e4e175ba6d212ba1  0.9s
 => => resolve docker.io/library/alpine:3.14@sha256:eb3e4e175ba6d212ba1  0.1s
 => => sha256:29291e31a76a7e560b9b7ad3cada56e8c18d50a96 2.81MB / 2.81MB  0.4s
 => => sha256:eb3e4e175ba6d212ba1d6e04fc0782916c08e1c9d 1.64kB / 1.64kB  0.0s
 => => sha256:be9bdc0ef8e96dbc428dc189b31e2e3b05523d96d12ed 528B / 528B  0.0s
 => => sha256:021b3423115ff662225e83d7e2606475217de7b55 1.47kB / 1.47kB  0.0s
 => => extracting sha256:29291e31a76a7e560b9b7ad3cada56e8c18d50a96cca8a  0.1s
 => [2/5] RUN apk add --no-cache   nodejs                                2.2s
 => [3/5] COPY package.json ./                                           0.2s
 => [4/5] RUN  apk add --no-cache npm  && npm i --no-optional  && npm   17.1s
 => [5/5] COPY . /app                                                    0.5s
 => exporting to image                                                   1.0s
 => => exporting layers                                                  0.9s
 => => writing image sha256:a3eaeba5365f22c780dac4f4bb4a3a1e9ef270cd257  0.0s
 => => naming to docker.io/shotaohtsuka/scout-demo:v1                    0.0s
 => pushing shotaohtsuka/scout-demo:v1 with docker                      18.3s
 => => pushing layer d90b04b50d09                                        5.2s
 => => pushing layer 0131ae8ee438                                        5.4s
 => => pushing layer cf318f9ae883                                        4.5s
 => => pushing layer 9e295186854f                                       12.8s
 => => pushing layer bc276c40b172                                       17.7s

ちなみにこのdocker imageはgithubからcloneしてきたDockerfileを参照に作成されているものです。

root@ohtsuka-swarm01:~/scout-demo-service# ls
app.js  Dockerfile  package.json  README.md

docker hubにWebブラウザでログインし、scout-demoのリポジトリが作成されていることを確認します。
image.png

docker scoutコマンドをインストールする

docker scoutコマンドをインストールします。
以下のGithubにinstallのシェルがありますので、サーバ上にコピペして実行します。

root@ohtsuka-swarm01:~/scout-demo-service# vi install.sh
root@ohtsuka-swarm01:~/scout-demo-service# chmod 777 install.sh
root@ohtsuka-swarm01:~/scout-demo-service# ./install.sh
[info] fetching release script for tag='v1.6.0'
[info] using release tag='v1.6.0' version='1.6.0' os='linux' arch='amd64'
[info] installed /root/.docker/cli-plugins/docker-scout

もしシェルでdocker scoutコマンドをインストールできないようであれば、docker scoutを実行できるコンテナをデプロイすることでも環境を用意できそうです。こちらの方がシェルよりも環境を選ばずに用意できるかなと思います。今後どうやって使うかの確認をしないとかな・・・?

シェル実行後docker scoutコマンドを実行するとUsageが表示されます。
docker scoutコマンドがうまくインストールされていることがわかりますね。

root@ohtsuka-swarm01:~# docker scout

 Command line tool for Docker Scout

Usage
  docker scout [command]

Available Commands
  attestation     Manage attestations on image indexes
  cache           Manage Docker Scout cache and temporary files
  compare         Compare two images and display differences (experimental)
  config          Manage Docker Scout configuration
  cves            Display CVEs identified in a software artifact
  enroll          Enroll an organization with Docker Scout
  environment     Manage environments (experimental)
  help            Display information about the available commands
  integration     Commands to list, configure, and delete Docker Scout integrations
  policy          Evaluate policies against an image and display the policy evaluation results (experimental)
  quickview       Quick overview of an image
  recommendations Display available base image updates and remediation recommendations
  repo            Commands to list, enable, and disable Docker Scout on repositories
  version         Show Docker Scout version information

リポジトリに格納されたdocker imageの脆弱性分析を行う

以下のコマンドで特定のリポジトリに対して分析を有効にします。
このコマンドで出力されるURL(今回は"https://scout.docker.com/org/shotaohtsuka/settings/repos")は後で使うので控えておいてください。

root@ohtsuka-swarm01:~# docker scout repo enable --org shotaohtsuka shotaohtsuka/scout-demo
    ✓ Enabled Docker Scout on  shotaohtsuka/scout-demo

What's Next?
  Manage repositories in the Docker Scout Dashboard → https://scout.docker.com/org/shotaohtsuka/settings/repos

次に以下のコマンドを実行することで分析を有効化したリポジトリに対してimage内にあるパッケージの脆弱性診断を開始します。
※image自体の脆弱性診断は"docker scout recommendations shotaohtsuka/scout-demo:v1"みたいなコマンドです。

パッケージにおいて、vulnerabilities(=脆弱性) Highが1つ出ていることがわかります。

root@ohtsuka-swarm01:~# docker scout cves --only-package express
    ...Storing image for indexing
    ✓ Image stored for indexing
    ...Indexing
    ✓ Indexed 79 packages
    ✗ Detected 1 vulnerable package with 1 vulnerability


## Overview
                    x       Analyzed Image
qqqqqqqqqqqqqqqqqqqqnqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
  Target            x
    digest          x  a3eaeba5365f
    platform        x linux/amd64
    vulnerabilities x    0C     1H     0M     0L
    size            x 22 MB
    packages        x 1


## Packages and Vulnerabilities
   0C     1H     0M     0L  express 4.17.1
pkg:npm/express@4.17.1
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
    ✗ HIGH CVE-2022-24999 [OWASP Top Ten 2017 Category A9 - Using Components with Known Vulnerabilities]
      https://scout.docker.com/v/CVE-2022-24999?s=gitlab&n=express&t=npm&vr=%3C4.17.3
      Affected range : <4.17.3
      Fixed version  : 4.17.3
      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

What's Next?
  View base image update recommendations → docker scout recommendations shotaohtsuka/scout-demo:v1

上記ログの★の部分ですが、ChatGPTに確認してみたところ以下の意味があるようです。
CVEとかCVSSとかは登録セキスぺなどの国家資格で出題されたような・・・もっと真剣に勉強しておけばよかった・・・
※本物の出力に★はありません汗


  • CVE-2022-24999: これは Common Vulnerabilities and Exposures (CVE) として識別された脆弱性の識別子です。脆弱性の詳細については CVE データベースで見ることができます。
  • OWASP Top Ten 2017 Category A9 - Using Components with Known Vulnerabilities: OWASP Top Ten は、アプリケーションセキュリティに関するトップ10の脆弱性のリストです。この特定の脆弱性は、OWASP Top Ten 2017 のカテゴリ A9 に関連付けられており、「既知の脆弱性を持つコンポーネントの使用」という問題に属しています。
  • https://scout.docker.com/v/CVE-2022-24999?s=gitlab&n=express&t=npm&vr=%3C4.17.3: このリンクは、CVE-2022-24999 に関連する詳細情報や修正方法を提供する可能性があります。リンクのパラメータには、脆弱性の種類や影響を指定するための情報が含まれています。
  • Affected range: <4.17.3: 影響を受ける範囲を示しています。この脆弱性は、バージョン 4.17.3 よりも古いバージョンのソフトウェアに影響を与える可能性があります。
  • Fixed version: 4.17.3: 問題を修正するために使用できるバージョンが示されています。この場合、バージョン 4.17.3 が脆弱性を解決するための修正を含んでいます。
  • CVSS Score: 7.5: Common Vulnerability Scoring System (CVSS) に基づいて計算された脆弱性の深刻度を示します。スコアが高いほど、脆弱性の影響が大きいことを示します。
  • CVSS Vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H: CVSS ベクトルは、脆弱性のさまざまな側面を表現するために使用されます。これには、攻撃の前提条件や攻撃の複雑さ、影響の範囲などが含まれます。

docker scoutのWebダッシュボードにアクセスしてみる

先ほど控えたURLをWebブラウザに入力してアクセスしてみます。
おそらく以下のようなdocker scoutのWebダッシュボードについての説明が確認できると思います。
※docker hubにログインしていないと「そのようなページはない」とはじかれるかもしれません。
image.png
image.png
image.png
説明を最後まで進むと以下のような画面が表示されます。分析を有効化したscout-demoリポジトリのみStatusがactiveになっていることがわかります。
image.png

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1