mondoo.client

MondooパッケージAnsibleロール

mondoo ansible role illustration

概要

このロールは、LinuxおよびWindowsサーバーにcnquerycnspecをインストールします。

主な機能は以下の通りです:

  • 署名されたcnquerycnspecのバイナリをインストール
  • Mondooプラットフォームにcnquerycnspecを登録
  • LinuxおよびWindowsでcnspecサービスを有効化

サポートされているオペレーティングシステム:

  • Amazon Linux
  • Debian
  • Red Hat Enterprise Linux およびその派生版(CentOS/AlmaLinux/Rocky Linux)
  • SUSE & openSUSE
  • Ubuntu
  • Windows 10, 11, 2016, 2019, 2022

このロールはAnsible Galaxyに公開されています:Mondoo/Client役割

要件

  • Ansible > 2.5

ロール変数

名前 デフォルト値 説明
registration_token_retrieval manual manualは``registration_token`を設定する必要があります
registration_token n/a cnquerycnspecの登録に使用するMondooプラットフォームの登録トークンを手動で設定
force_registration false 各実行で再登録を強制するかどうか

依存関係

このロールには依存関係がありません。

例:AnsibleプレイブックをAmazon EC2 Linuxインスタンスに適用する

このプレイブックは、Mondooパッケージロールを使用して多くのインスタンスにcnquerycnspecをインストールする方法を示します:

  1. 新しいhostsインベントリを作成し、ホストをグループに追加します。
[linux_hosts]
54.172.7.243  ansible_user=ec2-user
  1. playbook.ymlを作成し、registration_tokenを変更します:
---
- hosts: linux_hosts
  become: yes
  roles:
    - role: ansible-mondoo # galaxyから使用する場合: mondoo.client
      vars:
        registration_token: "changeme"

さらに、以下の変数もサポートしています:

変数 説明
force_registration: true cnquerycnspecを再登録したい場合はtrueに設定
ensure_managed_client: true 設定したクライアントがMondooの管理対象クライアントとして設定されていることを確認
proxy_env['https_proxy'] cnspecクライアントのプロキシを設定
annotations ノードにアノテーション/タグを設定
update_linux_enabled Linuxの更新タスクをcronジョブ経由で有効にしたい場合はtrueに設定
update_linux_cron_day cnspecの更新間隔を日単位で定義します。例:*/3は3日ごと
update_linux_cron_hour タスクを実行する時間を定義
update_linux_cron_minute タスクを実行する分を定義
update_windows_enabled Windowsの更新タスクをスケジュールされたタスク経由で有効にしたい場合はtrueに設定
update_windows_interval cnspecの更新の間隔を日単位で定義
update_windows_time タスクを実行する時間を定義
timer スキャン間隔を分単位で設定します。デフォルトは60です。
splay スキャンタイミングの遅延を定義
---
- hosts: linux_hosts
  become: yes
  roles:
    - role: ansible-mondoo # galaxyから使用する場合: mondoo.client
      vars:
        registration_token: "changeme"
        force_registration: true
        ensure_managed_client: true
        annotations: "[email protected],env=production"

プロキシの背後でcnspecを使用する場合:

---
- hosts: linux_hosts
  become: yes
  vars:
    proxy_env:
      http_proxy: "http://192.168.56.1:3128"
      https_proxy: "http://192.168.56.1:3128"

  roles:
    - role: ansible-mondoo # galaxyから使用する場合: mondoo.client
      vars:
        registration_token: "changeme"
        force_registration: true
        ensure_managed_client: true
      environment: "{{proxy_env}}"

Windowsの更新タスクを使用する場合:

---
- hosts: windows_hosts
  become: yes

  roles:
    - role: ansible-mondoo # galaxyから使用する場合: mondoo.client
      vars:
        registration_token: "changeme"
        force_registration: true
        ensure_managed_client: true
        update_windows_enabled: true
        update_windows_interval: "1"
        update_windows_time: "15:04"

Linuxの更新タスクを使用する場合:

---
- hosts: linux_hosts
  become: yes

  roles:
    - role: ansible-mondoo # galaxyから使用する場合: mondoo.client
      vars:
        registration_token: "changeme"
        force_registration: true
        ensure_managed_client: true
        update_linux_enabled: true
        update_linux_cron_day: "*"
        update_linux_cron_hour: "11"
        update_linux_cron_minute: "40"
  1. ローカルのホストファイルでプレイブックを実行します。
# GitHubからmondooロールをダウンロード
ansible-galaxy role install git+https://github.com/mondoohq/ansible-mondoo.git

# (代替) Ansible Galaxyからmondooロールをダウンロード
ansible-galaxy install mondoo.client

# プレイブックを適用
ansible-playbook -i hosts playbook.yml
  1. スキャン結果を表示するためにMondooコンソールにログインします。

AnsibleプレイブックをAmazon EC2 Windowsインスタンスに適用する

Windowsを使用している場合は、WinRMの設定またはSSHの設定についてのAnsibleのドキュメントを読んでください。

  1. 新しいhostsインベントリを作成し、ホストをグループに追加します。
[windows_hosts]
123.123.247.76 ansible_port=5986 ansible_connection=winrm ansible_user=Administrator ansible_password=changeme ansible_shell_type=powershell ansible_winrm_server_cert_validation=ignore

または、SSHを使用する場合:

3.235.247.76 ansible_port=22 ansible_connection=ssh ansible_user=admin ansible_shell_type=cmd
  1. playbook.ymlを作成し、registration_tokenを変更します:

Windowsをターゲットにする場合、設定は若干異なります。 becomeを無効にする必要があります:

- hosts: windows_hosts
  roles:
    - role: ansible-mondoo # galaxyから使用する場合: mondoo.client
      vars:
        registration_token: "changeme"
        force_registration: false
  1. ローカルのホストファイルでプレイブックを実行します。
# GitHubからmondooロールをダウンロード
ansible-galaxy role install git+https://github.com/mondoohq/ansible-mondoo.git

# (代替) Ansible Galaxyからmondooロールをダウンロード
ansible-galaxy install mondoo.client

# プレイブックを適用
ansible-playbook -i hosts playbook.yml

テスト

このロールはテストのためにMoleculeを使用します。依存関係をインストールするには:

pip install molecule
pip install docker
pip install 'molecule-plugins[docker]'

molecule CLIはテストライフサイクルをカバーします:

# moleculeをリセット
molecule reset
# ansibleでマシンを収束
image=geerlingguy/docker-ubuntu2204-ansible molecule converge
# cnspecでmoleculeテストを実行
image=geerlingguy/docker-ubuntu2204-ansible molecule verify
# デバッグのために個々のホストにログイン
molecule login --host ubuntu
# テストセットアップを破棄
molecule destroy
image=geerlingguy/docker-ubuntu2204-ansible molecule test
image=rsprta/opensuse-ansible molecule test

注意:M1 macOSでテストするには、上記のRocky LinuxのようなARM互換のDockerイメージが必要です。

Lintingにはansible-lintを使用します:

pip3 install ansible-lint

その後、ローカルの問題をすべて確認できます:

ansible-lint

著者

Mondoo, Inc

よくある質問

'module'オブジェクトに'HTTPSHandler'属性がありませんというエラー

TASK [mondoo : Download Mondoo RPM key] ********************************
    fatal: [suse]: FAILED! => {"changed": false, "module_stderr": "Shared connection to 127.0.0.1 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n  File \"/home/vagrant/.ansible/tmp/ansible-tmp-1562450830.52-85510064926638/AnsiballZ_get_url.py\", line 113, in <module>\r\n    _ansiballz_main()\r\n  File \"/home/vagrant/.ansible/tmp/ansible-tmp-1562450830.52-85510064926638/AnsiballZ_get_url.py\", line 105, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/home/vagrant/.ansible/tmp/ansible-tmp-1562450830.52-85510064926638/AnsiballZ_get_url.py\", line 48, in invoke_module\r\n    imp.load_module('__main__', mod, module, MOD_DESC)\r\n  File \"/tmp/ansible_get_url_payload_103dVU/__main__.py\", line 308, in <module>\r\n  File \"/tmp/ansible_get_url_payload_103dVU/ansible_get_url_payload.zip/ansible/module_utils/urls.py\", line 346, in <module>\r\nAttributeError: 'module' object has no attribute 'HTTPSHandler'\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
sudo zypper install python python2-urllib3 python3 python3-urllib3

WindowsでSSHを使用している場合のansible.legacy.setupのエラー

fatal: [123.123.247.76]: FAILED! => {"ansible_facts": {}, "changed": false, "failed_modules": {"ansible.legacy.setup": {"failed": true, "module_stderr": "Parameter format not correct - ;\r\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}}, "msg": "The following modules failed to execute: ansible.legacy.setup\n"}

powershellがシェルタイプの場合、Win32-OpenSSHのバージョンがv7.9.0.0p1-Betaより古い場合は正常に動作しません。シェルタイプをcmdに設定してください。

'jmespath'をインストールする必要がありますというエラー

jmespathがansibleと同じPython環境にインストールされていることを確認してください:

pip install jmespath

サポートされていないOSでテストしたい

main.ymlに以下を追加し、ansible_factsを印刷して、何が使用されているかを確認し、when条件を調整します:

- name: Print all available facts
  ansible.builtin.debug:
    var: ansible_facts

コミュニティに参加しよう!

MondooコミュニティGitHubディスカッションに参加して、政策のコーディングとセキュリティ自動化について共同作業をしましょう。

プロジェクトについて

Install and configure cnquery and cnspec

インストール
ansible-galaxy install mondoo.client
ライセンス
other
ダウンロード
12.4k
所有者
Cloud-Native Security & Vulnerability Management