Updated on 2024-03-14 GMT+08:00

Step 1: Add a Domain Name to WAF (Cloud Mode)

This topic describes how to add a domain name to WAF in CNAME access mode so that the website traffic can pass through WAF. After you connect a website domain name to your WAF instance, WAF works as a reverse proxy between the client and the server. The real IP address of the server is hidden and only the IP address of WAF is visible to web visitors.

Prerequisites

You have applied for a cloud WAF instance.

Constraints

  • Domain names added by an IAM user can be viewed by the account that creates the IAM user, but domain names added by an account cannot be viewed by IAM users created under the account.
  • A protected domain name can only be added to WAF once in cloud mode.

    Each combination of a domain name and a non-standard port is counted towards the domain name quota of the WAF edition you are using. For example, www.example.com:8080 and www.example.com:8081 use two domain names of the quota. If you want to protect web services over multiple ports with the same domain name, add the domain name and each port to WAF.

  • You can enter a multi-level single domain name (for example, top-level domain name example.com and level-2 domain name www.example.com) or a wildcard domain name (*.example.com).
    • WAF does not support wildcard domain names containing underscores (_).
    • The following are the rules for adding wildcards to domain names:
      • If the server IP address of each subdomain name is the same, enter a wildcard domain name to be protected. For example, if the subdomain names a.example.com, b.example.com, and c.example.com have the same server IP address, you can add the wildcard domain name *.example.com to WAF to protect all three.
      • If the server IP addresses of subdomain names are different, add subdomain names as single domain names one by one.
  • WAF does not support user-defined HTTP headers for protected domain names.
  • A CNAME record is generated based on the domain name. For the same domain name, the CNAME records are the same.
  • Only .pem certificates can be used in WAF.
  • WAF supports the WebSocket protocol, which is enabled by default.
    • WebSocket request inspection is enabled by default if Client Protocol is set to HTTP.
    • WebSockets request inspection is enabled by default if Client Protocol is set to HTTPS.

Specification Limitations

After your website is connected to WAF, you can upload a file no larger than 10 GB each time.

Impact on the System

If a non-standard port is configured, the visitors need to add the non-standard port to the end of the website address when they access the website.

Procedure

  1. Log in to the management console.
  2. Click in the upper left corner of the management console and select a region or project.
  3. Click in the upper left corner and choose Security > Web Application Firewall to go to the Dashboard page.
  4. In the navigation pane, choose Website Settings.
  5. In the upper left corner of the website list, click Add Website.
  6. Select Cloud and click OK.
  7. Provide the domain name details.

    • Website Name: (Optional) You can customize the website name.
    • Domain Name: Enter the domain name you want WAF to protect. You can enter a top-level single domain name, like example.com, a second-level domain name, like www.example.com, or a wildcard domain name, like *.example.com.
    • Website Remarks: (Optional) You can provide remarks about your website if you want.

  8. Configure the origin server. Table 1 describes the parameters. Figure 1 shows an example.

    Figure 1 Origin Server Settings
    Table 1 Parameter description

    Parameter

    Description

    Example Value

    Protected Port

    Select the port type that you want WAF to protect from the drop-down list.

    To protect port 80 or 443, select Standard port from the drop-down list.

    81

    Server Configuration

    Configurations of your web server address. You need to configure the client protocol, server protocol, server address, and server port.

    • Client Protocol: protocol used by a client to access a server. The options are HTTP and HTTPS.
    • Server Protocol: protocol used by WAF to forward client requests. The options are HTTP and HTTPS.
      NOTE:
    • Server Address: public IP address (generally corresponding to the A record of the domain name configured on the DNS) or domain name (generally corresponding to the CNAME of the domain name configured on the DNS) of the web server that a client accesses.
    • Server Port: service port over which the WAF instance forwards client requests to the origin server.

    Client Protocol: HTTP

    Server Protocol: HTTP

    Server Address: XXX.XXX.1.1

    Server Port: 80

    Certificate Name

    If you set Client Protocol to HTTPS, an SSL certificate is required. You can select a created certificate or import a certificate. For details about how to import a certificate, see Importing a New Certificate.

    The imported certificates are listed on the Certificates page. For more details, see Uploading a Certificate.

    NOTICE:
    • Only .pem certificates can be used in WAF. If the certificate is not in .pem format, convert it into .pem by referring to Table 3 before uploading the certificate.
    • If your website certificate is about to expire, purchase a new certificate before the expiration date and update the certificate associated with the website in WAF.
    • Each domain name must have a certificate associated. A wildcard domain name can only use a wildcard domain certificate. If you only have single-domain certificates, add domain names one by one in WAF.

    --

  9. Complete advanced settings.

    • Proxy Configured: Select Yes if your website is using a web proxy, such as anti-DDoS, CDN, or cloud acceleration products.

      If your website uses a layer-4 web proxy, such as advanced Anti-DDoS, set Proxy Configured to Yes. To ensure that WAF protection policies works on real source IP addresses, after Step 4: Modify the DNS Records of the Domain Name is complete, change Proxy Configured to No on the Basic Information page of the domain name.

      Cut

      If a proxy is deployed before WAF on your website, the WAF working mode cannot be switched to Bypassed. For details about how to switch the working mode, see Switching WAF Working Mode.

    • Specify Policy. By default, system-generated policy is selected. You can select custom rules. For details, see Table 2.

      You can select a policy you configured. You can also customize rules after the domain name is connected to WAF.

      Table 2 System-generated policies

      Policy

      Description

      Basic web protection (Log only mode and common checks)

      The basic web protection defends against attacks such as SQL injections, XSS, remote overflow vulnerabilities, file inclusions, Bash vulnerabilities, remote command execution, directory traversal, sensitive file access, and command/code injections.

      Basic web protection (Log only mode and common checks)

      The basic web protection defends against attacks such as SQL injections, XSS, remote overflow vulnerabilities, file inclusions, Bash vulnerabilities, remote command execution, directory traversal, sensitive file access, and command/code injections.

      Anti-crawler (Log only mode and Scanner feature)

      WAF only logs web scanning tasks, such as vulnerability scanning and virus scanning, such as crawling behavior of OpenVAS and Nmap.

      Log only: WAF only logs detected attacks instead of blocking them.

  10. Click OK.

    To enable WAF protection, there are three more steps, whitelisting WAF IP addresses, testing WAF, and routing your website traffic to WAF. You can click Later in this step. Then, finish those steps by referring to Step 2: Whitelist WAF IP Addresses, Step 3: Test WAF, and Step 4: Modify the DNS Records of the Domain Name.

