Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Info

The operation confirmation method for both the C version and Python version of the application is almost the same. I This page will explain using the C version as an example, and the different parts will be explained as appropriate. Also, the application path is as follows, so please read it as appropriate.

C version app path
${SDK_DIR}/src/adamapp

Python version app path
${SDK_DIR}/src/adamapp-py

...

Info

The example in this section uses Trivy and Dockle to extract vulnerabilities in container images, but please choose the appropriate tools and methods depending on the convenience and purpose of your development environment. In addition, each company is responsible for checking the license and usage conditions of each tool before making decisions regarding its use.

コンテナアプリの開発フローと、その中に脆弱性の抽出および対処を組込んだ例を下図に示します。脆弱性の抽出および対処は、早い段階から開発フローの中に組込み、実施することが推奨されます。最低限、イメージが製品リリースされる前の、実際の本番環境にデプロイされる前に必ず実施されるべきです。

本作業は、セキュリティに関するトレードオフの問題でもあります。抽出および対処にかかる時間や費用、頻度を考慮しなければなりません。しかし、セキュリティ上のリスクを最小限に抑えるために、脆弱性の抽出および対処は定期的に実施することが推奨されます。

...

 

本図の開発フローの例では、

  • コンテナイメージのビルド “Build Container Image” の工程の直後に、

  • ツールによる脆弱性の抽出と設計者による対応判定 “Check & Judge Vulnerability” を実施し、

  • 次にその判定で対応必要としたものに対し実際に処置をする “Modify Vulnerability” を実施する、

という例を示しています。

脆弱性抽出ツールはTrivyとDockleの2つ両方を使用する例を示しています。これら両方を使用する理由は、各ツールの抽出できる脆弱性の範囲が相異なるためです。Trivyは主にパッケージの脆弱性を抽出し、Dockleは例えば不要なファイルの検出や設定の不備の検出など、主にシステム関連の脆弱性を抽出します。両方のツールを使用することで、より包括的なコンテナイメージのセキュリティチェックを実施できます。これら2つのツールの使用方法の概略については以降の節で記述します。

また、本図では脆弱性チェックの対象として、自身の開発プロダクトであるアプリコンテナイメージだけでなく、その開発途中でマルチビルド等の目的でベースとして使用するコンテナイメージ(例: Debian の公式イメージなど) についても対象としています。その理由は使用するパッケージに対しての脆弱性を漏れなく調べるためなのですが、詳細は改めてTrivyの説明の節において記述します。

 

Trivy: Comprehensive Vulnerability Scanner

Trivyは、コンテナイメージやファイルシステムに存在する脆弱性を検出するオープンソースのスキャナです。主にOSパッケージやプログラミング言語のライブラリに関連する脆弱性を対象にしています。TrivyはAqua Security社によって開発・メンテナンスされており、コンテナ開発者にとって信頼性の高いツールの一つです。

Trivy の使い方の基本例を以下に示します。

(1)  Install Trivy:

まず、Trivy をインストールします。Trivyのリリースページから最新版のバイナリをダウンロードできます。下記リンクからTrivyのリリースページにアクセスしてください。

https://github.com/aquasecurity/trivy/releases

リリースページには、Linux、macOS、Windowsなどの各プラットフォーム向けのバイナリが用意されています。自分の環境に合ったバイナリを選択し、ダウンロードしてください。また、Trivyの公式ドキュメントには、各プラットフォームでのインストール方法が詳細に記載されていますので、そちらも参考にしてください。

Trivy は定期的に更新されていますので、最新版をインストールして使用するようにしてください。

(2)  Run Trivy:

インストールが完了したら、コマンドラインからTrivyを実行して、対象となるコンテナイメージの脆弱性をスキャンします。以下のコマンドは、your-image というコンテナイメージをスキャンする例です。

Code Block
buildhost$ trivy image your-image

絞り込みを行う際は必要に応じて、Trivy のオプションを使用してスキャン対象や表示内容をカスタマイズできます。例えば、特定の重要度 (後述) 以上の脆弱性のみを表示する場合は、以下のようなコマンドを使用できます。

Code Block
buildhost$ trivy image --severity CRITICAL,HIGH your-image

(3)  Check the result and determine how to deal with:

スキャンが完了すると、Trivy は検出された脆弱性の一覧を表示します。脆弱性の詳細や重要度(CRITICAL、HIGH、MEDIUM、LOW、UNKNOWN)が示され、修正が必要な箇所を特定しやすくなります。この結果をもとに、影響度などを加味しながらどれをどう対処していくのかを決定していきます。

