|
2 | 2 | A script to get Grafana users, teams and their permissions from an LDAP server and keep it in sync.
|
3 | 3 |
|
4 | 4 | ## Installation
|
5 |
| -Install all dependencies |
| 5 | +Install all dependencies. |
6 | 6 | ```bash
|
7 | 7 | pip install -r requirements.txt
|
8 | 8 | ```
|
9 | 9 |
|
| 10 | +or consider to install the dependencies only for the user which will be executing the script: |
| 11 | + |
| 12 | +```bash |
| 13 | +$ pip install --user -r requirements.txt |
| 14 | +``` |
| 15 | + |
10 | 16 | ## Running the Script
|
11 |
| -The script can be simply run with: |
| 17 | + |
| 18 | +*The script requires Python 3 to run!* |
| 19 | + |
| 20 | +It can be simply run with: |
12 | 21 | ```bash
|
13 |
| -python run.py [-h] --config *path-to-config.yml* --bind *path-to-bind-csv* [--dry-run] |
| 22 | +$ python run.py [-h] --config <path-to-config.yml> --bind <path-to-bind-csv> [--dry-run] |
14 | 23 | ```
|
15 | 24 |
|
16 | 25 | ## Usage
|
17 | 26 | If you just want to test the script, there is an example.csv predefined. Just enter your grafana credentials in the config.yml.
|
18 | 27 | The used LDAP-Server can be found [here](https://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/).
|
19 | 28 |
|
20 |
| -#### Config |
| 29 | +### Config |
21 | 30 | Before starting the script you need to enter your grafana & ldap credentials in the config.yml. You also need to add the
|
22 | 31 | path to your .csv file containing the bindings.
|
23 | 32 |
|
24 |
| -#### Binding |
| 33 | +### Binding |
25 | 34 | To bind LDAP-groups to grafana-teams and grant these teams access to folders you need to provide a .csv file. Please note
|
26 | 35 | that the first row of the csv is recognized as a header-row and is therefore being ignored.
|
27 | 36 | The file needs to contain the following information in this exact order:
|
28 |
| -<br> |
| 37 | +* **LDAP-Group**: The LDAP group which will be used for mapping. |
| 38 | +* **Grafana-Team Name**: The name of the Grafana team which will be created (if not exist) and where the group's users will be added to. |
| 39 | +* **Grafana-Team ID**: The ID of the Grafana team (currently not used). |
| 40 | +* **Grafana-Folder Name**: The Grafana folder which will be created (if not exist) and where the group's users will have the specified permission to. |
| 41 | +* **Grafana-Folder UUID**: The UUID of the Grafana folder. |
| 42 | +* **Grafana-Folder Permission**: The users' permission for the specified Grafana folder. (`View`, `Edit`, `Admin`) |
| 43 | + |
| 44 | +Missing folders, teams and users will be created by the script. |
| 45 | +Teams and users which are not existing in the LDAP mapping will be removed. Note: the user used by the script will not be deleted! |
| 46 | + |
| 47 | +#### Example CSV |
29 | 48 | ```CSV
|
30 |
| -LDAP-Group, Grafana-Team Name, Grafana-Team ID, Grafana-Folder ID, Grafana-Folder UUID, Grafana-Folder Permission |
| 49 | +ZBV/LDAP-Gruppe,Grafana-Team-Name,Grafana-Team-ID,Grafana-Folder-Name,Grafana-Folder-UUID,Grafana-Folder-Permissions |
| 50 | +mathematicians,mathematicians,0,Math,math_folder,Admin |
| 51 | +mathematicians,smart_people,0,Common Dashboards,all_folder,View |
| 52 | +scientists,scientists,0,Science,science_folder,Edit |
| 53 | +scientists,smart_people,0,Common Dashboards,all_folder,View |
31 | 54 | ```
|
32 |
| -Missing folders, teams and users will be created by the script. |
33 |
| -<br> |
34 |
| -Possible Grafana-Folder permissions are: |
35 |
| -- View |
36 |
| -- Edit |
37 |
| -- Admin |
| 55 | + |
| 56 | +Using this CSV mapping will result in the following operations: |
| 57 | +* The Grafana teams `mathematicians`, `smart_people` and `scientists` will be created. |
| 58 | +* The Grafana folders `Math`, `Common Dashboards` and `Science` will be created. |
| 59 | +* All users in the `mathematicians` LDAP group will be member of the Grafana team `mathematicians` and `smart_people`. |
| 60 | +* All users in the `scientists` LDAP group will be member of the Grafana team `scientists`. |
| 61 | +* All users in the `mathematicians` LDAP group will get `Admin` access to the `Math` folder. |
| 62 | +* All users in the `mathematicians` LDAP group will get `View` access to the `Common Dashboards` folder. |
| 63 | +* All users in the `scientists` LDAP group will get `Edit` access to the `Science` folder. |
| 64 | +* All users in the `scientists` LDAP group will get `View` access to the `Common Dashboards` folder. |
38 | 65 |
|
39 | 66 | #### Removing Bindings
|
40 | 67 | When a binding is removed in your .csv-file, this binding is also removed by the script. So if there is a team in your grafana instance which
|
41 | 68 | is not defined by the current binding the team will be deleted. This also applies to users. **This does not apply to folders!
|
42 |
| -Folders need to be deleted manually if not needed anymore!** |
| 69 | +Folders need to be deleted manually if not needed anymore!** |
| 70 | + |
| 71 | + |
| 72 | +## Bundle Scripts |
| 73 | + |
| 74 | +Using the Makefile, you can bundle all the scripts into a single zip-archive. |
| 75 | + |
| 76 | +``` |
| 77 | +$ make bundle |
| 78 | +``` |
0 commit comments