LoginSignup
7
7

More than 5 years have passed since last update.

GitLab Cookbook with SSL

Last updated at Posted at 2014-03-05

GitLabのインストールは簡単になりました。そのGitLab Omnibusでも利用されている
Cookbookは簡単にSSLが設定されたGitLabをインストールすることができます。

Prepare

最初にマシンドメイン証明書を準備します。

Machne

AWSさくらのVPS等でパブリックにマシンを作ります。
(今回のOSUbuntu 12.04を利用します。)

SSH

ローカルとリモートのSSHの設定をします。リモートのパスワード認証を禁止するには
sshd_configPasswordAuthenticationnoに編集します。

$ ssh ubuntu@example.com mkdir .ssh
$ scp ~/.ssh/id_rsa.pub ubuntu@example.com:.ssh/authorized_keys
$ cat << __EOS__ >> ~/.ssh/config
Host example.com
  User ubuntu
  IdentityFile ~/.ssh/id_rsa
__EOS__
$ ssh example.com
ubuntu@example:~$ sudo editor /etc/ssh/sshd_config
ubuntu@example:~$ sudo service ssh restart

Domain

お名前.comDoレジ等でドメインを取得します。
(DNSの設定でSPFレコードを登録しましょう。)

Sender Policy Framework

nslookupコマンドでTXTレコードを確認します。

$ nslookup -q=txt example.com
Server:   192.168.0.1
Address:  192.168.0.1#53

Non-authoritative answer:
example.com text = "v=spf1 ip4:93.184.216.119 -all"

Certificate

サイバートラストBIZCERT等でサーバ証明書を取得します。
(今回は自己署名証明書を利用します。)

Self-signed certificate

opensslコマンドで自己署名証明(オレオレ証明書)を作成します。

$ openssl genrsa -out server.key 2048
$ openssl req -new -key server.key -out server.csr
$ openssl rsa -in server.key -out server.key
$ openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt

秘密鍵証明書のファイルは後ほど利用します。

Files 内容 補足
server.key RSA PRIVATE KEY 秘密鍵
server.csr CERTIFICATE REQUEST 証明書署名要求
server.crt CERTIFICATE 証明書

Delivered

Chef Solo

次はChefのツールでGitLabをインストールします。

Download

インストールにはknife-soloBerkshelfを利用します。

$ gem install berkshelf
$ gem install knife-solo
$ knife configure
$ knife solo init ./gitlab_chef
$ cd ./gitlab_chef/
$ curl -o Berksfile https://gitlab.com/gitlab-org/cookbook-gitlab/raw/master/Berksfile
$ sed -i.bak '/^metadata$/d' Berksfile
$ echo "cookbook 'gitlab', git: 'https://gitlab.com/gitlab-org/cookbook-gitlab.git'" >> Berksfile
$ berks vendor

Provision

ssl_certificatessl_certificate_key証明書秘密鍵の内容を編集します。(改行は\nです。)
knife soloコマンドでGitLabがインストールされます。

$ cat << __EOS__ > ./nodes/example.com.json
{
  "gitlab": {
    "host": "example.com",
    "port": "443",
    "email_from": "gitlab@example.com",
    "url": "https://git.example.com/",
    "ssl_certificate": "-----BEGIN CERTIFICATE-----\nfoo\nbar\nbaz\n-----END CERTIFICATE-----",
    "ssl_certificate_key": "-----BEGIN RSA PRIVATE KEY-----\nqux\nquux\ncorge\n-----END RSA PRIVATE KEY-----"
  }
  "run_list": [
    "gitlab::default"
  ]
}
__EOS__
$ knife solo prepare example.com --bootstrap-version 11.4.4
$ knife solo cook example.com

Self-signed certificate

自己署名証明はconfig.ymlself_signed_certtrueに編集します。

$ ssh example.com
ubuntu@example:~$ sudo editor /home/git/gitlab-shell/config.yml

Mail(SMTP)

Postfix

メールの送信にPostfixを利用します。main.cfを編集してリスタートします。

$ ssh example.com
ubuntu@example:~$ sudo apt-get install postfix
ubuntu@example:~$ sudo editor /etc/postfix/main.cf
ubuntu@example:~$ sudo service postfix restart

Gitlab

production.rbconfig.action_mailer.delivery_method = :sendmail
次行に下記のconfig.action_mailer.sendmail_settingsを追加します。

config.action_mailer.sendmail_settings = {
  location: '/usr/sbin/sendmail',
  arguments: '-i -t'
}

production.rbを編集してリスタートします。

$ ssh example.com
ubuntu@example:~$ sudo editor /home/git/gitlab/config/environments/production.rb
ubuntu@example:~$ sudo service gitlab restart

Inspect

新しいユーザを作成して、プロジェクトを作成します。
さらに公開鍵を追加すると3通のメールが受信されます。

Actions Mail Subject
New User Account was created for you
New project Access to project was granted
Add SSH Key SSH key was added to your account

これで オレオレGitLab が完成です。

logo-black

Tips

Vagrant

VagrantAmazon EC2ではもっとに簡単にGitLabがインストールできます。

Download

Vagrantfileaccess_key_idsecret_access_keyprivate_key_pathkeypair_nameを編集します。

$ gem install berkshelf
$ vagrant plugin install vagrant-berkshelf
$ vagrant plugin install vagrant-omnibus
$ vagrant plugin install vagrant-aws
$ vagrant box add dummy https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box
$ git clone https://gitlab.com/gitlab-org/cookbook-gitlab.git ./gitlab
$ cd ./gitlab/
$ cp ./example/Vagrantfile_aws ./Vagrantfile
$ editor ./Vagrantfile

Provision

Vagrantfilechef.jsonchef.run_listChef Soloと同じように編集します。
vagrant provisionコマンドでGitLabがインストールされます。

$ vagrant up --provider=aws
$ eval $(vagrant ssh-config | awk '/HostName/ {print "HostName=" $2}')
$ sed -i.bak "s/example.com/$HostName/g" Vagrantfile
$ sed -i.bak 's/chef.run_list = \[\]/chef.run_list = \["gitlab::default"\]/g' Vagrantfile
$ vagrant provision

GitLab.orgのProductionも参考にしてください。

7
7
1

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