Protect a CDN-fronted OSS bucket with WAF
If you use Alibaba Cloud CDN to accelerate content delivery from a private Object Storage Service (OSS) bucket, you can add Web Application Firewall (WAF) to protect your website from web-based attacks. This guide shows you how to deploy CDN, OSS, and WAF together to secure your private OSS bucket.
Prerequisites
You have added a domain name to CDN for content acceleration and set a private OSS bucket as the origin server. For more information, see Beginner's Guide.
At this point, the DNS record for the domain name points to the CDN CNAME address, and the origin server is the OSS domain name.
-
You have an active Pay-as-you-go WAF 3.0 service.
Architecture
Step 1: Bind the domain to the OSS bucket
Log on to the OSS console.
Click Buckets, and then click the target bucket.
In the navigation pane on the left, choose Bucket Settings > Domain Names.
On the Domain Management page, click Map Custom Domain Name.
In the Map Custom Domain Name panel, enter the Domain Name that you want to bind.
- Note
Wildcard domain names, such as
*.example.com, are not supported.If a domain conflict error appears, it means the domain is already bound to another bucket. You can either use a different domain name or verify your ownership of the domain to force the binding. Verifying ownership will unbind the domain from the other bucket.
After binding the domain, open a web browser and enter the domain name followed by the name of a file in your bucket (for example, <your-domain-name>/test.png, where test.png is an image file uploaded to the bucket). If the content loads correctly, the domain has been bound successfully.
To find your OSS domain name, click Domain Binding Configuration in the Actions column for your domain.
Step 2: Add the domain to WAF and set the origin to OSS
To protect your private OSS bucket, add your CDN-accelerated domain name to WAF and configure the origin server as your OSS domain name.
-
Log on to the Web Application Firewall 3.0 console. From the top menu bar, select the resource group and region (Chinese Mainland or Outside Chinese Mainland) for the WAF instance.
-
In the left navigation pane, click Onboarding.
On the CNAME Record tab, click Add.
On the Configure Listener page, configure the following parameters and click Next.
Parameter
Description
Domain Name
Enter the domain name you bound to your OSS bucket in Step 1.
Protocol Type
Select the protocol (HTTP or HTTPS) and specify the port for your website. For more information, see Add a domain name to WAF using the CNAME record mode.
Layer-7 Proxy in Front of WAF
Select Yes.
More Settings
Enable IPv6: Enable this option based on your needs.
Exclusive IP Address: You can keep the default setting.
Protection Resource: Select the protection resource type based on your needs.
Resource Group
If you need to manage cloud resources by department or project, select the appropriate resource group for this domain.
On the Configure Forwarding Rule page, configure the following parameters and click Submit.
Parameter
Description
Load Balancing Algorithm
If your origin server has multiple server addresses, you can choose a Load Balancing Algorithm to distribute requests. WAF supports IP Hash, Round-robin, and Least Time.
Server Address
Enter the public IP address or domain name of your origin server. WAF forwards legitimate requests to this address. For this setup, enter the OSS Domain Name. For information about how to obtain the OSS domain name, see Obtain the OSS domain name.
Advanced HTTPS Settings
Enable HTTP Back-to-Origin: Enable this to forward all requests to your origin server over port 80, regardless of the original request port (80 or 443).
Origin SNI: If your origin server hosts multiple domains and WAF forwards requests over HTTPS, enable this option. Specify the requested domain name in the SNI field so your origin server can return the correct SSL certificate.
Other Advanced Settings
Enable Traffic Tagging: Enable this to add custom headers to requests forwarded to your origin server. These headers contain information like the client IP address and port, which helps you identify requests that have passed through WAF.
Configure the timeout periods for connections between WAF and the origin server based on your needs, including Connection Timeout Period, Read Timeout, and Write Timeout.
Retry on 5XX Error: Enable as needed.
Origin Keep-alive: Enable as needed.
On the Add Completed page, copy the CNAME address provided by WAF.
Step 3: Point the CDN origin to WAF
-
Log on to the CDN console.
-
In the left-side navigation pane, click Domain Names.
Find your target domain name and click the domain name or click Manage in the Actions column.
On the Origin Configuration tab, enable Back-to-Source to Private Alibaba Cloud OSS Bucket.
On the Basic Settings tab, find the target origin server, click Edit in the Actions column, set Origin Information to Origin Domain Name, and paste the WAF CNAME address obtained in Step 2On the Add Completed page, copy the CNAME address provided by WAF..
After you complete the configuration, verify that you can still access your content. In a browser, enter the domain name followed by the name of a file in your bucket (for example, <your-domain-name>/test.png, where test.png is an image file in the bucket). If the file displays correctly, the setup is successful.
To test WAF's protection, try to access your domain with a sample web attack string. For example, enter <your-domain-name>/alert(xss) in your browser, where alert(xss) is a cross-site scripting (XSS) attack payload. If a 405 block page appears, it indicates that WAF blocked the request and is working correctly.
Next steps
After this setup, WAF automatically adds your accelerated domain as a protected object and enables core web protection rules by default. It inspects incoming requests, forwards legitimate traffic to your private OSS bucket, and blocks threats.
For more tailored protection, you can log on to the Web Application Firewall 3.0 Console and navigate to the page to configure specific protection rules for your domain. For more information, see Overview of protection configuration.