Skip to content

Commit

Permalink
Merge branch 'master' into patch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
tschettervictor authored Jan 18, 2025
2 parents d9106b5 + fe63412 commit 03214c4
Show file tree
Hide file tree
Showing 44 changed files with 544 additions and 153 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2018-2024, Christer Edwards <[email protected]>
Copyright (c) 2018-2025, Christer Edwards <[email protected]>
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
2 changes: 1 addition & 1 deletion docs/chapters/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Bastille is available in the official FreeBSD ports tree at
`sysutils/bastille`. Binary packages available in `quarterly` and `latest`
repositories.

Current version is `0.12.20241124`.
Current version is `0.12.20250111`.

To install from the FreeBSD package repository:

Expand Down
4 changes: 2 additions & 2 deletions docs/chapters/subcommands/htop.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
htop
====

This one runs `htop` inside the container.
note: won't work if you don't have htop installed in the container.
This command runs `htop` in the targeted jail.
Requires htop to be installed in the jail.


.. image:: ../../images/htop.png
Expand Down
2 changes: 1 addition & 1 deletion docs/chapters/subcommands/top.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
top
===

This one runs `top` in that container.
This command runs `top` in the targeted jail.


.. image:: ../../images/top.png
Expand Down
2 changes: 1 addition & 1 deletion docs/chapters/subcommands/umount.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Syntax requires only the jail path to unmount.
Usage: bastille umount TARGET JAIL_PATH
If the directory you are unmounting has spaces, make sure to escape them with a backslash \, and enclode the mount point in quotes "".
If the directory you are unmounting has spaces, make sure to escape them with a backslash \, and enclose the mount point in quotes "".

.. code-block:: shell
Expand Down
6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
# -- Project information -----------------------------------------------------

project = 'Bastille'
copyright = '2018-2024, Christer Edwards'
copyright = '2018-2025, Christer Edwards'
author = 'Christer Edwards'

# The short X.Y version
version = '0.12.20241124'
version = '0.12.20250111'
# The full version, including alpha/beta/rc tags
release = '0.12.20241124-beta'
release = '0.12.20250111-beta'


# -- General configuration ---------------------------------------------------
Expand Down
25 changes: 16 additions & 9 deletions usr/local/bin/bastille
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/sh
#
# Copyright (c) 2018-2024, Christer Edwards <[email protected]>
# SPDX-License-Identifier: BSD-3-Clause
#
# Copyright (c) 2018-2025, Christer Edwards <[email protected]>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -30,28 +32,32 @@

PATH=${PATH}:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin

. /usr/local/share/bastille/common.sh

## check for config existence
bastille_conf_check() {
if [ ! -r "/usr/local/etc/bastille/bastille.conf" ]; then
warn "Configuration file not found. Do yu want to create it with default values? [y/N]"
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]|"")
error_exit "No configuration file has been generated. Exiting."
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
info "Configuration file has been generated. Continuing with default values"
echo "[INFO] Configuration file has been generated. Continuing with default values"
;;
*)
echo "[ERROR] Invalid option. Please answer with 'y' or 'N'."
exit 1
;;
esac
fi
}

bastille_conf_check

## we only load the config if conf_check passes
## we only load this if conf_check passes
. /usr/local/share/bastille/common.sh
. /usr/local/etc/bastille/bastille.conf
# Set default values for config properties added during the current major version:
: "${bastille_network_pf_ext_if:=ext_if}"
Expand All @@ -72,7 +78,7 @@ bastille_perms_check() {
bastille_perms_check

## version
BASTILLE_VERSION="0.12.20241124"
BASTILLE_VERSION="0.12.20250111"

usage() {
cat << EOF
Expand All @@ -93,6 +99,7 @@ Available Commands:
create Create a new thin container or a thick container if -T|--thick option specified.
destroy Destroy a stopped container or a FreeBSD release.
edit Edit container configuration files (advanced).
etcupdate Update /etc directory to specified release.
export Exports a specified container.
help Help about any command.
htop Interactive process viewer (requires htop).
Expand Down Expand Up @@ -157,7 +164,7 @@ version|-v|--version)
help|-h|--help)
usage
;;
bootstrap|create|destroy|export|htop|import|list|mount|rdr|restart|setup|start|top|umount|update|upgrade|verify)
bootstrap|create|destroy|etcupdate|export|htop|import|list|mount|rdr|restart|setup|start|top|umount|update|upgrade|verify)
# Nothing "extra" to do for these commands. -- cwells
;;
clone|config|cmd|console|convert|cp|edit|limits|pkg|rcp|rename|service|stop|sysrc|tags|template|zfs)
Expand Down
4 changes: 3 additions & 1 deletion usr/local/share/bastille/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/sh
#
# Copyright (c) 2018-2024, Christer Edwards <[email protected]>
# SPDX-License-Identifier: BSD-3-Clause
#
# Copyright (c) 2018-2025, Christer Edwards <[email protected]>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down
106 changes: 69 additions & 37 deletions usr/local/share/bastille/clone.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/sh
#
# Copyright (c) 2018-2024, Christer Edwards <[email protected]>
# SPDX-License-Identifier: BSD-3-Clause
#
# Copyright (c) 2018-2025, Christer Edwards <[email protected]>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -103,47 +105,77 @@ update_jailconf() {

