コンテンツにスキップ

AWSへのWallarm Dockerイメージのデプロイ

このクイックガイドでは、NGINXベースのWallarmノードのDockerイメージAmazon Elastic Container Service (Amazon ECS)を使用してAmazonクラウドプラットフォームへデプロイする手順を示します。

手順の制限

これらの手順は、ロードバランシングやノードのオートスケーリングの設定についてはカバーしておりません。これらのコンポーネントを自分で設定する場合は、AWSの手順の該当部分を確認することを推奨します。

ユースケース

Among all supported Wallarm deployment options, Wallarm deployment on AWS ECS using the Docker image is recommended in these use cases:

  • If your applications leverage a microservices architecture, and are already containerized and operational on AWS ECS.

  • If you require fine-grained control over each container, the Docker image excels. It affords a greater level of resource isolation than typically possible with traditional VM-based deployments.

必要条件

  • admin 権限を持つAWSアカウントおよびユーザー

  • AWS CLI 1またはAWS CLI 2が正しくインストールおよび設定されていること

  • US CloudまたはEU CloudのWallarm Consoleにおいて、Administratorロールで二要素認証が無効のアカウントへのアクセス

  • 攻撃検出ルールの更新ダウンロードやAPI仕様書の取得、allowlisted, denylisted, or graylisted国、地域、またはデータセンターの正確なIP取得用に、下記のIPアドレスへのアクセス

    34.96.64.17
    34.110.183.149
    35.235.66.155
    34.102.90.100
    34.94.156.115
    35.235.115.105
    
    34.160.38.183
    34.144.227.90
    34.90.110.226
    

WallarmノードDockerコンテナの設定オプション

The filtering node configuration parameters should be passed to the deployed Docker container in one of the following ways:

  • In the environment variables. This option allows for the configuration of only basic filtering node parameters. Most directives cannot be configured through environment variables.

  • In the mounted configuration file. This option allows full filtering node configuration via any directives. With this configuration method, environment variables with the filtering node and Wallarm Cloud connection settings are also passed to the container.

環境変数による設定のみで構成されたWallarmノードDockerコンテナのデプロイ

