Skip to content

Commit 4a5e4b9

Browse files
committed
Introduce JAILED_DATASET option to poudriere.conf
This option allows passing a temporary ZFS dataset into the jail along with full control over it from within the jail. Sponsored by: Future Crew, LLC
1 parent 6e626a7 commit 4a5e4b9

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

src/etc/poudriere.conf.sample

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
# root of the poudriere zfs filesystem, by default /poudriere
1919
# ZROOTFS=/poudriere
2020

21+
# ZFS dataset relative to ZROOTFS that will be passed into jail using zfs-jail(8)
22+
# The jail will have full control over this dataset
23+
# The dataset is recreated from scratch on every jail start and is destroyed
24+
# when jail is stopped
25+
# Enabling this feature will set "allow.mount=1", "allow.mount.zfs=1"
26+
# and "enforce_statfs=1" parameters for the jail
27+
#JAILED_DATASET=
28+
2129
# the host where to download sets for the jails setup
2230
# You can specify here a host or an IP
2331
# replace _PROTO_ by http or ftp

src/share/poudriere/common.sh

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,7 @@ injail_tty() {
929929
jstart() {
930930
local mpath name network
931931
local MAX_MEMORY_BYTES
932+
local allow_mount_args
932933

933934
unset MAX_MEMORY_BYTES
934935
case "${MAX_MEMORY:+set}" in
@@ -945,6 +946,12 @@ jstart() {
945946
;;
946947
esac
947948

949+
case "${JAILED_DATASET}" in
950+
"") ;;
951+
*)
952+
allow_mount_args="allow.mount=1 allow.mount.zfs=1 enforce_statfs=1"
953+
esac
954+
948955
_my_name name
949956

950957
mpath=${MASTERMNT:?}${MY_JOBID:+/../${MY_JOBID}}
@@ -954,13 +961,21 @@ jstart() {
954961
# Restrict to no networking (if RESTRICT_NETWORKING==yes)
955962
jail -c persist name=${name:?} \
956963
path=${mpath:?} \
957-
host.hostname=${BUILDER_HOSTNAME-${name}} \
958-
${network} ${JAIL_PARAMS}
964+
host.hostname=${BUILDER_HOSTNAME-${name:?}} \
965+
${network} ${allow_mount_args} ${JAIL_PARAMS}
959966
# Allow networking in -n jail
960-
jail -c persist name=${name}-n \
967+
jail -c persist name=${name:?}-n \
961968
path=${mpath:?} \
962-
host.hostname=${BUILDER_HOSTNAME-${name}} \
963-
${IPARGS} ${JAIL_PARAMS} ${JAIL_NET_PARAMS}
969+
host.hostname=${BUILDER_HOSTNAME-${name:?}} \
970+
${IPARGS} ${allow_mount_args} ${JAIL_PARAMS} ${JAIL_NET_PARAMS}
971+
972+
if [ "${JAILED_DATASET}" ]; then
973+
local jailed_dataset_name=${ZPOOL}${ZROOTFS}${JAILED_DATASET}_${name:?}
974+
zfs destroy -Rf ${jailed_dataset_name} 2>/dev/null || :
975+
zfs create -o jailed=on ${jailed_dataset_name}
976+
zfs jail ${name:?} ${jailed_dataset_name}
977+
zfs jail ${name:?}-n ${jailed_dataset_name}
978+
fi
964979
return 0
965980
}
966981

@@ -1000,6 +1015,10 @@ jstop() {
10001015
_my_name name
10011016
jail -r ${name:?} 2>/dev/null || :
10021017
jail -r ${name:?}-n 2>/dev/null || :
1018+
1019+
if [ "${JAILED_DATASET}" ]; then
1020+
zfs destroy -Rf ${ZPOOL}${ZROOTFS}${JAILED_DATASET}_${name:?} 2>/dev/null || :
1021+
fi
10031022
}
10041023

10051024
eargs() {
@@ -10471,6 +10490,11 @@ set) ;;
1047110490
case ${ZROOTFS} in
1047210491
[!/]*) err 1 "ZROOTFS should start with a /" ;;
1047310492
esac
10493+
: ${JAILED_DATASET=""}
10494+
case ${JAILED_DATASET} in
10495+
"") ;;
10496+
[!/]*) err 1 "JAILED_DATASET should start with a /" ;;
10497+
esac
1047410498
;;
1047510499
esac
1047610500

0 commit comments

Comments
 (0)