PolarDB for MySQL, , and support global IP whitelist management. You can create custom IP whitelist templates and associate them with your clusters. This allows you to maintain a single template that dynamically applies to all associated clusters, simplifying whitelist management. This topic shows you how to set up global IP whitelist templates.
Usage notes
-
A cluster can only be associated with an IP whitelist template in the same region.
-
When you delete an IP whitelist template, its settings are also removed from all associated clusters. To prevent database connection failures, be sure to disassociate the template from all relevant clusters before you delete it.
-
A single IP whitelist template can contain a maximum of 1,000 IP addresses.
-
A single cluster can be associated with multiple IP whitelist templates.
-
A single IP whitelist template can be associated with multiple clusters.
Create an IP whitelist template
-
Log in to the PolarDB console。
-
In the upper-left corner, select the region where the cluster is deployed.
-
In the left-side navigation pane, choose .
-
In the upper-left corner of the page, click Create IP Whitelist Template.
-
On the Create IP Whitelist Template page, enter an IP Whitelist Template Name and the IP Addresses in Whitelist.
NoteThe IP Whitelist Template Name must meet the following requirements:
-
It must consist of lowercase letters, digits, and underscores (_).
-
It must start with a letter and end with a letter or a digit.
-
It must be 2 to 120 characters long.
-
-
Click OK.
Modify an IP whitelist template
-
Log in to the PolarDB console。
-
In the upper-left corner, select the region where the cluster is deployed.
-
In the left-side navigation pane, choose .
-
On the IP Whitelist Templates page, find the target IP whitelist template and click Modify in the Operation column.
-
On the Modify IP Whitelist Template page, add or remove IP addresses from the whitelist, and then click OK.
-
In the dialog box, click OK.
NoteThe modified IP whitelist applies to all associated clusters. Proceed with caution.
Delete an IP whitelist template
-
Log in to the PolarDB console。
-
In the upper-left corner, select the region where the cluster is deployed.
-
In the left-side navigation pane, choose .
-
On the IP Whitelist Templates page, find the target IP whitelist template and click Delete in the Operation column.
-
In the dialog box that appears, click Delete.
NoteWhen you delete an IP whitelist template, its settings are removed from all associated clusters. To prevent connection failures, proceed with caution.
Associate an IP whitelist template
-
Log in to the PolarDB console。
-
In the upper-left corner, select the region where the cluster is deployed.
-
Find the target cluster and click its ID.
-
In the left-side navigation pane, choose .
-
On the Cluster Whitelists page, click Associate IP Whitelist Template.
-
In the Associate IP Whitelist Template dialog box, select a template and click OK.
Disassociate an IP whitelist template
-
Log in to the PolarDB console。
-
In the upper-left corner, select the region where the cluster is deployed.
-
Find the target cluster and click its ID.
-
In the left-side navigation pane, choose .
-
On the Cluster Whitelists page, find the target IP whitelist template and click Disassociate.
-
In the dialog box that appears, click OK.
FAQ
Q: How can I block a specific IP address from accessing a PolarDB for MySQL database?
A: PolarDB for MySQL does not provide a direct IP blacklist feature. However, you can achieve a similar outcome in one of the following ways:
Indirectly restrict access by using the IP whitelist feature: When you configure a whitelist group for a cluster endpoint, add only trusted IP addresses. If an IP address is not in any IP whitelist, it cannot establish a database connection. This is the recommended method for global protection.
Precisely block access by locking a specific user account: If you need to prevent a specific user from logging in from a specific IP address (for example, test@'192.168.0.1'), you can run the following commands:
-- 1. Create the user. You can create the user explicitly to lock it, even if the account is inactive.
CREATE USER 'test'@'192.168.0.1' IDENTIFIED BY 'xxxxx';
-- 2. Lock the user account.
ALTER USER 'test'@'192.168.0.1' ACCOUNT LOCK;
After the account is locked, if a connection attempt is made from that IP address as the test user, the following error is returned:
ERROR 3118 (HY000): Access denied for user 'test'@'192.168.0.1'. Account is locked.