Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-25515

Request: User Account Host Names using CIDR notation

    XMLWordPrintable

Details

    • Hide
      h3. CIDR notation for account host names (MDEV-25515)

      An IPv4 account host can now be specified using a CIDR prefix, for example {{CREATE USER u@'192.168.0.0/24'}}. This is equivalent to {{'192.168.0.0/255.255.255.0'}}.

      The prefix is converted to the netmask form when the statement is parsed. Therefore, the netmask form is stored and displayed by {{SHOW GRANTS}}.

      h4. Removing an old literal CIDR account requires a direct DELETE

      Earlier versions accepted a host such as {{10.0.0.0/24}} and stored it as plain text. Such an account never matched any client and therefore never worked.

      The server now converts {{10.0.0.0/24}} to {{10.0.0.0/255.255.255.0}} before looking up the account. As a result, {{DROP USER}} and {{RENAME USER}} can no longer find the old row, and {{DROP USER u@'10.0.0.0/24'}} fails.

      Such a row is skipped when privileges are loaded, and a warning is written to the error log. Consequently, the account grants no access.

      To remove the old account, delete its row from the privilege tables and reload the privileges:

      {code:sql}
      DELETE FROM mysql.global_priv WHERE User='u' AND Host='10.0.0.0/24';
      -- Repeat for mysql.db, mysql.tables_priv, mysql.columns_priv,
      -- mysql.procs_priv, mysql.proxies_priv, and mysql.roles_mapping
      -- if they contain rows for this account.
      FLUSH PRIVILEGES;
      {code}

      h4. Compatibility with MySQL 8.0

      MySQL 8.0.23 also introduced CIDR notation for account host names, but handles it differently.

      || Behavior || MySQL 8.0 || MariaDB ||
      | Storage | Stored exactly as specified ({{/24}} remains {{/24}}) | Converted to the netmask form |
      | {{/24}} and {{/255.255.255.0}} for the same user | Stored as separate accounts; one can shadow the other | Converted to the same netmask form; duplicate accounts are rejected |
      | Invalid hosts (see below) | Accepted and stored, but never match any client | Rejected with {{ER_INVALID_HOST_NETMASK}} when created or renamed to |
      | Existing invalid hosts or literal-CIDR rows | Not applicable | Skipped when privileges are loaded, with a warning in the error log |

      Invalid hosts include host bits being set ({{10.0.3.5/24}}), {{/0}}, a prefix greater than 32, a non-contiguous netmask, and a wildcard combined with a prefix.

      When migrating from MySQL:

      * Account statements from a MySQL 8.0 dump, such as {{CREATE USER}} and {{GRANT}}, work because MariaDB converts CIDR prefixes to the netmask form. Statements specifying invalid hosts listed above fail. MySQL never matched such accounts either.
      * A raw privilege-table row containing a literal CIDR host, for example from a restored dump of the {{mysql}} schema, is not converted by the server. The account is skipped when privileges are loaded and cannot be used to log in until the row is rewritten in netmask form, for example {{10.0.0.0/255.255.255.0}}.
      * MySQL 8.0 system tables cannot be reused in place. Converting such rows is the responsibility of migration tooling, not the server.
      Show
      h3. CIDR notation for account host names ( MDEV-25515 ) An IPv4 account host can now be specified using a CIDR prefix, for example {{CREATE USER u@'192.168.0.0/24'}}. This is equivalent to {{'192.168.0.0/255.255.255.0'}}. The prefix is converted to the netmask form when the statement is parsed. Therefore, the netmask form is stored and displayed by {{SHOW GRANTS}}. h4. Removing an old literal CIDR account requires a direct DELETE Earlier versions accepted a host such as {{10.0.0.0/24}} and stored it as plain text. Such an account never matched any client and therefore never worked. The server now converts {{10.0.0.0/24}} to {{10.0.0.0/255.255.255.0}} before looking up the account. As a result, {{DROP USER}} and {{RENAME USER}} can no longer find the old row, and {{DROP USER u@'10.0.0.0/24'}} fails. Such a row is skipped when privileges are loaded, and a warning is written to the error log. Consequently, the account grants no access. To remove the old account, delete its row from the privilege tables and reload the privileges: {code:sql} DELETE FROM mysql.global_priv WHERE User='u' AND Host='10.0.0.0/24'; -- Repeat for mysql.db, mysql.tables_priv, mysql.columns_priv, -- mysql.procs_priv, mysql.proxies_priv, and mysql.roles_mapping -- if they contain rows for this account. FLUSH PRIVILEGES; {code} h4. Compatibility with MySQL 8.0 MySQL 8.0.23 also introduced CIDR notation for account host names, but handles it differently. || Behavior || MySQL 8.0 || MariaDB || | Storage | Stored exactly as specified ({{/24}} remains {{/24}}) | Converted to the netmask form | | {{/24}} and {{/255.255.255.0}} for the same user | Stored as separate accounts; one can shadow the other | Converted to the same netmask form; duplicate accounts are rejected | | Invalid hosts (see below) | Accepted and stored, but never match any client | Rejected with {{ER_INVALID_HOST_NETMASK}} when created or renamed to | | Existing invalid hosts or literal-CIDR rows | Not applicable | Skipped when privileges are loaded, with a warning in the error log | Invalid hosts include host bits being set ({{10.0.3.5/24}}), {{/0}}, a prefix greater than 32, a non-contiguous netmask, and a wildcard combined with a prefix. When migrating from MySQL: * Account statements from a MySQL 8.0 dump, such as {{CREATE USER}} and {{GRANT}}, work because MariaDB converts CIDR prefixes to the netmask form. Statements specifying invalid hosts listed above fail. MySQL never matched such accounts either. * A raw privilege-table row containing a literal CIDR host, for example from a restored dump of the {{mysql}} schema, is not converted by the server. The account is skipped when privileges are loaded and cannot be used to log in until the row is rewritten in netmask form, for example {{10.0.0.0/255.255.255.0}}. * MySQL 8.0 system tables cannot be reused in place. Converting such rows is the responsibility of migration tooling, not the server.
    • Q3/2026 Server Development, Q4/2026 Server Maintenance

    Description

      CIDR Notation was specified by RFC 4632 in 2006.
      It is more compact than netmasks.
      I would like to request CIDR notation as a new feature for User Account Host Names.

      MySQL 8.0.23 has already done this with WL#14074:
      https://dev.mysql.com/worklog/task/?id=14074

      Thank you!
      Daniel Lewart
      Urbana, Illinois

      Attachments

        Issue Links

          Activity

            People

              pranav.tiwari@mariadb.com Pranav Kumar Tiwari
              lewart Daniel Lewart
              Pranav Kumar Tiwari Pranav Kumar Tiwari
              Votes:
              4 Vote for this issue
              Watchers:
              12 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - 9d Original Estimate - 9d
                  9d
                  Remaining:
                  Remaining Estimate - 0d
                  0d
                  Logged:
                  Time Spent - 9d 3.5h
                  9d 3.5h

                  Git Integration

                    Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.