血と汗となみだを流す

個人の思ったこと、やったことの吐き出し口です。

JAWS-UG コンテナ支部 入門編 #6 コンテナの始め方 後編②(Clairで脆弱性スキャン)

後編②とは

概要

  • ClairとTrivyをECSで動かして、dockerイメージの脆弱性をチェックする(今回はClair)
    • ローカル、ECRにpushしたイメージをチェックする
  • ハンズオン資料はGithubに公開されており、AWSアカウントがあれば誰でも実施することができます。ぜひ手を動かしてみることをお勧めします

資料のリンク

まえがき

  • Clair
  • Klar
  • ClairとKlarを使ってenvoy-alpineのイメージのスキャンを実行する
    • 緊急度をパラメータ指定して同じイメージをスキャンし、結果を比較する
  • ECS上にClair と Trivyを起動
    • ローカルや CI 環境上から、そのサーバーを利用してコンテナの脆弱性を診断
  • イメージを格納するS3作成
  • CloudFormationで環境作成
  • このハンズオンのコンテナイメージは、可用性を求めていないのでアンチパターンになっている
    • 同じイメージにPostgreSQLが入っている

Clairで一般Dockerイメージのスキャン

docker run --rm \
  -e CLAIR_ADDR="http://${API_HOST}:6060" \
  supinf/klar:2.4 envoyproxy/envoy-alpine:v1.10.0 | jq .

{
  "LayerCount": 6,
  "Vulnerabilities": {}
}
  • "Vulnerabilities": {}ってことは脆弱性はゼロ
  • 緊急度をあげてやってみるが同じ結果だった
docker run --rm \
  -e CLAIR_ADDR="http://${API_HOST}:6060" -e CLAIR_OUTPUT=Medium \
  supinf/klar:2.4 envoyproxy/envoy-alpine:v1.10.0 | jq .

{
  "LayerCount": 6,
  "Vulnerabilities": {}
}

脆弱性のあるイメージで、緊急度をMEDIUMにして実行

docker run --rm \
  -e CLAIR_ADDR="http://${API_HOST}:6060" -e CLAIR_OUTPUT=Medium \
  supinf/klar:2.4 envoyproxy/envoy:v1.10.0 | jq .

{
  "LayerCount": 9,
  "Vulnerabilities": {}
}
  • あれ?脆弱性でない?!
  • と思ったら以下の注意書きが・・・
