Compare commits

..

1 Commits

Author SHA1 Message Date
Christer Edwards
4206e05a5e working copy; work in progress 2023-11-28 10:51:53 -07:00
10 changed files with 108 additions and 80 deletions

View File

@@ -47,7 +47,7 @@ EOL Releases
------------ ------------
It is sometimes necessary to run end-of-life releases for testing or legacy It is sometimes necessary to run end-of-life releases for testing or legacy
application support. By default Bastille will only install supported releases application support. Dy default Bastille will only install supported releases
but you can bootstrap EOL / unsupported releases with a simple trick. but you can bootstrap EOL / unsupported releases with a simple trick.
.. code-block:: shell .. code-block:: shell

View File

@@ -158,18 +158,6 @@ clone|config|cmd|console|convert|cp|edit|htop|limits|mount|pkg|rcp|rename|servic
TARGET="${1}" TARGET="${1}"
shift shift
# This is needed to handle the special case of 'bastille rcp' and 'bastille cp' with the '-q' or '--quiet'
# option specified before the TARGET. Also seems the cp and rcp commands does not support ALL as a target, so
# that's why is handled here. Maybe this behaviour needs an improvement later. -- yaazkal
if { [ "${CMD}" = 'rcp' ] || [ "${CMD}" = 'cp' ]; } && \
{ [ "${TARGET}" = '-q' ] || [ "${TARGET}" = '--quiet' ]; }; then
TARGET="${1}"
JAILS="${TARGET}"
OPTION="-q"
export OPTION
shift
fi
if [ "${TARGET}" = 'ALL' ]; then if [ "${TARGET}" = 'ALL' ]; then
target_all_jails target_all_jails
elif [ "${CMD}" = "pkg" ] && [ "${TARGET}" = '-H' ] || [ "${TARGET}" = '--host' ]; then elif [ "${CMD}" = "pkg" ] && [ "${TARGET}" = '-H' ] || [ "${TARGET}" = '--host' ]; then

View File

@@ -41,7 +41,7 @@ bastille_url_midnightbsd="https://www.midnightbsd.org/ftp/MidnightBSD/releases/"
## ZFS options ## ZFS options
bastille_zfs_enable="" ## default: "" bastille_zfs_enable="" ## default: ""
bastille_zfs_zpool="" ## default: "" bastille_zfs_zpool="" ## default: ""
bastille_zfs_prefix="${bastille_zfs_zpool}/bastille" ## default: "${bastille_zfs_zpool}/bastille" bastille_zfs_prefix="bastille" ## default: "${bastille_zfs_zpool}/bastille"
bastille_zfs_options="-o compress=lz4 -o atime=off" ## default: "-o compress=lz4 -o atime=off" bastille_zfs_options="-o compress=lz4 -o atime=off" ## default: "-o compress=lz4 -o atime=off"
## Export/Import options ## Export/Import options

View File

@@ -3,7 +3,7 @@
# Bastille jail startup script # Bastille jail startup script
# #
# PROVIDE: bastille # PROVIDE: bastille
# REQUIRE: jail # REQUIRE: NETWORKING
# KEYWORD: shutdown # KEYWORD: shutdown
# Add the following to /etc/rc.conf[.local] to enable this service # Add the following to /etc/rc.conf[.local] to enable this service
@@ -41,7 +41,7 @@ restart_cmd="bastille_stop && bastille_start"
rcordered_list() { rcordered_list() {
local _jailsdir local _jailsdir
_jailsdir=$(. $bastille_conf; echo $bastille_jailsdir) _jailsdir=$(. $bastille_conf; echo $bastille_jailsdir)
bastille_ordered_list=$(rcorder -s nostart ${_jailsdir}/*/jail.conf | xargs dirname | xargs basename -a | tr "\n" " ") bastille_ordered_list=$(rcorder -s nostart ${_jailsdir}/*/jail.conf | xargs dirname | xargs basename | tr "\n" " ")
} }
bastille_start() bastille_start()

View File

