Skip to content

Commit e9de786

Browse files
committed
First stable version
Added gitattributes and gitignore suggested by github Added install scripts for 5.0 and 5.5 Added user setup example script Added License and Readme files
0 parents  commit e9de786

File tree

7 files changed

+775
-0
lines changed

7 files changed

+775
-0
lines changed

.gitattributes

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto
3+
4+
# Custom for Visual Studio
5+
*.cs diff=csharp
6+
7+
# Standard to msysgit
8+
*.doc diff=astextplain
9+
*.DOC diff=astextplain
10+
*.docx diff=astextplain
11+
*.DOCX diff=astextplain
12+
*.dot diff=astextplain
13+
*.DOT diff=astextplain
14+
*.pdf diff=astextplain
15+
*.PDF diff=astextplain
16+
*.rtf diff=astextplain
17+
*.RTF diff=astextplain

.gitignore

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Windows image file caches
2+
Thumbs.db
3+
ehthumbs.db
4+
5+
# Folder config file
6+
Desktop.ini
7+
8+
# Recycle Bin used on file shares
9+
$RECYCLE.BIN/
10+
11+
# Windows Installer files
12+
*.cab
13+
*.msi
14+
*.msm
15+
*.msp
16+
17+
# Windows shortcuts
18+
*.lnk
19+
20+
# =========================
21+
# Operating System Files
22+
# =========================
23+
24+
# OSX
25+
# =========================
26+
27+
.DS_Store
28+
.AppleDouble
29+
.LSOverride
30+
31+
# Thumbnails
32+
._*
33+
34+
# Files that might appear on external disk
35+
.Spotlight-V100
36+
.Trashes
37+
38+
# Directories potentially created on remote AFP share
39+
.AppleDB
40+
.AppleDesktop
41+
Network Trash Folder
42+
Temporary Items
43+
.apdisk

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2015 Choobs Ltd.
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