脆弱性 0 件でしたか??
とすると、それは脆弱性データベースがバックエンドで作成中だからです。
30 分ほどしてから再度試してみてください。
  • さすがフォローが熱い!筋トレして待とう
  • そしてちょっとまって再実行したらメッチャ出た!
{
  "LayerCount": 9,
  "Vulnerabilities": {
    "Medium": [
      {
        "Name": "CVE-2018-20839",
        "NamespaceName": "ubuntu:16.04",
        "Description": "systemd 242 changes the VT1 mode upon a logout, which allows attackers to read cleartext passwords in certain circumstances, such as watching a shutdown, or using Ctrl-Alt-F1 and Ctrl-Alt-F2. This occurs because the KDGKBMODE (aka current keyboard mode) check is mishandled.",
        "Link": "http://people.ubuntu.com/~ubuntu-security/cve/CVE-2018-20839",
        "Severity": "Medium",
        "Metadata": {
          "NVD": {
            "CVSSv2": {
              "Score": 5,
              "Vectors": "AV:N/AC:L/Au:N/C:P/I:N"
            }
          }
        },
        "FeatureName": "systemd",
        "FeatureVersion": "229-4ubuntu21.19"
      },
      {
        "Name": "CVE-2019-3842",
        "NamespaceName": "ubuntu:16.04",
        "Description": "In systemd before v242-rc4, it was discovered that pam_systemd does not properly sanitize the environment before using the XDG_SEAT variable. It is possible for an attacker, in some particular configurations, to set a XDG_SEAT environment variable which allows for commands to be checked against polkit policies using the \"allow_active\" element rather than \"allow_any\".",
        "Link": "http://people.ubuntu.com/~ubuntu-security/cve/CVE-2019-3842",
        "Severity": "Medium",
        "Metadata": {
          "NVD": {
            "CVSSv2": {
              "Score": 4.4,
              "Vectors": "AV:L/AC:M/Au:N/C:P/I:P"
            }
          }
        },
        "FixedBy": "229-4ubuntu21.21",
        "FeatureName": "systemd",
        "FeatureVersion": "229-4ubuntu21.19"
      },
      {
        "Name": "CVE-2009-5155",
        "NamespaceName": "ubuntu:16.04",
        "Description": "In the GNU C Library (aka glibc or libc6) before 2.28, parse_reg_exp in posix/regcomp.c misparses alternatives, which allows attackers to cause a denial of service (assertion failure and application exit) or trigger an incorrect result by attempting a regular-expression match.",
        "Link": "http://people.ubuntu.com/~ubuntu-security/cve/CVE-2009-5155",
        "Severity": "Medium",
        "Metadata": {
          "NVD": {
            "CVSSv2": {
              "Score": 5,
              "Vectors": "AV:N/AC:L/Au:N/C:N/I:N"
            }
          }
        },
        "FeatureName": "glibc",
        "FeatureVersion": "2.23-0ubuntu11"
      },
      {
        "Name": "CVE-2018-6485",
        "NamespaceName": "ubuntu:16.04",
        "Description": "An integer overflow in the implementation of the posix_memalign in memalign functions in the GNU C Library (aka glibc or libc6) 2.26 and earlier could cause these functions to return a pointer to a heap area that is too small, potentially leading to heap corruption.",
        "Link": "http://people.ubuntu.com/~ubuntu-security/cve/CVE-2018-6485",
        "Severity": "Medium",
        "Metadata": {
          "NVD": {
            "CVSSv2": {
              "Score": 7.5,
              "Vectors": "AV:N/AC:L/Au:N/C:P/I:P"
            }
          }
        },
        "FeatureName": "glibc",
        "FeatureVersion": "2.23-0ubuntu11"
      },
      {
        "Name": "CVE-2019-8457",
        "NamespaceName": "ubuntu:16.04",
        "Description": "(SQLite3 from 3.6.0 to and including 3.27.2 is vulnerable to heap out-o ...)",
        "Link": "http://people.ubuntu.com/~ubuntu-security/cve/CVE-2019-8457",
        "Severity": "Medium",
        "Metadata": {
          "NVD": {
            "CVSSv2": {
              "Score": 7.5,
              "Vectors": "AV:N/AC:L/Au:N/C:P/I:P"
            }
          }
        },
        "FeatureName": "db5.3",
        "FeatureVersion": "5.3.28-11ubuntu0.1"
      },
      {
        "Name": "CVE-2019-9893",
        "NamespaceName": "ubuntu:16.04",
        "Description": "libseccomp before 2.4.0 did not correctly generate 64-bit syscall argument comparisons using the arithmetic operators (LT, GT, LE, GE), which might able to lead to bypassing seccomp filters and potential privilege escalations.",
        "Link": "http://people.ubuntu.com/~ubuntu-security/cve/CVE-2019-9893",
        "Severity": "Medium",
        "Metadata": {
          "NVD": {
            "CVSSv2": {
              "Score": 7.5,
              "Vectors": "AV:N/AC:L/Au:N/C:P/I:P"
            }
          }
        },
        "FixedBy": "2.4.1-0ubuntu0.16.04.2",
        "FeatureName": "libseccomp",
        "FeatureVersion": "2.3.1-2.1ubuntu2~16.04.1"
      },
      {
        "Name": "CVE-2016-1585",
        "NamespaceName": "ubuntu:16.04",
        "Description": "In all versions of AppArmor mount rules are accidentally widened when compiled.",
        "Link": "http://people.ubuntu.com/~ubuntu-security/cve/CVE-2016-1585",
        "Severity": "Medium",
        "Metadata": {
          "NVD": {
            "CVSSv2": {
              "Score": 7.5,
              "Vectors": "AV:N/AC:L/Au:N/C:P/I:P"
            }
          }
        },
        "FeatureName": "apparmor",
        "FeatureVersion": "2.10.95-0ubuntu2.10"
      }
    ]
  }
}

ECRにおいたDockerイメージをスキャンしてみる

  • 脆弱性チェックが、AWSマネージドサービスで提供されていないのでこのような手法でやったほうがよいのかも
  • このハンズオンは各サービスや共通でもサーバを立てて脆弱性スキャンをする想定としている
  • ECRに、ハンズオンで使用しているイメージをpushして脆弱性スキャンをかける
docker run --rm \
  -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_DEFAULT_REGION \
  -e CLAIR_ADDR="http://${API_HOST}:6060" -e CLAIR_OUTPUT=Low \
  supinf/klar:2.4 ${image_name} | jq .

{
  "LayerCount": 20,
  "Vulnerabilities": {
    "High": [
      {
        "Name": "CVE-2016-4074",
        "NamespaceName": "alpine:v3.9",
        "Link": "https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2016-4074",
        "Severity": "High",
        "Metadata": {
          "NVD": {
            "CVSSv2": {
              "Score": 7.8,
              "Vectors": "AV:N/AC:L/Au:N/C:N/I:N"
            }
          }
        },
        "FixedBy": "1.6_rc1-r0",
        "FeatureName": "jq",
        "FeatureVersion": "1.6-r0"
      }
    ]
  }
}
  • alpine:v3.9のCVE-2016-4074が出た
  • jpの脆弱性かな?
  • このハンズオンの場合はリモートからJSONが送られることは無さそうだから大丈夫・・・?

次回

  • Trivyで同じ脆弱性をチェックしてみる!
プライバシーポリシー