はじめに

RedmineにPGP/MIMEプラグインを入れて通知メールの暗号化に成功したので紹介します。Redmineでメールの暗号化で検索すると、STARTTLSやSMTPs、POP3sなどがヒットするのですが、これらの方式はメールサーバが対応していないと使えないですし、メール配送の途中経路は必ずしも暗号化される保証はないですね。その点、S/MIMEかPGP/MIMEであれば、END-ENDで暗号化されますので途中経路を気にする必要がありません。S/MIMEは、現在redmine.orgの#15309にチケット化されていますが、現時点ではまだ実装が進んでいないようです。PGP/MIMEはプラグインとして公開していただいているものがありましたのでこれを使ってみることにします。実際に使ってみようとすると、いくつか嵌りどころがありましたので、この記事で紹介しますね。
 
(この記事は、Redmine アドベントカレンダー2020の11日目の記事です)

環境

Redmineの環境(PGP/MIMEプラグインのインストール前)

Environment:
  Redmine version                4.1.1.stable.19900
  Ruby version                   2.6.5-p114 (2019-10-01) [x86_64-linux]
  Rails version                  5.2.4.2
  Environment                    production
  Database adapter               PostgreSQL
  Mailer queue                   ActiveJob::QueueAdapters::AsyncAdapter
  Mailer delivery                smtp
SCM:
  Subversion                     1.7.14
  Git                            1.8.3.1
  Filesystem                     
Redmine plugins:
  redmine_theme_changer          0.4.0
  view_customize                 2.7.0 

インストールするプラグイン

本家のC3Sのプラグインは2015年以降更新がなくRedmine4.1に対応していないので、freedomofpressさんのfork版を使いました。

プラグインをインストールする

1.ディレクトリを移動する

 ここは迷うことなく、以下のように実行ですね。私の場合はrootでRedmineをインストールしているので、rootユーザで以下のように実行しました。(パスは読み替えてくださいね)

# cd /path/to/redmine/plugins

2.プラグインをクローンする

ここで、プラグインのインストール指示では、

$git clone https://github.com/C3S/redmine_openpgp openpgp

となっているのですが、freedomofpressさんのフォークを使うので以下のようにします。リポジトリの名前”redmine_openpgp”のままではなく、openpgpという名前でcloneしないといけないところ、注意しないといけないですね。
# git clone https://github.com/freedomofpress/redmine_openpgp openpgp

remote: Enumerating objects: 342, done.
remote: Total 342 (delta 0), reused 0 (delta 0), pack-reused 342
Receiving objects: 100% (342/342), 94.97 KiB | 0 bytes/s, done.
Resolving deltas: 100% (167/167), done.

3.署名確認のためのPGPキーをインポートする

$git show pgp | gpg --import

となっています。ただ、カレントディレクトリは/path/to/redmine/pluginsですのでcloneしたディレクトリに移動しないといけません。

# cd openpgp
# git show pgp | gpg --import
gpg: key 1C9182F8: public key "Alexander Blum <ablum@uos.de>" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
gpg: no ultimately trusted keys found

 4.署名を確認する

$git tag --verify 1.0

となっています。実行してみるとエラーでます。 署名が2015年に作成されたものなので、期限が切れているようです。ここは気にせずに進めることにします。

 # git tag --verify 1.0
object a22a9beb9079a4b413cfd5704c5bb5500a05262f
type commit
tag 1.0
tagger Alexander Blum <alexander.blum@c3s.cc> 1441337250 +0200

release version 1.0
gpg: Signature made Fri 04 Sep 2015 12:27:30 PM JST using RSA key ID 1C9182F8
gpg: Good signature from "Alexander Blum <ablum@uos.de>"
gpg:                 aka "Alexander Blum <a.blum@free-reality.net>"
gpg:                 aka "Alexander Blum (C3S) <alexander.blum@c3s.cc>"
gpg:                 aka "Alexander Blum <a.blum@comlot.de>"
gpg: Note: This key has expired!
Primary key fingerprint: 43AA 9302 3596 C83C 452E  63BB FB6A CC7A 1C91 82F8
error: could not verify the tag '1.0'

 

