Compare commits

..

19 Commits

Author SHA1 Message Date
Christer Edwards
dd60e7f175 add support for bastille_vnet devfs.rules in bastille setup 2023-11-25 17:19:57 -07:00
Christer Edwards
32d67aea40 Merge pull request #640 from BastilleBSD/eol_patch
fix for recent EOL support patch
2023-11-25 17:07:56 -07:00
Christer Edwards
b30a7484bb fix for recent EOL support patch 2023-11-25 17:06:05 -07:00
Christer Edwards
86cb374732 Merge pull request #639 from BastilleBSD/support_lowercase
support upper & lowercase values in bastille.conf
2023-11-25 16:16:47 -07:00
Christer Edwards
622c926917 support lowercase values in bastille.conf (issue #368) 2023-11-25 15:09:11 -07:00
Christer Edwards
b05493bc8e Merge pull request #638 from BastilleBSD/create_matrix
support combining options for bastille create
2023-11-24 16:42:40 -07:00
Christer Edwards
97a0e692d9 standardize options in create matrix 2023-11-24 16:41:25 -07:00
Christer Edwards
3df39078bf support combining options for bastille create 2023-11-24 16:28:31 -07:00
Christer Edwards
620ad465d6 Merge pull request #637 from BastilleBSD/20231125_prep
update documentation for 14.0-RELEASE
2023-11-24 16:04:21 -07:00
Christer Edwards
d44c85637e update documentation for 14.0-RELEASE 2023-11-24 15:20:15 -07:00
Christer Edwards
c2b17f346d Merge pull request #635 from BastilleBSD/readthedocs
fix more readthedocs build info
2023-11-21 13:22:44 -07:00
Christer Edwards
94656350a1 fix more readthedocs build info 2023-11-21 13:20:16 -07:00
Christer Edwards
d0ff97057e Merge pull request #634 from BastilleBSD/readthedocs
fix readthedocs build info
2023-11-21 13:13:22 -07:00
Christer Edwards
dc6e755c2b fix readthedocs build info 2023-11-21 13:12:21 -07:00
Christer Edwards
c8b3fb3bc1 Merge pull request #633 from BastilleBSD/eol_patch
initial support & docs to bootstrap EOL releases
2023-11-20 16:21:31 -07:00
Christer Edwards
8906e491d0 initial support & docs to bootstrap EOL releases 2023-11-20 16:07:11 -07:00
Christer Edwards
51f9003016 Merge pull request #629 from dsh2dsh/rcordered
rcorder(8)-ed startup script
2023-11-20 15:15:13 -07:00
Christer Edwards
2de0766b54 Merge pull request #632 from BastilleBSD/osrelease_patch
add osrelease to jail.conf for new jails
2023-11-19 14:41:11 -07:00
Denis Shaposhnikov
a38403b028 rcorder(8)-ed startup script
With

```sh
bastille_enable="YES"
bastille_rcorder="YES"
```

in `/etc/rc.conf`, the script will the script will start all jails, except jails
with "KEYWORD: nostart" in jail.conf.

Example of `jail.conf` with `KEYWORD: nostart`:

```
jailname {
...
}
```

`PROVIDE:` is optional. Actually all `rcorder(8)` labels are optional, but we
can use it to build jail dependencies. For instance, if we have jail `db` and
jails `alfa` and `zeta`, we can configure it so both jails require jail `db`:

`alfa/jail.conf`:
```
alfa {
...
}
```

`zeta/jail.conf`:
```
zeta {
...
}
```

`db/jail.conf`:
```
db {
...
}
```

With this configuration jail `db` will start first and stop last.
2023-11-11 19:35:56 +01:00
18 changed files with 201 additions and 69 deletions

View File

@@ -3,5 +3,7 @@ version: 2
sphinx: sphinx:
configuration: docs/conf.py configuration: docs/conf.py
python: build:
version: 3.11 os: "ubuntu-22.04"
tools:
python: "3.11"

View File

@@ -30,7 +30,7 @@ make install
**enable at boot** **enable at boot**
```shell ```shell
sysrc bastille_enable=YES sysrc bastille_enable=YES
sysrc bastille_list="azkaban alcatraz" # (optional whitelist of jails to start at boot; default: ALL) sysrc bastille_rcorder=YES
``` ```
Upgrading from a previous version Upgrading from a previous version
@@ -40,7 +40,7 @@ When upgrading from a previous version of bastille (e.g. 0.10.20230714 to
```shell ```shell
cd /usr/local/etc/bastille cd /usr/local/etc/bastille
vimdiff bastille.conf bastille.conf.sample diff -u bastille.conf bastille.conf.sample
``` ```
Merge the lines that are present in the new bastille.conf.sample into Merge the lines that are present in the new bastille.conf.sample into
@@ -75,6 +75,7 @@ Available Commands:
mount Mount a volume inside the targeted container(s). mount Mount a volume inside the targeted container(s).
pkg Manipulate binary packages within targeted container(s). See pkg(8). pkg Manipulate binary packages within targeted container(s). See pkg(8).
rdr Redirect host port to container port. rdr Redirect host port to container port.
rcp reverse cp(1) files from a single container to the host.
rename Rename a container. rename Rename a container.
restart Restart a running container. restart Restart a running container.
service Manage services within targeted container(s). service Manage services within targeted container(s).
@@ -131,7 +132,7 @@ Example (create, start, console)
This example creates, starts and consoles into the container. This example creates, starts and consoles into the container.
```shell ```shell
ishmael ~ # bastille create alcatraz 13.2-RELEASE 10.17.89.10 ishmael ~ # bastille create alcatraz 14.0-RELEASE 10.17.89.10/24
``` ```
```shell ```shell
@@ -143,7 +144,7 @@ alcatraz: created
```shell ```shell
ishmael ~ # bastille console alcatraz ishmael ~ # bastille console alcatraz
[alcatraz]: [alcatraz]:
FreeBSD 13.2-RELEASE-p4 GENERIC FreeBSD 14.0-RELEASE GENERIC
Welcome to FreeBSD! Welcome to FreeBSD!

View File

@@ -4,7 +4,7 @@ Bastille is available in the official FreeBSD ports tree at
`sysutils/bastille`. Binary packages available in `quarterly` and `latest` `sysutils/bastille`. Binary packages available in `quarterly` and `latest`
repositories. repositories.
Current version is `0.10.20231013`. Current version is `0.10.20231125`.
To install from the FreeBSD package repository: To install from the FreeBSD package repository:
@@ -19,6 +19,7 @@ PKG
pkg install bastille pkg install bastille
sysrc bastille_enable=YES sysrc bastille_enable=YES
sysrc bastille_rcorder=YES
To install from source (don't worry, no compiling): To install from source (don't worry, no compiling):
@@ -30,6 +31,7 @@ ports
make -C /usr/ports/sysutils/bastille install clean make -C /usr/ports/sysutils/bastille install clean
sysrc bastille_enable=YES sysrc bastille_enable=YES
sysrc bastille_rcorder=YES
GIT GIT
@@ -41,6 +43,7 @@ GIT
cd bastille cd bastille
make install make install
sysrc bastille_enable=YES sysrc bastille_enable=YES
sysrc bastille_rcorder=YES
This method will install the latest files from GitHub directly onto your This method will install the latest files from GitHub directly onto your
system. It is verbose about the files it installs (for later removal), and also system. It is verbose about the files it installs (for later removal), and also

View File

@@ -128,6 +128,11 @@ host system:
## /etc/devfs.rules (NOT .conf) ## /etc/devfs.rules (NOT .conf)
[bastille_vnet=13] [bastille_vnet=13]
add include $devfsrules_hide_all
add include $devfsrules_unhide_basic
add include $devfsrules_unhide_login
add include $devfsrules_jail
add include $devfsrules_jail_vnet
add path 'bpf*' unhide add path 'bpf*' unhide
Lastly, you may want to consider these three `sysctl` values: Lastly, you may want to consider these three `sysctl` values:
@@ -155,8 +160,6 @@ Below is the definition of what these three parameters are used for and mean:
interface, set to 0 to disable it. interface, set to 0 to disable it.
**Regarding Routes** **Regarding Routes**
Bastille will attempt to auto-detect the default route from the host system and Bastille will attempt to auto-detect the default route from the host system and

View File

@@ -27,7 +27,7 @@ release version as the argument.
.. code-block:: shell .. code-block:: shell
ishmael ~ # bastille bootstrap 12.4-RELEASE [update] ishmael ~ # bastille bootstrap 14.0-RELEASE [update]
ishmael ~ # bastille bootstrap 13.2-RELEASE [update] ishmael ~ # bastille bootstrap 13.2-RELEASE [update]
To `bootstrap` a HardenedBSD release, run the bootstrap sub-command with the To `bootstrap` a HardenedBSD release, run the bootstrap sub-command with the
@@ -43,6 +43,21 @@ download the requested release. For each requested release, `bootstrap` will
download the base.txz. These files are verified (sha256 via MANIFEST file) download the base.txz. These files are verified (sha256 via MANIFEST file)
before they are extracted for use. before they are extracted for use.
EOL Releases
------------
It is sometimes necessary to run end-of-life releases for testing or legacy
application support. Dy default Bastille will only install supported releases
but you can bootstrap EOL / unsupported releases with a simple trick.
.. code-block:: shell
ishmael ~ # export BASTILLE_URL_FREEBSD=http://ftp-archive.freebsd.org/pub/FreeBSD-Archive/old-releases/
ishmael ~ # bastille bootstrap 11.2-RELEASE
By overriding the BASTILLE_URL_FREEBSD variable you can now bootstrap archived
releases from the FTP archive.
Tips Tips
---- ----

View File

@@ -12,9 +12,9 @@ copyright = '2018-2023, Christer Edwards'
author = 'Christer Edwards' author = 'Christer Edwards'
# The short X.Y version # The short X.Y version
version = '0.10.20231013' version = '0.10.20231125'
# The full version, including alpha/beta/rc tags # The full version, including alpha/beta/rc tags
release = '0.10.20231013-beta' release = '0.10.20231125-beta'
# -- General configuration --------------------------------------------------- # -- General configuration ---------------------------------------------------
@@ -26,10 +26,10 @@ templates_path = ['_templates']
source_suffix = ['.rst', '.md'] source_suffix = ['.rst', '.md']
from recommonmark.parser import CommonMarkParser #from recommonmark.parser import CommonMarkParser
source_parsers = { #source_parsers = {
'.md': CommonMarkParser, # '.md': CommonMarkParser,
} #}
master_doc = 'index' master_doc = 'index'
language = None language = None

View File

@@ -62,7 +62,7 @@ bastille_perms_check() {
bastille_perms_check bastille_perms_check
## version ## version
BASTILLE_VERSION="0.10.20231013" BASTILLE_VERSION="0.10.20231125"
usage() { usage() {
cat << EOF cat << EOF

View File

@@ -8,10 +8,19 @@
# Add the following to /etc/rc.conf[.local] to enable this service # Add the following to /etc/rc.conf[.local] to enable this service
# #
# bastille_enable (bool): Set to NO by default. # bastille_enable (bool): Set to "NO" by default.
# Set it to YES to enable bastille. # Set it to "YES" to enable bastille.
# bastille_list (string): Set to "ALL" by default. # bastille_conf (bool): Set to "/usr/local/etc/bastille/bastille.conf" by default.
# Space separated list of jails to start. # Path to bastile.conf file. Used if bastille_rcorder="YES".
# bastille_list (string): Set to "ALL" by default.
# Space separated list of jails to start or "ALL" to start all
# jails.
# bastille_rcorder (bool): Set to "NO" by default.
# Set it to "YES" to start all jails in order, defined by
# rcorder(8). It starts all jails, except jails with "KEYWORD:
# nostart" in jail.conf. Value of bastille_list is ignored in this
# case, requires correct path to bastile.conf in bastille_conf
# var.
# #
. /etc/rc.subr . /etc/rc.subr
@@ -19,24 +28,36 @@
name=bastille name=bastille
rcvar=${name}_enable rcvar=${name}_enable
: ${bastille_enable:=NO} : ${bastille_enable:="NO"}
: ${bastille_conf:="/usr/local/etc/bastille/bastille.conf"}
: ${bastille_list:="ALL"} : ${bastille_list:="ALL"}
: ${bastille_rcorder:="NO"}
command=/usr/local/bin/${name} command=/usr/local/bin/${name}
start_cmd="bastille_start" start_cmd="bastille_start"
stop_cmd="bastille_stop" stop_cmd="bastille_stop"
restart_cmd="bastille_stop && bastille_start" restart_cmd="bastille_stop && bastille_start"
rcordered_list() {
local _jailsdir
_jailsdir=$(. $bastille_conf; echo $bastille_jailsdir)
bastille_ordered_list=$(rcorder -s nostart ${_jailsdir}/*/jail.conf | xargs dirname | xargs basename | tr "\n" " ")
}
bastille_start() bastille_start()
{ {
if [ -z "${bastille_list}" ]; then
echo "bastille_list is undefined"
return 1
fi
local _jail local _jail
for _jail in ${bastille_list}; do if checkyesno bastille_rcorder; then
rcordered_list
elif [ -z "${bastille_list}" ]; then
echo "bastille_list is undefined"
return 1
else
bastille_ordered_list=${bastille_list}
fi
for _jail in ${bastille_ordered_list}; do
echo "Starting Bastille Container: ${_jail}" echo "Starting Bastille Container: ${_jail}"
${command} start ${_jail} ${command} start ${_jail}
done done
@@ -44,16 +65,20 @@ bastille_start()
bastille_stop() bastille_stop()
{ {
if [ -z "${bastille_list}" ]; then local _jail _revlist
if checkyesno bastille_rcorder; then
rcordered_list
elif [ -z "${bastille_list}" ]; then
echo "bastille_list is undefined" echo "bastille_list is undefined"
return 1 return 1
else
bastille_ordered_list=${bastille_list}
fi fi
local _jail
## reverse order of list for shutdown ## fixes #389 ## reverse order of list for shutdown ## fixes #389
bastille_revlist=$(echo "${bastille_list}" | awk '{ for (i=NF; i>1; i--) printf("%s ",$i); print $1; }') _revlist=$(echo "${bastille_ordered_list}" | awk '{ for (i=NF; i>1; i--) printf("%s ",$i); print $1; }')
for _jail in ${bastille_revlist}; do for _jail in ${_revlist}; do
echo "Stopping Bastille Container: ${_jail}" echo "Stopping Bastille Container: ${_jail}"
${command} stop ${_jail} ${command} stop ${_jail}
done done

View File

@@ -45,7 +45,7 @@ esac
bastille_root_check bastille_root_check
#Validate if ZFS is enabled in rc.conf and bastille.conf. #Validate if ZFS is enabled in rc.conf and bastille.conf.
if [ "$(sysrc -n zfs_enable)" = "YES" ] && [ ! "${bastille_zfs_enable}" = "YES" ]; then if [ "$(sysrc -n zfs_enable)" = "YES" ] && checkyesno bastille_zfs_enable; then
warn "ZFS is enabled in rc.conf but not bastille.conf. Do you want to continue? (N|y)" warn "ZFS is enabled in rc.conf but not bastille.conf. Do you want to continue? (N|y)"
read answer read answer
case $answer in case $answer in
@@ -57,7 +57,7 @@ if [ "$(sysrc -n zfs_enable)" = "YES" ] && [ ! "${bastille_zfs_enable}" = "YES"
fi fi
# Validate ZFS parameters. # Validate ZFS parameters.
if [ "${bastille_zfs_enable}" = "YES" ]; then if checkyesno bastille_zfs_enable; then
## check for the ZFS pool and bastille prefix ## check for the ZFS pool and bastille prefix
if [ -z "${bastille_zfs_zpool}" ]; then if [ -z "${bastille_zfs_zpool}" ]; then
error_exit "ERROR: Missing ZFS parameters. See bastille_zfs_zpool." error_exit "ERROR: Missing ZFS parameters. See bastille_zfs_zpool."
@@ -102,7 +102,7 @@ bootstrap_directories() {
## ${bastille_prefix} ## ${bastille_prefix}
if [ ! -d "${bastille_prefix}" ]; then if [ ! -d "${bastille_prefix}" ]; then
if [ "${bastille_zfs_enable}" = "YES" ];then if checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then if [ -n "${bastille_zfs_zpool}" ]; then
zfs create ${bastille_zfs_options} -o mountpoint="${bastille_prefix}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}" zfs create ${bastille_zfs_options} -o mountpoint="${bastille_prefix}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}"
fi fi
@@ -114,7 +114,7 @@ bootstrap_directories() {
## ${bastille_backupsdir} ## ${bastille_backupsdir}
if [ ! -d "${bastille_backupsdir}" ]; then if [ ! -d "${bastille_backupsdir}" ]; then
if [ "${bastille_zfs_enable}" = "YES" ];then if checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then if [ -n "${bastille_zfs_zpool}" ]; then
zfs create ${bastille_zfs_options} -o mountpoint="${bastille_backupsdir}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/backups" zfs create ${bastille_zfs_options} -o mountpoint="${bastille_backupsdir}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/backups"
fi fi
@@ -126,7 +126,7 @@ bootstrap_directories() {
## ${bastille_cachedir} ## ${bastille_cachedir}
if [ ! -d "${bastille_cachedir}" ]; then if [ ! -d "${bastille_cachedir}" ]; then
if [ "${bastille_zfs_enable}" = "YES" ]; then if checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then if [ -n "${bastille_zfs_zpool}" ]; then
zfs create ${bastille_zfs_options} -o mountpoint="${bastille_cachedir}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/cache" zfs create ${bastille_zfs_options} -o mountpoint="${bastille_cachedir}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/cache"
# Don't create unused/stale cache/RELEASE directory on Linux jails creation. # Don't create unused/stale cache/RELEASE directory on Linux jails creation.
@@ -145,7 +145,7 @@ bootstrap_directories() {
elif [ ! -d "${bastille_cachedir}/${RELEASE}" ]; then elif [ ! -d "${bastille_cachedir}/${RELEASE}" ]; then
# Don't create unused/stale cache/RELEASE directory on Linux jails creation. # Don't create unused/stale cache/RELEASE directory on Linux jails creation.
if [ -z "${NOCACHEDIR}" ]; then if [ -z "${NOCACHEDIR}" ]; then
if [ "${bastille_zfs_enable}" = "YES" ]; then if checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then if [ -n "${bastille_zfs_zpool}" ]; then
zfs create ${bastille_zfs_options} -o mountpoint="${bastille_cachedir}/${RELEASE}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/cache/${RELEASE}" zfs create ${bastille_zfs_options} -o mountpoint="${bastille_cachedir}/${RELEASE}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/cache/${RELEASE}"
fi fi
@@ -157,7 +157,7 @@ bootstrap_directories() {
## ${bastille_jailsdir} ## ${bastille_jailsdir}
if [ ! -d "${bastille_jailsdir}" ]; then if [ ! -d "${bastille_jailsdir}" ]; then
if [ "${bastille_zfs_enable}" = "YES" ]; then if checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then if [ -n "${bastille_zfs_zpool}" ]; then
zfs create ${bastille_zfs_options} -o mountpoint="${bastille_jailsdir}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails" zfs create ${bastille_zfs_options} -o mountpoint="${bastille_jailsdir}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails"
fi fi
@@ -168,7 +168,7 @@ bootstrap_directories() {
## ${bastille_logsdir} ## ${bastille_logsdir}
if [ ! -d "${bastille_logsdir}" ]; then if [ ! -d "${bastille_logsdir}" ]; then
if [ "${bastille_zfs_enable}" = "YES" ]; then if checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then if [ -n "${bastille_zfs_zpool}" ]; then
zfs create ${bastille_zfs_options} -o mountpoint="${bastille_logsdir}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/logs" zfs create ${bastille_zfs_options} -o mountpoint="${bastille_logsdir}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/logs"
fi fi
@@ -179,7 +179,7 @@ bootstrap_directories() {
## ${bastille_templatesdir} ## ${bastille_templatesdir}
if [ ! -d "${bastille_templatesdir}" ]; then if [ ! -d "${bastille_templatesdir}" ]; then
if [ "${bastille_zfs_enable}" = "YES" ]; then if checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then if [ -n "${bastille_zfs_zpool}" ]; then
zfs create ${bastille_zfs_options} -o mountpoint="${bastille_templatesdir}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/templates" zfs create ${bastille_zfs_options} -o mountpoint="${bastille_templatesdir}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/templates"
fi fi
@@ -190,7 +190,7 @@ bootstrap_directories() {
## ${bastille_releasesdir} ## ${bastille_releasesdir}
if [ ! -d "${bastille_releasesdir}" ]; then if [ ! -d "${bastille_releasesdir}" ]; then
if [ "${bastille_zfs_enable}" = "YES" ]; then if checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then if [ -n "${bastille_zfs_zpool}" ]; then
zfs create ${bastille_zfs_options} -o mountpoint="${bastille_releasesdir}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases" zfs create ${bastille_zfs_options} -o mountpoint="${bastille_releasesdir}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases"
zfs create ${bastille_zfs_options} -o mountpoint="${bastille_releasesdir}/${RELEASE}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${RELEASE}" zfs create ${bastille_zfs_options} -o mountpoint="${bastille_releasesdir}/${RELEASE}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${RELEASE}"
@@ -201,7 +201,7 @@ bootstrap_directories() {
## create subsequent releases/XX.X-RELEASE datasets ## create subsequent releases/XX.X-RELEASE datasets
elif [ ! -d "${bastille_releasesdir}/${RELEASE}" ]; then elif [ ! -d "${bastille_releasesdir}/${RELEASE}" ]; then
if [ "${bastille_zfs_enable}" = "YES" ]; then if checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then if [ -n "${bastille_zfs_zpool}" ]; then
zfs create ${bastille_zfs_options} -o mountpoint="${bastille_releasesdir}/${RELEASE}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${RELEASE}" zfs create ${bastille_zfs_options} -o mountpoint="${bastille_releasesdir}/${RELEASE}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${RELEASE}"
fi fi
@@ -249,7 +249,7 @@ bootstrap_release() {
if [ "${FETCH_VALIDATION}" -ne "0" ]; then if [ "${FETCH_VALIDATION}" -ne "0" ]; then
## perform cleanup only for stale/empty directories on failure ## perform cleanup only for stale/empty directories on failure
if [ "${bastille_zfs_enable}" = "YES" ]; then if checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then if [ -n "${bastille_zfs_zpool}" ]; then
if [ ! "$(ls -A "${bastille_cachedir}/${RELEASE}")" ]; then if [ ! "$(ls -A "${bastille_cachedir}/${RELEASE}")" ]; then
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/cache/${RELEASE}" zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/cache/${RELEASE}"
@@ -383,7 +383,7 @@ debootstrap_release() {
info "Bootstrapping ${PLATFORM_OS} distfiles..." info "Bootstrapping ${PLATFORM_OS} distfiles..."
if ! debootstrap --foreign --arch=${ARCH_BOOTSTRAP} --no-check-gpg ${LINUX_FLAVOR} "${bastille_releasesdir}"/${DIR_BOOTSTRAP}; then if ! debootstrap --foreign --arch=${ARCH_BOOTSTRAP} --no-check-gpg ${LINUX_FLAVOR} "${bastille_releasesdir}"/${DIR_BOOTSTRAP}; then
## perform cleanup only for stale/empty directories on failure ## perform cleanup only for stale/empty directories on failure
if [ "${bastille_zfs_enable}" = "YES" ]; then if checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then if [ -n "${bastille_zfs_zpool}" ]; then
if [ ! "$(ls -A "${bastille_releasesdir}/${DIR_BOOTSTRAP}")" ]; then if [ ! "$(ls -A "${bastille_releasesdir}/${DIR_BOOTSTRAP}")" ]; then
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${DIR_BOOTSTRAP}" zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${DIR_BOOTSTRAP}"
@@ -414,7 +414,7 @@ bootstrap_template() {
## ${bastille_templatesdir} ## ${bastille_templatesdir}
if [ ! -d "${bastille_templatesdir}" ]; then if [ ! -d "${bastille_templatesdir}" ]; then
if [ "${bastille_zfs_enable}" = "YES" ]; then if checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then if [ -n "${bastille_zfs_zpool}" ]; then
zfs create ${bastille_zfs_options} -o mountpoint="${bastille_templatesdir}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/templates" zfs create ${bastille_zfs_options} -o mountpoint="${bastille_templatesdir}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/templates"
fi fi
@@ -473,6 +473,11 @@ if [ -n "${OPTION}" ] && [ "${OPTION}" != "${HW_MACHINE}" ] && [ "${OPTION}" !=
fi fi
fi fi
## allow override bootstrap URLs via environment variables
[ -n "${BASTILLE_URL_FREEBSD}" ] && bastille_url_freebsd="${BASTILLE_URL_FREEBSD}"
[ -n "${BASTILLE_URL_HARDENEDBSD}" ] && bastille_url_hardenedbsd="${BASTILLE_URL_HARDENEDBSD}"
[ -n "${BASTILLE_URL_MIDNIGHTBSD}" ] && bastille_url_midnightbsd="${BASTILLE_URL_MIDNIGHTBSD}"
## Filter sane release names ## Filter sane release names
case "${1}" in case "${1}" in
2.[0-9]*) 2.[0-9]*)
@@ -491,7 +496,7 @@ case "${1}" in
;; ;;
*-RELEASE|*-release|*-RC[1-9]|*-rc[1-9]|*-BETA[1-9]) *-RELEASE|*-release|*-RC[1-9]|*-rc[1-9]|*-BETA[1-9])
## check for FreeBSD releases name ## check for FreeBSD releases name
NAME_VERIFY=$(echo "${RELEASE}" | grep -iwE '^([1-9]{2,2})\.[0-9](-RELEASE|-RC[1-9]|-BETA[1-9])$' | tr '[:lower:]' '[:upper:]') NAME_VERIFY=$(echo "${RELEASE}" | grep -iwE '^([0-9]{1,2})\.[0-9](-RELEASE|-RC[1-9]|-BETA[1-9])$' | tr '[:lower:]' '[:upper:]')
UPSTREAM_URL="${bastille_url_freebsd}${HW_MACHINE}/${HW_MACHINE_ARCH}/${NAME_VERIFY}" UPSTREAM_URL="${bastille_url_freebsd}${HW_MACHINE}/${HW_MACHINE_ARCH}/${NAME_VERIFY}"
PLATFORM_OS="FreeBSD" PLATFORM_OS="FreeBSD"
validate_release_url validate_release_url

View File

@@ -154,7 +154,7 @@ clone_jail() {
# Attempt container clone # Attempt container clone
info "Attempting to clone '${TARGET}' to ${NEWNAME}..." info "Attempting to clone '${TARGET}' to ${NEWNAME}..."
if ! [ -d "${bastille_jailsdir}/${NEWNAME}" ]; then if ! [ -d "${bastille_jailsdir}/${NEWNAME}" ]; then
if [ "${bastille_zfs_enable}" = "YES" ]; then if checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then if [ -n "${bastille_zfs_zpool}" ]; then
# Replicate the existing container # Replicate the existing container
DATE=$(date +%F-%H%M%S) DATE=$(date +%F-%H%M%S)

View File

@@ -117,3 +117,24 @@ EOF
EOF EOF
fi fi
} }
checkyesno() {
## copied from /etc/rc.subr -- cedwards (20231125)
## issue #368 (lowercase values should be parsed)
## now used for all bastille_zfs_enable=YES|NO tests
## example: if checkyesno bastille_zfs_enable; then ...
## returns 0 for enabled; returns 1 for disabled
eval _value=\$${1}
case $_value in
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
return 0
;;
[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0)
return 1
;;
*)
warn "\$${1} is not set properly - see rc.conf(5)."
return 1
;;
esac
}

View File

@@ -281,7 +281,7 @@ create_jail() {
bastille_jail_resolv_conf="${bastille_jailsdir}/${NAME}/root/etc/resolv.conf" ## file bastille_jail_resolv_conf="${bastille_jailsdir}/${NAME}/root/etc/resolv.conf" ## file
if [ ! -d "${bastille_jailsdir}/${NAME}" ]; then if [ ! -d "${bastille_jailsdir}/${NAME}" ]; then
if [ "${bastille_zfs_enable}" = "YES" ]; then if checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then if [ -n "${bastille_zfs_zpool}" ]; then
## create required zfs datasets, mountpoint inherited from system ## create required zfs datasets, mountpoint inherited from system
if [ -z "${CLONE_JAIL}" ]; then if [ -z "${CLONE_JAIL}" ]; then
@@ -388,7 +388,7 @@ create_jail() {
fi fi
done done
else else
if [ "${bastille_zfs_enable}" = "YES" ]; then if checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then if [ -n "${bastille_zfs_zpool}" ]; then
if [ -n "${CLONE_JAIL}" ]; then if [ -n "${CLONE_JAIL}" ]; then
info "Creating a clonejail...\n" info "Creating a clonejail...\n"
@@ -607,36 +607,80 @@ 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) -E|--empty)
EMPTY_JAIL="1" EMPTY_JAIL="1"
shift shift
;; ;;
-L|--linux|linux) -L|--linux)
LINUX_JAIL="1" LINUX_JAIL="1"
shift shift
;; ;;
-T|--thick|thick) -T|--thick)
THICK_JAIL="1" THICK_JAIL="1"
shift shift
;; ;;
-V|--vnet|vnet) -V|--vnet)
VNET_JAIL="1" VNET_JAIL="1"
shift shift
;; ;;
-B|--bridge|bridge) -B|--bridge)
VNET_JAIL="1" VNET_JAIL="1"
VNET_JAIL_BRIDGE="1" VNET_JAIL_BRIDGE="1"
shift shift
;; ;;
-C|--clone|clone) -C|--clone)
CLONE_JAIL="1" CLONE_JAIL="1"
shift shift
;; ;;
-CV|-VC|--clone-vnet)
CLONE_JAIL="1"
VNET_JAIL="1"
shift
;;
-CB|-BC|--clone-bridge)
CLONE_JAIL="1"
VNET_JAIL="1"
VNET_JAIL_BRIDGE="1"
shift
;;
-TV|-VT|--thick-vnet)
THICK_JAIL="1"
VNET_JAIL="1"
shift
;;
-TB|-BT|--thick-bridge)
THICK_JAIL="1"
VNET_JAIL="1"
VNET_JAIL_BRIDGE="1"
shift
;;
-EB|-BE|--empty-bridge)
EMPTY_JAIL="1"
VNET_JAIL="1"
VNET_JAIL_BRIDGE="1"
shift
;;
-EV|-VE|--empty-vnet)
EMPTY_JAIL="1"
VNET_JAIL="1"
shift
;;
-LV|-VL|--linux-vnet)
LINUX_JAIL="1"
VNET_JAIL="1"
shift
;;
-LB|-BL|--linux-bridge)
LINUX_JAIL="1"
VNET_JAIL="1"
VNET_JAIL_BRIDGE="1"
shift
;;
-*|--*) -*|--*)
error_notify "Unknown Option." error_notify "Unknown Option."
usage usage
;; ;;
*) *)
break break
;; ;;
esac esac

View File

@@ -55,7 +55,7 @@ destroy_jail() {
if [ -d "${bastille_jail_base}" ]; then if [ -d "${bastille_jail_base}" ]; then
info "Deleting Jail: ${TARGET}." info "Deleting Jail: ${TARGET}."
if [ "${bastille_zfs_enable}" = "YES" ]; then if checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then if [ -n "${bastille_zfs_zpool}" ]; then
if [ -n "${TARGET}" ]; then if [ -n "${TARGET}" ]; then
OPTIONS="-r" OPTIONS="-r"
@@ -118,7 +118,7 @@ destroy_rel() {
if grep -qwo "${TARGET}" "${bastille_jailsdir}/${_jail}/fstab" 2>/dev/null; then if grep -qwo "${TARGET}" "${bastille_jailsdir}/${_jail}/fstab" 2>/dev/null; then
error_notify "Notice: (${_jail}) depends on ${TARGET} base." error_notify "Notice: (${_jail}) depends on ${TARGET} base."
BASE_HASCHILD="1" BASE_HASCHILD="1"
elif [ "${bastille_zfs_enable}" = "YES" ]; then elif checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then if [ -n "${bastille_zfs_zpool}" ]; then
## check if this release have child clones ## check if this release have child clones
if zfs list -H -t snapshot -r "${bastille_rel_base}" > /dev/null 2>&1; then if zfs list -H -t snapshot -r "${bastille_rel_base}" > /dev/null 2>&1; then
@@ -144,7 +144,7 @@ destroy_rel() {
else else
if [ "${BASE_HASCHILD}" -eq "0" ]; then if [ "${BASE_HASCHILD}" -eq "0" ]; then
info "Deleting base: ${TARGET}" info "Deleting base: ${TARGET}"
if [ "${bastille_zfs_enable}" = "YES" ]; then if checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then if [ -n "${bastille_zfs_zpool}" ]; then
if [ -n "${TARGET}" ]; then if [ -n "${TARGET}" ]; then
OPTIONS="-r" OPTIONS="-r"

View File

@@ -75,7 +75,7 @@ bastille_root_check
zfs_enable_check() { zfs_enable_check() {
# Temporarily disable ZFS so we can create a standard backup archive # Temporarily disable ZFS so we can create a standard backup archive
if [ "${bastille_zfs_enable}" = "YES" ]; then if checkyesno bastille_zfs_enable; then
bastille_zfs_enable="NO" bastille_zfs_enable="NO"
fi fi
} }
@@ -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 [ -z "${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
@@ -294,7 +294,7 @@ export_check() {
create_zfs_snap create_zfs_snap
fi fi
if [ "${bastille_zfs_enable}" = "YES" ]; then if checkyesno bastille_zfs_enable; then
if [ -z "${USER_EXPORT}" ]; then if [ -z "${USER_EXPORT}" ]; then
info "Sending ZFS data stream..." info "Sending ZFS data stream..."
fi fi
@@ -304,7 +304,7 @@ export_check() {
jail_export() { jail_export() {
# Attempt to export the container # Attempt to export the container
DATE=$(date +%F-%H%M%S) DATE=$(date +%F-%H%M%S)
if [ "${bastille_zfs_enable}" = "YES" ]; then if checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then if [ -n "${bastille_zfs_zpool}" ]; then
if [ -n "${RAW_EXPORT}" ]; then if [ -n "${RAW_EXPORT}" ]; then
FILE_EXT="" FILE_EXT=""
@@ -384,7 +384,7 @@ if [ -n "${TARGET}" ]; then
fi fi
# Check if is a ZFS system # Check if is a ZFS system
if [ "${bastille_zfs_enable}" != "YES" ]; then if ! checkyesno bastille_zfs_enable; then
# Check if container is running and ask for stop in non ZFS systems # Check if container is running and ask for stop in non ZFS systems
if [ -n "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then if [ -n "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
error_exit "${TARGET} is running. See 'bastille stop'." error_exit "${TARGET} is running. See 'bastille stop'."

View File

@@ -410,7 +410,7 @@ jail_import() {
FILE_TRIM=$(echo "${TARGET}" | sed 's/\.xz//g;s/\.gz//g;s/\.tgz//g;s/\.txz//g;s/\.zip//g;s/\.tar\.gz//g;s/\.tar//g') FILE_TRIM=$(echo "${TARGET}" | sed 's/\.xz//g;s/\.gz//g;s/\.tgz//g;s/\.txz//g;s/\.zip//g;s/\.tar\.gz//g;s/\.tar//g')
FILE_EXT=$(echo "${TARGET}" | sed "s/${FILE_TRIM}//g") FILE_EXT=$(echo "${TARGET}" | sed "s/${FILE_TRIM}//g")
if [ -d "${bastille_jailsdir}" ]; then if [ -d "${bastille_jailsdir}" ]; then
if [ "${bastille_zfs_enable}" = "YES" ]; then if checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then if [ -n "${bastille_zfs_zpool}" ]; then
if [ "${FILE_EXT}" = ".xz" ]; then if [ "${FILE_EXT}" = ".xz" ]; then
validate_archive validate_archive

View File

@@ -105,7 +105,7 @@ update_fstab() {
change_name() { change_name() {
# Attempt container name change # Attempt container name change
info "Attempting to rename '${TARGET}' to ${NEWNAME}..." info "Attempting to rename '${TARGET}' to ${NEWNAME}..."
if [ "${bastille_zfs_enable}" = "YES" ]; then if checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ] && [ -n "${bastille_zfs_prefix}" ]; then if [ -n "${bastille_zfs_zpool}" ] && [ -n "${bastille_zfs_prefix}" ]; then
# Check and rename container ZFS dataset accordingly # Check and rename container ZFS dataset accordingly
# Perform additional checks in case of non-ZFS existing containers # Perform additional checks in case of non-ZFS existing containers

View File

@@ -57,6 +57,19 @@ configure_vnet() {
info "Bringing up new interface: bastille1" info "Bringing up new interface: bastille1"
service netif cloneup service netif cloneup
if [ ! -f /etc/devfs.rules ]; then
info "Creating bastille_vnet devfs.rules"
cat << EOF > /etc/devfs.rules
[bastille_vnet=13]
add include \$devfsrules_hide_all
add include \$devfsrules_unhide_basic
add include \$devfsrules_unhide_login
add include \$devfsrules_jail
add include \$devfsrules_jail_vnet
add path 'bpf*' unhide
EOF
fi
} }
# Configure pf firewall # Configure pf firewall

View File

@@ -85,7 +85,7 @@ esac
bastille_root_check bastille_root_check
## check ZFS enabled ## check ZFS enabled
if [ ! "${bastille_zfs_enable}" = "YES" ]; then if ! checkyesno bastille_zfs_enable; then
error_exit "ZFS not enabled." error_exit "ZFS not enabled."
fi fi