Chroot-BIND8 HOWTO <author>Scott Wunsch, <tt>scott at wunsch.org</> <date>v1.4, 1 July 2001 <trans>中野武雄 <tt>nakano at apm.seikei.ac.jp</> <tdate>v1.4j1, 3 January 2002 <abstract> <!--O This document describes installing the BIND 8 nameserver to run in a chroot jail and as a non-root user, to provide added security and minimise the potential effects of a security compromise. This version of the document covers the old but still popular BIND 8; there is another document which provides similar information for BIND 9. --> この文書は BIND 8 のネームサーバを "chroot jail" の内部で、 非 root ユーザとして実行させるような インストールのやり方を説明します。 これによってセキュリティが強化され、 またセキュリティが破られたときも影響を最小限にできます。 こちらの文書は、昔の (でも依然としてよく使われている) BIND 8 を対象にしています。 BIND 9 に対して同様の情報を提供する、別の文書もあります。 </abstract> <!-- Table of contents --> <toc> <!-- Begin the document --> <!--O <sect>Introduction --> <sect>はじめに <p> <!--O This is the Chroot-BIND8 HOWTO; see <ref id="where" Name="Where?"> for the master site, which contains the latest copy. It is assumed that you already know how to configure and use BIND (the Berkeley Internet Name Domain). If not, I would recommend that you read the DNS HOWTO first. It is also assumed that you have a basic familiarity with compiling and installing software on your UNIX-like system. --> この文書は Chroot-BIND8 HOWTO です。 最新版の置かれているマスターサイトは <ref id="where" Name="Where?"> を見てください。 読者は BIND (the Berkeley Internet Name Domain) の設定方法・利用方法を 既に知っているとして話を進めます。 知らない人は、まず DNS HOWTO を読むと良いでしょう。 またお使いの UNIX 系システムにおけるコンパイル・インストールについては、 読者は習熟しているものとします。 <sect1>What? <p> <!--O This document describes some extra security precautions that you can take when you install BIND. It explains how to configure BIND so that it resides in a ``chroot jail'', meaning that it cannot see or access files outside its own little directory tree. We shall also configure it to run as a non-root user. --> この文書は、BIND のインストール時に取ることのできる、 付加的なセキュリティ対策について説明します。 まず、BIND を ``chroot jail'' の内部で動作させるよう 設定する方法について説明します。 すなわち、BIND は閉じ込められた小さなディレクトリツリーの 外部にあるファイルを見ることができなくなるのです。 また、BIND を非 root ユーザで実行させるような設定も行います。 <!--O The idea behind chroot is fairly simple. When you run BIND (or any other process) in a chroot jail, the process is simply unable to see any part of the filesystem outside the jail. For example, in this document, we'll set BIND up to run chrooted to the directory <tt>/chroot/named</>. Well, to BIND, the contents of this directory will appear to be <tt>/</>, the root directory. Nothing outside this directory will be accessible to it. You've probably encounted a chroot jail before, if you've ever ftped into a public system. --> chroot の背後にある考え方は、とても単純です。 BIND (あるいは他のプロセス) を chroot jail の内部で実行すると、 そのプロセスはファイルシステムのうち jail の内部しか見ることができなくなるのです。 例えば、この文書では、BIND を <tt>/chroot/named</> ディレクトリに chroot した状態で実行します。 BIND にとっては、このディレクトリの中身が <tt>/</> のように見えるのです。 このディレクトリの外部には一切アクセスできません。 公開システムに ftp したことのある人は、 おそらく既にこの chroot jail に出会ったことがあると思います。 <sect1>Why? <p> <!--O The idea behind running BIND in a chroot jail is to limit the amount of access any malicious individual could gain by exploiting vulnerabilities in BIND. It is for the same reason that we run BIND as a non-root user. --> なぜ BIND を chroot jail の内部で動作させると良いのでしょうか。 それは、仮に悪い奴が BIND の穴を使ってアクセスを得たとしても、 そのアクセスできる範囲を最小限に制限できるからです。 BIND を非 root ユーザ権限で動作させるのも同じ理由からです。 <!--O This should be considered as a supplement to the normal security precautions (running the latest version, using access control, etc.), not a replacement for them. --> これは通常言われているセキュリティ対策 (最新版を使う、アクセス制限をする、など) の、 いわば「おまけ」とみなすべきで、 これを代替するものと考えてはいけません。 <!--O If you're interested in DNS security, you might also be interested in a few other products. Building BIND with <url url="http://www.immunix.org/products.html#stackguard" name="StackGuard"> would probably be a good idea for even more protection. Using it is easy; it's just like using ordinary gcc. Also, <url url="http://cr.yp.to/dnscache.html" name="DNScache"> is a secure replacement for BIND, written by Dan Bernstein. Dan is the author of qmail, and DNScache appears to follow a similar philosophy. --> 読者が DNS のセキュリティに興味をお持ちなら、 他の製品を調べてみるのも良いかもしれません。 BIND を <url url="http://www.immunix.org/products.html#stackguard" name="StackGuard"> と共に構築すれば、きっと安全性をより向上させてくれるでしょう。 使い方は簡単です。普通の gcc と同じです。 また Dan Bernstein の書いた <url url="http://cr.yp.to/dnscache.html" name="DNScache"> は、BIND の代わりに利用できる安全なソフトウェアです。 【訳注: <url url="http://cr.yp.to/djbdns.html" name="djbdns"> に改名したようです】 Dan は qmail の著者でもあります。 <sect1>Where?<label id="where"> <p> <!--O The latest version of this document is always available from the web site of the Linux/Open Source Users of Regina, Sask., at <url url="http://www.losurs.org/docs/howto/Chroot-BIND8.html">. --> この文書の最新版は、常に Linux/Open Source Users of Regina, Sask. の web サイトより入手できます。 <url url="http://www.losurs.org/docs/howto/Chroot-BIND8.html"> です。 <!--O There is now a Japanese translation of this document, maintained by <tt>nakano at apm.seikei.ac.jp</>. This is available at <url url="http://www.linux.or.jp/JF/JFdocs/Chroot-BIND8-HOWTO.html">. --> 現在はこの文書の日本語版もあり、 中野武雄 <tt>nakano at apm.seikei.ac.jp</> が管理しています。 これは <url url="http://www.linux.or.jp/JF/JFdocs/Chroot-BIND8-HOWTO.html"> から入手できます。 <!--O BIND is available from <url url="http://www.isc.org/" name="the Internet Software Consortium"> at <url url="http://www.isc.org/bind.html">. As of this writing, the current version of BIND 8 is 8.2.4. BIND 9.x has now been released, and has been around for a little while. You may consider upgrading to it; the chroot process is certainly much simpler and cleaner. If you are running BIND 9, then you want the Chroot-BIND HOWTO, which should be available from the same location as this document. --> BIND は <url url="http://www.isc.org/" name="the Internet Software Consortium"> の <url url="http://www.isc.org/bind.html"> から入手できます。この文書の執筆時点での最新版は 8.2.4 です。 BIND 9 が使えるようになってからだいぶたち、 実際の業務に使っている人も多いようです。 こちらでは chroot の処理がかなり簡単かつ見通し良くなっていますので、 そろそろアップグレードを考えてもいいかもしれません。 BIND 9 を使っている方は、 Chroot-BIND HOWTO をご覧になってください。 この文書と同じ場所にあるはずです。 <!--O Keep in mind that there are <bf>known</> security holes in all versions of BIND 8 less than <bf>8.2.3</>, so make very sure that you're running the latest version! --> <bf>8.2.3</> より前のすべてのバージョンの BIND 8 には、 <bf>既知の</>セキュリティホールがあります。 必ず最新版を使うように、気をつけてください! <sect1>How? <p> <!--O I wrote this document based on my experiences in setting BIND up in a chroot environment. In my case, I already had an existing BIND installation in the form of a package that came with my Linux distribution. I'll assume that most of you are probably in the same situation, and will simply be transferring over and modifying the configuration files from your existing BIND installation, and then removing the package before installing the new one. Don't remove the package yet, though; we may want some files from it first. --> 私はこの文書を、 自分自身で chroot 環境な BIND をセットアップした経験に基づいて書きました。 私の場合は、既に BIND を (自分の Linux ディストリビューションの) パッケージ形式でインストールしてありました。 おそらく読者のほとんども同じでしょう。 ですので、ここでは既にインストール済みの BIND から 設定ファイルを移動して修正し、パッケージは削除して、 新しいのをインストールすることにします。 でもまだパッケージは削除しないでくださいね。 まずそこからいくつかファイルが必要になりますから。 <!--O If this is not the case for you, you should still be able to follow this document. The only difference is that, where I refer to copying an existing file, you first have to create it yourself. The DNS HOWTO may be helpful for this. --> まだ BIND をインストールしていない人でも、 この文書の方法を利用することはできます。 違いは、私が既存のファイルをコピーしてくるよう指示した部分で、 そのファイルをゼロから書き起こす必要がある、というだけです。 この際には DNS HOWTO が役に立つでしょう。 <!--O <sect1>Disclaimer --> <sect1>おことわり <p> <!--O These steps worked for me, on my system. Your mileage may vary. This is but one way to approach this; there are other ways to set the same thing up (although the general approach will be the same). It just happens that this was the first way that I tried that worked, so I wrote it down. --> これらの記述は私のシステムでは動作しました。 しかし読者のところでの結果は異なるかもしれません。 これは 1 つのアプローチに過ぎず、 同様の設定を行うにはいろいろな方法が有り得ます (一般的なアプローチはだいたい同じになるでしょうが)。 これは、私が試みた中で最初に動作したやり方だったので、 ここに書き記したにすぎません。 <!--O My BIND experience to date has been installing on Linux servers. However, most of the instructions in this document should be easily applicable to other flavours of UNIX as well, and I shall try to point out differences of which I am aware. --> 私の現在までに至る BIND の経験では、 Linux サーバにしかインストールを行っていません。 しかし、この文書の説明の大半は、 他の種類の UNIX にも容易に適用できるはずです。 私の気付いた違いについては、 できるだけ記述するつもりです。 <!--O <sect>Preparing the Jail --> <sect>jail の用意 <!--O <sect1>Creating a User --> <sect1>ユーザの作成 <p> <!--O As mentioned in the introduction, it's not a good idea to run BIND as root. So, before we begin, let's create a separate user for BIND. Note that you should never use an existing generic user like <tt>nobody</> for this purpose. However, some distributions, such as SuSE and Linux Mandrake have started providing a specific user (generally called <tt>named</>); you can simply adapt this user for our purposes, if you like. --> 「はじめに」で述べたように、 BIND を root 権限で実行するのはあまり良い考えではありません。 従って、まず最初に BIND 専用のユーザを作りましょう。 この目的に、<tt>nobody</> のような既存の一般向けユーザは、 決して使うべきではありません。 しかし、SuSE や Linux Mandrake など、 最初からこのためのユーザ (普通 <tt>named</> という名前) を用意しているディストリビューションもあるので、 その場合はお望みならこのユーザを用いても構いません。 <!--O This requires adding a line something like the following to <tt>/etc/passwd</>: --> さて、ユーザを追加するには、次のような行を <tt>/etc/passwd</> に加えます。 <tscreen><verb> named:x:200:200:Nameserver:/chroot/named:/bin/false </verb></tscreen> <!--O And one like this to <tt>/etc/group</>: --> そして次の行を <tt>/etc/group</> に加えます。 <tscreen><verb> named:x:200: </verb></tscreen> <!--O This creates a user and group called <tt>named</> for BIND. Make sure that the UID and GID (both 200 in this example) are unique on your system. The shell is set to <tt>/bin/false</> because this user will never need to log in. --> これで BIND 用の <tt>named</> というユーザとグループができました。 UID と GID (この例では両方とも 200) が、 お使いのシステムで他と重なっていないように注意しましょう。 このユーザはログインする必要がないので、 シェルは <tt>/bin/false</> にしてあります。 <!--O <sect1>Directory Structure --> <sect1>ディレクトリ構造 <p> <!--O Now, we must set up the directory structure that we will use for the chroot jail in which BIND will live. This can be anywhere on your filesystem; the truly paranoid may even want to put it on a separate volume. I shall assume that you will use <tt>/chroot/named</>. Let's start by creating the following directory structure: --> 次に、chroot jail に使用するディレクトリ構造を作ってあげる必要があります。 ここが BIND の生活の場となるわけです。 これはファイルシステムのどこでも構いません。 非常に神経質な人は、独立したボリューム (パーティション) に置きたいとさえ思うかもしれませんね。 ここでは <tt>/chroot/named</> を使います。 まず以下のようなディレクトリ構造を作ってください。 <tscreen><verb> /chroot +-- named +-- bin +-- dev +-- etc | +-- namedb +-- lib +-- var +-- run </verb></tscreen> 【訳注: Debian ユーザでバイナリの再コンパイルを行いたくない人 (後述) は、 <tt>/chroot/named/etc/namedb</> を <tt>/chroot/named/etc/bind</> としましょう】 <!--O <sect1>Placing the BIND Data --> <sect1>BIND のデータを配置する <p> <!--O Assuming that you have already done a conventional installation of BIND and are using it, you will already have an existing <tt>named.conf</> and zone files. These files must now be moved (or copied, to be safe) into the chroot jail, so that BIND can get at them. <tt>named.conf</> goes in <tt>/chroot/named/etc</>, and the zone files can go in <tt>/chroot/named/etc/namedb</>. For example: --> 既に通常のかたちで BIND がインストールできていて、 これを利用しているなら、 <tt>named.conf</> ファイルとゾーンファイルがあるはずです。 これらのファイルは chroot jail の中に移動 (あるいは安全にやるならコピー) して、BIND から見えるようにしてやる必要があります。 <tt/named.conf/ は <tt>/chroot/named/etc</> へ、 ゾーンファイルは <tt>/chroot/named/etc/namedb</> へ移動します。 例えば: <tscreen><verb> # cp -p /etc/named.conf /chroot/named/etc/ # cp -a /var/named/* /chroot/named/etc/namedb/ </verb></tscreen> 【訳注: Debian の場合は named.conf の場所は <tt>/chroot/named/etc/bind</> になります。 ゾーンファイルの置き場所は <tt/named.conf/ 中の記述に依存するのですが、 通常は <tt/named.conf/ と同じディレクトリになっています。】 <!--O BIND will likely need to write to the <tt>namedb</> directory, and probably some of the files in it. For example, if your DNS serves as a slave for a zone, it will have to update that zone file. Also, BIND can dump statistical information, and does so in this directory. For that reason, you should probably make the <tt>named</> user the owner of this directory and its contents: --> BIND はおそらく <tt/namedb/ ディレクトリと、 そこに置かれたファイル (の一部) に対する書きこみ権限を必要とします。 例えば、お使いの DNS があるゾーンをスレーブでサービスするなら、 BIND はそのゾーンファイルを更新できなければなりません。 また BIND は統計情報をダンプできますので、 それもこのディレクトリに書けるようにしてやる必要があります。 これらの理由から、このディレクトリ (とその中身) の 所有者は <tt/named/ ユーザにしておくべきでしょう。 <tscreen><verb> # chown -R named:named /chroot/named/etc/namedb </verb></tscreen> 【訳注:<label id="trans_named.conf"> 具体的には、<tt/named.conf/ の &dquot;options&dquot; 宣言中の directory 文が、 これらの書きこみが行われるディレクトリになります。 これはゾーンファイルのパス指定のベースディレクトリでもあります。 Debian の流儀ですと、 この directory は <tt>/var/cache/named</> になっており、 各ゾーンファイルはフルパスで指定するかたちになっています。 この場合は <tscreen><verb> # mkdir -p /chroot/named/var/cache/namedb # chown -R named:named /chroot/named/var/cache/namedb </verb></tscreen> などとすることになるでしょう。】 <!--O BIND will also need to write to the <tt>/var/run</> directory, to put its pidfile and ndc socket there, so let's allow it to do so: --> BIND は <tt>/var/run</> ディレクトリにも書きこみ権限を必要とします。 pid ファイルと ndc ソケットをここに作るからです。 次のコマンドでこれを可能にしてやりましょう。 <tscreen><verb> # chown named:named /chroot/named/var/run </verb></tscreen> <!--O <sect1>System Support Files --> <sect1>システムのサポートファイル <p> <!--O Once BIND is running in the chroot jail, it will not be able to access files outside the jail <bf>at all</>. However, it needs to access a few key files, such as the system's C library. Exactly what libraries are required will depend on your flavour of UNIX. For most modern Linux systems, the following commands will be sufficient to put the necessary libraries in place: --> BIND が chroot jail 内部での実行を始めると、 jail 外部のファイルへは<bf>一切</>アクセスできなくなります。 しかし、システムの C ライブラリなど、 いくつかの重要なファイルには実行後もアクセスできなければなりません。 実際にどのライブラリが必要になるかは、お使いの UNIX OS に依存します。 最新の Linux システムなら、 以下のコマンドを利用すれば必要なファイルを 適切な場所にちゃんと配置してくるはずです。 <tscreen><verb> # cd /chroot/named/lib # cp -p /lib/libc-2.*.so . # ln -s libc-2.*.so libc.so.6 # cp -p /lib/ld-2.*.so . # ln -s ld-2.*.so ld-linux.so.2 </verb></tscreen> <!--O As an alternative, you could simply build statically-linked versions of the BIND binaries to put in your chroot jail. You should also copy <tt>ldconfig</> into the jail, and run it to create an <tt>etc/ld.so.cache</> for the jail environment. The following commands could take care of this: --> こうする代わりに、BIND のバイナリを静的にリンクしてビルドし、 これを chroot jail 以下に置いて利用することも可能です。 <tt>ldconfig</> も jail の内部にコピーして実行し、 jail 環境用の <tt>etc/ld.so.cache</> を作りましょう。 次のコマンドがこれを行います: <tscreen><verb> # cp /sbin/ldconfig /chroot/named/bin/ # chroot /chroot/named /bin/ldconfig -v </verb></tscreen> <!--O BIND needs one more system file in its jail: good ol' <tt>/dev/null</>. Again, the exact command necessary to create this device node may vary from system to system; check your <tt>/dev/MAKEDEV</> script to be sure. Some systems may also require <tt>/dev/zero</>. For most Linux systems, we can use the following command: --> BIND はもう一つファイルを jail の内部に必要とします。 いつもの <tt>/dev/null</> です。 ここでも、このデバイスノードを作るために必要なコマンドは システムによって異なるでしょう。 <tt>/dev/MAKEDEV</> スクリプトを調べて確認してください。 システムによっては <tt>/dev/zero</> が必要なこともあります。 ほとんどの Linux システムでは、以下のコマンドが使えます。 <tscreen><verb> # mknod /chroot/named/dev/null c 1 3 </verb></tscreen> 【訳注 <tscreen><verb> # chmod go+w /chroot/named/dev/null </verb></tscreen> も必要だと思います。】 <!--O Finally, you need a couple extra files in the <tt>/etc</> directory inside the jail. In particular, you must copy <tt>/etc/localtime</> (this sometimes known as <tt>/usr/lib/zoneinfo/localtime</> on some systems) in there so that BIND logs things with the right time on them, and you must make a simple <tt>group</> file with the <tt>named</> group in it. The following two commands will take care of this: --> 最後に、さらにファイルを 2〜3、jail 内部の <tt>/etc</> ディレクトリに 持ってくる必要があります。 特に <tt>/etc/localtime</> (システムによっては <tt>/usr/lib/zoneinfo/localtime</> かもしれません) が、 BIND に正しい時刻でログ記録をさせるには必要です。 また <tt>named</> グループの含まれる簡単な <tt>group</> ファイルも作成する必要があります。 以下のコマンドがこれらの面倒を見てくれます。 <tscreen><verb> # cp /etc/localtime /chroot/named/etc/ # echo 'named:x:200:' > /chroot/named/etc/group </verb></tscreen> <!--O Keep in mind that the GID, 200 in this example, must match the one you defined in the real <tt>/etc/group</> above. --> GID (この例では 200) にご注目。 先に本当の <tt>/etc/group</> で定義したものと同じにしなければなりません。 <!--O <sect1>Logging<label id="logging"> --> <sect1>ログ記録<label id="logging"> <p> <!--O Unlike a conventional jailbird, BIND can't just scribble its log entries on the walls :-). Normally, BIND logs through <tt>syslogd</>, the system logging daemon. However, this type of logging is performed by sending the log entries to the special socket <tt>/dev/log</>. Since this is outside the jail, BIND can't use it any more. Fortuantely, there are a couple options to work around this. --> 本物の囚人とは異なり、BIND はログ記録を壁に書くことはできません :-)。 通常 BIND はログを、システムのロギングデーモンである <tt/syslogd/ 経由で記録します。 このタイプのログ記録は、特殊なソケットである <tt>/dev/log</> を通してログエントリを送信することで行われます。 しかしこれは jail の外部にありますから、BIND からは使えません。 でもありがたいことに、これを解決する方法はいくつか存在します。 <!--O <sect2>The Ideal Solution --> <sect2>理想的な解 <p> <!--O The ideal solution to this dilemma requires a reasonably recent version of <tt>syslogd</> which supports the <tt>-a</> switch introduced by OpenBSD. Check the manpage for your <tt>syslogd(8)</> to see if you have such a version. --> このジレンマに対する理想的な解決法には、 OpenBSD で導入された <tt/-a/ スイッチをサポートする、 比較的新しいバージョンの <tt/syslogd/ が必要です。 <tt/syslogd(8)/ の man ページをチェックして、 自分の使っているのがこれかどうか見てください。 <!--O If you do, all you have to do is add the switch ``<tt>-a /chroot/named/dev/log</>'' to the command line when you launch <tt>syslogd</>. On systems which use a full SysV-init (which includes most Linux distributions), this is typically done in the file <tt>/etc/rc.d/init.d/syslog</>. For example, on my Red Hat Linux system, I changed the line --> サポートしていれば、<tt/syslogd/ を起動する際のコマンドラインに ``<tt>-a /chroot/named/dev/log</>'' を追加するだけで OK です。 SysV-init をすべて使っているシステム (Linux ディストリビューションのほとんどはそう) なら、 起動は通常 <tt>/etc/rc.d/init.d/syslog</> ファイルでなされます。 例えば、私の Red Hat Linux システムでは、私は <tscreen><verb> daemon syslogd -m 0 </verb></tscreen> <!--O to --> の行を <tscreen><verb> daemon syslogd -m 0 -a /chroot/named/dev/log </verb></tscreen> と変更しました。 <!--O On Caldera OpenLinux systems, they use a daemon launcher called <tt>ssd</>, which reads configuration from <tt>/etc/sysconfig/daemons/syslog</>. You simply need to modify the options line to look like this: --> Caldera OpenLinux システムでは <tt/ssd/ というデーモンランチャを使っており、 これは設定を <tt>/etc/sysconfig/daemons/syslog</> から読みます。 この中のオプション行を以下のように修正するだけです。 <tscreen><verb> OPTIONS_SYSLOGD="-m 0 -a /chroot/named/dev/log" </verb></tscreen> <!--O Similarly, on SuSE systems, I'm told that the best place to add this switch is in the <tt>/etc/rc.config</> file. Changing the line --> 同様に SuSE システムでは、 このスイッチは <tt>/etc/rc.config</> ファイルに追加するのが良いそうです。 <tscreen><verb> SYSLOGD_PARAMS="" </verb></tscreen> <!--O to read --> という行を <tscreen><verb> SYSLOGD_PARAMS="-a /chroot/named/dev/log" </verb></tscreen> <!--O should do the trick. --> とすれば OK です。 【訳注: Debian なら <tt>/etc/init.d/syslogd</> の <tscreen><verb> SYSLOGD="" </verb></tscreen> という行を <tscreen><verb> SYSLOGD="-a /chroot/named/dev/log" </verb></tscreen> とします。】 <!--O Once you've figured out how to make this change for your system, simply restart <tt>syslogd</>, either by killing it and launching it again (with the extra parameters), or by using the SysV-init script to do it for you: --> お使いのシステムでの変更方法がわかったら、 <tt/syslogd/ を再起動するだけです。kill して再び (追加パラメータとともに) 起動してもいいですし、 SysV-init スクリプトを使って次のようにするのでも良いでしょう。 <tscreen><verb> # /etc/rc.d/init.d/syslog stop # /etc/rc.d/init.d/syslog start </verb></tscreen> <!--O Once it's been restarted, you should see a ``file'' in <tt>/chroot/named/dev</> called <tt>log</>, that looks something like this: --> 再起動できたら、<tt>/chroot/named/dev</> に 以下のような <tt/log/ という「ファイル」ができているはずです。 <verb>srw-rw-rw- 1 root root 0 Mar 13 20:58 log</verb> <!--O <sect2>The Other Solutions --> <sect2>別の解 <p> <!--O If you have an older <tt>syslogd</>, then you'll have to find another way to do your logging. There are a couple programs out there, such as <tt>holelogd</>, which are designed to help by acting as a ``proxy'' and accepting log entries from the chrooted BIND and passing them out to the regular <tt>/dev/log</> socket. --> 古い <tt/syslogd/ を使っている場合は、 ログを取るには別の方法を見つけなければなりません。 例えば <tt/hoellogd/ のような、 「プロキシ」として動作するよう設計されているプログラムも存在します。 これは chroot された BIND からログエントリを受け取り、 それを通常の <tt>/dev/log</> ソケットに渡します。 <!--O Alteratively, you can simply configure BIND to log to files instead of going through syslog. See the BIND documentation for more details if you choose to go this route. --> あるいは、BIND を設定して、ログを syslog に送るのではなく ファイルに書きこむようにもできます。 この方法を選ぶなら、BIND の文書にあたって詳細を調べてください。 <!--O <sect>Compiling BIND<label id="compiling"> --> <sect>BIND のコンパイル<label id="compiling"> <p> 【訳注: この章の内容は、 <tt/ndc/ の <tt/-c/, <tt/-p/, <tt/-n/ といったオプションを使えば 解決可能ではないかと思います。 これらはそれぞれ、 <tt/named/ との通信に使うソケット、 pid ファイル、<tt/named/ 本体、をデフォルト以外にするものです (<tt/-n/ は undocumented ですが)。 <tt/ndc/ の実行時に <tt>-c /chroot/named/var/run/ndc</> <tt>-p /chroot/named/var/run/named.pid</> <tt>-n /chroot/named/usr/sbin/named</> を指定してやれば、 ディストリビューションで配布されているバイナリが そのまま使えるかと思います。】 <!--O You should be able to find the BIND source by visiting <url url="http://www.isc.org/bind.html">. You need the <tt>bind-src.tar.gz</> package. Be sure to get the latest version! --> BIND のソースは <url url="http://www.isc.org/bind.html"> で見つかるはずです。 必要なのは <tt>bind-src.tar.gz</> パッケージです。 確実に最新版を入手すること! <!--O <sect1>Modifying Paths --> <sect1>パスの修正 <p> <!--O Things can get a bit confusing at this point, because different parts of the BIND package will be referring to the same directories by different names (depending on whether or not they're running inside the jail). I'll try not to confuse you <bf>too</> much :-). --> ここでちょっと事態は複雑になります。 BIND パッケージの個々の部分が、 同じディレクトリを (jail 内部で実行しているかどうかによって) 別々の名前で参照するからです。 が、できるだけ読者を混乱させないよう頑張ります :-) <!--O The main directory that we have to worry about here is <tt>/var/run</>, because its contents are required for both the main <tt>named</> daemon (inside the jail), and the <tt>ndc</> utility (on the outside). We'll start by setting everything up to find this directory from the outside world. To do this, we need to modify <tt>src/port/linux/Makefile.set</> (substitute your port's directory if you're not running Linux), and change the line --> 特に気をつけなければならないディレクトリが <tt>/var/run</> です。 ここの中身が、メインの <tt/named/ デーモン (jail 内部) と <tt/ndc/ ユーティリティ (jail 外部) の両方で必要となるからです。 まずこのディレクトリが、外部世界から見つかるように全体を設定しましょう。 これを行うには <tt>src/port/linux/Makefile.set</> (Linux 以外を使っている人は別のディレクトリです) の <tscreen><verb> DESTRUN=/var/run </verb></tscreen> <!--O to --> という行を <tscreen><verb> DESTRUN=/chroot/named/var/run </verb></tscreen> <!--O While you're in there, you may want to change the other destination paths from <tt>/usr</> to <tt>/usr/local</>. --> に修正します。インストール先のパスを <tt>/usr</> から <tt>/usr/local</> へ変更したい人は、 ここでそうしてください。 <!--O Now everything should be able to find that directory... except the <tt/named/ daemon itself, to which it's still just <tt>/var/run</> inside the jail. We can get around this by making a small change in the <tt/named/ source. In the file <tt>src/bin/named/named.h</>, find the line --> これで、すべてのものからディレクトリが見つかるようになったはずです。 ただし、<tt/named/ デーモンを除いては。 これは jail 内部の <tt>/var/run</> を見なければならないのです。 この問題を避けるには、<tt/named/ のソースに少々変更が必要です。 <tt>src/bin/named/named.h</> ファイル中の次の行を見つけてください。 <tscreen><verb> #include "pathnames.h" </verb></tscreen> <!--O and add the following line immediately after it --> この直後に <tscreen><verb> #define _PATH_NDCSOCK "/var/run/ndc" </verb></tscreen> を追加します。 <!--O This way, <tt/named/ will ignore our definition of <tt/DESTRUN/ over in <tt/Makefile.set/ and use the correct location (from its perspective in the chroot jail). You will notice some warnings about redefinitions of _PATH_NDCSOCK when you do the build; just ignore them. --> こうすれば <tt/named/ は先に <tt/Makefile.set/ で定義した <tt/DESTRUN/ を無視し、 (chroot jail から見て) 正しい場所を参照してくれます。 ビルドの最中に _PATH_NDCSOCK が再定義されているという warning が出ますが、無視して構いません。 <!--O <sect1>Doing the Build --> <sect1>ビルドする <p> <!--O You should now be able to compile BIND as normal, following the instructions in the <tt/INSTALL/ file. At this stage, we only want to compile BIND, not install it. Don't go too far when following the <tt/INSTALL/ file. Essentially, it's just <tt/make clean/, <tt/make depend/, and <tt/make/. --> では BIND をコンパイルしましょう。 コンパイルは <tt/INSTALL/ ファイルに従って普通にできます。 この段階では BIND のコンパイルだけを行い、 インストールはしません。 <tt/INSTALL/ ファイルのあまり先のほうまでは行かないように。 実際には <tt/make clean/, <tt/make depend/, <tt/make/ だけを行えば良いです。 <!--O <sect>Installing Your Shiny New BIND<label id="installing"> --> <sect>できたての BIND のインストール<label id="installing"> <p> <!--O I should mention that if you have an existing installation of BIND, such as from an RPM, you should probably remove it before installing the new one. On Red Hat systems, this probably means removing the packages <tt/bind/ and <tt/bind-utils/, and possibly <tt/bind-devel/ and <tt/caching-nameserver/, if you have them. --> 既に BIND が (例えば RPM から) インストール済みなら、 新しい BIND をインストールする前に、それらを削除しておきましょう。 Red Hat のシステムなら、 <tt/bind/ パッケージと <tt/bind-utils/ パッケージを削除すればいいです。 もし <tt/bind-devel/ や <tt/caching-nameserver/ があったら、 それらも削除しておきましょう。 <!--O You may want to save a copy of the init script (e.g., <tt>/etc/rc.d/init.d/named</>), if any, before doing so; it'll be useful later on. --> init スクリプト (<tt>/etc/rc.d/init.d/named</>) があったら、パッケージの削除前にコピーを保存しておくといいでしょう。 後で役に立ちます。 <!--O <sect1>Installing the Tools Outside the Jail --> <sect1>jail 外部へのツールのインストール <p> <!--O This is the easy part :-). Just run <tt/make install/ and let it take care of it for you. You may want to <tt>chmod 000 /usr/local/sbin/named</> afterwards, to make sure you don't accidentally run the non-chrooted copy of BIND. (This is <tt>/usr/sbin/named</> if you didn't tell it to go in <tt>/usr/local/sbin</> like I suggested.) --> これは簡単な方です :-) <tt/make install/ を実行すれば全部やってくれます。 chroot でないほうの BIND を間違って実行しないように、 あとで <tt>chmod 000 /usr/local/sbin/named</> を実行しておくといいかもしれません (先に私がおすすめした <tt>/usr/local/sbin</> を選ばなかった人は、 ここでは <tt>/usr/sbin/named</> になります)。 【訳注: バイナリの再ビルドをしなければ、ここの作業は不要ですね。】 <!--O <sect1>Installing the Binaries in the Jail --> <sect1>バイナリ <p> <!--O Only two parts of the package have to live inside the chroot jail: the main <tt/named/ daemon itself, and <tt/named-xfer/, which it uses for zone transfers. You can simply copy them in from the source tree: --> chroot jail の中で生活する必要があるのは 2 つのプログラムだけです。 メインの <tt/named/ デーモン自身と <tt/named-xfer/ です。後者はゾーン転送に用いられます。 ソースツリーからコピーするだけで OK です。 <tscreen><verb> # cp src/bin/named/named /chroot/named/bin # cp src/bin/named-xfer/named-xfer /chroot/named/bin </verb></tscreen> 【訳注: <label id="trans_dir-structure"> バイナリの再ビルドをしなければ、 ここではパッケージに含まれる <tt/named/, <tt/named-xfer/ を移動すれば良いです。 訳者としましては、 移動先にはデフォルトを反映させて <tt>/chroot/named/usr/sbin</> の方をおすすめしたいのですが。】 <!--O <sect1>Setting up the Init Script --> <sect1>init スクリプトを編集する。 <p> <!--O If you have an existing init script from your distribution, it would probably be best simply to modify it to run <tt>/chroot/named/bin/named</>, with the appropriate switches. The switches are... <it/(drumroll please...)/ --> ディストリビューションに含まれている init スクリプトがあれば、 それを <tt>/chroot/named/bin/named</> を 適切なスイッチとともに起動するよう変更するのが最も簡単でしょう。 スイッチは... <it/(ここでドラムロール...)/ <itemize> <!--O <item><tt/-u named/, which tells BIND to run as the user <tt/named/, rather than <tt/root/. <item><tt/-g named/, to run BIND under the group <tt/named/ too, rather than <tt/root/ or <tt/wheel/. <item><tt>-t /chroot/named</>, which tells BIND to chroot itself to the jail that we've set up. --> <item><tt/-u named/, これは BIND をユーザ <tt/root/ ではなく <tt/named/ で実行します。 <item><tt/-g named/, これは BIND をグループ <tt/root/ や <tt/wheel/ ではなく <tt/named/ で実行します。 <item><tt>-t /chroot/named</>, これはにより BIND は自分自身を (先に用意した) jail に chroot します。 </itemize> <!--O The following is the init script I use with my Red Hat 6.0 system. As you can see, it is almost exactly the same as the way it shipped from Red Hat. I have also modified the <tt>ndc restart</> command so that it restarts the server properly, and keeps it chrooted. You should probably do the same in your init script, even if you don't copy this one. --> 以下の init スクリプトは、著者が自分の Red Hat 6.0 システムで使っているものです。 おわかりのとおり、ほとんどは Red Hat のものと変わりありません。 <tt/ndc restart/ コマンドも少々変更し、 chroot を保ったまま正しくサーバを再起動するようにしてあります。 これをそのままコピーしただけでは使えない場合でも、 お使いの init スクリプトに同じ変更は簡単に行えるはずです。 <code> #!/bin/sh # # named This shell script takes care of starting and stopping # named (BIND DNS server). # # chkconfig: 345 55 45 # description: named (BIND) is a Domain Name Server (DNS) \ # that is used to resolve host names to IP addresses. # probe: true # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ ${NETWORKING} = "no" ] && exit 0 [ -f /chroot/named/bin/named ] || exit 0 [ -f /chroot/named/etc/named.conf ] || exit 0 # See how we were called. case "$1" in start) # Start daemons. echo -n "Starting named: " daemon /chroot/named/bin/named -u named -g named -t /chroot/named echo touch /var/lock/subsys/named ;; stop) # Stop daemons. echo -n "Shutting down named: " killproc named rm -f /var/lock/subsys/named echo ;; status) /usr/local/sbin/ndc status exit $? ;; restart) /usr/local/sbin/ndc -n /chroot/named/bin/named "restart -u named -g named -t /chroot/named" exit $? ;; reload) /usr/local/sbin/ndc reload exit $? ;; probe) # named knows how to reload intelligently; we don't want linuxconf # to offer to restart every time /usr/local/sbin/ndc reload >/dev/null 2>&1 || echo start exit 0 ;; *) echo "Usage: named {start|stop|status|restart}" exit 1 esac exit 0 </code> <!--O On Caldera OpenLinux systems, you simply need to modify the variables defined at the top, and it will apparently take care of the rest for you: --> Caldera OpenLinux システムでは、 先頭付近で定義されている変数を修正し、以下のようにすれば OK です。 <tscreen><verb> NAME=named DAEMON=/chroot/named/bin/$NAME OPTIONS="-t /chroot/named -u named -g named" </verb></tscreen> 【訳注: 先に述べたように、 <tt/ndc/ に <tt/-c/, <tt/-p/, <tt/-n/ などのオプションを用いれば、 バイナリの再コンパイルは訳者の環境では不要でした。 訳者が Debian で使っている init スクリプト (<tt>/etc/init.d/bind</>) を以下に示します。 <code> #!/bin/sh PATH=/sbin:/bin:/usr/sbin:/usr/bin test -x /chroot/named/usr/sbin/named || exit 0 case "$1" in start) echo -n "Starting domain name service: named" start-stop-daemon --start --quiet --exec /chroot/named/usr/sbin/named \ -- -u named -g named -t /chroot/named echo "." ;; stop) echo -n "Stopping domain name service: named" start-stop-daemon --stop --quiet \ --pidfile /chroot/named/var/run/named.pid \ --exec /chroot/named/usr/sbin/named echo "." ;; restart) /usr/sbin/ndc -c /chroot/named/var/run/ndc \ -n /chroot/named/usr/sbin/named \ -p /chroot/named/var/run/named.pid \ "restart -u named -g named -t /chroot/named" ;; reload) /usr/sbin/ndc -c /chroot/named/var/run/ndc \ -n /chroot/named/usr/sbin/named \ -p /chroot/named/var/run/named.pid \ reload ;; force-reload) $0 restart ;; *) echo "Usage: /etc/init.d/bind {start|stop|reload|restart|force-reload}" >&2 exit 1 ;; esac exit 0 </code> バイナリファイル (<tt/named/ と <tt/named-xfer/) の置場所は <ref id="trans_dir-structure" name="ディレクトリ構造に関する訳注"> のところで書いたように、chroot jail 内の <tt>/usr/sbin</> にしています。】 <!--O <sect1>Configuration Changes --> <sect1>設定を変更する <p> <!--O You will also have to add or change a few options in your <tt>named.conf</> to keep the various directories straight. In particular, you should add (or change, if you already have them) the following directives in the <tt>options</> section: --> <tt/named.conf/ にもいくつか追加・修正を行い、 いろいろなディレクトリが正しく動作するようにする必要があります。 特に、以下を <tt/option/ セクションに追加 (あるいはすでにあれば修正) しなければなりません。 <tscreen><verb> directory "/etc/namedb"; pid-file "/var/run/named.pid"; named-xfer "/bin/named-xfer"; </verb></tscreen> <!--O Since this file is being read by the <tt>named</> daemon, all the paths are of course relative to the chroot jail. --> これらのファイルは <tt/named/ デーモンが読むことになるので、 もちろんパスはすべて chroot jail 内部での相対位置になります。 【訳注: <ref id="trans_named.conf" name="named.conf に関する訳注"> のところで書きましたが、 directory は一時ファイルの置き場所であると同時に ゾーンファイルのパス指定のベースディレクトリになるところです。 pid-file はデフォルトと同じなので特に指定の必要はなし、 named-xfer は <ref id="trans_dir-structure" name="ディレクトリ構造に関する訳注"> で書いたように、バイナリを <tt>/chroot/named/usr/sbin</> に置けば指定しなくて良いはずです。】 <!--O Some people have also reported having to add an extra block to their <tt>named.conf</> to get <tt>ndc</> working properly: --> 何人かの人のレポートによれば、 以下の余分なブロックを <tt/named.conf/ に書かないと、 <tt/ndc/ が正しく動作しない、とのことです。 <tscreen><verb> controls { unix "/var/run/ndc" perm 0600 owner 0 group 0; }; </verb></tscreen> <!--O <sect>The End --> <sect>ジ・エンド <!--O <sect1>Launching BIND --> <sect1>BIND の起動 <p> <!--O Everything should be set up, and you should be ready to put your new, more secure BIND into action. Assuming you set up a SysV-style init script, you can simply launch it as: --> これですべての設定が終了しました。新しい、 より安全な BIND を実行に移せる時が来たわけです。 SysV 形式の init スクリプトを用いているなら、 次のように実行するだけです。 <tscreen><verb> # /etc/rc.d/init.d/named start </verb></tscreen> <!--O Make sure you kill any old versions of BIND still running before doing this. --> 実行前に古いバージョンの BIND が実行中だったら kill するのを忘れないように。 <!--O If you take a look at your logs, you should find the initialisation messages that BIND spits out when it loads. (If not, there's a problem with your <ref id="logging" name="logging configuration"> that you need to fix.) Amongst those messages, BIND should tell you that it chrooted successfully, and that it is running as the user and group <tt>named</>. If not, you have a problem. --> ログを見れば、BIND がロードされたときに初期化メッセージを記録しているのが 見つかるはずです (もしなければ、 <ref id="logging" name ="ログ記録"> での設定に問題があり、 修正を要します)。 これらのメッセージの中で、 BIND はうまく chroot できた、 ユーザ/グループ <tt/named/ で起動できた、 いうメッセージを伝えているはずです。 もしそれらがなければ、なにか問題があります。 <!--O <sect1>That's It! --> <sect1>以上! <p> <!--O You can go take a nap now ;-). --> これで安心して眠ることができますね ;-) <!--O <sect>Appendix - Upgrading BIND Later<label id="upgrading"> --> <sect>付録 - 後に BIND をアップグレードするには<label id="upgrading"> <!--O <p>So, you had BIND 8.2.2_P7 all nicely chrooted and tweaked to your taste... and then you hear this nasty rumour that there's a remotely-exploitable root hole in that version too, and you need to upgrade to 8.2.3 right away. Do you have to go through this whole long process to install this new version? --> <p> さて、やっと BIND 8.2.2_P7 がうまく chroot して、 望みのとおりにチューンできました... そうしたら、このバージョンに、 リモートから root を奪えるセキュリティホールが見つかった、 との腹立たしい噂が流れてきました。 すぐに 8.2.3 にアップグレードしなければなりません。 この新しいバージョンでも、 ここまで述べてきた長い手続き全体を繰り返さなければならないのでしょうか? <!--O Nope. In fact, you really just need the section on <ref id="compiling" name="Compiling BIND"> and the first two parts of the section on <ref id="installing" name="Installing BIND"> (installing the binaries outside and inside the jail, respectively). --> いいえ。実際に必要なのは、 <ref id="compiling" name="BIND のコンパイル"> のセクションと、 <ref id="compiling" name="BIND のインストール"> のセクションの最初の 2 つ、 バイナリを jail の内外にそれぞれインストールする作業だけです。 <!--O The rest of the HOWTO deals with setting up the jail and other things like that, which shouldn't need to be altered between versions of BIND. You can just dump the new binaries in over top of the old ones, and you're good to go. But don't forget to kill and restart BIND afterwards, or the old, vulnerable version will still be running! --> HOWTO の残りの部分、jail その他を設定するところは、 BIND のバージョンを変更しても変える必要はありません。 新しいバイナリを古いバイナリの上に上書きするだけで OK です。 ただしその後 BIND を kill して再起動すること。 さもないと危険なバージョンがそのまま実行し続けていますから! <!--O <sect>Appendix - Thanks<label id="thanks"> --> <sect>付録 - 謝辞<label id="thanks"> <p> <!--O I'd like to thank the following people for their assistance in the creation of this HOWTO: --> この HOWTO の作成の助けとなってくださった、 以下の方々に感謝します。 <itemize> <!--O <item>Lonny Selinger <tt><lonny at abyss.za.org></> for "testing" the first version of this HOWTO and making sure that I didn't miss any steps. --> <item>Lonny Selinger <tt><lonny at abyss.za.org></> は、この HOWTO の最初の版を「テスト」してくださり、 必要な手続きを飛ばしていないことを筆者に確信させてくれました。 <!--O <item>Chirik <tt><chirik at CastleFur.COM></>, Dwayne Litzenberger <tt><dlitz at dlitz.net></>, Phil Bambridge <tt><phil.b at cableinet.co.uk></>, Robert Cole <tt><rcole at metrum-datatape.com></>, Colin MacDonald <tt><colinm at telus.net></>, and others for pointing out errors, omissions, and providing other useful advice to make this HOWTO even better. --> <item>Chirik <tt><chirik at CastleFur.COM></>, Dwayne Litzenberger <tt><dlitz at dlitz.net></>, Phil Bambridge <tt><phil.b at cableinet.co.uk></>, Robert Cole <tt><rcole at metrum-datatape.com></>, Colin MacDonald <tt><colinm at telus.net></> ほか、 多くの皆さんがこの文書の間違い、欠落を指摘していただき、 またこの HOWOTO をより良くするための有益なアドバイスをくださいました。 <!--O <item>Erik Wallin <tt><erikw at sec.se></> and Brian Cervenka <tt><brian at zerobelow.org></> for providing good suggestions for further tightening the jail. --> <item>Erik Wallin <tt><erikw at sec.se></> と Brian Cervenka <tt><brian at zerobelow.org></> は、jail をさらに強固にするための、 優れた提案を送ってくれました。 </itemize> <!--O And last but certainly not least, I'd like to thank Nakano Takeo <tt><nakano at apm.seikei.ac.jp></> for translating the Chroot-BIND HOWTO into Japanese. You can find his translation at <url url="http://www.linux.or.jp/JF/JFdocs/Chroot-BIND-HOWTO.html">. --> そして最後に、 Chroot-BIND HOWTO を日本語に翻訳してくれた Nakano Takeo <tt><nakano at apm.seikei.ac.jp></> に感謝します。この翻訳は <url url="http://www.linux.or.jp/JF/JFdocs/Chroot-BIND-HOWTO.html"> にあります。 <!--O <sect>Appendix - Document Distribution Policy<label id="legal"> --> <sect>付録 - 文書の配布ポリシー<label id="legal"> <p> Copyright © Scott Wunsch, 2000-2001. This document may be distributed only subject to the terms set forth in the LDP licence at <url url="http://metalab.unc.edu/LDP/COPYRIGHT.html">. This HOWTO is free documentation; you can redistribute it and/or modify it under the terms of the LDP licence. It is distributed in the hope that it will be useful, but <bf>without any warranty</>; without even the impled warranty of merchantability or fitness for a particular purpose. See the LDP licence for more details. 【訳注: 原文が優先されますが、参照のために翻訳を示します。 Copyright © Scott Wunsch, 2000-2001. この文書は <url url="http://metalab.unc.edu/LDP/COPYRIGHT.html"> にある LDP ライセンスに従えば配布できます。 この HOWTO はフリー文書です。 LDP ライセンスの下で再配布・改変が可能です。 この文書は有益であらんことを願って配布されていますが、 <bf>保証は一切ありません</>。 暗黙のものも含め、商用に役立つ保証もありませんし、 特定の用途に合致するかどうかもわかりません。 詳細は LDP ライセンスを見てください。 なお翻訳版も LDP ライセンスの下で再配布・改変可能とします。 Copyright © NAKANO Takeo, 2001.】 </article>