Configure whitelists for a cluster

Updated at:

IP whitelists control which IP addresses or security groups can access a PolarDB for MySQL cluster. After you create a cluster, you must add the IP addresses of your on-premises environment or ECS instances to the whitelist of the cluster before you can access the cluster.

Precautions

  • PolarDB does not support automatically obtaining the private IP addresses of ECS instances in VPCs. You must manually enter the private IP address of the ECS instance that needs to access the PolarDB for MySQL cluster in the whitelist.

  • You can configure both IP whitelists and security groups. The ECS instances in the IP whitelist and the ECS instances in the security group can both access the PolarDB for MySQL cluster.

  • ali_dms_group (IP whitelist for DMS), hdm_security_ips (IP whitelist for DAS), dtspolardb (IP whitelist for DTS) are automatically generated when you use the related services. Do not modify or delete these groups to avoid affecting the use of the related services.

    Important

    Do not add your business IP addresses to these groups. Otherwise, your business IP addresses may be overwritten when the related services are updated, affecting normal business operations.

    Whitelists

  • You can create up to 50 IP whitelist groups, and all IP whitelist groups support a cumulative total of 1,000 IP addresses or CIDR blocks.

Scenarios

IP whitelists control which IP addresses or security groups can access a PolarDB for MySQL cluster. Configuring IP whitelists provides a high level of access security for your PolarDB for MySQL cluster. We recommend that you maintain whitelists on a regular basis. The following are common scenarios where you need to configure IP whitelists:

  • If your ECS instance needs to access a PolarDB for MySQL cluster, you can view the IP address of the ECS instance on the Instance Details page and add it to the IP whitelist.

    Note
    • If your ECS instance and the PolarDB for MySQL cluster are in the same VPC, you can enter the private IP address of the ECS instance or the CIDR block of the VPC.

    • If your ECS instance and the PolarDB for MySQL cluster are not in the same VPC, you can enter the public IP address of the ECS instance or add the security group to which the ECS instance belongs. You can also migrate the ECS instance to the VPC where the PolarDB for MySQL cluster resides, and then enter the private IP address of the ECS instance or the CIDR block of the VPC.

  • If your on-premises servers, computers, or other cloud servers need to access a PolarDB cluster, add their public IP addresses to the IP whitelist.

Configure IP whitelists

  1. Log in to the PolarDB console,In the navigation pane on the left, click Clusters. Select the Region where the cluster is deployed, and then click the cluster ID to go to the cluster details page。

  2. In the left-side navigation pane, choose Settings and Management > Cluster Whitelists.

  3. On the Cluster Whitelists page, you can Add IP Whitelist or Modify an existing whitelist group.

    • Add an IP whitelist group:

      Click Add IP Whitelist. In the Add IP Whitelist dialog box, enter the group name and the IP addresses that are allowed to access the cluster.

    • Configure an IP whitelist group:

      Click Modify to the right of the target IP whitelist group name. In the Modify Whitelist dialog box, enter the IP addresses that are allowed to access the cluster.

    Note
    • The name of the IP whitelist group must meet the following requirements:

      • It can contain lowercase letters, digits, and underscores (_).

      • It must start with a letter and end with a letter or digit.

      • It must be 2 to 120 characters in length.

    • For IP addresses in the whitelist:

      • You can enter an IP address (such as 192.168.0.1) or a CIDR block (such as 192.168.0.0/24).

      • When pods in a Kubernetes cluster (such as ACK) access the cluster, the pod IP addresses change when containers are recreated. Configure the CIDR block to which the pod IP addresses belong instead of a single pod IP address. For example, if the pod IP addresses are in the 172.19.34.x range, configure 172.19.34.0/24. If you are not sure about the CIDR block, you can configure 172.19.0.0/16. You can also associate a security group. The ECS instances in the security group are automatically added to the whitelist.

      • Separate multiple IP addresses with commas (,), for example, 192.168.0.1,192.168.0.0/24.

      • 127.0.0.1 indicates that no IP address is allowed to access the cluster.

      • 0.0.0.0/0 indicates that any IP address is allowed to access the database cluster. This setting significantly reduces the security of the database. Do not use this setting unless necessary.

    • Each cluster includes a default IP whitelist group named default that contains the IP address 127.0.0.1, which means no IP address can access the cluster.

FAQ

An ECS instance cannot connect to a PolarDB cluster

