Docker で Python 用の App and API Protection をセットアップする
This product is not supported for your selected
Datadog site. (
).
You can enable App and API Protection for Python services with the following setup options:
- If your Python service already has APM tracing set up and running, then skip to service configuration
- If your Python service doesn't have APM tracing set up, you can easily enable App and API Protection with Datadog's Automatic Installation
- Otherwise, keep reading the following manual setup instructions
Overview
App and API Protection leverages the Datadog Python library to monitor and secure your Python service. The library integrates seamlessly with your existing application without requiring code changes.
For detailed compatibility information, including supported Python versions, frameworks, and deployment environments, see Python Compatibility Requirements.
This guide explains how to set up App and API Protection (AAP) for Python applications. The setup involves:
- Installing the Datadog Agent
- Enabling App and API Protection monitoring
- Running your Python application with the Datadog Agent
- Verifying the setup
前提条件
- ホストに Docker がインストールされている
- Docker でコンテナ化された Python アプリケーション
- Datadog API キー
- Datadog Python SDK (バージョン要件 を参照)
1. Datadog Agent をインストールする
Docker のセットアップ手順に従って Datadog Agent をインストールします。
2. App and API Protection モニタリングを有効化する
Automatically enabling App and API Protection through Remote Configuration
You can enable services with remote configuration on your services dashboard.
Check the box for the service you want to enable App and API Protection for under Activate on your APM services.
App and API Protection モニタリングを手動で有効化する
Dockerfile に次の環境変数を追加します。
# Install the Datadog Python SDK
RUN pip install ddtrace
# Set environment variables
ENV DD_APPSEC_ENABLED=true
ENV DD_SERVICE=<YOUR_SERVICE_NAME>
ENV DD_ENV=<YOUR_ENVIRONMENT>
# Use ddtrace-run to start your application
CMD ["ddtrace-run", "python", "app.py"]
App and API Protection を有効にしたまま APM トレースを無効にするには、APM トレース変数を false に設定する必要があります。
Dockerfile に次の環境変数を追加します。
# Install the Datadog Python SDK
RUN pip install ddtrace
# Set environment variables
ENV DD_APPSEC_ENABLED=true
ENV DD_APM_TRACING_ENABLED=false
ENV DD_SERVICE=<YOUR_SERVICE_NAME>
ENV DD_ENV=<YOUR_ENVIRONMENT>
# Use ddtrace-run to start your application
CMD ["ddtrace-run", "python", "app.py"]
3. アプリケーションを実行する
イメージをビルドしてから、コンテナを実行します。
コンテナを実行する際は、必ず次の操作を行ってください。
- コンテナを Datadog Agent と同じ Docker ネットワークに接続します。
- 必要な環境変数を設定します。
docker run -d \
--name your-python-app \
your-python-app-image
4. Verify setup
To verify that App and API Protection is working correctly:
- Send some traffic to your application
- Check the Application Signals Explorer in Datadog
- Look for security signals and vulnerabilities
トラブルシューティング
Python アプリケーションの App and API Protection のセットアップ中に問題が発生した場合は、「Python App and API Protection トラブルシューティングガイド」を参照してください。
参考資料