salt icon indicating copy to clipboard operation
salt copied to clipboard

mysql_grant fails with MySQL Error 1144: Illegal GRANT/REVOKE command

Open OliverKellyATech opened this issue 8 years ago • 17 comments

Description of Issue/Question

mysql_grant fails with error "MySQL Error 1144: Illegal GRANT/REVOKE command;" for certain simple priv_level with global scope (eg: PROCESS, SUPER).

Setup

SLS uses the following definition:

metricbeat:
  ...
  mysql_user:
    - present
    - host: '%'
    - password: metricbeat
    - require:
      - service: mysql
  mysql_grants:
    - present
    - grant: PROCESS
    - database: '*.*'
    - user: metricbeat
    - host: '%'
    - require:
      - mysql_user: metricbeat

Minion uses the following to provide MySQL admin access via /etc/salt/minion:

mysql.default_file: "/etc/mysql/debian.cnf"

"MySQL" server is MariaDB 10.1.32

Steps to Reproduce Issue

With setup and SLS above, run salt-cale state.highstate, the following error will be generated:

[ERROR   ] MySQL Error 1144: Illegal GRANT/REVOKE command; please consult the manual to see which privileges can be used
[ERROR   ] Failed to execute: "GRANT PROCESS ON *.* TO metricbeat@%" (MySQL Error 1144: Illegal GRANT/REVOKE command; please consult the manual to see which privileges can be used)

And the following error in the highstate summary:

ID: metricbeat
    Function: mysql_grants.present
      Result: False
     Comment: Failed to execute: "GRANT PROCESS ON *.* TO metricbeat@%" (MySQL Error 1144: Illegal GRANT/REVOKE command; please consult the manual to see which privileges can be used)
     Started: 09:00:21.236148
    Duration: 9.586 ms

Running the generated SQL statement GRANT PROCESS ON *.* TO metricbeat@% directly via the MariaDB console also gives the following error:

MariaDB [(none)]> GRANT process ON *.* TO metricbeat@%;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '%' at line 1

However, correcting the SQL statement to quote the host wildcard GRANT process ON *.* TO metricbeat@'%'; results in a successful execution:

MariaDB [(none)]> GRANT process ON *.* TO metricbeat@'%';
Query OK, 0 rows affected (0.00 sec)

Other mysql_grant definitions which also use a % host wildcard but have more common priv_levels (eg: ALL PRIVILEGES, SELECT, etc.) seem to have no issue, on same host with same MariaDB version, and on other hosts with MariaDB or MySQL versions.

Versions Report

Master package version is salt-master 2018.3.0+ds-1:

Salt Version:
           Salt: 2018.3.0
 
Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.4.2
      docker-py: Not Installed
          gitdb: 0.6.4
      gitpython: 1.0.1
          ioflo: Not Installed
         Jinja2: 2.8
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: 1.0.3
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.12 (default, Dec  4 2017, 14:50:18)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.2.0
           RAET: Not Installed
          smmap: 0.9.0
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4
 
System Versions:
           dist: Ubuntu 16.04 xenial
         locale: UTF-8
        machine: x86_64
        release: 4.4.0-119-generic
         system: Linux
        version: Ubuntu 16.04 xenial

Minion is same package version as master: salt-minion 2018.3.0+ds-1:

Salt Version:
           Salt: 2018.3.0
 
Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.4.2
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.8
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: 1.0.3
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: 1.3.7
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.12 (default, Dec  4 2017, 14:50:18)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.2.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.2.3
 
System Versions:
           dist: Ubuntu 16.04 xenial
         locale: UTF-8
        machine: x86_64
        release: 4.4.0-119-generic
         system: Linux
        version: Ubuntu 16.04 xenial

OliverKellyATech avatar Apr 15 '18 23:04 OliverKellyATech

@UtahDave I know you were looking at these at some point, would you mind poking around here and seeing if you remember how to fix this?

Thanks, Daniel

gtmanfred avatar Apr 16 '18 19:04 gtmanfred

