LoginSignup
6
4

More than 5 years have passed since last update.

【AWS】ELB+Gitlabの構築・設定(Google認証付き)

Posted at

目的

AWSでGitlabを構築するにあたり、ELBでHTTPSを受け付け、後段EC2のGitlabサーバにて処理。
それを実現するためのGitlab設定方法をまとめる。
併せて、Gitlabでoogle認証を行う場合の設定も記載。

全体概要はこんな感じ

  • ELBには「https://xxx」で通常443ポート開放
  • https://xxx/gitlab/」でアクセスした場合はGitlabサーバに「http://xxx/gitlab」で送る。
  • 他に「https://xxx/app1/」とした場合は別のサーバへ振り分けるイメージ

スクリーンショット 2017-08-06 16.51.02.png

やらないこと

  • ELB、EC2などのAWSの設定
  • 公式に載っているGitlabのインストール手順
  • google認証を行うためのgoogle側の設定

前提

Gitlabのバージョン:GitLab Community Edition 9.3.6
標準のgitlabのインストールを実行済み
公式インストール手順(CentOS6)
※AWSLinuxでも同様

gitlabへSSH通信は行わない。PushなどはHTTPSでの認証とする。

1. ELBとGitlabの連携

1-1. gitlab.rbの編集

==[ELBの連携まで]==
#cd /etc/gitlab/gitlab.rb
#diff gitlab.rb gitlab.rb.org

13,14c13
< external_url 'https://xxx/gitlab'
---
> external_url 'http://xxx'
807c806
< nginx['listen_port'] = 80
---
> # nginx['listen_port'] = nil
811c810
< nginx['listen_https'] = false #https通信の無効化
---
> # nginx['listen_https'] = nil
817c816
<  nginx['proxy_set_headers'] = {
---
> # nginx['proxy_set_headers'] = {
821c820
<   "X-Forwarded-Proto" => "https",
---
> #  "X-Forwarded-Proto" => "https",
825c824
<  }
---
> # }

1-2. 再起動

gitlab-ctl reconfigure
gitlab-ctl start

1-3. ELB連携のポイント

gitlab.rbのみ編集し、reconfigureで反映するため一番きれいな方法だと思います。
直接nginx.conf等修正するとreconfigure時に上書きされるので。

ブラウザからの画面表示(リンクやPOSTのパス)はHTTPSにする必要がありつつ、
gitlabサーバ自体をHTTPで処理させるのが面倒でした。

2. GitlabでGoogle認証を設定する場合

2-1. gitlab.rbの編集

==[GoogleAuthまで]==
#cd /etc/gitlab/gitlab.rb
#diff gitlab.rb gitlab.rb.org

221c220
< gitlab_rails['omniauth_enabled'] = true
---
> # gitlab_rails['omniauth_enabled'] = false
223d221
< gitlab_rails['omniauth_allow_single_sign_on'] = ['google_oauth2']
230,239c228,235
< gitlab_rails['omniauth_external_providers'] = ['google_oauth2']
< gitlab_rails['omniauth_providers'] = [
<   {
<     "name" => "google_oauth2",
<     "app_id" => "各自のapp-id",
<     "app_secret" => "各自のシークレット",
<     "args" => { "access_type" => "offline", "approval_prompt" => "",
<     "hd" =>  "許容ドメイン(hoge.com)" }
<   }
< ]
---
> # gitlab_rails['omniauth_providers'] = [
> #   {
> #     "name" => "google_oauth2",
> #     "app_id" => "YOUR APP ID",
> #     "app_secret" => "YOUR APP SECRET",
> #     "args" => { "access_type" => "offline", "approval_prompt" => "" }
> #   }
> # ]

2-2. 再起動

gitlab-ctl reconfigure
gitlab-ctl start

2-3. google認証のポイント

特定のドメインのみ許可したい場合は、hdオプションを利用することです。
google認証側で特定ドメインのみ対応してくれます。
特定ドメインが不要であればオプション外せば大丈夫なはずです。

おまけ

Gitlab, Redmine, Jenkinsなど利用しますが、どれも/配下やHttps->Httpの切り替え方法が異なるので、
いちいち調べるのが面倒。なんかいい方法ないかなぁ。

参考

似たような対応として下記の記事を参考にさせて頂きましたが、Reconfigureをすると、
設定が変更されてしまうためメンテナンスする際に面倒なため、/etc/gitlab/gitlab.rbのみで対応できる方法を書きました。
http://qiita.com/morozumi_h/items/128d3254fd2eb4671966

6
4
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
6
4