James Moger
2015-11-22 ed552ba47c02779c270ffd62841d6d1048dade70
commit | author | age
8c99a7 1 ## Built-in Authentication
JM 2
3 By default, Gitblit stores and authenticates all users against `users.conf`.  However, you may wish to integrate Gitblit into an existing user account infrastructure.
4
5 Gitblit supports additional authentication mechanisms aside from it's internal one.
6
7 * LDAP authentication
8 * Windows authentication
2659e7 9 * PAM authentication
a0c34e 10 * Htpasswd authentication
8c99a7 11 * Redmine auhentication
JM 12 * Salesforce.com authentication
cc0477 13 * Servlet container authentication
8c99a7 14
JM 15 ### LDAP Authentication
16 *SINCE 1.0.0*
17
04a985 18 LDAP can be used to authenticate Users and optionally control Team memberships.  When properly configured, Gitblit will delegate authentication to your LDAP server and will cache some user information in the usual users.conf file.
8c99a7 19
JM 20 When using the LDAP User Service, new user accounts can not be manually created from Gitblit.  Gitblit user accounts are automatically created for new users on their first succesful authentication through Gitblit against the LDAP server.  It is also important to note that the LDAP User Service does not retrieve or store user passwords nor does it implement any LDAP-write functionality.
21
04a985 22 To use the *LdapUserService* set *realm.authenticationProviders=ldap* in your `gitblit.properties` file and then configure the *realm.ldap* settings appropriately for your LDAP environment.
8c99a7 23
JM 24 #### Example LDAP Layout
25 ![block diagram](ldapSample.png "LDAP Sample")
26
27 Please see [ldapUserServiceSampleData.ldif](https://github.com/gitblit/gitblit/blob/master/tests/com/gitblit/tests/resources/ldapUserServiceSampleData.ldif) to see the data in LDAP that reflects the above picture.
28
29 #### Gitblit Settings for Example LDAP Layout
30 The following are the settings required to configure Gitblit to authenticate against the example LDAP server with LDAP-controlled team memberships.
31
32 <table class="table">
33 <thead>
34 <tr><th>parameter</th><th>value</th><th>description</th></tr>
35 </thead>
36 <tbody>
37 <tr>
38   <th>realm.ldap.server</th><td>ldap://localhost:389</td>
39   <td>Tells Gitblit to connect to the LDAP server on localhost port 389.  The URL Must be of form ldap(s)://&lt;server&gt;:&lt;port&gt; with port being optional (389 for ldap, 636 for ldaps).</td>
40 </tr>
41 <tr>
42   <th>realm.ldap.username</th><td>cn=Directory Manager</td>
43   <td>The credentials that will log into the LDAP server</td>
44 </tr>
45 <tr>
46   <th>realm.ldap.password</th><td>password</td>
47   <td>The credentials that will log into the LDAP server</td>
48 </tr>
49 <tr>
50   <th>realm.ldap.maintainTeams</th><td>true</td>
51   <td>Are team memberships maintained in LDAP (<em>true</em>) or manually in Gitblit (<em>false</em>).</td>
52 </tr>
53 <tr>
54   <th>realm.ldap.accountBase</th><td>OU=Users,OU=UserControl,OU=MyOrganization,DC=MyDomain</td>
55   <td>What is the root node for all users in this LDAP system.  Subtree searches will start from this node.</td>
56 </tr>
57 <tr>
58   <th>realm.ldap.accountPattern</th><td>(&(objectClass=person)(sAMAccountName=${username}))</td><td>The LDAP search filter that will match a particular user in LDAP.  ${username} will be replaced with whatever the user enters as their username in the Gitblit login panel.</td>
59 </tr>
60 <tr>
61   <th>realm.ldap.groupBase</th><td>OU=Groups,OU=UserControl,OU=MyOrganization,DC=MyDomain</td>
62   <td>What is the root node for all teams in this LDAP system.  Subtree searches will start from this node.</td>
63 </tr>
64 <tr>
65   <th>realm.ldap.groupMemberPattern</th><td>(&(objectClass=group)(member=${dn}))</td><td>The LDAP search filter that will match all teams for the authenticating user.  ${username} will be replaced with whatever the user enters as their username in the Gitblit login panel.  Anything else in ${} will be replaced by Attributes from the User node.</td>
66 </tr>
67 <tr>
68   <th>realm.ldap.admins</th><td>@Git_Admins</td><td>A space-delimited list of usernames and/or teams that indicate admin status in Gitblit.  Teams are referenced with a leading <em>@</em> character.</td>
69 </tr>
70 </tbody>
71 </table>
72
73 #### LDAP In-Memory Server
74
75 You can start Gitblit GO with an in-memory LDAP server by specifying the *--ldapLdifFile* command-line argument.  The LDAP server will listen on localhost of the port specified in *realm.ldap.url* of `gitblit.properties`.  Additionally, a root user record is automatically created for *realm.ldap.username* and *realm.ldap.password*.  Please note that the ldaps:// protocol is not supported for the in-memory server.
76
77 ### Windows Authentication
78
cc0477 79 Windows authentication is based on the use of Waffle and JNA.  It is known to work properly for authenticating against the local Windows machine, but it is unclear if it works properly with a domain controller and Active Directory.  To use this service, your Gitblit server must be installed on a Windows machine.
JM 80
04a985 81     realm.authenticationProviders = windows
cc0477 82     realm.windows.defaultDomain =
JM 83
2659e7 84 ### PAM Authentication
JM 85
e4c244 86 PAM authentication is based on the use of libpam4j and JNA.  To use this service, your Gitblit server must be installed on a Linux/Unix/MacOSX machine.
2659e7 87
04a985 88     realm.authenticationProviders = pam
e4c244 89     realm.pam.serviceName = gitblit
JM 90     
91 Then define a gitblit authentication policy in `/etc/pam.d/gitblit`
92
93     # PAM configuration for the gitblit service
94     # Standard Un*x authentication.
95     @include common-auth
2659e7 96
a0c34e 97 ### Htpasswd Authentication
FZ 98
99 Htpasswd authentication allows you to maintain your user credentials in an Apache htpasswd file thay may be shared with other htpasswd-capable servers.
100
04a985 101     realm.authenticationProviders = htpasswd
a0c34e 102     realm.htpasswd.userFile = /path/to/htpasswd
FZ 103
8c99a7 104 ### Redmine Authentication
cc0477 105
JM 106 You may authenticate your users against a Redmine installation as long as your Redmine install has properly enabled [API authentication](http://www.redmine.org/projects/redmine/wiki/Rest_Api#Authentication).  This user service only supports user authentication; it does not support team creation based on Redmine groups.  Redmine administrators will also be Gitblit administrators.
107
04a985 108     realm.authenticationProviders = redmine
cc0477 109     realm.redmine.url = http://example.com/redmine
8c99a7 110
JM 111 ### Salesforce.com Authentication
112
cc0477 113 You may authenticate your users against Salesforce.com.  You can require that user's belong to a particular organization by specifying a non-zero organization id.
JM 114
04a985 115     realm.authenticationProviders = salesforce
cc0477 116     realm.salesforce.orgId = 0
JM 117
118 ### Container Authentication
119
120 If you are using the WAR variant and deploying into your own servlet container which has a pre-defined authentication mechanism protecting the Gitblit webapp, then you may instruct Gitblit to automatically create Gitblit accounts for container-authenticated user principals.
121
122     realm.container.autoCreateAccounts = true
123
8c99a7 124 ## Custom Authentication
cc0477 125
8c99a7 126 This is the simplest choice where you implement custom authentication and delegate all other standard user and team operations to one of Gitblit's user service implementations.  This choice insulates your customization from changes in User and Team model classes and additional API that may be added to IUserService.
JM 127
bdcb8d 128 Please subclass [com.gitblit.auth.AuthenticationProvider.UsernamePasswordAuthenticationProvider](https://github.com/gitblit/gitblit/blob/master/src/main/java/com/gitblit/auth/AuthenticationProvider.java).
8c99a7 129
04a985 130 You may use your subclass by specifying its fully qualified classname in the *realm.authenticationProviders* setting.
8c99a7 131
JM 132 Your subclass must be on Gitblit's classpath and must have a public default constructor.  
133
134 ### Custom Everything
cc0477 135
JM 136 Instead of maintaining a `users.conf` file, you may want to integrate Gitblit into an existing environment.
8c99a7 137
JM 138 You may use your own custom *com.gitblit.IUserService* implementation by specifying its fully qualified classname in the *realm.userService* setting.
139
140 Your user service class must be on Gitblit's classpath and must have a public default constructor.  
cc0477 141 Please see the following interface definition [com.gitblit.IUserService](https://github.com/gitblit/gitblit/blob/master/src/main/java/com/gitblit/IUserService.java).
8c99a7 142