@oekelly has this worked on previous versions of Salt or is this the first time you've attempted this?

UtahDave avatar Apr 16 '18 23:04 UtahDave

Hi David,

Yes these mysql_grant states have worked in the past, although I can't confirm the exact salt or mysql versions.

I'll do some digging to see if I can find out exact versions for you.

On Tue., 17 Apr. 2018, 09:54 David Boucha, [email protected] wrote:

@oekelly https://github.com/oekelly has this worked on previous versions of Salt or is this the first time you've attempted this?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/saltstack/salt/issues/47086#issuecomment-381785661, or mute the thread https://github.com/notifications/unsubscribe-auth/AHLmxcMZkn43V7BuQxqmxJsxBEMbGrydks5tpS8bgaJpZM4TVsSp .

OliverKellyATech avatar Apr 17 '18 00:04 OliverKellyATech

Hi @UtahDave ,

Here is a server where the same mysql_grant state works:

# salt-minion --versions-report
Salt Version:
           Salt: 2015.8.8
 
Dependency Versions:
         Jinja2: 2.8
       M2Crypto: Not Installed
           Mako: 1.0.3
         PyYAML: 3.11
          PyZMQ: 15.2.0
         Python: 2.7.12 (default, Dec  4 2017, 14:50:18)
           RAET: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.4.2
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
        libgit2: Not Installed
        libnacl: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: 1.3.7
      pycparser: Not Installed
       pycrypto: 2.6.1
         pygit2: Not Installed
   python-gnupg: Not Installed
          smmap: Not Installed
        timelib: Not Installed
 
System Versions:
           dist: Ubuntu 16.04 xenial
        machine: x86_64
        release: 4.4.0-119-generic
         system: Ubuntu 16.04 xenial
 
# dpkg -l | egrep mariadb-server
ii  mariadb-server-10.1                 10.1.32+maria-1~xenial                     amd64        MariaDB database server binaries

As you can see this is the same mariadb-server pkg version (10.1.32), but a different (albeit quite old) salt-minion pkg version.

OliverKellyATech avatar Apr 17 '18 01:04 OliverKellyATech

I am seeing the same behavior. None of my states using mysql_grants.present work in 2018.3.0 but they work fine in 2017.7.5.

Mysql version: Percona-XtraDB-Cluster-server-57 OS Version: CentOS 7.4.1708

Hopefully that helps.

andygabby avatar Apr 25 '18 04:04 andygabby

Are you experiencing this same issue, or are you experiencing https://github.com/saltstack/salt/issues/46917 ?

gtmanfred avatar Apr 25 '18 12:04 gtmanfred

The same here. No changes in states. On April 6th, 9:07, I upgraded from 2017.7.4 to 2018.3.0. At 9:09 the error occured for the first time.

It doesn't happen when granting 'all privileges'. Additionally the execution of the statement is unnecessary as the grants in my case were already correctly set.

Salt Version:
           Salt: 2018.3.0
 
Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.4.2
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.9.4
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: 1.3.7
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.12 (default, Dec  4 2017, 14:50:18)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.2.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4
 
System Versions:
           dist: Ubuntu 16.04 xenial
         locale: ANSI_X3.4-1968
        machine: x86_64
        release: 4.13.13-6-pve
         system: Linux
        version: Ubuntu 16.04 xenial

ghost avatar Apr 25 '18 13:04 ghost

Perhaps I am mistaken, but I think at the core this is the same issue as https://github.com/saltstack/salt/issues/46917, the difference being that specific issue talks about granting on table.* and this is *.*. I have issues with both.

Issue descibed here:

