From be4d68fcf10a2728c781679de74b1095c0c8c938 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Fri, 16 May 2025 15:32:56 -0600 Subject: [PATCH 01/10] setup: Add -y --- usr/local/share/bastille/setup.sh | 175 ++++++++++++++++++++---------- 1 file changed, 117 insertions(+), 58 deletions(-) diff --git a/usr/local/share/bastille/setup.sh b/usr/local/share/bastille/setup.sh index eee1d7e2..06c369bd 100644 --- a/usr/local/share/bastille/setup.sh +++ b/usr/local/share/bastille/setup.sh @@ -33,7 +33,22 @@ . /usr/local/share/bastille/common.sh usage() { - error_exit "Usage: bastille setup [-b|bridge] [-f|--filesystem] [-l|loopback] [-p|pf|firewall] [-s|shared] [-v|vnet] [-z|zfs|storage]" + error_notify "Usage: bastille setup [option(s)] [-b|bridge]" + error_notify " [-f|filesystem]" + error_notify " [-l|loopback]" + error_notify " [-p|pf|firewall]" + error_notify " [-s|shared]" + error_notify " [-v|vnet]" + error_notify " [-z|zfs|storage]" + cat << EOF + + Options: + + -y | --yes Assume always yes on prompts. + -x | --debug Enable debug mode. + +EOF + exit 1 } # Check for too many args @@ -57,7 +72,7 @@ configure_filesystem() { fi chmod 0750 "${bastille_prefix}" # Make sure the dataset is mounted in the proper place - elif [ -d "${bastille_prefix}" ]; then + elif [ -d "${bastille_prefix}" ] && checkyesno bastille_zfs_enable; then if ! zfs list "${bastille_zfs_zpool}/${bastille_zfs_prefix}" >/dev/null; then zfs create ${bastille_zfs_options} -o mountpoint="${bastille_prefix}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}" elif [ "$(zfs get -H -o value mountpoint ${bastille_zfs_zpool}/${bastille_zfs_prefix})" != "${bastille_prefix}" ]; then @@ -341,72 +356,112 @@ if [ $# -eq 0 ]; then exit 0 fi +# Handle options. +AUTO_YES=0 +while [ "$#" -gt 0 ]; do + case "${1}" in + -h|--help|help) + usage + ;; + -y|--yes) + AUTO_YES=1 + shift + ;; + -x|--debug) + enable_debug + shift + ;; + -*) + for _opt in $(echo ${1} | sed 's/-//g' | fold -w1); do + case ${_opt} in + y) AUTO_YES=1 ;; + x) enable_debug ;; + *) error_exit "[ERROR]: Unknown Option: \"${1}\"" ;; + esac + done + shift + ;; + *) + break + ;; + esac +done + # Handle options. case "$1" in - -h|--help|help) - usage - ;; - -f|--filesystem) + -f|filesystem) configure_filesystem ;; -p|pf|firewall) configure_pf ;; -n|netgraph) - warn "[WARNING]: Bastille only allows using either 'if_bridge' or 'netgraph'" - warn "as VNET network options. You CANNOT use both on the same system. If you have" - warn "already started using bastille with 'if_bridge' do not continue." - # shellcheck disable=SC3045 - read -p "Do you really want to continue setting up netgraph for Bastille? [y|n]:" _answer - case "${_answer}" in - [Yy]|[Yy][Ee][Ss]) - configure_vnet - configure_netgraph - ;; - [Nn]|[Nn][Oo]) - error_exit "Netgraph setup cancelled." - ;; - *) - error_exit "Invalid selection. Please answer 'y' or 'n'" - ;; - esac + if [ "${AUTO_YES}" -eq 1 ]; then + configure_vnet + configure_netgraph + else + warn "[WARNING]: Bastille only allows using either 'if_bridge' or 'netgraph'" + warn "as VNET network options. You CANNOT use both on the same system. If you have" + warn "already started using bastille with 'if_bridge' do not continue." + # shellcheck disable=SC3045 + read -p "Do you really want to continue setting up netgraph for Bastille? [y|n]:" _answer + case "${_answer}" in + [Yy]|[Yy][Ee][Ss]) + configure_vnet + configure_netgraph + ;; + [Nn]|[Nn][Oo]) + error_exit "Netgraph setup cancelled." + ;; + *) + error_exit "Invalid selection. Please answer 'y' or 'n'" + ;; + esac + fi ;; - -l|loopback) - warn "[WARNING]: Bastille only allows using either the 'loopback' or 'shared'" - warn "interface to be configured ant one time. If you continue, the 'shared'" - warn "interface will be disabled, and the 'loopback' interface will be used as default." - # shellcheck disable=SC3045 - read -p "Do you really want to continue setting up the loopback interface? [y|n]:" _answer - case "${_answer}" in - [Yy]|[Yy][Ee][Ss]) - configure_loopback_interface - ;; - [Nn]|[Nn][Oo]) - error_exit "Loopback interface setup cancelled." - ;; - *) - error_exit "Invalid selection. Please answer 'y' or 'n'" - ;; - esac + if [ "${AUTO_YES}" -eq 1 ]; then + configure_loopback_interface + else + warn "[WARNING]: Bastille only allows using either the 'loopback' or 'shared'" + warn "interface to be configured ant one time. If you continue, the 'shared'" + warn "interface will be disabled, and the 'loopback' interface will be used as default." + # shellcheck disable=SC3045 + read -p "Do you really want to continue setting up the loopback interface? [y|n]:" _answer + case "${_answer}" in + [Yy]|[Yy][Ee][Ss]) + configure_loopback_interface + ;; + [Nn]|[Nn][Oo]) + error_exit "Loopback interface setup cancelled." + ;; + *) + error_exit "Invalid selection. Please answer 'y' or 'n'" + ;; + esac + fi ;; -s|shared) - warn "[WARNING]: Bastille only allows using either the 'loopback' or 'shared'" - warn "interface to be configured at one time. If you continue, the 'loopback'" - warn "interface will be disabled, and the shared interface will be used as default." - # shellcheck disable=SC3045 - read -p "Do you really want to continue setting up the shared interface? [y|n]:" _answer - case "${_answer}" in - [Yy]|[Yy][Ee][Ss]) - configure_shared_interface - ;; - [Nn]|[Nn][Oo]) - error_exit "Shared interface setup cancelled." - ;; - *) - error_exit "Invalid selection. Please answer 'y' or 'n'" - ;; - esac + if [ "${AUTO_YES}" -eq 1 ]; then + configure_shared_interface + else + warn "[WARNING]: Bastille only allows using either the 'loopback' or 'shared'" + warn "interface to be configured at one time. If you continue, the 'loopback'" + warn "interface will be disabled, and the shared interface will be used as default." + # shellcheck disable=SC3045 + read -p "Do you really want to continue setting up the shared interface? [y|n]:" _answer + case "${_answer}" in + [Yy]|[Yy][Ee][Ss]) + configure_shared_interface + ;; + [Nn]|[Nn][Oo]) + error_exit "Shared interface setup cancelled." + ;; + *) + error_exit "Invalid selection. Please answer 'y' or 'n'" + ;; + esac + fi ;; -z|zfs|storage) configure_storage @@ -415,8 +470,12 @@ case "$1" in configure_vnet ;; -b|bridge) - configure_vnet - configure_bridge + if [ "${AUTO_YES}" -eq 1 ]; then + error_exit "[ERROR]: [-b|bridge] does not support [-y|--yes]." + else + configure_vnet + configure_bridge + fi ;; *) error_exit "[ERROR]: Unknown option: \"${1}\"" From 0c3e5b1fd79941f72b410f46a99b6c16c784a314 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Fri, 16 May 2025 18:29:35 -0600 Subject: [PATCH 02/10] setup: USe - only for options --- usr/local/share/bastille/setup.sh | 32 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/usr/local/share/bastille/setup.sh b/usr/local/share/bastille/setup.sh index 06c369bd..b0b273a9 100644 --- a/usr/local/share/bastille/setup.sh +++ b/usr/local/share/bastille/setup.sh @@ -33,13 +33,13 @@ . /usr/local/share/bastille/common.sh usage() { - error_notify "Usage: bastille setup [option(s)] [-b|bridge]" - error_notify " [-f|filesystem]" - error_notify " [-l|loopback]" - error_notify " [-p|pf|firewall]" - error_notify " [-s|shared]" - error_notify " [-v|vnet]" - error_notify " [-z|zfs|storage]" + error_notify "Usage: bastille setup [option(s)] [bridge]" + error_notify " [filesystem]" + error_notify " [loopback]" + error_notify " [pf|firewall]" + error_notify " [shared]" + error_notify " [vnet]" + error_notify " [storage]" cat << EOF Options: @@ -388,14 +388,14 @@ while [ "$#" -gt 0 ]; do done # Handle options. -case "$1" in - -f|filesystem) +case "${1}" in + filesystem) configure_filesystem ;; - -p|pf|firewall) + pf|firewall) configure_pf ;; - -n|netgraph) + netgraph) if [ "${AUTO_YES}" -eq 1 ]; then configure_vnet configure_netgraph @@ -419,7 +419,7 @@ case "$1" in esac fi ;; - -l|loopback) + loopback) if [ "${AUTO_YES}" -eq 1 ]; then configure_loopback_interface else @@ -441,7 +441,7 @@ case "$1" in esac fi ;; - -s|shared) + shared) if [ "${AUTO_YES}" -eq 1 ]; then configure_shared_interface else @@ -463,13 +463,13 @@ case "$1" in esac fi ;; - -z|zfs|storage) + storage) configure_storage ;; - -v|vnet) + vnet) configure_vnet ;; - -b|bridge) + bridge) if [ "${AUTO_YES}" -eq 1 ]; then error_exit "[ERROR]: [-b|bridge] does not support [-y|--yes]." else From 2d1dfcd5ceabf50bc09f7159783bb3efb534e143 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Fri, 16 May 2025 18:36:09 -0600 Subject: [PATCH 03/10] docs: Update setup for consistency --- docs/chapters/subcommands/setup.rst | 63 ++++++++++++++++++----------- 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/docs/chapters/subcommands/setup.rst b/docs/chapters/subcommands/setup.rst index 40987f98..a67c6571 100644 --- a/docs/chapters/subcommands/setup.rst +++ b/docs/chapters/subcommands/setup.rst @@ -12,53 +12,68 @@ Below is a list of available options that can be used with the ``setup`` command .. code-block:: shell - ishmael ~ # bastille setup -h ## display setup help - ishmael ~ # bastille setup -b ## configure bridge interface - ishmael ~ # bastille setup -f ## configure filesystem/structure - ishmael ~ # bastille setup -l ## configure loopback interface - ishmael ~ # bastille setup -p ## configure default pf firewall - ishmael ~ # bastille setup -s ## configure shared interface - ishmael ~ # bastille setup -v ## configure VNET - ishmael ~ # bastille setup -z ## configure ZFS storage - ishmael ~ # bastille setup ## configure -l -p and -z + ishmael ~ # bastille setup -h + Usage: bastille setup [option(s)] [bridge] + [filesystem] + [loopback] + [pf|firewall] + [shared] + [vnet] + [storage] + + Options: -The ``-l|loopback`` option will configure a loopback interface called ``bastille0`` that + -y | --yes Assume always yes on prompts. + -x | --debug Enable debug mode. + +The ``loopback`` option will configure a loopback interface called ``bastille0`` that will be used as a default when not specifying an interface with the ``create`` command. -The ``-s|shared`` option will configure the interface you choose to also be used as the default +The ``shared`` option will configure the interface you choose to also be used as the default when not specifying an interface with the ``create`` command. Please note. You CANNOT run both a loopback and a shared interface with Bastille. Only one should be configured. If you configure one, it will disable the other. -The ``-l|loopback`` option is the default, and is enough for most use cases. It is simply an ``lo`` interface +The ``loopback`` option is the default, and is enough for most use cases. It is simply an ``lo`` interface that jails will get linked to on creation. It is not attached to any specific interface. This is the simplest -networking option. The ``-l|loopback`` and ``-s|shared`` options are only for cases where the ``interface`` +networking option. The ``loopback`` and ``shared`` options are only for cases where the ``interface`` is not specified during the ``create`` command. If an interface is specified, these options have no effect. Instead, the specified interface will be used. -The ``-f|--filesystem`` option is to ensure the proper datasets/directories are in place +The ``filesystem`` option is to ensure the proper datasets/directories are in place for using Bastille. This should only have to be run once on a new system. -The ``-s|shared`` option is for cases where you want an actual interface to use with bastille as +The ``shared`` option is for cases where you want an actual interface to use with bastille as opposed to a loopback. Jails will be linked to the shared interface on creation. -The ``-p|pf|firewall`` option will configure the pf firewall by enabling the service and creating the +The ``pf|firewall`` option will configure the pf firewall by enabling the service and creating the default ``pf.conf`` file. Once this is done, you can use the ``rdr`` command to forward traffic into a jail. -The ``-z|zfs|storage`` option will attempt to configure a pool and dataset for Bastille, but only -if ZFS in enabled on your system. +The ``storage`` option will attempt to configure a pool and dataset for Bastille, but only +if ZFS in enabled on your system. Otherwise it will use UFS. -The ``-v|vnet`` option will configure your system for use with VNET ``-V`` jails. +The ``vnet`` option will configure your system for use with VNET ``-V`` jails. -The ``-b|bridge`` options will attempt to configure a bridge interface for use with bridged VNET +The ``bridge`` options will attempt to configure a bridge interface for use with bridged VNET ``-B`` jails. -Running ``bastille setup`` without any options will attempt to auto-configure the ``-f``, ``-l``, ``-p`` and -``-z`` options. +Running ``bastille setup`` without any options will attempt to auto-configure the ``filesystem``, ``loopback``, ``firewall`` and +``storage`` options. .. code-block:: shell - ishmael ~ # bastille setup help - Usage: bastille setup [-b|bridge] [-f|--filesystem] [-l|loopback] [-p|pf|firewall] [-s|shared] [-v|vnet] [-z|zfs|storage] + ishmael ~ # bastille setup -h + Usage: bastille setup [option(s)] [bridge] + [filesystem] + [loopback] + [pf|firewall] + [shared] + [vnet] + [storage] + + Options: + + -y | --yes Assume always yes on prompts. + -x | --debug Enable debug mode. From 25cde6153ca169c5bd5c564bdb193a54a9d35fb4 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Fri, 16 May 2025 18:41:44 -0600 Subject: [PATCH 04/10] setup: Options are first --- usr/local/share/bastille/setup.sh | 67 ++++++++++++++++--------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/usr/local/share/bastille/setup.sh b/usr/local/share/bastille/setup.sh index b0b273a9..90deaaef 100644 --- a/usr/local/share/bastille/setup.sh +++ b/usr/local/share/bastille/setup.sh @@ -51,11 +51,46 @@ EOF exit 1 } +# Handle options. +AUTO_YES=0 +while [ "$#" -gt 0 ]; do + case "${1}" in + -h|--help|help) + usage + ;; + -y|--yes) + AUTO_YES=1 + shift + ;; + -x|--debug) + enable_debug + shift + ;; + -*) + for _opt in $(echo ${1} | sed 's/-//g' | fold -w1); do + case ${_opt} in + y) AUTO_YES=1 ;; + x) enable_debug ;; + *) error_exit "[ERROR]: Unknown Option: \"${1}\"" ;; + esac + done + shift + ;; + *) + break + ;; + esac +done + # Check for too many args if [ "$#" -gt 1 ]; then usage fi +OPT_CONFIG="${1}" + +bastille_root_check + configure_filesystem() { # This is so we dont have to introduce breaking @@ -356,38 +391,6 @@ if [ $# -eq 0 ]; then exit 0 fi -# Handle options. -AUTO_YES=0 -while [ "$#" -gt 0 ]; do - case "${1}" in - -h|--help|help) - usage - ;; - -y|--yes) - AUTO_YES=1 - shift - ;; - -x|--debug) - enable_debug - shift - ;; - -*) - for _opt in $(echo ${1} | sed 's/-//g' | fold -w1); do - case ${_opt} in - y) AUTO_YES=1 ;; - x) enable_debug ;; - *) error_exit "[ERROR]: Unknown Option: \"${1}\"" ;; - esac - done - shift - ;; - *) - break - ;; - esac -done - -# Handle options. case "${1}" in filesystem) configure_filesystem From fd9583e911ab360c5e4377d6ea30da2a74355ef6 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Fri, 16 May 2025 18:43:29 -0600 Subject: [PATCH 05/10] setup: Don't support -y on shared --- usr/local/share/bastille/setup.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usr/local/share/bastille/setup.sh b/usr/local/share/bastille/setup.sh index 90deaaef..01e22404 100644 --- a/usr/local/share/bastille/setup.sh +++ b/usr/local/share/bastille/setup.sh @@ -446,7 +446,7 @@ case "${1}" in ;; shared) if [ "${AUTO_YES}" -eq 1 ]; then - configure_shared_interface + error_exit "[ERROR]: 'shared' does not support [-y|--yes]." else warn "[WARNING]: Bastille only allows using either the 'loopback' or 'shared'" warn "interface to be configured at one time. If you continue, the 'loopback'" @@ -474,7 +474,7 @@ case "${1}" in ;; bridge) if [ "${AUTO_YES}" -eq 1 ]; then - error_exit "[ERROR]: [-b|bridge] does not support [-y|--yes]." + error_exit "[ERROR]: 'bridge' does not support [-y|--yes]." else configure_vnet configure_bridge From 00912e086c8704f163b0b42653b27f9f12aff37f Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Fri, 16 May 2025 18:46:00 -0600 Subject: [PATCH 06/10] setup: Use OPT_CONFIG instead of $1 --- usr/local/share/bastille/setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr/local/share/bastille/setup.sh b/usr/local/share/bastille/setup.sh index 01e22404..c37e8e37 100644 --- a/usr/local/share/bastille/setup.sh +++ b/usr/local/share/bastille/setup.sh @@ -391,7 +391,7 @@ if [ $# -eq 0 ]; then exit 0 fi -case "${1}" in +case "${OPT_CONFIG}" in filesystem) configure_filesystem ;; From 32520802359df1028013f4dae18387b814dcc026 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Fri, 16 May 2025 21:39:16 -0600 Subject: [PATCH 07/10] Update setup.sh --- usr/local/share/bastille/setup.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usr/local/share/bastille/setup.sh b/usr/local/share/bastille/setup.sh index c37e8e37..54473278 100644 --- a/usr/local/share/bastille/setup.sh +++ b/usr/local/share/bastille/setup.sh @@ -358,7 +358,7 @@ fi # Configure storage configure_storage() { - if mount | grep "zfs"; then + if mount | grep "zfs" >/dev/null 2>/dev/null; then if [ ! "$(kldstat -m zfs)" ]; then info "ZFS module not loaded; skipping..." elif sysrc -f ${BASTILLE_CONFIG} -n bastille_zfs_enable | grep -Eoq "([Y|y][E|e][S|s])"; then @@ -375,7 +375,7 @@ configure_storage() { sysrc -f "${BASTILLE_CONFIG}" bastille_zfs_zpool="${bastille_zroot}" info "\nUsing ZFS filesystem." fi - elif mount | grep "ufs"; then + elif mount | grep "ufs" >/dev/null 2>/dev/null; then info "\nUsing UFS filesystem." fi } From daa8e4881fd544a07689f55862e5d33787b769fc Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Fri, 16 May 2025 21:42:08 -0600 Subject: [PATCH 08/10] bastille: Allow setup subcommand to copy default config file --- usr/local/bin/bastille | 43 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/usr/local/bin/bastille b/usr/local/bin/bastille index 8af81bfb..1b18db63 100755 --- a/usr/local/bin/bastille +++ b/usr/local/bin/bastille @@ -34,25 +34,23 @@ PATH=${PATH}:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin BASTILLE_VERSION=0.14.20250420 -## check for config existence +# Validate config file +# Copy default when 'setup' is called +# so we can skip to the setup command bastille_conf_check() { - if [ ! -r "/usr/local/etc/bastille/bastille.conf" ]; then - echo "[INFO] Configuration file not found. Do you want to create it with default values? [y/N]" - read answer - case "${answer}" in - [Nn][Oo]|[Nn]|"") - echo "[INFO] No configuration file has been generated. Exiting." - exit - ;; - [Yy][Ee][Ss]|[Yy]) - cp /usr/local/etc/bastille/bastille.conf.sample /usr/local/etc/bastille/bastille.conf - echo "[INFO] Configuration file has been generated. Continuing with default values" - ;; - *) - echo "[ERROR] Invalid option. Please answer with 'y' or 'N'." - exit 1 - ;; - esac + + local _config="${1}" + shift 1 + local _args="$@" + + if [ ! -r "${_config}" ]; then + if echo "${_args}" | grep -Eosqw "setup"; then + cp /usr/local/etc/bastille/bastille.conf.sample /usr/local/etc/bastille/bastille.conf + else + echo "[ERROR]: No config file found." + echo "Please run 'bastille setup' to configure Bastille." + exit 1 + fi fi } @@ -127,9 +125,6 @@ EOF exit 1 } -bastille_conf_check -bastille_perms_check - if [ -z "${BASTILLE_CONFIG}" ]; then if [ -z "${BASTILLE_CONFIG}" ]; then BASTILLE_CONFIG=/usr/local/etc/bastille/bastille.conf @@ -141,7 +136,11 @@ if [ -z "${BASTILLE_CONFIG}" ]; then echo "Not a valid config file: ${BASTILLE_CONFIG}" exit 1 fi -fi +fi + +# Pass BASTILLE_CONFIG and ARGS to config function +bastille_conf_check "${BASTILLE_CONFIG}" "$@" +bastille_perms_check # Load common.sh after setting BASTILLE_CONFIG . /usr/local/share/bastille/common.sh From 5486e28e26847adbc52aebdbd19b3c19761e5c9d Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Fri, 16 May 2025 21:44:52 -0600 Subject: [PATCH 09/10] Use newlines for easier reading --- usr/local/bin/bastille | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usr/local/bin/bastille b/usr/local/bin/bastille index 1b18db63..5acdf342 100755 --- a/usr/local/bin/bastille +++ b/usr/local/bin/bastille @@ -47,8 +47,8 @@ bastille_conf_check() { if echo "${_args}" | grep -Eosqw "setup"; then cp /usr/local/etc/bastille/bastille.conf.sample /usr/local/etc/bastille/bastille.conf else - echo "[ERROR]: No config file found." - echo "Please run 'bastille setup' to configure Bastille." + echo -e "\n[ERROR]: No config file found!" + echo -e "Please run 'bastille setup' to configure Bastille.\n" exit 1 fi fi From e6ae4a0d7579a43fa08720d8a5926f4c8041b642 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Fri, 16 May 2025 21:48:41 -0600 Subject: [PATCH 10/10] setup: Use newlines --- usr/local/share/bastille/setup.sh | 50 +++++++++++++++++-------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/usr/local/share/bastille/setup.sh b/usr/local/share/bastille/setup.sh index 54473278..05b6ced1 100644 --- a/usr/local/share/bastille/setup.sh +++ b/usr/local/share/bastille/setup.sh @@ -186,8 +186,14 @@ configure_filesystem() { # Configure netgraph configure_netgraph() { if [ ! "$(kldstat -m netgraph)" ]; then + # Ensure jib script is in place for VNET jails + if [ ! "$(command -v jng)" ]; then + if [ -f /usr/share/examples/jails/jng ] && [ ! -f /usr/local/bin/jng ]; then + install -m 0544 /usr/share/examples/jails/jng /usr/local/bin/jng + fi + fi sysrc -f "${BASTILLE_CONFIG}" bastille_network_vnet_type="netgraph" - info "Configuring netgraph modules..." + info "\nConfiguring netgraph modules..." kldload netgraph kldload ng_netflow kldload ng_ksocket @@ -202,25 +208,25 @@ configure_netgraph() { sysrc -f /boot/loader.conf ng_bridge_load="YES" sysrc -f /boot/loader.conf ng_eiface_load="YES" sysrc -f /boot/loader.conf ng_socket_load="YES" - info "Netgraph has been successfully configured!" + info "\nNetgraph has been successfully configured!" else - info "Netgraph has already been configured!" + info "\nNetgraph has already been configured!" fi } # Configure bastille loopback network interface configure_loopback_interface() { if [ -z "$(sysrc -f ${BASTILLE_CONFIG} -n bastille_network_loopback)" ] || ! sysrc -n cloned_interfaces | grep -oq "lo1"; then - info "Configuring bastille0 loopback interface" + info "\nConfiguring bastille0 loopback interface" sysrc cloned_interfaces+=lo1 sysrc ifconfig_lo1_name="bastille0" - info "Bringing up new interface: [bastille0]" + info "\nBringing up new interface: [bastille0]" service netif cloneup sysrc -f "${BASTILLE_CONFIG}" bastille_network_loopback="bastille0" sysrc -f "${BASTILLE_CONFIG}" bastille_network_shared="" - info "Loopback interface successfully configured: [bastille0]" + info "\nLoopback interface successfully configured: [bastille0]" else - info "Loopback interface has already been configured: [bastille0]" + info "\nLoopback interface has already been configured: [bastille0]" fi } @@ -231,8 +237,8 @@ configure_shared_interface() { error_exit "Unable to detect interfaces, exiting." fi if [ -z "$(sysrc -f ${BASTILLE_CONFIG} -n bastille_network_shared)" ]; then - info "Attempting to configure shared interface for bastille..." - info "Listing available interfaces..." + info "\nAttempting to configure shared interface for bastille..." + info "\nListing available interfaces..." for _if in ${_interface_list}; do echo "[${_interface_count}] ${_if}" _if_num="${_if_num} [${_interface_count}]${_if}" @@ -250,9 +256,9 @@ configure_shared_interface() { sysrc cloned_interfaces-="lo1" ifconfig bastille0 destroy 2>/dev/null sysrc -f "${BASTILLE_CONFIG}" bastille_network_shared="${_interface_select}" - info "Shared interface successfully configured: [${_interface_select}]" + info "\nShared interface successfully configured: [${_interface_select}]" else - info "Shared interface has already been configured: [$(sysrc -f ${BASTILLE_CONFIG} -n bastille_network_shared)]" + info "\nShared interface has already been configured: [$(sysrc -f ${BASTILLE_CONFIG} -n bastille_network_shared)]" fi } @@ -265,8 +271,8 @@ configure_bridge() { error_exit "Unable to detect interfaces, exiting." fi if ! ifconfig -g bridge | grep -oqw "${_bridge_name}"; then - info "Configuring ${_bridge_name} bridge interface..." - info "Listing available interfaces..." + info "\nConfiguring ${_bridge_name} bridge interface..." + info "\nListing available interfaces..." for _if in ${_interface_list}; do if ifconfig -g bridge | grep -oqw "${_if}" || ifconfig -g lo | grep -oqw "${_if}"; then continue @@ -291,9 +297,9 @@ configure_bridge() { sysrc ifconfig_bridge0_name="bastillebridge" sysrc ifconfig_bastillebridge="addm ${_interface_select} up" - info "Bridge interface successfully configured: [${_bridge_name}]" + info "\nBridge interface successfully configured: [${_bridge_name}]" else - info "Bridge has alread been configured: [${_bridge_name}]" + info "\nBridge has alread been configured: [${_bridge_name}]" fi } @@ -306,7 +312,7 @@ configure_vnet() { fi # Create default VNET ruleset if [ ! -f /etc/devfs.rules ] || ! grep -oq "bastille_vnet=13" /etc/devfs.rules; then - info "Creating bastille_vnet devfs.rules" + info "\nCreating bastille_vnet devfs.rules" cat << EOF > /etc/devfs.rules [bastille_vnet=13] add include \$devfsrules_hide_all @@ -317,7 +323,7 @@ add include \$devfsrules_jail_vnet add path 'bpf*' unhide EOF else - info "VNET has already been configured!" + info "\nVNET has already been configured!" fi } @@ -328,8 +334,8 @@ if [ ! -f "${bastille_pf_conf}" ]; then # shellcheck disable=SC3043 local ext_if ext_if=$(netstat -rn | awk '/default/ {print $4}' | head -n1) - info "Determined default network interface: ($ext_if)" - info "${bastille_pf_conf} does not exist: creating..." + info "\nDetermined default network interface: ($ext_if)" + echo "${bastille_pf_conf} does not exist: creating..." ## creating pf.conf cat << EOF > "${bastille_pf_conf}" @@ -352,7 +358,7 @@ EOF sysrc pf_enable=YES warn "pf ruleset created, please review ${bastille_pf_conf} and enable it using 'service pf start'." else - info "Firewall (pf) has already been configured!" + info "\nFirewall (pf) has already been configured!" fi } @@ -360,9 +366,9 @@ fi configure_storage() { if mount | grep "zfs" >/dev/null 2>/dev/null; then if [ ! "$(kldstat -m zfs)" ]; then - info "ZFS module not loaded; skipping..." + info "\nZFS module not loaded; skipping..." elif sysrc -f ${BASTILLE_CONFIG} -n bastille_zfs_enable | grep -Eoq "([Y|y][E|e][S|s])"; then - info "ZFS has already been configured!" + info "\nZFS has already been configured!" else ## attempt to determine bastille_zroot from `zpool list` bastille_zroot=$(zpool list | grep -v NAME | awk '{print $1}')