Troubleshoot as follows:

  1. Check whether the PolarDB cluster is in the running state.

  2. Verify that the database endpoint, port, account, and password are correct. Obtain the database endpoint and port.

  3. Test network connectivity from the ECS instance using ping <database endpoint> or telnet <database endpoint> <port>.

    1. If you are using a private network endpoint:

      1. Check whether the ECS instance and the PolarDB cluster are in the same VPC. If they are not in the same VPC, you cannot use the private network endpoint. Use one of the following solutions to place the ECS instance and the PolarDB cluster in the same VPC:

      2. Check whether the private IP address, IP address range, or security group of the ECS instance is added to the cluster whitelist.

    2. If you are using a public network endpoint, check whether the public IP address or security group of the ECS instance is added to the cluster whitelist.

Note

Virtual hosts and simple application servers cannot connect to PolarDB through a private network endpoint.

An on-premises environment cannot connect to a PolarDB cluster

Troubleshoot as follows:

  1. Check whether the PolarDB cluster is in the running state.

  2. Verify that the database endpoint, port, account, and password are correct. Obtain the database endpoint and port.

    Note

    The database endpoint must be a public network endpoint. If you are using an ECS instance that is in the same VPC as the PolarDB cluster, you can use a private network endpoint.

  3. Test network connectivity from your on-premises environment using ping <database endpoint> or telnet <database endpoint> <port>.

  4. Check whether the public IP address or IP address range of your on-premises environment is added to the cluster whitelist.

    Obtain your public IP address:

    • Linux operating system: Open the terminal and run the curl ifconfig.me command.

    • Windows operating system: Open the command prompt and run the curl ip.me command.

    • macOS operating system: Open the terminal and run the curl ifconfig.me command.

    If your on-premises network environment uses a proxy server or has other similar configurations, the IP address obtained using the preceding methods may not be your real public IP address. You can add the IP address range 0.0.0.0/0 to the PolarDB cluster whitelist. After you successfully connect to the cluster, run the SHOW PROCESSLIST; command to obtain the real public IP address and add it to the cluster whitelist. Then, remove the IP address range 0.0.0.0/0 from the whitelist.

    image

Cannot connect to a PolarDB cluster with the error "Can't connect to MySQL server on 'xxx'" or "Connection timed out"

The public IP address or IP address range of your environment is likely not in the PolarDB cluster whitelist, or the IP address you entered is incorrect.

Obtain your public IP address:

  • Linux operating system: Open the terminal and run the curl ifconfig.me command.

  • Windows operating system: Open the command prompt and run the curl ip.me command.

  • macOS operating system: Open the terminal and run the curl ifconfig.me command.

If your on-premises network environment uses a proxy server or has other similar configurations, the IP address obtained using the preceding methods may not be your real public IP address. You can add the IP address range 0.0.0.0/0 to the PolarDB cluster whitelist. After you successfully connect to the cluster, run the SHOW PROCESSLIST; command to obtain the real public IP address and add it to the cluster whitelist. Then, remove the IP address range 0.0.0.0/0 from the whitelist.

image

After I remove an IP address from a whitelist, are existing connections disconnected?

No. The whitelist is checked only when a new connection is established. After an IP address is removed, existing connections are not affected, but new connections are blocked. To disconnect existing connections, manually terminate the sessions.

How do I troubleshoot connections from unknown IP addresses?

If you discover connections from unknown IP addresses, follow these steps to identify the IP source:

  1. Log on to the PolarDB console, go to the cluster details page, and chooseSettings and Management>Cluster Whitelists.

  2. Check each whitelist group in the IP list for unknown IP addresses or a0.0.0.0/0entry.0.0.0.0/0indicates that any IP address is allowed to access the database cluster. This setting significantly reduces the security of the database. Do not use this setting unless necessary.

  3. hdm_security_ips(IP whitelist for DAS),ali_dms_group(IP whitelist for DMS) and other system groups contain IP addresses from Alibaba Cloud internal monitoring and health check services. This is expected behavior.

  4. Confirm the source of the unknown IP address before taking action. Accidentally deleting system group IP addresses may cause monitoring and other features of the related services to malfunction.

For more information about IP whitelist issues, see Troubleshoot IP whitelist issues.

References

  • Set up a global IP whitelist template: A global IP whitelist template allows you to maintain a single set of IP whitelist templates that dynamically apply to all associated PolarDB clusters.

  • Configure a security group: After a security group is added, the ECS instances in the security group are automatically added to the PolarDB cluster whitelist and kept up to date. This eliminates the need to manually update the PolarDB cluster whitelist after new ECS instances are added.

Related API operations

API

Description

DescribeDBClusterAccessWhitelist

Queries the IP addresses that are allowed to access a specified PolarDB for MySQL cluster.

ModifyDBClusterAccessWhitelist

Modifies the IP addresses that are allowed to access a specified PolarDB for MySQL cluster.