Verification

  • By default, WAF detects the Access Status of each protected domain name on an hourly basis.
  • Generally, if you have performed domain connection and Access Status is Accessible, the domain name is connected to WAF.

    If a domain name has been connected to WAF but Access Status is Inaccessible, click to refresh. If Access Status is still Inaccessible, connect the domain name to WAF again by referring to Step 4: Modify the DNS Records of the Domain Name.

Importing a New Certificate

If you set Client Protocol to HTTPS, an SSL certificate is required. You can perform the following steps to import a new certificate.

  1. Click Import New Certificate. In the displayed Import New Certificate dialog box, enter the certificate name and paste the certificate file and private key to the corresponding text boxes.

    WAF encrypts and saves the private key to keep it safe.

    Only .pem certificates can be used in WAF. If the certificate is not in .pem format, convert it into .pem locally by referring to Table 3 before uploading it.
    Table 3 Certificate conversion commands

    Format

    Conversion Method

    CER/CRT

    Rename the cert.crt certificate file to cert.pem.

    PFX

    • Obtain a private key. For example, run the following command to convert cert.pfx into key.pem:

      openssl pkcs12 -in cert.pfx -nocerts -out key.pem -nodes

    • Obtain a certificate. For example, run the following command to convert cert.pfx into cert.pem:

      openssl pkcs12 -in cert.pfx -nokeys -out cert.pem

    P7B

    1. Convert a certificate. For example, run the following command to convert cert.p7b into cert.cer:

      openssl pkcs7 -print_certs -in cert.p7b -out cert.cer

    2. Rename certificate file cert.cer to cert.pem.

    DER

    • Obtain a private key. For example, run the following command to convert privatekey.der into privatekey.pem:

      openssl rsa -inform DER -outform PEM -in privatekey.der -out privatekey.pem

    • Obtain a certificate. For example, run the following command to convert cert.cer into cert.pem:

      openssl x509 -inform der -in cert.cer -out cert.pem

    • Before running an OpenSSL command, ensure that the OpenSSL tool has been installed on the local host.
    • If your local PC runs a Windows operating system, go to the command line interface (CLI) and then run the certificate conversion command.
  2. Click Confirm.

Example Configuration

There are some configuration examples provided for your reference in Configuration Example: Adding a Domain Name to WAF.