SELinux関連のドキュメント

hbstudy# 28 SELinux HandsOn 公開版
http://www.slideshare.net/ishikawa84g/hbstudy-28-selinuxhandson
SELinuxの必要性や問題の調べ方・対応方法についてひと通り書いています。

Red Hat Enterprise Linux 6.4 Security-Enhanced Linux ユーザーガイド
https://access.redhat.com/site/documentation/ja-JP/Red_Hat_Enterprise_Linux/6/html/Security-Enhanced_Linux/index.html
RedHatの公式資料の日本語版。6.5の日本語版はまだありませんでした。
SELinuxの資料はFedraかRedHatを漁れば出てきます。

SELinux Project Wiki
http://selinuxproject.org/page/Main_Page
Additional Resourcesに様々な情報のリンクがあるので、キーワードを知らない時はググる前にこちらを参照してみると良いと思います(ググるとdisabled率が高いし)。

Download a Reference Policy Release
http://oss.tresys.com/projects/refpolicy/wiki/DownloadRelease
最新のポリシーファイルが公開されています。
selinux-policy-targetedの最新は http://rpmfind.net/linux/rpm2html/search.php?query=selinux-policy-targeted では3.13.1-45(fc21)だそうですが、CentOS-Baseだと3.7.19-231になってしまいます。運用面を考えるとRPMを入れた方が楽なのですが、とりあえずアプリケーションの動作を確認したいためなら、こちらからソースを取得した方が簡単です。ちなみに、zabbixは最新は1.7.0でしたが、3.7.19-231のポリシーだと1.2.0でした。

 

書籍については、SELinux System Administration Kindle版が入手しやすいと思います。
 

SELinux System Administration

SELinux System Administration

 

 

日本語訳版のSELinuxシステム管理は絶版になっていますが、丸善紀伊國屋書店にはまだあるかもしれません。ネットで調べて在庫のある店舗を見つけたら、近所の店舗に送ってもらえます。

 

SELinuxシステム管理 ―セキュアOSの基礎と運用

SELinuxシステム管理 ―セキュアOSの基礎と運用

 

 

 ※2014/4/14 追記

 

Download a Reference Policy Release

ポリシーファイルのリポジトリはこちらです。

http://oss.tresys.com/git/refpolicy-contrib.git

このリポジトリの開発メーリングリストはこちらです。

http://oss.tresys.com/mailman/listinfo/refpolicy

 

 

githubにリポジトリを登録する

 よく忘れてしまうので、メモ。

  1. SSH鍵を作成する(初回のみ)
    ssh-keygen -t rsa -C "mail address"
  2. githubで作成した公開鍵を登録する
     Keyの欄に、~/.ssh/id_rsa.pub の中身を貼り付けます。
    f:id:wankomagic:20131020113536p:plain
  3. githubでリポジトリを作成する

    f:id:wankomagic:20131020113820p:plain

  4. 自分の環境をリポジトリに登録する
     githubでリポジトリを作成すると、登録するためのコマンドが表示されるので、この通り実行する。

    f:id:wankomagic:20131020120513p:plain

DevOpsDays TOkyo 2013に行きました

プログラム: http://devopsdays.org/events/2013-tokyo/ja/program/

USTREAM: http://ustre.am/14dK3

Togetter: http://togetter.com/li/570042

 

 今年はヤフーさんで行われました。ちゃんと机があるっていいですね。参加登録は満席だったのに、結構席が空いてるのが気になりますが。

 感覚的なのですが、昨年はDevOpsって何か、インフラ構築をプログラミングしましょう(chef/puppet)、うまく回すためにこんなツールがあります(CIとか)、といった話だったのが、今年はモニタリングでDevとOpsとBizでコミュニケーションできるようにしましょう、といった話が増えてきた気がします。オープンスペースは相変わらずChefの話のようでしたが(参加してなくて、議題を見ただけなので、具体的にはわかりませんが)。Zabbix, muninは使っていますが、他のものはあまり使っていないので、今後試してみるつもりです。

 あとはジョブスケジューリングをコード化したいけれど、みんなはどうしているのでしょうか。

 

muninのズーム機能をSELinuxを有効にした状態で利用する

 muninの各グラフはCGIによりズーム表示することができます。2.0.16ではデフォルトで設定されているのですが、2.0.6では少し手を加える必要があります。

 

環境

手順

ズーム機能の設定

 http://d.hatena.ne.jp/pospome/20130221/1361447896 を参考にさせて頂きました。

  1. munin-cgi がインストールされていない場合はインストールする
  2. muninの設定ファイル /etc/munin/munin.conf に次の記述がなければ追記する
    cgiurl_graph /munin-cgi/munin-cgi-graph
  3. httpdの設定ファイル /etc/httpd/conf.d/munin.conf に次の記述がない場合は追記する
    ScriptAlias /munin-cgi/munin-cgi-graph /var/www/cgi-bin/munin-cgi-graph
  4. httpdのCGI設定ファイル /etc/httpd/conf.d/munin-cgi.conf がある場合は削除する
  5. munin-node と httpd を再起動する

 

