Google Cloudとコンテナの継続的なセキュリティ
本文の内容は、2019年7月9日にSysdigのKaizhe Huangが投稿したブログ(https://sysdig.com/blog/how-to-detect-kubernetes-vulnerability-cve-2019-11246-using-falco/)を元に日本語に翻訳・再構成した内容となっております。
最近のCNCF主催のKubernetesセキュリティ監査でCVE-2019-11246が発見されました。これはコマンドラインのkubectlツールに影響を及ぼす重大度の高い脆弱性です。 悪用された場合は、ディレクトリートラバーサルで悪意のあるコンテナがユーザーのワークステーション上のファイルを置き換えたり作成したりする可能性があります。この脆弱性は以前に公開された脆弱性(CVE-2019-1002101)の不完全な修正によるものです。
CVE 概要
CVEは2つのフェーズで構成されています。
あなたの環境は脆弱な状態ですか?
kubectl version --clientを実行し、クライアントのバージョンが1.12.9、1.13.6、または1.14.2以降ではない場合、脆弱なバージョンを実行しています。
どのようにアップグレードを行うのか?
https://kubernetes.io/docs/tasks/tools/install-kubectl/こちらのインストール手順に従ってください。
この発表の時点で、すべてのインストールガイドが最新のkubectlバージョンを提供するわけではありません。 常にkubectlバージョンである事を確認しましょう。
CVEエクスプロイト検出
このブログ記事では、CNCFオープンソースプロジェクトのFalcoを使用して、このCVEで説明されているエクスプロイトの両方の段階を検出する方法を説明します。
Falcoは、コンテナとホストの異常な振る舞いを検出するために設計されたオープンソースのコンテナセキュリティモニタです。 当初FacloはSysdigプロジェクトでした。Falcoは、システムコールを利用して、すべてのシステムアクティビティのイベントストリームを生成します。 Falcoのルールエンジンは、このイベントストリームに基づいてルールを作成することを可能にし、異常に見えるシステムコールイベントを警告することを可能にします。 Falcoの柔軟な言語により、ホストレベルでルールを書き、疑わしい行動を特定することができます。
- rule: Write below monitored dir
desc: an attempt to write to any file below a set of binary directories
condition: >
evt.dir = < and open_write and monitored_dir
and not package_mgmt_procs
and not coreos_write_ssh_dir
and not exe_running_docker_save
and not python_running_get_pip
and not python_running_ms_oms
and not google_accounts_daemon_writing_ssh
and not cloud_init_writing_ssh
and not user_known_write_monitored_dir_conditions
output: >
File below a monitored directory opened for writing (user=%user.name
command=%proc.cmdline file=%fd.name parent=%proc.pname pcmdline=%proc.pcmdline gparent=%proc.aname[2] container_id=%container.id image=%container.image.repository)
priority: ERROR
tags: [filesystem, mitre_persistence]
Output:
10:16:16.067583414: Error File below a known binary directory opened for writing (user=root command=cp /tmp/tar.hacked /bin/tar file=/bin/tar parent=bash pcmdline=bash gparent=containerd-shim container_id=404b298fb6ee image=nginx) k8s.ns=default k8s.pod=nginx container=404b298fb6ee k8s.ns=default k8s.pod=nginx container=404b298fb6ee
Falcoルールアラートの出力から、/bin/tarファイルを/tmpフォルダのtar.hackedファイルで上書きしようとしています。これは正に疑わしい振る舞いです。 出力には、コンテナ、イメージ、pod、namespace情報などに関する詳細な情報も含まれます。
- macro: safe_kubectl_version
condition: (jevt.value[/userAgent] startswith "kubectl/v1.15" or
jevt.value[/userAgent] startswith "kubectl/v1.14.3" or
jevt.value[/userAgent] startswith "kubectl/v1.14.2" or
jevt.value[/userAgent] startswith "kubectl/v1.13.7" or
jevt.value[/userAgent] startswith "kubectl/v1.13.6" or
jevt.value[/userAgent] startswith "kubectl/v1.12.9")
# CVE-2019-1002101
# Run kubectl version --client and if it does not say client version 1.12.9,
1.13.6, or 1.14.2 or newer, you are running a vulnerable version.
- rule: K8s Vulnerable Kubectl Copy
desc: Detect any attempt vulnerable kubectl copy in pod
condition: kevt_started and pod_subresource and kcreate and
ka.target.subresource = "exec" and ka.uri.param[command] = "tar" and
not safe_kubectl_version
output: Vulnerable kubectl copy detected (user=%ka.user.name pod=%ka.target.name ns=%ka.target.namespace action=%ka.target.subresource command=%ka.uri.param[command] userAgent=%jevt.value[/userAgent])
priority: WARN
source: k8s_audit
tags: [k8s]
Output:
09:51:26.488577024: Warning Vulnerable kubectl copy detected (user=kubernetes-admin pod=nginx ns=default action=exec command=tar userAgent=kubectl/v1.13.4 (linux/amd64) kubernetes/c27b913)
CVE修正で説明されているように、kubectlバージョン1.13.4にはDevOpsが注意すべき脆弱性があり、それに応じたパッチ計画をセットアップするべきです。これは、FalcoエンジンがコンテナーおよびKubernetes環境で発生している悪意のある活動を正確に特定するのにお役に立てる事を示唆しています。
考慮すべき事項
いくつかの攻撃は複数の段階で起こります。 ビットコインマイニングでは、攻撃に対するより良い洞察を提供するために悪質なアクティビティを相互に関連付けることが非常に重要になります。 上記のkubectl cpの脆弱性の悪用の例では、/bin/tarファイルの置き換えとkubectlの両方が同じpod内に存在します。 pod名に基づいて2つのイベントを追加すると、真のkubectl cpの脆弱性の悪用が明らかになります。
結論
Kubernetesは急速に進化しており、コードの問題はセキュリティの脆弱性へと発展することがあります。 セキュリティの観点からは、アプリケーション/インフラストラクチャに適切なタイミングでパッチを適用することが常に重要です。さらに重要なことは、本番環境でクラウドネイティブの環境用の堅牢で包括的なセキュリティソリューションを準備しておくことが非常に重要です。
リファレンスリンク:
https://www.cvedetails.com/cve/CVE-2019-1002101/
https://github.com/kubernetes/kubernetes/pull/75037
https://cve.mitre.org/cgi-bin/cvename.cgi?name=2019-11246