Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL execute as user or impersonate

Tags:

mysql

In MySQL, is there a way to execute a query as a specific user to test table permissions? Is there a way to impersonate a user execution context when you are connected with a higher privileged account?

In the MSSQL world, one would use EXECUTE AS login = 'username', followed by your SQL Statements, then finally a REVERT, to close the impersonation.

Is there something similar in MySQL?

like image 968
Kevin Avatar asked Sep 12 '13 23:09

Kevin


1 Answers

Personally I have never tried before, but you can take a look at the "Mysql Proxy User" available starting from MySQL 5.5.7

The plugin may request that the connecting (external) user be treated as a different user for privilege-checking purposes. This enables the external user to be a proxy for the second user; that is, to have the privileges of the second user. In other words, the external user is a “proxy user” (a user who can impersonate or become known as another user) and the second user is a “proxied user” (a user whose identity can be taken on by a proxy user)

Also you can write your own authentication plugins for proxy users

... Here another post that explain this kind of behaviour "MySQL Proxy Users – SU emulation"

like image 142
Cristian Porta Avatar answered Sep 20 '22 17:09

Cristian Porta