You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

authentication.en-us.md 11 kB

Add single sign-on support via SSPI on Windows (#8463) * Add single sign-on support via SSPI on Windows * Ensure plugins implement interface * Ensure plugins implement interface * Move functions used only by the SSPI auth method to sspi_windows.go * Field SSPISeparatorReplacement of AuthenticationForm should not be required via binding, as binding will insist the field is non-empty even if another login type is selected * Fix breaking of oauth authentication on download links. Do not create new session with SSPI authentication on download links. * Update documentation for the new 'SPNEGO with SSPI' login source * Mention in documentation that ROOT_URL should contain the FQDN of the server * Make sure that Contexter is not checking for active login sources when the ORM engine is not initialized (eg. when installing) * Always initialize and free SSO methods, even if they are not enabled, as a method can be activated while the app is running (from Authentication sources) * Add option in SSPIConfig for removing of domains from logon names * Update helper text for StripDomainNames option * Make sure handleSignIn() is called after a new user object is created by SSPI auth method * Remove default value from text of form field helper Co-Authored-By: Lauris BH <lauris@nix.lv> * Remove default value from text of form field helper Co-Authored-By: Lauris BH <lauris@nix.lv> * Remove default value from text of form field helper Co-Authored-By: Lauris BH <lauris@nix.lv> * Only make a query to the DB to check if SSPI is enabled on handlers that need that information for templates * Remove code duplication * Log errors in ActiveLoginSources Co-Authored-By: Lauris BH <lauris@nix.lv> * Revert suffix of randomly generated E-mails for Reverse proxy authentication Co-Authored-By: Lauris BH <lauris@nix.lv> * Revert unneeded white-space change in template Co-Authored-By: Lauris BH <lauris@nix.lv> * Add copyright comments at the top of new files * Use loopback name for randomly generated emails * Add locale tag for the SSPISeparatorReplacement field with proper casing * Revert casing of SSPISeparatorReplacement field in locale file, moving it up, next to other form fields * Update docs/content/doc/features/authentication.en-us.md Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Remove Priority() method and define the order in which SSO auth methods should be executed in one place * Log authenticated username only if it's not empty * Rephrase helper text for automatic creation of users * Return error if more than one active SSPI auth source is found * Change newUser() function to return error, letting caller log/handle the error * Move isPublicResource, isPublicPage and handleSignIn functions outside SSPI auth method to allow other SSO methods to reuse them if needed * Refactor initialization of the list containing SSO auth methods * Validate SSPI settings on POST * Change SSPI to only perform authentication on its own login page, API paths and download links. Leave Toggle middleware to redirect non authenticated users to login page * Make 'Default language' in SSPI config empty, unless changed by admin * Show error if admin tries to add a second authentication source of type SSPI * Simplify declaration of global variable * Rebuild gitgraph.js on Linux * Make sure config values containing only whitespace are not accepted
5 years ago
Add single sign-on support via SSPI on Windows (#8463) * Add single sign-on support via SSPI on Windows * Ensure plugins implement interface * Ensure plugins implement interface * Move functions used only by the SSPI auth method to sspi_windows.go * Field SSPISeparatorReplacement of AuthenticationForm should not be required via binding, as binding will insist the field is non-empty even if another login type is selected * Fix breaking of oauth authentication on download links. Do not create new session with SSPI authentication on download links. * Update documentation for the new 'SPNEGO with SSPI' login source * Mention in documentation that ROOT_URL should contain the FQDN of the server * Make sure that Contexter is not checking for active login sources when the ORM engine is not initialized (eg. when installing) * Always initialize and free SSO methods, even if they are not enabled, as a method can be activated while the app is running (from Authentication sources) * Add option in SSPIConfig for removing of domains from logon names * Update helper text for StripDomainNames option * Make sure handleSignIn() is called after a new user object is created by SSPI auth method * Remove default value from text of form field helper Co-Authored-By: Lauris BH <lauris@nix.lv> * Remove default value from text of form field helper Co-Authored-By: Lauris BH <lauris@nix.lv> * Remove default value from text of form field helper Co-Authored-By: Lauris BH <lauris@nix.lv> * Only make a query to the DB to check if SSPI is enabled on handlers that need that information for templates * Remove code duplication * Log errors in ActiveLoginSources Co-Authored-By: Lauris BH <lauris@nix.lv> * Revert suffix of randomly generated E-mails for Reverse proxy authentication Co-Authored-By: Lauris BH <lauris@nix.lv> * Revert unneeded white-space change in template Co-Authored-By: Lauris BH <lauris@nix.lv> * Add copyright comments at the top of new files * Use loopback name for randomly generated emails * Add locale tag for the SSPISeparatorReplacement field with proper casing * Revert casing of SSPISeparatorReplacement field in locale file, moving it up, next to other form fields * Update docs/content/doc/features/authentication.en-us.md Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Remove Priority() method and define the order in which SSO auth methods should be executed in one place * Log authenticated username only if it's not empty * Rephrase helper text for automatic creation of users * Return error if more than one active SSPI auth source is found * Change newUser() function to return error, letting caller log/handle the error * Move isPublicResource, isPublicPage and handleSignIn functions outside SSPI auth method to allow other SSO methods to reuse them if needed * Refactor initialization of the list containing SSO auth methods * Validate SSPI settings on POST * Change SSPI to only perform authentication on its own login page, API paths and download links. Leave Toggle middleware to redirect non authenticated users to login page * Make 'Default language' in SSPI config empty, unless changed by admin * Show error if admin tries to add a second authentication source of type SSPI * Simplify declaration of global variable * Rebuild gitgraph.js on Linux * Make sure config values containing only whitespace are not accepted
5 years ago
Add single sign-on support via SSPI on Windows (#8463) * Add single sign-on support via SSPI on Windows * Ensure plugins implement interface * Ensure plugins implement interface * Move functions used only by the SSPI auth method to sspi_windows.go * Field SSPISeparatorReplacement of AuthenticationForm should not be required via binding, as binding will insist the field is non-empty even if another login type is selected * Fix breaking of oauth authentication on download links. Do not create new session with SSPI authentication on download links. * Update documentation for the new 'SPNEGO with SSPI' login source * Mention in documentation that ROOT_URL should contain the FQDN of the server * Make sure that Contexter is not checking for active login sources when the ORM engine is not initialized (eg. when installing) * Always initialize and free SSO methods, even if they are not enabled, as a method can be activated while the app is running (from Authentication sources) * Add option in SSPIConfig for removing of domains from logon names * Update helper text for StripDomainNames option * Make sure handleSignIn() is called after a new user object is created by SSPI auth method * Remove default value from text of form field helper Co-Authored-By: Lauris BH <lauris@nix.lv> * Remove default value from text of form field helper Co-Authored-By: Lauris BH <lauris@nix.lv> * Remove default value from text of form field helper Co-Authored-By: Lauris BH <lauris@nix.lv> * Only make a query to the DB to check if SSPI is enabled on handlers that need that information for templates * Remove code duplication * Log errors in ActiveLoginSources Co-Authored-By: Lauris BH <lauris@nix.lv> * Revert suffix of randomly generated E-mails for Reverse proxy authentication Co-Authored-By: Lauris BH <lauris@nix.lv> * Revert unneeded white-space change in template Co-Authored-By: Lauris BH <lauris@nix.lv> * Add copyright comments at the top of new files * Use loopback name for randomly generated emails * Add locale tag for the SSPISeparatorReplacement field with proper casing * Revert casing of SSPISeparatorReplacement field in locale file, moving it up, next to other form fields * Update docs/content/doc/features/authentication.en-us.md Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Remove Priority() method and define the order in which SSO auth methods should be executed in one place * Log authenticated username only if it's not empty * Rephrase helper text for automatic creation of users * Return error if more than one active SSPI auth source is found * Change newUser() function to return error, letting caller log/handle the error * Move isPublicResource, isPublicPage and handleSignIn functions outside SSPI auth method to allow other SSO methods to reuse them if needed * Refactor initialization of the list containing SSO auth methods * Validate SSPI settings on POST * Change SSPI to only perform authentication on its own login page, API paths and download links. Leave Toggle middleware to redirect non authenticated users to login page * Make 'Default language' in SSPI config empty, unless changed by admin * Show error if admin tries to add a second authentication source of type SSPI * Simplify declaration of global variable * Rebuild gitgraph.js on Linux * Make sure config values containing only whitespace are not accepted
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. ---
  2. date: "2016-12-01T16:00:00+02:00"
  3. title: "Authentication"
  4. slug: "authentication"
  5. weight: 10
  6. toc: true
  7. draft: false
  8. menu:
  9. sidebar:
  10. parent: "features"
  11. name: "Authentication"
  12. weight: 10
  13. identifier: "authentication"
  14. ---
  15. # Authentication
  16. ## LDAP (Lightweight Directory Access Protocol)
  17. Both the LDAP via BindDN and the simple auth LDAP share the following fields:
  18. - Authorization Name **(required)**
  19. - A name to assign to the new method of authorization.
  20. - Host **(required)**
  21. - The address where the LDAP server can be reached.
  22. - Example: `mydomain.com`
  23. - Port **(required)**
  24. - The port to use when connecting to the server.
  25. - Example: `389` for LDAP or `636` for LDAP SSL
  26. - Enable TLS Encryption (optional)
  27. - Whether to use TLS when connecting to the LDAP server.
  28. - Admin Filter (optional)
  29. - An LDAP filter specifying if a user should be given administrator
  30. privileges. If a user account passes the filter, the user will be
  31. privileged as an administrator.
  32. - Example: `(objectClass=adminAccount)`
  33. - Example for Microsoft Active Directory (AD): `(memberOf=CN=admin-group,OU=example,DC=example,DC=org)`
  34. - Username attribute (optional)
  35. - The attribute of the user's LDAP record containing the user name. Given
  36. attribute value will be used for new Gitea account user name after first
  37. successful sign-in. Leave empty to use login name given on sign-in form.
  38. - This is useful when supplied login name is matched against multiple
  39. attributes, but only single specific attribute should be used for Gitea
  40. account name, see "User Filter".
  41. - Example: `uid`
  42. - Example for Microsoft Active Directory (AD): `sAMAccountName`
  43. - First name attribute (optional)
  44. - The attribute of the user's LDAP record containing the user's first name.
  45. This will be used to populate their account information.
  46. - Example: `givenName`
  47. - Surname attribute (optional)
  48. - The attribute of the user's LDAP record containing the user's surname.
  49. This will be used to populate their account information.
  50. - Example: `sn`
  51. - E-mail attribute **(required)**
  52. - The attribute of the user's LDAP record containing the user's email
  53. address. This will be used to populate their account information.
  54. - Example: `mail`
  55. **LDAP via BindDN** adds the following fields:
  56. - Bind DN (optional)
  57. - The DN to bind to the LDAP server with when searching for the user. This
  58. may be left blank to perform an anonymous search.
  59. - Example: `cn=Search,dc=mydomain,dc=com`
  60. - Bind Password (optional)
  61. - The password for the Bind DN specified above, if any. _Note: The password
  62. is stored in plaintext at the server. As such, ensure that the Bind DN
  63. has as few privileges as possible._
  64. - User Search Base **(required)**
  65. - The LDAP base at which user accounts will be searched for.
  66. - Example: `ou=Users,dc=mydomain,dc=com`
  67. - User Filter **(required)**
  68. - An LDAP filter declaring how to find the user record that is attempting to
  69. authenticate. The `%s` matching parameter will be substituted with login
  70. name given on sign-in form.
  71. - Example: `(&(objectClass=posixAccount)(uid=%s))`
  72. - Example for Microsoft Active Directory (AD): `(&(objectCategory=Person)(memberOf=CN=user-group,OU=example,DC=example,DC=org)(sAMAccountName=%s)(!(UserAccountControl:1.2.840.113556.1.4.803:=2)))`
  73. - To substitute more than once, `%[1]s` should be used instead, e.g. when
  74. matching supplied login name against multiple attributes such as user
  75. identifier, email or even phone number.
  76. - Example: `(&(objectClass=Person)(|(uid=%[1]s)(mail=%[1]s)(mobile=%[1]s)))`
  77. - Enable user synchronization
  78. - This option enables a periodic task that synchronizes the Gitea users with
  79. the LDAP server. The default period is every 24 hours but that can be
  80. changed in the app.ini file. See the *cron.sync_external_users* section in
  81. the [sample
  82. app.ini](https://github.com/go-gitea/gitea/blob/master/custom/conf/app.ini.sample)
  83. for detailed comments about that section. The *User Search Base* and *User
  84. Filter* settings described above will limit which users can use Gitea and
  85. which users will be synchronized. When initially run the task will create
  86. all LDAP users that match the given settings so take care if working with
  87. large Enterprise LDAP directories.
  88. **LDAP using simple auth** adds the following fields:
  89. - User DN **(required)**
  90. - A template to use as the user's DN. The `%s` matching parameter will be
  91. substituted with login name given on sign-in form.
  92. - Example: `cn=%s,ou=Users,dc=mydomain,dc=com`
  93. - Example: `uid=%s,ou=Users,dc=mydomain,dc=com`
  94. - User Search Base (optional)
  95. - The LDAP base at which user accounts will be searched for.
  96. - Example: `ou=Users,dc=mydomain,dc=com`
  97. - User Filter **(required)**
  98. - An LDAP filter declaring when a user should be allowed to log in. The `%s`
  99. matching parameter will be substituted with login name given on sign-in
  100. form.
  101. - Example: `(&(objectClass=posixAccount)(cn=%s))`
  102. - Example: `(&(objectClass=posixAccount)(uid=%s))`
  103. **Verify group membership in LDAP** uses the following fields:
  104. * Group Search Base (optional)
  105. * The LDAP DN used for groups.
  106. * Example: `ou=group,dc=mydomain,dc=com`
  107. * Group Name Filter (optional)
  108. * An LDAP filter declaring how to find valid groups in the above DN.
  109. * Example: `(|(cn=gitea_users)(cn=admins))`
  110. * User Attribute in Group (optional)
  111. * Which user LDAP attribute is listed in the group.
  112. * Example: `uid`
  113. * Group Attribute for User (optional)
  114. * Which group LDAP attribute contains an array above user attribute names.
  115. * Example: `memberUid`
  116. ## PAM (Pluggable Authentication Module)
  117. To configure PAM, set the 'PAM Service Name' to a filename in `/etc/pam.d/`. To
  118. work with normal Linux passwords, the user running Gitea must have read access
  119. to `/etc/shadow`.
  120. ## SMTP (Simple Mail Transfer Protocol)
  121. This option allows Gitea to log in to an SMTP host as a Gitea user. To
  122. configure this, set the fields below:
  123. - Authentication Name **(required)**
  124. - A name to assign to the new method of authorization.
  125. - SMTP Authentication Type **(required)**
  126. - Type of authentication to use to connect to SMTP host, PLAIN or LOGIN.
  127. - Host **(required)**
  128. - The address where the SMTP host can be reached.
  129. - Example: `smtp.mydomain.com`
  130. - Port **(required)**
  131. - The port to use when connecting to the server.
  132. - Example: `587`
  133. - Allowed Domains
  134. - Restrict what domains can log in if using a public SMTP host or SMTP host
  135. with multiple domains.
  136. - Example: `gitea.io,mydomain.com,mydomain2.com`
  137. - Enable TLS Encryption
  138. - Enable TLS encryption on authentication.
  139. - Skip TLS Verify
  140. - Disable TLS verify on authentication.
  141. - This authentication is activate
  142. - Enable or disable this auth.
  143. ## FreeIPA
  144. - In order to log in to Gitea using FreeIPA credentials, a bind account needs to
  145. be created for Gitea:
  146. - On the FreeIPA server, create a `gitea.ldif` file, replacing `dc=example,dc=com`
  147. with your DN, and provide an appropriately secure password:
  148. ```
  149. dn: uid=gitea,cn=sysaccounts,cn=etc,dc=example,dc=com
  150. changetype: add
  151. objectclass: account
  152. objectclass: simplesecurityobject
  153. uid: gitea
  154. userPassword: secure password
  155. passwordExpirationTime: 20380119031407Z
  156. nsIdleTimeout: 0
  157. ```
  158. - Import the LDIF (change localhost to an IPA server if needed). A prompt for
  159. Directory Manager password will be presented:
  160. ```
  161. ldapmodify -h localhost -p 389 -x -D \
  162. "cn=Directory Manager" -W -f gitea.ldif
  163. ```
  164. - Add an IPA group for gitea\_users :
  165. ```
  166. ipa group-add --desc="Gitea Users" gitea_users
  167. ```
  168. - Note: For errors about IPA credentials, run `kinit admin` and provide the
  169. domain admin account password.
  170. - Log in to Gitea as an Administrator and click on "Authentication" under Admin Panel.
  171. Then click `Add New Source` and fill in the details, changing all where appropriate.
  172. ## SPNEGO with SSPI (Kerberos/NTLM, for Windows only)
  173. Gitea supports SPNEGO single sign-on authentication (the scheme defined by RFC4559) for the web part of the server via the Security Support Provider Interface (SSPI) built in Windows. SSPI works only in Windows environments - when both the server and the clients are running Windows.
  174. Before activating SSPI single sign-on authentication (SSO) you have to prepare your environment:
  175. - Create a separate user account in active directory, under which the `gitea.exe` process will be running (eg. `user` under domain `domain.local`):
  176. - Create a service principal name for the host where `gitea.exe` is running with class `HTTP`:
  177. - Start `Command Prompt` or `PowerShell` as a priviledged domain user (eg. Domain Administrator)
  178. - Run the command below, replacing `host.domain.local` with the fully qualified domain name (FQDN) of the server where the web application will be running, and `domain\user` with the name of the account created in the previous step:
  179. ```
  180. setspn -A HTTP/host.domain.local domain\user
  181. ```
  182. - Sign in (*sign out if you were already signed in*) with the user created
  183. - Make sure that `ROOT_URL` in the `[server]` section of `custom/conf/app.ini` is the fully qualified domain name of the server where the web application will be running - the same you used when creating the service principal name (eg. `host.domain.local`)
  184. - Start the web server (`gitea.exe web`)
  185. - Enable SSPI authentication by adding an `SPNEGO with SSPI` authentication source in `Site Administration -> Authentication Sources`
  186. - Sign in to a client computer in the same domain with any domain user (client computer, different from the server running `gitea.exe`)
  187. - If you are using Chrome or Edge, add the URL of the web app to the Local intranet sites (`Internet Options -> Security -> Local intranet -> Sites`)
  188. - Start Chrome or Edge and navigate to the FQDN URL of gitea (eg. `http://host.domain.local:3000`)
  189. - Click the `Sign In` button on the dashboard and choose SSPI to be automatically logged in with the same user that is currently logged on to the computer
  190. - If it does not work, make sure that:
  191. - You are not running the web browser on the same server where gitea is running. You should be running the web browser on a domain joined computer (client) that is different from the server. If both the client and server are runnning on the same computer NTLM will be prefered over Kerberos.
  192. - There is only one `HTTP/...` SPN for the host
  193. - The SPN contains only the hostname, without the port
  194. - You have added the URL of the web app to the `Local intranet zone`
  195. - The clocks of the server and client should not differ with more than 5 minutes (depends on group policy)
  196. - `Integrated Windows Authentication` should be enabled in Internet Explorer (under `Advanced settings`)