Ce produit n'est pas pris en charge par le site Datadog que vous avez sélectionné. ().

Overview

App and API Protection works by leveraging the Datadog Node.js library to monitor and secure your Node.js service. The library integrates seamlessly with your existing application without requiring code changes.

For detailed compatibility information, including supported Node.js versions, frameworks, and deployment environments, see Node.js Compatibility Requirements.

This guide explains how to set up App and API Protection (AAP) for Node.js applications. The setup involves:

  1. Installing the Datadog Agent
  2. Enabling App and API Protection monitoring
  3. Running your Node.js application with the Datadog Agent
  4. Verifying the setup

Prérequis

  • Environnement AWS Fargate
  • Application Node.js conteneurisée avec Docker
  • AWS CLI configuré avec les autorisations appropriées
  • Votre clé d’API Datadog
  • SDK Datadog Node.js (voir exigences de version)

1. Installation du Datadog Agent

Installez le Datadog Agent dans votre définition de tâche Fargate :

{
  "containerDefinitions": [
    {
      "name": "datadog-agent",
      "image": "public.ecr.aws/datadog/agent:latest",
      "environment": [
        {
          "name": "DD_API_KEY",
          "value": "<YOUR_API_KEY>"
        },
        {
          "name": "DD_APM_ENABLED",
          "value": "true"
        },
        {
          "name": "DD_APM_NON_LOCAL_TRAFFIC",
          "value": "true"
        }
      ]
    }
  ]
}

2. Activation de la surveillance de la protection des applications et des API

Automatically enabling App and API Protection through Remote Configuration

APM Tracing cannot be disabled for the time being with remote config.

You can enable remote configuration on your services dashboard. Simply check the box for the service you want to enable App and API Protection for under "Activate on your APM services".

Activation manuelle de la surveillance de la protection des applications et des API

Assurez-vous que votre Dockerfile inclut la bibliothèque Datadog Node.js :

FROM node:18-alpine

# Install the Datadog Node.js library
RUN npm install dd-trace

# Copy your application files
COPY package*.json ./
COPY . .
RUN npm install

# Start the application with the Datadog SDK
CMD ["node", "--require", "dd-trace/init", "app.js"]

Mettez à jour votre définition de tâche pour inclure le conteneur d’application Node.js avec la configuration de la protection des applications et des API :

{
  "containerDefinitions": [
    {
      "name": "your-nodejs-app",
      "image": "your-nodejs-app-image",
      "environment": [
        {
          "name": "DD_APPSEC_ENABLED",
          "value": "true"
        },
        {
          "name": "DD_SERVICE",
          "value": "<YOUR_SERVICE_NAME>"
        },
        {
          "name": "DD_ENV",
          "value": "<YOUR_ENVIRONMENT>"
        }
      ]
    }
  ]
}

Pour désactiver le traçage APM tout en conservant la protection des applications et des API activée, vous devez définir la variable de traçage APM sur false.

Mettez à jour votre définition de tâche pour inclure le conteneur d’application Node.js avec la configuration de la protection des applications et des API :

{
  "containerDefinitions": [
    {
      "name": "your-nodejs-app",
      "image": "your-nodejs-app-image",
      "environment": [
        {
          "name": "DD_APPSEC_ENABLED",
          "value": "true"
        },
        {
          "name": "DD_APM_TRACING_ENABLED",
          "value": "false"
        },
        {
          "name": "DD_SERVICE",
          "value": "<YOUR_SERVICE_NAME>"
        },
        {
          "name": "DD_ENV",
          "value": "<YOUR_ENVIRONMENT>"
        }
      ]
    }
  ]
}

3. Exécutez votre application

Déployez votre tâche Fargate avec la configuration mise à jour :

aws ecs register-task-definition --cli-input-json file://task-definition.json
aws ecs run-task --cluster your-cluster --task-definition your-task-definition

4. Verify setup

To verify that App and API Protection is working correctly:

  1. Send some traffic to your application
  2. Check the Application Signals Explorer in Datadog
  3. Look for security signals and vulnerabilities

Dépannage

Si vous rencontrez des problèmes lors de la configuration de la protection des applications et des API pour votre application Node.js, consultez le guide de dépannage de la protection des applications et des API Node.js.

Pour aller plus loin