LoginSignup
1
0

More than 1 year has passed since last update.

Docker Bench for Securityのハンズオンをやってみた

Posted at

Docker Bench を使用してコンテナのセキュリティを強化する内容の教材を使ってハンズオンを実施したため、備忘録として記載させていただきます。

DockerBenchリポジトリをGitHubから現在の作業ディレクトリに複製

GitHubからDockerベンチリポジトリを複製する。

$ git clone https://github.com/docker/docker-bench-security.git
Cloning into 'docker-bench-security'...
remote: Enumerating objects: 2513, done.
remote: Counting objects: 100% (591/591), done.
remote: Compressing objects: 100% (141/141), done.
remote: Total 2513 (delta 483), reused 452 (delta 450), pack-reused 1922
Receiving objects: 100% (2513/2513), 4.11 MiB | 0 bytes/s, done.
Resolving deltas: 100% (1761/1761), done.

ディレクトリをdocker-bench-securityディレクトリに変更し、docker-bench-securityスクリプトを実行

作業ディレクトリをdocker-bench-securityに変更。

$ cd docker-bench-security

docker-bench-security.shシェルスクリプトを実行し、標準出力を/tmp/bench1.outファイルにリダイレクトする。

$ sudo sh docker-bench-security.sh > /tmp/bench1.out
WARNING: You're not using the default seccomp profile

https://docs.docker.com/engine/security/seccomp/
seccompとは何かを調べてみると、Linux カーネルの機能の1つでコンテナー内で使用可能なアクションを制限できるものらしい。特にこちらは設定しなくてもハンズオンは実施できるため、今回は割愛する。

レポートを実行した後、Linuxのmoreコマンドで内容を確認。

$ more /tmp/bench1.out
# --------------------------------------------------------------------------------------------
# Docker Bench for Security v1.3.6
#
# Docker, Inc. (c) 2015-2022
#
# Checks for dozens of common best-practices around deploying Docker containers in production.
# Based on the CIS Docker Benchmark 1.4.0.
# --------------------------------------------------------------------------------------------

Initializing 2022-10-10T08:20:46-04:00


Section A - Check results

[INFO] 1 - Host Configuration
[INFO] 1.1 - Linux Hosts Specific Configuration
[WARN] 1.1.1 - Ensure a separate partition for containers has been created (Automated)
[INFO] 1.1.2 - Ensure only trusted users are allowed to control Docker daemon (Automated)
[INFO]       * Users:
[WARN] 1.1.3 - Ensure auditing is configured for the Docker daemon (Automated)
[WARN] 1.1.4 - Ensure auditing is configured for Docker files and directories -/run/containerd (Automated)
[WARN] 1.1.5 - Ensure auditing is configured for Docker files and directories - /var/lib/docker (Automated)
[WARN] 1.1.6 - Ensure auditing is configured for Docker files and directories - /etc/docker (Automated)
[WARN] 1.1.7 - Ensure auditing is configured for Docker files and directories - docker.service (Automated)
[INFO] 1.1.8 - Ensure auditing is configured for Docker files and directories - containerd.sock (Automated)

サーバーの監査ルールを更新して、DockerDaemonの監査を含める。

ホストにすでに設定されているルールを一覧表示するには、次のように入力。
特に何もルールがなかった。

$ sudo auditctl -l
No rules

auditctl コマンドを使用して、1.1.5にある/var/lib/dockerのDockerファイルを監査するルールを追加。

$ sudo auditctl -w /var/lib/docker -k "docker lib"

dockerデーモンの監査がセットアップされたことを確認するため、-lコマンドを再度入力。

$ sudo auditctl -l
-w /var/lib/docker -p rwxa -k docker lib

Docker Benchセキュリティユーティリティを再度実行し、出力を最初の実行と比較。

次に、dockerベンチユーティリティを再度実行し、出力を/tmp/bench2.outに送信する。

$ sudo sh docker-bench-security.sh > /tmp/bench2.out
WARNING: You're not using the default seccomp profile

新しいレポートの内容を表示するには、moreコマンドを再度使用できる。

$ more /tmp/bench2.out
# --------------------------------------------------------------------------------------------
# Docker Bench for Security v1.3.6
#
# Docker, Inc. (c) 2015-2022
#
# Checks for dozens of common best-practices around deploying Docker containers in production.
# Based on the CIS Docker Benchmark 1.4.0.
# --------------------------------------------------------------------------------------------

Initializing 2022-10-10T08:25:53-04:00


Section A - Check results

[INFO] 1 - Host Configuration
[INFO] 1.1 - Linux Hosts Specific Configuration
[WARN] 1.1.1 - Ensure a separate partition for containers has been created (Automated)
[INFO] 1.1.2 - Ensure only trusted users are allowed to control Docker daemon (Automated)
[INFO]       * Users:
[WARN] 1.1.3 - Ensure auditing is configured for the Docker daemon (Automated)
[WARN] 1.1.4 - Ensure auditing is configured for Docker files and directories -/run/containerd (Automated)
[PASS] 1.1.5 - Ensure auditing is configured for Docker files and directories - /var/lib/docker (Automated)
[WARN] 1.1.6 - Ensure auditing is configured for Docker files and directories - /etc/docker (Automated)
[WARN] 1.1.7 - Ensure auditing is configured for Docker files and directories - docker.service (Automated)
[INFO] 1.1.8 - Ensure auditing is configured for Docker files and directories - containerd.sock (Automated)

次に、Linuxのdiffコマンドを使用して、bench1.outでの最初の実行の出力と、bench2.outでの2番目の実行の出力を比較。
1.1.5が警告[WARN]から合格[PASS]に変わっていることが確認できた。

$ diff /tmp/bench1.out /tmp/bench2.out
10c10
< Initializing 2022-10-10T08:20:46-04:00
---
> Initializing 2022-10-10T08:25:53-04:00
22c22
< [WARN] 1.1.5 - Ensure auditing is configured for Docker files and directories - /var/lib/docker (Automated)
---
> [PASS] 1.1.5 - Ensure auditing is configured for Docker files and directories - /var/lib/docker (Automated)
151c151
< [INFO] Score: 9
---
1
0
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
1
0