Connecting a Website to WAF Using Dedicated Access
Application Scenarios
In this practice, we assume that you want to add domain name www.example.com to WAF using dedicated access. The configurations are as follows:
- Origin Server: A Huawei Cloud ECS with private IP address 192.168.1.100 and port 80 opened for web services.
- VPC: vpc-example (created)
- Protected Port: 80 (standard port)
- Client Protocol: HTTP
- Server Protocol: HTTP
Procedure
| Operation | Description |
|---|---|
| Buy a dedicated WAF instance in the target region and VPC. | |
| Create a dedicated load balancer and add a listener to it. | |
| Add a website to WAF and configure origin server information on the WAF console. | |
| Step 4: Add the Dedicated WAF Instance to the ELB Load Balancer | Add the dedicated WAF instance to the backend server group of the load balancer. |
| Unbind the EIP from the origin server and bind it to the load balancer of WAF. | |
| Step 6: Whitelist the Back-to-Origin IP Addresses of Your Dedicated WAF Instance | Allow the back-to-origin IP addresses of the dedicated WAF instance in the security group configured for the origin server. |
| Verify that the WAF forwarding and protection functions are normal. |
Procedure
You can take the steps below to connect your website to WAF.
Step 1: Buy a Dedicated WAF Instance
- Log in to the WAF console.
- In the upper right corner of the page, click Buy WAF and configure the following key parameters:
- Billing Mode: Select Pay-per-use.
- Region: Select the same region as the origin server ECS (for example, CN North-Beijing4).
- VPC: Select vpc-example.
- Edition: Select an edition based on your service QPS. For example, a WI-500 instance supports about 5,000 QPS for HTTP and 4,000 QPS for HTTPS.
- Click Buy Now and complete the payment.
HA suggestions: To prevent single points of failure (SPOFs), buy at least two dedicated WAF instances in the same VPC and use ELB to enable active-active services.
Step 2: Configure a Load Balancer
- Go to the load balancer list page.
- Click Buy Elastic Load Balancer and configure the following parameters:
- Type: Select Dedicated load balancer.
- Specification Type: Select Application (HTTP/HTTPS).
- VPC: Select vpc-example (same as that of the dedicated WAF instance).
- After the purchase is complete, click the target load balancer name to go to its details page.
- On the Listeners tab, click Add Listener and configure the following parameters:
- Frontend Protocol: Select HTTP.
- Frontend Port: Select 80.
- Load Balancing Algorithm: Select Weighted round robin.
- Sticky Session: Disable it. (Note that enabling sticky sessions may cause request errors when a fault occurs.)
- Health Check: Enable it.
Step 3. Add a Domain Name
- Log in to the WAF console.
- In the navigation pane on the left, choose Access Management.
- On the Access Management page, click the Dedicated tab and click Add Website.
If only one access mode is enabled, click Add Website.
- On the Add Website page, configure the following parameters:
- Protected Object: Enter www.example.com.
- Protected Port: Select Standard port (80).
- Client Protocol: Select HTTP.
If you select HTTPS for Client Protocol, you need to select or import an SSL certificate. Currently, only .pem certificates are supported.
- Server Protocol: Select HTTP.
- VPC: Select vpc-example.
- Server Address: Enter 192.168.1.100.
- Server Port: Enter 80.
- Weight: Enter 100.
- IP Tag: Select $remote_sockaddr. (Select this option if there is no other proxy in front of WAF.)
- Policy: Select System-generated policy. (By default, this policy enables basic web protection in log-only mode.)
- Click OK.
Step 4: Add the Dedicated WAF Instance to the ELB Load Balancer
- Log in to the WAF console.
- In the navigation pane on the left, choose .
- Locate the row containing the WAF instance. In the Operation column, choose More > Add to ELB.
- On the Add to ELB page, configure the following parameters:
- ELB (Load Balancer): Select the load balancer created in step 2.
- ELB Listener: Select the listener created in step 2.
- Backend Server Group: Use the default or custom one.
- Click Next. Set the service port to 80 (the same as the protected port) and the weight to 100.
- Click OK.
- Check the health check result to see whether it is Normal. If it is abnormal, rectify the fault by referring to Health Check Troubleshooting.
Step 5: Bind an EIP
- Go to the load balancer list page.
- Locate the load balancer (if any) configured for the origin server and unbind the EIP of the load balancer from it.
- In the row containing the load balancer configured for the origin server, choose More > Unbind IPv4 EIP in the Operation column.
- In the displayed dialog box, click Yes.
- Locate the load balancer configured for the dedicated WAF instance and bind the unbound EIP to it.
- In the row containing the load balancer configured for the dedicated WAF instance, choose More > Bind IPv4 EIP in the Operation column.
- In the displayed dialog box, select the EIP unbound and click OK.
Step 6: Whitelist the Back-to-Origin IP Addresses of Your Dedicated WAF Instance
- Log in to the WAF console.
- In the navigation pane on the left, choose .
- Click the IP address in the IP Address column of the target dedicated WAF instance and copy the subnet IP address, which is 192.168.2.10 in this example.
- Log in to the ECS console.
- Click the target ECS. On the details page, click the Security Groups tab and then click the name of the target security group to go to the security group configuration page.
- On the Inbound Rules tab, click Add Rule.
- Action: Select Allow.
- Protocol & Port: Select TCP (Custom) and leave the port empty or enter a port number ranging from 1 to 65535.
- Source: Enter 192.168.2.10, which is the subnet IP address of the dedicated WAF instance.
- Click OK.
Verification method: Run the telnet origin server IP address 80 command. If the port cannot be directly connected but the website is accessible, the security group rule is configured successfully.
Step 7: Verify Website Access
You can refer to the following procedure to check whether your website has been successfully connected to WAF.
Testing Your Dedicated WAF Instance
Create an ECS that is in the same VPC as the dedicated WAF instance and perform the following tests:
Forwarding test
curl -kv -H "Host: www.example.com" http://192.168.2.10
If the response code is 200, the request has been forwarded.
Attack blocking test
# Ensure that the basic web protection in block mode is enabled in the policy. curl -kv -H "Host: www.example.com" http://192.168.2.10 --data "id=1 and 1='1'"
If the response code is 418, the request has been blocked, indicating that the dedicated WAF works properly.
Testing Your Dedicated WAF Instance and Dedicated ELB Load Balancer
HTTP forwarding test
# Use the private IP address of the ELB load balancer for the test: curl -kv -H "Host: www.example.com" http://192.168.3.20 # Use the EIP (if any) of the ELB load balancer for the test: curl -kv -H "Host: www.example.com" http://100.10.x.x
HTTPS forwarding test (the external protocol is HTTPS):
curl -kv --resolve www.example.com:443:100.10.x.x https://www.example.com
Attack blocking test
curl -kv -H "Host: www.example.com" http://100.10.x.x --data "id=1 and 1='1'"
If the response code is 418, the request has been blocked, indicating that both your dedicated WAF instance and ELB load balancer work properly.
Verifying the Access Status
- On the WAF console, go to the Access Management page and check the access status of the domain name.
- If the access status is Inaccessible, access the protected website many times within one minute and click the refresh button.
- When WAF detects at least 50 requests to the protected website within the last day, the website is considered accessible.
Configuration Suggestions for Your Production Environment
- Access time: Change DNS resolution during off-peak hours to minimize the impact on your customers.
- Gray policy: Connect domain names for the non-production environment first. After the services have been running properly for a period, then connect the domain names to the production environment.
- Service checks: After the access is complete, check whether the proportion of status code 200 in the log fluctuates significantly, whether the QPS increases or decreases sharply, and whether the functions on the service side are normal.
- Origin server hardening: Configure an access control policy on your origin server to allow only WAF back-to-origin IP addresses to access the origin server on any ports. This prevents hackers from bypassing WAF to attack origin servers.
- HTTPS configuration: Deploy the SSL certificate on both the origin server and WAF. Upload the certificate to Cloud Certificate Manager (CCM), select HTTPS for the client protocol in WAF, configure PCI DSS/3DS compliance checks and TLS, and enable certificate expiration alarm notifications.
- Rule optimization: Observe services for a period of time (log only mode) before enabling a rule to ensure that no normal requests are blocked mistakenly.
- Monitoring and alarms: Enable alarm notifications and configure alarm rules. Observe the numbers of requests, 5XX status codes, basic web protection events, and CC protection events for the protected domain name.
- Backup policy: Save the current DNS, certificate, and back-to-origin configurations for quick rollback in case of a fault.
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot