Compare commits

..

93 Commits

Author SHA1 Message Date
Christer Edwards
00d9e03520 Merge pull request #477 from cedwards/christmas_release
prepare for 0.9.20211225 release
2021-12-24 20:59:46 -07:00
Christer Edwards
9010b58eb8 prepare for 0.9.20211225 release 2021-12-24 20:58:14 -07:00
Christer Edwards
aaea27dcb3 Merge pull request #476 from cedwards/host_pkg_fix
accidentally the jail name in run test
2021-12-23 14:36:14 -07:00
Christer Edwards
c825f0ca75 accidentally the jail name in run test 2021-12-23 14:34:43 -07:00
Christer Edwards
7558fd42ca Merge pull request #475 from cedwards/jls_patch
change new PKG option from -P to -H
2021-12-23 14:19:10 -07:00
Christer Edwards
570c80ba85 change new PKG option from -P to -H 2021-12-23 14:13:23 -07:00
Christer Edwards
b7914ba67a Merge pull request #474 from cedwards/jls_patch
jls path fix + support using host package manager
2021-12-23 14:01:36 -07:00
Christer Edwards
e21d31518a jls path fix + support using host package manager 2021-12-23 13:57:18 -07:00
Christer Edwards
d3d5bf2df4 Merge pull request #473 from cedwards/debian_bullseye
add Debian 11 'bullseye' to Linux supported list
2021-12-22 18:38:20 -07:00
Christer Edwards
2f59bdecec add Debian 11 'bullseye' to Linux supported list 2021-12-22 18:35:49 -07:00
Christer Edwards
a115ba5b87 Merge pull request #420 from JRGTH/master
Extra validation for Linux jails, small changes
2021-12-21 20:15:58 -07:00
Christer Edwards
ef070c9aed Merge pull request #450 from w4andy/feature/update-template
easy way to update templates
2021-12-21 19:29:29 -07:00
Christer Edwards
e2f051f899 Merge pull request #471 from cedwards/fix-vnet
hotfix for the VNET interface description patch
2021-12-21 19:21:23 -07:00
Christer Edwards
5dabc75257 hotfix for the VNET interface description patch 2021-12-21 19:20:31 -07:00
Christer Edwards
8683ad15d2 Merge pull request #469 from cedwards/fix_460_jls_path
use full path when calling jls binary
2021-12-17 19:12:19 -07:00
Christer Edwards
faf3b2b691 use full path when calling jls binary 2021-12-17 19:09:49 -07:00
Christer Edwards
8a4b0a1f5c Merge pull request #467 from yaazkal/tzdata
Use host's time zone by default for jails
2021-12-17 18:28:12 -07:00
yaazkal
68951de687 [FIX] Only use host's time zone for jails when already set in host 2021-12-12 12:38:05 -05:00
yaazkal
35d3038bea [REF] Use host's time zone for jails by default 2021-12-12 12:10:39 -05:00
Christer Edwards
947ed27f90 Merge pull request #445 from frikilax/custom_template_path
TEMPLATE.SH::ADDED:: ability to apply templates using a custom directory path
2021-12-09 10:54:23 -07:00
Christer Edwards
c09a5b05bf Merge pull request #459 from robarnold/description
Add a description to the host vnet interface
2021-12-09 10:53:28 -07:00
Christer Edwards
bbe44f79c6 Merge pull request #466 from yaazkal/ref_bootstrap
[REF] bootsrap: Removes code duplication to prevent future errors
2021-12-09 10:52:49 -07:00
Christer Edwards
4c4edc07c5 Merge pull request #451 from w4andy/update-vagrant
update vagrant to FreeBSD-13.0 and install git
2021-12-09 10:51:37 -07:00
Christer Edwards
da2f9bce8e Merge pull request #446 from frikilax/clone_fix
Fixed to update_fstab() in clone.sh
2021-12-09 10:50:32 -07:00
Christer Edwards
3af8d7384c Merge pull request #442 from zilti/master
Fix for issue #403
2021-12-09 10:49:18 -07:00
Christer Edwards
7c255d26b3 Merge pull request #452 from w4andy/verify-fix-bastillefile-include
add recursive verify for includes in Bastillefile
2021-12-09 10:48:09 -07:00
Christer Edwards
2327c6a662 Merge pull request #461 from robarnold/devfs
Use the devfs_ruleset number from imported iocage jails
2021-12-09 10:46:58 -07:00
Christer Edwards
d6b12f93e7 Merge pull request #465 from draga79/master
Added code and -B option to "create" to allow creating/managing jails attached to external bridge
2021-12-09 10:45:58 -07:00
Yaazkal
1c5d343171 [REF] bootsrap: Removes code duplication to prevent future errors 2021-12-05 08:56:59 -05:00
Stefano Marinelli
d951a70b30 Added doc and fixes - bridge support 2021-12-02 15:22:08 +01:00
Stefano Marinelli
ec1356df08 Added and modified code for existing bridge jail attachement. 2021-12-02 15:06:47 +01:00
Rob Arnold
5aba3df6ae Use the devfs_ruleset number from imported iocage jails
This property is not set by default on all iocage jails. By default, iocage assumes this value is 4. Confusingly, if you query this value from iocage while the jail is running, it will give a dynamically generated value. However, a jail must be stopped to be exported, so we can trust the value in config.json.
2021-11-19 21:46:22 -08:00
Rob Arnold
0a232dd140 Add a description to the host vnet interface
This makes it much easier to understand `ifconfig` when run on the jail host. Not sure how to test this, but manually appyling this via `bastille edit` to an existing vnet jail had the right effects when I restarted the jail.
2021-11-14 19:53:55 -08:00
Christer Edwards
e49662bab4 Merge pull request #457 from cedwards/readthedocs
fixing issue with docs (conflict with docutils v0.18)
2021-11-07 09:44:25 -07:00
Christer Edwards
f4c60291c0 fixing issue with docs (conflict with docutils v0.18) 2021-11-07 09:42:13 -07:00
Christer Edwards
d1043bded2 Merge pull request #456 from cedwards/docs-quickfix
minor fix for docs path
2021-11-05 16:08:49 -06:00
Christer Edwards
6f8f025baf minor fix for docs path 2021-11-05 16:08:04 -06:00
Christer Edwards
a73173e828 Merge pull request #455 from cedwards/docs-quickfix
add zfs-support doc to toctree
2021-11-05 16:06:13 -06:00
Christer Edwards
97d15d1a2f add zfs-support doc to toctree 2021-11-05 16:05:16 -06:00
Christer Edwards
22b8f2f041 Merge pull request #454 from cedwards/docs-quickfix
fix image path for zfs support screenshot
2021-11-05 15:53:13 -06:00
Christer Edwards
686fbc8572 fix image path for zfs support screenshot 2021-11-05 15:52:01 -06:00
Christer Edwards
85f138cd5a Merge pull request #453 from Bennykillua/zfs-support-to-docs
Zfs support to docs
2021-11-05 15:43:19 -06:00
Bennykillua
5c947d46d6 zfs support to docs 2021-11-05 15:40:02 +01:00
Bennykillua
45b4005237 adding zfs support to docs 2021-11-05 15:31:20 +01:00
Andreas Diem
ce52faad9d add recursive verify for includes in Bastillefile 2021-11-01 21:45:15 +01:00
Andreas Diem
db2e7e3062 update vagrant to FreeBSD-13.0 and install git 2021-11-01 15:55:32 +01:00
Andreas Diem
4aa6b35e20 simple template update command 2021-11-01 15:54:08 +01:00
JRGTH
1e32811ea6 Update bootstrap.sh 2021-09-20 04:47:25 -04:00
JRGTH
c0e2499dfc Bootstrap cmd consistency updates/improvements 2021-09-13 05:06:23 -04:00
Théo Bertin
35938461d4 CLONE.SH::FIXED:: ensure release grep in update_fstab only returns the release name once
Situations could happen when release name could match several times (if jail name contains release name for example)
2021-09-11 12:50:55 +02:00
Théo Bertin
b0c5a61d4a CLONE.SH::FIXED:: remove duplicate match group in release grep during fstab updating 2021-09-11 12:42:17 +02:00
Théo Bertin
2446f5c70e TEMPLATE.SH::ADDED:: ability to apply templates using a custom absolute directory path 2021-09-11 12:16:54 +02:00
Daniel Ziltener
cd054f2a32 Fix for issue #403 2021-09-02 22:44:49 +02:00
Christer Edwards
27ea04712f Merge pull request #436 from yaazkal/patch-4
Sets require NETWORKING in the rc script
2021-08-07 20:55:37 -06:00
yaazkal
77afbd189f Sets require NETWORKING in the rc script
In general and knowing what role will play bastille in the system, has more sense to require networking than login.

This can also helps speeding up boot time if for instance some jails in bastille provide some kind of networking role like acting as a DNS server.
2021-08-07 18:23:10 -05:00
JRGTH
125b829872 Small cosmetic changes/readability 2021-08-07 13:33:57 -04:00
JRGTH
e92451b37c Add debian stretch/buster, small changes 2021-08-07 13:17:32 -04:00
JRGTH
9967a56e64 Improvements for Linux releases and code maintenance 2021-08-06 19:44:25 -04:00
JRGTH
9d3cb5f5e3 Merge remote-tracking branch 'upstream/master' 2021-08-06 17:22:22 -04:00
Christer Edwards
fdc688bafe Merge pull request #433 from cedwards/linux-pkg-support
basic PKG support for ubuntu/debian containers
2021-07-31 19:49:09 -06:00
Christer Edwards
03c830bea4 basic PKG support for ubuntu/debian containers 2021-07-31 19:47:01 -06:00
Christer Edwards
cd93e139a2 Merge pull request #432 from cedwards/mount_all_fix
fix overloaded variable in mount command
2021-07-31 15:24:12 -06:00
Christer Edwards
cc38fabd31 fix overloaded variable in mount command 2021-07-31 15:22:17 -06:00
Christer Edwards
c77ffb9617 Merge pull request #431 from cedwards/no_color_improvement
improve NO_COLOR detection
2021-07-31 15:06:05 -06:00
Christer Edwards
3a7e720e82 improve NO_COLOR detection 2021-07-31 15:04:08 -06:00
Christer Edwards
30ba4bbb69 revert double-slash fix
this causes issues if the user doesn't provide a starting /. cosmetic only.
2021-07-31 14:42:24 -06:00
Christer Edwards
7f1dbc17c9 Merge pull request #303 from yerrysherry/cmdbug
bastille cmd exit code not respected #272
2021-07-31 14:40:05 -06:00
Christer Edwards
5c89ac5a27 Merge branch 'master' into cmdbug 2021-07-31 14:39:24 -06:00
Christer Edwards
c02a8735d8 Merge pull request #430 from yaazkal/debian10
Adds: Debian 10 (Buster) as a release for linux jails
2021-07-30 13:00:23 -06:00
Yaazkal
5fcc56367d Fix: Debian 10 (Buster) path for increasing apt cache-start 2021-07-30 07:41:24 -05:00
Yaazkal
a21be862d8 Adds: Debian 10 (Buster) as a release for linux jails 2021-07-30 07:40:01 -05:00
Christer Edwards
4be0143de5 Merge pull request #429 from FloGatt/vnet_ipv6
Added logic for setting ipv6_defaultrouter for vnet template
2021-07-27 10:38:49 -06:00
Florian Gattermeier
2581218f82 Added logic for setting ipv6_defaultrouter for vnet template 2021-07-26 11:13:04 +02:00
Christer Edwards
47fed3a76d Merge pull request #427 from yaazkal/linux-debian-distros
Adds: Debian 9 (Stretch) as a release for linux jails
2021-07-23 15:53:24 -06:00
Yaazkal
f6b2e57051 Adds: Debian 9 (Stretch) as a release for linux jails 2021-07-23 12:07:21 -05:00
Christer Edwards
7c8c324a17 Merge pull request #426 from yaazkal/linux-bootstrap-functions
Refactor: Creates Linux jails bootstrap functions
2021-07-23 10:46:40 -06:00
Christer Edwards
e99fc5de6c Merge pull request #425 from yaazkal/patch-3
Fix minor typo in README
2021-07-23 10:44:38 -06:00
Yaazkal
403d6739bc Fix: removes unwanted line in esure_debootstrap 2021-07-23 05:56:00 -05:00
Yaazkal
295e57ac04 Refactor: removes cosmetic whitelines 2021-07-23 05:51:35 -05:00
Yaazkal
85b5c204c4 Refactor: Creates ensure_debootstrap an change logic to prevent typing errors because of duplicated code 2021-07-23 05:50:23 -05:00
Yaazkal
f9018047ea Refactor: check_linux_prerequisites indentation 2021-07-23 05:42:04 -05:00
Yaazkal
116014d191 Refactor: creates check_linux_prerequisites function 2021-07-23 05:33:49 -05:00
yaazkal
261fdd7dc9 Fix minor typo in README 2021-07-23 05:05:20 -05:00
JRGTH
c90fea3066 Extra validation on Linux Jails, revert cp.sh to avoid issues with templates 2021-07-15 16:30:36 -04:00
JRGTH
494d811c32 Use statement here 2021-07-15 12:32:37 -04:00
JRGTH
d8f925b1c8 Merge remote-tracking branch 'upstream/master' 2021-07-15 12:26:28 -04:00
Christer Edwards
93bb9a5048 Merge pull request #422 from cynix/fix_linux_jail
Fix creation of Linux jails
2021-07-15 07:25:31 -06:00
cynix
387fe3cf91 Avoid mounting devfs twice 2021-07-15 23:01:13 +10:00
cynix
857414f410 Fix missing redirection 2021-07-15 21:26:35 +10:00
cynix
b294a45bb9 Fix fstab creation for Linux jails 2021-07-15 20:52:16 +10:00
JRGTH
2caf01b722 Cosmetics changes to prevent double "/" 2021-07-14 16:50:35 -04:00
Gerrit Sere
bc143f8fe2 Merge branch 'master' of https://github.com/BastilleBSD/bastille into cmdbug 2021-01-06 13:42:39 +01:00
Gerrit Sere
b2134145a2 bastille cmd exit code not respected #272 2021-01-05 00:30:06 +01:00
34 changed files with 515 additions and 190 deletions

9
.readthedocs.yaml Normal file
View File

@@ -0,0 +1,9 @@
version: 2
sphinx:
configuration: docs/conf.py
python:
version: 3.7
install:
- requirements: docs/requirements.txt

View File

@@ -22,6 +22,7 @@ Christer Edwards [christer.edwards@gmail.com]
- Petru T. Garstea
- Sven R.
- Tobias Tom
- Stefano Marinelli
### Special thanks
Software doesn't happen in a vacuum. Thank you to the following people who may

View File

@@ -296,7 +296,7 @@ patches.
The bootstrap process for Linux containers is very different from the BSD process.
You will need the package debootstrap and some kernel modules for that.
But don't worry, Bastille will do that for that for you.
But don't worry, Bastille will do that for you.
```shell
ishmael ~ # bastille bootstrap focal

5
Vagrantfile vendored
View File

@@ -9,8 +9,8 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
vm_config.ssh.shell = "sh"
vm_config.vm.box = "freebsd/FreeBSD-12.1-RELEASE"
vm_config.vm.box_version = "2019.11.01"
vm_config.vm.box = "freebsd/FreeBSD-13.0-RELEASE"
vm_config.vm.box_version = "2021.04.09"
vm_config.vm.provider "virtualbox" do |vb|
vb.name = "bastille"
@@ -19,6 +19,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
end
vm_config.vm.provision "shell", inline: "cd /vagrant; make install"
vm_config.vm.provision "shell", inline: "pkg install -y git-lite"
end
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

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`
repositories.
Current version is `0.9.20210714`.
Current version is `0.9.20211225`.
To install from the FreeBSD package repository:

View File

@@ -109,6 +109,18 @@ To define a default route / gateway for all VNET containers define the value in
This config change will apply the defined gateway to any new containers.
Existing containers will need to be manually updated.
Virtual Network (VNET) on External Bridge
--------------------------------------
To create a VNET based container and attach it to an external, already existing bridge, use the `-B` option, an IP/netmask and
external bridge.
.. code-block:: shell
bastille create -B azkaban 12.1-RELEASE 192.168.1.50/24 bridge0
Bastille will automagically create the interface, attach it to the specified bridge and connect /
disconnect containers as they are started and stopped.
The bridge needs to be created/enabled before creating and starting the jail.
Public Network
==============

View File

@@ -0,0 +1,28 @@
ZFS Support
====================
.. image:: /images/bastillebsd-twitter-poll.png
:width: 400
:alt: Alternative text
Bastille 0.4 added initial support for ZFS. ``bastille bootstrap`` and ``bastille create`` will generate ZFS volumes based on settings found in the ``bastille.conf``. This section outlines how to enable and configure Bastille for ZFS.
Two values are required for Bastille to use ZFS. The default values in the ``bastille.conf`` are empty. Populate these two to enable ZFS.
.. code-block:: shell
## ZFS options
bastille_zfs_enable="" ## default: ""
bastille_zfs_zpool="" ## default: ""
bastille_zfs_prefix="bastille" ## default: "${bastille_zfs_zpool}/bastille"
bastille_prefix="/bastille" ## default: "/usr/local/bastille". ${bastille_zfs_prefix} gets mounted here
bastille_zfs_options="-o compress=lz4 -o atime=off" ## default: "-o compress=lz4 -o atime=off"
Example
.. code-block:: shell
ishmael ~ # sysrc -f /usr/local/etc/bastille/bastille.conf bastille_zfs_enable=YES
ishmael ~ # sysrc -f /usr/local/etc/bastille/bastille.conf bastille_zfs_zpool=ZPOOL_NAME
Replace ``ZPOOL_NAME`` with the zpool you want Bastille to use. Tip: ``zpool list`` and ``zpool status`` will help.
If you get 'no pools available' you are likely not using ZFS and can safely ignore these settings.

View File

@@ -12,9 +12,9 @@ copyright = '2018-2021, Christer Edwards'
author = 'Christer Edwards'
# The short X.Y version
version = '0.9.20210714'
version = '0.9.20211225'
# The full version, including alpha/beta/rc tags
release = '0.8.20210714-beta'
release = '0.9.20211225-beta'
# -- General configuration ---------------------------------------------------

View File

@@ -18,6 +18,7 @@ https://docs.bastillebsd.org.
chapters/subcommands/index
chapters/template
chapters/jail-config
chapters/zfs-support
copyright

1
docs/requirements.txt Normal file
View File

@@ -0,0 +1 @@
docutils < 0.18

View File

@@ -70,7 +70,7 @@ bastille_perms_check() {
bastille_perms_check
## version
BASTILLE_VERSION="0.9.20210714"
BASTILLE_VERSION="0.9.20211225"
usage() {
cat << EOF
@@ -147,14 +147,24 @@ clone|config|cmd|console|convert|cp|edit|htop|limits|mount|pkg|rename|service|st
shift
if [ "${TARGET}" = 'ALL' ]; then
_JAILS=$(jls name)
_JAILS=$(/usr/sbin/jls name)
JAILS=""
for _jail in ${_JAILS}; do
_JAILPATH=$(jls -j "${_jail}" path)
_JAILPATH=$(/usr/sbin/jls -j "${_jail}" path)
if [ -z ${_JAILPATH##${bastille_jailsdir}*} ]; then
JAILS="${JAILS} ${_jail}"
fi
done
elif [ "${CMD}" = "pkg" ] && [ "${TARGET}" = '-H' ] || [ "${TARGET}" = '--host' ]; then
TARGET="${1}"
USE_HOST_PKG=1
JAILS="${TARGET}"
shift
# Require the target to be running
if [ ! "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
error_exit "[${TARGET}]: Not started. See 'bastille start ${TARGET}'."
fi
elif [ "${CMD}" = 'template' ] && [ "${TARGET}" = '--convert' ]; then
# This command does not act on a jail, so we are temporarily bypassing the presence/started
# checks. The command will simply convert a template from hooks to a Bastillefile. -- cwells
@@ -169,18 +179,19 @@ clone|config|cmd|console|convert|cp|edit|htop|limits|mount|pkg|rename|service|st
case "${CMD}" in
cmd|console|htop|pkg|service|stop|sysrc|template|top)
# Require the target to be running. -- cwells
if [ ! "$(jls name | awk "/^${TARGET}$/")" ]; then
if [ ! "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
error_exit "[${TARGET}]: Not started. See 'bastille start ${TARGET}'."
fi
;;
convert|rename)
# Require the target to be stopped. -- cwells
if [ "$(jls name | awk "/^${TARGET}$/")" ]; then
if [ "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
error_exit "${TARGET} is running. See 'bastille stop ${TARGET}'."
fi
;;
esac
fi
export USE_HOST_PKG
export TARGET
export JAILS
fi

View File

@@ -25,7 +25,7 @@ bastille_sharedir="/usr/local/share/bastille" ## default
bastille_bootstrap_archives="base" ## default: "base"
## default timezone
bastille_tzdata="Etc/UTC" ## default: "Etc/UTC"
bastille_tzdata="" ## default: empty to use host's time zone
## default jail resolv.conf
bastille_resolv_conf="/etc/resolv.conf" ## default: "/etc/resolv.conf"
@@ -51,6 +51,7 @@ bastille_decompress_gz_options="-k -d -c -v" ## default
bastille_network_loopback="bastille0" ## default: "bastille0"
bastille_network_shared="" ## default: ""
bastille_network_gateway="" ## default: ""
bastille_network_gateway6="" ## default: ""
## Default Templates
bastille_template_base="default/base" ## default: "default/base"

View File

@@ -3,7 +3,7 @@
# Bastille jail startup script
#
# PROVIDE: bastille
# REQUIRE: LOGIN
# REQUIRE: NETWORKING
# KEYWORD: shutdown
# Add the following to /etc/rc.conf[.local] to enable this service

View File

@@ -103,12 +103,11 @@ bootstrap_directories() {
if [ "${bastille_zfs_enable}" = "YES" ];then
if [ -n "${bastille_zfs_zpool}" ]; then
zfs create ${bastille_zfs_options} -o mountpoint="${bastille_prefix}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}"
chmod 0750 "${bastille_prefix}"
fi
else
mkdir -p "${bastille_prefix}"
chmod 0750 "${bastille_prefix}"
fi
chmod 0750 "${bastille_prefix}"
fi
## ${bastille_backupsdir}
@@ -116,12 +115,11 @@ bootstrap_directories() {
if [ "${bastille_zfs_enable}" = "YES" ];then
if [ -n "${bastille_zfs_zpool}" ]; then
zfs create ${bastille_zfs_options} -o mountpoint="${bastille_backupsdir}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/backups"
chmod 0750 "${bastille_backupsdir}"
fi
else
mkdir -p "${bastille_backupsdir}"
chmod 0750 "${bastille_backupsdir}"
fi
chmod 0750 "${bastille_backupsdir}"
fi
## ${bastille_cachedir}
@@ -304,6 +302,106 @@ bootstrap_release() {
echo
}
debootstrap_release() {
#check and install OS dependencies @hackacad
#ToDo: add function 'linux_pre' for sysrc etc.
required_mods="fdescfs linprocfs linsysfs tmpfs"
linuxarc_mods="linux linux64"
for _req_kmod in ${required_mods}; do
if [ ! "$(sysrc -f /boot/loader.conf -qn ${_req_kmod}_load)" = "YES" ]; then
warn "${_req_kmod} not enabled in /boot/loader.conf, Should I do that for you? (N|y)"
read answer
case "${answer}" in
[Nn][Oo]|[Nn]|"")
error_exit "Exiting."
;;
[Yy][Ee][Ss]|[Yy])
# Skip already loaded known modules.
if ! kldstat -m ${_req_kmod} >/dev/null 2>&1; then
info "Loading kernel module: ${_req_kmod}"
kldload -v ${_req_kmod}
fi
info "Persisting module: ${_req_kmod}"
sysrc -f /boot/loader.conf ${_req_kmod}_load=YES
;;
esac
else
# If already set in /boot/loader.conf, check and try to load the module.
if ! kldstat -m ${_req_kmod} >/dev/null 2>&1; then
info "Loading kernel module: ${_req_kmod}"
kldload -v ${_req_kmod}
fi
fi
done
# Mandatory Linux modules/rc.
for _lin_kmod in ${linuxarc_mods}; do
if ! kldstat -n ${_lin_kmod} >/dev/null 2>&1; then
info "Loading kernel module: ${_lin_kmod}"
kldload -v ${_lin_kmod}
fi
done
if [ ! "$(sysrc -qn linux_enable)" = "YES" ]; then
sysrc linux_enable=YES
fi
if ! which -s debootstrap; then
warn "Debootstrap not found. Should it be installed? (N|y)"
read answer
case $answer in
[Nn][Oo]|[Nn]|"")
error_exit "Exiting. You need to install debootstap before boostrapping a Linux jail."
;;
[Yy][Ee][Ss]|[Yy])
pkg install -y debootstrap
;;
esac
fi
# Create subsequent Linux releases datasets
if [ ! -d "${bastille_releasesdir}/${DIR_BOOTSTRAP}" ]; then
if [ "${bastille_zfs_enable}" = "YES" ]; then
if [ -n "${bastille_zfs_zpool}" ]; then
zfs create ${bastille_zfs_options} -o mountpoint="${bastille_releasesdir}/${DIR_BOOTSTRAP}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${DIR_BOOTSTRAP}"
fi
else
mkdir -p "${bastille_releasesdir}/${DIR_BOOTSTRAP}"
fi
fi
# Fetch the Linux flavor
info "Bootstrapping ${PLATFORM_OS} distfiles..."
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
if [ "${bastille_zfs_enable}" = "YES" ]; then
if [ -n "${bastille_zfs_zpool}" ]; then
if [ ! "$(ls -A "${bastille_releasesdir}/${DIR_BOOTSTRAP}")" ]; then
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${DIR_BOOTSTRAP}"
fi
fi
fi
if [ -d "${bastille_releasesdir}/${DIR_BOOTSTRAP}" ]; then
if [ ! "$(ls -A "${bastille_releasesdir}/${DIR_BOOTSTRAP}")" ]; then
rm -rf "${bastille_releasesdir:?}/${DIR_BOOTSTRAP}"
fi
fi
error_exit "Bootstrap failed."
fi
case "${LINUX_FLAVOR}" in
bionic|stretch|buster|bullseye)
info "Increasing APT::Cache-Start"
echo "APT::Cache-Start 251658240;" > "${bastille_releasesdir}"/${DIR_BOOTSTRAP}/etc/apt/apt.conf.d/00aptitude
;;
esac
info "Bootstrap successful."
info "See 'bastille --help' for available commands."
echo
}
bootstrap_template() {
## ${bastille_templatesdir}
@@ -431,86 +529,45 @@ http?://*/*/*)
;;
#adding Ubuntu Bionic as valid "RELEASE" for POC @hackacad
ubuntu_bionic|bionic|ubuntu-bionic)
#check and install OS dependencies @hackacad
if [ ! "$(sysrc -f /boot/loader.conf -n linprocfs_load)" = "YES" ] && [ ! "$(sysrc -f /boot/loader.conf -n linsysfs_load)" = "YES" ] && [ ! "$(sysrc -f /boot/loader.conf -n tmpfs_load)" = "YES" ]; then
warn "linprocfs_load, linsysfs_load, tmpfs_load not enabled in /boot/loader.conf or linux_enable not active. Should I do that for you? (N|y)"
read answer
case $answer in
[Nn][Oo]|[Nn]|"")
error_exit "Exiting."
;;
[Yy][Ee][Ss]|[Yy])
info "Loading modules"
kldload linux linux64 linprocfs linsysfs tmpfs
info "Persisting modules"
sysrc linux_enable=YES
sysrc -f /boot/loader.conf linprocfs_load=YES
sysrc -f /boot/loader.conf linsysfs_load=YES
sysrc -f /boot/loader.conf tmpfs_load=YES
;;
esac
fi
if which -s debootstrap; then
debootstrap --foreign --arch=amd64 --no-check-gpg bionic "${bastille_releasesdir}"/Ubuntu_1804
else
warn "Debootstrap not found. Should it be installed? (N|y)"
read answer
case $answer in
[Nn][Oo]|[Nn]|"")
error_exit "Exiting. You need to install debootstap before boostrapping a Linux jail."
;;
[Yy][Ee][Ss]|[Yy])
pkg install -y debootstrap
debootstrap --foreign --arch=amd64 --no-check-gpg bionic "${bastille_releasesdir}"/Ubuntu_1804
;;
esac
fi
echo "APT::Cache-Start 251658240;" > "${bastille_releasesdir}"/Ubuntu_1804/etc/apt/apt.conf.d/00aptitude
PLATFORM_OS="Ubuntu/Linux"
LINUX_FLAVOR="bionic"
DIR_BOOTSTRAP="Ubuntu_1804"
ARCH_BOOTSTRAP="amd64"
debootstrap_release
;;
ubuntu_focal|focal|ubuntu-focal)
#check and install OS dependencies @hackacad
#ToDo: add function 'linux_pre' for sysrc etc.
if [ ! "$(sysrc -f /boot/loader.conf -n linprocfs_load)" = "YES" ] && [ ! "$(sysrc -f /boot/loader.conf -n linsysfs_load)" = "YES" ] && [ ! "$(sysrc -f /boot/loader.conf -n tmpfs_load)" = "YES" ]; then
warn "linprocfs_load, linsysfs_load, tmpfs_load not enabled in /boot/loader.conf or linux_enable not active. Should I do that for you? (N|y)"
read answer
case $answer in
[Nn][Oo]|[Nn]|"")
error_exit "Exiting."
;;
[Yy][Ee][Ss]|[Yy])
info "Loading modules"
kldload linux linux64 linprocfs linsysfs tmpfs
info "Persisting modules"
sysrc linux_enable=YES
sysrc -f /boot/loader.conf linprocfs_load=YES
sysrc -f /boot/loader.conf linsysfs_load=YES
sysrc -f /boot/loader.conf tmpfs_load=YES
;;
esac
fi
if which -s debootstrap; then
debootstrap --foreign --arch=amd64 --no-check-gpg focal "${bastille_releasesdir}"/Ubuntu_2004
else
warn "Debootstrap not found. Should it be installed? (N|y)"
read answer
case $answer in
[Nn][Oo]|[Nn]|"")
error_exit "Exiting. You need to install debootstap before boostrapping a Linux jail."
;;
[Yy][Ee][Ss]|[Yy])
pkg install -y debootstrap
debootstrap --foreign --arch=amd64 --no-check-gpg focal "${bastille_releasesdir}"/Ubuntu_2004
;;
esac
fi
PLATFORM_OS="Ubuntu/Linux"
LINUX_FLAVOR="focal"
DIR_BOOTSTRAP="Ubuntu_2004"
ARCH_BOOTSTRAP="amd64"
debootstrap_release
;;
debian_stretch|stretch|debian-stretch)
PLATFORM_OS="Debian/Linux"
LINUX_FLAVOR="stretch"
DIR_BOOTSTRAP="Debian9"
ARCH_BOOTSTRAP="amd64"
debootstrap_release
;;
debian_buster|buster|debian-buster)
PLATFORM_OS="Debian/Linux"
LINUX_FLAVOR="buster"
DIR_BOOTSTRAP="Debian10"
ARCH_BOOTSTRAP="amd64"
debootstrap_release
;;
debian_bullseye|bullseye|debian-bullseye)
PLATFORM_OS="Debian/Linux"
LINUX_FLAVOR="bullseye"
DIR_BOOTSTRAP="Debian11"
ARCH_BOOTSTRAP="amd64"
debootstrap_release
;;
*)
usage
;;
esac
case "${OPTION}" in
update)
bastille update "${RELEASE}"