参考で、以下に公式の ubuntu のイメージに対し trivy を実行した例 (オプション指定無し) の抜粋を示します。(実行例は Trivy は 0.38.3 を使用しています。)

 

Example execution of trivy: target image = ubuntu

buildhost$ trivy image  ubuntu:latest

2023-02-22T15:23:36.453+0900   INFO     Vulnerability scanning is enabled

<<<<........ SNIP ........>>>>

2023-02-22T15:23:43.579+0900   INFO     Detected OS: ubuntu

2023-02-22T15:23:43.580+0900   INFO     Detecting Ubuntu vulnerabilities...

2023-02-22T15:23:43.596+0900   INFO     Number of language-specific files: 0

 

ubuntu:latest (ubuntu 22.04)

============================

Total: 31 (UNKNOWN: 0, LOW: 16, MEDIUM: 14, HIGH: 1, CRITICAL: 0)

 

...

The diagram below shows the development flow of a container app and an example of incorporating vulnerability extraction and countermeasures into it. It is recommended that vulnerability extraction and countermeasures be incorporated into the development flow from an early stage. At a minimum, this should be done before the image is released into production and deployed to an actual production environment.

This work is also a matter of security trade-offs. The time, cost, and frequency of extraction and treatment must be considered. However, to minimize security risks, it is recommended that vulnerabilities be identified and addressed on a regular basis.

...

 

In the example development flow shown in this diagram, an example is shown.

  • Immediately after the “Build Container Image” step,

  • By extracting vulnerabilities using tools and conducting “Check & Judge Vulnerability” by designers,

  • Next, carry out “Modify Vulnerability” to actually take action on what needs to be addressed based on the judgment.

This example uses both Trivy and Dockle as vulnerability extraction tools. The reason for using both of these is that each tool extracts a different range of vulnerabilities. Trivy mainly extracts vulnerabilities in packages. Dockle mainly extracts system-related vulnerabilities, such as detecting unnecessary files or misconfigurations. By using both tools, you can perform more comprehensive security checks on your container images. The following sections outline how to use these two tools.

In addition, in this figure, vulnerability checks are not limited to application container images that are self-developed products, but also container images that are used as a base for multi-build purposes during development (e.g., Debian official images, etc.) It also covers. The reason for this is to thoroughly check for vulnerabilities in the packages you use. The details will be described in the Trivy explanation section.

 

Trivy: Comprehensive Vulnerability Scanner

Trivy is an open source scanner that detects vulnerabilities in container images and file systems. It mainly targets vulnerabilities related to OS packages and programming language libraries. Trivy is developed and maintained by Aqua Security and is one of the most reliable tools for container developers.

Below is a basic example of how to use Trivy.

(1)  Install Trivy:

First, install Trivy. You can download the latest version of the binaries from the Trivy release page. Please access the Trivy release page from the link below.

https://github.com/aquasecurity/trivy/releases

The release page provides binaries for each platform, including Linux, macOS, and Windows. Select the binary that suits your environment and download it. Also, please refer to Trivy's official documentation, which has detailed instructions on how to install it on each platform.

Trivy is updated regularly, so be sure to install and use the latest version.

(2)  Run Trivy:

Once installed, run Trivy from the command line to scan the target container image for vulnerabilities. The following command is an example of scanning a container image called your-image.

Code Block
buildhost$ trivy image your-image

When filtering, you can use Trivy's options to customize what is scanned and what is displayed, if necessary. For example, if you want to display only vulnerabilities of a certain severity level (described below), you can use a command like the following:

Code Block
buildhost$ trivy image --severity CRITICAL,HIGH your-image

(3)  Check the result and determine how to deal with:

Once the scan is complete, Trivy displays a list of detected vulnerabilities. Vulnerability details and severity (CRITICAL, HIGH, MEDIUM, LOW, UNKNOWN) are shown, making it easier to identify areas that need fixing. Based on these results, we will decide which ones to deal with and how to deal with them, taking into consideration factors such as the degree of impact. For reference, below is an excerpt of an example of running trivy on an official ubuntu image (without specifying options). (The execution example uses Trivy 0.38.3.)

 

Example execution of trivy: target image = ubuntu

buildhost$ trivy image  ubuntu:latest

2023-02-22T15:23:36.453+0900   INFO     Vulnerability scanning is enabled

<<<<........ SNIP ........>>>>

2023-02-22T15:23:43.579+0900   INFO     Detected OS: ubuntu

