IPsec Labeled Networkingの設定

何気なく redhat-lspp で過去に流れたメールを見ていると、IBMのJoy Lattenが去年の11月に投稿した[redhat-lspp] IPSec Configuration docというメールが目に止まった。
http://www.redhat.com/archives/redhat-lspp/2006-November/msg00051.html

NSASELinux-MLにはポストされていなかったので見落としていたようだ。
IPsecにセキュリティコンテキストを乗せて、ラベル付き通信を行うための方法が記載されている。
折角なので、自分の環境で試してみた。

[必要なもの]
ipsec-tools-0.6.5-6 以降のバージョン
・RedHatEL5のカーネル

ipsec-toolsはFC6のモノでOK。カーネルはFedoraのモノは使えない(※)ので、Steve Grubbのリポジトリから対応カーネルをダウンロードする。
最新カーネルは lspp.67 だが、MLでBUG()を踏んだとか報告が上がっているので、ひとまず kernel-2.6.18-8.el5.lspp.65.i686.rpm を利用することにする。
http://people.redhat.com/sgrubb/files/lspp/

(※) Fedoraのカーネルは、CONFIG_SECURITY_NETWORK_XFRMが有効になっていない。RedHatEL5のSELinuxはFC6と同じだと思ってると、実は痛い目に遭いそうな予感。

[設定]
テスト機を2台用意する。我が家の環境では masu(192.168.11.6) と fc6(192.168.11.8) があり、以降の説明はそれを前提とする。

o SPD(Security Policy Database)へのポリシーの追加
用語がかぶっていて非常に紛らわしいが、これはIPsecの設定。
以下の内容を netlabel.conf という名前で保存し、setkeyコマンドでカーネルにロードする。相手側マシンの場合は、IPアドレスのsrc/destが逆転する。

<strong>[masu(192.168.11.6)での設定]</strong>
spdadd 192.168.11.6 192.168.11.8 any
-ctx 1 1 "system_u:object_r:unlabeled_t:s0"
-P out ipsec
esp/transport//require;

spdadd 192.168.11.8 192.168.11.6 any
-ctx 1 1 "system_u:object_r:unlabeled_t:s0"
-P in ipsec
esp/transport//require;

# setkey -f netlabel.conf

o /etc/racoon/racoon.conf の設定
鍵交換サーバ racoon の設定を行う。fc6(192.168.11.8)に対する通信をIPsec利用とするので、以下の追加設定が必要になる。(太字箇所が追加部分)

[masu(192.168.11.6)での設定]
# Racoon IKE daemon configuration file.
# See 'man racoon.conf' for a description of the format and entries.

path include "/etc/racoon";
path pre_shared_key "/etc/racoon/psk.txt";
path certificate "/etc/racoon/certs";

sainfo anonymous
{
        pfs_group 2;
        lifetime time 1 hour ;
        encryption_algorithm 3des, blowfish 448, rijndael ;
        authentication_algorithm hmac_sha1, hmac_md5 ;
        compression_algorithm deflate ;
}

remote 192.168.11.8
{
        exchange_mode aggressive, main;
        my_identifier address;
        proposal {
                encryption_algorithm 3des;
                hash_algorithm sha1;
                authentication_method pre_shared_key;
                dh_group 2 ;
        }
}

これも、ネットワーク対抗機では "remote 192.168.11.8" の部分だけ異なる。

o /etc/racoon/psk.txt の設定
設定を単純化するために、事前共有鍵(pre shared key)を用いる。以下の設定を加えた。

[masu(192.168.11.6)での設定]
# file for pre-shared keys used for IKE authentication
# format is:  'identifier' 'key'
# For example:
#
#  10.1.1.1             flibbertigibbet
#  www.example.com      12345
#  foo@www.example.com  micropachycephalosaurus
192.168.11.8        sushikuitai

以上で設定は終わり。racoon を起動すると、IPsec Labeld Networking が可能な状態となる。

[実行例]
実際に通信してみた。接続するのはもちろん SE-PostgreSQL である。

[root@fc6 ~]# id -Z
root:system_r:unconfined_t:SystemLow-SystemHigh
[root@fc6 ~]# psql -q -h 192.168.11.6 -Ukaigai postgres
postgres=# select sepgsql_getcon();
                 sepgsql_getcon
                                                                                                • -
root:system_r:unconfined_t:SystemLow-SystemHigh (1 row) postgres=#

接続元は SystemLow-SystemHigh なので、コンテキストを取得できている。
これだけではアレなので、別のセキュリティコンテキストから接続してみた。

[root@fc6 ~]# runcon -l s0:c0.c2 bash
[root@fc6 ~]# id -Z
root:system_r:unconfined_t:s0:c0.c2
[root@fc6 ~]# psql -q -h 192.168.11.6 -Ukaigai postgres
postgres=# select sepgsql_getcon();
           sepgsql_getcon
                                                                        • -
root:system_r:unconfined_t:s0:c0.c2 (1 row) postgres=#

キタ--------(・∀・)--------!!!!
というわけです。
IPsec Labeled Networkingに関しては、動向をあまり追えていないので、細かい挙動を調べるのは後回しにして、とりあえず動かすところまではOK…と。