Kubernetes で AAP for Gateway API を有効にする
This product is not supported for your selected
Datadog site. (
).
App and API Protection は、Datadog Government サイト US1-FED でプレビュー版として提供されています。
AAP for Gateway API は試験機能です。試してみるには以下の手順に従ってください。
概要
Datadog AppSec Gateway API Request Mirror は、Kubernetes Gateway API の RequestMirror 機能を活用してトラフィックを Datadog App & API Protection エンドポイントに複製することで、アプリケーションセキュリティを強化します。これにより、プライマリリクエストフローに影響を与えることなく、アプリケーションレベルの潜在的な攻撃のリアルタイム検知と分析や、API エンドポイントの検出などが可能になります。
前提条件
脅威検知の有効化
インストール
Kubernetes インストールガイドに従って 1. Datadog Agent を Kubernetes クラスターにデプロイします。
APM をトランスポートとして使用して AppSec の受信ペイロードをサポートするように 2. Datadog Agent を構成します。
AppSec Gateway API Request Mirror を任意の名前空間 (例: datadog) にサービスとともにデプロイします。
kubectl apply -f https://raw.githubusercontent.com/DataDog/dd-trace-go/refs/heads/main/contrib/k8s.io/gateway-api/cmd/request-mirror/deployment.yml
デプロイメントを検証します。
kubectl get pods -l app=request-mirror
Gateway リソースにパッチを適用して、デプロイメントがある名前空間へのアクセスを許可します。
git clone https://github.com/DataDog/dd-trace-go.git
cd dd-trace-go
go run ./contrib/k8s.io/gateway-api/cmd/patch-gateways
パッチ適用動作をカスタマイズするためのオプションを確認するには -help フラグを使用します。
HTTPRoute リソースにパッチを適用して、トラフィックをサービスにリダイレクトします。
go run ./contrib/k8s.io/gateway-api/cmd/patch-httproutes
このコマンドは、すべての名前空間のすべての HTTPRoute リソースに RequestMirror フィルターを追加します。構成オプションを確認するには -help フラグを使用します。
注: このコマンドを定期的に実行することで、新しく作成された HTTPRoute リソースに RequestMirror フィルターが自動的に含まれるようになります。結果として得られるパッチを、HTTPRoute リソースが変更される CI/CD パイプラインに追加することを検討してください。
After this configuration is complete, the library collects security data from your application and sends it to the Agent. The Agent sends the data to Datadog, where out-of-the-box detection rules flag attacker techniques and potential misconfigurations so you can take steps to remediate.
To see App and API Protection 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 send known attack patterns to it, threat information appears in the Application Signals Explorer and vulnerability information appears in the Vulnerabilities explorer.
構成
環境変数
Gateway API Request Mirror のデプロイメントは、以下の環境変数を使用して構成できます。
| 環境変数 | デフォルト値 | 説明 |
|---|
DD_REQUEST_MIRROR_LISTEN_ADDR | :8080 | ミラーリングされたリクエストを受信するためにリクエストミラーサービスがリッスンするアドレスとポート |
DD_REQUEST_MIRROR_HEALTHCHECK_ADDR | :8081 | ヘルスチェックエンドポイントが提供されるアドレスとポート |
以下の環境変数を使用して、インテグレーションからトレースを受信するように Datadog Agent を構成します。
| 環境変数 | デフォルト値 | 説明 |
|---|
DD_AGENT_HOST | localhost | Datadog Agent が実行されているホスト名 |
DD_TRACE_AGENT_PORT | 8126 | トレース収集用の Datadog Agent のポート |
デプロイメントの例
デフォルトのデプロイメントによって作成されるサービスは、ミラーリングされたリクエストをポート 8080 でリッスンし、ポート 8081 でヘルスチェックエンドポイントを公開します。
apiVersion: apps/v1
kind: Deployment
metadata:
name: request-mirror
labels:
app.kubernetes.io/component: request-mirror
app.kubernetes.io/name: datadog
spec:
strategy:
type: RollingUpdate
selector:
matchLabels:
app: request-mirror
template:
metadata:
labels:
app: request-mirror
spec:
containers:
- name: request-mirror
image: ghcr.io/datadog/dd-trace-go/request-mirror:latest
ports:
- containerPort: 8080
name: http
livenessProbe:
httpGet:
path: /
port: 8081
readinessProbe:
httpGet:
path: /
port: 8081
env:
- name: DD_AGENT_HOST
value: "datadog-agent" # Adjust to your Agent service name
---
apiVersion: v1
kind: Service
metadata:
name: request-mirror
spec:
selector:
app: request-mirror
ports:
- name: http
port: 8080
targetPort: 8080
Datadog Go Tracer と Gateway API のインテグレーション
AAP Gateway API インテグレーションは、Datadog Go Tracer 上に構築されています。このトレーサーと同じリリースプロセスに従っており、対応するトレーサーのバージョンが Docker イメージにタグ付けされています。
Gateway API インテグレーションは Datadog Go Tracer を使用し、このトレーサーのすべての環境変数を継承します。詳細については、Go SDK の構成および AAP ライブラリの構成を参照してください。
APM トレーシングの有効化
デフォルトでは、リクエストミラーのトレースは Datadog の APM 製品を有効にしません。APM トレーシング機能を使用せずにApp and API Protection を使用する場合、これはデフォルトの動作です。
APM トレーシングを有効にするには、リクエストミラーのデプロイメントで環境変数 DD_APM_TRACING_ENABLED=true を設定してください。
App and API Protection の使用中に APM トレーシングを明示的に無効にするには、次の手順を実行します。
- デプロイメントの構成時に、
DD_APPSEC_ENABLED=true 環境変数に加えて DD_APM_TRACING_ENABLED=false 環境変数も使用します。 - この構成により、Datadog に送信される APM データの量が、App and API Protection 製品で必要とされる最小限の量に削減されます。
詳細については、スタンドアロンの App and API Protection を参照してください。
制限事項
Gateway API インテグレーションには、以下の制限があります。
- HTTP レスポンスにアクセスできません
- リクエストのブロックを適用できません
- HTTP リクエストボディの分析では JSON のみがサポートされています
より詳細な分析やその他の AAP 機能が必要な場合は、他の AAP インテグレーションを試してみることを検討してください。
参考資料