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

Executing a query via CTE requires more permissions than the query itself

Details

    • 10.2.11

    Description

      Based on the question posted at stackoverflow by Diogo Melo:
      https://stackoverflow.com/questions/45510362/error-1142-42000-select-command-denied-for-with-recursive-statement-on-ma

      When a query is executed via CTE, it's not enough to have normal privileges for the query, the user must also have SELECT privileges for the CTE itself, which are impossible to grant.

      create database db;
      use db;
      create table t1 (i int);
       
      create user foo@localhost;
      grant SELECT on db.t1 to foo@localhost;
       
      --connect (con1,localhost,foo,,)
      use db;
      with cte as (select * from t1) select * from cte;
       
      # Cleanup
      --disconnect con1
       
      --connection default
      drop database db;
      drop user foo@localhost;
      

      CURRENT_TEST: bug.t6
      mysqltest: At line 10: query 'with cte as (select * from t1) select * from cte' failed: 1142: SELECT command denied to user 'foo'@'localhost' for table 'cte'
      

      Attachments

        Issue Links

          Activity

            elenst Elena Stepanova created issue -
            elenst Elena Stepanova made changes -
            Field Original Value New Value
            Description Based on the question posted at stackoverflow:
            https://stackoverflow.com/questions/45510362/error-1142-42000-select-command-denied-for-with-recursive-statement-on-ma

            When a query is executed via CTE, it's not enough to have normal privileges for the query, the user must also have grants for the CTE itself, which are impossible to grant.

            {code:sql}
            create database db;
            use db;
            create table t1 (i int);

            create user foo@localhost;
            grant SELECT on db.t1 to foo@localhost;

            --connect (con1,localhost,foo,,)
            use db;
            with cte as (select * from t1) select * from cte;

            # Cleanup
            --disconnect con1

            --connection default
            drop database db;
            drop user foo@localhost;
            {code}

            {noformat}
            CURRENT_TEST: bug.t6
            mysqltest: At line 10: query 'with cte as (select * from t1) select * from cte' failed: 1142: SELECT command denied to user 'foo'@'localhost' for table 'cte'
            {noformat}
            Based on the question posted at stackoverflow by *Diogo Melo*:
            https://stackoverflow.com/questions/45510362/error-1142-42000-select-command-denied-for-with-recursive-statement-on-ma

            When a query is executed via CTE, it's not enough to have normal privileges for the query, the user must also have grants for the CTE itself, which are impossible to grant.

            {code:sql}
            create database db;
            use db;
            create table t1 (i int);

            create user foo@localhost;
            grant SELECT on db.t1 to foo@localhost;

            --connect (con1,localhost,foo,,)
            use db;
            with cte as (select * from t1) select * from cte;

            # Cleanup
            --disconnect con1

            --connection default
            drop database db;
            drop user foo@localhost;
            {code}

            {noformat}
            CURRENT_TEST: bug.t6
            mysqltest: At line 10: query 'with cte as (select * from t1) select * from cte' failed: 1142: SELECT command denied to user 'foo'@'localhost' for table 'cte'
            {noformat}
            elenst Elena Stepanova made changes -
            Description Based on the question posted at stackoverflow by *Diogo Melo*:
            https://stackoverflow.com/questions/45510362/error-1142-42000-select-command-denied-for-with-recursive-statement-on-ma

            When a query is executed via CTE, it's not enough to have normal privileges for the query, the user must also have grants for the CTE itself, which are impossible to grant.

            {code:sql}
            create database db;
            use db;
            create table t1 (i int);

            create user foo@localhost;
            grant SELECT on db.t1 to foo@localhost;

            --connect (con1,localhost,foo,,)
            use db;
            with cte as (select * from t1) select * from cte;

            # Cleanup
            --disconnect con1

            --connection default
            drop database db;
            drop user foo@localhost;
            {code}

            {noformat}
            CURRENT_TEST: bug.t6
            mysqltest: At line 10: query 'with cte as (select * from t1) select * from cte' failed: 1142: SELECT command denied to user 'foo'@'localhost' for table 'cte'
            {noformat}
            Based on the question posted at stackoverflow by *Diogo Melo*:
            https://stackoverflow.com/questions/45510362/error-1142-42000-select-command-denied-for-with-recursive-statement-on-ma

            When a query is executed via CTE, it's not enough to have normal privileges for the query, the user must also have SELECT privileges for the CTE itself, which are impossible to grant.

            {code:sql}
            create database db;
            use db;
            create table t1 (i int);

            create user foo@localhost;
            grant SELECT on db.t1 to foo@localhost;

            --connect (con1,localhost,foo,,)
            use db;
            with cte as (select * from t1) select * from cte;

            # Cleanup
            --disconnect con1

            --connection default
            drop database db;
            drop user foo@localhost;
            {code}

            {noformat}
            CURRENT_TEST: bug.t6
            mysqltest: At line 10: query 'with cte as (select * from t1) select * from cte' failed: 1142: SELECT command denied to user 'foo'@'localhost' for table 'cte'
            {noformat}
            elenst Elena Stepanova made changes -

            Seems to work on 10.2.2, so perhaps a regression?

            rjasdf Rick James (Inactive) added a comment - Seems to work on 10.2.2, so perhaps a regression?
            elenst Elena Stepanova made changes -
            serg Sergei Golubchik made changes -
            Sprint 10.2.11 [ 203 ]
            igor Igor Babaev (Inactive) made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            igor Igor Babaev (Inactive) made changes -
            Assignee Igor Babaev [ igor ] Oleksandr Byelkin [ sanja ]
            Status In Progress [ 3 ] In Review [ 10002 ]

            OK to push after fixing resulta and adding the comment we discussed.

            sanja Oleksandr Byelkin added a comment - OK to push after fixing resulta and adding the comment we discussed.
            sanja Oleksandr Byelkin made changes -
            Assignee Oleksandr Byelkin [ sanja ] Igor Babaev [ igor ]
            Status In Review [ 10002 ] Stalled [ 10000 ]

            The fix for this bug was pushed into the 10.2 tree.

            igor Igor Babaev (Inactive) added a comment - The fix for this bug was pushed into the 10.2 tree.
            igor Igor Babaev (Inactive) made changes -
            Fix Version/s 10.2.11 [ 22634 ]
            Fix Version/s 10.2 [ 14601 ]
            Resolution Fixed [ 1 ]
            Status Stalled [ 10000 ] Closed [ 6 ]
            markus makela markus makela made changes -
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 81913 ] MariaDB v4 [ 152569 ]

            People

              igor Igor Babaev (Inactive)
              elenst Elena Stepanova
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

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