血と汗となみだを流す

クラウドエンジニアになるための修業の場

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

後編③とは

概要

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

資料のリンク

まえがき

Clairでは脆弱性なしと結果がでた envoyproxy/envoy-alpine:v1.10.0を Trivyで検査する

curl -s -X GET -H 'Content-Type:application/json' \
  "http://${API_HOST}:9000/api/v1/images/envoyproxy%2Fenvoy-alpine%3Av1.10.0/vulnerabilities" \
  | jq .
{
  "Count": 1,
  "Vulnerabilities": [
    {
      "Description": "ChaCha20-Poly1305 is an AEAD cipher, and requires a unique nonce input for every encryption operation. RFC 7539 specifies that the nonce value (IV) should be 96 bits (12 bytes). OpenSSL allows a variable nonce length and front pads the nonce with 0 bytes if it is less than 12 bytes. However it also incorrectly allows a nonce to be set of up to 16 bytes. In this case only the last 12 bytes are significant and any additional leading bytes are ignored. It is a requirement of using this cipher that nonce values are unique. Messages encrypted using a reused nonce value are susceptible to serious confidentiality and integrity attacks. If an application changes the default nonce length to be longer than 12 bytes and then makes a change to the leading bytes of the nonce expecting the new value to be a new unique nonce then such an application could inadvertently encrypt messages with a reused nonce. Additionally the ignored bytes in a long nonce are not covered by the integrity guarantee of this cipher. Any application that relies on the integrity of these ignored leading bytes of a long nonce may be further affected. Any OpenSSL internal use of this cipher, including in SSL/TLS, is safe because no such use sets such a long nonce value. However user applications that use this cipher directly and set a non-default nonce length to be longer than 12 bytes may be vulnerable. OpenSSL versions 1.1.1 and 1.1.0 are affected by this issue. Due to the limited scope of affected deployments this has been assessed as low severity and therefore we are not creating new releases at this time. Fixed in OpenSSL 1.1.1c (Affected 1.1.1-1.1.1b). Fixed in OpenSSL 1.1.0k (Affected 1.1.0-1.1.0j).",
      "FixedVersion": "1.1.1b-r1",
      "InstalledVersion": "1.1.1a-r1",
      "PkgName": "openssl",
      "References": [
        "https://git.openssl.org/gitweb/?p=openssl.git;a=commitdiff;h=ee22257b1418438ebaf54df98af4e24f494d1809",
        "https://git.openssl.org/gitweb/?p=openssl.git;a=commitdiff;h=f426625b6ae9a7831010750490a5f0ad689c5ba3",
        "https://www.openssl.org/news/secadv/20190306.txt"
      ],
      "Severity": "MEDIUM",
      "Title": "openssl: ChaCha20-Poly1305 with long nonces",
      "VulnerabilityID": "CVE-2019-1543"
    }
  ]
}
docker run --rm \
  -e CLAIR_ADDR="http://${API_HOST}:6060" \
  supinf/klar:2.4 envoyproxy/envoy-alpine:v1.10.0 | jq .

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

Docker公式イメージであっても、古いバージョンには脆弱性が残っている例

  • python:3.7.3-alpine3.9python:3.4.10-alpine3.9
