You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/application-gateway/for-containers/how-to-waf-gateway-api.md
+75-69Lines changed: 75 additions & 69 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
-
title: Web Application Firewall on Application Gateway for Containers - Gateway API
3
-
description: This document provides an example scenario for testing the Web Application Firewall (WAF) on Application Gateway for Containers.
2
+
title: Azure Web Application Firewall on Application Gateway for Containers - Gateway API
3
+
description: This article provides an example scenario for testing Azure Web Application Firewall on Application Gateway for Containers.
4
4
services: application-gateway
5
5
author: jackstromberg
6
6
ms.service: azure-appgw-for-containers
@@ -9,42 +9,46 @@ ms.date: 7/21/2025
9
9
ms.author: jstrom
10
10
---
11
11
12
-
# Web Application Firewall on Application Gateway for Containers with Gateway API
12
+
# Azure Web Application Firewall on Application Gateway for Containers with the Gateway API
13
13
14
-
This document helps set up an example application that uses the following resources from Gateway API. Steps are provided to:
14
+
This article helps you set up an example application that uses resources from the Gateway API. The article provides steps to:
15
15
16
-
- Create a [Gateway](https://gateway-api.sigs.k8s.io/concepts/api-overview/#gateway) resource with one HTTPS listener.
17
-
- Create an [HTTPRoute](https://gateway-api.sigs.k8s.io/api-types/httproute) that references a backend service.
18
-
- Create a `WebApplicationFirewallPolicy` resource that references an HTTPRoute.
16
+
- Create a [`Gateway`](https://gateway-api.sigs.k8s.io/concepts/api-overview/#gateway) resource with one HTTPS listener.
17
+
- Create an [`HTTPRoute`](https://gateway-api.sigs.k8s.io/api-types/httproute)resource that references a back-end service.
18
+
- Create a `WebApplicationFirewallPolicy` resource that references an `HTTPRoute` resource.
19
19
20
20
## Background
21
21
22
-
Application Gateway for Containers leverages web application firewall to block a malicious request from being proxied to the backend target. See the following example scenario:
22
+
Application Gateway for Containers uses Azure Web Application Firewall to block a malicious request from being proxied to the back-end target. The following diagram shows an example scenario.
23
23
24
-

24
+

25
25
26
26
## Prerequisites
27
27
28
-
1. If following the BYO deployment strategy, ensure you have set up your Application Gateway for Containers resources and [ALB Controller](quickstart-deploy-application-gateway-for-containers-alb-controller.md)
29
-
2. If following the ALB managed deployment strategy, ensure you have provisioned your [ALB Controller](quickstart-deploy-application-gateway-for-containers-alb-controller.md) and provisioned the Application Gateway for Containers resources via the [ApplicationLoadBalancer custom resource](quickstart-create-application-gateway-for-containers-managed-by-alb-controller.md).
30
-
3. Deploy sample HTTP application
31
-
Apply the following deployment.yaml file on your cluster to create a sample web application to demonstrate the header rewrite.
28
+
- If you're following the bring-your-own (BYO) deployment strategy, ensure that you set up your Application Gateway for Containers resources and [ALB Controller](quickstart-deploy-application-gateway-for-containers-alb-controller.md).
- If you're following the Application Load Balancer (ALB) managed deployment strategy, ensure that you:
31
+
32
+
- Provisioned your [ALB Controller](quickstart-deploy-application-gateway-for-containers-alb-controller.md).
33
+
- Provisioned the Application Gateway for Containers resources via the [`ApplicationLoadBalancer` custom resource](quickstart-create-application-gateway-for-containers-managed-by-alb-controller.md).
34
+
35
+
- Apply the following `deployment.yaml` file on your cluster to create a sample web application that demonstrates the header rewrite:
RESOURCE_GROUP='<resource group name of the Application Gateway For Containers resource>'
79
-
RESOURCE_NAME='alb-test'
80
-
81
-
RESOURCE_ID=$(az network alb show --resource-group $RESOURCE_GROUP --name $RESOURCE_NAME --query id -o tsv)
82
-
FRONTEND_NAME='frontend'
83
-
```
81
+
```bash
82
+
RESOURCE_GROUP='<resource group name of the Application Gateway For Containers resource>'
83
+
RESOURCE_NAME='alb-test'
84
+
85
+
RESOURCE_ID=$(az network alb show --resource-group $RESOURCE_GROUP --name $RESOURCE_NAME --query id -o tsv)
86
+
FRONTEND_NAME='frontend'
87
+
```
84
88
85
-
2. Create a Gateway
89
+
2. Create a `Gateway` resource:
86
90
87
-
```bash
88
-
kubectl apply -f - <<EOF
89
-
apiVersion: gateway.networking.k8s.io/v1
90
-
kind: Gateway
91
-
metadata:
92
-
name: gateway-01
93
-
namespace: test-infra
94
-
annotations:
95
-
alb.networking.azure.io/alb-id: $RESOURCE_ID
96
-
spec:
97
-
gatewayClassName: azure-alb-external
98
-
listeners:
99
-
- name: http-listener
100
-
port: 80
101
-
protocol: HTTP
102
-
allowedRoutes:
103
-
namespaces:
104
-
from: Same
105
-
addresses:
106
-
- type: alb.networking.azure.io/alb-frontend
107
-
value: $FRONTEND_NAME
108
-
EOF
109
-
```
91
+
```bash
92
+
kubectl apply -f - <<EOF
93
+
apiVersion: gateway.networking.k8s.io/v1
94
+
kind: Gateway
95
+
metadata:
96
+
name: gateway-01
97
+
namespace: test-infra
98
+
annotations:
99
+
alb.networking.azure.io/alb-id: $RESOURCE_ID
100
+
spec:
101
+
gatewayClassName: azure-alb-external
102
+
listeners:
103
+
- name: http-listener
104
+
port: 80
105
+
protocol: HTTP
106
+
allowedRoutes:
107
+
namespaces:
108
+
from: Same
109
+
addresses:
110
+
- type: alb.networking.azure.io/alb-frontend
111
+
value: $FRONTEND_NAME
112
+
EOF
113
+
```
110
114
111
115
---
112
116
113
-
Once the gateway resource is created, ensure the status is valid, the listener is _Programmed_, and an address is assigned to the gateway.
117
+
After you create the `Gateway` resource, ensure that the status is valid, the listener has a status of `Programmed`, and an address is assigned to it:
114
118
115
119
```bash
116
120
kubectl get gateway gateway-01 -n test-infra -o yaml
117
121
```
118
122
119
-
Example output of successful gateway creation.
123
+
Here's example output for successful creation of a `Gateway` resource:
120
124
121
125
```yaml
122
126
status:
@@ -163,7 +167,7 @@ status:
163
167
kind: HTTPRoute
164
168
```
165
169
166
-
Once the gateway is created, create an HTTPRoutethat listens for hostname contoso.com.
170
+
Create an `HTTPRoute` resource that listens for the host name `contoso.com`:
167
171
168
172
```bash
169
173
kubectl apply -f - <<EOF
@@ -185,13 +189,13 @@ spec:
185
189
EOF
186
190
```
187
191
188
-
Once the HTTPRoute resource is created, ensure the route is _Accepted_ and the Application Gateway for Containers resource is _Programmed_.
192
+
After you create the `HTTPRoute` resource, ensure that the status of the route is `Accepted` and the status of the Application Gateway for Containers resource is `Programmed`:
189
193
190
194
```bash
191
195
kubectl get httproute header-rewrite-route -n test-infra -o yaml
192
196
```
193
197
194
-
Verify the status of the Application Gateway for Containers resource has been successfully updated.
198
+
Verify that the status of the Application Gateway for Containers resource was successfully updated:
195
199
196
200
```yaml
197
201
status:
@@ -225,7 +229,7 @@ status:
225
229
226
230
### Configure WebApplicationFirewallPolicy
227
231
228
-
Application Gateway for Containers uses a custom resource called `WebApplicationFirewallPolicy` to define WAF protection. In this example, WAF will protect a specific HTTPRoute.
232
+
Application Gateway for Containers uses a custom resource called `WebApplicationFirewallPolicy` to define Azure Web Application Firewall protection. In this example, Azure Web Application Firewall helps protect a specific `HTTPRoute` resource:
229
233
230
234
```bash
231
235
kubectl apply -f - <<EOF
@@ -240,12 +244,13 @@ spec:
240
244
kind: HTTPRoute
241
245
name: contoso-waf-route
242
246
namespace: test-infra
243
-
#sectionNames: ["listenerA"] # defined if targeting a specific listener on a gateway resource or path
247
+
#sectionNames: ["listenerA"] # defined if you're targeting a specific listener on a gateway resource or path
Now we're ready to send some traffic to our sample application, via the FQDN assigned to the frontend. Use the following command to get the FQDN:
274
+
Now you're ready to send some traffic to the sample application, via the fully qualified domain name (FQDN) assigned to the frontend resource. Use the following command to get the FQDN:
269
275
270
276
```bash
271
277
fqdn=$(kubectl get gateway gateway-01 -n test-infra -o jsonpath='{.status.addresses[0].value}')
272
278
```
273
279
274
-
If you specify the server name indicator using the curl command, `contoso.com` for the frontend FQDN, the output should return a response from the backend-v1 service.
280
+
If you specify the server name indicator by using the `curl` command, with `contoso.com` for the frontend resource's FQDN, the output should return a response from the `backend-v1` service:
Congratulations, you have installed ALB Controller, deployed a backend application and used Web Application Firewall functionality to block a malicious request.
333
+
Congratulations! You installed an ALB Controller, deployed a back-end application, and used Azure Web Application Firewall functionality to block a malicious request.
0 commit comments