PageRenderTime 30ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/doc/integration/omniauth.md

https://gitlab.com/axil/gitlab
Markdown | 359 lines | 258 code | 101 blank | 0 comment | 0 complexity | f83f16b4d863cbf99601ffa7a3c10688 MD5 | raw file
  1. ---
  2. stage: Create
  3. group: Ecosystem
  4. info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
  5. ---
  6. # OmniAuth
  7. GitLab leverages OmniAuth to allow users to sign in using Twitter, GitHub, and
  8. other popular services. [OmniAuth](https://rubygems.org/gems/omniauth/) is
  9. "a generalized Rack framework for multiple-provider authentication, built on Ruby.
  10. Configuring OmniAuth does not prevent standard GitLab authentication or LDAP
  11. (if configured) from continuing to work. Users can choose to sign in using any
  12. of the configured mechanisms.
  13. - [Initial OmniAuth Configuration](#initial-omniauth-configuration)
  14. - [Supported Providers](#supported-providers)
  15. - [Enable OmniAuth for an Existing User](#enable-omniauth-for-an-existing-user)
  16. - [OmniAuth configuration sample when using Omnibus GitLab](https://gitlab.com/gitlab-org/omnibus-gitlab/tree/master#omniauth-google-twitter-github-login)
  17. - [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)
  18. ## Supported Providers
  19. This is a list of the current supported OmniAuth providers. Before proceeding
  20. on each provider's documentation, make sure to first read this document as it
  21. contains some settings that are common for all providers.
  22. - [GitHub](github.md)
  23. - [Bitbucket](bitbucket.md)
  24. - [GitLab.com](gitlab.md)
  25. - [Google](google.md)
  26. - [Facebook](facebook.md)
  27. - [Twitter](twitter.md)
  28. - [Shibboleth](shibboleth.md)
  29. - [SAML](saml.md)
  30. - [Crowd](../administration/auth/crowd.md)
  31. - [Azure](azure.md)
  32. - [Auth0](auth0.md)
  33. - [Authentiq](../administration/auth/authentiq.md)
  34. - [OAuth2Generic](oauth2_generic.md)
  35. - [JWT](../administration/auth/jwt.md)
  36. - [OpenID Connect](../administration/auth/oidc.md)
  37. - [Salesforce](salesforce.md)
  38. - [AWS Cognito](../administration/auth/cognito.md)
  39. ## Initial OmniAuth Configuration
  40. Before configuring individual OmniAuth providers there are a few global settings
  41. that are in common for all providers that we need to consider.
  42. NOTE:
  43. Starting from GitLab 11.4, OmniAuth is enabled by default. If you're using an
  44. earlier version, you must explicitly enable it.
  45. - `allow_single_sign_on` allows you to specify the providers you want to allow to
  46. automatically create an account. It defaults to `false`. If `false` users must
  47. be created manually or they can't sign in by using OmniAuth.
  48. - `auto_link_ldap_user` can be used if you have [LDAP / ActiveDirectory](../administration/auth/ldap/index.md)
  49. integration enabled. It defaults to `false`. When enabled, users automatically
  50. created through an OmniAuth provider have their LDAP identity created in GitLab as well.
  51. - `block_auto_created_users` defaults to `true`. If `true` auto created users will
  52. be blocked by default and must be unblocked by an administrator before
  53. they are able to sign in.
  54. NOTE:
  55. If you set `block_auto_created_users` to `false`, make sure to only
  56. define providers under `allow_single_sign_on` that you are able to control, like
  57. SAML, Shibboleth, Crowd, or Google. Otherwise, set it to `false`, or any user on
  58. the Internet can successfully sign in to your GitLab without
  59. administrative approval.
  60. NOTE:
  61. `auto_link_ldap_user` requires the `uid` of the user to be the same in both LDAP
  62. and the OmniAuth provider.
  63. To change these settings:
  64. - **For Omnibus package**
  65. Open the configuration file:
  66. ```shell
  67. sudo editor /etc/gitlab/gitlab.rb
  68. ```
  69. and change:
  70. ```ruby
  71. # CAUTION!
  72. # This allows users to sign in without having a user account first. Define the allowed providers
  73. # using an array, for example, ["saml", "twitter"], or as true/false to allow all providers or none.
  74. # User accounts will be created automatically when authentication was successful.
  75. gitlab_rails['omniauth_allow_single_sign_on'] = ['saml', 'twitter']
  76. gitlab_rails['omniauth_auto_link_ldap_user'] = true
  77. gitlab_rails['omniauth_block_auto_created_users'] = true
  78. ```
  79. - **For installations from source**
  80. Open the configuration file:
  81. ```shell
  82. cd /home/git/gitlab
  83. sudo -u git -H editor config/gitlab.yml
  84. ```
  85. and change the following section:
  86. ```yaml
  87. ## OmniAuth settings
  88. omniauth:
  89. # Allow sign-in by using Twitter, Google, etc. using OmniAuth providers
  90. # Versions prior to 11.4 require this to be set to true
  91. # enabled: true
  92. # CAUTION!
  93. # This allows users to sign in without having a user account first. Define the allowed providers
  94. # using an array, for example, ["saml", "twitter"], or as true/false to allow all providers or none.
  95. # User accounts will be created automatically when authentication was successful.
  96. allow_single_sign_on: ["saml", "twitter"]
  97. auto_link_ldap_user: true
  98. # Locks down those users until they have been cleared by the admin (default: true).
  99. block_auto_created_users: true
  100. ```
  101. Now we can choose one or more of the [Supported Providers](#supported-providers)
  102. listed above to continue the configuration process.
  103. ## Enable OmniAuth for an Existing User
  104. Existing users can enable OmniAuth for specific providers after the account is
  105. created. For example, if the user originally signed in with LDAP, an OmniAuth
  106. provider such as Twitter can be enabled. Follow the steps below to enable an
  107. OmniAuth provider for an existing user.
  108. 1. Sign in normally - whether standard sign in, LDAP, or another OmniAuth provider.
  109. 1. In the top-right corner, select your avatar.
  110. 1. Select **Edit profile**.
  111. 1. In the left sidebar, select **Account**.
  112. 1. In the **Connected Accounts** section, select the desired OmniAuth provider, such as Twitter.
  113. 1. The user is redirected to the provider. After the user authorizes GitLab,
  114. they are redirected back to GitLab.
  115. The chosen OmniAuth provider is now active and can be used to sign in to GitLab from then on.
  116. ## Automatically Link Existing Users to OmniAuth Users
  117. > [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/36664) in GitLab 13.4.
  118. You can automatically link OmniAuth users with existing GitLab users if their email addresses match.
  119. For example, the following setting is used to enable the auto link feature for both a SAML provider and the Twitter OAuth provider:
  120. **For Omnibus installations**
  121. ```ruby
  122. gitlab_rails['omniauth_auto_link_user'] = ["saml", "twitter"]
  123. ```
  124. **For installations from source**
  125. ```yaml
  126. omniauth:
  127. auto_link_user: ["saml", "twitter"]
  128. ```
  129. ## Configure OmniAuth Providers as External
  130. You can define which OmniAuth providers you want to be `external`. Users
  131. creating accounts, or logging in by using these `external` providers cannot have
  132. access to internal projects. You must use the full name of the provider,
  133. like `google_oauth2` for Google. Refer to the examples for the full names of the
  134. supported providers.
  135. NOTE:
  136. If you decide to remove an OmniAuth provider from the external providers list,
  137. you must manually update the users that use this method to sign in if you want
  138. their accounts to be upgraded to full internal accounts.
  139. **For Omnibus installations**
  140. ```ruby
  141. gitlab_rails['omniauth_external_providers'] = ['twitter', 'google_oauth2']
  142. ```
  143. **For installations from source**
  144. ```yaml
  145. omniauth:
  146. external_providers: ['twitter', 'google_oauth2']
  147. ```
  148. ## Using Custom OmniAuth Providers
  149. NOTE:
  150. The following information only applies for installations from source.
  151. GitLab uses [OmniAuth](https://github.com/omniauth/omniauth) for authentication and already ships
  152. with a few providers pre-installed, such as LDAP, GitHub, and Twitter. You may also
  153. need to integrate with other authentication solutions. For
  154. these cases, you can use the OmniAuth provider.
  155. ### Steps
  156. These steps are fairly general and you must figure out the exact details
  157. from the OmniAuth provider's documentation.
  158. - Stop GitLab:
  159. ```shell
  160. sudo service gitlab stop
  161. ```
  162. - Add the gem to your [`Gemfile`](https://gitlab.com/gitlab-org/gitlab/blob/master/Gemfile):
  163. ```shell
  164. gem "omniauth-your-auth-provider"
  165. ```
  166. - Install the new OmniAuth provider gem by running the following command:
  167. ```shell
  168. sudo -u git -H bundle install --without development test mysql --path vendor/bundle --no-deployment
  169. ```
  170. > 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`.
  171. - Start GitLab:
  172. ```shell
  173. sudo service gitlab start
  174. ```
  175. ### Examples
  176. If you have successfully set up a provider that is not shipped with GitLab itself,
  177. please let us know.
  178. Share your experience [in the public Wiki](https://github.com/gitlabhq/gitlab-public-wiki/wiki/Custom-omniauth-provider-configurations).
  179. You can help others by reporting successful configurations and probably share a
  180. few insights or provide warnings for common errors or pitfalls.
  181. While we can't officially support every possible authentication mechanism out there,
  182. we'd like to at least help those with specific needs.
  183. ## Enable or disable Sign In with an OmniAuth provider without disabling import sources
  184. Administrators are able to enable or disable **Sign In** by using some OmniAuth providers.
  185. NOTE:
  186. By default, **Sign In** is enabled by using all the OAuth Providers that have been configured in `config/gitlab.yml`.
  187. To enable/disable an OmniAuth provider:
  188. 1. In the top navigation bar, go to **Admin Area**.
  189. 1. In the left sidebar, go to **Settings**.
  190. 1. Scroll to the **Sign-in Restrictions** section, and click **Expand**.
  191. 1. Next to **Enabled OAuth Sign-In sources**, select the check box for each provider you want to enable or disable.
  192. ![Enabled OAuth Sign-In sources](img/enabled-oauth-sign-in-sources.png)
  193. ## Disabling OmniAuth
  194. Starting from version 11.4 of GitLab, OmniAuth is enabled by default. This only
  195. has an effect if providers are configured and [enabled](#enable-or-disable-sign-in-with-an-omniauth-provider-without-disabling-import-sources).
  196. If OmniAuth providers are causing problems even when individually disabled, you
  197. can disable the entire OmniAuth subsystem by modifying the configuration file:
  198. **For Omnibus installations**
  199. ```ruby
  200. gitlab_rails['omniauth_enabled'] = false
  201. ```
  202. **For installations from source**
  203. ```yaml
  204. omniauth:
  205. enabled: false
  206. ```
  207. ## Keep OmniAuth user profiles up to date
  208. You can enable profile syncing from selected OmniAuth providers and for all or for specific user information.
  209. When authenticating using LDAP, the user's name and email are always synced.
  210. ```ruby
  211. gitlab_rails['omniauth_sync_profile_from_provider'] = ['twitter', 'google_oauth2']
  212. gitlab_rails['omniauth_sync_profile_attributes'] = ['name', 'email', 'location']
  213. ```
  214. **For installations from source**
  215. ```yaml
  216. omniauth:
  217. sync_profile_from_provider: ['twitter', 'google_oauth2']
  218. sync_profile_attributes: ['email', 'location']
  219. ```
  220. ## Bypassing two factor authentication
  221. In GitLab 12.3 or later, users can sign in with specified providers _without_
  222. using two factor authentication.
  223. Define the allowed providers using an array (for example, `["twitter", 'google_oauth2']`),
  224. or as `true` or `false` to allow all providers (or none). This option should be
  225. configured only for providers which already have two factor authentication
  226. (default: false). This configuration doesn't apply to SAML.
  227. ```ruby
  228. gitlab_rails['omniauth_allow_bypass_two_factor'] = ['twitter', 'google_oauth2']
  229. ```
  230. **For installations from source**
  231. ```yaml
  232. omniauth:
  233. allow_bypass_two_factor: ['twitter', 'google_oauth2']
  234. ```
  235. ## Automatically sign in with provider
  236. You can add the `auto_sign_in_with_provider` setting to your GitLab
  237. configuration to redirect login requests to your OmniAuth provider for
  238. authentication. This removes the need to click a button before actually signing in.
  239. For example, when using the Azure integration, set the following to enable auto
  240. sign-in:
  241. For Omnibus package:
  242. ```ruby
  243. gitlab_rails['omniauth_auto_sign_in_with_provider'] = 'azure_oauth2'
  244. ```
  245. For installations from source:
  246. ```yaml
  247. omniauth:
  248. auto_sign_in_with_provider: azure_oauth2
  249. ```
  250. Keep in mind that every sign-in attempt is redirected to the OmniAuth
  251. provider; you can't sign in using local credentials. Ensure at least
  252. one of the OmniAuth users has administrator permissions.
  253. You may also bypass the auto sign in feature by browsing to
  254. `https://gitlab.example.com/users/sign_in?auto_sign_in=false`.
  255. ## Passwords for users created via OmniAuth
  256. The [Generated passwords for users created through integrated authentication](../security/passwords_for_integrated_authentication_methods.md)
  257. guide provides an overview about how GitLab generates and sets passwords for
  258. users created with OmniAuth.