update_jailconf_vnet() {
bastille_jail_rc_conf="${bastille_jailsdir}/${NEWNAME}/root/etc/rc.conf"

# Determine number of containers and define an uniq_epair
local list_jails_num="$(bastille list jails | wc -l | awk '{print $1}')"
local num_range="$(expr "${list_jails_num}" + 1)"
jail_list=$(bastille list jail)
for _num in $(seq 0 "${num_range}"); do
if [ -n "${jail_list}" ]; then
if ! grep -q "e0b_bastille${_num}" "${bastille_jailsdir}"/*/jail.conf; then
if ! grep -q "epair${_num}" "${bastille_jailsdir}"/*/jail.conf; then
local uniq_epair="bastille${_num}"
# Determine number of interfaces and define a uniq_epair
local _if_list="$(grep -Eo 'epair[0-9]+|bastille[0-9]+' ${JAIL_CONFIG} | sort -u)"
for _if in ${_if_list}; do
local _epair_if_count="$(grep -Eo 'epair[0-9]+' ${bastille_jailsdir}/*/jail.conf | sort -u | wc -l | awk '{print $1}')"
local _bastille_if_count="$(grep -Eo 'bastille[0-9]+' ${bastille_jailsdir}/*/jail.conf | sort -u | wc -l | awk '{print $1}')"
local epair_num_range=$((_epair_if_count + 1))
local bastille_num_range=$((_bastille_if_count + 1))
if echo ${_if} | grep -Eoq 'epair[0-9]+'; then
# Update bridged VNET config
for _num in $(seq 0 "${epair_num_range}"); do
if ! grep -oq "epair${_num}" ${bastille_jailsdir}/*/jail.conf; then
# Update jail.conf epair name
local uniq_epair_bridge="${_num}"
# since we don't have access to the external_interface variable, we cat the jail.conf file to retrieve the mac prefix
# we also do not use the main generate_static_mac function here
local macaddr_prefix="$(cat ${JAIL_CONFIG} | grep -m 1 ether | grep -oE '([0-9a-f]{2}(:[0-9a-f]{2}){5})' | awk -F: '{print $1":"$2":"$3}')"
local macaddr_suffix="$(echo -n ${NEWNAME} | sha256 | cut -b -5 | sed 's/\([0-9a-fA-F][0-9a-fA-F]\)\([0-9a-fA-F][0-9a-fA-F]\)\([0-9a-fA-F]\)/\1:\2:\3/')"
local macaddr="${macaddr_prefix}:${macaddr_suffix}"
# Update the exec.* with uniq_epair when cloning jails.
# for VNET jails
sed -i '' "s|bastille\([0-9]\{1,\}\)|${uniq_epair}|g" "${JAIL_CONFIG}"
sed -i '' "s|e\([0-9]\{1,\}\)a_${NEWNAME}|e${uniq_epair_bridge}a_${NEWNAME}|g" "${JAIL_CONFIG}"
sed -i '' "s|e\([0-9]\{1,\}\)b_${NEWNAME}|e${uniq_epair_bridge}b_${NEWNAME}|g" "${JAIL_CONFIG}"
sed -i '' "s|epair\([0-9]\{1,\}\)|epair${uniq_epair_bridge}|g" "${JAIL_CONFIG}"
sed -i '' "s|exec.prestart += \"ifconfig e0a_bastille\([0-9]\{1,\}\).*description.*|exec.prestart += \"ifconfig e0a_${uniq_epair} description \\\\\"vnet host interface for Bastille jail ${NEWNAME}\\\\\"\";|" "${JAIL_CONFIG}"
sed -i '' "s|ether.*:.*:.*:.*:.*:.*a\";|ether ${macaddr}a\";|" "${JAIL_CONFIG}"
sed -i '' "s|ether.*:.*:.*:.*:.*:.*b\";|ether ${macaddr}b\";|" "${JAIL_CONFIG}"
local _if_epaira="${_if}a"
local _if_epairb="${_if}b"
local _if_vnet="$(grep ${_if_epairb} "${bastille_jail_rc_conf}" | grep -Eo -m 1 "vnet[0-9]+")"
sed -i '' "s|${_if}|epair${uniq_epair_bridge}|g" "${JAIL_CONFIG}"
# If jail had a static MAC, generate one for clone
if grep ether ${JAIL_CONFIG} | grep -qoc epair${uniq_epair_bridge}; then
local external_interface="$(grep "epair${uniq_epair_bridge}" ${JAIL_CONFIG} | grep -o '[^ ]* addm' | awk '{print $1}')"
generate_static_mac "${NEWNAME}" "${external_interface}"
sed -i '' "s|epair${uniq_epair_bridge}a ether.*:.*:.*:.*:.*:.*a\";|epair${uniq_epair_bridge}a ether ${macaddr}a\";|" "${JAIL_CONFIG}"
sed -i '' "s|epair${uniq_epair_bridge}b ether.*:.*:.*:.*:.*:.*b\";|epair${uniq_epair_bridge}b ether ${macaddr}b\";|" "${JAIL_CONFIG}"
fi
sed -i '' "s|vnet host interface for Bastille jail ${TARGET}|vnet host interface for Bastille jail ${NEWNAME}|g" "${JAIL_CONFIG}"
# Update /etc/rc.conf
sed -i '' "s|${_if_epairb}_name|epair${uniq_epair_bridge}b_name|" "${bastille_jail_rc_conf}"
if grep "vnet0" "${bastille_jail_rc_conf}" | grep -q "epair${uniq_epair_bridge}b_name"; then
if [ "${IP}" = "0.0.0.0" ]; then
sysrc -f "${bastille_jail_rc_conf}" ifconfig_vnet0="SYNCDHCP"
else
sysrc -f "${bastille_jail_rc_conf}" ifconfig_vnet0="inet ${IP}"
fi
else
sysrc -f "${bastille_jail_rc_conf}" ifconfig_${_if_vnet}="SYNCDHCP"
fi
break
fi
fi
done
elif echo ${_if} | grep -Eoq 'bastille[0-9]+'; then
# Update VNET config
for _num in $(seq 0 "${bastille_num_range}"); do
if ! grep -oq "bastille${_num}" ${bastille_jailsdir}/*/jail.conf; then
# Update jail.conf epair name
local uniq_epair="bastille${_num}"
local _if_vnet="$(grep ${_if} "${bastille_jail_rc_conf}" | grep -Eo -m 1 "vnet[0-9]+")"
sed -i '' "s|${_if}|${uniq_epair}|g" "${JAIL_CONFIG}"
# If jail had a static MAC, generate one for clone
if grep ether ${JAIL_CONFIG} | grep -qoc ${uniq_epair}; then
local external_interface="$(grep ${uniq_epair} ${JAIL_CONFIG} | grep -o 'addm.*' | awk '{print $3}' | sed 's/["|;]//g')"
generate_static_mac "${NEWNAME}" "${external_interface}"
sed -i '' "s|${uniq_epair} ether.*:.*:.*:.*:.*:.*a\";|${uniq_epair} ether ${macaddr}a\";|" "${JAIL_CONFIG}"
sed -i '' "s|${uniq_epair} ether.*:.*:.*:.*:.*:.*b\";|${uniq_epair} ether ${macaddr}b\";|" "${JAIL_CONFIG}"
fi
sed -i '' "s|vnet host interface for Bastille jail ${TARGET}|vnet host interface for Bastille jail ${NEWNAME}|g" "${JAIL_CONFIG}"
# Update /etc/rc.conf
sed -i '' "s|ifconfig_e0b_${_if}_name|ifconfig_e0b_${uniq_epair}_name|" "${bastille_jail_rc_conf}"
if grep "vnet0" "${bastille_jail_rc_conf}" | grep -q ${uniq_epair}; then
if [ "${IP}" = "0.0.0.0" ]; then
sysrc -f "${bastille_jail_rc_conf}" ifconfig_vnet0="SYNCDHCP"
else
sysrc -f "${bastille_jail_rc_conf}" ifconfig_vnet0=" inet ${IP} "
fi
else
sysrc -f "${bastille_jail_rc_conf}" ifconfig_${_if_vnet}="SYNCDHCP"
fi
break
fi
done
fi
done