SELinuxのポリシーファイルの作成

 SELinuxを無効にしておくとグラフが個別に表示され、ズームすることができるのですが、有効にしておくと、グラフが表示されません。setroubleshootパッケージをインストールしておけば、/var/log/audit/audit.logにdeniedが出力されるので、これをもとに、ポリシーファイルを作成します。エラーは次のようなものが出力されます(何度かアクセスエラー+設定を繰り返します)。

type=AVC msg=audit(1374249069.044:764787): avc:  denied  { search } for  pid=31282 comm="munin-cgi-graph" name="munin" dev=sda2 ino=281106 
scontext=unconfined_u:system_r:httpd_sys_script_t:s0 
tcontext=system_u:object_r:munin_var_lib_t:s0 
tclass=dir

type=AVC msg=audit(1374249989.708:764820): avc:  denied  { getattr } for  pid=32987 comm="munin-cgi-graph" path="/var/lib/munin/datafile.storable" dev=sda2 ino=304179 
scontext=unconfined_u:system_r:httpd_sys_script_t:s0 
tcontext=system_u:object_r:munin_var_lib_t:s0 
tclass=file

type=AVC msg=audit(1374250204.627:764848): avc:  denied  { unix_read unix_write } for  pid=33159 comm="mysql_network_t" key=1667461225  
scontext=unconfined_u:system_r:munin_services_plugin_t:s0 
tcontext=system_u:system_r:munin_services_plugin_t:s0 
tclass=shm

type=AVC msg=audit(1374250438.152:764892): avc:  denied  { read } for  pid=33653 comm="munin-cgi-graph" name="datafile.storable" dev=sda2 ino=304184 
scontext=unconfined_u:system_r:httpd_sys_script_t:s0 
tcontext=system_u:object_r:munin_var_lib_t:s0 
tclass=file

type=AVC msg=audit(1374250438.158:764893): avc:  denied  { search } for  pid=33653 comm="munin-cgi-graph" name="munin" dev=sda2 ino=281767 
scontext=unconfined_u:system_r:httpd_sys_script_t:s0 
tcontext=system_u:object_r:munin_log_t:s0 
tclass=dir

type=AVC msg=audit(1374250893.404:765016): avc:  denied  { open } for  pid=34755 comm="munin-cgi-graph" name="datafile.storable" dev=sda2 ino=304185 
scontext=unconfined_u:system_r:httpd_sys_script_t:s0 
tcontext=system_u:object_r:munin_var_lib_t:s0 
tclass=file

type=AVC msg=audit(1374250893.413:765017): avc:  denied  { open } for  pid=34755 comm="munin-cgi-graph" name="munin-cgi-graph.log" dev=sda2 ino=281111 
scontext=unconfined_u:system_r:httpd_sys_script_t:s0 
tcontext=unconfined_u:object_r:munin_log_t:s0 
tclass=file

type=AVC msg=audit(1374251968.585:765185): avc:  denied  { ioctl } for  pid=36533 comm="munin-cgi-graph" path="/var/lib/munin/datafile.storable" dev=sda2 ino=304179 
scontext=unconfined_u:system_r:httpd_sys_script_t:s0 
tcontext=system_u:object_r:munin_var_lib_t:s0 
tclass=file

type=AVC msg=audit(1374251102.485:765022): avc:  denied  { associate } for  pid=34814 comm="mysql_innodb_bp" key=1667461225  
scontext=unconfined_u:system_r:munin_services_plugin_t:s0 
tcontext=system_u:system_r:munin_services_plugin_t:s0 
tclass=shm

type=AVC msg=audit(1374252419.524:765299): avc:  denied  { ioctl } for  pid=37619 comm="munin-cgi-graph" path="/var/lib/munin/datafile.storable" dev=sda2 ino=304185 
scontext=unconfined_u:system_r:httpd_sys_script_t:s0 
tcontext=system_u:object_r:munin_var_lib_t:s0 
tclass=file

type=AVC msg=audit(1374252419.540:765300): avc:  denied  { open } for  pid=37619 comm="munin-cgi-graph" name="munin-cgi-graph.log" dev=sda2 ino=281111 
scontext=unconfined_u:system_r:httpd_sys_script_t:s0 
tcontext=unconfined_u:object_r:munin_log_t:s0 
tclass=file

 これをもとに、次のTEファイルを作成します(仮に、munin-cgi-graph-policy.te とします)。

module munin-cgi-graph-policy 1.0;

require {
  type httpd_sys_script_t;
  type munin_var_lib_t;
  type munin_services_plugin_t;
  type munin_log_t;
  class dir { search };
  class file { getattr read open ioctl };
  class shm { unix_read unix_write associate };
}

allow httpd_sys_script_t munin_var_lib_t:dir { search };
allow httpd_sys_script_t munin_var_lib_t:file { getattr read open ioctl };
allow httpd_sys_script_t munin_log_t:dir { search };
allow httpd_sys_script_t munin_log_t:file { open };
allow munin_services_plugin_t self:shm { unix_read unix_write associate };

 作成したらコンパイルして、適用します。

