コンテンツにスキップ

Wallarm cloud-initスクリプトの仕様

Infrastructure as Code(IaC)のアプローチに従う場合、パブリッククラウドにWallarmノードをデプロイするためにcloud-initスクリプトを使用する必要がある場合があります。リリース4.0以降、Wallarmは、本トピックで説明するすぐに使用可能なcloud-init.pyスクリプトを同梱したクラウドイメージを配布しています。

Wallarm cloud-initスクリプトの概要

Wallarmのcloud-initスクリプトはWallarm AWSクラウドイメージ内の/opt/wallarm/usr/share/wallarm-common/cloud-init.pyパスにあります。このスクリプトは、以下の主な段階を通じて、インスタンスの初期設定および詳細設定の両方を実行します。

  • Wallarmのregister-nodeスクリプトを実行して、Wallarm Cloudで事前に作成したWallarmノードを起動します

  • preset変数に指定されたプロキシ方式に従ってインスタンスを構成します(Terraformモジュールを使用してWallarmをデプロイする場合)

  • NGINXスニペットに従ってインスタンスを詳細設定します

  • Wallarmノードを詳細設定します

  • ロードバランサーのヘルスチェックを実行します

cloud-initスクリプトはインスタンスの起動時に一度だけ実行され、インスタンスの再起動では再実行されません。詳細はスクリプトの概念に関するAWSドキュメントをご参照ください。

Wallarm cloud-initスクリプトの実行

Wallarm cloud-initスクリプトは次の方法で実行できます。

  • クラウドインスタンスを起動し、そのメタデータにcloud-init.pyスクリプトの実行内容を記述します

  • cloud-init.pyスクリプトを含むインスタンスのLaunch Templateを作成し、それに基づいてAuto Scaling groupを作成します

httpbin.org向けのプロキシサーバーとしてWallarmノードを実行するためのスクリプト実行例:

#!/bin/bash
set -e

### Wallarmを有効化しないままNGINXが実行されないようにします。
### すべての処理が完了する前にヘルスチェックを実行することは
### 推奨しません。
###
systemctl stop nginx.service

/opt/wallarm/usr/share/wallarm-common/cloud-init.py \
    -t xxxxx-base64-registration-token-from-wallarm-cloud-xxxxx \
    -p proxy \
    -m monitoring \
    --proxy-pass https://httpbin.org

systemctl restart nginx.service

echo Wallarm Node successfuly configured!

IaCのアプローチに沿うため、Wallarmのcloud-initスクリプトの使用例として参考になるAWS向けTerraformモジュールを実装しています。

Wallarm cloud-initスクリプトのヘルプデータ

usage: /opt/wallarm/usr/share/wallarm-common/cloud-init.py [-h] -t TOKEN [-H HOST] [--skip-register] [-p {proxy,custom}]
                                                      [-m {off,monitoring,safe_blocking,block}] [--proxy-pass PROXY_PASS]
                                                      [--libdetection] [--global-snippet GLOBAL_SNIPPET_FILE]
                                                      [--http-snippet HTTP_SNIPPET_FILE] [--server-snippet SERVER_SNIPPET_FILE]
                                                      [-l LOG_LEVEL]

Runs the Wallarm node with the specified configuration in the PaaS cluster. https://docs.wallarm.com/installation/cloud-platforms/cloud-init/

optional arguments:
  -h, --help            show this help message and exit
  -t TOKEN, --token TOKEN
                        Wallarm node token copied from the Wallarm Console UI.
  -H HOST, --host HOST  Wallarm API server specific for the Wallarm Cloud being used: https://docs.wallarm.com/about-wallarm/overview/#cloud. By default, api.wallarm.com.
  --skip-register       Skips the stage of local running the node created in the Wallarm Cloud (skips the register-node script
                        execution). This stage is crucial for successful node deployment.
  -p {proxy,custom}, --preset {proxy,custom}
                        Wallarm node preset: "proxy" for the node to operate as a proxy server, "custom" for configuration defined via NGINX snippets only.
  -m {off,monitoring,safe_blocking,block}, --mode {off,monitoring,safe_blocking,block}
                        Traffic filtration mode: https://docs.wallarm.com/admin-en/configure-parameters-en/#wallarm_mode.
  --proxy-pass PROXY_PASS
                        Proxied server protocol and address. Required if "proxy" is specified as a preset.
  --libdetection        Whether to use the libdetection library during the traffic analysis: https://docs.wallarm.com/about-wallarm/protecting-against-attacks/#library-libdetection.
  --global-snippet GLOBAL_SNIPPET_FILE
                        Custom configuration to be added to the NGINX global configuration.
  --http-snippet HTTP_SNIPPET_FILE
                        Custom configuration to be added to the "http" configuration block of NGINX.
  --server-snippet SERVER_SNIPPET_FILE
                        Custom configuration to be added to the "server" configuration block of NGINX.
  -l LOG_LEVEL, --log LOG_LEVEL
                        Level of verbosity.

This script covers a few most popular configurations for AWS, GCP, Azure and other PaaS. If you need a more powerful configuration,
you are welcome to review Wallarm node public documentation: https://docs.wallarm.com.