2014 年 9 月 24 日に発表された bash のリモート コード実行の脆弱性を考慮して、Ansible を使用して apt ベースのシステムを更新するにはどうすればよいですか?
7312 次
1 に答える
4
これは、かなり均一な環境での私の推奨ソリューションです。version=latest
これの利点は、他の人が使用しているパターンとは異なり、更新に時間がかからないことです。
- name: update apt cache if not done today
apt: update_cache=yes cache_valid_time=86400
# http://seclists.org/oss-sec/2014/q3/650
- name: ensure secure ansible, ubuntu 1204 edition
apt: pkg=bash=4.2-2ubuntu2.5 state=present
when: ansible_distribution=='Ubuntu' and ansible_distribution_version=='12.04'
- name: ensure secure ansible, ubuntu 1404 edition
apt: pkg=bash=4.3-7ubuntu1.3 state=present
when: ansible_distribution=='Ubuntu' and ansible_distribution_version=='14.04'
# based on the following gist and comments below. there have been several exploits, this covers them well.
# https://gist.github.com/kacy/2b9408af04c71fab686e
- name: ensure bash is not vulnerable to 201409 problem
shell: "foo='() { echo not patched; }' bash -c foo"
register: command_result
ignore_errors: yes
failed_when: "'command not found' not in command_result.stderr"
説明: apt-cache の更新は、1 日に何度も行うとコストがかかります。キャッシュ時間は調整できます。コードは実際にテストして、脆弱性が修正されていることを確認します。テストは適切です。これにより、コード化されたディストリビューション/バージョンでカバーされていないホストが強調表示されます。
SO ユーザー @jarvも優れたソリューションを投稿しました。apt を常に更新するのではなく、問題が修正されていない場合にのみ更新します。これは可能な限り最速のソリューションです(少なくともこの回答では)。jarv は、リンクされたリポジトリに分散テストも追加しました。これは、異種環境に役立ちます。
- name: Check if we are vulnerable
shell: executable=/bin/bash env x='() { :;}; echo vulnerable' bash -c "echo this is a test"
register: test_vuln
- name: Apply bash security update if we are vulnerable
apt: name=bash state=latest update_cache=true
when: "'vulnerable' in test_vuln.stdout"
- name: Check again and fail if we are still vulnerable
shell: executable=/bin/bash env x='() { :;}; echo vulnerable' bash -c "echo this is a test"
when: "'vulnerable' in test_vuln.stdout"
register: test_vuln
failed_when: "'vulnerable' in test_vuln.stdout"
他の方法があります。Ansible の作成者である Michael DeHaan と公式の @ansible アカウントは、いくつかのソリューションをツイートしました。
ここにワンライナーがあります:
ansible all -m apt -a 'update_cache=yes name=bash state=latest'
更新とチェックのソリューションは次のとおりです。
- name: update apt
command: apt-get update
- name: update bash
command: apt-get --only-upgrade install bash
- name: check bash fix
command: env x='() { :;}; echo vulnerable' bash -c "echo this is a test"
register: command_result
failed_when: "'error' not in command_result.stderr"
于 2014-09-24T19:01:40.167 に答える