|
| 1 | +--- |
| 2 | +title: Enabling App and API Protection for Istio |
| 3 | +code_lang: istio |
| 4 | +type: multi-code-lang |
| 5 | +code_lang_weight: 50 |
| 6 | +further_reading: |
| 7 | + - link: 'https://github.com/DataDog/dd-trace-go/tree/main/contrib/envoyproxy/go-control-plane/cmd/serviceextensions' |
| 8 | + tag: "Source Code" |
| 9 | + text: "Envoy integration's source code" |
| 10 | + - link: "/security/default_rules/?category=cat-application-security" |
| 11 | + tag: "Documentation" |
| 12 | + text: "OOTB App and API Protection Rules" |
| 13 | + - link: "/security/application_security/troubleshooting" |
| 14 | + tag: "Documentation" |
| 15 | + text: "Troubleshooting App and API Protection" |
| 16 | +--- |
| 17 | + |
| 18 | +{{< callout url="#" btn_hidden="true" header="App and API Protection for Istio is in Preview" >}} |
| 19 | +To try the preview of App and API Protection for Istio, follow the setup instructions below. |
| 20 | +{{< /callout >}} |
| 21 | + |
| 22 | +You can enable App and API Protection for your services within an Istio service mesh. The Datadog Istio integration allows Datadog to inspect and protect your traffic for threat detection and blocking directly at the edge of your infrastructure. This can be applied at the Istio Ingress Gateway or at the sidecar level. |
| 23 | + |
| 24 | +## Prerequisites |
| 25 | + |
| 26 | +Before you begin, ensure you have the following: |
| 27 | + |
| 28 | +1. A running Kubernetes cluster with [Istio][1] installed. |
| 29 | +2. The [Datadog Agent is installed and configured][2] in your Kubernetes cluster. |
| 30 | + - Ensure [Remote Configuration][3] is enabled and configured to enable blocking attackers through the Datadog UI. |
| 31 | + - Ensure [APM is enabled][4] in the Agent. *This allows the external processor service to send its own traces to the Agent.* |
| 32 | + |
| 33 | +## Enabling threat detection |
| 34 | + |
| 35 | +Enabling the threat detection for Istio involves two main steps: |
| 36 | +1. Deploying the Datadog External Processor service. |
| 37 | +2. Configuring an `EnvoyFilter` to direct traffic from your Istio Ingress Gateway (or sidecars) to this service. |
| 38 | + |
| 39 | +### 1. Deploy the Datadog External Processor Service |
| 40 | + |
| 41 | +This service is a gRPC server that Envoy communicates with to have requests and responses analysed by App and API Protection. |
| 42 | + |
| 43 | +Create a Kubernetes Deployment and Service for the Datadog External Processor. It's recommended to deploy this service in a namespace accessible by your Istio Ingress Gateway, such as `istio-system` or a dedicated namespace. |
| 44 | + |
| 45 | +The Datadog External Processor Docker image is available on the [Datadog Go tracer GitHub Registry][5]. |
| 46 | + |
| 47 | +Here is an example manifest (`datadog-aap-extproc-service.yaml`): |
| 48 | + |
| 49 | +```yaml |
| 50 | +apiVersion: apps/v1 |
| 51 | +kind: Deployment |
| 52 | +metadata: |
| 53 | + name: datadog-aap-extproc-deployment |
| 54 | + namespace: istio-system # Or your preferred namespace, ensure it's resolvable by the Envoy proxy |
| 55 | + labels: |
| 56 | + app: datadog-aap-extproc |
| 57 | +spec: |
| 58 | + replicas: 1 # Adjust replica count based on your load |
| 59 | + selector: |
| 60 | + matchLabels: |
| 61 | + app: datadog-aap-extproc |
| 62 | + template: |
| 63 | + metadata: |
| 64 | + labels: |
| 65 | + app: datadog-aap-extproc |
| 66 | + spec: |
| 67 | + containers: |
| 68 | + - name: datadog-aap-extproc-container |
| 69 | + image: ghcr.io/datadog/dd-trace-go/service-extensions-callout:v1.73.1 # Replace with the latest version version |
| 70 | + ports: |
| 71 | + - name: grpc |
| 72 | + containerPort: 443 # Default gRPC port for the external processor |
| 73 | + - name: health |
| 74 | + containerPort: 80 # Default health check port |
| 75 | + env: |
| 76 | + # ---- Required Agent Configuration ---- |
| 77 | + # Configure the address of your Datadog Agent for the processor |
| 78 | + - name: DD_AGENT_HOST |
| 79 | + value: "<your-datadog-agent-service>.<your-datadog-agent-namespace>.svc.cluster.local" |
| 80 | + - name: DD_TRACE_AGENT_PORT # Optional if your Agent's trace port is the default 8126 |
| 81 | + value: "8126" |
| 82 | + |
| 83 | + readinessProbe: |
| 84 | + httpGet: |
| 85 | + path: / |
| 86 | + port: health |
| 87 | + initialDelaySeconds: 5 |
| 88 | + periodSeconds: 10 |
| 89 | + livenessProbe: |
| 90 | + httpGet: |
| 91 | + path: / |
| 92 | + port: health |
| 93 | + initialDelaySeconds: 15 |
| 94 | + periodSeconds: 20 |
| 95 | +--- |
| 96 | +apiVersion: v1 |
| 97 | +kind: Service |
| 98 | +metadata: |
| 99 | + name: datadog-aap-extproc-service # This name will be used in the EnvoyFilter configuration |
| 100 | + namespace: istio-system # Must be the same namespace as the Deployment |
| 101 | + labels: |
| 102 | + app: datadog-aap-extproc |
| 103 | +spec: |
| 104 | + ports: |
| 105 | + - name: grpc |
| 106 | + port: 443 |
| 107 | + targetPort: grpc |
| 108 | + protocol: TCP |
| 109 | + selector: |
| 110 | + app: datadog-aap-extproc |
| 111 | + type: ClusterIP |
| 112 | +``` |
| 113 | +
|
| 114 | +#### Environment Variables for the External Processor |
| 115 | +
|
| 116 | +The Datadog App and API Protection External Processor supports the following environment variables to be configured: |
| 117 | +
|
| 118 | +| Environment variable | Default value | Description | |
| 119 | +|----------------------------------------|-----------------|------------------------------------------------------------------------------| |
| 120 | +| `DD_SERVICE_EXTENSION_HOST` | `0.0.0.0` | gRPC server listening address. | |
| 121 | +| `DD_SERVICE_EXTENSION_PORT` | `443` | gRPC server port. | |
| 122 | +| `DD_SERVICE_EXTENSION_HEALTHCHECK_PORT`| `80` | HTTP server port for health checks. | |
| 123 | + |
| 124 | +Configure the connection from the external processor to the Datadog Agent using these environment variables: |
| 125 | + |
| 126 | +| Environment variable | Default value | Description | |
| 127 | +|----------------------------------------|---------------|----------------------------------------------------------------------------------| |
| 128 | +| `DD_AGENT_HOST` | `localhost` | Hostname or IP of your Datadog Agent. | |
| 129 | +| `DD_TRACE_AGENT_PORT` | `8126` | Port of the Datadog Agent for trace collection. | |
| 130 | + |
| 131 | +<div class="alert alert-warning"> |
| 132 | + <strong>Note:</strong> The External Processor is built on top of the Datadog Go Tracer. It follows the same release process as the tracer, and its Docker images are tagged with the corresponding tracer version. |
| 133 | +</div> |
| 134 | + |
| 135 | +You can find more configuration options in [Configuring the Go Tracing Library][6] and [App and API Protection Library Configuration][7]. |
| 136 | + |
| 137 | +### 2. Configure an EnvoyFilter |
| 138 | + |
| 139 | +Next, create an `EnvoyFilter` resource to instruct your Istio Ingress Gateway or specific sidecar proxies to send traffic to the `datadog-aap-extproc-service` you deployed. This filter tells Envoy how to connect to the external processor and which traffic to send. |
| 140 | + |
| 141 | +Choose the appropriate configuration based on whether you want to apply App and API Protection at the Ingress Gateway or directly on your application's sidecar proxies. |
| 142 | + |
| 143 | +{{< tabs >}} |
| 144 | +{{% tab "Istio Ingress Gateway" %}} |
| 145 | + |
| 146 | +This configuration applies App and API Protection to all traffic passing through your Istio Ingress Gateway. This is a common approach to protect all north-south traffic entering your service mesh. |
| 147 | + |
| 148 | +Here is an example manifest (`datadog-aap-gateway-filter.yaml`) that targets the default Istio Ingress Gateway, which typically runs in the `istio-system` namespace with the label `istio: ingressgateway`. You must update these to match your specific application. |
| 149 | + |
| 150 | +```yaml |
| 151 | +apiVersion: networking.istio.io/v1alpha3 |
| 152 | +kind: EnvoyFilter |
| 153 | +metadata: |
| 154 | + name: datadog-aap-gateway-filter |
| 155 | + namespace: istio-system # Namespace of your Istio Ingress Gateway |
| 156 | +spec: |
| 157 | + workloadSelector: |
| 158 | + labels: |
| 159 | + istio: ingressgateway # Standard label for Istio Ingress Gateway pods |
| 160 | + configPatches: |
| 161 | + # Patch 1: Add the Cluster definition for the Datadog External Processing service |
| 162 | + - applyTo: CLUSTER |
| 163 | + match: |
| 164 | + context: GATEWAY |
| 165 | + cluster: |
| 166 | + service: "*" |
| 167 | + patch: |
| 168 | + operation: ADD |
| 169 | + value: |
| 170 | + name: "datadog_aap_ext_proc_cluster" # A unique name for this cluster configuration |
| 171 | + type: STRICT_DNS |
| 172 | + connect_timeout: 0.2s |
| 173 | + lb_policy: ROUND_ROBIN |
| 174 | + http2_protocol_options: {} |
| 175 | + transport_socket: |
| 176 | + name: envoy.transport_sockets.tls |
| 177 | + typed_config: |
| 178 | + "@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext |
| 179 | + sni: "localhost" |
| 180 | + load_assignment: |
| 181 | + cluster_name: "datadog_aap_ext_proc_cluster" |
| 182 | + endpoints: |
| 183 | + - lb_endpoints: |
| 184 | + - endpoint: |
| 185 | + address: |
| 186 | + socket_address: |
| 187 | + # Address of the Datadog External Processor service |
| 188 | + address: "datadog-aap-extproc-service.istio-system.svc.cluster.local" # Adjust if your service name or namespace is different |
| 189 | + port_value: 443 |
| 190 | +
|
| 191 | + # Patch 2: Add the External Processing HTTP Filter to the Gateway's HTTP connection manager |
| 192 | + - applyTo: HTTP_FILTER |
| 193 | + match: |
| 194 | + context: GATEWAY |
| 195 | + listener: |
| 196 | + filterChain: |
| 197 | + filter: |
| 198 | + name: "envoy.filters.network.http_connection_manager" |
| 199 | + subFilter: |
| 200 | + name: "envoy.filters.http.router" |
| 201 | + patch: |
| 202 | + operation: INSERT_BEFORE |
| 203 | + value: |
| 204 | + name: envoy.filters.http.ext_proc |
| 205 | + typed_config: |
| 206 | + "@type": type.googleapis.com/envoy.extensions.filters.http.ext_proc.v3.ExternalProcessor |
| 207 | + grpc_service: |
| 208 | + envoy_grpc: |
| 209 | + cluster_name: "datadog_aap_ext_proc_cluster" |
| 210 | +``` |
| 211 | + |
| 212 | +{{% /tab %}} |
| 213 | +{{% tab "Sidecar" %}} |
| 214 | + |
| 215 | +This configuration applies App and API Protection to specific pods within your service mesh by targeting their Istio sidecar proxies. This allows for more granular control over which services are protected. |
| 216 | + |
| 217 | +Here is an example manifest (`datadog-aap-sidecar-filter.yaml`) that targets pods with the label `app: <your-app-label>` in the namespace `<your-application-namespace>`. You must update these to match your specific application. |
| 218 | + |
| 219 | +```yaml |
| 220 | +apiVersion: networking.istio.io/v1alpha3 |
| 221 | +kind: EnvoyFilter |
| 222 | +metadata: |
| 223 | + name: datadog-aap-sidecar-filter |
| 224 | + namespace: <your-application-namespace> # Namespace of your application |
| 225 | +spec: |
| 226 | + workloadSelector: |
| 227 | + labels: |
| 228 | + app: <your-app-label> # Label of your application pods |
| 229 | + configPatches: |
| 230 | + # Patch 1: Add the Cluster definition for the Datadog External Processing service |
| 231 | + - applyTo: CLUSTER |
| 232 | + match: |
| 233 | + context: SIDECAR_INBOUND |
| 234 | + cluster: |
| 235 | + service: "*" |
| 236 | + patch: |
| 237 | + operation: ADD |
| 238 | + value: |
| 239 | + name: "datadog_aap_ext_proc_cluster" # A unique name for this cluster configuration |
| 240 | + type: STRICT_DNS |
| 241 | + connect_timeout: 0.2s |
| 242 | + lb_policy: ROUND_ROBIN |
| 243 | + http2_protocol_options: {} |
| 244 | + transport_socket: |
| 245 | + name: envoy.transport_sockets.tls |
| 246 | + typed_config: |
| 247 | + "@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext |
| 248 | + sni: "localhost" |
| 249 | + load_assignment: |
| 250 | + cluster_name: "datadog_aap_ext_proc_cluster" |
| 251 | + endpoints: |
| 252 | + - lb_endpoints: |
| 253 | + - endpoint: |
| 254 | + address: |
| 255 | + socket_address: |
| 256 | + # Address of the Datadog External Processor service |
| 257 | + address: "datadog-aap-extproc-service.<extproc-service-namespace>.svc.cluster.local" # Adjust if your service name or namespace is different |
| 258 | + port_value: 443 |
| 259 | +
|
| 260 | + # Patch 2: Add the External Processing HTTP Filter to the Sidecar's connection manager |
| 261 | + - applyTo: HTTP_FILTER |
| 262 | + match: |
| 263 | + context: SIDECAR_INBOUND |
| 264 | + listener: |
| 265 | + filterChain: |
| 266 | + filter: |
| 267 | + name: "envoy.filters.network.http_connection_manager" |
| 268 | + subFilter: |
| 269 | + name: "envoy.filters.http.router" |
| 270 | + patch: |
| 271 | + operation: INSERT_BEFORE |
| 272 | + value: |
| 273 | + name: envoy.filters.http.ext_proc |
| 274 | + typed_config: |
| 275 | + "@type": type.googleapis.com/envoy.extensions.filters.http.ext_proc.v3.ExternalProcessor |
| 276 | + grpc_service: |
| 277 | + envoy_grpc: |
| 278 | + cluster_name: "datadog_aap_ext_proc_cluster" |
| 279 | + timeout: 0.2s |
| 280 | +``` |
| 281 | + |
| 282 | +{{% /tab %}} |
| 283 | +{{< /tabs >}} |
| 284 | + |
| 285 | +After applying the chosen `EnvoyFilter`, traffic passing through your Istio Ingress Gateway or selected sidecars will be processed by the Datadog External Processor service, enabling App and API Protection features. |
| 286 | + |
| 287 | +### Validation |
| 288 | + |
| 289 | +{{% appsec-getstarted-2-plusrisk %}} |
| 290 | + |
| 291 | +{{< img src="/security/application_security/appsec-getstarted-threat-and-vuln_2.mp4" alt="Video showing Signals explorer and details, and Vulnerabilities explorer and details." video="true" >}} |
| 292 | + |
| 293 | +## Limitations |
| 294 | + |
| 295 | +The Istio integration has the following limitations: |
| 296 | + |
| 297 | +* The request body is not inspected, regardless of its content type. |
| 298 | + |
| 299 | +## Further Reading |
| 300 | + |
| 301 | +{{< partial name="whats-next/whats-next.html" >}} |
| 302 | + |
| 303 | +[1]: https://istio.io/ |
| 304 | +[2]: https://docs.datadoghq.com/containers/kubernetes/installation/?tab=datadogoperator |
| 305 | +[3]: https://docs.datadoghq.com/agent/remote_config/?tab=helm#enabling-remote-configuration |
| 306 | +[4]: https://docs.datadoghq.com/error_tracking/guides/enable_apm/?tab=kubernetes |
| 307 | +[5]: https://github.com/DataDog/dd-trace-go/pkgs/container/dd-trace-go%2Fservice-extensions-callout |
| 308 | +[6]: https://docs.datadoghq.com/tracing/trace_collection/library_config/go/ |
| 309 | +[7]: https://docs.datadoghq.com/security/application_security/threats/library_configuration/ |
0 commit comments