環境変数のみで設定されたコンテナ化されたWallarmフィルタリングノードをデプロイするために、AWS Management ConsoleおよびAWS CLIを使用します。

  1. Get Wallarm token of the appropriate type:

    1. Open Wallarm Console → SettingsAPI tokens in the US Cloud or EU Cloud.
    2. Find or create API token with the Node deployment/Deployment usage type.
    3. Copy this token.
    1. Open Wallarm Console → Nodes in the US Cloud or EU Cloud.
    2. Do one of the following:
      • Create the node of the Wallarm node type and copy the generated token.
      • Use existing node group - copy token using node's menu → Copy token.
  2. AWS Management Console にサインインし、ServicesリストからElastic Container Serviceを選択します。

  3. Create Clusterボタンをクリックしてクラスター作成に進みます:

    1. テンプレートとしてEC2 Linux + Networkingを選択します。
    2. クラスター名を指定します(例:wallarm-cluster)。
    3. 必要に応じて、AWSの手順に従いその他の設定を行います。
    4. クラスターを保存します。
  4. Wallarm Cloudに接続するために必要な機微なデータ(ノードトークン)を、AWS Secrets ManagerまたはAWS Systems Manager → Parameter Storeを使用して暗号化します。

    本手順では、機微なデータはAWS Secrets Managerに保存されます。

    機微なデータストレージへのアクセス

    Dockerコンテナが暗号化された機微なデータを読み取れるようにするため、AWSの設定が以下の要件を満たしていることを確認してください:

    • 機微なデータはDockerコンテナ実行に使用するリージョンに保存されていること。
    • タスク定義のexecutionRoleArnパラメータに指定されたユーザーに、IAMポリシーSecretsManagerReadWriteがアタッチされていること。IAMポリシーの設定の詳細 →
  5. タスク定義(タスク定義はDockerコンテナの動作シナリオを設定します)の内容を記述した以下のローカルJSONファイルを作成します:

    {
        "executionRoleArn": "arn:aws:iam::<AWS_ACCOUNT_ID>:role/ecsTaskExecutionRole",
        "containerDefinitions": [
            {
                "memory": 128,
                "portMappings": [
               {
                   "hostPort": 80,
                   "containerPort": 80,
                   "protocol": "tcp"
               }
           ],
           "essential": true,
           "environment": [
               {
                   "name": "WALLARM_API_HOST",
                   "value": "us1.api.wallarm.com"
               },
               {
                   "name": "NGINX_BACKEND",
                   "value": "<HOST_TO_PROTECT_WITH_WALLARM>"
               },
               {
                   "name": "WALLARM_LABELS",
                   "value": "group=<GROUP>"
               }
           ],
           "secrets": [
               {
                   "name": "WALLARM_API_TOKEN",
                   "valueFrom": "arn:aws:secretsmanager:<SECRETS_MANAGER_AWS_REGION>:<AWS_ACCOUNT_ID>:secret:<SECRET_NAME>:<WALLARM_API_TOKEN_PARAMETER_NAME>::"
               }
           ],
           "name": "wallarm-container",
           "image": "registry-1.docker.io/wallarm/node:5.3.0"
           }
       ],
       "family": "wallarm-api-security-node"
       }
    
    {
        "executionRoleArn": "arn:aws:iam::<AWS_ACCOUNT_ID>:role/ecsTaskExecutionRole",
        "containerDefinitions": [
            {
                "memory": 128,
                "portMappings": [
               {
                   "hostPort": 80,
                   "containerPort": 80,
                   "protocol": "tcp"
               }
           ],
           "essential": true,
           "environment": [
               {
                   "name": "NGINX_BACKEND",
                   "value": "<HOST_TO_PROTECT_WITH_WALLARM>"
               },
               {
                   "name": "WALLARM_LABELS",
                   "value": "group=<GROUP>"
               }
           ],
           "secrets": [
               {
                   "name": "WALLARM_API_TOKEN",
                   "valueFrom": "arn:aws:secretsmanager:<SECRETS_MANAGER_AWS_REGION>:<AWS_ACCOUNT_ID>:secret:<SECRET_NAME>:<WALLARM_API_TOKEN_PARAMETER_NAME>::"
               }
           ],
           "name": "wallarm-container",
           "image": "registry-1.docker.io/wallarm/node:5.3.0"
           }
       ],
       "family": "wallarm-api-security-node"
       }
    
    • <AWS_ACCOUNT_ID>: あなたのAWSアカウントID
    • environmentオブジェクトは、テキスト形式でDockerコンテナに渡す環境変数を設定します。利用可能な環境変数の一覧は以下の表に記載されています。変数WALLARM_API_TOKENsecretsオブジェクトで渡すことを推奨します。
    • secretsオブジェクトは、機微なデータストレージへのリンクとしてDockerコンテナに渡す環境変数を設定します。値のフォーマットは選択したストレージに依存します(詳細はAWS Secrets ManagerまたはAWS Systems Manager → Parameter Storeのドキュメントを参照してください)。

      変数WALLARM_API_TOKENsecretsオブジェクトで渡すことを推奨します。

      Environment variable Description Required
      WALLARM_API_TOKEN Wallarm node or API token. Yes
      WALLARM_LABELS

      Available starting from node 4.6. Works only if WALLARM_API_TOKEN is set to API token with the Deploy role. Sets the group label for node instance grouping, for example:

      WALLARM_LABELS="group=<GROUP>"

      ...will place node instance into the <GROUP> instance group (existing, or, if does not exist, it will be created).

      Yes (for API tokens)
      NGINX_BACKEND Domain or IP address of the resource to protect with the Wallarm solution. Yes
      WALLARM_API_HOST Wallarm API server:
      • us1.api.wallarm.com for the US Cloud
      • api.wallarm.com for the EU Cloud
      By default: api.wallarm.com.
      No
      WALLARM_MODE Node mode:
      • block to block malicious requests
      • safe_blocking to block only those malicious requests originated from graylisted IP addresses
      • monitoring to analyze but not block requests
      • off to disable traffic analyzing and processing
      By default: monitoring.
      Detailed description of filtration modes →
      No
      WALLARM_APPLICATION Unique identifier of the protected application to be used in the Wallarm Cloud. The value can be a positive integer except for 0.

      Default value (if the variable is not passed to the container) is -1 which indicates the default application displayed in Wallarm Console → Settings → Application.

      More details on setting up applications →
      No
      SLAB_ALLOC_ARENA (TARANTOOL_MEMORY_GB [NGINX Node 5.x and earlier][what-is-new-wstore]) Amount of memory allocated to wstore. The value can be a float (a dot . is a decimal separator). By default: 1.0 (1 gygabyte). No
      NGINX_PORT Sets a port that NGINX will use inside the Docker container.

      Starting from the Docker image 4.0.2-1, the wallarm-status service automatically runs on the same port as NGINX.

      Default value (if the variable is not passed to the container) is 80.

      Syntax is NGINX_PORT='443'.
      No
      WALLARM_STATUS_ALLOW Custom CIDRs that are allowed to access the /wallarm-status endpoint from outside the Docker container. Example value: 10.0.0.0/8. If you need to pass several values, use a comma , as a separator. To access the service externally, use the Docker container's IP, specifying the /wallarm-status endpoint path. No
      DISABLE_IPV6 The variable with any value except for an empty one deletes the listen [::]:80 default_server ipv6only=on; line from the NGINX configuration file which will stop NGINX from IPv6 connection processing.

      If the variable is not specified explicitly or has an empty value "", NGINX processes both IPv6 and IPv4 connections.
      No
      WALLARM_APIFW_ENABLE This setting toggles API Specification Enforcement on or off, available from release 4.10 onwards. Please note that activating this feature does not substitute for the required subscription and configuration through the Wallarm Console UI.

      Its default value is true, enabling the functionality.
      No
      WALLARM_APID_ONLY (5.3.7 and higher) In this mode, attacks detected in your traffic are blocked locally by the node (if enabled) but not exported to Wallarm Cloud. Meanwhile, API Discovery and some other features remain fully functional, detecting your API inventory and uploading it to the Cloud for visualization. This mode is for those who want to review their API inventory and identify sensitive data first, and plan controlled attack data export accordingly. However, disabling attack export is rare, as Wallarm securely processes attack data and provides sensitive attack data masking if needed. More details
      By default: false.
      No
    • 全ての設定ファイルパラメータはAWSのドキュメントに記載されています。

  6. ローカルのJSON構成ファイルを使用して、aws ecs register‑task‑definitionコマンドによりタスク定義を登録します:

    aws ecs register-task-definition --cli-input-json file://<PATH_TO_JSON_FILE>/<JSON_FILE_NAME>
    
    • <PATH_TO_JSON_FILE>: タスク定義が記載されたJSONファイルのローカルマシン上のパス。
    • <JSON_FILE_NAME>: タスク定義が記載されたJSONファイルのファイル名および拡張子。
  7. aws ecs run-taskコマンドを使用して、クラスター内でタスクを実行します:

    aws ecs run-task --cluster <CLUSTER_NAME> --launch-type EC2 --task-definition <FAMILY_PARAM_VALUE>
    
    • <CLUSTER_NAME>: 1番目のステップで作成したクラスター名(例:wallarm-cluster)。
    • <FAMILY_PARAM_VALUE>: 作成したタスク定義の名前。JSONファイル内で指定されたfamilyパラメータの値に対応する必要があります(例:wallarm-api-security-node)。
  8. AWS Management ConsoleでElastic Container Service→実行中のタスクがあるクラスター→Tasksを開き、タスクが一覧に表示されていることを確認します。

  9. フィルタリングノードの動作をテストします。

