PageRenderTime 24ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/doc/integration/omniauth.md

https://gitlab.com/tancnle/gitlab-ce
Markdown | 330 lines | 238 code | 92 blank | 0 comment | 0 complexity | 3131e4f2db5c6abe26d5b2fc52b92635 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. - [JWT](../administration/auth/jwt.md)
  30. - [OpenID Connect](../administration/auth/oidc.md)
  31. - [UltraAuth](ultra_auth.md)
  32. - [SalesForce](salesforce.md)
  33. ## Initial OmniAuth Configuration
  34. Before configuring individual OmniAuth providers there are a few global settings
  35. that are in common for all providers that we need to consider.
  36. > **NOTE:**
  37. > Starting from GitLab 11.4, Omniauth is enabled by default. If you're using an
  38. > earlier version, you'll need to explicitly enable it.
  39. - `allow_single_sign_on` allows you to specify the providers you want to allow to
  40. automatically create an account. It defaults to `false`. If `false` users must
  41. be created manually or they will not be able to sign in via OmniAuth.
  42. - `auto_link_ldap_user` can be used if you have [LDAP / ActiveDirectory](ldap.md)
  43. integration enabled. It defaults to false. When enabled, users automatically
  44. created through OmniAuth will be linked to their LDAP entry as well.
  45. - `block_auto_created_users` defaults to `true`. If `true` auto created users will
  46. be blocked by default and will have to be unblocked by an administrator before
  47. they are able to sign in.
  48. > **Note:**
  49. > If you set `block_auto_created_users` to `false`, make sure to only
  50. > define providers under `allow_single_sign_on` that you are able to control, like
  51. > SAML, Shibboleth, Crowd or Google, or set it to `false` otherwise any user on
  52. > the Internet will be able to successfully sign in to your GitLab without
  53. > administrative approval.
  54. >
  55. > **Note:**
  56. > `auto_link_ldap_user` requires the `uid` of the user to be the same in both LDAP
  57. > and the OmniAuth provider.
  58. To change these settings:
  59. - **For Omnibus package**
  60. Open the configuration file:
  61. ```sh
  62. sudo editor /etc/gitlab/gitlab.rb
  63. ```
  64. and change:
  65. ```ruby
  66. # Versions prior to 11.4 require this to be set to true
  67. # gitlab_rails['omniauth_enabled'] = nil
  68. # CAUTION!
  69. # This allows users to login without having a user account first. Define the allowed providers
  70. # using an array, e.g. ["saml", "twitter"], or as true/false to allow all providers or none.
  71. # User accounts will be created automatically when authentication was successful.
  72. gitlab_rails['omniauth_allow_single_sign_on'] = ['saml', 'twitter']
  73. gitlab_rails['omniauth_auto_link_ldap_user'] = true
  74. gitlab_rails['omniauth_block_auto_created_users'] = true
  75. ```
  76. - **For installations from source**
  77. Open the configuration file:
  78. ```sh
  79. cd /home/git/gitlab
  80. sudo -u git -H editor config/gitlab.yml
  81. ```
  82. and change the following section:
  83. ```yaml
  84. ## OmniAuth settings
  85. omniauth:
  86. # Allow login via Twitter, Google, etc. using OmniAuth providers
  87. # Versions prior to 11.4 require this to be set to true
  88. # enabled: true
  89. # CAUTION!
  90. # This allows users to login without having a user account first. Define the allowed providers
  91. # using an array, e.g. ["saml", "twitter"], or as true/false to allow all providers or none.
  92. # User accounts will be created automatically when authentication was successful.
  93. allow_single_sign_on: ["saml", "twitter"]
  94. auto_link_ldap_user: true
  95. # Locks down those users until they have been cleared by the admin (default: true).
  96. block_auto_created_users: true
  97. ```
  98. Now we can choose one or more of the [Supported Providers](#supported-providers)
  99. listed above to continue the configuration process.
  100. ## Enable OmniAuth for an Existing User
  101. Existing users can enable OmniAuth for specific providers after the account is
  102. created. For example, if the user originally signed in with LDAP, an OmniAuth
  103. provider such as Twitter can be enabled. Follow the steps below to enable an
  104. OmniAuth provider for an existing user.
  105. 1. Sign in normally - whether standard sign in, LDAP, or another OmniAuth provider.
  106. 1. Go to profile settings (the silhouette icon in the top right corner).
  107. 1. Select the "Account" tab.
  108. 1. Under "Connected Accounts" select the desired OmniAuth provider, such as Twitter.
  109. 1. The user will be redirected to the provider. Once the user authorized GitLab
  110. they will be redirected back to GitLab.
  111. The chosen OmniAuth provider is now active and can be used to sign in to GitLab from then on.
  112. ## Configure OmniAuth Providers as External
  113. >**Note:**
  114. This setting was introduced with version 8.7 of GitLab
  115. You can define which OmniAuth providers you want to be `external` so that all users
  116. **creating accounts, or logging in via these providers** will not be able to have
  117. access to internal projects. You will need to use the full name of the provider,
  118. like `google_oauth2` for Google. Refer to the examples for the full names of the
  119. supported providers.
  120. >**Note:**
  121. If you decide to remove an OmniAuth provider from the external providers list
  122. you will need to manually update the users that use this method to login, if you
  123. want their accounts to be upgraded to full internal accounts.
  124. **For Omnibus installations**
  125. ```ruby
  126. gitlab_rails['omniauth_external_providers'] = ['twitter', 'google_oauth2']
  127. ```
  128. **For installations from source**
  129. ```yaml
  130. omniauth:
  131. external_providers: ['twitter', 'google_oauth2']
  132. ```
  133. ## Using Custom Omniauth Providers
  134. >**Note:**
  135. The following information only applies for installations from source.
  136. GitLab uses [Omniauth](https://github.com/omniauth/omniauth) for authentication and already ships
  137. with a few providers pre-installed (e.g. LDAP, GitHub, Twitter). But sometimes that
  138. is not enough and you need to integrate with other authentication solutions. For
  139. these cases you can use the Omniauth provider.
  140. ### Steps
  141. These steps are fairly general and you will need to figure out the exact details
  142. from the Omniauth provider's documentation.
  143. - Stop GitLab:
  144. ```sh
  145. sudo service gitlab stop
  146. ```
  147. - Add the gem to your [Gemfile](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/Gemfile):
  148. ```sh
  149. gem "omniauth-your-auth-provider"
  150. ```
  151. - Install the new Omniauth provider gem by running the following command:
  152. ```sh
  153. sudo -u git -H bundle install --without development test mysql --path vendor/bundle --no-deployment
  154. ```
  155. > These are the same commands you used during initial installation in the [Install Gems section](../install/installation.md#install-gems) with `--path vendor/bundle --no-deployment` instead of `--deployment`.
  156. - Start GitLab:
  157. ```sh
  158. sudo service gitlab start
  159. ```
  160. ### Examples
  161. If you have successfully set up a provider that is not shipped with GitLab itself,
  162. please let us know.
  163. You can help others by reporting successful configurations and probably share a
  164. few insights or provide warnings for common errors or pitfalls by sharing your
  165. experience [in the public Wiki](https://github.com/gitlabhq/gitlab-public-wiki/wiki/Custom-omniauth-provider-configurations).
  166. While we can't officially support every possible authentication mechanism out there,
  167. we'd like to at least help those with specific needs.
  168. ## Enable or disable Sign In with an OmniAuth provider without disabling import sources
  169. >**Note:**
  170. This setting was introduced with version 8.8 of GitLab.
  171. Administrators are able to enable or disable Sign In via some OmniAuth providers.
  172. >**Note:**
  173. By default Sign In is enabled via all the OAuth Providers that have been configured in `config/gitlab.yml`.
  174. 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.
  175. ![Enabled OAuth Sign-In sources](img/enabled-oauth-sign-in-sources.png)
  176. ## Disabling Omniauth
  177. Starting from version 11.4 of GitLab, Omniauth is enabled by default. This only
  178. has an effect if providers are configured and [enabled](#enable-or-disable-sign-in-with-an-omniauth-provider-without-disabling-import-sources).
  179. If omniauth providers are causing problems even when individually disabled, you
  180. can disable the entire omniauth subsystem by modifying the configuration file:
  181. **For Omnibus installations**
  182. ```ruby
  183. gitlab_rails['omniauth_enabled'] = false
  184. ```
  185. **For installations from source**
  186. ```yaml
  187. omniauth:
  188. enabled: false
  189. ```
  190. ## Keep OmniAuth user profiles up to date
  191. You can enable profile syncing from selected OmniAuth providers and for all or for specific user information.
  192. When authenticating using LDAP, the user's name and email are always synced.
  193. ```ruby
  194. gitlab_rails['sync_profile_from_provider'] = ['twitter', 'google_oauth2']
  195. gitlab_rails['sync_profile_attributes'] = ['name', 'email', 'location']
  196. ```
  197. **For installations from source**
  198. ```yaml
  199. omniauth:
  200. sync_profile_from_provider: ['twitter', 'google_oauth2']
  201. sync_profile_attributes: ['email', 'location']
  202. ```
  203. ## Bypassing two factor authentication
  204. Starting with GitLab 12.3, this allows users to login with the specified
  205. providers without two factor authentication.
  206. Define the allowed providers using an array, e.g. `["twitter", 'google_oauth2']`, or as
  207. `true`/`false` to allow all providers or none. This option should only be configured
  208. for providers which already have two factor authentication (default: false).
  209. This configration dose not apply to SAML.
  210. ```ruby
  211. gitlab_rails['omniauth_allow_bypass_two_factor'] = ['twitter', 'google_oauth2']
  212. ```
  213. **For installations from source**
  214. ```yaml
  215. omniauth:
  216. allow_bypass_two_factor: ['twitter', 'google_oauth2']
  217. ```
  218. ## Automatically sign in with provider
  219. You can add the `auto_sign_in_with_provider` setting to your
  220. GitLab configuration to automatically redirect login requests
  221. to your OmniAuth provider for authentication, thus removing the need to click a button
  222. before actually signing in.
  223. For example, when using the Azure integration, you would set the following
  224. to enable auto sign in.
  225. For Omnibus package:
  226. ```ruby
  227. gitlab_rails['omniauth_auto_sign_in_with_provider'] = 'azure_oauth2'
  228. ```
  229. For installations from source:
  230. ```yaml
  231. omniauth:
  232. auto_sign_in_with_provider: azure_oauth2
  233. ```
  234. Please keep in mind that every sign in attempt will be redirected to the OmniAuth provider,
  235. so you will not be able to sign in using local credentials. Make sure that at least one
  236. of the OmniAuth users has admin permissions.
  237. You may also bypass the auto signin feature by browsing to
  238. `https://gitlab.example.com/users/sign_in?auto_sign_in=false`.