1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

BastilleBSDを試してみた

Last updated at Posted at 2021-06-01

13.0-RELEASE/amd64でjailの管理ツールのBastilleBSDを試してみました。

jailは一つのホストの中に複数のホストがあるように見せかける技術です。FreeBSDなんかより以前の太古の時代に作られたchrootを使った仕組みです。FreeBSDでは古くからある技術で最近はコンテナと呼ばれることもあるようです。

FreeBSDにはbhyveと呼ばれるハイパーバイザーがあり、OSの完全分離が可能ですが、jailより多くの資源を必要とするため、私は試した事がありません。

jail.png

jailをサポートする仕組みは標準のカーネルに入っていて、jexec,jlsなどの設定コマンドも標準で用意されています。ただこれらのコマンドで設定していくのはかなり複雑で、これまで代替のコマンドがいろいろ作られてきましたが、最近はBastilleBSDやiocageがトレンドのようです。

pkgでBastilleBSDをインストールします。

% sudo pkg install bastille
% sudo bastille -v
0.8.20210115

インターフェースを作ります。

% sudo sysrc cloned_interfaces+=lo1
% sudo sysrc ifconfig_lo1_name="bastille0"
% sudo service netif cloneup

/etc/pf.confを書きます。ext_ifは自分のホストのインターフェースにします。

ext_if="alc0"

set block-policy return
scrub in on $ext_if all fragment reassemble
set skip on lo

table <jails> persist
nat on $ext_if from <jails> to any -> ($ext_if)

## Enable dynamic rdr (see below) bastille 0.7+
rdr-anchor "rdr/*"

block in all
pass out quick keep state
antispoof for $ext_if inet #disable for VNET
pass in inet proto tcp from any to any port ssh flags S/SA keep state

pfは設定を間違えると、ログインできなくなりますので、注意してください。またこの設定だとホストでtftpクライアントも使用できなくなりますので必要な設定を追加する必要があります。pfを有効にします。

% sudo sysrc pf_enable="YES"
% sudo service pf start

セッションが切れるのでもう一度ログインします。

/usr/local/etc/bastille/bastille.confのbastille_tzdataを"Asia/Tokyo"に変更しておきます。

jailを作ります。IPアドレスはホストのインターフェースでnatするのでホストのインターフェースとは別のサブネットでアドレスを設定します。

% sudo bastille bootstrap 13.0-RELEASE
% sudo bastille create testjail 13.0-RELEASE 192.168.10.50

rootでjailに入ります。

% sudo bastille console testjail

ツール名はパリにあった「バスティーユ牢獄」によるものだと思います。

マシン起動時にjailを上げておきたい時は、下記を実行しておきます。

% sudo sysrc bastille_enable=YES
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?