マウントファイルによる設定が適用されたWallarmノードDockerコンテナのデプロイ

環境変数とマウントされたファイルによって構成されたコンテナ化されたWallarmフィルタリングノードをデプロイするために、AWS Management ConsoleおよびAWS CLIを使用します。

本手順では、設定ファイルはAWS EFSファイルシステムからマウントされます。ファイルのマウントその他の方法については、AWSのドキュメントを確認してください。

環境変数およびAWS EFSからマウントされた設定ファイルでコンテナをデプロイするには:

  1. Get Wallarm token of the appropriate type:

    1. Open Wallarm Console → SettingsAPI tokens in the US Cloud or EU Cloud.
    2. Find or create API token with the Node deployment/Deployment usage type.
    3. Copy this token.
    1. Open Wallarm Console → Nodes in the US Cloud or EU Cloud.
    2. Do one of the following:
      • Create the node of the Wallarm node type and copy the generated token.
      • Use existing node group - copy token using node's menu → Copy token.
  2. AWS Management Console にサインインし、ServicesリストからElastic Container Serviceを選択します。

  3. Create Clusterボタンをクリックしてクラスター作成に進みます:

    • Template: EC2 Linux + Networking
    • Cluster name: 例としてwallarm-cluster
    • Provisioning Model: On-Demand Instance
    • EC2 instance type: t2.micro
    • Number of instances: 1
    • EC2 AMI ID: Amazon Linux 2 Amazon ECS-optimized AMI
    • Key pair: SSH接続用のkey pair(設定ファイルをストレージへアップロードするために、SSHでインスタンスに接続する必要があります)
    • その他の設定はデフォルトのままで構いません。他の設定を変更する場合は、AWS EFSの設定手順に従うことを推奨します。
  4. AWSの手順のステップ2~4に従い、AWS EFSストレージを設定します。

  5. AWSの手順4において、設定ファイルdefaultを作成し、デフォルトでマウントするディレクトリに配置します。ファイルdefaultにはフィルタリングノードの設定が記述されます。最小の設定例は以下です:

    server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;
        #listen 443 ssl;
    
        server_name localhost;
    
        #ssl_certificate cert.pem;
        #ssl_certificate_key cert.key;
    
        root /usr/share/nginx/html;
    
        index index.html index.htm;
    
        wallarm_mode monitoring;
        # wallarm_application 1;
    
        location / {
                proxy_pass http://example.com;
                include proxy_params;
        }
    }
    

    設定ファイルに指定可能なフィルタリングノードディレクティブのセット →

  6. Wallarm Cloudに接続するために必要な機微なデータ(ノードトークン)を、AWS Secrets ManagerまたはAWS Systems Manager → Parameter Storeを使用して暗号化します。

    本手順では、機微なデータはAWS Secrets Managerに保存されます。

    機微なデータストレージへのアクセス

    Dockerコンテナが暗号化された機微なデータを読み取れるようにするため、AWSの設定が以下の要件を満たしていることを確認してください:

    • 機微なデータはDockerコンテナ実行に使用するリージョンに保存されていること。
    • タスク定義のexecutionRoleArnパラメータに指定されたユーザーに、IAMポリシーSecretsManagerReadWriteがアタッチされていること。IAMポリシーの設定の詳細 →
  7. 以下のローカルJSONファイルを作成し、タスク定義(タスク定義はDockerコンテナの動作シナリオを設定します)を記述します:

    {
        "executionRoleArn": "arn:aws:iam::<AWS_ACCOUNT_ID>:role/ecsTaskExecutionRole",
        "containerDefinitions": [
            {
                "memory": 128,
                "portMappings": [
               {
                   "hostPort": 80,
                   "containerPort": 80,
                   "protocol": "tcp"
               }
           ],
           "essential": true,
           "mountPoints": [
               {
                   "containerPath": "<PATH_FOR_MOUNTED_CONFIG>",
                   "sourceVolume": "<NAME_FROM_VOLUMES_OBJECT>"
               }
           ],
           "environment": [
               {
                   "name": "WALLARM_API_HOST",
                   "value": "us1.api.wallarm.com"
               },
               {
                   "name": "WALLARM_LABELS",
                   "value": "group=<GROUP>"
               }
           ],
           "secrets": [
               {
                   "name": "WALLARM_API_TOKEN",
                   "valueFrom": "arn:aws:secretsmanager:<SECRETS_MANAGER_AWS_REGION>:<AWS_ACCOUNT_ID>:secret:<SECRET_NAME>:<WALLARM_API_TOKEN_PARAMETER_NAME>::"
               }
           ],
           "name": "wallarm-container",
           "image": "registry-1.docker.io/wallarm/node:5.3.0"
           }
       ],
       "volumes": [
           {
               "name": "<VOLUME_NAME>",
               "efsVolumeConfiguration": {
                   "fileSystemId": "<EFS_FILE_SYSTEM_ID>",
                   "transitEncryption": "ENABLED"
               }
           }
       ],
       "family": "wallarm-api-security-node"
       }
    
    {
        "executionRoleArn": "arn:aws:iam::<AWS_ACCOUNT_ID>:role/ecsTaskExecutionRole",
        "containerDefinitions": [
            {
                "memory": 128,
                "portMappings": [
               {
                   "hostPort": 80,
                   "containerPort": 80,
                   "protocol": "tcp"
               }
           ],
           "essential": true,
           "mountPoints": [
               {
                   "containerPath": "/etc/nginx/sites-enabled",
                   "sourceVolume": "default"
               }
           ],
           "environment": [
               {
                   "name": "WALLARM_LABELS",
                   "value": "group=<GROUP>"
               }
           ],
           "secrets": [
               {
                   "name": "WALLARM_API_TOKEN",
                   "valueFrom": "arn:aws:secretsmanager:<SECRETS_MANAGER_AWS_REGION>:<AWS_ACCOUNT_ID>:secret:<SECRET_NAME>:<WALLARM_API_TOKEN_PARAMETER_NAME>::"
               }
           ],
           "name": "wallarm-container",
           "image": "registry-1.docker.io/wallarm/node:5.3.0"
           }
       ],
       "volumes": [
           {
               "name": "default",
               "efsVolumeConfiguration": {
                   "fileSystemId": "<EFS_FILE_SYSTEM_ID>",
                   "transitEncryption": "ENABLED"
               }
           }
       ],
       "family": "wallarm-api-security-node"
       }
    
    • <AWS_ACCOUNT_ID>: あなたのAWSアカウントID
    • <PATH_FOR_MOUNTED_CONFIG>: コンテナ内で設定ファイルをマウントするディレクトリ。設定ファイルはNGINXで以下のディレクトリにマウント可能です:

      • /etc/nginx/conf.d — 共通設定
      • /etc/nginx/sites-enabled — バーチャルホストの設定
      • /var/www/html — 静的ファイル

      フィルタリングノードのディレクティブは/etc/nginx/sites-enabled/defaultファイルに記述されるべきです。

    • <NAME_FROM_VOLUMES_OBJECT>: マウントされた設定ファイルのAWS EFSストレージの構成が記述されたvolumesオブジェクトの名称(値は<VOLUME_NAME>と一致させる必要があります)。

    • <VOLUME_NAME>: マウントされた設定ファイルのAWS EFSストレージの構成が記述されたvolumesオブジェクトの名称。
    • <EFS_FILE_SYSTEM_ID>: コンテナにマウントするファイルが存在するAWS EFSファイルシステムのID。IDはAWS Management ConsoleのServicesEFSFile systemsに表示されます。
    • environmentオブジェクトは、テキスト形式でDockerコンテナに渡す環境変数を設定します。利用可能な環境変数の一覧は以下の表に記載されています。変数WALLARM_API_TOKENsecretsオブジェクトで渡すことを推奨します。
    • secretsオブジェクトは、機微なデータストレージへのリンクとしてDockerコンテナに渡す環境変数を設定します。値のフォーマットは選択したストレージに依存します(詳細はAWS Secrets ManagerまたはAWS Systems Manager → Parameter Storeのドキュメントを参照してください)。

      変数WALLARM_API_TOKENsecretsオブジェクトで渡すことを推奨します。

      Environment variable Description Required
      WALLARM_API_TOKEN Wallarm node or API token. Yes
      WALLARM_API_HOST Wallarm API server:
      • us1.api.wallarm.com for the US Cloud
      • api.wallarm.com for the EU Cloud
      By default: api.wallarm.com.
      No
      WALLARM_LABELS

      Available starting from node 4.6. Works only if WALLARM_API_TOKEN is set to API token with the Deploy role. Sets the group label for node instance grouping, for example:

      WALLARM_LABELS="group=<GROUP>"

      ...will place node instance into the <GROUP> instance group (existing, or, if does not exist, it will be created).

      Yes (for API tokens)
      SLAB_ALLOC_ARENA (TARANTOOL_MEMORY_GB [NGINX Node 5.x and earlier][what-is-new-wstore]) Amount of memory allocated to wstore. The value can be a float (a dot . is a decimal separator). By default: 1.0 (1 gygabyte). No
      WALLARM_APID_ONLY (5.3.7 and higher) In this mode, attacks detected in your traffic are blocked locally by the node (if enabled) but not exported to Wallarm Cloud. Meanwhile, API Discovery and some other features remain fully functional, detecting your API inventory and uploading it to the Cloud for visualization. This mode is for those who want to review their API inventory and identify sensitive data first, and plan controlled attack data export accordingly. However, disabling attack export is rare, as Wallarm securely processes attack data and provides sensitive attack data masking if needed. More details
      By default: false.
      No
    • 全ての設定ファイルパラメータは、AWSのドキュメントに記載されています。

  8. ローカルのJSON構成ファイルを使用して、aws ecs register‑task‑definitionコマンドによりタスク定義を登録します:

    aws ecs register-task-definition --cli-input-json file://<PATH_TO_JSON_FILE>/<JSON_FILE_NAME>
    
    • <PATH_TO_JSON_FILE>: タスク定義が記載されたJSONファイルのローカルマシン上のパス。
    • <JSON_FILE_NAME>: タスク定義が記載されたJSONファイルのファイル名および拡張子。
  9. aws ecs run-taskコマンドを使用して、クラスター内でタスクを実行します:

    aws ecs run-task --cluster <CLUSTER_NAME> --launch-type EC2 --task-definition <FAMILY_PARAM_VALUE>
    
    • <CLUSTER_NAME>: 1番目のステップで作成したクラスター名(例:wallarm-cluster)。
    • <FAMILY_PARAM_VALUE>: 作成したタスク定義の名前。JSONファイル内で指定されたfamilyパラメータの値に対応する必要があります(例:wallarm-api-security-node)。
  10. AWS Management ConsoleでElastic Container Service→実行中のタスクがあるクラスター→Tasksを開き、タスクが一覧に表示されていることを確認します。

  11. フィルタリングノードの動作をテストします。

フィルタリングノードの動作テスト

  1. AWS Management Consoleで実行中のタスクを開き、External LinkフィールドからコンテナのIPアドレスをコピーします。

    Settig up container instance

    IPアドレスが空の場合は、コンテナがRUNNING状態になっているか確認してください。

  2. コピーしたアドレスに対して、テストPath Traversal攻撃のリクエストを送信します:

    curl http://<COPIED_IP>/etc/passwd
    
  3. Wallarm ConsoleでUS CloudまたはEU CloudAttacksを開き、攻撃が一覧に表示されていることを確認します。
    Attacks in UI

コンテナデプロイ時に発生したエラーの詳細は、AWS Management Consoleのタスク詳細に表示されます。コンテナが利用できない場合は、必要なフィルタリングノードパラメータが正しい値でコンテナに渡されていることを確認してください。