2023-02-22T15:23:43.580+0900   INFO     Detecting Ubuntu vulnerabilities...

2023-02-22T15:23:43.596+0900   INFO     Number of language-specific files: 0

 

ubuntu:latest (ubuntu 22.04)

============================

Total: 31 (UNKNOWN: 0, LOW: 16, MEDIUM: 14, HIGH: 1, CRITICAL: 0)

 

+---------------+-----------+|    Library    | ----+----------+--------------+------------+---------------------------------------+

|    Library    | Vulnerability | Severity | Install Ver   | Fixed Ver  | Title                                   |

+---------------+---------------+----------+--------------+------------+---------------------------------------+

| bash          | CVE-2022-3715 | LOW      | 5.1-6ubuntu1 |              | bash: a heap-buffer-overflow  |

|                 |                |           |                |              | in valid_parameter_transform  |

|                 |               |            |                |              | https://avd.aquasec.com/nvd/ |

|                |               |            |                |              | cve-2022-3715                          |

+---------------+---------------+----------+--------------+------------+---------------------------------------+

| coreutils     | CVE-2016-2781 |            | 8.32-4.1      |             | coreutils: Non-privileged session can |

|                |                 |           | ubuntu1      |              | escape to the parent session in chroot|

|                 |                 |           |                |             | https://avd.aquasec.com/nvd/            |

|                |                |            |                |             | cve-2016-2781                          |

<<<<........ SNIP ........>>>>

+---------------+---------------+----------+--------------+------------+---------------------------------------+

| libssl3      | CVE-2023-0286  | HIGH    | 3.0.2-0       | 3.0.2-0     | There is a type confusion               |

|                |                 |            | ubuntu1.7    | ubuntu1.8| vulnerability relating to X.400        |

|                |                 |           |                |              | address proc ...                       |

(4)  Note for use:

ここで、Trivyにかけるイメージについて一つ注意点があります。Trivy はパッケージの脆弱性をスキャンする際にパッケージ情報を参照しています。しかし、コンテナイメージのビルドプロセスによっては、パッケージ情報が最終プロダクトであるコンテナイメージに含まれないことがあります。この場合、Trivy がパッケージ脆弱性の検出に関連する情報を取得できず、その機能を利用できない可能性があります。

コンテナ開発者としては、Trivy を適切に活用するために、コンテナイメージにパッケージ情報を含めるか、あるいは Trivy のスキャン対象となるよう別の方法でパッケージ情報を提供することが重要です。例えば、Dockerfile の RUN コマンドでパッケージのインストールとクリーンアップを同時に行っている場合、パッケージ情報がコンテナイメージに含まれないことがあります。このような状況では、Trivy の利用に制限が生じるため、必要に応じてビルドプロセスを調整することが望ましいです。

一手段として、ベースとして使用したコンテナイメージにはパッケージ情報を残したままにしておき、そのイメージに対して Trivy を実行する方法があります。最終プロダクトのコンテナに取り込む対象物は開発者が把握しているはずですので、その対象物に対応するパッケージの脆弱性情報のみを Trivy の実行結果から抽出すればよいわけです。

...

| libssl3      | CVE-2023-0286  | HIGH    | 3.0.2-0       | 3.0.2-0     | There is a type confusion               |

|                |                 |            | ubuntu1.7    | ubuntu1.8| vulnerability relating to X.400        |

|                |                 |           |                |              | address proc ...                       |

(4)  Note for use:

Here, there is one thing to note about the image you give to Trivy. Trivy references package information when scanning packages for vulnerabilities. However, depending on the container image build process, package information may not be included in the final product, the container image. In this case, Trivy may not be able to retrieve information related to package vulnerability detection and may not be able to take advantage of that functionality.

As a container developer, it is important to include package information in your container images or otherwise provide package information for Trivy to scan in order to properly utilize Trivy. For example, if your Dockerfile's RUN command installs and cleans up packages at the same time, the package information may not be included in the container image. In these situations, there are limitations to the use of Trivy, so it is best to adjust the build process as necessary.

One option is to leave the package information in the container image you used as a base and run Trivy against that image. The developer knows what to include in the container of the final product. He only needs to extract vulnerability information for the package corresponding to the target from the Trivy execution results.

As mentioned above, it is important to regularly check for vulnerabilities in container images using tools like Trivy to reduce security risks. Additionally, by incorporating Trivy into your CI/CD pipeline, you can achieve automated vulnerability detection and improve security throughout your development process.

 

Dockle: Container Image Security Linter

...