The included scripts provide an example of using the Gitlab and GitGuardian APIs to map Gitlab groups and the repositories they own to GitGuardian Teams and their perimeters.
Caution
This is example code that can be used as a starting point for your own solution. While we're happy to answer questions about it it is not a supported part of the product.
The easiest method of installation is to use Python virtual environment (venv):
unzip team-mapping-gitlab-gitguardian.zip
cd team-mapping-gitlab-gitguardian
python3 -mvenv .venv
source .venv/bin/activate
pip install -r requirements.txt
Three environment variables must be set to configure the connection:
GITLAB_URL
- The base URL for your Gitlab instance.GITLAB_ACCESS_TOKEN
- A Gitlab PAT withread_api
andread_user
permissions.GITGUARDIAN_API_KEY
- A GitGuardian API Service Account Token withmembers:read
,members:write
,teams:read
,teams:write
,sources:read
andsources:write
permissions.
Tip
If a Personal Access Token is used, the user who owns the PAT will be added to all teams when they're created. SATs are preferred for this reason.
Optional environment variables:
GITGUARDIAN_INSTANCE
- The URL of a self-hosted GitGuardian instance. Just the scheme and hostname: https://gitguardian.example.comSEND_EMAIL
- Defines whether we should send an email to users when sending invitationsREMOVE_MEMBERS
- Defines whether we should delete users from teams if they are not in any Gitlab groupEXCLUDE_ADMIN
- Defines whether we should exclude admin users from syncDEFAULT_INCIDENT_PERMISSION
- Defines the default incident permission level for team members, defaults tocan_edit
, it's value must be one of :can_view
: For read permissionscan_edit
: For read and write permissionsfull_access
: For manager permissions
In order to ensure you have the correct configuration, you can run the following command to display the configuration:
python config.py
Teams in GitGuardian will be created based on the full path of the group of every user's group.
This means that if a user is in top-group / middle-group / bottom-group
, he will be added to the team top-group / middle-group / bottom-group
in GitGuardian.
Upon invocation, the script will sync teams and their perimeters from Gitlab to GitGuardian. It can be invoked like this:
python sync_gitlab.py