@@ -79,8 +79,7 @@ generate_vnet_jail_netblock() {
## define uniq_epair ## define uniq_epair
local jail_list=$(bastille list jails) local jail_list=$(bastille list jails)
if [ -n "${jail_list}" ]; then if [ -n "${jail_list}" ]; then
# local list_jails_num=$(echo "${jail_list}" | wc -l | awk '{print $1}') local list_jails_num=$(echo "${jail_list}" | wc -l | awk '{print $1}')
local list_jails_num=$(grep -e "e[0-9]b_bastille" "${bastille_jailsdir}"/*/jail.conf | grep -Eo '(bastille)([0-9]{1,3});' | grep -Eo '[0-9]{1,2}' | sort -hr | head -1 | awk '{print $1}')
local num_range=$((list_jails_num + 1)) local num_range=$((list_jails_num + 1))
for _num in $(seq 0 "${num_range}"); do for _num in $(seq 0 "${num_range}"); do
if ! grep -q "e[0-9]b_bastille${_num}" "${bastille_jailsdir}"/*/jail.conf; then if ! grep -q "e[0-9]b_bastille${_num}" "${bastille_jailsdir}"/*/jail.conf; then
@@ -113,7 +112,7 @@ EOF
vnet; vnet;
vnet.interface = e0b_${uniq_epair}; vnet.interface = e0b_${uniq_epair};
exec.prestart += "jib addm ${uniq_epair} ${external_interface}"; exec.prestart += "jib addm ${uniq_epair} ${external_interface}";
exec.prestart += "ifconfig e0a_${uniq_epair} description \'vnet host interface for Bastille jail ${jail_name}\'"; exec.prestart += "ifconfig e0a_${uniq_epair} description \"vnet host interface for Bastille jail ${jail_name}\"";
exec.poststop += "jib destroy ${uniq_epair}"; exec.poststop += "jib destroy ${uniq_epair}";
EOF EOF
fi fi

View File

@@ -82,7 +82,6 @@ for _jail in ${JAILS}; do
if [ -n "${USER}" ]; then if [ -n "${USER}" ]; then
validate_user validate_user
else else
check_fib
LOGIN="$(jexec -l "${_jail}" which login)" LOGIN="$(jexec -l "${_jail}" which login)"
${_setfib} jexec -l "${_jail}" $LOGIN -f root ${_setfib} jexec -l "${_jail}" $LOGIN -f root
fi fi

View File

@@ -39,12 +39,13 @@ usage() {
cat << EOF cat << EOF
Options: Options:
-E | --empty -- Creates an empty container, intended for custom jail builds (thin/thick/linux or unsupported). -B | --bridge -- Enables VNET. VNET containers are attached to a bridge interface. (DIY)
-L | --linux -- This option is intended for testing with Linux jails, this is considered experimental. -C | --clone -- Creates a ZFS clone container. Clones are ZFS snapshots of the release, consuming minimal storage.
-T | --thick -- Creates a thick container, they consume more space as they are self contained and independent. -E | --empty -- Creates an empty container. Intended for custom jail builds and experimentation.
-V | --vnet -- Enables VNET, VNET containers are attached to a virtual bridge interface for connectivity. -L | --linux -- This option is intended for testing with Linux jails. This is considered experimental.
-C | --clone -- Creates a clone container, they are duplicates of the base release, consume low space and preserves changing data. -N | --nested -- Creates a Nested container. Nesting containers provides support for "pods", poudriere, etc.
-B | --bridge -- Enables VNET, VNET containers are attached to a specified, already existing external bridge. -T | --thick -- Creates a thick container. Thick containers consume more space as they are full copies of a release.
-V | --vnet -- Enables VNET. VNET containers are attached to a bridge interface (FreeBSD jib).
EOF EOF
exit 1 exit 1
@@ -165,15 +166,10 @@ EOF
} }
generate_jail_conf() { generate_jail_conf() {
if [ "$(sysctl -n security.jail.jailed)" -eq 1 ]; then
devfs_ruleset_value=0
else
devfs_ruleset_value=4
fi
cat << EOF > "${bastille_jail_conf}" cat << EOF > "${bastille_jail_conf}"
${NAME} { ${NAME} {
devfs_ruleset = 4;
enforce_statfs = 2; enforce_statfs = 2;
devfs_ruleset = ${devfs_ruleset_value};
exec.clean; exec.clean;
exec.consolelog = ${bastille_jail_log}; exec.consolelog = ${bastille_jail_log};
exec.start = '/bin/sh /etc/rc'; exec.start = '/bin/sh /etc/rc';
@@ -194,17 +190,12 @@ EOF
} }
generate_linux_jail_conf() { generate_linux_jail_conf() {
if [ "$(sysctl -n security.jail.jailed)" -eq 1 ]; then
devfs_ruleset_value=0
else
devfs_ruleset_value=4
fi
cat << EOF > "${bastille_jail_conf}" cat << EOF > "${bastille_jail_conf}"
${NAME} { ${NAME} {
host.hostname = ${NAME}; host.hostname = ${NAME};
mount.fstab = ${bastille_jail_fstab}; mount.fstab = ${bastille_jail_fstab};
path = ${bastille_jail_path}; path = ${bastille_jail_path};
devfs_ruleset = ${devfs_ruleset_value}; devfs_ruleset = 4;
enforce_statfs = 1; enforce_statfs = 1;
exec.start = '/bin/true'; exec.start = '/bin/true';
@@ -222,16 +213,11 @@ EOF
} }
generate_vnet_jail_conf() { generate_vnet_jail_conf() {
if [ "$(sysctl -n security.jail.jailed)" -eq 1 ]; then
devfs_ruleset_value=0
else
devfs_ruleset_value=13
fi
NETBLOCK=$(generate_vnet_jail_netblock "$NAME" "${VNET_JAIL_BRIDGE}" "${bastille_jail_conf_interface}") NETBLOCK=$(generate_vnet_jail_netblock "$NAME" "${VNET_JAIL_BRIDGE}" "${bastille_jail_conf_interface}")
cat << EOF > "${bastille_jail_conf}" cat << EOF > "${bastille_jail_conf}"
${NAME} { ${NAME} {
devfs_ruleset = 13;
enforce_statfs = 2; enforce_statfs = 2;
devfs_ruleset = ${devfs_ruleset_value};
exec.clean; exec.clean;
exec.consolelog = ${bastille_jail_log}; exec.consolelog = ${bastille_jail_log};
exec.start = '/bin/sh /etc/rc'; exec.start = '/bin/sh /etc/rc';
@@ -248,6 +234,44 @@ ${NETBLOCK}
EOF EOF
} }
generate_nested_vnet_jail_conf() {
NETBLOCK=$(generate_vnet_jail_netblock "$NAME" "${VNET_JAIL_BRIDGE}" "${bastille_jail_conf_interface}")
cat << EOF > "${bastille_jail_conf}"
${NAME} {
devfs_ruleset = 13;
enforce_statfs = 1;
exec.clean;
exec.consolelog = ${bastille_jail_log};
exec.start = '/bin/sh /etc/rc';
exec.stop = '/bin/sh /etc/rc.shutdown';
host.hostname = ${NAME};
mount.devfs;
mount.fstab = ${bastille_jail_fstab};
path = ${bastille_jail_path};
securelevel = 2;
osrelease = ${RELEASE};
children.max = 16;
allow.chflags;
allow.mount;
allow.mount.devfs;
allow.mount.fdescfs;
allow.mount.linprocfs;
allow.mount.nullfs;
allow.mount.procfs;
allow.mount.tmpfs;
allow.mount.zfs;
allow.raw_sockets;
allow.set_hostname;
## nested params
${NETBLOCK}
}
EOF
}
post_create_jail() { post_create_jail() {
# Common config checks and settings. # Common config checks and settings.
@@ -277,7 +301,9 @@ post_create_jail() {
fi fi
# Generate the jail configuration file. # Generate the jail configuration file.
if [ -n "${VNET_JAIL}" ]; then if [ -n "${NESTED_JAIL}" ] && [ -n "${VNET_JAIL}" ]; then
generate_nested_vnet_jail_conf
elif [ -n "${VNET_JAIL}" ]; then
generate_vnet_jail_conf generate_vnet_jail_conf
else else
generate_jail_conf generate_jail_conf
@@ -622,22 +648,6 @@ LINUX_JAIL=""
# Handle and parse options # Handle and parse options
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case "${1}" in case "${1}" in
-E|--empty)
EMPTY_JAIL="1"
shift
;;
-L|--linux)
LINUX_JAIL="1"
shift
;;
-T|--thick)
THICK_JAIL="1"
shift
;;
-V|--vnet)
VNET_JAIL="1"
shift
;;
-B|--bridge) -B|--bridge)
VNET_JAIL="1" VNET_JAIL="1"
VNET_JAIL_BRIDGE="1" VNET_JAIL_BRIDGE="1"
@@ -647,28 +657,34 @@ while [ $# -gt 0 ]; do
CLONE_JAIL="1" CLONE_JAIL="1"
shift shift
;; ;;
-CV|-VC|--clone-vnet)
CLONE_JAIL="1"
VNET_JAIL="1"
shift
;;
-CB|-BC|--clone-bridge) -CB|-BC|--clone-bridge)
CLONE_JAIL="1" CLONE_JAIL="1"
VNET_JAIL="1" VNET_JAIL="1"
VNET_JAIL_BRIDGE="1" VNET_JAIL_BRIDGE="1"
shift shift
;; ;;
-TV|-VT|--thick-vnet) -CV|-VC|--clone-vnet)
THICK_JAIL="1" CLONE_JAIL="1"
VNET_JAIL="1" VNET_JAIL="1"
shift shift
;; ;;
-TB|-BT|--thick-bridge) -CNB|--nested-clone-bridge)
THICK_JAIL="1" CLONE_JAIL="1"
NESTED_JAIL="1"
VNET_JAIL="1" VNET_JAIL="1"
VNET_JAIL_BRIDGE="1" VNET_JAIL_BRIDGE="1"
shift shift
;; ;;
-CNV|--nested-clone-vnet)
CLONE_JAIL="1"
NESTED_JAIL="1"
VNET_JAIL="1"
shift
;;
-E|--empty)
EMPTY_JAIL="1"
shift
;;
-EB|-BE|--empty-bridge) -EB|-BE|--empty-bridge)
EMPTY_JAIL="1" EMPTY_JAIL="1"
VNET_JAIL="1" VNET_JAIL="1"
@@ -680,9 +696,8 @@ while [ $# -gt 0 ]; do
VNET_JAIL="1" VNET_JAIL="1"
shift shift
;; ;;
-LV|-VL|--linux-vnet) -L|--linux)
LINUX_JAIL="1" LINUX_JAIL="1"
VNET_JAIL="1"
shift shift
;; ;;
-LB|-BL|--linux-bridge) -LB|-BL|--linux-bridge)
@@ -691,6 +706,34 @@ while [ $# -gt 0 ]; do
VNET_JAIL_BRIDGE="1" VNET_JAIL_BRIDGE="1"
shift shift
;; ;;
-N|--nested)
NESTED_JAIL="1"
shift
;;
-T|--thick)
THICK_JAIL="1"
shift
;;
-TB|-BT|--thick-bridge)
THICK_JAIL="1"
VNET_JAIL="1"
VNET_JAIL_BRIDGE="1"
shift
;;
-TV|-VT|--thick-vnet)
THICK_JAIL="1"
VNET_JAIL="1"
shift
;;
-V|--vnet)
VNET_JAIL="1"
shift
;;
-LV|-VL|--linux-vnet)
LINUX_JAIL="1"
VNET_JAIL="1"
shift
;;
-*|--*) -*|--*)
error_notify "Unknown Option." error_notify "Unknown Option."
usage usage

View File

@@ -212,7 +212,7 @@ if [ -n "${TXZ_EXPORT}" -o -n "${TGZ_EXPORT}" ] && [ -n "${SAFE_EXPORT}" ]; then
error_exit "Error: Simple archive modes with safe ZFS export can't be used together." error_exit "Error: Simple archive modes with safe ZFS export can't be used together."
fi fi
if ! checkyesno bastille_zfs_enable; then if checkyesno bastille_zfs_enable; then
if [ -n "${GZIP_EXPORT}" -o -n "${RAW_EXPORT}" -o -n "${SAFE_EXPORT}" -o "${OPT_ZSEND}" = "-Rv" ]; then if [ -n "${GZIP_EXPORT}" -o -n "${RAW_EXPORT}" -o -n "${SAFE_EXPORT}" -o "${OPT_ZSEND}" = "-Rv" ]; then
error_exit "Options --gz, --raw, --safe, --verbose are valid for ZFS configured systems only." error_exit "Options --gz, --raw, --safe, --verbose are valid for ZFS configured systems only."
fi fi

View File

@@ -28,9 +28,8 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
bastille_config="/usr/local/etc/bastille/bastille.conf"
. /usr/local/share/bastille/common.sh . /usr/local/share/bastille/common.sh
. ${bastille_config} . /usr/local/etc/bastille/bastille.conf
usage() { usage() {
error_exit "Usage: bastille setup [pf|bastille0|zfs|vnet]" error_exit "Usage: bastille setup [pf|bastille0|zfs|vnet]"
@@ -112,8 +111,8 @@ configure_zfs() {
else else
## attempt to determine bastille_zroot from `zpool list` ## attempt to determine bastille_zroot from `zpool list`
bastille_zroot=$(zpool list | grep -v NAME | awk '{print $1}') bastille_zroot=$(zpool list | grep -v NAME | awk '{print $1}')
sysrc -f "${bastille_config}" bastille_zfs_enable=YES sysrc -f "${bastille_prefix}/bastille.conf" bastille_zfs_enable=YES
sysrc -f "${bastille_config}" bastille_zfs_zpool="${bastille_zroot}" sysrc -f "${bastille_prefix}/bastille.conf" bastille_zfs_zpool="${bastille_zroot}"
fi fi
} }