MDEV-25515 Request: User Account Host Names using CIDR notation - #5500
Open
pranavktiwari wants to merge 1 commit into
Open
MDEV-25515 Request: User Account Host Names using CIDR notation#5500pranavktiwari wants to merge 1 commit into
pranavktiwari wants to merge 1 commit into
Conversation
pranavktiwari
marked this pull request as draft
August 6, 2026 08:19
There was a problem hiding this comment.
Pull request overview
This PR implements support for specifying user account hostnames using CIDR prefix notation (e.g. 10.0.0.0/24) in addition to the existing dotted-quad netmask notation, and ensures masked host entries are ordered by subnet specificity during ACL matching.
Changes:
- Added CIDR prefix parsing and masked-host validation (contiguous, non-zero mask; network address only) for account creation paths.
- Updated ACL user sorting to prefer more-specific masked subnets when resolving otherwise-equal matches.
- Added a mysql-test that exercises valid/invalid CIDR inputs, precedence ordering, and persistence across
FLUSH PRIVILEGES.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
sql/sql_acl.cc |
Adds CIDR parsing (/N), validates masked hosts on account creation/rename, and sorts masked entries by subnet specificity. |
sql/share/errmsg-utf8.txt |
Introduces new ER_INVALID_HOST_NETMASK error text for invalid masked-host specifications. |
mysql-test/main/grant_cidr.test |
New test coverage for CIDR host notation, rejection cases, and precedence rules. |
mysql-test/main/grant_cidr.result |
Expected output for the new CIDR test. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
pranavktiwari
force-pushed
the
bb-main-MDEV-25515
branch
3 times, most recently
from
August 11, 2026 05:48
a36fc70 to
65c05a5
Compare
Accept CIDR notation (RFC 4632) as an alternative spelling of the
ip/netmask host form, matching MySQL 8.0.23 (WL#14074):
CREATE USER u@'192.168.0.0/24'; -- same as '192.168.0.0/255.255.255.0'
update_hostname() tries the dotted-quad mask first and falls back to the
new calc_cidr(), so both spellings yield the same acl_host_and_ip and are
interchangeable wherever a host is used - user, db, table, routine and
proxy privileges, and the plugin API. IPv4 only. The host string is
stored and reported verbatim; neither spelling is normalised.
Add is_valid_masked_host(), rejecting at DDL time what was previously
accepted and left silently unusable:
- a prefix outside 1..32, or a mask of 0.0.0.0
- a non-contiguous mask, e.g. 10.0.0.0/255.0.255.0
- an address with host bits set, e.g. 10.1.2.3/24
- anything containing '/' that is not a dotted quad, including IPv6
prefixes such as 2001:db8::/32
The check runs in replace_user_table(), covering CREATE USER and every
GRANT variant that can auto-create an account, and in mysql_rename_user()
for the rename target. It applies only to rows about to be created:
- existing rows are not validated, so an account created by an older
version stays revocable, renamable and droppable
- acl_load() is unchanged, so a malformed row in the privilege tables
cannot prevent the server from starting
- RENAME USER validates the target only, so such an account can be
repaired by renaming it onto a valid host
New error ER_INVALID_HOST_NETMASK.
acl_user_compare() now compares ip_mask before the host string, treating
an unmasked host as /32, so the most specific subnet wins:
u@'10.0.0.0/24' is preferred over u@'10.0.0.0/8'
This corrects precedence for existing netmask accounts as well, and
applies to acl_users only; acl_dbs, acl_hosts, acl_proxy_users and the
table/routine grant hashes are left unchanged.
pranavktiwari
force-pushed
the
bb-main-MDEV-25515
branch
from
August 11, 2026 05:55
65c05a5 to
a7f376c
Compare
pranavktiwari
marked this pull request as ready for review
August 11, 2026 06:00
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MDEV-25515 User Account Host Names using CIDR notation
Accept CIDR notation (RFC 4632) as an alternative spelling of the ip/netmask host form, matching MySQL 8.0.23 (WL#14074):
update_hostname() tries the dotted-quad mask first and falls back to the
new calc_cidr(), so both spellings yield the same acl_host_and_ip and are
interchangeable wherever a host is used - user, db, table, routine and
proxy privileges, and the plugin API. IPv4 only. The host string is
stored and reported verbatim; neither spelling is normalised.
Add is_valid_masked_host(), rejecting at DDL time what was previously
accepted and left silently unusable:
The check runs in replace_user_table(), covering CREATE USER and every
GRANT variant that can auto-create an account, and in mysql_rename_user()
for the rename target. It applies only to rows about to be created:
New error ER_INVALID_HOST_NETMASK.
acl_user_compare() now compares ip_mask before the host string, treating
an unmasked host as /32, so the most specific subnet wins:
This corrects precedence for existing netmask accounts as well, and
applies to acl_users only; acl_dbs, acl_hosts, acl_proxy_users and the
table/routine grant hashes are left unchanged.