# Rename interface to new uniq_epair
sed -i '' "s|ifconfig_e0b_bastille.*_name|ifconfig_e0b_${uniq_epair}_name|" "${bastille_jail_rc_conf}"
sed -i '' "s|ifconfig_e.*b_${TARGET}_name|ifconfig_e${uniq_epair_bridge}b_${NEWNAME}_name|" "${bastille_jail_rc_conf}"

# If 0.0.0.0 set DHCP, else set static IP address
if [ "${IP}" = "0.0.0.0" ]; then
sysrc -f "${bastille_jail_rc_conf}" ifconfig_vnet0="SYNCDHCP"
else
sysrc -f "${bastille_jail_rc_conf}" ifconfig_vnet0="inet ${IP}"
fi
}

update_fstab() {
Expand Down
4 changes: 3 additions & 1 deletion usr/local/share/bastille/cmd.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/sh
#
# Copyright (c) 2018-2024, Christer Edwards <[email protected]>
# SPDX-License-Identifier: BSD-3-Clause
#
# Copyright (c) 2018-2025, Christer Edwards <[email protected]>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down
2 changes: 2 additions & 0 deletions usr/local/share/bastille/colors.pre.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/sh
#
# SPDX-License-Identifier: BSD-3-Clause
#
# Copyright (c) 2014-2015 Bryan Drewery <[email protected]>
# All rights reserved.
#
Expand Down
Loading

0 comments on commit 03214c4

Please sign in to comment.