View File

@@ -130,7 +130,7 @@ update_fstab() {
# Update fstab to use the new name
FSTAB_CONFIG="${bastille_jailsdir}/${NEWNAME}/fstab"
if [ -f "${FSTAB_CONFIG}" ]; then
FSTAB_RELEASE=$(grep -owE '([1-9]{2,2})\.[0-9](-RELEASE|-RELEASE-i386|-RC[1-2])|([0-9]{1,2}-stable-build-[0-9]{1,3})|(current-build)-([0-9]{1,3})|(current-BUILD-LATEST)|([0-9]{1,2}-stable-BUILD-LATEST)|(current-BUILD-LATEST)' "${FSTAB_CONFIG}")
FSTAB_RELEASE=$(grep -owE '([1-9]{2,2})\.[0-9](-RELEASE|-RELEASE-i386|-RC[1-2])|([0-9]{1,2}-stable-build-[0-9]{1,3})|(current-build)-([0-9]{1,3})|(current-BUILD-LATEST)|([0-9]{1,2}-stable-BUILD-LATEST)' "${FSTAB_CONFIG}" | uniq)
FSTAB_CURRENT=$(grep -w ".*/releases/.*/jails/${TARGET}/root/.bastille" "${FSTAB_CONFIG}")
FSTAB_NEWCONF="${bastille_releasesdir}/${FSTAB_RELEASE} ${bastille_jailsdir}/${NEWNAME}/root/.bastille nullfs ro 0 0"
if [ -n "${FSTAB_CURRENT}" ] && [ -n "${FSTAB_NEWCONF}" ]; then
@@ -164,7 +164,7 @@ clone_jail() {
else
# Just clone the jail directory
# Check if container is running
if [ -n "$(jls name | awk "/^${TARGET}$/")" ]; then
if [ -n "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
error_exit "${TARGET} is running. See 'bastille stop ${TARGET}'."
fi

View File

@@ -45,8 +45,28 @@ if [ $# -eq 0 ]; then
usage
fi
COUNT=0
RETURN=0
for _jail in ${JAILS}; do
COUNT=$(($COUNT+1))
info "[${_jail}]:"
jexec -l -U root "${_jail}" "$@"
ERROR_CODE=$?
info "[${_jail}]: ${ERROR_CODE}"
if [ "$COUNT" -eq 1 ]; then
RETURN=$ERROR_CODE
else
RETURN=$(($RETURN+$ERROR_CODE))
fi
echo
done
# Check when a command is executed in all running jails. (bastille cmd ALL ...)
if [ "$COUNT" -gt 1 ] && [ "$RETURN" -gt 0 ]; then
RETURN=1
fi
return "$RETURN"

View File

@@ -38,7 +38,7 @@ enable_color() {
}
# If "NO_COLOR" environment variable is present, disable output colors.
if ! export | grep -q "NO_COLOR"; then
if [ -z "${NO_COLOR}" ]; then
enable_color
fi

View File

@@ -43,13 +43,14 @@ usage() {
-L | --linux -- This option is intended for testing with Linux jails, this is considered experimental.
-T | --thick -- Creates a thick container, they consume more space as they are self contained and independent.
-V | --vnet -- Enables VNET, VNET containers are attached to a virtual bridge interface for connectivity.
-B | --bridge -- Enables VNET, VNET containers are attached to a specified, already existing external bridge.
EOF
exit 1
}
running_jail() {
if [ -n "$(jls name | awk "/^${NAME}$/")" ]; then
if [ -n "$(/usr/sbin/jls name | awk "/^${NAME}$/")" ]; then
error_exit "A running jail matches name."
elif [ -d "${bastille_jailsdir}/${NAME}" ]; then
error_exit "Jail: ${NAME} already created."
@@ -113,6 +114,13 @@ validate_netconf() {
}
validate_release() {
## ensure the user set the Linux(experimental) option explicitly
if [ -n "${UBUNTU}" ]; then
if [ -z "${LINUX_JAIL}" ]; then
usage
fi
fi
## check release name match, else show usage
if [ -n "${NAME_VERIFY}" ]; then
RELEASE="${NAME_VERIFY}"
@@ -166,8 +174,6 @@ ${NAME} {
exec.stop = '/bin/true';
persist;
mount.devfs;
allow.mount;
allow.mount.devfs;
@@ -187,15 +193,46 @@ generate_vnet_jail_conf() {
local list_jails_num=$(echo "${jail_list}" | wc -l | awk '{print $1}')
local num_range=$(expr "${list_jails_num}" + 1)
for _num in $(seq 0 "${num_range}"); do
if ! grep -q "e0b_bastille${_num}" "${bastille_jailsdir}"/*/jail.conf; then
if ! grep -q "e${_num}b" "${bastille_jailsdir}"/*/jail.conf; then
uniq_epair="bastille${_num}"
uniq_epair_bridge="${_num}"
break
fi
done
else
uniq_epair="bastille0"
uniq_epair_bridge="0"
fi
if [ -n "${VNET_JAIL_BRIDGE}" ]; then
## generate bridge config
cat << EOF > "${bastille_jail_conf}"
${NAME} {
devfs_ruleset = 13;
enforce_statfs = 2;
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;
exec.prestart += "ifconfig epair${uniq_epair_bridge} create";
exec.prestart += "ifconfig ${bastille_jail_conf_interface} addm epair${uniq_epair_bridge}a";
exec.prestart += "ifconfig epair${uniq_epair_bridge}a up name e${uniq_epair_bridge}a_${NAME}";
exec.prestart += "ifconfig epair${uniq_epair_bridge}b up name e${uniq_epair_bridge}b_${NAME}";
exec.poststop += "ifconfig ${bastille_jail_conf_interface} deletem e${uniq_epair_bridge}a_${NAME}";
exec.poststop += "ifconfig e${uniq_epair_bridge}a_${NAME} destroy";
vnet;
vnet.interface = "e${uniq_epair_bridge}b_${NAME}";
}
EOF
else
## generate config
cat << EOF > "${bastille_jail_conf}"
${NAME} {
@@ -214,9 +251,11 @@ ${NAME} {
vnet;
vnet.interface = e0b_${uniq_epair};
exec.prestart += "jib addm ${uniq_epair} ${bastille_jail_conf_interface}";
exec.prestart += "ifconfig e0a_${uniq_epair} description \"vnet host interface for Bastille jail ${NAME}\"";
exec.poststop += "jib destroy ${uniq_epair}";
}
EOF
fi
}
create_jail() {
@@ -255,7 +294,7 @@ create_jail() {
touch "${bastille_jail_path}/dev/shm"
touch "${bastille_jail_path}/dev/fd"
cp -RPf ${bastille_releasesdir}/${RELEASE}/* ${bastille_jail_path}/
echo ${NAME} ${bastille_jail_path}/etc/hostname
echo "${NAME}" > ${bastille_jail_path}/etc/hostname
if [ ! -d "${bastille_jail_template}" ]; then
mkdir -p "${bastille_jail_template}"
@@ -264,14 +303,14 @@ create_jail() {
if [ ! -f "${bastille_jail_fstab}" ]; then
touch "${bastille_jail_fstab}"
fi
echo -e "devfs ${bastille_jail_path}/dev devfs rw 0 0" > "${bastille_jail_fstab}"
echo -e "tmpfs ${bastille_jail_path}/dev/shm tmpfs rw,size=1g,mode=1777 0 0" > "${bastille_jail_fstab}"
echo -e "fdescfs ${bastille_jail_path}/dev/fd fdescfs rw,linrdlnk 0 0" > "${bastille_jail_fstab}"
echo -e "linprocfs ${bastille_jail_path}/proc linprocfs rw 0 0" > "${bastille_jail_fstab}"
echo -e "linsysfs ${bastille_jail_path}/sys linsysfs rw 0 0" > "${bastille_jail_fstab}"
echo -e "/tmp ${bastille_jail_path}/tmp nullfs rw 0 0" > "${bastille_jail_fstab}"
echo -e "devfs ${bastille_jail_path}/dev devfs rw 0 0" >> "${bastille_jail_fstab}"
echo -e "tmpfs ${bastille_jail_path}/dev/shm tmpfs rw,size=1g,mode=1777 0 0" >> "${bastille_jail_fstab}"
echo -e "fdescfs ${bastille_jail_path}/dev/fd fdescfs rw,linrdlnk 0 0" >> "${bastille_jail_fstab}"
echo -e "linprocfs ${bastille_jail_path}/proc linprocfs rw 0 0" >> "${bastille_jail_fstab}"
echo -e "linsysfs ${bastille_jail_path}/sys linsysfs rw 0 0" >> "${bastille_jail_fstab}"
echo -e "/tmp ${bastille_jail_path}/tmp nullfs rw 0 0" >> "${bastille_jail_fstab}"
## removed temporarely / only for X11 jails? @hackacad
#echo -e "/home ${bastille_jail_path}/home nullfs rw 0 0" > "${bastille_jail_fstab}"
#echo -e "/home ${bastille_jail_path}/home nullfs rw 0 0" >> "${bastille_jail_fstab}"
if [ ! -f "${bastille_jail_conf}" ]; then
if [ -z "${bastille_network_loopback}" ] && [ -n "${bastille_network_shared}" ]; then
@@ -408,8 +447,16 @@ create_jail() {
ln -s usr/home home
fi
## TZ: configurable (default: Etc/UTC)
ln -s "/usr/share/zoneinfo/${bastille_tzdata}" etc/localtime
## TZ: configurable (default: empty to use host's time zone)
if [ -z "${bastille_tzdata}" ]; then
# Note that if host has no time zone, FreeBSD assumes UTC anyway
if [ -e /etc/localtime ]; then
# uses cp as a way to prevent issues with symlinks if the host happens to use that for tz configuration
cp /etc/localtime etc/localtime
fi
else
ln -s "/usr/share/zoneinfo/${bastille_tzdata}" etc/localtime
fi
# Post-creation jail misc configuration
# Create a dummy fstab file
@@ -454,6 +501,7 @@ create_jail() {
uniq_epair=$(grep vnet.interface "${bastille_jailsdir}/${NAME}/jail.conf" | awk '{print $3}' | sed 's/;//')
_gateway=''
_gateway6=''
_ifconfig=SYNCDHCP
if [ "${IP}" != "0.0.0.0" ]; then # not using DHCP, so set static address.
if [ -n "${ip6}" ]; then
@@ -463,6 +511,8 @@ create_jail() {
fi
if [ -n "${bastille_network_gateway}" ]; then
_gateway="${bastille_network_gateway}"
elif [ -n "${bastille_network_gateway6}" ]; then
_gateway6="${bastille_network_gateway6}"
else
if [ -z ${ip6} ]; then
_gateway="$(netstat -4rn | awk '/default/ {print $2}')"
@@ -471,7 +521,7 @@ create_jail() {
fi
fi
fi
bastille template "${NAME}" ${bastille_template_vnet} --arg BASE_TEMPLATE="${bastille_template_base}" --arg HOST_RESOLV_CONF="${bastille_resolv_conf}" --arg EPAIR="${uniq_epair}" --arg GATEWAY="${_gateway}" --arg IFCONFIG="${_ifconfig}"
bastille template "${NAME}" ${bastille_template_vnet} --arg BASE_TEMPLATE="${bastille_template_base}" --arg HOST_RESOLV_CONF="${bastille_resolv_conf}" --arg EPAIR="${uniq_epair}" --arg GATEWAY="${_gateway}" --arg GATEWAY6="${_gateway6}" --arg IFCONFIG="${_ifconfig}"
fi
elif [ -n "${THICK_JAIL}" ]; then
if [ -n "${bastille_template_thick}" ]; then
@@ -544,6 +594,11 @@ while [ $# -gt 0 ]; do
VNET_JAIL="1"
shift
;;
-B|--bridge|bridge)
VNET_JAIL="1"
VNET_JAIL_BRIDGE="1"
shift
;;
-*|--*)
error_notify "Unknown Option."
usage
@@ -595,6 +650,18 @@ if [ -n "${LINUX_JAIL}" ]; then
## check for FreeBSD releases name
NAME_VERIFY=ubuntu_focal
;;
debian_stretch|stretch|debian-stretch)
## check for FreeBSD releases name
NAME_VERIFY=stretch
;;
debian_buster|buster|debian-buster)
## check for FreeBSD releases name
NAME_VERIFY=buster
;;
debian_bullseye|bullseye|debian-bullseye)
## check for FreeBSD releases name
NAME_VERIFY=bullseye
;;
*)
error_notify "Unknown Linux."
usage
@@ -646,13 +713,27 @@ if [ -z "${EMPTY_JAIL}" ]; then
validate_release
;;
ubuntu_bionic|bionic|ubuntu-bionic)
UBUNTU="1"
NAME_VERIFY=Ubuntu_1804
validate_release
;;
ubuntu_focal|focal|ubuntu-focal)
UBUNTU="1"
NAME_VERIFY=Ubuntu_2004
validate_release
;;
debian_stretch|stretch|debian-stretch)
NAME_VERIFY=Debian9
validate_release
;;
debian_buster|buster|debian-buster)
NAME_VERIFY=Debian10
validate_release
;;
debian_bullseye|bullseye|debian-bullseye)
NAME_VERIFY=Debian11
validate_release
;;
*)
error_notify "Unknown Release."
usage

View File

@@ -40,7 +40,7 @@ destroy_jail() {
bastille_jail_base="${bastille_jailsdir}/${TARGET}" ## dir
bastille_jail_log="${bastille_logsdir}/${TARGET}_console.log" ## file
if [ "$(jls name | awk "/^${TARGET}$/")" ]; then
if [ "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
if [ "${FORCE}" = "1" ]; then
bastille stop "${TARGET}"
else
@@ -207,27 +207,37 @@ case "${TARGET}" in
;;
*-stable-LAST|*-STABLE-last|*-stable-last|*-STABLE-LAST)
## check for HardenedBSD releases name
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '^([1-9]{2,2})(-stable-last)$' | sed 's/STABLE/stable/g' | sed 's/last/LAST/g')
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '^([1-9]{2,2})(-stable-last)$' | sed 's/STABLE/stable/g;s/last/LAST/g')
destroy_rel
;;
*-stable-build-[0-9]*|*-STABLE-BUILD-[0-9]*)
## check for HardenedBSD(specific stable build releases)
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '([0-9]{1,2})(-stable-build)-([0-9]{1,3})$' | sed 's/BUILD/build/g' | sed 's/STABLE/stable/g')
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '([0-9]{1,2})(-stable-build)-([0-9]{1,3})$' | sed 's/BUILD/build/g;s/STABLE/stable/g')
destroy_rel
;;
*-stable-build-latest|*-stable-BUILD-LATEST|*-STABLE-BUILD-LATEST)
## check for HardenedBSD(latest stable build release)
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '([0-9]{1,2})(-stable-build-latest)$' | sed 's/STABLE/stable/g' | sed 's/build/BUILD/g' | sed 's/latest/LATEST/g')
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '([0-9]{1,2})(-stable-build-latest)$' | sed 's/STABLE/stable/;s/build/BUILD/g;s/latest/LATEST/g')
destroy_rel
;;
current-build-[0-9]*|CURRENT-BUILD-[0-9]*)
## check for HardenedBSD(specific current build releases)
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '(current-build)-([0-9]{1,3})' | sed 's/BUILD/build/g' | sed 's/CURRENT/current/g')
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '(current-build)-([0-9]{1,3})' | sed 's/BUILD/build/g;s/CURRENT/current/g')
destroy_rel
;;
current-build-latest|current-BUILD-LATEST|CURRENT-BUILD-LATEST)
## check for HardenedBSD(latest current build release)
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '(current-build-latest)$' | sed 's/CURRENT/current/g' | sed 's/build/BUILD/g' | sed 's/latest/LATEST/g')
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '(current-build-latest)$' | sed 's/CURRENT/current/;s/build/BUILD/g;s/latest/LATEST/g')
destroy_rel
;;
Ubuntu_1804|Ubuntu_2004|UBUNTU_1804|UBUNTU_2004)
## check for Linux releases
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '(Ubuntu_1804)$|(Ubuntu_2004)$' | sed 's/UBUNTU/Ubuntu/g;s/ubuntu/Ubuntu/g')
destroy_rel
;;
Debian9|Debian10|Debian11|DEBIAN9|DEBIAN10|DEBIAN11)
## check for Linux releases
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '(Debian9)$|(Debian10)$|(Debian11)$' | sed 's/DEBIAN/Debian/g')
destroy_rel
;;
*)

View File

@@ -172,7 +172,7 @@ fi
if [ -n "${SAFE_EXPORT}" ]; then
# Check if container is running, otherwise just ignore
if [ -z "$(jls name | awk "/^${TARGET}$/")" ]; then
if [ -z "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
SAFE_EXPORT=
fi
fi
@@ -212,7 +212,7 @@ clean_zfs_snap() {
export_check() {
# Inform the user about the exporting method
if [ -z "${USER_EXPORT}" ]; then
if [ -n "$(jls name | awk "/^${TARGET}$/")" ]; then
if [ -n "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
if [ -n "${SAFE_EXPORT}" ]; then
EXPORT_AS="Safely exporting"
else
@@ -336,7 +336,7 @@ if [ -n "${TARGET}" ]; then
# Check if is a ZFS system
if [ "${bastille_zfs_enable}" != "YES" ]; then
# Check if container is running and ask for stop in non ZFS systems
if [ -n "$(jls name | awk "/^${TARGET}$/")" ]; then
if [ -n "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
error_exit "${TARGET} is running. See 'bastille stop'."
fi
fi

View File

@@ -47,7 +47,7 @@ if [ $# -ne 0 ]; then
fi
for _jail in ${JAILS}; do
bastille_jail_path=$(jls -j "${_jail}" path)
bastille_jail_path=$(/usr/sbin/jls -j "${_jail}" path)
if [ ! -x "${bastille_jail_path}/usr/local/bin/htop" ]; then
error_notify "htop not found on ${_jail}."
elif [ -x "${bastille_jail_path}/usr/local/bin/htop" ]; then

View File

@@ -173,6 +173,7 @@ generate_config() {
# Attempt to read previous config file and set required variables accordingly
# If we can't get a valid interface, fallback to lo1 and warn user
info "Generating jail.conf..."
DEVFS_RULESET=4
if [ "${FILE_EXT}" = ".zip" ]; then
# Gather some bits from foreign/iocage config files
@@ -180,6 +181,8 @@ generate_config() {
if [ -n "${JSON_CONFIG}" ]; then
IPV4_CONFIG=$(grep -wo '\"ip4_addr\": \".*\"' "${JSON_CONFIG}" | tr -d '" ' | sed 's/ip4_addr://')
IPV6_CONFIG=$(grep -wo '\"ip6_addr\": \".*\"' "${JSON_CONFIG}" | tr -d '" ' | sed 's/ip6_addr://')
DEVFS_RULESET=$(grep -wo '\"devfs_ruleset\": \".*\"' "${JSON_CONFIG}" | tr -d '" ' | sed 's/devfs_ruleset://')
DEVFS_RULESET=${DEVFS_RULESET:-4}
fi
elif [ "${FILE_EXT}" = ".tar.gz" ]; then
# Gather some bits from foreign/ezjail config files
@@ -257,7 +260,7 @@ generate_config() {
# Generate a basic jail configuration file on foreign imports
cat << EOF > "${bastille_jailsdir}/${TARGET_TRIM}/jail.conf"
${TARGET_TRIM} {
devfs_ruleset = 4;
devfs_ruleset = ${DEVFS_RULESET};
enforce_statfs = 2;
exec.clean;
exec.consolelog = ${bastille_logsdir}/${TARGET_TRIM}_console.log;
@@ -577,7 +580,7 @@ else
fi
# Check if a running jail matches name or already exist
if [ -n "$(jls name | awk "/^${TARGET_TRIM}$/")" ]; then
if [ -n "$(/usr/sbin/jls name | awk "/^${TARGET_TRIM}$/")" ]; then
error_exit "A running jail matches name."
elif [ -n "${TARGET_TRIM}" ]; then
if [ -d "${bastille_jailsdir}/${TARGET_TRIM}" ]; then

View File

@@ -36,11 +36,11 @@ usage() {
}
if [ $# -eq 0 ]; then
jls -N
/usr/sbin/jls -N
fi
if [ "$1" == "-j" ]; then
jls -N --libxo json
/usr/sbin/jls -N --libxo json
exit 0
fi
@@ -80,18 +80,18 @@ if [ $# -gt 0 ]; then
JAIL_LIST=$(ls "${bastille_jailsdir}" | sed "s/\n//g")
for _JAIL in ${JAIL_LIST}; do
if [ -f "${bastille_jailsdir}/${_JAIL}/jail.conf" ]; then
if [ "$(jls name | awk "/^${_JAIL}$/")" ]; then
if [ "$(/usr/sbin/jls name | awk "/^${_JAIL}$/")" ]; then
JAIL_STATE="Up"
if [ "$(awk '$1 == "vnet;" { print $1 }' "${bastille_jailsdir}/${_JAIL}/jail.conf")" ]; then
JAIL_IP=$(jexec -l ${_JAIL} ifconfig -n vnet0 inet 2> /dev/null | sed -n "/.inet /{s///;s/ .*//;p;}")
if [ ! ${JAIL_IP} ]; then JAIL_IP=$(jexec -l ${_JAIL} ifconfig -n vnet0 inet6 2> /dev/null | awk '/inet6 / && (!/fe80::/ || !/%vnet0/)' | sed -n "/.inet6 /{s///;s/ .*//;p;}"); fi
else
JAIL_IP=$(jls -j ${_JAIL} ip4.addr 2> /dev/null)
if [ ${JAIL_IP} = "-" ]; then JAIL_IP=$(jls -j ${_JAIL} ip6.addr 2> /dev/null); fi
JAIL_IP=$(/usr/sbin/jls -j ${_JAIL} ip4.addr 2> /dev/null)
if [ ${JAIL_IP} = "-" ]; then JAIL_IP=$(/usr/sbin/jls -j ${_JAIL} ip6.addr 2> /dev/null); fi
fi
JAIL_HOSTNAME=$(jls -j ${_JAIL} host.hostname 2> /dev/null)
JAIL_HOSTNAME=$(/usr/sbin/jls -j ${_JAIL} host.hostname 2> /dev/null)
JAIL_PORTS=$(pfctl -a "rdr/${_JAIL}" -Psn 2> /dev/null | awk '{ printf "%s/%s:%s"",",$7,$14,$18 }' | sed "s/,$//")
JAIL_PATH=$(jls -j ${_JAIL} path 2> /dev/null)
JAIL_PATH=$(/usr/sbin/jls -j ${_JAIL} path 2> /dev/null)
JAIL_RELEASE=$(jexec -l ${_JAIL} freebsd-version -u 2> /dev/null)
else
JAIL_STATE=$(if [ "$(sed -n "/^${_JAIL} {$/,/^}$/p" "${bastille_jailsdir}/${_JAIL}/jail.conf" | awk '$0 ~ /^'${_JAIL}' \{|\}/ { printf "%s",$0 }')" == "${_JAIL} {}" ]; then echo "Down"; else echo "n/a"; fi)
@@ -132,7 +132,7 @@ if [ $# -gt 0 ]; then
if [ -d "${bastille_releasesdir}" ]; then
REL_LIST=$(ls "${bastille_releasesdir}" | sed "s/\n//g")
for _REL in ${REL_LIST}; do
if [ -f "${bastille_releasesdir}/${_REL}/root/.profile" ]; then
if [ -f "${bastille_releasesdir}/${_REL}/root/.profile" -o -d "${bastille_releasesdir}/${_REL}/debootstrap" ]; then
echo "${_REL}"
fi
done

View File

@@ -93,25 +93,25 @@ for _jail in ${JAILS}; do
info "[${_jail}]:"
## aggregate variables into FSTAB entry
_jailpath="${bastille_jailsdir}/${_jail}/root/${_jailpath}"
_fstab_entry="${_hostpath} ${_jailpath} ${_type} ${_perms} ${_checks}"
_fullpath="${bastille_jailsdir}/${_jail}/root/${_jailpath}"
_fstab_entry="${_hostpath} ${_fullpath} ${_type} ${_perms} ${_checks}"
## Create mount point if it does not exist. -- cwells
if [ ! -d "${_jailpath}" ]; then
if ! mkdir -p "${_jailpath}"; then
if [ ! -d "${_fullpath}" ]; then
if ! mkdir -p "${_fullpath}"; then
error_exit "Failed to create mount point inside jail."
fi
fi
## if entry doesn't exist, add; else show existing entry
if ! egrep -q "[[:blank:]]${_jailpath}[[:blank:]]" "${bastille_jailsdir}/${_jail}/fstab" 2> /dev/null; then
if ! egrep -q "[[:blank:]]${_fullpath}[[:blank:]]" "${bastille_jailsdir}/${_jail}/fstab" 2> /dev/null; then
if ! echo "${_fstab_entry}" >> "${bastille_jailsdir}/${_jail}/fstab"; then
error_exit "Failed to create fstab entry: ${_fstab_entry}"
fi
echo "Added: ${_fstab_entry}"
else
warn "Mountpoint already present in ${bastille_jailsdir}/${_jail}/fstab"
egrep "[[:blank:]]${_jailpath}[[:blank:]]" "${bastille_jailsdir}/${_jail}/fstab"
egrep "[[:blank:]]${_fullpath}[[:blank:]]" "${bastille_jailsdir}/${_jail}/fstab"
fi
mount -F "${bastille_jailsdir}/${_jail}/fstab" -a
echo

View File

@@ -31,7 +31,7 @@
. /usr/local/share/bastille/common.sh
usage() {
error_exit "Usage: bastille pkg TARGET command [args]"
error_exit "Usage: bastille pkg [-H|--host] TARGET command [args]"
}
# Handle special-case commands first.
@@ -47,10 +47,15 @@ fi
for _jail in ${JAILS}; do
info "[${_jail}]:"
if [ -f "/usr/sbin/pkg" ]; then
jexec -l "${_jail}" /usr/sbin/pkg "$@"
bastille_jail_path=$(/usr/sbin/jls -j "${_jail}" path)
if [ -f "/usr/sbin/mport" ]; then
jexec -l -U root "${_jail}" /usr/sbin/mport "$@"
elif [ -f "${bastille_jail_path}/usr/bin/apt" ]; then
jexec -l "${_jail}" /usr/bin/apt "$@"
elif [ "${USE_HOST_PKG}" = 1 ]; then
/usr/sbin/pkg -j "${_jail}" "$@"
else
jexec -l "${_jail}" /usr/sbin/mport "$@"
jexec -l -U root "${_jail}" /usr/sbin/pkg "$@"
fi
echo
done

View File

@@ -47,37 +47,42 @@ if [ $# -lt 2 ]; then
fi
TARGET="${1}"
JAIL_NAME=""
JAIL_IP=""
EXT_IF=""
shift
# Can only redirect to single jail
if [ "${TARGET}" = 'ALL' ]; then
error_exit "Can only redirect to a single jail."
fi
# Check if jail name is valid
JAIL_NAME=$(jls -j "${TARGET}" name 2>/dev/null)
if [ -z "${JAIL_NAME}" ]; then
error_exit "Jail not found: ${TARGET}"
fi
# Check if jail ip4 address (ip4.addr) is valid (non-VNET only)
if [ "$(bastille config $TARGET get vnet)" != 'enabled' ]; then
JAIL_IP=$(jls -j "${TARGET}" ip4.addr 2>/dev/null)
if [ -z "${JAIL_IP}" -o "${JAIL_IP}" = "-" ]; then
error_exit "Jail IP not found: ${TARGET}"
check_jail_validity() {
# Can only redirect to single jail
if [ "${TARGET}" = 'ALL' ]; then
error_exit "Can only redirect to a single jail."
fi
fi
# Check if rdr-anchor is defined in pf.conf
if ! (pfctl -sn | grep rdr-anchor | grep 'rdr/\*' >/dev/null); then
error_exit "rdr-anchor not found in pf.conf"
fi
# Check if jail name is valid
JAIL_NAME=$(/usr/sbin/jls -j "${TARGET}" name 2>/dev/null)
if [ -z "${JAIL_NAME}" ]; then
error_exit "Jail not found: ${TARGET}"
fi
# Check if ext_if is defined in pf.conf
EXT_IF=$(grep '^[[:space:]]*ext_if[[:space:]]*=' /etc/pf.conf)
if [ -z "${EXT_IF}" ]; then
error_exit "ext_if not defined in pf.conf"
fi
# Check if jail ip4 address (ip4.addr) is valid (non-VNET only)
if [ "$(bastille config $TARGET get vnet)" != 'enabled' ]; then
JAIL_IP=$(/usr/sbin/jls -j "${TARGET}" ip4.addr 2>/dev/null)
if [ -z "${JAIL_IP}" -o "${JAIL_IP}" = "-" ]; then
error_exit "Jail IP not found: ${TARGET}"
fi
fi
# Check if rdr-anchor is defined in pf.conf
if ! (pfctl -sn | grep rdr-anchor | grep 'rdr/\*' >/dev/null); then
error_exit "rdr-anchor not found in pf.conf"
fi
# Check if ext_if is defined in pf.conf
EXT_IF=$(grep '^[[:space:]]*ext_if[[:space:]]*=' /etc/pf.conf)
if [ -z "${EXT_IF}" ]; then
error_exit "ext_if not defined in pf.conf"
fi
}
# function: write rule to rdr.conf
persist_rdr_rule() {
@@ -96,17 +101,34 @@ load_rdr_rule() {
while [ $# -gt 0 ]; do
case "$1" in
list)
pfctl -a "rdr/${JAIL_NAME}" -Psn 2>/dev/null
if [ "${TARGET}" = 'ALL' ]; then
for JAIL_NAME in $(ls "${bastille_jailsdir}" | sed "s/\n//g"); do
echo "${JAIL_NAME} redirects:"
pfctl -a "rdr/${JAIL_NAME}" -Psn 2>/dev/null
done
else
check_jail_validity
pfctl -a "rdr/${JAIL_NAME}" -Psn 2>/dev/null
fi
shift
;;
clear)
pfctl -a "rdr/${JAIL_NAME}" -Fn
if [ "${TARGET}" = 'ALL' ]; then
for JAIL_NAME in $(ls "${bastille_jailsdir}" | sed "s/\n//g"); do
echo "${JAIL_NAME} redirects:"
pfctl -a "rdr/${JAIL_NAME}" -Fn
done
else
check_jail_validity
pfctl -a "rdr/${JAIL_NAME}" -Fn
fi
shift
;;
tcp|udp)
if [ $# -lt 3 ]; then
usage
fi
check_jail_validity
persist_rdr_rule $1 $2 $3
load_rdr_rule $1 $2 $3
shift 3

View File

@@ -62,11 +62,11 @@ fi
for _jail in ${JAILS}; do
## test if running
if [ "$(jls name | awk "/^${_jail}$/")" ]; then
if [ "$(/usr/sbin/jls name | awk "/^${_jail}$/")" ]; then
error_notify "[${_jail}]: Already started."
## test if not running
elif [ ! "$(jls name | awk "/^${_jail}$/")" ]; then
elif [ ! "$(/usr/sbin/jls name | awk "/^${_jail}$/")" ]; then
# Verify that the configured interface exists. -- cwells
if [ "$(bastille config $_jail get vnet)" != 'enabled' ]; then
_interface=$(bastille config $_jail get interface)

View File

@@ -48,11 +48,11 @@ fi
for _jail in ${JAILS}; do
## test if running
if [ "$(jls name | awk "/^${_jail}$/")" ]; then
if [ "$(/usr/sbin/jls name | awk "/^${_jail}$/")" ]; then
## remove ip4.addr from firewall table:jails
if [ -n "${bastille_network_loopback}" ]; then
if grep -qw "interface.*=.*${bastille_network_loopback}" "${bastille_jailsdir}/${_jail}/jail.conf"; then
pfctl -q -t jails -T delete "$(jls -j ${_jail} ip4.addr)"
pfctl -q -t jails -T delete "$(/usr/sbin/jls -j ${_jail} ip4.addr)"
fi
fi

View File

@@ -186,7 +186,11 @@ case ${TEMPLATE} in
;;
*/*)
if [ ! -d "${bastille_templatesdir}/${TEMPLATE}" ]; then
error_exit "${TEMPLATE} not found."
if [ ! -d ${TEMPLATE} ]; then
error_exit "${TEMPLATE} not found."
else
bastille_template=${TEMPLATE}
fi
fi
;;
*)
@@ -222,9 +226,9 @@ for _jail in ${JAILS}; do
info "Applying template: ${TEMPLATE}..."
## jail-specific variables.
bastille_jail_path=$(jls -j "${_jail}" path)
bastille_jail_path=$(/usr/sbin/jls -j "${_jail}" path)
if [ "$(bastille config $TARGET get vnet)" != 'enabled' ]; then
_jail_ip=$(jls -j "${_jail}" ip4.addr 2>/dev/null)
_jail_ip=$(/usr/sbin/jls -j "${_jail}" ip4.addr 2>/dev/null)
if [ -z "${_jail_ip}" -o "${_jail_ip}" = "-" ]; then
error_notify "Jail IP not found: ${_jail}"
_jail_ip='' # In case it was -. -- cwells

View File

@@ -5,9 +5,11 @@ INCLUDE ${BASE_TEMPLATE} --arg HOST_RESOLV_CONF="${HOST_RESOLV_CONF}"
ARG EPAIR
ARG GATEWAY
ARG GATEWAY6
ARG IFCONFIG="SYNCDHCP"
SYSRC ifconfig_${EPAIR}_name=vnet0
SYSRC ifconfig_vnet0="${IFCONFIG}"
# GATEWAY will be empty for a DHCP config. -- cwells
CMD if [ -n "${GATEWAY}" ]; then /usr/sbin/sysrc defaultrouter="${GATEWAY}"; fi
CMD if [ -n "${GATEWAY6}" ]; then /usr/sbin/sysrc ipv6_defaultrouter="${GATEWAY6}"; fi

View File

@@ -32,7 +32,7 @@
. /usr/local/etc/bastille/bastille.conf
usage() {
error_exit "Usage: bastille update [release|container] | [force]"
error_exit "Usage: bastille update [release|container|template] | [force]"
}
# Handle special-case commands first.
@@ -75,7 +75,7 @@ fi
jail_check() {
# Check if the jail is thick and is running
if [ ! "$(jls name | awk "/^${TARGET}$/")" ]; then
if [ ! "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
error_exit "[${TARGET}]: Not started. See 'bastille start ${TARGET}'."
else
if grep -qw "${bastille_jailsdir}/${TARGET}/root/.bastille" "${bastille_jailsdir}/${TARGET}/fstab"; then
@@ -110,8 +110,48 @@ release_update() {
fi
}
template_update() {
# Update a template
_template_path=${bastille_templatesdir}/${BASTILLE_TEMPLATE}
if [ -d $_template_path ]; then
info "[${BASTILLE_TEMPLATE}]:"
git -C $_template_path pull ||\
error_notify "${BASTILLE_TEMPLATE} update unsuccessful."
bastille verify "${BASTILLE_TEMPLATE}"
else
error_exit "${BASTILLE_TEMPLATE} not found. See 'bastille bootstrap'."
fi
}
templates_update() {
# Update all templates
_updated_templates=0
if [ -d ${bastille_templatesdir} ]; then
for _template_path in $(ls -d ${bastille_templatesdir}/*/*); do
if [ -d $_template_path/.git ]; then
BASTILLE_TEMPLATE=$(echo "$_template_path" | awk -F / '{ print $(NF-1) "/" $NF }')
template_update
_updated_templates=$((_updated_templates+1))
fi
done
fi
if [ "$_updated_templates" -ne "0" ]; then
info "$_updated_templates templates updated."
else
error_exit "no templates found. See 'bastille bootstrap'."
fi
}
# Check what we should update
if echo "${TARGET}" | grep -q "[0-9]\{2\}.[0-9]-RELEASE"; then
if [ "${TARGET}" = 'TEMPLATES' ]; then
templates_update
elif echo "${TARGET}" | grep -Eq '^[A-Za-z0-9_-]+/[A-Za-z0-9_-]+$'; then
BASTILLE_TEMPLATE="${TARGET}"
template_update
elif echo "${TARGET}" | grep -q "[0-9]\{2\}.[0-9]-RELEASE"; then
release_update
else
jail_update

View File

@@ -76,7 +76,7 @@ esac
jail_check() {
# Check if the jail is thick and is running
if [ ! "$(jls name | awk "/^${TARGET}$/")" ]; then
if [ ! "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
error_exit "[${TARGET}]: Not started. See 'bastille start ${TARGET}'."
else
if grep -qw "${bastille_jailsdir}/${TARGET}/root/.bastille" "${bastille_jailsdir}/${TARGET}/fstab"; then

View File

@@ -51,6 +51,22 @@ verify_release() {
fi
}
handle_template_include() {
case ${TEMPLATE_INCLUDE} in
http?://*/*/*)
bastille bootstrap "${TEMPLATE_INCLUDE}"
;;
*/*)
BASTILLE_TEMPLATE_USER=$(echo "${TEMPLATE_INCLUDE}" | awk -F / '{ print $1 }')
BASTILLE_TEMPLATE_REPO=$(echo "${TEMPLATE_INCLUDE}" | awk -F / '{ print $2 }')
bastille verify "${BASTILLE_TEMPLATE_USER}/${BASTILLE_TEMPLATE_REPO}"
;;
*)
error_exit "Template INCLUDE content not recognized."
;;
esac
}
verify_template() {
_template_path=${bastille_templatesdir}/${BASTILLE_TEMPLATE}
_hook_validate=0
@@ -75,20 +91,8 @@ verify_template() {
echo
while read _include; do
info "[${_hook}]:[${_include}]:"
case ${_include} in
http?://*/*/*)
bastille bootstrap "${_include}"
;;
*/*)
BASTILLE_TEMPLATE_USER=$(echo "${_include}" | awk -F / '{ print $1 }')
BASTILLE_TEMPLATE_REPO=$(echo "${_include}" | awk -F / '{ print $2 }')
bastille verify "${BASTILLE_TEMPLATE_USER}/${BASTILLE_TEMPLATE_REPO}"
;;
*)
error_exit "Template INCLUDE content not recognized."
;;
esac
TEMPLATE_INCLUDE="${_include}"
handle_template_include
done < "${_path}"
## if tree; tree -a bastille_template/_dir
@@ -105,6 +109,18 @@ verify_template() {
fi
echo
done < "${_path}"
elif [ "${_hook}" = 'Bastillefile' ]; then
info "[${_hook}]:"
cat "${_path}"
while read _line; do
_cmd=$(echo "${_line}" | awk '{print tolower($1);}')
## if include; recursive verify
if [ "${_cmd}" = 'include' ]; then
TEMPLATE_INCLUDE=$(echo "${_line}" | awk '{print $2;}')
handle_template_include
fi
done < "${_path}"
echo
else
info "[${_hook}]:"
cat "${_path}"