make -f /usr/share/selinux/devel/Makefile
semodule -i munin-cgi-graph-policy.pp

  セキュリティコンテキストの設定でもっとうまくできないかが今後の課題。

Subversion1.8をRPMでインストールする

 今更Subversionかとも思うし、だからバージョンアップしてもパッケージングされなくてソースコードビルドすることになるんだけど、そのためにまず古いSubversionをインストールしないといけないというRubyみたいなこともしたくないので、パッケージングしてるリポジトリを探したら、WANdiscoという所を見つけました。

 

環境

手順

  1. /etc/yum.repos.d/wandisco.repo というファイルを作成する
    [wandisco]
    name=WANDisco Repository - svn-1.8 centos6
    baseurl=http://opensource.wandisco.com/centos/6/svn-1.8/RPMS/$basearch/
    enabled=0
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-WANdisco
  2. GPGキーを取り込む
    rpm --import http://opensource.wandisco.com/RPM-GPG-KEY-WANdisco
  3. インストールを実行する
     yum install --enablerepo=wandisco --disablerepo=base,updates subversion

  Subversionのためだけなので、普段は無効に。デフォルトだとCentOSのBaseやupdatesの方が優先されるので、対象外にする。

MySQL5.6からMariaDB10.0に移行する(のに失敗した話)

 今までMySQLを使っていたのだけれど、SkySQLとMonty Programの合併でMariaDBに注力されるみたいだし、wikipediaとかいろんなところがMariaDBに乗り換えてるとか聞くし、ZabbixもMariaDBサポート!?みたいな話を人づて(ソース不明)に聞いたので、ちょっと試してみました。

 

環境

 

準備

 https://kb.askmonty.org/en/installing-mariadb-with-yum/

上記サイトを参考に、リポジトリファイルを作成します。

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.0/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
enabled=1
gpgcheck=1

 mysqlは停止させておきます。

 

 updateしてみる

yum update mysql

 を実行してみたところ、こうなりました。

=============================================================
Package Arch Version Repository Size
=============================================================
Installing:
MariaDB-client x86_64 10.0.2-1 mariadb 10 M
replacing MySQL-client.x86_64 5.6.11-2.el6
MariaDB-server x86_64 10.0.2-1 mariadb 33 M
replacing MySQL-server.x86_64 5.6.11-2.el6
Installing for dependencies:
MariaDB-common x86_64 10.0.2-1 mariadb 23 k
MariaDB-compat x86_64 10.0.2-1 mariadb 2.7 M

Transaction Summary
============================================================

 MariaDBのサイトを見ると、 yum install MariaDB-server・・・と書いてますが、mysql と書くと同様の動きをします。MySQLMariaDBはアップグレードらしい。

しかし、これではdevelやsharedが変わらないので、これらを個別に指定する必要があるのですが、shared-compatが競合するため、予め削除する必要があります。つまり、実際には次のコマンドを実行します。

rpm -e MySQL-shared-compat --nodeps
yum update MySQL-server MySQL-client MySQL-devel MySQL-shared

 devel, sharedを追加すると、mysqlでserverとclientがインストール対象にならないので、わざわざ指定しています。

このまま起動すると、バイナリログの差異エラーが出るので、予め削除しておきます。

rm -f /var/lib/mysql/ib_logfile*

起動ファイルが同じ名前で作成されているので、同じように起動します。

service mysql start

すると、次のエラーが出ます。

 Starting MySQL. ERROR! The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid).

なので、skipモードで起動してみます。

mysqld --skip-grant &

すると、起動はされるのですが、起動中に次のエラーメッセージが何件か表示されます。

[ERROR] Incorrect definition of table performance_schema.events_waits_current: expected column 'THREAD_ID' at position 0 to have type int(11), found type bigint(20) unsigned.

performance_schemaのいくつかのテーブルの主キーTHREAD_IDは5.5ではint(11)だったのですが、5.6ではbigint(20)になっています。MariaDBの10.0は5.5に対応しているため、エラーが発生しました。

ちなみに、本環境ではMySQL5.6で書いていますが、別環境のMySQL5.5で同じようにやったところ、正常に起動することができました。

 

インストールしなおす

とすることにしました。古いMySQLをアンインストールして、MariaDBをインストールします。データベースは一旦削除します。これを実行する前にダンプファイルをとっておきます。

rpm -e --nodeps MySQL-server MySQL-client MySQL-shared MySQL-shared-compat MySQL-devel
rm -rf /var/lib/mysql
yum install MariaDB-server MariaDB-client MariaDB-devel MySQL-shared

上記と同じコマンドでサービスを起動して、データをインポートすれば完了です。

 

ZabbixとMariaDBの連携

MySQLMariaDBのコマンド名とかモジュール名がほとんど同じなので、連携できるかなーと思ったのですが、phpmysqlライブラリ側で連携が失敗しました。こちらのサイトの「互換性」の見出しのところに原因と対策が書いています。

http://research.sakura.ad.jp/2013/02/28/mariadb-galera-cluster-3/

 

今回はやってません。