curl -s -X GET -H 'Content-Type:application/json' \
  "http://${API_HOST}:9000/api/v1/images/python%3A3.7.3-alpine3.9/vulnerabilities" \
  | jq .
{
  "Count": 2,
  "Vulnerabilities": [
    {
      "Description": "SQLite3 from 3.6.0 to and including 3.27.2 is vulnerable to heap out-of-bound read in the rtreenode() function when handling invalid rtree tables.",
      "FixedVersion": "3.28.0-r0",
      "InstalledVersion": "3.26.0-r3",
      "PkgName": "sqlite",
      "References": [
        "https://www.sqlite.org/releaselog/3_28_0.html",
        "https://www.sqlite.org/src/info/90acdbfce9c08858",
        "https://security.netapp.com/advisory/ntap-20190606-0002/",
        "https://usn.ubuntu.com/4004-1/",
        "https://usn.ubuntu.com/4004-2/"
      ],
      "Severity": "HIGH",
      "VulnerabilityID": "CVE-2019-8457"
    },
    {
      "Description": "An exploitable use after free vulnerability exists in the window function functionality of Sqlite3 3.26.0. A specially crafted SQL command can cause a use after free vulnerability, potentially resulting in remote code execution. An attacker can send a malicious SQL command to trigger this vulnerability.",
      "FixedVersion": "3.28.0-r0",
      "InstalledVersion": "3.26.0-r3",
      "PkgName": "sqlite",
      "References": [
        "http://packetstormsecurity.com/files/152809/Sqlite3-Window-Function-Remote-Code-Execution.html",
        "http://www.securityfocus.com/bid/108294",
        "https://security.netapp.com/advisory/ntap-20190521-0001/",
        "https://talosintelligence.com/vulnerability_reports/TALOS-2019-0777"
      ],
      "Severity": "MEDIUM",
      "VulnerabilityID": "CVE-2019-5018"
    }
  ]
}
curl -s -X GET -H 'Content-Type:application/json' \
  "http://${API_HOST}:9000/api/v1/images/python%3A3.4.10-alpine3.9/vulnerabilities" \
  | jq .
{
  "Count": 3,
  "Vulnerabilities": [
    {
      "Description": "ChaCha20-Poly1305 is an AEAD cipher, and requires a unique nonce input for every encryption operation. RFC 7539 specifies that the nonce value (IV) should be 96 bits (12 bytes). OpenSSL allows a variable nonce length and front pads the nonce with 0 bytes if it is less than 12 bytes. However it also incorrectly allows a nonce to be set of up to 16 bytes. In this case only the last 12 bytes are significant and any additional leading bytes are ignored. It is a requirement of using this cipher that nonce values are unique. Messages encrypted using a reused nonce value are susceptible to serious confidentiality and integrity attacks. If an application changes the default nonce length to be longer than 12 bytes and then makes a change to the leading bytes of the nonce expecting the new value to be a new unique nonce then such an application could inadvertently encrypt messages with a reused nonce. Additionally the ignored bytes in a long nonce are not covered by the integrity guarantee of this cipher. Any application that relies on the integrity of these ignored leading bytes of a long nonce may be further affected. Any OpenSSL internal use of this cipher, including in SSL/TLS, is safe because no such use sets such a long nonce value. However user applications that use this cipher directly and set a non-default nonce length to be longer than 12 bytes may be vulnerable. OpenSSL versions 1.1.1 and 1.1.0 are affected by this issue. Due to the limited scope of affected deployments this has been assessed as low severity and therefore we are not creating new releases at this time. Fixed in OpenSSL 1.1.1c (Affected 1.1.1-1.1.1b). Fixed in OpenSSL 1.1.0k (Affected 1.1.0-1.1.0j).",
      "FixedVersion": "1.1.1b-r1",
      "InstalledVersion": "1.1.1a-r1",
      "PkgName": "openssl",
      "References": [
        "https://git.openssl.org/gitweb/?p=openssl.git;a=commitdiff;h=ee22257b1418438ebaf54df98af4e24f494d1809",
        "https://git.openssl.org/gitweb/?p=openssl.git;a=commitdiff;h=f426625b6ae9a7831010750490a5f0ad689c5ba3",
        "https://www.openssl.org/news/secadv/20190306.txt"
      ],
      "Severity": "MEDIUM",
      "Title": "openssl: ChaCha20-Poly1305 with long nonces",
      "VulnerabilityID": "CVE-2019-1543"
    },
    {
      "Description": "SQLite3 from 3.6.0 to and including 3.27.2 is vulnerable to heap out-of-bound read in the rtreenode() function when handling invalid rtree tables.",
      "FixedVersion": "3.28.0-r0",
      "InstalledVersion": "3.26.0-r3",
      "PkgName": "sqlite",
      "References": [
        "https://security.netapp.com/advisory/ntap-20190606-0002/",
        "https://usn.ubuntu.com/4004-1/",
        "https://usn.ubuntu.com/4004-2/",
        "https://www.sqlite.org/releaselog/3_28_0.html",
        "https://www.sqlite.org/src/info/90acdbfce9c08858"
      ],
      "Severity": "HIGH",
      "VulnerabilityID": "CVE-2019-8457"
    },
    {
      "Description": "An exploitable use after free vulnerability exists in the window function functionality of Sqlite3 3.26.0. A specially crafted SQL command can cause a use after free vulnerability, potentially resulting in remote code execution. An attacker can send a malicious SQL command to trigger this vulnerability.",
      "FixedVersion": "3.28.0-r0",
      "InstalledVersion": "3.26.0-r3",
      "PkgName": "sqlite",
      "References": [
        "http://packetstormsecurity.com/files/152809/Sqlite3-Window-Function-Remote-Code-Execution.html",
        "http://www.securityfocus.com/bid/108294",
        "https://security.netapp.com/advisory/ntap-20190521-0001/",
        "https://talosintelligence.com/vulnerability_reports/TALOS-2019-0777"
      ],
      "Severity": "MEDIUM",
      "VulnerabilityID": "CVE-2019-5018"
    }
  ]
}
  • python:3.7.3-alpine3.9で検出された脆弱性
    • CVE-2019-8457
    • CVE-2019-5018
  • python:3.4.10-alpine3.9で検出された脆弱性
    • CVE-2019-1543
    • CVE-2019-8457
    • CVE-2019-5018
  • CVE-2019-8457CVE-2019-5018に関しては2019/05に出ているやつなので両方で検出されているのかな
  • おそらくここのハンズオンで差を出したかったのはCVE-2019-1543
  • python:3.8.0b1-alpine3.9にしたらゼロ件でした
curl -s -X GET -H 'Content-Type:application/json' \
  "http://${API_HOST}:9000/api/v1/images/python%3A3.8.0b1-alpine3.9/vulnerabilities" \
  | jq .
{
  "Count": 0,
  "Vulnerabilities": []
}

CIにおけるリリース判定

  • CI中に脆弱性が出たらリリースを停止したい
  • exit codeや応答値を見て処理が停止するように書くことができる
docker run --rm \
      -e CLAIR_ADDR="http://${API_HOST}:6060" \
      supinf/klar:2.4 envoyproxy/envoy:v1.10.0 \
      | jq ".Vulnerabilities | length"
1
curl -s -X GET -H 'Content-Type:application/json' \
  "http://${API_HOST}:9000/api/v1/images/python%3A3.4.10-alpine3.9/vulnerabilities?skip-update=yes" \
  | jq -r ".Count"
3

まとめ

  • 「このツールならすべての脆弱性をチェックできる」というのは無さそう
  • Dockerイメージごとに得意分野が異なってる
  • 公式イメージの最新であっても脆弱性が入っている可能性がままある

感想

  • まだDockerfileを書くのもままならない状態なので、脆弱性というところまで頭が回っていない
  • しかしインターネットに公開するのであれば脆弱性チェックはしっかりやって置かないと行けないと感じた
  • ただ、そのリリースサイクルに追いついていけるかが自信ない・・・

終わりに

  • アウトプットにだいぶ時間が掛かってしまいましたが、ハンズオンの裏には膨大な情報があることがよくわかりました。
  • 噛めば噛むほど味がでる、とてもよいコンテンツです。
  • 次回も是非参加したいですね!抽選漏れてもハンズオンはやるぞ!!!
プライバシーポリシー