パスワード管理ツールMortimerのインストール方法

Ruby on Rails製のパスワード管理ツール「Mortimer」を

CentOS6.2にインストールしてみました。

ローカルのサーバーに構築が行えるので、

パスワードをチームで共有したい時などに便利です。


CentOS6.2環境の準備

今回は、以下のURLからCentOS-6.2-x86_64-minimal.isoをダウンロードし、
CentOS6.2環境を構築しました。

http://centos.arcticnetwork.ca/6.2/isos/x86_64/

インストール後は、とりあえずSELinuxをpermissiveにしておきます。

この設定を行わないと、後述するPassengerがうまく動いてくれません。

1
vi /etc/sysconfig/selinux

編集後の/etc/sysconfig/selinuxは↓の様になりました。

1
2
3
4
5
6
7
8
9
10
11
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
# SELINUX=enforcing
SELINUX=permissive
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted

apacheのインストール

apacheをインストールします。
(ついでに自動起動の設定もします)

1
2
yum -y install httpd
chkconfig httpd on

Mortimerはhttps以外ではアクセスできないようになっています。

httpsが使えるように、mod_sslもインストールします。

1
yum -y install mod_ssl

iptablesコマンドで、https用のポートを開けます。

1
iptables -I INPUT 5 -m state --state NEW -p tcp --dport 443 -j ACCEPT

ポートが開いているか確認します。

1
iptables -L --line-numbers

Chain INPUTにhttpsのポートが追加されているのを確認します。

1
2
3
4
5
6
7
8
9
10
11
12
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
2 ACCEPT icmp -- anywhere anywhere
3 ACCEPT all -- anywhere anywhere
4 ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
<span style="color:red">5 ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:https</span>
6 REJECT all -- anywhere anywhere reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
num target prot opt source destination
1 REJECT all -- anywhere anywhere reject-with icmp-host-prohibited

ポートの設定を保存します。

1
service iptables save

Passengerのインストール

passengerのインストールに必要なパッケージをインストールします。

1
2
yum -y install ruby ruby-devel rubygems
gem install rails -v=2.3.2

passengerのコンパイルに必要なパッケージをインストールし、

passengerをインストールします。

1
2
yum -y install gcc make
gem install passenger

passengerのapache用モジュールのコンパイルに必要なパッケージをインストールし、

passengerのapache用モジュールをインストールします。

1
2
yum -y install gcc-c++ httpd-devel openssl-devel readline-devel zlib-devel curl-devel
passenger-install-apache2-module -a

Mortimerのインストール

Mortimerのソースコードはgithub上に公開されているので、

まずはCentOS6.2にgitをインストールします。

1
yum install -y git

Mortimer用のディレクトリを作成し、gitコマンドでMortimerのソースコードをコピーします。

1
2
3
mkdir /var/www/mortimer
cd /var/www/mortimer
git clone https://github.com/aiaio/mortimer.git .

passengerのapache用モジュールに必要な設定ファイルを作成します。

1
passenger-install-apache2-module --snippet > /etc/httpd/conf.d/mortimer.conf

作成したファイルに、Mortimer用の設定を追記します。

1
vi /etc/httpd/conf.d/mortimer.conf

追記後は以下の様になります。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-3.0.11/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-3.0.11
PassengerRuby /usr/bin/ruby

PassengerAppRoot /var/www/mortimer
PassengerMaxPoolSize 20
PassengerMaxInstancesPerApp 4
PassengerPoolIdleTime 3600
PassengerUseGlobalQueue on
PassengerHighPerformance on
PassengerStatThrottleRate 10
RailsSpawnMethod smart
RailsAppSpawnerIdleTime 86400
RailsFrameworkSpawnerIdleTime 0
RailsBaseURI /

apacheのDocumentRootを変更し、Mortimerのpublicディレクトリのパスを設定します。

1
vi /etc/httpd/conf/httpd.conf

以下の様に編集します。

1
2
DocumentRoot "/var/www/html"
DocumentRoot "/var/www/mortimer/public"

Mortimerの初期設定

最後に、Mortimerの管理者アカウントの登録や、
データベースの暗号化キーの設定などの初期設定を行います。

1
rake auth:ten:site_key

データベースの設定ファイルを作成します。

1
vi /var/www/mortimer/config/database.yml

以下の様に記述します。

1
2
3
4
production:
adapter: sqlite3
database: db/mortimer.sqlite3
pool: 5

sqliteを使うためのライブラリをインストールします。

1
2
yum install sqlite-devel
gem install sqlite3-ruby

データベースの作成を行います。

1
rake db:migrate RAILS_ENV=production

管理者アカウント登録等を行う為のスクリプトを実行します。

1
rake setup RAILS_ENV=production

以下の様に、対話形式でアカウント情報を設定します。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
*****mortimer setup for PRODUCTION environment:*****
You are about to create the root accout
along with an initial admin account.
Press any key to continue...

Email:
Password:

Now you'll create the first ADMIN user:
Login:
First name:
Last name:
Email:
Password:

mortimerの実行時にエラーになってしまうので、/var/www/mortimer/root_key.rsa を/rootディレクトリに移動させます。

1
mv /var/www/mortimer/root_key.rsa ~/.

apacheを起動します。

1
service httpd start

最後にWebブラウザで

https://サーバーのIP/

にアクセスして以下のようなログイン画面が表示されればインストール完了です。