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

/doc/integration/omniauth.md

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