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

/doc/integration/azure.md

https://gitlab.com/klml/gitlab-ee
Markdown | 200 lines | 144 code | 56 blank | 0 comment | 0 complexity | ded67fa1ad6cb0fc8f18f1cdc3005ca5 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. # Microsoft Azure OAuth2 OmniAuth Provider **(FREE)**
  7. NOTE:
  8. Per Microsoft, this provider uses the [older Azure Active Directory v1.0 endpoint](https://docs.microsoft.com/en-us/azure/active-directory/azuread-dev/v1-protocols-oauth-code).
  9. Microsoft documentation suggests that you should use the [OpenID Connect protocol to use the v2 endpoints](../administration/auth/oidc.md#microsoft-azure) for new projects.
  10. To use v2 endpoints via OmniAuth, please follow [Microsoft Azure OAuth2 OmniAuth Provider v2 instructions](#microsoft-azure-oauth2-omniauth-provider-v2).
  11. To enable the Microsoft Azure OAuth2 OmniAuth provider, you must register your application with Azure. Azure generates a client ID and secret key for you to use.
  12. Sign in to the [Azure Portal](https://portal.azure.com), and follow the instructions in
  13. the [Microsoft Quickstart documentation](https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app).
  14. As you go through the Microsoft procedure, keep the following in mind:
  15. - If you have multiple instances of Azure Active Directory, you can switch to the desired tenant.
  16. - You're setting up a Web application.
  17. - The redirect URI requires the URL of the Azure OAuth callback of your GitLab
  18. installation. For example, `https://gitlab.mycompany.com/users/auth/azure_oauth2/callback`.
  19. The type dropdown should be set to **Web**.
  20. - The `client ID` and `client secret` are terms associated with OAuth 2. In some Microsoft documentation,
  21. the terms may be listed as `Application ID` and `Application Secret`.
  22. - If you need to generate a new client secret, follow the Microsoft documentation
  23. for [creating a new application secret](https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal#create-a-new-application-secret).
  24. - Save the client ID and client secret for your new app, as the client secret is only
  25. displayed one time.
  26. 1. On your GitLab server, open the configuration file.
  27. For Omnibus GitLab:
  28. ```shell
  29. sudo editor /etc/gitlab/gitlab.rb
  30. ```
  31. For installations from source:
  32. ```shell
  33. cd /home/git/gitlab
  34. sudo -u git -H editor config/gitlab.yml
  35. ```
  36. 1. Refer to [Initial OmniAuth Configuration](omniauth.md#initial-omniauth-configuration)
  37. for initial settings.
  38. 1. Add the provider configuration:
  39. For Omnibus GitLab:
  40. ```ruby
  41. gitlab_rails['omniauth_providers'] = [
  42. {
  43. "name" => "azure_oauth2",
  44. "args" => {
  45. "client_id" => "CLIENT ID",
  46. "client_secret" => "CLIENT SECRET",
  47. "tenant_id" => "TENANT ID",
  48. }
  49. }
  50. ]
  51. ```
  52. For installations from source:
  53. ```yaml
  54. - { name: 'azure_oauth2',
  55. args: { client_id: "CLIENT ID",
  56. client_secret: "CLIENT SECRET",
  57. tenant_id: "TENANT ID" } }
  58. ```
  59. The `base_azure_url` is optional and can be added for different locales;
  60. such as `base_azure_url: "https://login.microsoftonline.de"`.
  61. 1. Replace `CLIENT ID`, `CLIENT SECRET` and `TENANT ID` with the values you got above.
  62. 1. Save the configuration file.
  63. 1. Reconfigure or restart GitLab, depending on your installation method:
  64. - *If you installed from Omnibus GitLab,*
  65. [reconfigure](../administration/restart_gitlab.md#omnibus-gitlab-reconfigure) GitLab.
  66. - *If you installed from source,*
  67. [restart GitLab](../administration/restart_gitlab.md#installations-from-source).
  68. On the sign-in page, you should now see a Microsoft icon below the regular sign-in form.
  69. Click the icon to begin the authentication process. Microsoft then asks you to
  70. sign in and authorize the GitLab application. If successful, you are returned to GitLab and signed in.
  71. Read [Enable OmniAuth for an Existing User](omniauth.md#enable-omniauth-for-an-existing-user)
  72. for information on how existing GitLab users can connect to their newly-available Azure AD accounts.
  73. ## Microsoft Azure OAuth2 OmniAuth Provider v2
  74. In order to use v2 endpoints provided by Microsoft Azure Active Directory you must to configure it via Azure OAuth2 OmniAuth Provider v2.
  75. ### Registering an Azure application
  76. To enable the Microsoft Azure OAuth2 OmniAuth provider, you must register your application with Azure. Azure generates a client ID and secret key for you to use.
  77. Sign in to the [Azure Portal](https://portal.azure.com), and follow the instructions in
  78. the [Microsoft Quickstart documentation](https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app).
  79. As you go through the Microsoft procedure, keep the following in mind:
  80. - If you have multiple instances of Azure Active Directory, you can switch to the desired tenant.
  81. - You're setting up a Web application.
  82. - The redirect URI requires the URL of the Azure OAuth callback of your GitLab
  83. installation. For example, `https://gitlab.example.com/users/auth/azure_activedirectory_v2/callback`.
  84. The type dropdown should be set to **Web**.
  85. - The `client ID` and `client secret` are terms associated with OAuth 2. In some Microsoft documentation,
  86. the terms may be listed as `Application ID` and `Application Secret`.
  87. - If you need to generate a new client secret, follow the Microsoft documentation
  88. for [creating a new application secret](https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal#create-a-new-application-secret).
  89. - Save the client ID and client secret for your new app, as the client secret is only
  90. displayed one time.
  91. ### Adding API permissions (scopes)
  92. Once you have created an application, follow the [Microsoft Quickstart documentation to expose a web API](https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-configure-app-expose-web-apis). Be sure to add the following delegated permissions under the Microsoft Graph API:
  93. - `email`
  94. - `openid`
  95. - `profile`
  96. ### Configuring GitLab
  97. 1. On your GitLab server, open the configuration file.
  98. For Omnibus GitLab:
  99. ```shell
  100. sudo editor /etc/gitlab/gitlab.rb
  101. ```
  102. For installations from source:
  103. ```shell
  104. cd /home/git/gitlab
  105. sudo -u git -H editor config/gitlab.yml
  106. ```
  107. 1. Refer to [Initial OmniAuth Configuration](omniauth.md#initial-omniauth-configuration)
  108. for initial settings.
  109. 1. Add the provider configuration:
  110. For Omnibus GitLab:
  111. ```ruby
  112. gitlab_rails['omniauth_providers'] = [
  113. {
  114. "name" => "azure_activedirectory_v2",
  115. "args" => {
  116. "client_id" => "CLIENT ID",
  117. "client_secret" => "CLIENT SECRET",
  118. "tenant_id" => "TENANT ID",
  119. }
  120. }
  121. ]
  122. ```
  123. For installations from source:
  124. ```yaml
  125. - { name: 'azure_activedirectory_v2',
  126. args: { client_id: "CLIENT ID",
  127. client_secret: "CLIENT SECRET",
  128. tenant_id: "TENANT ID" } }
  129. ```
  130. The `base_azure_url` is optional and can be added for different locales;
  131. such as `base_azure_url: "https://login.microsoftonline.de"`.
  132. The `scope` parameter is optional and can be added to `args`. Default `scope` is: `openid profile email`.
  133. 1. Replace `CLIENT ID`, `CLIENT SECRET`, and `TENANT ID` with the values you got above.
  134. 1. Save the configuration file.
  135. 1. Reconfigure or restart GitLab, depending on your installation method:
  136. - *If you installed from Omnibus GitLab,*
  137. [reconfigure](../administration/restart_gitlab.md#omnibus-gitlab-reconfigure) GitLab.
  138. - *If you installed from source,*
  139. [restart GitLab](../administration/restart_gitlab.md#installations-from-source).
  140. On the sign-in page, you should now see a Microsoft icon below the regular sign-in form.
  141. Select the icon to begin the authentication process. Microsoft then asks you to
  142. sign in and authorize the GitLab application. If successful, you are returned to GitLab and signed in.
  143. Read [Enable OmniAuth for an Existing User](omniauth.md#enable-omniauth-for-an-existing-user)
  144. for information on how existing GitLab users can connect to their newly available Azure AD accounts.