Docker、Kubernetes、Amazon ECS、AWS Fargate で実行されている Node.js アプリのアプリケーションセキュリティを監視することができます。

In general, setting up Application Security Management (ASM) involves:

  1. Identifying services that are vulnerable or are under attack, which would most benefit from ASM. Find them on the Security tab of your Service Catalog.
  2. Updating to the latest Datadog library (the most recent APM tracing library).
  3. Enabling the library to collect the application security data from the services and send it to Datadog.
  4. Triggering security signals in your application and seeing how Datadog displays the resulting information.

Prerequisites

1-Click Enablement
If your service is running with an Agent with Remote Configuration enabled and a tracing library version that supports it, hover over the Not Enabled indicator in the ASM Status column and click Enable ASM. There's no need to re-launch the service with the DD_APPSEC_ENABLED=true or --enable-appsec flags.

脅威検出を有効にする

はじめに

  1. 以下のコマンドのいずれかを実行して、Datadog Node.js ライブラリパッケージを少なくともバージョン 2.23.0 (NodeJS 12+ の場合) または 3.10.0 (NodeJS 14+ の場合) に更新します

    npm install dd-trace@^2.23.0
    npm install dd-trace@^3.10.0
    

    または、以前にインストールした 1.x バージョンから更新するには

    npm install dd-trace@2
    

    ライブラリを 1.x から 2.x にアップグレードした場合は、この移行ガイドを使用して破壊的変更を評価してください。

    Application Security Management は、Express v4+ および NodeJS v12.17.0+ と互換性があります。詳細については、互換性を参照してください。

  2. **APM 用の Node.js ライブラリをインポートして初期化する場合は、ASM も有効にしてください。**これは、コードの中か、環境変数の中か、どちらかでしょう。コードで APM を初期化した場合は、init 文に {appsec: true} を追加してください。

    // この行は、インスツルメントされたいずれのモジュールのインポートより前である必要があります。
    const tracer = require('dd-trace').init({
      appsec: true
    })
    

    EcmaScript モジュール構文をサポートする TypeScript およびバンドラーの場合、正しいロード順序を維持するために、別のファイルでトレーサーを初期化します。

    // server.ts
    import './tracer'; // インスツルメントされたいずれのモジュールのインポートより前である必要があります。
    
    // tracer.ts
    import tracer from 'dd-trace';
    tracer.init({
      appsec: true
    }); // ホイストを避けるため異なるファイルで初期化。
    export default tracer;
    

    デフォルトの構成で十分であるか、またはすべての構成が環境変数を通じて行われる場合は、dd-trace/init を使用してもよく、これにより一度にロードと初期化が行えます。

    import `dd-trace/init`;
    

または Node.js の --require オプションを使用してコマンドラインで APM ライブラリを初期化する場合

node --require dd-trace/init app.js

そして、環境変数を使って ASM を有効にします。

DD_APPSEC_ENABLED=true node app.js

この方法は、サービスの実行場所によって異なります。

APM 用の構成コンテナを更新するには、docker run コマンドに以下の引数を追加します。

docker run [...] -e DD_APPSEC_ENABLED=true [...]

コンテナの Dockerfile に以下の環境変数の値を追加します。

ENV DD_APPSEC_ENABLED=true

APM 用の構成 yaml ファイルコンテナを更新し、AppSec の環境変数を追加します。

spec:
  template:
    spec:
      containers:
        - name: <CONTAINER_NAME>
          image: <CONTAINER_IMAGE>/<TAG>
          env:
            - name: DD_APPSEC_ENABLED
              value: "true"

以下を環境セクションに追加して、ECS タスク定義 JSON ファイルを更新します。

"environment": [
  ...,
  {
    "name": "DD_APPSEC_ENABLED",
    "value": "true"
  }
]

コード内で ASM を初期化するか、サービス起動時に環境変数 DD_APPSEC_ENABLEDtrue に設定します。

DD_APPSEC_ENABLED=true node app.js

After this configuration is complete, the library collects security data from your application and sends it to the Agent, which sends it to Datadog, where out-of-the-box detection rules flag attacker techniques and potential misconfigurations so you can take steps to remediate.

  1. To see Application Security Management threat detection in action, send known attack patterns to your application. For example, trigger the Security Scanner Detected rule by running a file that contains the following curl script:

    for ((i=1;i<=250;i++)); 
    do
    # Target existing service’s routes
    curl https://your-application-url/existing-route -A dd-test-scanner-log;
    # Target non existing service’s routes
    curl https://your-application-url/non-existing-route -A dd-test-scanner-log;
    done

    Note: The dd-test-scanner-log value is supported in the most recent releases.

    A few minutes after you enable your application and exercise it, threat information appears in the Application Signals Explorer and vulnerability information appears in the Vulnerability Explorer.

コードレベルの脆弱性検出の有効化

コードレベルの脆弱性検出のための Vulnerability Management をサポートするトレーシングライブラリのバージョンを実行しているサービスでは、DD_IAST_ENABLED=true 環境変数に設定してサービスを再起動することで機能を有効にしてください。

サービスにコードレベルの脆弱性検出機能を活用するには

  1. Datadog Agent をバージョン 7.41.1 以上に更新します。

  2. トレーシングライブラリを、コードレベルの脆弱性検出を有効にするために必要な最小限のバージョンに更新します。詳しくは、ASM 機能サポートを参照してください。

  3. アプリケーションの構成に DD_IAST_ENABLED=true 環境変数を追加します。

    Node.js の --require オプションを使用してコマンドラインで APM ライブラリを初期化する場合

    node --require dd-trace/init app.js
    

    そして、環境変数を使って ASM を有効にします。

    DD_IAST_ENABLED=true node app.js
    

    その方法は、サービスがどこで実行されているかによって変わります。

    APM 用の構成コンテナを更新するには、docker run コマンドに以下の引数を追加します。

    docker run [...] -e DD_IAST_ENABLED=true [...]
    

    コンテナの Dockerfile に以下の環境変数の値を追加します。

    ENV DD_IAST_ENABLED=true
    

    APM 用の構成 yaml ファイルコンテナを更新し、AppSec の環境変数を追加します。

    spec:
      template:
        spec:
          containers:
            - name: <CONTAINER_NAME>
              image: <CONTAINER_IMAGE>/<TAG>
              env:
                - name: DD_IAST_ENABLED
                  value: "true"
    

    以下を環境セクションに追加して、ECS タスク定義 JSON ファイルを更新します。

    "environment": [
      ...,
      {
        "name": "DD_IAST_ENABLED",
        "value": "true"
      }
    ]
    

  4. サービスを再起動します。

  5. コードレベルの脆弱性に対する Application Vulnerability Management の機能を実際に確認するには、サービスをブラウズし、Vulnerability Explorer でコードレベルの脆弱性が表示されるのを確認します。SOURCE 列には Code の値が表示されます。

さらにサポートが必要な場合は、Datadog サポートにお問い合わせください。

その他の参考資料