LoginSignup
9
11

More than 5 years have passed since last update.

gitlabとazure-adを連携する

Last updated at Posted at 2018-06-15

gitlabとAzureAD連携できたのでその備忘録です。

・AzurePortal側の設定

AzureADの画面からアプリの登録を実施

名前:Gitlab
タイプ:WebAPI
URL:https://your-gitlab-url/

アプリケーションIDを控えておく

設定から応答URLを追加
https://your-gitlab-url/users/auth/azure_oauth2/callback

権限を付与ボタンを押した

キーから鍵を追加

キーを登録した内容を控えておく(入力したパスワードが変換されてでてきたトークン)

アプリの登録の画面からエンドポイントを確認

・gitlab側の設定

以下のとおり設定。

# cd /etc/gitlab
# cp -p gitlab.rb{,.`date +%Y%m%d`}
# ls
gitlab.rb           gitlab.rb.20180508  gitlab.rb.20180614   trusted-certs
gitlab.rb.20180501  gitlab.rb.20180518  gitlab-secrets.json
# vi gitlab.rb
# diff gitlab.rb{,.`date +%Y%m%d`}
171,172c171,172
< gitlab_rails['omniauth_enabled'] = true
< gitlab_rails['omniauth_allow_single_sign_on'] = ['azure_oauth2']
---
> # gitlab_rails['omniauth_enabled'] = false
> # gitlab_rails['omniauth_allow_single_sign_on'] = ['saml']
174,175c174,175
< gitlab_rails['omniauth_block_auto_created_users'] = true
< gitlab_rails['omniauth_auto_link_ldap_user'] = true
---
> # gitlab_rails['omniauth_block_auto_created_users'] = true
> # gitlab_rails['omniauth_auto_link_ldap_user'] = false
177,189c177,185
< gitlab_rails['omniauth_external_providers'] = ['azure_oauth2']
< gitlab_rails['sync_profile_from_provider'] = ['azure_oauth2']
< gitlab_rails['sync_profile_attributes'] = ['name', 'email']
< gitlab_rails['omniauth_providers'] = [
<   {
<     "name" => "azure_oauth2",
<     "args" => {
<        "client_id" => "****アプリケーションID****",
<        "client_secret" => "****アプリで登録したキー*****",
<        "tenant_id" => "****AADのディレクトリのID****",
<     }
<   }
< ]
---
> # gitlab_rails['omniauth_external_providers'] = ['twitter', 'google_oauth2']
> # gitlab_rails['omniauth_providers'] = [
> #   {
> #     "name" => "google_oauth2",
> #     "app_id" => "YOUR APP ID",
> #     "app_secret" => "YOUR APP SECRET",
> #     "args" => { "access_type" => "offline", "approval_prompt" => "" }
> #   }
> # ]

# gitlab-ctl reconfigure
# gitlab-ctl status

※omniauth_block_auto_created_usersをtrueにしてるのでデフォだとブロックされて管理者が解除する必要がある仕様。

ユーザのログイン

で、自分のアカウントセッティングする画面からazureっぽい窓マーク(connect)と書いてあるのをポチっとして
gitlab-azuread-connect-mask.png

サインアウトすると
窓マークが出てるのでぽちっとするとログインできるようになりました。
(二段階認証設定してあるなら入れる必要有)
認証の手段が一個増えただけって感じですね。AzureAD側で認証してあるならID/PW入力が不要なとこが便利に。
既存使い続けるで問題ないならなにもしなくても大丈夫。

参考

https://docs.gitlab.com/ce/integration/azure.html
https://docs.gitlab.com/ce/integration/omniauth.html#initial-omniauth-configuration
https://docs.microsoft.com/ja-jp/azure/active-directory/develop/active-directory-protocols-oauth-code
https://serverfault.com/questions/874484/gitlab-and-oauth-to-azure-ad

9
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
11