@@ -369,6 +369,12 @@ private function validateConfig(array &$config, array &$problems = null): bool
369
369
$ addProblem ("error " , "ldap->queries->userEmailAttribute not specified. " );
370
370
}
371
371
372
+ if (!isset ($ config ["ldap " ]["queries " ]["userSshKeyAttribute " ])) {
373
+ $ addProblem ("warning " , "ldap->queries->userSshKeyAttribute missing. " );
374
+ } else if (!$ config ["ldap " ]["queries " ]["userSshKeyAttribute " ] = trim ($ config ["ldap " ]["queries " ]["userSshKeyAttribute " ])) {
375
+ $ addProblem ("warning " , "ldap->queries->userSshKeyAttribute not specified. " );
376
+ }
377
+
372
378
if (!isset ($ config ["ldap " ]["queries " ]["groupDn " ])) {
373
379
$ addProblem ("error " , "ldap->queries->groupDn missing. " );
374
380
} else if (!$ config ["ldap " ]["queries " ]["groupDn " ] = trim ($ config ["ldap " ]["queries " ]["groupDn " ])) {
@@ -490,6 +496,26 @@ private function validateConfig(array &$config, array &$problems = null): bool
490
496
$ addProblem ("error " , "gitlab->options->newMemberAccessLevel is not an integer. " );
491
497
}
492
498
499
+ if (!isset ($ config ["gitlab " ]["options " ]["sshKeysImportMode " ])) {
500
+ $ addProblem ("warning " , "gitlab->options->sshKeysImportMode missing. (Assuming false.) " );
501
+ $ config ["gitlab " ]["options " ]["sshKeysImportMode " ] = false ;
502
+ } else if (null === $ config ["gitlab " ]["options " ]["sshKeysImportMode " ]) {
503
+ $ addProblem ("warning " , "gitlab->options->sshKeysImportMode not specified. (Assuming false.) " );
504
+ $ config ["gitlab " ]["options " ]["sshKeysImportMode " ] = false ;
505
+ } else if ($ config ["gitlab " ]["options " ]["sshKeysImportMode " ]) {
506
+ $ config ["gitlab " ]["options " ]["sshKeysImportMode " ] = strtolower (trim ($ config ["gitlab " ]["options " ]["sshKeysImportMode " ]));
507
+
508
+ switch ($ config ["gitlab " ]["options " ]["sshKeysImportMode " ]) {
509
+ case "insert " :
510
+ case "merge " :
511
+ case "replace " :
512
+ break ;
513
+
514
+ default :
515
+ $ addProblem ("error " , "gitlab->options->sshKeysImportMode invalid. (Must be \"insert \", \"merge \", or \"replace \".) " );
516
+ }
517
+ }
518
+
493
519
if (!isset ($ config ["gitlab " ]["options " ]["groupNamesOfAdministrators " ])) {
494
520
// $addProblem("warning", "gitlab->options->groupNamesOfAdministrators missing. (Assuming none.)");
495
521
$ config ["gitlab " ]["options " ]["groupNamesOfAdministrators " ] = [];
@@ -635,9 +661,10 @@ private function getLdapUsersAndGroups(array $config, array &$users, int &$users
635
661
if (is_array ($ ldapUsers = @ldap_get_entries ($ ldap , $ ldapUsersQuery ))) {
636
662
if ($ ldapUsersNum = count ($ ldapUsers )) {
637
663
$ this ->logger ->notice (sprintf ("%d directory user(s) found. " , $ ldapUsersNum ));
638
- $ ldapUserAttribute = strtolower ($ config ["ldap " ]["queries " ]["userUniqueAttribute " ]);
639
- $ ldapNameAttribute = strtolower ($ config ["ldap " ]["queries " ]["userNameAttribute " ]);
640
- $ ldapEmailAttribute = strtolower ($ config ["ldap " ]["queries " ]["userEmailAttribute " ]);
664
+ $ ldapUserAttribute = strtolower ($ config ["ldap " ]["queries " ]["userUniqueAttribute " ]);
665
+ $ ldapNameAttribute = strtolower ($ config ["ldap " ]["queries " ]["userNameAttribute " ]);
666
+ $ ldapEmailAttribute = strtolower ($ config ["ldap " ]["queries " ]["userEmailAttribute " ]);
667
+ $ ldapSshKeyAttribute = strtolower ($ config ["ldap " ]["queries " ]["userSshKeyAttribute " ]);
641
668
642
669
foreach ($ ldapUsers as $ i => $ ldapUser ) {
643
670
if (!is_int ($ i )) {
@@ -705,6 +732,19 @@ private function getLdapUsersAndGroups(array $config, array &$users, int &$users
705
732
continue ;
706
733
}
707
734
735
+ $ ldapUserSshKeys = null ;
736
+ if ($ ldapSshKeyAttribute ) {
737
+ $ ldapUserSshKeys = [];
738
+
739
+ if (!isset ($ ldapUser [$ ldapSshKeyAttribute ])) {
740
+ $ this ->logger ->warning (sprintf ("User #%d [%s]: Missing attribute \"%s \". " , $ n , $ ldapUserDn , $ ldapSshKeyAttribute ));
741
+ } elseif (!is_array ($ ldapUser [$ ldapSshKeyAttribute ])) {
742
+ $ this ->logger ->warning (sprintf ("User #%d [%s]: Invalid attribute \"%s \". " , $ n , $ ldapUserDn , $ ldapSshKeyAttribute ));
743
+ } elseif (count ($ ldapUserSshKeys = $ ldapUser [$ ldapSshKeyAttribute ]) < 1 ) {
744
+ $ this ->logger ->warning (sprintf ("User #%d [%s]: Empty attribute \"%s \". " , $ n , $ ldapUserDn , $ ldapSshKeyAttribute ));
745
+ }
746
+ }
747
+
708
748
if ($ this ->in_array_i ($ ldapUserName , $ config ["gitlab " ]["options " ]["userNamesToIgnore " ])) {
709
749
$ this ->logger ->info (sprintf ("User \"%s \" in ignore list. " , $ ldapUserName ));
710
750
continue ;
@@ -721,6 +761,7 @@ private function getLdapUsersAndGroups(array $config, array &$users, int &$users
721
761
"username " => $ ldapUserName ,
722
762
"fullName " => $ ldapUserFullName ,
723
763
"email " => $ ldapUserEmail ,
764
+ "sshKeys " => $ ldapUserSshKeys ,
724
765
"isAdmin " => false ,
725
766
"isExternal " => false ,
726
767
];
0 commit comments