Skip to content

Commit 6562fe7

Browse files
committed
Looks like a user rake WILL need to be part of this tool, because Gitlab has no built-in way of doing that essential task.
1 parent 2590146 commit 6562fe7

File tree

3 files changed

+238
-85
lines changed

3 files changed

+238
-85
lines changed

README.md

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# LDAP group sync script for Gitlab-CE
22

3-
This nifty little PHP-CLI tool will synchronise user groups from an LDAP server to Gitlab community edition instance(s).
3+
This nifty little PHP-CLI tool will synchronise users and user groups from an LDAP server to Gitlab community edition instance(s).
44

55
Though this functionality is available out of the box with Gitlab enterprise edition the pricing model is completely infeasible for teams of hobbyists working on non-revenue based projects but need to use a centralised authentication base.
66

7-
This tool is not designed to sync the users themselves into Gitlab as Gitlab-CE can already authenticate fully against an LDAP instance. It is only designed to sync user group memberships, which is typically only available in Gitlab-EE.
7+
As a bonus it can also do a light rake of LDAP users not currently in Gitlab, so those that haven't signed in for their first time can still have projects and permissions assigned to them. **This may make the tool unsuitable git Gitlab-EE as this would certainly impact its licensing fees!**
88

99
## Getting Started
1010

@@ -18,7 +18,7 @@ Requirements for running this tool from a management station:
1818
* [PHP](https://www.php.net) version 7.0 or later: Available to most Linux distributions via `apt-get` or `yum`. You don't need anything web related, but you will need the command line interface.
1919
* [Composer](https://getcomposer.org/): Available to most Linux distributions via `apt-get` or `yum`, or manually download it as `composer.phar` alongside this tool.
2020
* LDAP instance: Used for Gitlab's authentication. It can (likely) be Microsoft Active Directory, OpenLDAP, 389-DS (including FreeIPA), and likely any other LDAP system, though **most of my testing is using a 389-DS instance**.
21-
* [Gitlab community edition](https://gitlab.com/gitlab-org/gitlab-ce/): This must be configured to authenticate against an LDAP instance.
21+
* [Gitlab community edition](https://gitlab.com/gitlab-org/gitlab-ce/): This must be configured to authenticate against an LDAP instance already.
2222

2323
## Installing
2424

@@ -67,7 +67,7 @@ Leaving this null will assume version 3.
6767

6868
The encryption protocol.
6969

70-
* "none" for unencrypted connections, usually port 389. (Generally only safe to use with "localhost".)
70+
* "none" for unencrypted connections, usually port 389. (Generally only safe to use with "localhost" or a very tightly controlled link between this tool and the LDAP server.)
7171
* "tls" for **explicit** SSL/TLS connections, usually on port 389. (Often called "STARTTLS".)
7272
* "ssl" for **implicit** SSL/TLS connections, usually on port 636. (Often called "LDAPS".)
7373

@@ -176,6 +176,16 @@ This section configures how to communicate with your Gitlab-CE instance.
176176

177177
#### options
178178

179+
##### userRake *(bool|null)*
180+
181+
Specify whether LDAP users should be raked into Gitlab. This means that LDAP users of which have not signed in for the first time will now have a minimal user record created for them on Gitlab in advance, which allows you to assign them projects and permissions, and of course put them into their respective groups in advance.
182+
183+
This could result in a large number of user records being created on Gitlab of which may never sign in.
184+
185+
**Do not enable this option if you so happen to have the enterprise edition of Gitlab as it can impact the licensing fees you need to pay.**
186+
187+
Default: *true*
188+
179189
##### createEmptyGroups *(bool|null)*
180190

181191
Specify whether groups containing no LDAP users should still be created in Gitlab.
@@ -265,7 +275,7 @@ Make up an instance name. For example if you had multiple Gitlab installations o
265275

266276
###### url *(string)*
267277

268-
Specify the full HTTP/HTTPS URL to this Gitlab instance, e.g. "https://athena.gitlab.example.com". This is the same URL you use to really visit this Gitlab installation from your web browser.
278+
Specify the full HTTP/HTTPS URL to this Gitlab instance, e.g. "https://athena.gitlab.example.com" or "https://demeter.gitlab.example.com". This is the same URL you use to really visit this Gitlab installation from your web browser.
269279

270280
###### token *(string)*
271281

@@ -279,21 +289,22 @@ Specify the LDAP server name used by this Gitlab instance. You can find this in
279289

280290
Once you've configured this tool you can run it from a CLI using:
281291

282-
`php bin/console ldap:groups:sync -d`
292+
`php bin/console ldap:sync -d`
283293

284294
Depending on your system's PHP installation you may need to use `php-cli` instead of `php`. (This typically only occurs on WHM/cPanel based servers configured to host PHP via the fast process manager, PHP-FPM.)
285295

286-
The `-d` option is important for your first run. This enables "dry run" mode, meaning no changes will be persisted to your Gitlab instances. After running this tool you should evaluate the changes that will be made based on the output, then run it again without the `-d` option to persist the changes.
296+
**The `-d` option is important for your first run.** This enables "dry run" mode, meaning no changes will be persisted to your Gitlab instances. After running this tool you should evaluate the changes that will be made based on the output, then run it again without the `-d` option to persist the changes.
287297

288298
If you'd like to see more verbose output you can add up to 3 `-v` switches, for example:
289299

290-
`php bin/console ldap:groups:sync -v`
291-
`php bin/console ldap:groups:sync -vv`
292-
`php bin/console ldap:groups:sync -vvv`
300+
`php bin/console ldap:sync -v`
301+
`php bin/console ldap:sync -vv`
302+
`php bin/console ldap:sync -vvv`
293303

294304
If you'd like to only sync with a single Gitlab instance you can specify the name of it as per your configuration as an argument, for example:
295305

296-
`php bin/console ldap:groups:sync -d athena`
306+
`php bin/console ldap:sync athena`
307+
`php bin/console ldap:sync demeter`
297308

298309
## Built With
299310

config.yml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ gitlab:
3131
debug: false
3232

3333
options:
34+
userRake: true
3435
createEmptyGroups: false
3536
deleteExtraGroups: false
3637

0 commit comments

Comments
 (0)