PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/doc/integration/omniauth.md

https://gitlab.com/certik/gitlab-ce
Markdown | 244 lines | 172 code | 72 blank | 0 comment | 0 complexity | 8bbb2d155de111becaf33fedbcfc8281 MD5 | raw file
  1. # OmniAuth
  2. GitLab leverages OmniAuth to allow users to sign in using Twitter, GitHub, and
  3. other popular services.
  4. Configuring OmniAuth does not prevent standard GitLab authentication or LDAP
  5. (if configured) from continuing to work. Users can choose to sign in using any
  6. of the configured mechanisms.
  7. - [Initial OmniAuth Configuration](#initial-omniauth-configuration)
  8. - [Supported Providers](#supported-providers)
  9. - [Enable OmniAuth for an Existing User](#enable-omniauth-for-an-existing-user)
  10. - [OmniAuth configuration sample when using Omnibus GitLab](https://gitlab.com/gitlab-org/omnibus-gitlab/tree/master#omniauth-google-twitter-github-login)
  11. - [Enable or disable Sign In with an OmniAuth provider without disabling import sources](#enable-or-disable-sign-in-with-an-omniauth-provider-without-disabling-import-sources)
  12. ## Supported Providers
  13. This is a list of the current supported OmniAuth providers. Before proceeding
  14. on each provider's documentation, make sure to first read this document as it
  15. contains some settings that are common for all providers.
  16. - [GitHub](github.md)
  17. - [Bitbucket](bitbucket.md)
  18. - [GitLab.com](gitlab.md)
  19. - [Google](google.md)
  20. - [Facebook](facebook.md)
  21. - [Twitter](twitter.md)
  22. - [Shibboleth](shibboleth.md)
  23. - [SAML](saml.md)
  24. - [Crowd](../administration/auth/crowd.md)
  25. - [Azure](azure.md)
  26. - [Auth0](auth0.md)
  27. - [Authentiq](../administration/auth/authentiq.md)
  28. - [OAuth2Generic](oauth2_generic.md)
  29. ## Initial OmniAuth Configuration
  30. Before configuring individual OmniAuth providers there are a few global settings
  31. that are in common for all providers that we need to consider.
  32. - Omniauth needs to be enabled, see details below for example.
  33. - `allow_single_sign_on` allows you to specify the providers you want to allow to
  34. automatically create an account. It defaults to `false`. If `false` users must
  35. be created manually or they will not be able to sign in via OmniAuth.
  36. - `auto_link_ldap_user` can be used if you have [LDAP / ActiveDirectory](ldap.md)
  37. integration enabled. It defaults to false. When enabled, users automatically
  38. created through OmniAuth will be linked to their LDAP entry as well.
  39. - `block_auto_created_users` defaults to `true`. If `true` auto created users will
  40. be blocked by default and will have to be unblocked by an administrator before
  41. they are able to sign in.
  42. >**Note:**
  43. If you set `block_auto_created_users` to `false`, make sure to only
  44. define providers under `allow_single_sign_on` that you are able to control, like
  45. SAML, Shibboleth, Crowd or Google, or set it to `false` otherwise any user on
  46. the Internet will be able to successfully sign in to your GitLab without
  47. administrative approval.
  48. >**Note:**
  49. `auto_link_ldap_user` requires the `uid` of the user to be the same in both LDAP
  50. and the OmniAuth provider.
  51. To change these settings:
  52. * **For omnibus package**
  53. Open the configuration file:
  54. ```sh
  55. sudo editor /etc/gitlab/gitlab.rb
  56. ```
  57. and change:
  58. ```ruby
  59. gitlab_rails['omniauth_enabled'] = true
  60. # CAUTION!
  61. # This allows users to login without having a user account first. Define the allowed providers
  62. # using an array, e.g. ["saml", "twitter"], or as true/false to allow all providers or none.
  63. # User accounts will be created automatically when authentication was successful.
  64. gitlab_rails['omniauth_allow_single_sign_on'] = ['saml', 'twitter']
  65. gitlab_rails['omniauth_auto_link_ldap_user'] = true
  66. gitlab_rails['omniauth_block_auto_created_users'] = true
  67. ```
  68. * **For installations from source**
  69. Open the configuration file:
  70. ```sh
  71. cd /home/git/gitlab
  72. sudo -u git -H editor config/gitlab.yml
  73. ```
  74. and change the following section:
  75. ```yaml
  76. ## OmniAuth settings
  77. omniauth:
  78. # Allow login via Twitter, Google, etc. using OmniAuth providers
  79. enabled: true
  80. # CAUTION!
  81. # This allows users to login without having a user account first. Define the allowed providers
  82. # using an array, e.g. ["saml", "twitter"], or as true/false to allow all providers or none.
  83. # User accounts will be created automatically when authentication was successful.
  84. allow_single_sign_on: ["saml", "twitter"]
  85. auto_link_ldap_user: true
  86. # Locks down those users until they have been cleared by the admin (default: true).
  87. block_auto_created_users: true
  88. ```
  89. Now we can choose one or more of the [Supported Providers](#supported-providers)
  90. listed above to continue the configuration process.
  91. ## Enable OmniAuth for an Existing User
  92. Existing users can enable OmniAuth for specific providers after the account is
  93. created. For example, if the user originally signed in with LDAP, an OmniAuth
  94. provider such as Twitter can be enabled. Follow the steps below to enable an
  95. OmniAuth provider for an existing user.
  96. 1. Sign in normally - whether standard sign in, LDAP, or another OmniAuth provider.
  97. 1. Go to profile settings (the silhouette icon in the top right corner).
  98. 1. Select the "Account" tab.
  99. 1. Under "Connected Accounts" select the desired OmniAuth provider, such as Twitter.
  100. 1. The user will be redirected to the provider. Once the user authorized GitLab
  101. they will be redirected back to GitLab.
  102. The chosen OmniAuth provider is now active and can be used to sign in to GitLab from then on.
  103. ## Configure OmniAuth Providers as External
  104. >**Note:**
  105. This setting was introduced with version 8.7 of GitLab
  106. You can define which OmniAuth providers you want to be `external` so that all users
  107. **creating accounts, or logging in via these providers** will not be able to have
  108. access to internal projects. You will need to use the full name of the provider,
  109. like `google_oauth2` for Google. Refer to the examples for the full names of the
  110. supported providers.
  111. >**Note:**
  112. If you decide to remove an OmniAuth provider from the external providers list
  113. you will need to manually update the users that use this method to login, if you
  114. want their accounts to be upgraded to full internal accounts.
  115. **For Omnibus installations**
  116. ```ruby
  117. gitlab_rails['omniauth_external_providers'] = ['twitter', 'google_oauth2']
  118. ```
  119. **For installations from source**
  120. ```yaml
  121. omniauth:
  122. external_providers: ['twitter', 'google_oauth2']
  123. ```
  124. ## Using Custom Omniauth Providers
  125. >**Note:**
  126. The following information only applies for installations from source.
  127. GitLab uses [Omniauth](http://www.omniauth.org/) for authentication and already ships
  128. with a few providers pre-installed (e.g. LDAP, GitHub, Twitter). But sometimes that
  129. is not enough and you need to integrate with other authentication solutions. For
  130. these cases you can use the Omniauth provider.
  131. ### Steps
  132. These steps are fairly general and you will need to figure out the exact details
  133. from the Omniauth provider's documentation.
  134. - Stop GitLab:
  135. sudo service gitlab stop
  136. - Add the gem to your [Gemfile](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/Gemfile):
  137. gem "omniauth-your-auth-provider"
  138. - If you're using MySQL, install the new Omniauth provider gem by running the following command:
  139. sudo -u git -H bundle install --without development test postgres --path vendor/bundle --no-deployment
  140. - If you're using PostgreSQL, install the new Omniauth provider gem by running the following command:
  141. sudo -u git -H bundle install --without development test mysql --path vendor/bundle --no-deployment
  142. > These are the same commands you used in the [Install Gems section](#install-gems) with `--path vendor/bundle --no-deployment` instead of `--deployment`.
  143. - Start GitLab:
  144. sudo service gitlab start
  145. ### Examples
  146. If you have successfully set up a provider that is not shipped with GitLab itself,
  147. please let us know.
  148. You can help others by reporting successful configurations and probably share a
  149. few insights or provide warnings for common errors or pitfalls by sharing your
  150. experience [in the public Wiki](https://github.com/gitlabhq/gitlab-public-wiki/wiki/Custom-omniauth-provider-configurations).
  151. While we can't officially support every possible authentication mechanism out there,
  152. we'd like to at least help those with specific needs.
  153. ## Enable or disable Sign In with an OmniAuth provider without disabling import sources
  154. >**Note:**
  155. This setting was introduced with version 8.8 of GitLab.
  156. Administrators are able to enable or disable Sign In via some OmniAuth providers.
  157. >**Note:**
  158. By default Sign In is enabled via all the OAuth Providers that have been configured in `config/gitlab.yml`.
  159. In order to enable/disable an OmniAuth provider, go to Admin Area -> Settings -> Sign-in Restrictions section -> Enabled OAuth Sign-In sources and select the providers you want to enable or disable.
  160. ![Enabled OAuth Sign-In sources](img/enabled-oauth-sign-in-sources.png)
  161. ## Keep OmniAuth user profiles up to date
  162. You can enable profile syncing from selected OmniAuth providers and for all or for specific user information.
  163. ```ruby
  164. gitlab_rails['sync_profile_from_provider'] = ['twitter', 'google_oauth2']
  165. gitlab_rails['sync_profile_attributes'] = ['name', 'email', 'location']
  166. ```
  167. **For installations from source**
  168. ```yaml
  169. omniauth:
  170. sync_profile_from_provider: ['twitter', 'google_oauth2']
  171. sync_profile_claims_from_provider: ['email', 'location']
  172. ```