|
| 1 | +--- |
| 2 | +title: Enabling App and API Protection for Envoy Gateway |
| 3 | +code_lang: envoy-gateway |
| 4 | +code_lang_weight: 50 |
| 5 | +further_reading: |
| 6 | + - link: 'https://github.com/DataDog/dd-trace-go/tree/main/contrib/envoyproxy/go-control-plane/cmd/serviceextensions' |
| 7 | + tag: "Source Code" |
| 8 | + text: "Envoy integration source code" |
| 9 | + - link: "/security/default_rules/?category=cat-application-security" |
| 10 | + tag: "Documentation" |
| 11 | + text: "OOTB App and API Protection Rules" |
| 12 | + - link: "/security/application_security/troubleshooting" |
| 13 | + tag: "Documentation" |
| 14 | + text: "Troubleshooting App and API Protection" |
| 15 | +--- |
| 16 | + |
| 17 | +{{< callout url="#" btn_hidden="true" header="App and API Protection for Envoy Gateway is in Preview" >}} |
| 18 | +App and API Protection for Envoy Gateway is in Preview. Use the following instructions to try the preview. |
| 19 | +{{< /callout >}} |
| 20 | + |
| 21 | +You can enable Datadog App and API Protection for traffic managed by [Envoy Gateway][1]. The Datadog Envoy Gateway integration allows Datadog to inspect and protect your traffic for threat detection and blocking directly at the edge of your infrastructure. |
| 22 | + |
| 23 | +## Prerequisites |
| 24 | + |
| 25 | +1. A running Kubernetes cluster with [Envoy Gateway][1] installed. |
| 26 | +2. The [Datadog Agent is installed and configured][2] in your Kubernetes cluster. |
| 27 | + - Ensure [Remote Configuration][3] is enabled and configured to enable blocking attackers through the Datadog UI. |
| 28 | + - Ensure [APM is enabled][4] in the Agent to allow the external processor service to send its own traces to the Agent. |
| 29 | + - Optionally, enable the [Cluster Agent Admission Controller][5] to automatically inject the Datadog Agent host information to the App and API Protection External Processor service. |
| 30 | + |
| 31 | +## Enabling threat detection |
| 32 | + |
| 33 | +To enable App and API Protection with Envoy Gateway, do the following: |
| 34 | + |
| 35 | +1. Deploying the Datadog External Processor service in your cluster. |
| 36 | +2. Configure an `EnvoyExtensionPolicy` that points to the processor service. This will direct traffic from your Envoy Gateway to this service. |
| 37 | + |
| 38 | +### 1. Deploy the Datadog External Processor service |
| 39 | + |
| 40 | +This service is a gRPC server that Envoy communicates with to have requests and responses analyzed by App and API Protection. |
| 41 | + |
| 42 | +Create a Kubernetes Deployment and Service for the Datadog External Processor. It's recommended to deploy this service in a namespace accessible by your Envoy Gateway. |
| 43 | + |
| 44 | +The Datadog External Processor Docker image is available on the [Datadog Go tracer GitHub Registry][6]. |
| 45 | + |
| 46 | +Here is an example manifest (`datadog-aap-extproc-service.yaml`): |
| 47 | + |
| 48 | +```yaml |
| 49 | +apiVersion: apps/v1 |
| 50 | +kind: Deployment |
| 51 | +metadata: |
| 52 | + name: datadog-aap-extproc-deployment |
| 53 | + namespace: <your-preferred-namespace> # Change to your preferred namespace, ensure it's resolvable by the Envoy Gateway |
| 54 | + labels: |
| 55 | + app: datadog-aap-extproc |
| 56 | +spec: |
| 57 | + replicas: 1 # Adjust replica count based on your load |
| 58 | + selector: |
| 59 | + matchLabels: |
| 60 | + app: datadog-aap-extproc |
| 61 | + template: |
| 62 | + metadata: |
| 63 | + labels: |
| 64 | + app: datadog-aap-extproc |
| 65 | + spec: |
| 66 | + containers: |
| 67 | + - name: datadog-aap-extproc-container |
| 68 | + image: ghcr.io/datadog/dd-trace-go/service-extensions-callout:v2.4.0 # Replace with the latest released version |
| 69 | + ports: |
| 70 | + - name: grpc |
| 71 | + containerPort: 443 # Default gRPC port for the external processor |
| 72 | + - name: health |
| 73 | + containerPort: 80 # Default health check port |
| 74 | + env: |
| 75 | + # Optional: Agent Configuration |
| 76 | + # If you enabled the Cluster Agent Admission Controller, you can skip this section as the Agent host information is automatically injected. |
| 77 | + # Otherwise, configure the address of your Datadog Agent for the external 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 | + # Disable TLS for communication between Envoy Gateway and the external processor. Default is true. |
| 84 | + # By default, the external processor configuration used by Envoy Gateway is configured to not use TLS. |
| 85 | + # You can enable TLS and configure it with DD_SERVICE_EXTENSION_TLS_KEY_FILE and DD_SERVICE_EXTENSION_TLS_CERT_FILE |
| 86 | + # and apply a BackendTLSPolicy on the Datadog External Processor Service. |
| 87 | + - name: DD_SERVICE_EXTENSION_TLS |
| 88 | + value: "false" |
| 89 | + |
| 90 | + readinessProbe: |
| 91 | + httpGet: |
| 92 | + path: / |
| 93 | + port: health |
| 94 | + initialDelaySeconds: 5 |
| 95 | + periodSeconds: 10 |
| 96 | + livenessProbe: |
| 97 | + httpGet: |
| 98 | + path: / |
| 99 | + port: health |
| 100 | + initialDelaySeconds: 15 |
| 101 | + periodSeconds: 20 |
| 102 | +--- |
| 103 | +apiVersion: v1 |
| 104 | +kind: Service |
| 105 | +metadata: |
| 106 | + name: datadog-aap-extproc-service # This name will be used in the EnvoyExtensionPolicy configuration |
| 107 | + namespace: <your-preferred-namespace> # Change to your preferred namespace, ensure it's resolvable by the Envoy Gateway |
| 108 | + labels: |
| 109 | + app: datadog-aap-extproc |
| 110 | +spec: |
| 111 | + ports: |
| 112 | + - name: grpc |
| 113 | + port: 443 |
| 114 | + targetPort: grpc |
| 115 | + protocol: TCP |
| 116 | + selector: |
| 117 | + app: datadog-aap-extproc |
| 118 | + type: ClusterIP |
| 119 | +``` |
| 120 | +
|
| 121 | +#### Configuration options for the External Processor |
| 122 | +
|
| 123 | +The Datadog External Processor exposes some settings: |
| 124 | +
|
| 125 | +| Environment variable | Default value | Description | |
| 126 | +|-------------------------------------------|---------------------|------------------------------------------------------------------------------------------------------------------------------------------| |
| 127 | +| `DD_SERVICE_EXTENSION_HOST` | `0.0.0.0` | gRPC server listening address. | |
| 128 | +| `DD_SERVICE_EXTENSION_PORT` | `443` | gRPC server port. | |
| 129 | +| `DD_SERVICE_EXTENSION_HEALTHCHECK_PORT` | `80` | HTTP server port for health checks. | |
| 130 | +| `DD_SERVICE_EXTENSION_TLS` | `true` | Enable the gRPC TLS layer. | |
| 131 | +| `DD_SERVICE_EXTENSION_TLS_KEY_FILE` | `localhost.key` | Change the default gRPC TLS layer key. | |
| 132 | +| `DD_SERVICE_EXTENSION_TLS_CERT_FILE` | `localhost.crt` | Change the default gRPC TLS layer certificate. | |
| 133 | +| `DD_APPSEC_BODY_PARSING_SIZE_LIMIT` | `10485760` | Maximum size of the bodies to be processed in bytes. If set to `0`, the bodies are not processed. The recommended value is `10485760` (10MB). (To fully enable body processing, the `allowModeOverride` option should also be set in the External Processing filter configuration.) | |
| 134 | +| `DD_SERVICE` | `serviceextensions` | Service name shown in the Datadog UI. | |
| 135 | + |
| 136 | + |
| 137 | +Configure the connection from the external processor to the Datadog Agent using these environment variables: |
| 138 | + |
| 139 | +| Environment variable | Default value | Description | |
| 140 | +|----------------------------------------|---------------|----------------------------------------------------------------------------------| |
| 141 | +| `DD_AGENT_HOST` | `localhost` | Hostname or IP of your Datadog Agent. | |
| 142 | +| `DD_TRACE_AGENT_PORT` | `8126` | Port of the Datadog Agent for trace collection. | |
| 143 | + |
| 144 | +The External Processor is built on top of the [Datadog Go Tracer][7] and inherits all of its environment variables. See [Configuring the Go Tracing Library][8] and [App and API Protection Library Configuration][9]. |
| 145 | + |
| 146 | +<div class="alert alert-danger"> |
| 147 | + <strong>Note:</strong> As the Datadog External Processor is built on top of the Datadog Go Tracer, it generally follows the same release process as the tracer, and its Docker images are tagged with the corresponding tracer version (for example, <code>v2.2.2</code>). In some cases, early release versions might be published between official tracer releases, and these images are tagged with a suffix such as <code>-docker.1</code>. |
| 148 | +</div> |
| 149 | + |
| 150 | +### 2. Configure an EnvoyExtensionPolicy |
| 151 | + |
| 152 | +Use an `EnvoyExtensionPolicy` to instruct Envoy Gateway to call the Datadog external processor. You can attach the policy to a Gateway or to specific HTTPRoute/GRPCRoute resources. |
| 153 | + |
| 154 | +This sends all traffic on the selected Gateway to the external processor. Here is an example manifest (`datadog-aap-extproc-eep.yaml`): |
| 155 | + |
| 156 | +```yaml |
| 157 | +apiVersion: gateway.envoyproxy.io/v1alpha1 |
| 158 | +kind: EnvoyExtensionPolicy |
| 159 | +metadata: |
| 160 | + name: datadog-aap-extproc-eep |
| 161 | + namespace: <your-preferred-namespace> # same namespace as the Gateway |
| 162 | +spec: |
| 163 | + targetRefs: |
| 164 | + # Target the entire Gateway |
| 165 | + - group: gateway.networking.k8s.io |
| 166 | + kind: Gateway |
| 167 | + name: <your-gateway-name> # update to your specific gateway name |
| 168 | + # Target specific HTTPRoutes/GRPCRoutes |
| 169 | + #- group: gateway.networking.k8s.io |
| 170 | + # kind: HTTPRoute |
| 171 | + # name: <your-http-route-name> |
| 172 | + extProc: |
| 173 | + - backendRefs: |
| 174 | + - group: "" |
| 175 | + kind: Service |
| 176 | + name: datadog-aap-extproc-service |
| 177 | + namespace: <your-preferred-namespace> # namespace of the external processor Service |
| 178 | + port: 443 |
| 179 | +
|
| 180 | + # Optional: Enable fail open mode. Default is false. |
| 181 | + # Normally, if the external processor fails or times out, the filter fails and Envoy |
| 182 | + # returns a 5xx error to the downstream client. Setting this to true allows requests |
| 183 | + # to continue without error if a failure occurs. |
| 184 | + failOpen: true |
| 185 | +
|
| 186 | + # Optional: Set a timeout by processing message. Default is 200ms. |
| 187 | + # There is a maxium of 2 messages per requests with headers only and 4 messages maximum |
| 188 | + # with body processing enabled. |
| 189 | + # Note: This timeout also includes the data communication between Envoy and the external processor. |
| 190 | + # The timeout should be adjusted to accommodate the additional possible processing time. |
| 191 | + # Larger payloads will require a longer timeout. |
| 192 | + messageTimeout: 200ms |
| 193 | +
|
| 194 | + processingMode: |
| 195 | + # The external processor can dynamically override the processing mode as needed, instructing |
| 196 | + # Envoy to forward request and response bodies to the external processor. |
| 197 | + allowModeOverride: true |
| 198 | + # Only enable the request and response header modes by default. |
| 199 | + request: {} |
| 200 | + response: {} |
| 201 | +``` |
| 202 | + |
| 203 | +#### Cross‑namespace reference |
| 204 | + |
| 205 | +If your external processor `Service` is in a **different namespace** than the policy, add a [ReferenceGrant][10] in the processor’s namespace. For example, you can do this with a manifest such as `datadog-aap-eep-rg.yaml`. |
| 206 | + |
| 207 | +```yaml |
| 208 | +apiVersion: gateway.networking.k8s.io/v1beta1 |
| 209 | +kind: ReferenceGrant |
| 210 | +metadata: |
| 211 | + name: datadog-aap-eep-rg |
| 212 | + namespace: <your-extproc-namespace> # namespace of the external processor Service |
| 213 | +spec: |
| 214 | + from: |
| 215 | + - group: gateway.envoyproxy.io |
| 216 | + kind: EnvoyExtensionPolicy |
| 217 | + namespace: <your-policy-namespace> # namespace of the EnvoyExtensionPolicy (and the Gateway) |
| 218 | + to: |
| 219 | + - group: "" |
| 220 | + kind: Service |
| 221 | + name: datadog-aap-extproc-service |
| 222 | +``` |
| 223 | + |
| 224 | +### Validation |
| 225 | + |
| 226 | +After applying the policy, traffic through the targeted Gateway/Routes is inspected by App and API Protection. |
| 227 | + |
| 228 | +{{% appsec-getstarted-2-plusrisk %}} |
| 229 | + |
| 230 | +{{< 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" >}} |
| 231 | + |
| 232 | +## Limitations |
| 233 | + |
| 234 | +The Envoy Gateway integration has the following limitations: |
| 235 | + |
| 236 | +* Observability mode (asynchronous analysis) is not available for Envoy Gateway. |
| 237 | + |
| 238 | +For additional details on the Envoy Gateway integration compatibilities, refer to the [Envoy Gateway integration compatibility page][11]. |
| 239 | + |
| 240 | +## Further Reading |
| 241 | + |
| 242 | +{{< partial name="whats-next/whats-next.html" >}} |
| 243 | + |
| 244 | +[1]: https://gateway.envoyproxy.io/docs/ |
| 245 | +[2]: /containers/kubernetes/installation/?tab=datadogoperator |
| 246 | +[3]: /agent/remote_config/?tab=helm#enabling-remote-configuration |
| 247 | +[4]: /tracing/guide/setting_up_apm_with_kubernetes_service/?tab=datadogoperator |
| 248 | +[5]: /tracing/guide/setting_up_apm_with_kubernetes_service/?tab=datadogoperator#cluster-agent-admission-controller |
| 249 | +[6]: https://github.com/DataDog/dd-trace-go/pkgs/container/dd-trace-go%2Fservice-extensions-callout |
| 250 | +[7]: https://github.com/DataDog/dd-trace-go |
| 251 | +[8]: /tracing/trace_collection/library_config/go/ |
| 252 | +[9]: /security/application_security/policies/library_configuration/ |
| 253 | +[10]: https://gateway-api.sigs.k8s.io/api-types/referencegrant/ |
| 254 | +[11]: /security/application_security/setup/compatibility/envoy-gateway |
0 commit comments