Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 20 May 2006 15:21:00 +0800
From:      Xin LI <delphij@delphij.net>
To:        freebsd-rc <freebsd-rc@freebsd.org>
Cc:        Ruslan Ermilov <ru@FreeBSD.org>, "Simon L. Nielsen" <simon@FreeBSD.org>
Subject:   [PATCH FOR REVIEW] Implementation of skeleton jail
Message-ID:  <1148109661.952.26.camel@spirit>

next in thread | raw e-mail | index | archive | help

--=-G8bjTm799TE2Zwvazs4l
Content-Type: multipart/mixed; boundary="=-CvtWJFjMbskxW/CB0lDN"


--=-CvtWJFjMbskxW/CB0lDN
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

Hi, folks,

Here is an implementation of what I call it "skeleton jail".  The idea
is that it is more or less to be common that we do not want to actually
copy of the base system (sometimes even other stuff) across zillions of
jails.

The skeleton jail is an approach that makes management of such jails
easier, by making use of mount_nullfs(8) to make read-only shadow or
read-write shadow from the so-called "skeleton root".

For instance, by default the skeleton jail would mount the following
directories from the skeleton root (/) to the jail:

bin          -> ${_root}/bin
sbin         -> ${_root}/sbin
lib          -> ${_root}/lib
libexec      -> ${_root}/libexec
usr/bin      -> ${_root}/usr/bin
usr/sbin     -> ${_root}/usr/sbin
usr/include  -> ${_root}/usr/include
usr/lib      -> ${_root}/usr/lib
usr/libdata  -> ${_root}/usr/libdata
usr/libexec  -> ${_root}/usr/libexec
usr/sbin     -> ${_root}/sbin
usr/share    -> ${_root}/share

In order to create the environment that is suitable for the skeleton
jail (say, create the directory hierarchy, populate the /etc/ stuff,
etc, but not the actual installworld), I have added a new target
"installskel" to src/Makefile which will help the work.

There are four variables that can be set in either system level default
or per-jail way:

 - _skel_enable
Whether to raise the jail from a skeleton root.  The default is NO
 - _skel_root
The place of skeleton root.  The default is "/"
 - _skel_romounts
Which directories (relative to the skeleton root) should be mounted
read-only to the skeleton jail.  The default is shown above.
 - _skel_rwmounts
Which directories (relative to the skeleton root) should be mounted
read-write to the skeleton jail.  The default is nothing, but a
potential useful option might be "/usr/ports", except for security
concerns.

To try out the patch:

 - Apply the patch.
 - Do a full "make buildworld" and potentially "make installworld" so
that your system is fresh.
 - Install the patched jail script into /etc/rc.d/ (e.g. can be done
with rm /etc/rc.d/jail && mergemaster -i)
 - Create a directory, i.e. "/vhosts/skeltest"
 - Do a "make installskel DESTDIR=3D/vhosts/skeltest"
 - Add the following stuff into /etc/rc.conf:
jail_enable=3D"YES"
jail_list=3D"skeltest"

jail_skeltest_rootdir=3D"/vhosts/skeltest"
jail_skeltest_hostname=3D"skeltest.example.com"
jail_skeltest_ip=3D"127.0.0.1"
jail_skeltest_devfs_enable=3D"YES"
jail_skeltest_exec=3D"/bin/sh /etc/rc"

 - Do a "/etc/rc.d/jail start skeltest" or reboot to see the jail up.

Comments?

Cheers,
--=20
Xin LI <delphij delphij net>    http://www.delphij.net/

--=-CvtWJFjMbskxW/CB0lDN
Content-Disposition: attachment; filename=patch-skel
Content-Type: text/x-patch; name=patch-skel; charset=ISO-8859-1
Content-Transfer-Encoding: base64

SW5kZXg6IE1ha2VmaWxlDQo9PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09DQpSQ1MgZmlsZTogL2hvbWUvbmN2cy9zcmMvTWFr
ZWZpbGUsdg0KcmV0cmlldmluZyByZXZpc2lvbiAxLjMyOQ0KZGlmZiAtdSAtcjEuMzI5IE1ha2Vm
aWxlDQotLS0gTWFrZWZpbGUJMTEgTWF5IDIwMDYgMTg6NTQ6MTYgLTAwMDAJMS4zMjkNCisrKyBN
YWtlZmlsZQkxNSBNYXkgMjAwNiAwMjowNDoxMyAtMDAwMA0KQEAgLTcxLDcgKzcxLDcgQEANCiAJ
Y2xlYW4gY2xlYW5kZXBlbmQgY2xlYW5kaXIgZGVsZXRlLW9sZCBkZWxldGUtb2xkLWxpYnMgZGVw
ZW5kIFwNCiAJZGlzdHJpYnV0ZSBkaXN0cmlidXRld29ybGQgZGlzdHJpYi1kaXJzIGR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sgdGhlbg0KKwkJCQkJZGVidWcgQ3JlYXRp
bmcgbWlzc2luZyBkaXJlY3RvcnkgJHtfcm9vdGRpcn0vJHtfbW50cHR9DQorCQkJCQlta2RpciAt
cCAke19yb290ZGlyfS8ke19tbnRwdH0NCisJCQkJZmkNCisJCQlkb25lDQorCQkJZm9yIF9tbnRw
dCBpbiAke19za2VsX3JvbW91bnRzfQ0KKwkJCWRvDQorCQkJCW1vdW50X251bGxmcyAtb3Jkb25s
eSAke19za2VsX3Jvb3R9LyR7X21udHB0fSAke19yb290ZGlyfS8ke19tbnRwdH0gPiAvZGV2L251
bGwgMj4mMQ0KKwkJCWRvbmUNCisJCQlmb3IgX21udHB0IGluICR7X3NrZWxfcndtb3VudHN9DQor
CQkJZG8NCisJCQkJbW91bnRfbnVsbGZzICR7X3NrZWxfcm9vdH0vJHtfbW50cHR9ICR7X3Jvb3Rk
aXJ9LyR7X21udHB0fSA+IC9kZXYvbnVsbCAyPiYxDQorCQkJZG9uZQ0KKwkJZmkNCiAJCWlmIGNo
ZWNreWVzbm8gX2RldmZzOyB0aGVuDQogCQkJIyBJZiBkZXZmcyBpcyBhbHJlYWR5IG1vdW50ZWQg
aGVyZSwgc2tpcCBpdC4NCiAJCQlkZiAtdCBkZXZmcyAiJHtfZGV2ZGlyfSIgPi9kZXYvbnVsbA0K



--=-CvtWJFjMbskxW/CB0lDN--

--=-G8bjTm799TE2Zwvazs4l
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: =?UTF-8?Q?=E8=BF=99=E6=98=AF=E4=BF=A1=E4=BB=B6=E7=9A=84=E6=95=B0?=
	=?UTF-8?Q?=E5=AD=97=E7=AD=BE=E5=90=8D=E9=83=A8=E5=88=86?=

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (FreeBSD)

iD8DBQBEbsNchcUczkLqiksRAunoAJ9Jj/rn9m4dE5uXCaKml+DM8ieJegCfU3J2
d+NX/FgkCXlz9Oh5WD+6OFg=
=fbK7
-----END PGP SIGNATURE-----

--=-G8bjTm799TE2Zwvazs4l--




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1148109661.952.26.camel>