目的
- trivyを理解する
手段
killercodaで手を動かす
環境
killercodaで手を動かす
trivyとは
trivy はセキュリティスキャナです。trivy はコンテナイメージ・ファイルシステム・リポジトリに対して脆弱性やSBOMのスキャンを実行できます。例えば、現在利用中のコンテナイメージに対して特定 CVE が該当しているかどうかを確認できます。
手を動かす
コマンドフォーマットは以下の通りです。
controlplane:~$ trivy --help
NAME:
trivy - A simple and comprehensive vulnerability scanner for containers
USAGE:
trivy [global options] command [command options] target
VERSION:
0.22.0
COMMANDS:
image, i scan an image
filesystem, fs scan local filesystem for language-specific dependencies and config files
rootfs scan rootfs
repository, repo scan remote repository
client, c client mode
server, s server mode
config, conf scan config files
plugin, p manage plugins
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--quiet, -q suppress progress bar and log output (default: false) [$TRIVY_QUIET]
--debug, -d debug mode (default: false) [$TRIVY_DEBUG]
--cache-dir value cache directory (default: "/root/.cache/trivy") [$TRIVY_CACHE_DIR]
--help, -h show help (default: false)
--version, -v print the version (default: false)
# trivy {実行対象} |grep -E "CVE-XXXX-XXXX" のような形式で利用します
既存 deployment の image を確認します。
controlplane:~$ k -n applications get po -oyaml |grep image:
- image: nginx:1.19.1-alpine-perl
image: docker.io/library/nginx:1.19.1-alpine-perl
- image: nginx:1.19.1-alpine-perl
image: docker.io/library/nginx:1.19.1-alpine-perl
- image: nginx:1.20.2-alpine
image: docker.io/library/nginx:1.20.2-alpine
# -oyaml でyamlフォーマットで出力すれば一覧で確認できます
特定イメージに対して trivy でスキャンします。
controlplane:~$ trivy image nginx:1.19.1-alpine-perl | grep "CVE-2021-28831"
| busybox | CVE-2021-28831 | | 1.31.1-r9 | 1.31.1-r10 | busybox: invalid free or segmentation |
| ssl_client | CVE-2021-28831 | HIGH | 1.31.1-r9 | 1.31.1-r10 | busybox: invalid free or segmentation |
# スキャン対象のコンテナイメージは当該 CVE に該当しています。
あとがき
もう1つくらい書きたい。。。