README.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
Choobs MySQL Grants Toolkit
2+
===========================
3+
4+
MySQL's [GRANT syntax](http://dev.mysql.com/doc/refman/5.0/en/grant.html "MySQL 5.0 Reference Manual") uses the WITH GRANT OPTION which lets you GRANT a permission to a user and then allows the user to GRANT that permission further. However a limitation of MySQL is that the option is automatically valid for **all** permissions you granted the user, not just the one that you specified with the WITH GRANT OPTION.
5+
6+
This means that the moment you use the WITH GRANT OPTION the user automatically can give his permissions and the power to GRANT to another user. In effect with the help of another user the current user can gain all the permissions of the other user.
7+
8+
This toolkit restricts the GRANT OPTION by adding a layer of checking which means you can only apply grants for a specific set of permissions (wether you have them or not).
9+
10+
You can therefore limit the propagation of permissions between users to a well defined set of permissions and databases/tables.
11+
12+
##Documentation
13+
14+
MySQL stores table privileges in mysql.tables_priv and column privileges in mysql.columns_priv internally. However, since GRANT statement has the aforementioned issue, we avoid giving actual GRANT permissions to the users.
15+
Instead, we give EXECUTE privilege to custom procedures which do what the GRANT/REVOKE statements do after checking if the user is allowed to grant the privilege. The list of privileges the user is allowed to grant is stored in a custom table. The users don't actually have the GRANT privilege, so they can't bypass the security using GRANT statement.
16+
17+
#### Compatibility
18+
Limited testing was done on MySQL and MariaDB. In principle any MySQL compatible database server version 5.0 and later should work. Please let us know if you have any issues with your database.
19+
20+
#### Setup
21+
Use the install-mysqlgt-5.0.sql for MySQL version >=5.0 and <5.5 and install-mysqlgt-5.5.sql for MySQL version >=5.5. The script must be run as root.
22+
23+
After you run it, a new schema mysqlgt is created with tables mysqlgt.db_grant and mysqlgt.log and new procedures mysqlgt.gtSIMPLIFY_DATA, mysqlgt.gtGRANT and mysqlgt.gtREVOKE are created.
24+
25+
To allow a user (say test_user) to grant only the specified privileges:
26+
27+
* give EXECUTE permissions to the user to execute mysqlgt.gtGRANT and mysqlgt.gtREVOKE
28+
* insert a row in mysqlgt.db_grant specifying what table privileges a user is allowed to grant
29+
30+
##### Example:
31+
32+
In the following example, a user test_user@localhost is allowed to grant SELECT, UPDATE, INSERT and DELETE privileges on database test_db:
33+
34+
```sql
35+
-- Allow EXECUTE for 'test_user'@'localhost' on mysqlgt procedures
36+
GRANT EXECUTE ON PROCEDURE `mysqlgt`.`gtREVOKE` TO 'test_user'@'localhost';
37+
GRANT EXECUTE ON PROCEDURE `mysqlgt`.`gtGRANT` TO 'test_user'@'localhost';
38+
39+
-- Allow the user to reload privileges after updating grants
40+
-- make sure you are comfortable giving this permission to the user
41+
-- allows reloading of logs, replication sync and a few other reloads
42+
GRANT RELOAD ON *.* TO 'test_user'@'localhost';
43+
44+
REPLACE INTO `mysqlgt`.`db_grant` (`Host`, `Db`, `User`, `Table_priv`) VALUES
45+
-- Allow SELECT,INSERT,UPDATE,DELETE GRANT for test@% on schema test
46+
('%', 'test_db', 'test_user', 'select,insert,update,delete')
47+
```
48+
49+
Please note that in mysqlgt.db_grant, Host is set to '%'. Please check the [Known Issues](#known-issues) section for more information about why this is done here.
50+
51+
#### Usage
52+
Now, the user (test_user) will be allowed to grant/revoke privileges to/from other users in the following ways:
53+
54+
```sql
55+
CALL mysqlgt.gtGRANT ( PERMISSIONS, DB.TABLE[.COLUMN], USER@HOST )
56+
CALL mysqlgt.gtREVOKE ( PERMISSIONS, DB.TABLE[.COLUMN], USER@HOST )
57+
```
58+
59+
##### Examples:
60+
###### Table privileges:
61+
62+
```sql
63+
CALL mysqlgt.gtGRANT ( 'Delete,Insert,Update', 'mydb.mytable', 'myuser@hostname' );
64+
CALL mysqlgt.gtREVOKE ( 'Update,Delete', 'mydb.mytable', 'myuser@hostname' );
65+
```
66+
67+
###### Column privileges:
68+
69+
```sql
70+
CALL mysqlgt.gtGRANT ( 'Select,Insert,Update', 'mydb.mytable.mycol', 'myuser@hostname' );
71+
CALL mysqlgt.gtREVOKE ( 'Select,Insert', 'mydb.mytable.mycol', 'myuser@hostname' );
72+
```
73+
74+
##### Notes:
75+
76+
Please note that mysqlgt.gtGRANT and mysqlgt.gtREVOKE will not always replace single GRANT/REVOKE statement with a single call. Consider the following MySQL GRANT Statement:
77+
```sql
78+
GRANT SELECT (mycol1), INSERT (mycol1,mycol2), DELETE ON mydb.mytbl TO 'myuser'@'hostname';
79+
```
80+
81+
Equavalent mysqlgt calls to acheive the above will be:
82+
```sql
83+
CALL mysqlgt.gtGRANT ( 'Select,Insert', 'mydb.mytable.mycol1', 'myuser@hostname' );
84+
CALL mysqlgt.gtGRANT ( 'Insert', 'mydb.mytable.mycol2', 'myuser@hostname' );
85+
CALL mysqlgt.gtGRANT ( 'Delete', 'mydb.mytable', 'myuser@hostname' );
86+
```
87+
88+
Also, note that it currently only supports table and column privileges, it doesn't support database privileges. So, there is no equivalent for the following statement:
89+
```sql
90+
GRANT SELECT ON mydb.* TO 'myuser'@'hostname';
91+
```
92+
This feature is planned for future release.
93+
94+
#### Known Issues
95+
Because using the function `CURRENT_USER()` returns the DEFINER inside of our PROCEDURE instead of the calling user. We were forced to use `USER()` which returns the connected user. However this introduces the following issue.
96+
97+
In the row in mysqlgt.db_grant, Host must be set to whatever the user connects with, not what is in the user db. If name resolve is enabled and you are in an intranet, it is possible that the server will get the hostname (instead of the IP) eg. user@my-pc-hostname instead of [email protected]
98+
99+
This can be an issue for configuration. The following approaches can be used to workaround this limitation:
100+
101+
* disable dns resolve on the MySQL server (add skip-name-resolve under [mysqld] in my.ini) and use static IPs for your users
102+
* use the exact hostname of your user
103+
* use % to match anything, the user will already be authenticated by MySQL according to its HOST rules
104+
105+
#### Contributing To Choobs MySQL Grants Toolkit
106+
107+
Since this is hosted on github:
108+
109+
**All issues and pull requests should be filed on the [choobs/mysqlgt](http://github.com/choobs/mysqlgt) repository.**
110+
111+
Thank you.
112+
113+
## Authors
114+
115+
* Erik DeLamarter ([email protected])
116+
* Pravin Dahal
117+
118+
## License
119+
120+
The Choobs MySQL Grants Toolkit is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

0 commit comments

Comments
 (0)