5.現在のリリースタグに移動

$git checkout tags/1.0

 となっています。ん?1.0は古いやん。これをチェックアウトしたらデグレしてしまいますので実行しません。

6.Redmineのルートディレクトリに戻る

これは指示どおり実行します。
 # cd /path/to/redmine/

 7.gemをインストールします

以下のように必要なgemがインストールされます

# bundle install

Don't run Bundler as root. Bundler can ask for sudo if it is needed, and

installing your bundle as root will break this application for all non-root users on this machine.

The dependency tzinfodata (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x64-mingw32, x86-mswin32. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x64-mingw32 x86-mswin32`.

The dependency ffi (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x64-mingw32, x86-mswin32. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x64-mingw32 x86-mswin32`.

Fetching gem metadata from https://rubygems.org/..........

Fetching gem metadata from https://rubygems.org/.

Resolving dependencies...

  ・

  ・

 8.データベースのマイグレーションをします

$RAILS_ENV=production bundle exec rake redmine:plugins:migrate

# RAILS_ENV=production bundle exec rake redmine:plugins:migrate

== 1 CreatePgpkeys: migrating ================================================

-- create_table(:pgpkeys)

  -> 0.0436s

== 1 CreatePgpkeys: migrated (0.0436s) ======================================== 

9.Redmineを再起動します

インストール指示には以下のように書かれていますが、自分の環境にあったやり方でRedmineを再起動します。

$sudo service apache2 restart

10.Redmineを実行しているユーザにsuします

インストール指示は以下のようになっています。

$su redmine

私の環境ではRedmineはapacheユーザで実行されています。 apacheはnologinユーザなので、ログインするときに-s /bin/bashオプションをつけます。apacheにsuしようとすると、apacheの実行シェルは/sbin/nologinになっていますのでsuすることができません。そこで、apacheユーザのshを通常の/bin/bashに変更します。 また、apacheユーザのホームディレクトリをapacheユーザの所有に変更し、apacheユーザになりました。
# chown -R apache.apache /usr/share/httpd

# su - apache -s /bin/bash

bash-4.2$ whoami

apache

11.gpgリングが作成されていることを確認する

以下の指示にしたがい、コマンドをうってみたら、新たなキーリングが作成された、というようなメッセージが表示されました。次に進みます。

$gpg --list-keys  

# gpg --list-keys
gpg: directory `/usr/share/httpd/.gnupg' created
gpg: new configuration file `/usr/share/httpd/.gnupg/gpg.conf' created
gpg: WARNING: options in `/usr/share/httpd/.gnupg/gpg.conf' are not yet active during this run
gpg: keyring `/usr/share/httpd/.gnupg/pubring.gpg' created
gpg: /usr/share/httpd/.gnupg/trustdb.gpg: trustdb created

 

 12.Redmineを実行しているユーザのホームディレクトリにあるgpgリングのディレクトリの所有ユーザが正しいか確認する。

インストール指示は以下のようになっています。redmineユーザではなくapacheユーザに変更します。(10の手順でchown実行済みなので、すでに所有者はapacheになっていますけど)

$chown redmine ~/.gnupg

# chown apache.apache ~/.gnupg
# ls -l ~/.gnupg
total 28
-rw------- 1 apache apache 7680 Dec 11 02:43 gpg.conf
-rw------- 1 apache apache 6012 Dec 11 02:43 pubring.gpg
-rw------- 1 apache apache    0 Dec 11 02:43 secring.gpg
-rw------- 1 apache apache 1200 Dec 11 02:43 trustdb.gpg

 

 

関連記事

RedmineにPGP/MIMEプラグインを入れてみた(その2)

RedmineにPGP/MIMEプラグインを入れてみた(その3)