|
| 1 | +# WAF |
| 2 | + |
| 3 | +In this example we deploy the NGINX Plus Ingress controller with [NGINX App Protect](https://www.nginx.com/products/nginx-app-protect/), a simple web application and then configure load balancing and WAF protection for that application using the VirtualServer resource. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +1. Follow the installation [instructions](../../docs/installation.md) to deploy the Ingress controller with NGINX App Protect. |
| 8 | +1. Save the public IP address of the Ingress controller into a shell variable: |
| 9 | + ``` |
| 10 | + $ IC_IP=XXX.YYY.ZZZ.III |
| 11 | + ``` |
| 12 | +1. Save the HTTPS port of the Ingress controller into a shell variable: |
| 13 | + ``` |
| 14 | + $ IC_HTTPS_PORT=<port number> |
| 15 | + ``` |
| 16 | +
|
| 17 | +## Step 1. Deploy a Web Application |
| 18 | +
|
| 19 | +Create the application deployment and service: |
| 20 | +``` |
| 21 | +$ kubectl apply -f webapp.yaml |
| 22 | +``` |
| 23 | +
|
| 24 | +## Step 2 - Deploy the AP Policy |
| 25 | +
|
| 26 | +1. Create the syslog service and pod for the App Protect security logs: |
| 27 | + ``` |
| 28 | + $ kubectl apply -f syslog.yaml |
| 29 | + ``` |
| 30 | +1. Create the App Protect policy, log configuration and user defined signature: |
| 31 | + ``` |
| 32 | + $ kubectl apply -f ap-dataguard-alarm-policy.yaml |
| 33 | + $ kubectl apply -f ap-logconf.yaml |
| 34 | + $ kubectl apply -f ap-apple-uds.yaml |
| 35 | + ``` |
| 36 | +
|
| 37 | +## Step 3 - Configure Load Balancing |
| 38 | +
|
| 39 | +Update the `logDest` field from `virtualserver.yaml` with the ClusterIP of the syslog service. For example, if the IP is `10.101.21.110`: |
| 40 | +```yaml |
| 41 | +waf: |
| 42 | + ... |
| 43 | + logDest: "syslog:server=10.101.21.110:514" |
| 44 | +``` |
| 45 | + |
| 46 | +Create the VirtualServer Resource: |
| 47 | +``` |
| 48 | +$ kubectl apply -f virtualserver.yaml |
| 49 | +``` |
| 50 | +Note the App Protect configuration settings in the Policy resource. They enable WAF protection by configuring App Protect with the policy and log configuration created in the previous step. |
| 51 | + |
| 52 | +## Step 4 - Test the Application |
| 53 | + |
| 54 | +1. To access the application, curl the coffee and the tea services. We'll use `curl`'s `--insecure` option to turn off certificate verification of our self-signed |
| 55 | +certificate and the --resolve option to set the Host header of a request with `webapp.example.com` |
| 56 | + |
| 57 | + Send a request to the application: |
| 58 | + ``` |
| 59 | + $ curl --resolve webapp.example.com:$IC_HTTPS_PORT:$IC_IP https://webapp.example.com:$IC_HTTPS_PORT/ --insecure |
| 60 | + Server address: 10.12.0.18:80 |
| 61 | + Server name: webapp-7586895968-r26zn |
| 62 | + ... |
| 63 | + ``` |
| 64 | + |
| 65 | + Now, let's try to send a request with a suspicious URL: |
| 66 | + ``` |
| 67 | + $ curl --resolve webapp.example.com:$IC_HTTPS_PORT:$IC_IP "https://webapp.example.com:$IC_HTTPS_PORT/<script>" --insecure |
| 68 | + <html><head><title>Request Rejected</title></head><body> |
| 69 | + ... |
| 70 | + ``` |
| 71 | + Lastly, let's try to send some suspicious data that matches the user defined signature. |
| 72 | + ``` |
| 73 | + $ curl --resolve webapp.example.com:$IC_HTTPS_PORT:$IC_IP -X POST -d "apple" "https://webapp.example.com:$IC_HTTPS_PORT/" --insecure |
| 74 | + <html><head><title>Request Rejected</title></head><body> |
| 75 | + ... |
| 76 | + ``` |
| 77 | + As you can see, the suspicious requests were blocked by App Protect |
| 78 | + |
| 79 | +1. To check the security logs in the syslog pod: |
| 80 | + ``` |
| 81 | + $ kubectl exec -it <SYSLOG_POD> -- cat /var/log/messages |
| 82 | + ``` |