[DEBUG   ] Doing query: GRANT PROCESS, RELOAD, LOCK TABLES, REPLICATION CLIENT ON `*`.`*` TO %(user)s@%(host)s args: {u'host': u'localhost', u'user': u'dbuser'} 
[ERROR   ] MySQL Error 1144: Illegal GRANT/REVOKE command; please consult the manual to see which privileges can be used
[ERROR   ] Failed to execute: "GRANT PROCESS,RELOAD,LOCK TABLES,REPLICATION CLIENT ON *.* TO dbuser@localhost" (MySQL Error 1144: Illegal GRANT/REVOKE command; please consult the manual to see which privileges can be used)

Issue described in https://github.com/saltstack/salt/issues/46917

[DEBUG   ] Doing query: GRANT SELECT, INSERT, UPDATE, DELETE ON `mydb`.`*` TO %(user)s@%(host)s args: {u'host': u'10.84.0.0/255.255.0.0', u'user': u'dbuser2'} 
[ERROR   ] MySQL Error 1146: Table 'mydb.*' doesn't exist
[ERROR   ] Failed to execute: "GRANT select,insert,update,delete ON mydb.* TO [email protected]/255.255.0.0" (MySQL Error 1146: Table 'mydb.*' doesn't exist)

In both cases it looks like the backticks around * cause the problem.

andygabby avatar Apr 25 '18 16:04 andygabby

My issue is fixed with https://github.com/saltstack/salt/commit/8af407173d6c199c840dac1fc78d6ffc2e4410d2#diff-29a8d4513061a20d02e36c542ea18e19

[DEBUG   ] grants mismatch '{'host': u'localhost', 'database': u'*.*', 'user': u'salt', 'grant': ['SELECT', 'INSERT', 'UPDATE', 'DELETE', 'CREATE', 'DROP', 'RELOAD', 'PROCESS', 'REFERENCES', 'INDEX', 'ALTER', u'CREATE TEMPORARY TABLES', u'LOCK TABLES', 'EXECUTE', u'CREATE VIEW', u'SHOW VIEW', u'CREATE ROUTINE', u'ALTER ROUTINE', 'EVENT', 'TRIGGER']}'<>'{'host': u'localhost', 'database': u'`*`.`*`', 'user': u'salt', 'grant': ['SELECT', 'INSERT', 'UPDATE', 'DELETE', 'EXECUTE', u'SHOW VIEW', 'ALTER', 'CREATE', 'DROP', 'INDEX', 'REFERENCES', u'CREATE VIEW', u'CREATE ROUTINE', u'ALTER ROUTINE', 'EVENT', 'TRIGGER', u'CREATE TEMPORARY TABLES', u'LOCK TABLES', 'PROCESS', 'RELOAD']}'

So just waiting for the next release ;-)

ghost avatar Apr 27 '18 07:04 ghost

I just hit this same issue, I hope this will get fixed in 2018.3.1

soostdijck avatar May 04 '18 09:05 soostdijck

Duplicate of https://github.com/saltstack/salt/issues/47460 ? Having the same problem, really need this fixed in 2018.3.1

zerthimon avatar May 31 '18 13:05 zerthimon

https://github.com/saltstack/salt/issues/46666

zerthimon avatar May 31 '18 13:05 zerthimon

https://github.com/saltstack/salt/issues/47004

zerthimon avatar May 31 '18 14:05 zerthimon

I am also effected by this issue, when is 2018.3.1 set to release? I noticed that 2018.3.0 has many broken features, that used to work in 2017.7.? Perhaps more testing should be done before accepting an PR into the release branch? I am boggled at how this mysql_grant state issue got into a release version of SaltStack. Additional QA should be performed on updates to major widely used modules such as this.

kveroneau avatar May 31 '18 22:05 kveroneau

same with 2018.3.0

vshuraeff avatar Jun 07 '18 11:06 vshuraeff

This issue is resolved for me in 2018.3.2

soostdijck avatar Jul 03 '18 10:07 soostdijck

if we do this then this user can also modify other user's databases ???? I have mysql 5.6 MariaDB [(none)]> GRANT process ON . TO metricbeat@'%'; Query OK, 0 rows affected (0.00 sec)

PrakashElsner avatar Mar 18 '19 08:03 PrakashElsner