|
| 1 | +# WAF |
| 2 | + |
| 3 | +In this example we deploy the NGINX Plus Ingress Controller with [NGINX App |
| 4 | +Protect WAF version 5](https://www.nginx.com/products/nginx-app-protect/), a simple web application and then configure load balancing |
| 5 | +and WAF protection for that application using the VirtualServer resource. |
| 6 | + |
| 7 | +Before applying a policy and security log configuration, a WAF v5 policy and logconf bundle must be created, then copied to a volume mounted to `/etc/app_protect/bundles`. |
| 8 | + |
| 9 | +## Prerequisites |
| 10 | + |
| 11 | +1. Follow the installation [instructions](https://docs.nginx.com/nginx-ingress-controller/installation) to deploy the |
| 12 | + Ingress Controller with NGINX App Protect version 5. |
| 13 | + |
| 14 | +1. Save the public IP address of the Ingress Controller into a shell variable: |
| 15 | + |
| 16 | + ```console |
| 17 | + IC_IP=XXX.YYY.ZZZ.III |
| 18 | + ``` |
| 19 | + |
| 20 | +1. Save the HTTP port of the Ingress Controller into a shell variable: |
| 21 | + |
| 22 | + ```console |
| 23 | + IC_HTTP_PORT=<port number> |
| 24 | + ``` |
| 25 | + |
| 26 | +## Step 1. Deploy a Web Application |
| 27 | + |
| 28 | +Create the application deployment and service:<
8000
/div> |
| 29 | + |
| 30 | +```console |
| 31 | +kubectl apply -f webapp.yaml |
| 32 | +``` |
| 33 | + |
| 34 | +## Step 2 - Create and Deploy the WAF Policy Bundle |
| 35 | + |
| 36 | +1. Create a WAF v5 policy bundle (`<your_policy_bundle.tgz>`) and copy the bundle to a volume mounted to `/etc/app_protect/bundles`. |
| 37 | + |
| 38 | +## Step 3 - Create and Deploy the WAF Policy |
| 39 | + |
| 40 | +1. Create the syslog service and pod for the App Protect security logs: |
| 41 | + |
| 42 | + ```console |
| 43 | + kubectl apply -f syslog.yaml |
| 44 | + ``` |
| 45 | + |
| 46 | +1. Create the WAF policy |
| 47 | + |
| 48 | + ```console |
| 49 | + kubectl apply -f waf.yaml |
| 50 | + ``` |
| 51 | + |
| 52 | +## Step 4 - Configure Load Balancing |
| 53 | + |
| 54 | +1. Create the VirtualServer Resource: |
| 55 | + |
| 56 | + ```console |
| 57 | + kubectl apply -f virtual-server.yaml |
| 58 | + ``` |
| 59 | + |
| 60 | +Note that the VirtualServer references the policy `waf-policy` created in Step 3. |
| 61 | + |
| 62 | +## Step 5 - Test the Application |
| 63 | + |
| 64 | +To access the application, curl the coffee and the tea services. We'll use the --resolve option to set the Host header |
| 65 | +of a request with `webapp.example.com` |
| 66 | + |
| 67 | +1. Send a request to the application: |
| 68 | + |
| 69 | + ```console |
| 70 | + curl --resolve webapp.example.com:$IC_HTTP_PORT:$IC_IP http://webapp.example.com:$IC_HTTP_PORT/ |
| 71 | + ``` |
| 72 | + |
| 73 | + ```text |
| 74 | + Server address: 10.12.0.18:80 |
| 75 | + Server name: webapp-7586895968-r26zn |
| 76 | + ... |
| 77 | + ``` |
| 78 | + |
| 79 | +1. Now, let's try to send a request with a suspicious URL: |
| 80 | + |
| 81 | + ```console |
| 82 | + curl --resolve webapp.example.com:$IC_HTTP_PORT:$IC_IP "http://webapp.example.com:$IC_HTTP_PORT/<script>" |
| 83 | + ``` |
| 84 | + |
| 85 | + ```text |
| 86 | + <html><head><title>Request Rejected</title></head><body> |
| 87 | + ... |
| 88 | + ``` |
| 89 | + |
| 90 | +1. To check the security logs in the syslog pod: |
| 91 | + |
| 92 | + Note that this step applies only if the `syslog.yaml` was created (Step 2). |
| 93 | + |
| 94 | + ```console |
| 95 | + kubectl exec -it <SYSLOG_POD> -- cat /var/log/messages |
| 96 | + ``` |
0 commit comments