You are currently viewing How To Add Members In Group And Projects In GitLab Using API

How To Add Members In Group And Projects In GitLab Using API

How To Add Members In Group And Projects In GitLab Using API

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed how to create groups and subgroups in GitLab.

https://cloudaffaire.com/how-to-create-a-group-and-subgroup-in-gitlab-using-api/

In this blog post, we will discuss how to add members in group and projects in GitLab. The demo is created using API as we are taking a programmatic approach to cover most of the demo. But we have also provided the console steps as well so that if you want to perform the demo from GitLab console, you can do the same.

What Is GitLab User?

Each GitLab account has a user profile, and settings. Your profile contains information about you, and your GitLab activity. Your settings allow you to customize some aspects of GitLab to suit yourself. As a GitLab user you’ll have access to all the features your subscription includes. Users have different abilities depending on the access level they have in a particular group or project. If a user is both in a project’s group and the project itself, the highest permission level is used. A user’s permission is defined by the role user is assigned to.

What Is GitLab Role?

A role is the permission boundary a user can have in GitLab. Below is the list of inbuilt role’s available in GitLab.

  • Administrator: Provides GitLab instance level admin privileges to a user. Administrator is the highest privilege a user can have in GitLab. GitLab administrator is not available in GitLab.com user accounts and is only available if you have installed and configured your own GitLab server.
  • Owner: Provides GitLab group level highest privilege to a user. Every group in GitLab has at least one owner assigned to it and the owner can control all behaviour within that group, subgroups and projects inside that group.
  • Maintainer: Provides GitLab project level highest privilege to a user. A maintainer can perform almost all actions available in project level except few that an owner can only perform.
  • Developer: Provides less permission than maintainer but more permissions than reporter.
  • Reporter: Provides less permission than developer role.
  • Guest: Least privilege a user can have in GitLab.

Below table summarize the current access level for all roles.

Action Guest Reporter Developer Maintainer Owner* Administartor
Download project ✓ (1)
Leave comments ✓ (1)
View Insights charts
View approved/blacklisted licenses ✓ (1)
View License Compliance reports ✓ (1)
View Security reports ✓ (3)
View Dependency list ✓ (1)
View License list ✓ (1)
View licenses in Dependency list ✓ (1)
View Design Management pages
View project code ✓ (1)
Pull project code ✓ (1)
View GitLab Pages protected by access control
View wiki pages
See a list of jobs ✓ (3)
See a job log ✓ (3)
Download and browse job artifacts ✓ (3)
Create new issue ✓ (1)
See related issues
Create confidential issue ✓ (1)
View confidential issues ✓ (2)
Assign issues  
Label issues  
Set issue weight  
Lock issue threads  
Manage issue tracker  
Manage related issues  
Manage labels  
Create code snippets  
See a commit status  
See a container registry  
See environments  
See a list of merge requests  
View project statistics  
View Error Tracking list  
Pull from Conan repository, Maven repository, or NPM registry  
Publish to Conan repository, Maven repository, or NPM registry    
Upload Design Management files    
Create new branches    
Push to non-protected branches    
Force push to non-protected branches    
Remove non-protected branches    
Create new merge request  
Assign merge requests    
Label merge requests    
Lock merge request threads    
Manage/Accept merge requests    
Create new environments    
Stop environments    
Enable Review Apps    
Add tags    
Cancel and retry jobs    
Create or update commit status     ✓ (5)
Update a container registry    
Remove a container registry image    
Create/edit/delete project milestones    
Use security dashboard    
View vulnerabilities in Dependency list    
Create issue from vulnerability    
Dismiss vulnerability    
Apply code change suggestions    
Create and edit wiki pages    
Rewrite/remove Git tags    
Manage Feature Flags    
Use environment terminals      
Run Web IDE’s Interactive Web Terminals      
Add new team members      
Enable/disable branch protection      
Push to protected branches      
Turn on/off protected branch push for devs      
Enable/disable tag protections      
Edit project      
Add deploy keys to project      
Configure project hooks      
Manage Runners      
Manage job triggers      
Manage CI/CD variables      
Manage GitLab Pages      
Manage GitLab Pages domains and certificates      
Remove GitLab Pages      
Manage clusters      
View Pods logs      
Manage license policy      
Edit comments (posted by any user)      
Manage Error Tracking      
Delete wiki pages      
View project Audit Events      
Manage push rules      
Switch visibility level        
Transfer project to another namespace        
Remove project        
Delete issues        
Disable notification emails        
Force push to protected branches (4)          
Remove protected branches (4)          
Administer GitLab Instance          

* Owner permission is only available at the group or personal namespace level (and for instance admins) and is inherited by its projects.

  1. Guest users are able to perform this action on public and internal projects, but not private projects.
  2. Guest users can only view the confidential issues they created themselves.
  3. If Public pipelines are enabled in Project Settings > CI/CD.
  4. Not allowed for Guest, Reporter, Developer, Maintainer, or Owner. See Protected Branches.
  5. If the branch is protected, this depends on the access Developers and Maintainers are given.

Note: Admin privileges for GitLab.com are restricted to the GitLab team and are not covered in this demo.

How To Add Members In Group And Projects In GitLab Using API:

Step 1: Get 2nd user’s user_id.

Step 2: Add 2nd user to 1st user’s group and sub-group as a member.

Step 3: Remove 2nd user’s membership in 1st user’s group and sub-group.

Step 4: Add 2nd user to 1st user’s project as a member.

Step 5: Edit the 2nd user’s membership in 1st user’s project.

Step 6: Cleanup.

Hope you enjoyed this article. In the next blog post, we will discuss CI/CD in GitLab.

To get more details on GitLab you can follow the below link.

https://docs.gitlab.com/ee/README.html

To Get more details on Git you can follow the below links.

https://cloudaffaire.com/category/devops/git/

https://git-scm.com/doc

 

Leave a Reply