Compare commits
156 Commits
0.9.202202
...
updatejail
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bf98acd330 | ||
|
|
01ee385384 | ||
|
|
22b3c3cd69 | ||
|
|
3ac2921559 | ||
|
|
0354baa6d5 | ||
|
|
445b42ed39 | ||
|
|
00d5c97f64 | ||
|
|
4ea6f00077 | ||
|
|
10fe9df412 | ||
|
|
440b24371b | ||
|
|
8b38497cb1 | ||
|
|
b0ba336d7e | ||
|
|
fe31dbdca8 | ||
|
|
4bebca9a69 | ||
|
|
864d8d03f5 | ||
|
|
ca2b75e8c0 | ||
|
|
b76df46cd1 | ||
|
|
2c932cf281 | ||
|
|
e7eb9b7717 | ||
|
|
27e88d45d5 | ||
|
|
721a5ca6a0 | ||
|
|
91f479e5d7 | ||
|
|
f35de69b28 | ||
|
|
e078aed54a | ||
|
|
848be8d8e3 | ||
|
|
a0d6d58a6b | ||
|
|
40e4b817d8 | ||
|
|
6be0f23256 | ||
|
|
3355c07dbf | ||
|
|
aa688f7072 | ||
|
|
9fc8804f97 | ||
|
|
d6b5733d48 | ||
|
|
72bd211f7b | ||
|
|
61e7084b33 | ||
|
|
3ea553086f | ||
|
|
2fd1f2c812 | ||
|
|
e15a481e46 | ||
|
|
15f2ea8574 | ||
|
|
4efcc5021c | ||
|
|
a2e1befa80 | ||
|
|
15c43ee214 | ||
|
|
a406654e18 | ||
|
|
7f41973f43 | ||
|
|
373ccd45d9 | ||
|
|
6e78be22f0 | ||
|
|
cf569eaeeb | ||
|
|
8d16399e50 | ||
|
|
bea80db898 | ||
|
|
a89f42242c | ||
|
|
16fae72518 | ||
|
|
4891ce69e7 | ||
|
|
e64a6af214 | ||
|
|
72b8000347 | ||
|
|
a0140e18bb | ||
|
|
bc9f4d7e90 | ||
|
|
0b7ed7850a | ||
|
|
e454f1c826 | ||
|
|
cb840684ab | ||
|
|
2e583cf9ab | ||
|
|
6ec7ae99f0 | ||
|
|
8f803d511e | ||
|
|
c760b817bd | ||
|
|
be50bd2359 | ||
|
|
228420049c | ||
|
|
d7609c2bc1 | ||
|
|
bf6fbed2b5 | ||
|
|
2e2032fee8 | ||
|
|
a9d8ae2cf1 | ||
|
|
f936afeae6 | ||
|
|
5aa98a8dae | ||
|
|
64c3b6045e | ||
|
|
6776427e5a | ||
|
|
10d94668fc | ||
|
|
91d1768740 | ||
|
|
c94f653e0b | ||
|
|
09a1d306dc | ||
|
|
b60bc10537 | ||
|
|
7b63059d03 | ||
|
|
34669ce2e6 | ||
|
|
5c94c283fb | ||
|
|
5c84731cd4 | ||
|
|
c016bc0667 | ||
|
|
3f665e4738 | ||
|
|
9588d52686 | ||
|
|
5adc75abed | ||
|
|
9a00ae5323 | ||
|
|
124902d6ba | ||
|
|
0629233f25 | ||
|
|
c00d8a4e05 | ||
|
|
bfce059225 | ||
|
|
ec7a6d8f6d | ||
|
|
0240d6532b | ||
|
|
ec18847f3e | ||
|
|
dd7f195c1e | ||
|
|
bdae170529 | ||
|
|
0ee17be875 | ||
|
|
778ef6e581 | ||
|
|
a73b9972e3 | ||
|
|
6a7ab04d9b | ||
|
|
937986f4b6 | ||
|
|
a4102c7f61 | ||
|
|
3702066864 | ||
|
|
79897e9af7 | ||
|
|
55c7c4c6be | ||
|
|
e5c71c794a | ||
|
|
e04aee2617 | ||
|
|
0dcefae18c | ||
|
|
37e607c055 | ||
|
|
f6f179b6c3 | ||
|
|
fdfbb8287f | ||
|
|
44cc3c0b91 | ||
|
|
2f35d07e58 | ||
|
|
d451573889 | ||
|
|
64fcda2533 | ||
|
|
ca3303fd4d | ||
|
|
f1d73a0c02 | ||
|
|
a0abac97ff | ||
|
|
6f739229cb | ||
|
|
427128b9f0 | ||
|
|
cf6e555ce9 | ||
|
|
c9d28ceed1 | ||
|
|
797f406a31 | ||
|
|
a352fd6507 | ||
|
|
a4ac5e961f | ||
|
|
c50e99b3e7 | ||
|
|
a0b7bc54e0 | ||
|
|
639334052f | ||
|
|
40c99ef979 | ||
|
|
260149c2a9 | ||
|
|
722adc44cb | ||
|
|
e35c59330d | ||
|
|
74b6eb76e7 | ||
|
|
da377f4735 | ||
|
|
f5b47d8f9e | ||
|
|
6de6e7bc6f | ||
|
|
533d108d91 | ||
|
|
a5bf6eca16 | ||
|
|
10468cd08f | ||
|
|
e8a72bcd75 | ||
|
|
b69eedc066 | ||
|
|
62d038049d | ||
|
|
3ba1024704 | ||
|
|
dbb720fef4 | ||
|
|
d0903347a6 | ||
|
|
b9d38a5d01 | ||
|
|
f14eddc958 | ||
|
|
e64c81d18a | ||
|
|
674a34d69c | ||
|
|
a97ac27a46 | ||
|
|
4302445eb5 | ||
|
|
d9f1dfdc2f | ||
|
|
ebb93c795e | ||
|
|
dbd4b5edc5 | ||
|
|
abc8a6b280 | ||
|
|
6e5a566d7f | ||
|
|
24eb03c2e6 |
@@ -4,6 +4,4 @@ sphinx:
|
||||
configuration: docs/conf.py
|
||||
|
||||
python:
|
||||
version: 3.7
|
||||
install:
|
||||
- requirements: docs/requirements.txt
|
||||
version: 3.11
|
||||
|
||||
@@ -23,6 +23,11 @@ Christer Edwards [christer.edwards@gmail.com]
|
||||
- Sven R.
|
||||
- Tobias Tom
|
||||
- Stefano Marinelli
|
||||
- Logan Ellis
|
||||
- Chuck Tuffli
|
||||
- Niketh Murali
|
||||
- Eric Borisch
|
||||
- Kevet Duncombe
|
||||
|
||||
### Special thanks
|
||||
Software doesn't happen in a vacuum. Thank you to the following people who may
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
||||
BSD 3-Clause License
|
||||
|
||||
Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
|
||||
8
Makefile
8
Makefile
@@ -1,3 +1,5 @@
|
||||
BASTILLE_VERSION=$$(git rev-parse HEAD)
|
||||
|
||||
.PHONY: all
|
||||
all:
|
||||
@echo "Nothing to be done. Please use make install or make uninstall"
|
||||
@@ -5,9 +7,13 @@ all:
|
||||
install:
|
||||
@echo "Installing Bastille"
|
||||
@echo
|
||||
@echo "Updating Bastille version to match git revision."
|
||||
@echo "BASTILLE_VERSION: ${BASTILLE_VERSION}"
|
||||
@sed -i.orig "s/BASTILLE_VERSION=.*/BASTILLE_VERSION=${BASTILLE_VERSION}/" usr/local/bin/bastille
|
||||
@cp -Rv usr /
|
||||
@echo
|
||||
@echo "This method is for testing / development."
|
||||
@echo "This method is for testing & development."
|
||||
@echo "Please report any issues to https://github.com/BastilleBSD/bastille/issues"
|
||||
|
||||
.PHONY: uninstall
|
||||
uninstall:
|
||||
|
||||
93
docs/chapters/gcp.rst
Normal file
93
docs/chapters/gcp.rst
Normal file
@@ -0,0 +1,93 @@
|
||||
Bastille VNET on GCP
|
||||
====================
|
||||
|
||||
Bastille VNET runs on GCP with a few small tweaks. In summary, they are:
|
||||
|
||||
- change MTU setting in jib script
|
||||
- add an IP address to the bridge interface
|
||||
- configure host pf to NAT and allow bridge traffic
|
||||
- set defaultrouter and nameserver in the host
|
||||
|
||||
## Change MTU in the jib script
|
||||
|
||||
GCP uses ``vtnet`` with MTU 1460, which [jib fails on](https://github.com/BastilleBSD/bastille/issues/538).
|
||||
|
||||
Apply the below patch to set the correct MTU. You may need to ``cp /usr/share/examples/jails/jib /usr/local/bin/`` first.
|
||||
|
||||
``patch /usr/local/bin/jib jib.patch``
|
||||
|
||||
.. code-block:: text
|
||||
--- /usr/local/bin/jib 2022-07-31 03:27:04.163245000 +0000
|
||||
+++ jib.fixed 2022-07-31 03:41:16.710401000 +0000
|
||||
@@ -299,14 +299,14 @@
|
||||
|
||||
# Make sure the interface has been bridged
|
||||
if ! ifconfig "$iface$bridge" > /dev/null 2>&1; then
|
||||
- new=$( ifconfig bridge create ) || return
|
||||
+ new=$( ifconfig bridge create mtu 1460 ) || return
|
||||
ifconfig $new addm $iface || return
|
||||
ifconfig $new name "$iface$bridge" || return
|
||||
ifconfig "$iface$bridge" up || return
|
||||
fi
|
||||
|
||||
# Create a new interface to the bridge
|
||||
- new=$( ifconfig epair create ) || return
|
||||
+ new=$( ifconfig epair create mtu 1460 ) || return
|
||||
ifconfig "$iface$bridge" addm $new || return
|
||||
|
||||
# Rename the new interface
|
||||
|
||||
## Configure bridge interface
|
||||
|
||||
Configure the bridge interface in /etc/rc.conf so it is available in the firewall rules.
|
||||
|
||||
.. code-block:: shell
|
||||
sysrc cloned_interfaces="bridge0"
|
||||
sysrc ifconfig_bridge0="inet 192.168.1.1/24 mtu 1460 addm vtnet0 name vtnet0bridge up"
|
||||
sysrc gateway_enable="yes"
|
||||
sysrc pf_enable="yes"
|
||||
|
||||
## Configure host pf
|
||||
|
||||
This basic /etc/pf.conf allow incoming packets on the bridge interface, and NATs them through the external interface:
|
||||
|
||||
.. code-block:: text
|
||||
ext_if="vtnet0"
|
||||
bridge_if="vtnet0bridge"
|
||||
|
||||
set skip on lo
|
||||
scrub in
|
||||
|
||||
# permissive NAT allows jail bridge and wireguard tunnels
|
||||
nat on $ext_if inet from !($ext_if) -> ($ext_if:0)
|
||||
|
||||
block in
|
||||
pass out
|
||||
|
||||
pass in proto tcp to port {22}
|
||||
pass in inet proto icmp icmp-type { echoreq }
|
||||
pass in on $bridge_if
|
||||
|
||||
Restart the host and make sure everything comes up correctly. You should see the following ifconfig:
|
||||
|
||||
.. code-block:: text
|
||||
vtnet0bridge: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1460
|
||||
ether 58:9c:fc:10:ff:90
|
||||
inet 192.168.1.1 netmask 0xffffff00 broadcast 192.168.1.255
|
||||
id 00:00:00:00:00:00 priority 32768 hellotime 2 fwddelay 15
|
||||
maxage 20 holdcnt 6 proto rstp maxaddr 2000 timeout 1200
|
||||
root id 00:00:00:00:00:00 priority 32768 ifcost 0 port 0
|
||||
member: vtnet0 flags=143<LEARNING,DISCOVER,AUTOEDGE,AUTOPTP>
|
||||
ifmaxaddr 0 port 1 priority 128 path cost 2000
|
||||
groups: bridge
|
||||
|
||||
## Configure router and resolver for new jails
|
||||
|
||||
Set the default network gateway for new jails as described in the Networking chapter, and configure a default resolver.
|
||||
|
||||
.. code-block:: shell
|
||||
sysrc -f /usr/local/etc/bastille/bastille.conf bastille_network_gateway="192.168.1.1"
|
||||
echo "nameserver 8.8.8.8" > /usr/local/etc/bastille/resolv.conf
|
||||
sysrc -f /usr/local/etc/bastille/bastille.conf bastille_resolv_conf="/usr/local/etc/bastille/resolv.conf"
|
||||
|
||||
You can now create a VNET jail with ``bastille create -V myjail 13.2-RELEASE 192.168.1.50/24 vtnet0``
|
||||
@@ -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.20220216`.
|
||||
Current version is `0.10.20231013`.
|
||||
|
||||
To install from the FreeBSD package repository:
|
||||
|
||||
@@ -18,6 +18,7 @@ PKG
|
||||
.. code-block:: shell
|
||||
|
||||
pkg install bastille
|
||||
sysrc bastille_enable=YES
|
||||
|
||||
|
||||
To install from source (don't worry, no compiling):
|
||||
@@ -28,6 +29,7 @@ ports
|
||||
.. code-block:: shell
|
||||
|
||||
make -C /usr/ports/sysutils/bastille install clean
|
||||
sysrc bastille_enable=YES
|
||||
|
||||
|
||||
GIT
|
||||
@@ -38,7 +40,13 @@ GIT
|
||||
git clone https://github.com/BastilleBSD/bastille.git
|
||||
cd bastille
|
||||
make install
|
||||
sysrc bastille_enable=YES
|
||||
|
||||
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
|
||||
has a `make uninstall` target.
|
||||
has a `make uninstall` target. You may need to manually copy the `.sample`
|
||||
config into place before Bastille will run. (ie;
|
||||
`/usr/local/etc/bastille/bastille.conf.sample`)
|
||||
|
||||
Note: installing using this method overwrites the version variable to match
|
||||
that of the source revision commit hash.
|
||||
|
||||
36
docs/chapters/migration.rst
Normal file
36
docs/chapters/migration.rst
Normal file
@@ -0,0 +1,36 @@
|
||||
Stop the running jail and export it:
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
iocage stop jailname
|
||||
iocage export jailname
|
||||
|
||||
Move the backup files (.zip and .sha256) into Bastille backup dir (default: /usr/local/bastille/backups/):
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
mv /iocage/images/jailname_$(date +%F).* /usr/local/bastille/backups/
|
||||
|
||||
for remote systems you could use rsync:
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
rsync -avh /iocage/images/jailname_$(date +%F).* root@10.0.1.10:/usr/local/bastille/backups/
|
||||
|
||||
|
||||
Import the iocage backup file (use zip file name)
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
bastille import jailname_$(date +%F).zip
|
||||
|
||||
Set your new ip address and interface:
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
vim /usr/local/bastille/jails/jailname/jail.conf
|
||||
interface = bastille0;
|
||||
ip4.addr = "192.168.0.1";
|
||||
|
||||
|
||||
You can use you primary network interface instead of the virtual bastille0 interface as well if you know what you’re doing.
|
||||
@@ -1,36 +1,44 @@
|
||||
Network Requirements
|
||||
====================
|
||||
Here's the scenario. You've installed Bastille at home or in the cloud and want
|
||||
to get started putting applications in secure little containers, but how do I
|
||||
get these containers on the network?
|
||||
to get started putting applications in secure little containers, but how do you
|
||||
get these containers on the network? Bastille tries to be flexible about how to
|
||||
network containerized applications. Four methods are described here.
|
||||
|
||||
Bastille tries to be flexible about how to network containerized applications.
|
||||
Three methods are described here. Consider each options when deciding
|
||||
which design work best for your needs. One of the methods works better in the
|
||||
cloud while the others are simpler if used in local area networks.
|
||||
1. Home or Small Office
|
||||
|
||||
**Note: if you are running in the cloud and only have a single public IP you
|
||||
may want the Public Network option. See below.**
|
||||
2. Cloud with IPV4 and multiple IPV6
|
||||
|
||||
3. Cloud with single IPV4 (internal bridge)
|
||||
|
||||
Local Area Network
|
||||
==================
|
||||
I will cover the local area network (LAN) method first. This method is simpler
|
||||
to get going and works well in a home network (or similar) where adding alias
|
||||
IP addresses is no problem.
|
||||
4. Cloud with a single IPV4 (external bridge)
|
||||
|
||||
Shared Interface (IP alias)
|
||||
---------------------------
|
||||
In FreeBSD network interfaces have different names, but look something like
|
||||
`em0`, `bge0`, `re0`, etc. On a virtual machine it may be `vtnet0`. You get the
|
||||
idea...
|
||||
Please choose the option which is most appropriate for your environment.
|
||||
|
||||
Bastille allows you to define the interface you want the IP attached to when
|
||||
you create it. An example:
|
||||
First a few notes. Bastille tries to verify that the interface name you provide
|
||||
is a valid interface. In FreeBSD network interfaces have different names, but
|
||||
look something like `em0`, `bge0`, `re0`, `vtnet0` etc. Running the ifconfig
|
||||
commend will tell you the name of your existing interfaces. Bastille also
|
||||
checks for a valid syntax IP4 or IP6 address. When you are testing calling out
|
||||
from your containers, please note that the ping command is disabled within the
|
||||
containers, because raw socket access are a security hole. Instead, install and
|
||||
test with `wget`/`curl`/`fetch` instead.
|
||||
|
||||
Shared Interface on Home or Small Office Network
|
||||
================================================
|
||||
If you have just one computer, or a home or small office network, where you are
|
||||
separated from the rest of the internet by a router. So you are free to use
|
||||
`private IP addresses
|
||||
<https://www.lifewire.com/what-is-a-private-ip-address-2625970>`_.
|
||||
|
||||
In this environment, to use Bastille, just create the container, give it a
|
||||
unique private ip address, and attach its ip address to your primary interface.
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
bastille create alcatraz 12.1-RELEASE 192.168.1.50 em0
|
||||
bastille create alcatraz 13.2-RELEASE 192.168.1.50 em0
|
||||
|
||||
You may have to change em0
|
||||
|
||||
When the `alcatraz` container is started it will add `192.168.1.50` as an IP
|
||||
alias to the `em0` interface. It will then simply be another member of the
|
||||
@@ -38,13 +46,57 @@ hosts network. Other networked systems (firewall permitting) should be able to
|
||||
reach services at that address.
|
||||
|
||||
This method is the simplest. All you need to know is the name of your network
|
||||
interface and a free IP on your current network.
|
||||
interface and a free IP on your local network.
|
||||
|
||||
Shared Interface on IPV6 network (vultr.com)
|
||||
============================================
|
||||
Some ISP's, such as `Vultr <https://vultr.com>`_, give you a single ipv4 address,
|
||||
and a large block of ipv6 addresses. You can then assign a unique ipv6 address
|
||||
to each Bastille Container.
|
||||
|
||||
On a virtual machine such as vultr.com the virtual interface may be `vtnet0`.
|
||||
So we issue the command:
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
bastille create alcatraz 13.2-RELEASE 2001:19f0:6c01:114c::100 vtnet0
|
||||
|
||||
We could also write the ipv6 address as 2001:19f0:6c01:114c:0:100
|
||||
|
||||
The tricky part are the ipv6 addresses. IPV6 is a string of 8 4 digit
|
||||
hexadecimal characters. At vultr they said:
|
||||
|
||||
Your server was assigned the following six section subnet:
|
||||
|
||||
2001:19f0:6c01:114c:: / 64
|
||||
|
||||
The `vultr ipv6 subnet calculator
|
||||
<https://www.vultr.com/resources/subnet-calculator-ipv6/?prefix_length=64&display=long&ipv6_address=2001%3Adb8%3Aacad%3Ae%3A%3A%2F64>`_
|
||||
is helpful in making sense of that ipv6 address.
|
||||
|
||||
We could have also written that IPV6 address as 2001:19f0:6c01:114c:0:0
|
||||
|
||||
Where the /64 basicaly means that the first 64 bits of the address (4x4
|
||||
character hexadecimal) values define the network, and the remaining characters,
|
||||
we can assign as we want to the Bastille Container. In the actual bastille
|
||||
create command given above, it was defined to be 100. But we also have to tell
|
||||
the host operating system that we are now using this address. This is done on
|
||||
freebsd with the following command
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
ifconfig_vtnet0_alias0="inet6 2001:19f0:6c01:114c::100 prefixlen 64"
|
||||
|
||||
At that point your container can talk to the world, and the world can ping your
|
||||
container. Of course when you reboot the machine, that command will be
|
||||
forgotten. To make it permanent, prefix the same command with `sysrc`
|
||||
|
||||
Just remember you cannot ping out from the container. Instead, install and
|
||||
use `wget`/`curl`/`fetch` to test the connectivity.
|
||||
|
||||
Bastille tries to verify that the interface name you provide it is a valid
|
||||
interface. It also checks for a valid syntax IP4 or IP6 address.
|
||||
|
||||
Virtual Network (VNET)
|
||||
----------------------
|
||||
======================
|
||||
(Added in 0.6.x) VNET is supported on FreeBSD 12+ only.
|
||||
|
||||
Virtual Network (VNET) creates a private network interface for a container.
|
||||
@@ -56,12 +108,12 @@ external interface.
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
bastille create -V azkaban 12.1-RELEASE 192.168.1.50/24 em0
|
||||
bastille create -V azkaban 13.2-RELEASE 192.168.1.50/24 em0
|
||||
|
||||
Bastille will automagically create the bridge interface and connect /
|
||||
disconnect containers as they are started and stopped. A new interface will be
|
||||
created on the host matching the pattern `interface0bridge`. In the example
|
||||
here, `em0bridge`.
|
||||
here, `em0bridge`.
|
||||
|
||||
The `em0` interface will be attached to the bridge along with the unique
|
||||
container interfaces as they are started and stopped. These interface names
|
||||
@@ -86,12 +138,31 @@ Lastly, you may want to consider these three `sysctl` values:
|
||||
net.link.bridge.pfil_onlyip=0
|
||||
net.link.bridge.pfil_member=0
|
||||
|
||||
Below is the definition of what these three parameters are used for and mean:
|
||||
|
||||
|
||||
net.link.bridge.pfil_onlyip Controls the handling of non-IP packets
|
||||
which are not passed to pfil(9). Set to 1
|
||||
to only allow IP packets to pass (subject
|
||||
to firewall rules), set to 0 to uncondi-
|
||||
tionally pass all non-IP Ethernet frames.
|
||||
|
||||
net.link.bridge.pfil_member Set to 1 to enable filtering on the incom-
|
||||
ing and outgoing member interfaces, set to
|
||||
0 to disable it.
|
||||
|
||||
net.link.bridge.pfil_bridge Set to 1 to enable filtering on the bridge
|
||||
interface, set to 0 to disable it.
|
||||
|
||||
|
||||
|
||||
|
||||
**Regarding Routes**
|
||||
|
||||
Bastille will attempt to auto-detect the default route from the host system and
|
||||
assign it to the VNET container. This auto-detection may not always be accurate
|
||||
for your needs for the particular container. In this case you'll need to add
|
||||
a default route manually or define the preferred default route in the
|
||||
for your needs for the particular container. In this case you'll need to add a
|
||||
default route manually or define the preferred default route in the
|
||||
`bastille.conf`.
|
||||
|
||||
.. code-block:: shell
|
||||
@@ -110,31 +181,32 @@ 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.
|
||||
=========================================
|
||||
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 create -B azkaban 13.2-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.
|
||||
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
|
||||
==============
|
||||
In this section I'll describe how to network containers in a public network
|
||||
such as a cloud hosting provider (AWS, digital ocean, vultr, etc)
|
||||
In this section we describe how to network containers in a public network
|
||||
such as a cloud hosting provider who only provides you with a single ip address.
|
||||
(AWS, Digital Ocean, etc) (The exception is vultr.com, which does
|
||||
provide you with lots of IPV6 addresses and does a great job supporting FreeBSD!)
|
||||
|
||||
In the public cloud you don't often have access to multiple private IP
|
||||
addresses for your virtual machines. This means if you want to create multiple
|
||||
containers and assign them all IP addresses, you'll need to create a new
|
||||
So if you only have a single IP address and if you want to create multiple
|
||||
containers and assign them all unique IP addresses, you'll need to create a new
|
||||
network.
|
||||
|
||||
loopback (bastille0)
|
||||
--------------------
|
||||
What I recommend is creating a cloned loopback interface (`bastille0`) and
|
||||
What we recommend is creating a cloned loopback interface (`bastille0`) and
|
||||
assigning all the containers private (rfc1918) addresses on that interface. The
|
||||
setup I develop on and use Bastille day-to-day uses the `10.0.0.0/8` address
|
||||
range. I have the ability to use whatever address I want within that range
|
||||
@@ -193,7 +265,7 @@ to containers are:
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
nat on $ext_if from <jails> to any -> ($ext_if)
|
||||
nat on $ext_if from <jails> to any -> ($ext_if:0)
|
||||
|
||||
The `nat` routes traffic from the loopback interface to the external
|
||||
interface for outbound access.
|
||||
@@ -207,16 +279,18 @@ The `rdr-anchor "rdr/*"` enables dynamic rdr rules to be setup using the
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
bastille rdr <jail> tcp 2001 22 # Redirects tcp port 2001 on host to 22 on jail
|
||||
bastille rdr <jail> udp 2053 53 # Same for udp
|
||||
bastille rdr <jail> list # List dynamic rdr rules
|
||||
bastille rdr <jail> clear # Clear dynamic rdr rules
|
||||
bastille rdr TARGET tcp 2001 22 # Redirects tcp port 2001 on host to 22 on jail
|
||||
bastille rdr TARGET udp 2053 53 # Same for udp
|
||||
bastille rdr TARGET list # List dynamic rdr rules
|
||||
bastille rdr TARGET clear # Clear dynamic rdr rules
|
||||
|
||||
Note that if you are redirecting ports where the host is also listening (eg.
|
||||
ssh) you should make sure that the host service is not listening on the cloned
|
||||
interface - eg. for ssh set sshd_flags in rc.conf
|
||||
|
||||
sshd_flags="-o ListenAddress=<hostname>"
|
||||
.. code-block:: shell
|
||||
|
||||
sshd_flags="-o ListenAddress=<host-address>"
|
||||
|
||||
Finally, start up the firewall:
|
||||
|
||||
|
||||
@@ -22,13 +22,21 @@ Releases
|
||||
Example
|
||||
-------
|
||||
|
||||
To `bootstrap` a release, run the bootstrap sub-command with the
|
||||
To `bootstrap` a FreeBSD release, run the bootstrap sub-command with the
|
||||
release version as the argument.
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
ishmael ~ # bastille bootstrap 11.4-RELEASE [update]
|
||||
ishmael ~ # bastille bootstrap 12.1-RELEASE
|
||||
ishmael ~ # bastille bootstrap 12.4-RELEASE [update]
|
||||
ishmael ~ # bastille bootstrap 13.2-RELEASE [update]
|
||||
|
||||
To `bootstrap` a HardenedBSD release, run the bootstrap sub-command with the
|
||||
build version as the argument.
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
ishmael ~ # bastille bootstrap 13-stable-build-latest
|
||||
|
||||
|
||||
This command will ensure the required directory structures are in place and
|
||||
download the requested release. For each requested release, `bootstrap` will
|
||||
|
||||
@@ -31,3 +31,13 @@ ranges include:
|
||||
|
||||
Bastille does its best to validate the submitted ip is valid. This has not been
|
||||
thouroughly tested--I generally use the 10/8 range.
|
||||
|
||||
A couple of notes about the created jails. First, MOTD has been disabled inside
|
||||
of the jails because it does not give information about the jail, but about the host
|
||||
system. This caused confusion for some users, so we implemented the .hushlogin which
|
||||
silences the MOTD at login.
|
||||
|
||||
Also, uname does not work from within a jail. Much like MOTD, it gives you the version
|
||||
information about the host system instead of the jail. If you need to check the version
|
||||
of freebsd running on the jail use the freebsd-version command to get accurate information.
|
||||
|
||||
|
||||
@@ -16,4 +16,16 @@ can be exported only when the jail is not running.
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
Usage: bastille export TARGET
|
||||
Usage: bastille export | option(s) | TARGET | PATH
|
||||
|
||||
Available options are:
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
--gz -- Export a ZFS jail using GZIP(.gz) compressed image.
|
||||
-r | --raw -- Export a ZFS jail to an uncompressed RAW image.
|
||||
-s | --safe -- Safely stop and start a ZFS jail before the exporting process.
|
||||
--tgz -- Export a jail using simple .tgz compressed archive instead.
|
||||
--txz -- Export a jail using simple .txz compressed archive instead.
|
||||
-v | --verbose -- Be more verbose during the ZFS send operation.
|
||||
--xz -- Export a ZFS jail using XZ(.xz) compressed image.
|
||||
|
||||
@@ -23,9 +23,11 @@ Bastille sub-commands
|
||||
rename
|
||||
restart
|
||||
service
|
||||
setup
|
||||
start
|
||||
stop
|
||||
sysrc
|
||||
tags
|
||||
top
|
||||
umount
|
||||
update
|
||||
|
||||
@@ -10,31 +10,7 @@ To manage binary packages within the container use `bastille pkg`.
|
||||
[folsom]:
|
||||
The package management tool is not yet installed on your system.
|
||||
Do you want to fetch and install it now? [y/N]: y
|
||||
Bootstrapping pkg from pkg+http://pkg.FreeBSD.org/FreeBSD:10:amd64/quarterly, please wait...
|
||||
Verifying signature with trusted certificate pkg.freebsd.org.2013102301... done
|
||||
[folsom] Installing pkg-1.10.5_5...
|
||||
[folsom] Extracting pkg-1.10.5_5: 100%
|
||||
Updating FreeBSD repository catalogue...
|
||||
pkg: Repository FreeBSD load error: access repo file(/var/db/pkg/repo-FreeBSD.sqlite) failed: No such file or directory
|
||||
[folsom] Fetching meta.txz: 100% 944 B 0.9kB/s 00:01
|
||||
[folsom] Fetching packagesite.txz: 100% 6 MiB 3.4MB/s 00:02
|
||||
Processing entries: 100%
|
||||
FreeBSD repository update completed. 32550 packages processed.
|
||||
All repositories are up to date.
|
||||
Updating database digests format: 100%
|
||||
The following 10 package(s) will be affected (of 0 checked):
|
||||
|
||||
New packages to be INSTALLED:
|
||||
vim-console: 8.1.0342
|
||||
git-lite: 2.19.1
|
||||
zsh: 5.6.2
|
||||
expat: 2.2.6_1
|
||||
curl: 7.61.1
|
||||
libnghttp2: 1.33.0
|
||||
ca_root_nss: 3.40
|
||||
pcre: 8.42
|
||||
gettext-runtime: 0.19.8.1_1
|
||||
indexinfo: 0.3.1
|
||||
...[snip]...
|
||||
|
||||
Number of packages to be installed: 10
|
||||
|
||||
@@ -42,41 +18,7 @@ To manage binary packages within the container use `bastille pkg`.
|
||||
17 MiB to be downloaded.
|
||||
|
||||
Proceed with this action? [y/N]: y
|
||||
[folsom] [1/10] Fetching vim-console-8.1.0342.txz: 100% 5 MiB 5.8MB/s 00:01
|
||||
[folsom] [2/10] Fetching git-lite-2.19.1.txz: 100% 4 MiB 2.1MB/s 00:02
|
||||
[folsom] [3/10] Fetching zsh-5.6.2.txz: 100% 4 MiB 4.4MB/s 00:01
|
||||
[folsom] [4/10] Fetching expat-2.2.6_1.txz: 100% 109 KiB 111.8kB/s 00:01
|
||||
[folsom] [5/10] Fetching curl-7.61.1.txz: 100% 1 MiB 1.2MB/s 00:01
|
||||
[folsom] [6/10] Fetching libnghttp2-1.33.0.txz: 100% 107 KiB 109.8kB/s 00:01
|
||||
[folsom] [7/10] Fetching ca_root_nss-3.40.txz: 100% 287 KiB 294.3kB/s 00:01
|
||||
[folsom] [8/10] Fetching pcre-8.42.txz: 100% 1 MiB 1.2MB/s 00:01
|
||||
[folsom] [9/10] Fetching gettext-runtime-0.19.8.1_1.txz: 100% 148 KiB 151.3kB/s 00:01
|
||||
[folsom] [10/10] Fetching indexinfo-0.3.1.txz: 100% 6 KiB 5.7kB/s 00:01
|
||||
Checking integrity... done (0 conflicting)
|
||||
[folsom] [1/10] Installing libnghttp2-1.33.0...
|
||||
[folsom] [1/10] Extracting libnghttp2-1.33.0: 100%
|
||||
[folsom] [2/10] Installing ca_root_nss-3.40...
|
||||
[folsom] [2/10] Extracting ca_root_nss-3.40: 100%
|
||||
[folsom] [3/10] Installing indexinfo-0.3.1...
|
||||
[folsom] [3/10] Extracting indexinfo-0.3.1: 100%
|
||||
[folsom] [4/10] Installing expat-2.2.6_1...
|
||||
[folsom] [4/10] Extracting expat-2.2.6_1: 100%
|
||||
[folsom] [5/10] Installing curl-7.61.1...
|
||||
[folsom] [5/10] Extracting curl-7.61.1: 100%
|
||||
[folsom] [6/10] Installing pcre-8.42...
|
||||
[folsom] [6/10] Extracting pcre-8.42: 100%
|
||||
[folsom] [7/10] Installing gettext-runtime-0.19.8.1_1...
|
||||
[folsom] [7/10] Extracting gettext-runtime-0.19.8.1_1: 100%
|
||||
[folsom] [8/10] Installing vim-console-8.1.0342...
|
||||
[folsom] [8/10] Extracting vim-console-8.1.0342: 100%
|
||||
[folsom] [9/10] Installing git-lite-2.19.1...
|
||||
===> Creating groups.
|
||||
Creating group 'git_daemon' with gid '964'.
|
||||
===> Creating users
|
||||
Creating user 'git_daemon' with uid '964'.
|
||||
[folsom] [9/10] Extracting git-lite-2.19.1: 100%
|
||||
[folsom] [10/10] Installing zsh-5.6.2...
|
||||
[folsom] [10/10] Extracting zsh-5.6.2: 100%
|
||||
...[snip]...
|
||||
|
||||
|
||||
The PKG sub-command can, of course, do more than just `install`. The
|
||||
@@ -146,7 +88,7 @@ expectation is that you can fully leverage the pkg manager. This means,
|
||||
The following 1 package(s) will be affected (of 0 checked):
|
||||
|
||||
Installed packages to be UPGRADED:
|
||||
nginx-lite: 1.14.0_14,2 -> 1.14.1,2
|
||||
nginx-lite: 1.23.0 -> 1.24.0_12,3
|
||||
|
||||
Number of packages to be upgraded: 1
|
||||
|
||||
@@ -155,10 +97,10 @@ expectation is that you can fully leverage the pkg manager. This means,
|
||||
Proceed with this action? [y/N]: y
|
||||
[nginx] [1/1] Fetching nginx-lite-1.14.1,2.txz: 100% 315 KiB 322.8kB/s 00:01
|
||||
Checking integrity... done (0 conflicting)
|
||||
[nginx] [1/1] Upgrading nginx-lite from 1.14.0_14,2 to 1.14.1,2...
|
||||
[nginx] [1/1] Upgrading nginx-lite from 1.23.0 to 1.24.0_12,3...
|
||||
===> Creating groups.
|
||||
Using existing group 'www'.
|
||||
===> Creating users
|
||||
Using existing user 'www'.
|
||||
[nginx] [1/1] Extracting nginx-lite-1.14.1,2: 100%
|
||||
[nginx] [1/1] Extracting nginx-lite-1.24.0_12: 100%
|
||||
You may need to manually remove /usr/local/etc/nginx/nginx.conf if it is no longer needed.
|
||||
|
||||
16
docs/chapters/subcommands/setup.rst
Normal file
16
docs/chapters/subcommands/setup.rst
Normal file
@@ -0,0 +1,16 @@
|
||||
=====
|
||||
setup
|
||||
=====
|
||||
|
||||
The `setup` sub-command attempts to automatically configure a host system for
|
||||
Bastille containers. This allows you to configure networking, firewall, and storage
|
||||
options for a Bastille host with one command.
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
ishmael ~ # bastille setup -h ## display setup help
|
||||
ishmael ~ # bastille setup bastille0 ## only configure loopback interface
|
||||
ishmael ~ # bastille setup pf ## only configure default firewall
|
||||
ishmael ~ # bastille setup zfs ## only configure ZFS storage
|
||||
ishmael ~ # bastille setup vnet ## only configure VNET bridge
|
||||
ishmael ~ # bastille setup ## configure all of the above
|
||||
13
docs/chapters/subcommands/tags.rst
Normal file
13
docs/chapters/subcommands/tags.rst
Normal file
@@ -0,0 +1,13 @@
|
||||
====
|
||||
tags
|
||||
====
|
||||
|
||||
The `tags` sub-command adds, removes or lists arbitrary tags on your containers.
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
ishmael ~ # bastille tags -h ## display tags help
|
||||
ishmael ~ # bastille tags TARGET add tag1,tag2 ## add the tags "tag1" and "tag2" to TARGET
|
||||
ishmael ~ # bastille tags TARGET delete tag2 ## delete tag "tag2" from TARGET
|
||||
ishmael ~ # bastille tags TARGET list ## list tags assigned to TARGET
|
||||
ishmael ~ # bastille tags ALL list ## list tags from ALL containers
|
||||
@@ -10,14 +10,14 @@ If no updates are available, a message will be shown:
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
ishmael ~ # bastille update 11.2-RELEASE
|
||||
ishmael ~ # bastille update 11.4-RELEASE
|
||||
Looking up update.FreeBSD.org mirrors... 2 mirrors found.
|
||||
Fetching metadata signature for 11.2-RELEASE from update4.freebsd.org... done.
|
||||
Fetching metadata signature for 11.4-RELEASE from update4.freebsd.org... done.
|
||||
Fetching metadata index... done.
|
||||
Inspecting system... done.
|
||||
Preparing to download files... done.
|
||||
|
||||
No updates needed to update system to 11.2-RELEASE-p4.
|
||||
No updates needed to update system to 11.4-RELEASE-p4.
|
||||
No updates are available to install.
|
||||
|
||||
|
||||
@@ -25,9 +25,9 @@ The older the release, however, the more updates will be available:
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
ishmael ~ # bastille update 10.4-RELEASE
|
||||
ishmael ~ # bastille update 13.2-RELEASE
|
||||
Looking up update.FreeBSD.org mirrors... 2 mirrors found.
|
||||
Fetching metadata signature for 10.4-RELEASE from update1.freebsd.org... done.
|
||||
Fetching metadata signature for 13.2-RELEASE from update1.freebsd.org... done.
|
||||
Fetching metadata index... done.
|
||||
Fetching 2 metadata patches.. done.
|
||||
Applying metadata patches... done.
|
||||
@@ -35,7 +35,7 @@ The older the release, however, the more updates will be available:
|
||||
Inspecting system... done.
|
||||
Preparing to download files... done.
|
||||
|
||||
The following files will be added as part of updating to 10.4-RELEASE-p13:
|
||||
The following files will be added as part of updating to 13.2-RELEASE-p4:
|
||||
...[snip]...
|
||||
|
||||
To be safe, you may want to restart any containers that have been updated live.
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
=======
|
||||
upgrade
|
||||
=======
|
||||
|
||||
This command lets you upgrade a release to a new release. Depending on the
|
||||
workflow this can be similar to a `bootstrap`.
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
ishmael ~ # bastille upgrade 12.0-RELEASE 12.1-RELEASE
|
||||
@@ -27,7 +27,7 @@ Examples: Containers
|
||||
| cmd | ALL | 'sockstat -4' | execute `sockstat -4` in ALL containers (ip4 sockets) |
|
||||
+-----------+--------+-----+------------+-------------------------------------------------------------+
|
||||
| console | mariadb02 | --- | console (shell) access to mariadb02 |
|
||||
+----+------+----+---------+------------+--------------+----------------------------------------------+
|
||||
+----+------+--------+-----+------------+-------------------------------------------------------------+
|
||||
| pkg | web01 | 'install nginx' | install nginx package in web01 container |
|
||||
+-----------+--------+------------------+-------------------------------------------------------------+
|
||||
| pkg | ALL | upgrade | upgrade packages in ALL containers |
|
||||
@@ -39,11 +39,11 @@ Examples: Containers
|
||||
| template | ALL | username/base | apply `username/base` template to ALL containers |
|
||||
+-----------+--------+------------------+-------------------------------------------------------------+
|
||||
| start | web02 | --- | start web02 container |
|
||||
+-----------+--------+-----+------------+-------------------------------------------------------------+
|
||||
| cp | bastion03 | /tmp/resolv.conf-cf etc/resolv.conf | copy host-path to container-path in bastion03|
|
||||
+----+------+----+---+------------------+--------------+----------------------------------------------+
|
||||
| create | folsom | 12.1-RELEASE 10.17.89.10 | create 12.1 container named `folsom` with IP |
|
||||
+-----------+--------+------------------+--------------+----------------------------------------------+
|
||||
| cp | bastion03 | /tmp/resolv.conf-cf etc/resolv.conf | copy host-path to container-path in bastion03|
|
||||
+----+------+----+---+---------------------------------+----------------------------------------------+
|
||||
| create | folsom | 13.2-RELEASE 10.17.89.10 | create 13.2 container named `folsom` with IP |
|
||||
+-----------+--------+---------------------------------+----------------------------------------------+
|
||||
|
||||
|
||||
Examples: Releases
|
||||
@@ -56,11 +56,9 @@ Examples: Releases
|
||||
+-----------+--------------+--------------+-------------------------------------------------------------+
|
||||
| command | target | args | description |
|
||||
+===========+==============+==============+=============================================================+
|
||||
| bootstrap | 12.1-RELEASE | --- | bootstrap 12.1-RELEASE release |
|
||||
| bootstrap | 13.2-RELEASE | --- | bootstrap 13.2-RELEASE release |
|
||||
+-----------+--------------+--------------+-------------------------------------------------------------+
|
||||
| update | 11.4-RELEASE | --- | update 11.4-RELEASE release |
|
||||
| update | 12.4-RELEASE | --- | update 12.4-RELEASE release |
|
||||
+-----------+--------------+--------------+-------------------------------------------------------------+
|
||||
| upgrade | 11.3-RELEASE | 11.4-RELEASE | update 11.4-RELEASE release |
|
||||
+-----------+--------------+--------------+-------------------------------------------------------------+
|
||||
| verify | 11.4-RELEASE | --- | update 11.4-RELEASE release |
|
||||
| verify | 12.4-RELEASE | --- | verify 12.4-RELEASE release |
|
||||
+-----------+--------------+--------------+-------------------------------------------------------------+
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
========
|
||||
Template
|
||||
========
|
||||
Looking for ready made CI/CD validated [Bastille
|
||||
Templates](https://gitlab.com/BastilleBSD-Templates)?
|
||||
Looking for ready made CI/CD validated `Bastille Templates`_?
|
||||
|
||||
Bastille supports a templating system allowing you to apply files, pkgs and
|
||||
execute commands inside the containers automatically.
|
||||
@@ -71,7 +70,7 @@ use, be sure to include `usr` in the template OVERLAY definition. eg;
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
echo "CP usr" >> /usr/local/bastille/templates/username/template/Bastillefile
|
||||
echo "CP usr /" >> /usr/local/bastille/templates/username/template/Bastillefile
|
||||
|
||||
The above example "usr" will include anything under "usr" inside the template.
|
||||
You do not need to list individual files. Just include the top-level directory
|
||||
@@ -139,3 +138,38 @@ directory names in the `bastille/templates` directory.
|
||||
Executing final command(s).
|
||||
chsh: user information updated
|
||||
Template Complete.
|
||||
|
||||
.. _Bastille Templates: https://gitlab.com/BastilleBSD-Templates
|
||||
|
||||
Using Ports in Templates
|
||||
------------------------
|
||||
|
||||
Sometimes when you make a template you need special options for a package, or you need a newer version than what is in the pkgs. The solution for these cases, or a case like minecraft server that has NO compiled option, is to use the ports. A working example of this is the minecraft server template in the template repo. The main lines needed to use this is first to mount the ports directory, then compile the port. Below is an example of the minecraft template where this was used.
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
ARG MINECRAFT_MEMX="1024M"
|
||||
ARG MINECRAFT_MEMS="1024M"
|
||||
ARG MINECRAFT_ARGS=""
|
||||
CONFIG set enforce_statfs=1;
|
||||
CONFIG set allow.mount.fdescfs;
|
||||
CONFIG set allow.mount.procfs;
|
||||
RESTART
|
||||
PKG dialog4ports tmux openjdk17
|
||||
MOUNT /usr/ports usr/ports nullfs ro 0 0
|
||||
CP etc /
|
||||
CP var /
|
||||
CMD make -C /usr/ports/games/minecraft-server install clean
|
||||
CP usr /
|
||||
SYSRC minecraft_enable=YES
|
||||
SYSRC minecraft_memx=${MINECRAFT_MEMX}
|
||||
SYSRC minecraft_mems=${MINECRAFT_MEMS}
|
||||
SYSRC minecraft_args=${MINECRAFT_ARGS}
|
||||
SERVICE minecraft restart
|
||||
RDR tcp 25565 25565
|
||||
|
||||
The MOUNT line mounts the ports directory, then the CMD make line makes the port. This can be modified to use any port in the port tree.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
41
docs/chapters/upgrading.rst
Normal file
41
docs/chapters/upgrading.rst
Normal file
@@ -0,0 +1,41 @@
|
||||
=========
|
||||
Upgrading
|
||||
=========
|
||||
This document outlines upgrading jails hosted using Bastille.
|
||||
|
||||
Bastille can "bootstrap" multiple versions of FreeBSD to be used by jails. All jails do not NEED to be the same version (even if they often are), the only requirement here is that the "bootstrapped" versions are less than or equal to the host version of FreeBSD.
|
||||
|
||||
To upgrade Bastille jails for a minor release (ie; 13.1→13.2) you can do the following:
|
||||
|
||||
1. ensure the new release version is bootstrapped and updated to the latest patch release: `bastille bootstrap 13.2-RELEASE update`
|
||||
2. stop the jail(s) that need to be updated.
|
||||
3. use `bastille edit TARGET fstab` to manually update the jail mounts from 13.1 to 13.2 release path.
|
||||
4. start the jail(s) that were edited
|
||||
5. upgrade complete!
|
||||
|
||||
To upgrade Bastille jails for a major release (ie; 12.4→13.2) you can do the following:
|
||||
|
||||
1. ensure the new version is bootstrapped and update to the latest patch release: `bastille bootstrap 13.2-RELEASE update`
|
||||
2. stop the jail(s) that need to be updated.
|
||||
3. use `bastille edit TARGET fstab` to manually update the jail mounts from 12.4 to 13.2 release path.
|
||||
4. start the jail(s) that were edited
|
||||
5. Force the reinstallation or upgrade of all installed packages (ABI change): `pkg upgrade -f` within each jail (or `bastille pkg ALL upgrade -f`)
|
||||
6. restart the affected jail(s)
|
||||
7. upgrade complete!
|
||||
|
||||
Revert Upgrade / Downgrade Process
|
||||
----------------------------------
|
||||
The downgrade process (not usually needed) is similar to the upgrade process only in reverse.
|
||||
|
||||
If you did a minor upgrade changing the release path from 13.1 to 13.2, stop the jail and revert that change. Downgrade complete.
|
||||
|
||||
If you did a major upgrade changing the release path from 12.4 to 13.2, stop the jail and revert that change. The pkg reinstallation will also need to be repeated after the jail restarts on the previous release.
|
||||
|
||||
Old Releases
|
||||
----------------------------------
|
||||
After upgrading all jails from one release to the next you may find that you now have bootstrapped a release that is no longer used. Once you've decided that you no longer need the option to revert the change you can destroy the old release.
|
||||
|
||||
|
||||
`bastille list releases` to list all bootstrapped releases.
|
||||
|
||||
`bastille destroy X.Y-RELEASE` to fully delete the release.
|
||||
@@ -8,13 +8,13 @@ else:
|
||||
# -- Project information -----------------------------------------------------
|
||||
|
||||
project = 'Bastille'
|
||||
copyright = '2018-2022, Christer Edwards'
|
||||
copyright = '2018-2023, Christer Edwards'
|
||||
author = 'Christer Edwards'
|
||||
|
||||
# The short X.Y version
|
||||
version = '0.9.20220216'
|
||||
version = '0.10.20231013'
|
||||
# The full version, including alpha/beta/rc tags
|
||||
release = '0.9.20220216-beta'
|
||||
release = '0.10.20231013-beta'
|
||||
|
||||
|
||||
# -- General configuration ---------------------------------------------------
|
||||
|
||||
@@ -12,13 +12,17 @@ https://docs.bastillebsd.org.
|
||||
:caption: Contents:
|
||||
|
||||
chapters/installation
|
||||
chapters/upgrading
|
||||
chapters/networking
|
||||
chapters/usage
|
||||
chapters/targeting
|
||||
chapters/upgrading
|
||||
chapters/subcommands/index
|
||||
chapters/template
|
||||
chapters/jail-config
|
||||
chapters/zfs-support
|
||||
chapters/gcp
|
||||
chapters/migration
|
||||
|
||||
copyright
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -32,17 +32,6 @@ PATH=${PATH}:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
|
||||
|
||||
. /usr/local/share/bastille/common.sh
|
||||
|
||||
## root check first.
|
||||
bastille_root_check() {
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
## permission denied
|
||||
error_notify "Bastille: Permission Denied"
|
||||
error_exit "root / sudo / doas required"
|
||||
fi
|
||||
}
|
||||
|
||||
bastille_root_check
|
||||
|
||||
## check for config existance
|
||||
bastille_conf_check() {
|
||||
if [ ! -r "/usr/local/etc/bastille/bastille.conf" ]; then
|
||||
@@ -54,6 +43,9 @@ bastille_conf_check
|
||||
|
||||
## we only load the config if conf_check passes
|
||||
. /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}"
|
||||
: "${bastille_network_pf_table:=jails}"
|
||||
|
||||
## bastille_prefix should be 0750
|
||||
## this restricts file system access to privileged users
|
||||
@@ -70,7 +62,7 @@ bastille_perms_check() {
|
||||
bastille_perms_check
|
||||
|
||||
## version
|
||||
BASTILLE_VERSION="0.9.20220216"
|
||||
BASTILLE_VERSION="0.10.20231013"
|
||||
|
||||
usage() {
|
||||
cat << EOF
|
||||
@@ -82,8 +74,8 @@ Usage:
|
||||
|
||||
Available Commands:
|
||||
bootstrap Bootstrap a FreeBSD release for container base.
|
||||
cmd Execute arbitrary command on targeted container(s).
|
||||
clone Clone an existing container.
|
||||
cmd Execute arbitrary command on targeted container(s).
|
||||
config Get or set a config value for the targeted container(s).
|
||||
console Console into a running container.
|
||||
convert Convert a Thin container into a Thick container.
|
||||
@@ -99,13 +91,16 @@ Available Commands:
|
||||
list List containers (running and stopped).
|
||||
mount Mount a volume inside the targeted container(s).
|
||||
pkg Manipulate binary packages within targeted container(s). See pkg(8).
|
||||
rcp reverse cp(1) files from a single container to the host.
|
||||
rdr Redirect host port to container port.
|
||||
rename Rename a container.
|
||||
restart Restart a running container.
|
||||
service Manage services within targeted container(s).
|
||||
setup Attempt to auto-configure network, firewall and storage on new installs.
|
||||
start Start a stopped container.
|
||||
stop Stop a running container.
|
||||
sysrc Safely edit rc files within targeted container(s).
|
||||
tags Add or remove tags to targeted container(s).
|
||||
template Apply file templates to targeted container(s).
|
||||
top Display and update information about the top(1) cpu processes.
|
||||
umount Unmount a volume from within the targeted container(s).
|
||||
@@ -126,6 +121,23 @@ EOF
|
||||
CMD=$1
|
||||
shift
|
||||
|
||||
target_all_jails() {
|
||||
_JAILS=$(/usr/sbin/jls name)
|
||||
JAILS=""
|
||||
for _jail in ${_JAILS}; do
|
||||
_JAILPATH=$(/usr/sbin/jls -j "${_jail}" path)
|
||||
if [ -z ${_JAILPATH##${bastille_jailsdir}*} ]; then
|
||||
JAILS="${JAILS} ${_jail}"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
check_target_is_running() {
|
||||
if [ ! "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
|
||||
error_exit "[${TARGET}]: Not started. See 'bastille start ${TARGET}'."
|
||||
fi
|
||||
}
|
||||
|
||||
# Handle special-case commands first.
|
||||
case "${CMD}" in
|
||||
version|-v|--version)
|
||||
@@ -135,10 +147,10 @@ version|-v|--version)
|
||||
help|-h|--help)
|
||||
usage
|
||||
;;
|
||||
bootstrap|create|destroy|export|import|list|rdr|restart|start|update|upgrade|verify)
|
||||
bootstrap|create|destroy|export|import|list|rdr|restart|setup|start|update|upgrade|verify)
|
||||
# Nothing "extra" to do for these commands. -- cwells
|
||||
;;
|
||||
clone|config|cmd|console|convert|cp|edit|htop|limits|mount|pkg|rename|service|stop|sysrc|template|top|umount|zfs)
|
||||
clone|config|cmd|console|convert|cp|edit|htop|limits|mount|pkg|rcp|rename|service|stop|sysrc|tags|template|top|umount|zfs)
|
||||
# Parse the target and ensure it exists. -- cwells
|
||||
if [ $# -eq 0 ]; then # No target was given, so show the command's help. -- cwells
|
||||
PARAMS='help'
|
||||
@@ -147,24 +159,17 @@ clone|config|cmd|console|convert|cp|edit|htop|limits|mount|pkg|rename|service|st
|
||||
shift
|
||||
|
||||
if [ "${TARGET}" = 'ALL' ]; then
|
||||
_JAILS=$(/usr/sbin/jls name)
|
||||
JAILS=""
|
||||
for _jail in ${_JAILS}; do
|
||||
_JAILPATH=$(/usr/sbin/jls -j "${_jail}" path)
|
||||
if [ -z ${_JAILPATH##${bastille_jailsdir}*} ]; then
|
||||
JAILS="${JAILS} ${_jail}"
|
||||
fi
|
||||
done
|
||||
target_all_jails
|
||||
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}'."
|
||||
if [ "${TARGET}" = 'ALL' ]; then
|
||||
target_all_jails
|
||||
else
|
||||
JAILS="${TARGET}"
|
||||
check_target_is_running
|
||||
fi
|
||||
shift
|
||||
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
|
||||
@@ -178,10 +183,7 @@ 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 [ ! "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
|
||||
error_exit "[${TARGET}]: Not started. See 'bastille start ${TARGET}'."
|
||||
fi
|
||||
check_target_is_running
|
||||
;;
|
||||
convert|rename)
|
||||
# Require the target to be stopped. -- cwells
|
||||
|
||||
@@ -11,6 +11,9 @@ bastille_releasesdir="${bastille_prefix}/releases" ## default
|
||||
bastille_templatesdir="${bastille_prefix}/templates" ## default: "${bastille_prefix}/templates"
|
||||
bastille_logsdir="/var/log/bastille" ## default: "/var/log/bastille"
|
||||
|
||||
## pf configuration path
|
||||
bastille_pf_conf="/etc/pf.conf" ## default: "/etc/pf.conf"
|
||||
|
||||
## bastille scripts directory (assumed by bastille pkg)
|
||||
bastille_sharedir="/usr/local/share/bastille" ## default: "/usr/local/share/bastille"
|
||||
|
||||
@@ -32,7 +35,7 @@ bastille_resolv_conf="/etc/resolv.conf" ## default
|
||||
|
||||
## bootstrap urls
|
||||
bastille_url_freebsd="http://ftp.freebsd.org/pub/FreeBSD/releases/" ## default: "http://ftp.freebsd.org/pub/FreeBSD/releases/"
|
||||
bastille_url_hardenedbsd="http://installer.hardenedbsd.org/pub/hardenedbsd/" ## default: "https://installer.hardenedbsd.org/pub/HardenedBSD/releases/"
|
||||
bastille_url_hardenedbsd="https://installers.hardenedbsd.org/pub/" ## default: "https://installer.hardenedbsd.org/pub/HardenedBSD/releases/"
|
||||
bastille_url_midnightbsd="https://www.midnightbsd.org/ftp/MidnightBSD/releases/" ## default: "https://www.midnightbsd.org/pub/MidnightBSD/releases/"
|
||||
|
||||
## ZFS options
|
||||
@@ -46,9 +49,12 @@ bastille_compress_xz_options="-0 -v" ## default
|
||||
bastille_decompress_xz_options="-c -d -v" ## default "-c -d -v"
|
||||
bastille_compress_gz_options="-1 -v" ## default "-1 -v"
|
||||
bastille_decompress_gz_options="-k -d -c -v" ## default "-k -d -c -v"
|
||||
bastille_export_options="" ## default "" predefined export options, e.g. "--safe --gz"
|
||||
|
||||
## Networking
|
||||
bastille_network_loopback="bastille0" ## default: "bastille0"
|
||||
bastille_network_pf_ext_if="ext_if" ## default: "ext_if"
|
||||
bastille_network_pf_table="jails" ## default: "jails"
|
||||
bastille_network_shared="" ## default: ""
|
||||
bastille_network_gateway="" ## default: ""
|
||||
bastille_network_gateway6="" ## default: ""
|
||||
|
||||
@@ -51,7 +51,9 @@ bastille_stop()
|
||||
|
||||
local _jail
|
||||
|
||||
for _jail in ${bastille_list}; do
|
||||
## 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; }')
|
||||
for _jail in ${bastille_revlist}; do
|
||||
echo "Stopping Bastille Container: ${_jail}"
|
||||
${command} stop ${_jail}
|
||||
done
|
||||
|
||||
Binary file not shown.
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -42,6 +42,8 @@ help|-h|--help)
|
||||
;;
|
||||
esac
|
||||
|
||||
bastille_root_check
|
||||
|
||||
#Validate if ZFS is enabled in rc.conf and bastille.conf.
|
||||
if [ "$(sysrc -n zfs_enable)" = "YES" ] && [ ! "${bastille_zfs_enable}" = "YES" ]; then
|
||||
warn "ZFS is enabled in rc.conf but not bastille.conf. Do you want to continue? (N|y)"
|
||||
@@ -127,19 +129,29 @@ bootstrap_directories() {
|
||||
if [ "${bastille_zfs_enable}" = "YES" ]; 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}/${RELEASE}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/cache/${RELEASE}"
|
||||
# Don't create unused/stale cache/RELEASE directory on Linux jails creation.
|
||||
if [ -z "${NOCACHEDIR}" ]; then
|
||||
zfs create ${bastille_zfs_options} -o mountpoint="${bastille_cachedir}/${RELEASE}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/cache/${RELEASE}"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
mkdir -p "${bastille_cachedir}/${RELEASE}"
|
||||
mkdir -p "${bastille_cachedir}"
|
||||
# Don't create unused/stale cache/RELEASE directory on Linux jails creation.
|
||||
if [ -z "${NOCACHEDIR}" ]; then
|
||||
mkdir -p "${bastille_cachedir}/${RELEASE}"
|
||||
fi
|
||||
fi
|
||||
## create subsequent cache/XX.X-RELEASE datasets
|
||||
elif [ ! -d "${bastille_cachedir}/${RELEASE}" ]; then
|
||||
if [ "${bastille_zfs_enable}" = "YES" ]; 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}"
|
||||
# Don't create unused/stale cache/RELEASE directory on Linux jails creation.
|
||||
if [ -z "${NOCACHEDIR}" ]; then
|
||||
if [ "${bastille_zfs_enable}" = "YES" ]; 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}"
|
||||
fi
|
||||
else
|
||||
mkdir -p "${bastille_cachedir}/${RELEASE}"
|
||||
fi
|
||||
else
|
||||
mkdir -p "${bastille_cachedir}/${RELEASE}"
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -305,6 +317,7 @@ bootstrap_release() {
|
||||
debootstrap_release() {
|
||||
|
||||
# Make sure to check/bootstrap directories first.
|
||||
NOCACHEDIR=1
|
||||
RELEASE="${DIR_BOOTSTRAP}"
|
||||
bootstrap_directories
|
||||
|
||||
@@ -386,7 +399,7 @@ debootstrap_release() {
|
||||
fi
|
||||
|
||||
case "${LINUX_FLAVOR}" in
|
||||
bionic|stretch|buster|bullseye)
|
||||
bionic|focal|jammy|buster|bullseye|bookworm)
|
||||
info "Increasing APT::Cache-Start"
|
||||
echo "APT::Cache-Start 251658240;" > "${bastille_releasesdir}"/${DIR_BOOTSTRAP}/etc/apt/apt.conf.d/00aptitude
|
||||
;;
|
||||
@@ -414,7 +427,7 @@ bootstrap_template() {
|
||||
## define basic variables
|
||||
_url=${BASTILLE_TEMPLATE_URL}
|
||||
_user=${BASTILLE_TEMPLATE_USER}
|
||||
_repo=${BASTILLE_TEMPLATE_REPO}
|
||||
_repo=${BASTILLE_TEMPLATE_REPO%.*} # Remove the trailing ".git"
|
||||
_template=${bastille_templatesdir}/${_user}/${_repo}
|
||||
|
||||
## support for non-git
|
||||
@@ -445,6 +458,7 @@ else
|
||||
HW_MACHINE_ARCH_LINUX=${HW_MACHINE_ARCH}
|
||||
fi
|
||||
|
||||
NOCACHEDIR=
|
||||
RELEASE="${1}"
|
||||
OPTION="${2}"
|
||||
|
||||
@@ -502,8 +516,8 @@ case "${1}" in
|
||||
## check for HardenedBSD(latest stable build release)
|
||||
NAME_VERIFY=$(echo "${RELEASE}" | 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_RELEASE=$(echo "${NAME_VERIFY}" | sed 's/-BUILD-LATEST//g')
|
||||
NAME_BUILD=$(echo "${NAME_VERIFY}" | sed 's/[0-9]\{1,2\}-stable-//g')
|
||||
UPSTREAM_URL="${bastille_url_hardenedbsd}${NAME_RELEASE}/${HW_MACHINE}/${HW_MACHINE_ARCH}/${NAME_BUILD}"
|
||||
NAME_BUILD=$(echo "${NAME_VERIFY}" | sed 's/[0-9]\{1,2\}-stable-BUILD-//g')
|
||||
UPSTREAM_URL="${bastille_url_hardenedbsd}${NAME_RELEASE}/${HW_MACHINE}/${HW_MACHINE_ARCH}/installer/${NAME_BUILD}"
|
||||
PLATFORM_OS="HardenedBSD"
|
||||
validate_release_url
|
||||
;;
|
||||
@@ -520,8 +534,8 @@ current-build-latest|current-BUILD-LATEST|CURRENT-BUILD-LATEST)
|
||||
## check for HardenedBSD(latest current build release)
|
||||
NAME_VERIFY=$(echo "${RELEASE}" | grep -iwE '(current-build-latest)' | sed 's/CURRENT/current/g' | sed 's/build/BUILD/g' | sed 's/latest/LATEST/g')
|
||||
NAME_RELEASE=$(echo "${NAME_VERIFY}" | sed 's/current-.*/current/g')
|
||||
NAME_BUILD=$(echo "${NAME_VERIFY}" | sed 's/current-//g')
|
||||
UPSTREAM_URL="${bastille_url_hardenedbsd}${NAME_RELEASE}/${HW_MACHINE}/${HW_MACHINE_ARCH}/${NAME_BUILD}"
|
||||
NAME_BUILD=$(echo "${NAME_VERIFY}" | sed 's/current-BUILD-//g')
|
||||
UPSTREAM_URL="${bastille_url_hardenedbsd}${NAME_RELEASE}/${HW_MACHINE}/${HW_MACHINE_ARCH}/installer/${NAME_BUILD}"
|
||||
PLATFORM_OS="HardenedBSD"
|
||||
validate_release_url
|
||||
;;
|
||||
@@ -531,6 +545,13 @@ http?://*/*/*)
|
||||
BASTILLE_TEMPLATE_REPO=$(echo "${1}" | awk -F / '{ print $5 }')
|
||||
bootstrap_template
|
||||
;;
|
||||
git@*:*/*)
|
||||
BASTILLE_TEMPLATE_URL=${1}
|
||||
git_repository=$(echo "${1}" | awk -F : '{ print $2 }')
|
||||
BASTILLE_TEMPLATE_USER=$(echo "${git_repository}" | awk -F / '{ print $1 }')
|
||||
BASTILLE_TEMPLATE_REPO=$(echo "${git_repository}" | awk -F / '{ print $2 }')
|
||||
bootstrap_template
|
||||
;;
|
||||
#adding Ubuntu Bionic as valid "RELEASE" for POC @hackacad
|
||||
ubuntu_bionic|bionic|ubuntu-bionic)
|
||||
PLATFORM_OS="Ubuntu/Linux"
|
||||
@@ -546,10 +567,10 @@ ubuntu_focal|focal|ubuntu-focal)
|
||||
ARCH_BOOTSTRAP=${HW_MACHINE_ARCH_LINUX}
|
||||
debootstrap_release
|
||||
;;
|
||||
debian_stretch|stretch|debian-stretch)
|
||||
PLATFORM_OS="Debian/Linux"
|
||||
LINUX_FLAVOR="stretch"
|
||||
DIR_BOOTSTRAP="Debian9"
|
||||
ubuntu_jammy|jammy|ubuntu-jammy)
|
||||
PLATFORM_OS="Ubuntu/Linux"
|
||||
LINUX_FLAVOR="jammy"
|
||||
DIR_BOOTSTRAP="Ubuntu_2204"
|
||||
ARCH_BOOTSTRAP=${HW_MACHINE_ARCH_LINUX}
|
||||
debootstrap_release
|
||||
;;
|
||||
@@ -567,6 +588,13 @@ debian_bullseye|bullseye|debian-bullseye)
|
||||
ARCH_BOOTSTRAP=${HW_MACHINE_ARCH_LINUX}
|
||||
debootstrap_release
|
||||
;;
|
||||
debian_bookworm|bookworm|debian-bookworm)
|
||||
PLATFORM_OS="Debian/Linux"
|
||||
LINUX_FLAVOR="bookworm"
|
||||
DIR_BOOTSTRAP="Debian12"
|
||||
ARCH_BOOTSTRAP=${HW_MACHINE_ARCH_LINUX}
|
||||
debootstrap_release
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
;;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -46,6 +46,8 @@ if [ $# -ne 2 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
bastille_root_check
|
||||
|
||||
NEWNAME="${1}"
|
||||
IP="${2}"
|
||||
|
||||
@@ -68,7 +70,7 @@ validate_ip() {
|
||||
error_exit "Invalid: (${TEST_IP})"
|
||||
fi
|
||||
done
|
||||
if ifconfig | grep -qw "${TEST_IP}"; then
|
||||
if ifconfig | grep -qwF "${TEST_IP}"; then
|
||||
warn "Warning: IP address already in use (${TEST_IP})."
|
||||
else
|
||||
info "Valid: (${IP})."
|
||||
@@ -109,7 +111,11 @@ update_jailconf_vnet() {
|
||||
if [ -n "${jail_list}" ]; then
|
||||
if ! grep -q "e0b_bastille${_num}" "${bastille_jailsdir}"/*/jail.conf; then
|
||||
uniq_epair="bastille${_num}"
|
||||
# Update the exec.* with uniq_epair when cloning jails.
|
||||
sed -i '' "s|vnet.interface = e0b_bastille.*;|vnet.interface = e0b_${uniq_epair};|" "${JAIL_CONFIG}"
|
||||
sed -i '' "s|exec.prestart += \"jib addm bastille[0-9]|exec.prestart += \"jib addm ${uniq_epair}|" "${JAIL_CONFIG}"
|
||||
sed -i '' "s|exec.prestart += \"ifconfig e0a_bastille[0-9].*|exec.prestart += \"ifconfig e0a_${uniq_epair} description \\\\\"vnet host interface for Bastille jail ${NEWNAME}\\\\\"\";|" "${JAIL_CONFIG}"
|
||||
sed -i '' "s|exec.poststop += \"jib destroy bastille[0-9]\";|exec.poststop += \"jib destroy ${uniq_epair}\";|" "${JAIL_CONFIG}"
|
||||
break
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -29,6 +29,7 @@
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
. /usr/local/share/bastille/common.sh
|
||||
. /usr/local/etc/bastille/bastille.conf
|
||||
|
||||
usage() {
|
||||
error_exit "Usage: bastille cmd TARGET command"
|
||||
@@ -45,18 +46,27 @@ if [ $# -eq 0 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
bastille_root_check
|
||||
|
||||
COUNT=0
|
||||
RETURN=0
|
||||
|
||||
for _jail in ${JAILS}; do
|
||||
COUNT=$(($COUNT+1))
|
||||
info "[${_jail}]:"
|
||||
jexec -l -U root "${_jail}" "$@"
|
||||
|
||||
if grep -qw "linsysfs" "${bastille_jailsdir}/${_jail}/fstab"; then
|
||||
# Allow executing commands on Linux jails.
|
||||
jexec -l -u root "${_jail}" "$@"
|
||||
else
|
||||
jexec -l -U root "${_jail}" "$@"
|
||||
fi
|
||||
|
||||
ERROR_CODE=$?
|
||||
info "[${_jail}]: ${ERROR_CODE}"
|
||||
|
||||
if [ "$COUNT" -eq 1 ]; then
|
||||
RETURN=$ERROR_CODE
|
||||
RETURN=${ERROR_CODE}
|
||||
else
|
||||
RETURN=$(($RETURN+$ERROR_CODE))
|
||||
fi
|
||||
@@ -65,8 +75,8 @@ for _jail in ${JAILS}; do
|
||||
done
|
||||
|
||||
# Check when a command is executed in all running jails. (bastille cmd ALL ...)
|
||||
if [ "$COUNT" -gt 1 ] && [ "$RETURN" -gt 0 ]; then
|
||||
if [ "${COUNT}" -gt 1 ] && [ "${RETURN}" -gt 0 ]; then
|
||||
RETURN=1
|
||||
fi
|
||||
|
||||
return "$RETURN"
|
||||
return "${RETURN}"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -33,12 +33,21 @@ COLOR_GREEN=
|
||||
COLOR_YELLOW=
|
||||
COLOR_RESET=
|
||||
|
||||
bastille_root_check() {
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
## permission denied
|
||||
error_notify "Bastille: Permission Denied"
|
||||
error_exit "root / sudo / doas required"
|
||||
fi
|
||||
}
|
||||
|
||||
enable_color() {
|
||||
. /usr/local/share/bastille/colors.pre.sh
|
||||
}
|
||||
|
||||
# If "NO_COLOR" environment variable is present, disable output colors.
|
||||
if [ -z "${NO_COLOR}" ]; then
|
||||
# If "NO_COLOR" environment variable is present, or we aren't speaking to a
|
||||
# tty, disable output colors.
|
||||
if [ -z "${NO_COLOR}" -a -t 1 ]; then
|
||||
enable_color
|
||||
fi
|
||||
|
||||
@@ -74,9 +83,11 @@ generate_vnet_jail_netblock() {
|
||||
local num_range=$((list_jails_num + 1))
|
||||
for _num in $(seq 0 "${num_range}"); do
|
||||
if ! grep -q "e[0-9]b_bastille${_num}" "${bastille_jailsdir}"/*/jail.conf; then
|
||||
local uniq_epair="bastille${_num}"
|
||||
local uniq_epair_bridge="${_num}"
|
||||
break
|
||||
if ! grep -q "epair${_num}" "${bastille_jailsdir}"/*/jail.conf; then
|
||||
local uniq_epair="bastille${_num}"
|
||||
local uniq_epair_bridge="${_num}"
|
||||
break
|
||||
fi
|
||||
fi
|
||||
done
|
||||
else
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -35,6 +35,15 @@ usage() {
|
||||
error_exit "Usage: bastille config TARGET get|set propertyName [newValue]"
|
||||
}
|
||||
|
||||
# we need jail(8) to parse the config file so it can expand variables etc
|
||||
print_jail_conf() {
|
||||
|
||||
# we need to pass a literal \n to jail to get each parameter on its own
|
||||
# line
|
||||
jail -f "$1" -e '
|
||||
'
|
||||
}
|
||||
|
||||
# Handle special-case commands first.
|
||||
case "$1" in
|
||||
help|-h|--help)
|
||||
@@ -46,6 +55,8 @@ if [ $# -eq 1 ] || [ $# -gt 3 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
bastille_root_check
|
||||
|
||||
ACTION=$1
|
||||
shift
|
||||
|
||||
@@ -71,22 +82,39 @@ for _jail in ${JAILS}; do
|
||||
continue
|
||||
fi
|
||||
|
||||
ESCAPED_PROPERTY=$(echo "${PROPERTY}" | sed 's/\./\\\./g')
|
||||
MATCH_LINE=$(grep "^[[:blank:]]*${ESCAPED_PROPERTY}[[:blank:]=;]" "${FILE}" 2>/dev/null)
|
||||
MATCH_FOUND=$?
|
||||
|
||||
if [ "${ACTION}" = 'get' ]; then
|
||||
if [ "${MATCH_FOUND}" -ne 0 ]; then
|
||||
warn "not set"
|
||||
elif ! echo "${MATCH_LINE}" | grep '=' > /dev/null 2>&1; then
|
||||
echo "enabled"
|
||||
_output=$(
|
||||
print_jail_conf "${FILE}" | awk -F= -v property="${PROPERTY}" '
|
||||
$1 == property {
|
||||
# note that we have found the property
|
||||
found = 1;
|
||||
# check if there is a value for this property
|
||||
if (NF == 2) {
|
||||
# remove any quotes surrounding the string
|
||||
sub(/^"/, "", $2);
|
||||
sub(/"$/, "", $2);
|
||||
print $2;
|
||||
} else {
|
||||
# no value, just the property name
|
||||
print "enabled";
|
||||
}
|
||||
exit 0;
|
||||
}
|
||||
END {
|
||||
# if we have not found anything we need to print a special
|
||||
# string
|
||||
if (! found) {
|
||||
print("not set");
|
||||
# let the caller know that this is a warn condition
|
||||
exit(120);
|
||||
}
|
||||
}'
|
||||
)
|
||||
# check if our output is a warning or regular
|
||||
if [ $? -eq 120 ]; then
|
||||
warn "${_output}"
|
||||
else
|
||||
VALUE=$(echo "${MATCH_LINE}" | sed -E 's/.+= *(.+) *;$/\1/' 2>/dev/null)
|
||||
if [ $? -ne 0 ]; then
|
||||
error_notify "Failed to get value."
|
||||
else
|
||||
echo "${VALUE}"
|
||||
fi
|
||||
echo "${_output}"
|
||||
fi
|
||||
else # Setting the value. -- cwells
|
||||
if [ -n "${VALUE}" ]; then
|
||||
@@ -99,11 +127,40 @@ for _jail in ${JAILS}; do
|
||||
LINE=" ${PROPERTY};"
|
||||
fi
|
||||
|
||||
if [ "${MATCH_FOUND}" -ne 0 ]; then # No match, so insert the property at the end. -- cwells
|
||||
echo "$(awk -v line="${LINE}" '$0 == "}" { print line; } 1 { print $0; }' "${FILE}")" > "${FILE}"
|
||||
else # Replace the existing value. -- cwells
|
||||
sed -i '' -E "s/ *${ESCAPED_PROPERTY}[ =;].*/${LINE}/" "${FILE}"
|
||||
fi
|
||||
# add the value to the config file, replacing any existing value or, if
|
||||
# there is none, at the end
|
||||
#
|
||||
# awk doesn't have "inplace" editing so we use a temp file
|
||||
_tmpfile=$(mktemp) || error_exit "unable to set because mktemp failed"
|
||||
cp "${FILE}" "${_tmpfile}" && \
|
||||
awk -F= -v line="${LINE}" -v property="${PROPERTY}" '
|
||||
BEGIN {
|
||||
# build RE as string as we can not expand vars in RE literals
|
||||
prop_re = "^[[:space:]]*" property "[[:space:]]*$";
|
||||
}
|
||||
$1 ~ prop_re && !found {
|
||||
# we already have an entry in the config for this property so
|
||||
# we need to substitute our line here rather than keep the
|
||||
# existing line
|
||||
print(line);
|
||||
# note we have already found the property
|
||||
found = 1;
|
||||
# move onto the next line
|
||||
next;
|
||||
}
|
||||
$1 == "}" {
|
||||
# reached the end of the stanza so if we have not already
|
||||
# added our line we need to do so now
|
||||
if (! found) {
|
||||
print(line);
|
||||
}
|
||||
}
|
||||
{
|
||||
# print each uninteresting line unchanged
|
||||
print;
|
||||
}
|
||||
' "${_tmpfile}" > "${FILE}"
|
||||
rm "${_tmpfile}"
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -46,6 +46,8 @@ if [ $# -gt 1 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
bastille_root_check
|
||||
|
||||
USER="${1}"
|
||||
|
||||
validate_user() {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -46,6 +46,8 @@ if [ $# -ne 0 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
bastille_root_check
|
||||
|
||||
convert_symlinks() {
|
||||
# Work with the symlinks, revert on first cp error
|
||||
if [ -d "${bastille_releasesdir}/${RELEASE}" ]; then
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -54,6 +54,8 @@ if [ $# -ne 2 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
bastille_root_check
|
||||
|
||||
case "${OPTION}" in
|
||||
-q|--quiet)
|
||||
OPTION="-a"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -69,34 +69,57 @@ validate_name() {
|
||||
}
|
||||
|
||||
validate_ip() {
|
||||
IPX_ADDR="ip4.addr"
|
||||
IP6_MODE="disable"
|
||||
ip6=$(echo "${IP}" | grep -E '^(([a-fA-F0-9:]+$)|([a-fA-F0-9:]+\/[0-9]{1,3}$))')
|
||||
ipx_addr="ip4.addr"
|
||||
ip="$1"
|
||||
ip6=$(echo "${ip}" | grep -E '^(([a-fA-F0-9:]+$)|([a-fA-F0-9:]+\/[0-9]{1,3}$)|SLAAC)')
|
||||
if [ -n "${ip6}" ]; then
|
||||
info "Valid: (${ip6})."
|
||||
IPX_ADDR="ip6.addr"
|
||||
ipx_addr="ip6.addr"
|
||||
IP6_MODE="new"
|
||||
else
|
||||
local IFS
|
||||
if echo "${IP}" | grep -Eq '^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))?$'; then
|
||||
TEST_IP=$(echo "${IP}" | cut -d / -f1)
|
||||
IFS=.
|
||||
set ${TEST_IP}
|
||||
for quad in 1 2 3 4; do
|
||||
if eval [ \$$quad -gt 255 ]; then
|
||||
echo "Invalid: (${TEST_IP})"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
if ifconfig | grep -qw "${TEST_IP}"; then
|
||||
warn "Warning: IP address already in use (${TEST_IP})."
|
||||
else
|
||||
info "Valid: (${IP})."
|
||||
fi
|
||||
if [ "${ip}" = "DHCP" ]; then
|
||||
info "Valid: (${ip})."
|
||||
else
|
||||
error_exit "Invalid: (${IP})."
|
||||
local IFS
|
||||
if echo "${ip}" | grep -Eq '^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))?$'; then
|
||||
TEST_IP=$(echo "${ip}" | cut -d / -f1)
|
||||
IFS=.
|
||||
set ${TEST_IP}
|
||||
for quad in 1 2 3 4; do
|
||||
if eval [ \$$quad -gt 255 ]; then
|
||||
echo "Invalid: (${TEST_IP})"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
if ifconfig | grep -qwF "${TEST_IP}"; then
|
||||
warn "Warning: IP address already in use (${TEST_IP})."
|
||||
else
|
||||
info "Valid: (${ip})."
|
||||
fi
|
||||
else
|
||||
error_exit "Invalid: (${ip})."
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
if echo "${ip}" | grep -qvE '(SLAAC|DHCP|0[.]0[.]0[.]0)'; then
|
||||
if [ "${ipx_addr}" = "ip4.addr" ]; then
|
||||
IP4_ADDR="${ip}"
|
||||
IP4_DEFINITION="${ipx_addr} = ${ip};"
|
||||
else
|
||||
IP6_ADDR="${ip}"
|
||||
IP6_DEFINITION="${ipx_addr} = ${ip};"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
validate_ips() {
|
||||
IP6_MODE="disable"
|
||||
IP4_DEFINITION=""
|
||||
IP6_DEFINITION=""
|
||||
IP4_ADDR=""
|
||||
IP6_ADDR=""
|
||||
for ip in ${IP}; do
|
||||
validate_ip "${ip}"
|
||||
done
|
||||
}
|
||||
|
||||
validate_netif() {
|
||||
@@ -157,7 +180,8 @@ ${NAME} {
|
||||
securelevel = 2;
|
||||
|
||||
interface = ${bastille_jail_conf_interface};
|
||||
${IPX_ADDR} = ${IP};
|
||||
${IP4_DEFINITION}
|
||||
${IP6_DEFINITION}
|
||||
ip6 = ${IP6_MODE};
|
||||
}
|
||||
EOF
|
||||
@@ -170,6 +194,7 @@ ${NAME} {
|
||||
mount.fstab = ${bastille_jail_fstab};
|
||||
path = ${bastille_jail_path};
|
||||
devfs_ruleset = 4;
|
||||
enforce_statfs = 1;
|
||||
|
||||
exec.start = '/bin/true';
|
||||
exec.stop = '/bin/true';
|
||||
@@ -179,7 +204,7 @@ ${NAME} {
|
||||
allow.mount.devfs;
|
||||
|
||||
interface = ${bastille_jail_conf_interface};
|
||||
${IPX_ADDR} = ${IP};
|
||||
${ipx_addr} = ${IP};
|
||||
ip6 = ${IP6_MODE};
|
||||
}
|
||||
EOF
|
||||
@@ -478,25 +503,44 @@ create_jail() {
|
||||
|
||||
_gateway=''
|
||||
_gateway6=''
|
||||
_ifconfig=SYNCDHCP
|
||||
if [ "${IP}" != "0.0.0.0" ]; then # not using DHCP, so set static address.
|
||||
if [ -n "${ip6}" ]; then
|
||||
_ifconfig="inet6 ${IP}"
|
||||
else
|
||||
_ifconfig="inet ${IP}"
|
||||
fi
|
||||
_ifconfig_inet=''
|
||||
_ifconfig_inet6=''
|
||||
if echo "${IP}" | grep -qE '(0[.]0[.]0[.]0|DHCP)'; then
|
||||
# Enable DHCP if requested
|
||||
_ifconfig_inet=SYNCDHCP
|
||||
else
|
||||
# Else apply the default gateway
|
||||
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}')"
|
||||
_gateway="$(netstat -rn | awk '/default/ {print $2}')"
|
||||
fi
|
||||
fi
|
||||
# Add IPv4 address (this is empty if DHCP is used)
|
||||
if [ -n "${IP4_ADDR}" ]; then
|
||||
_ifconfig_inet="${_ifconfig_inet} inet ${IP4_ADDR}"
|
||||
fi
|
||||
# Enable IPv6 if used
|
||||
if [ "${IP6_MODE}" != "disable" ]; then
|
||||
_ifconfig_inet6='inet6 -ifdisabled'
|
||||
if echo "${IP}" | grep -qE 'SLAAC'; then
|
||||
# Enable SLAAC if requested
|
||||
_ifconfig_inet6="${_ifconfig_inet6} accept_rtadv"
|
||||
else
|
||||
# Else apply the default gateway
|
||||
if [ -n "${bastille_network_gateway6}" ]; then
|
||||
_gateway6="${bastille_network_gateway6}"
|
||||
else
|
||||
_gateway="$(netstat -6rn | awk '/default/ {print $2}')"
|
||||
_gateway6="$(netstat -6rn | awk '/default/ {print $2}')"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
# Add IPv6 address (this is empty if SLAAC is used)
|
||||
if [ -n "${IP6_ADDR}" ]; then
|
||||
_ifconfig_inet6="${_ifconfig_inet6} ${IP6_ADDR}"
|
||||
fi
|
||||
# Join together IPv4 and IPv6 parts of ifconfig
|
||||
_ifconfig="${_ifconfig_inet} ${_ifconfig_inet6}"
|
||||
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
|
||||
@@ -544,6 +588,8 @@ help|-h|--help)
|
||||
;;
|
||||
esac
|
||||
|
||||
bastille_root_check
|
||||
|
||||
if echo "$3" | grep '@'; then
|
||||
BASTILLE_JAIL_IP=$(echo "$3" | awk -F@ '{print $2}')
|
||||
BASTILLE_JAIL_INTERFACES=$( echo "$3" | awk -F@ '{print $1}')
|
||||
@@ -637,9 +683,9 @@ if [ -n "${LINUX_JAIL}" ]; then
|
||||
## check for FreeBSD releases name
|
||||
NAME_VERIFY=ubuntu_focal
|
||||
;;
|
||||
debian_stretch|stretch|debian-stretch)
|
||||
jammy|ubuntu_jammy|ubuntu-jammy)
|
||||
## check for FreeBSD releases name
|
||||
NAME_VERIFY=stretch
|
||||
NAME_VERIFY=ubuntu_jammy
|
||||
;;
|
||||
debian_buster|buster|debian-buster)
|
||||
## check for FreeBSD releases name
|
||||
@@ -649,6 +695,10 @@ if [ -n "${LINUX_JAIL}" ]; then
|
||||
## check for FreeBSD releases name
|
||||
NAME_VERIFY=bullseye
|
||||
;;
|
||||
debian_bookworm|bookworm|debian-bookworm)
|
||||
## check for FreeBSD releases name
|
||||
NAME_VERIFY=bookworm
|
||||
;;
|
||||
*)
|
||||
error_notify "Unknown Linux."
|
||||
usage
|
||||
@@ -709,8 +759,9 @@ if [ -z "${EMPTY_JAIL}" ]; then
|
||||
NAME_VERIFY=Ubuntu_2004
|
||||
validate_release
|
||||
;;
|
||||
debian_stretch|stretch|debian-stretch)
|
||||
NAME_VERIFY=Debian9
|
||||
ubuntu_jammy|jammy|ubuntu-jammy)
|
||||
UBUNTU="1"
|
||||
NAME_VERIFY=Ubuntu_2204
|
||||
validate_release
|
||||
;;
|
||||
debian_buster|buster|debian-buster)
|
||||
@@ -721,6 +772,10 @@ if [ -z "${EMPTY_JAIL}" ]; then
|
||||
NAME_VERIFY=Debian11
|
||||
validate_release
|
||||
;;
|
||||
debian_bookworm|bookworm|debian-bookworm)
|
||||
NAME_VERIFY=Debian12
|
||||
validate_release
|
||||
;;
|
||||
*)
|
||||
error_notify "Unknown Release."
|
||||
usage
|
||||
@@ -739,7 +794,7 @@ if [ -z "${EMPTY_JAIL}" ]; then
|
||||
|
||||
## check if ip address is valid
|
||||
if [ -n "${IP}" ]; then
|
||||
validate_ip
|
||||
validate_ips
|
||||
else
|
||||
usage
|
||||
fi
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -210,6 +210,8 @@ if [ $# -gt 1 ] || [ $# -lt 1 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
bastille_root_check
|
||||
|
||||
## check what should we clean
|
||||
case "${TARGET}" in
|
||||
*-CURRENT|*-CURRENT-I386|*-CURRENT-i386|*-current)
|
||||
@@ -247,14 +249,14 @@ current-build-latest|current-BUILD-LATEST|CURRENT-BUILD-LATEST)
|
||||
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)
|
||||
Ubuntu_1804|Ubuntu_2004|Ubuntu_2204|UBUNTU_1804|UBUNTU_2004|UBUNTU_2204)
|
||||
## check for Linux releases
|
||||
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '(Ubuntu_1804)$|(Ubuntu_2004)$' | sed 's/UBUNTU/Ubuntu/g;s/ubuntu/Ubuntu/g')
|
||||
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '(Ubuntu_1804)$|(Ubuntu_2004)$|(Ubuntu_2204)$' | sed 's/UBUNTU/Ubuntu/g;s/ubuntu/Ubuntu/g')
|
||||
destroy_rel
|
||||
;;
|
||||
Debian9|Debian10|Debian11|DEBIAN9|DEBIAN10|DEBIAN11)
|
||||
Debian10|Debian11|Debian12|DEBIAN10|DEBIAN11|DEBIAN12)
|
||||
## check for Linux releases
|
||||
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '(Debian9)$|(Debian10)$|(Debian11)$' | sed 's/DEBIAN/Debian/g')
|
||||
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '(Debian10)$|(Debian11)$|(Debian12)$' | sed 's/DEBIAN/Debian/g')
|
||||
destroy_rel
|
||||
;;
|
||||
*)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -48,6 +48,8 @@ elif [ $# -eq 1 ]; then
|
||||
TARGET_FILENAME="${1}"
|
||||
fi
|
||||
|
||||
bastille_root_check
|
||||
|
||||
if [ -z "${EDITOR}" ]; then
|
||||
EDITOR=vi
|
||||
fi
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -71,6 +71,8 @@ if [ $# -gt 5 ] || [ $# -lt 1 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
bastille_root_check
|
||||
|
||||
zfs_enable_check() {
|
||||
# Temporarily disable ZFS so we can create a standard backup archive
|
||||
if [ "${bastille_zfs_enable}" = "YES" ]; then
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -46,6 +46,8 @@ if [ $# -ne 0 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
bastille_root_check
|
||||
|
||||
for _jail in ${JAILS}; do
|
||||
bastille_jail_path=$(/usr/sbin/jls -j "${_jail}" path)
|
||||
if [ ! -x "${bastille_jail_path}/usr/local/bin/htop" ]; then
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -59,6 +59,8 @@ if [ $# -gt 3 ] || [ $# -lt 1 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
bastille_root_check
|
||||
|
||||
TARGET="${1}"
|
||||
OPT_FORCE=
|
||||
USER_IMPORT=
|
||||
@@ -150,6 +152,11 @@ update_jailconf() {
|
||||
sed -i '' "s|path.*=.*;|path = ${bastille_jailsdir}/${TARGET_TRIM}/root;|" "${JAIL_CONFIG}"
|
||||
sed -i '' "s|mount.fstab.*=.*;|mount.fstab = ${bastille_jailsdir}/${TARGET_TRIM}/fstab;|" "${JAIL_CONFIG}"
|
||||
fi
|
||||
|
||||
# Check for the jib script
|
||||
if grep -qw "vnet" "${JAIL_CONFIG}"; then
|
||||
vnet_requirements
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -207,6 +214,7 @@ generate_config() {
|
||||
# See if we need to generate a vnet network section
|
||||
if [ "${IS_VNET_JAIL:-0}" = "1" ]; then
|
||||
NETBLOCK=$(generate_vnet_jail_netblock "${TARGET_TRIM}" "" "${VNET_DEFAULT_INTERFACE}")
|
||||
vnet_requirements
|
||||
else
|
||||
# If there are multiple IP/NIC let the user configure network
|
||||
if [ -n "${IPV4_CONFIG}" ]; then
|
||||
@@ -333,6 +341,17 @@ workout_components() {
|
||||
fi
|
||||
}
|
||||
|
||||
vnet_requirements() {
|
||||
# VNET jib script requirement
|
||||
if [ ! "$(command -v jib)" ]; then
|
||||
if [ -f "/usr/share/examples/jails/jib" ] && [ ! -f "/usr/local/bin/jib" ]; then
|
||||
install -m 0544 /usr/share/examples/jails/jib /usr/local/bin/jib
|
||||
else
|
||||
warn "Warning: Unable to locate/install jib script required by VNET jails."
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
config_netif() {
|
||||
# Get interface from bastille configuration
|
||||
if [ -n "${bastille_network_loopback}" ]; then
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
# Ressource limits added by Sven R github.com/hackacad
|
||||
#
|
||||
@@ -55,6 +55,8 @@ if [ $# -ne 2 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
bastille_root_check
|
||||
|
||||
OPTION="${1}"
|
||||
VALUE="${2}"
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -35,106 +35,114 @@ usage() {
|
||||
error_exit "Usage: bastille list [-j|-a] [release [-p]|template|(jail|container)|log|limit|(import|export|backup)]"
|
||||
}
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
/usr/sbin/jls -N
|
||||
if [ "${1}" = help -o "${1}" = "-h" -o "${1}" = "--help" ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
if [ "$1" == "-j" ]; then
|
||||
bastille_root_check
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
/usr/sbin/jls
|
||||
fi
|
||||
|
||||
if [ "${1}" == "-j" ]; then
|
||||
/usr/sbin/jls -N --libxo json
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ $# -gt 0 ]; then
|
||||
# Handle special-case commands first.
|
||||
case "$1" in
|
||||
help|-h|--help)
|
||||
usage
|
||||
;;
|
||||
all|-a|--all)
|
||||
TARGET=
|
||||
|
||||
list_all(){
|
||||
if [ -d "${bastille_jailsdir}" ]; then
|
||||
DEFAULT_VALUE="-"
|
||||
SPACER=2
|
||||
MAX_LENGTH_JAIL_NAME=$(find ""${bastille_jailsdir}/*/jail.conf"" -maxdepth 1 -type f -print0 2> /dev/null | xargs -r0 -P0 grep -h -m 1 -e "^.* {$" | awk '{ print length($1) }' | sort -nr | head -n 1)
|
||||
MAX_LENGTH_JAIL_NAME=${MAX_LENGTH_JAIL_NAME:-3}
|
||||
if [ ${MAX_LENGTH_JAIL_NAME} -lt 3 ]; then MAX_LENGTH_JAIL_NAME=3; fi
|
||||
if [ "${MAX_LENGTH_JAIL_NAME}" -lt 3 ]; then MAX_LENGTH_JAIL_NAME=3; fi
|
||||
MAX_LENGTH_JAIL_IP=$(find ""${bastille_jailsdir}/*/jail.conf"" -maxdepth 1 -type f -print0 2> /dev/null | xargs -r0 -P0 sed -n "s/^[ ]*ip[4,6].addr[ ]*=[ ]*\(.*\);$/\1 /p" | sed 's/\// /g' | awk '{ print length($1) }' | sort -nr | head -n 1)
|
||||
MAX_LENGTH_JAIL_IP=${MAX_LENGTH_JAIL_IP:-10}
|
||||
MAX_LENGTH_JAIL_VNET_IP=$(find ""${bastille_jailsdir}/*/jail.conf"" -maxdepth 1 -type f -print0 2> /dev/null | xargs -r0 -P0 grep -l "vnet;" | grep -h "ifconfig_vnet0=" $(sed -n "s/\(.*\)jail.conf$/\1root\/etc\/rc.conf/p") | sed -n "s/^ifconfig_vnet0=\"\(.*\)\"$/\1/p"| sed "s/\// /g" | awk '{ if ($1 ~ /^[inet|inet6]/) print length($2); else print 15 }' | sort -nr | head -n 1)
|
||||
MAX_LENGTH_JAIL_VNET_IP=${MAX_LENGTH_JAIL_VNET_IP:-10}
|
||||
if [ ${MAX_LENGTH_JAIL_VNET_IP} -gt ${MAX_LENGTH_JAIL_IP} ]; then MAX_LENGTH_JAIL_IP=${MAX_LENGTH_JAIL_VNET_IP}; fi
|
||||
if [ ${MAX_LENGTH_JAIL_IP} -lt 10 ]; then MAX_LENGTH_JAIL_IP=10; fi
|
||||
if [ "${MAX_LENGTH_JAIL_VNET_IP}" -gt "${MAX_LENGTH_JAIL_IP}" ]; then MAX_LENGTH_JAIL_IP=${MAX_LENGTH_JAIL_VNET_IP}; fi
|
||||
if [ "${MAX_LENGTH_JAIL_IP}" -lt 10 ]; then MAX_LENGTH_JAIL_IP=10; fi
|
||||
MAX_LENGTH_JAIL_HOSTNAME=$(find ""${bastille_jailsdir}/*/jail.conf"" -maxdepth 1 -type f -print0 2> /dev/null | xargs -r0 -P0 grep -h -m 1 -e "^[ ]*host.hostname[ ]*=[ ]*\(.*\);" | awk '{ print length(substr($3, 1, length($3)-1)) }' | sort -nr | head -n 1)
|
||||
MAX_LENGTH_JAIL_HOSTNAME=${MAX_LENGTH_JAIL_HOSTNAME:-8}
|
||||
if [ ${MAX_LENGTH_JAIL_HOSTNAME} -lt 8 ]; then MAX_LENGTH_JAIL_HOSTNAME=8; fi
|
||||
if [ "${MAX_LENGTH_JAIL_HOSTNAME}" -lt 8 ]; then MAX_LENGTH_JAIL_HOSTNAME=8; fi
|
||||
MAX_LENGTH_JAIL_PORTS=$(find ""${bastille_jailsdir}/*/rdr.conf"" -maxdepth 1 -type f -print0 2> /dev/null | xargs -r0 -P0 -n1 awk '{ lines++; chars += length($0)} END { chars += lines - 1; print chars }' | sort -nr | head -n 1)
|
||||
MAX_LENGTH_JAIL_PORTS=${MAX_LENGTH_JAIL_PORTS:-15}
|
||||
if [ ${MAX_LENGTH_JAIL_PORTS} -lt 15 ]; then MAX_LENGTH_JAIL_PORTS=15; fi
|
||||
if [ ${MAX_LENGTH_JAIL_PORTS} -gt 30 ]; then MAX_LENGTH_JAIL_PORTS=30; fi
|
||||
if [ "${MAX_LENGTH_JAIL_PORTS}" -lt 15 ]; then MAX_LENGTH_JAIL_PORTS=15; fi
|
||||
if [ "${MAX_LENGTH_JAIL_PORTS}" -gt 30 ]; then MAX_LENGTH_JAIL_PORTS=30; fi
|
||||
MAX_LENGTH_JAIL_RELEASE=$(find ""${bastille_jailsdir}/*/fstab"" -maxdepth 1 -type f -print0 2> /dev/null | xargs -r0 -P0 grep -h "/releases/.*/root/.bastille.*nullfs" | grep -hE "^USERLAND_VERSION=" $(sed -n "s/^\(.*\) \/.*$/\1\/bin\/freebsd-version/p" | awk '!_[$0]++') | sed "s/[\"\'\^]//g;s/ .*$//g" | sed -n "s/^USERLAND_VERSION=\(.*\)$/\1/p" | awk '{ print length($0) }' | sort -nr | head -n 1)
|
||||
MAX_LENGTH_JAIL_RELEASE=${MAX_LENGTH_JAIL_RELEASE:-7}
|
||||
MAX_LENGTH_THICK_JAIL_RELEASE=$(find ""${bastille_jailsdir}/*/root/bin/freebsd-version"" -maxdepth 1 -type f -print0 2> /dev/null | xargs -r0 -P0 grep -hE "^USERLAND_VERSION=" | sed "s/[\"\'\^]//g;s/ .*$//g" | sed -n "s/^USERLAND_VERSION=\(.*\)$/\1/p" | awk '{ print length($0) }' | sort -nr | head -n 1)
|
||||
MAX_LENGTH_THICK_JAIL_RELEASE=${MAX_LENGTH_THICK_JAIL_RELEASE:-7}
|
||||
MAX_LENGTH_LINUX_JAIL_RELEASE=$(find ""${bastille_jailsdir}/*/fstab"" -maxdepth 1 -type f -print0 2> /dev/null | xargs -r0 -P0 grep -h "/jails/.*/root/proc.*linprocfs" | grep -hE "^NAME=|^VERSION_ID=|^VERSION_CODENAME=" $(sed -n "s/^linprocfs *\(.*\)\/.*$/\1\/etc\/os-release/p") 2> /dev/null | sed "s/\"//g" | sed "s/ GNU\/Linux//g" | sed "N;N;s/\n/;/g" | sed -n "s/^NAME=\(.*\);VERSION_ID=\(.*\);VERSION_CODENAME=\(.*\)$/\1 \2 (\3)/p" | awk '{ print length($0) }' | sort -nr | head -n 1)
|
||||
MAX_LENGTH_LINUX_JAIL_RELEASE=${MAX_LENGTH_LINUX_JAIL_RELEASE:-7}
|
||||
if [ ${MAX_LENGTH_THICK_JAIL_RELEASE} -gt ${MAX_LENGTH_JAIL_RELEASE} ]; then MAX_LENGTH_JAIL_RELEASE=${MAX_LENGTH_THICK_JAIL_RELEASE}; fi
|
||||
if [ ${MAX_LENGTH_LINUX_JAIL_RELEASE} -gt ${MAX_LENGTH_JAIL_RELEASE} ]; then MAX_LENGTH_JAIL_RELEASE=${MAX_LENGTH_LINUX_JAIL_RELEASE}; fi
|
||||
if [ ${MAX_LENGTH_JAIL_RELEASE} -lt 7 ]; then MAX_LENGTH_JAIL_RELEASE=7; fi
|
||||
if [ "${MAX_LENGTH_THICK_JAIL_RELEASE}" -gt "${MAX_LENGTH_JAIL_RELEASE}" ]; then MAX_LENGTH_JAIL_RELEASE=${MAX_LENGTH_THICK_JAIL_RELEASE}; fi
|
||||
if [ "${MAX_LENGTH_LINUX_JAIL_RELEASE}" -gt "${MAX_LENGTH_JAIL_RELEASE}" ]; then MAX_LENGTH_JAIL_RELEASE=${MAX_LENGTH_LINUX_JAIL_RELEASE}; fi
|
||||
if [ "${MAX_LENGTH_JAIL_RELEASE}" -lt 7 ]; then MAX_LENGTH_JAIL_RELEASE=7; fi
|
||||
printf " JID%*sState%*sIP Address%*sPublished Ports%*sHostname%*sRelease%*sPath\n" "$((${MAX_LENGTH_JAIL_NAME} + ${SPACER} - 3))" "" "$((${SPACER}))" "" "$((${MAX_LENGTH_JAIL_IP} + ${SPACER} - 10))" "" "$((${MAX_LENGTH_JAIL_PORTS} + ${SPACER} - 15))" "" "$((${MAX_LENGTH_JAIL_HOSTNAME} + ${SPACER} - 8))" "" "$((${MAX_LENGTH_JAIL_RELEASE} + ${SPACER} - 7))" ""
|
||||
JAIL_LIST=$(ls "${bastille_jailsdir}" | sed "s/\n//g")
|
||||
if [ -n "${TARGET}" ]; then
|
||||
# Query all info for a specific jail.
|
||||
JAIL_LIST="${TARGET}"
|
||||
else
|
||||
# Query all info for all jails(default).
|
||||
JAIL_LIST=$(ls "${bastille_jailsdir}" | sed "s/\n//g")
|
||||
fi
|
||||
for _JAIL in ${JAIL_LIST}; do
|
||||
if [ -f "${bastille_jailsdir}/${_JAIL}/jail.conf" ]; then
|
||||
JAIL_NAME=$(grep -h -m 1 -e "^.* {$" "${bastille_jailsdir}/${_JAIL}/jail.conf" 2> /dev/null | awk '{ print $1 }')
|
||||
IS_FREEBSD_JAIL=0
|
||||
if [ -f "${bastille_jailsdir}/${JAIL_NAME}/root/bin/freebsd-version" -o -f "${bastille_jailsdir}/${JAIL_NAME}/root/.bastille/bin/freebsd-version" -o "$(grep -c "/releases/.*/root/.bastille.*nullfs" "${bastille_jailsdir}/${JAIL_NAME}/fstab" 2> /dev/null)" -gt 0 ]; then IS_FREEBSD_JAIL=1; fi
|
||||
IS_FREEBSD_JAIL=${IS_FREEBSD_JAIL:-0}
|
||||
IS_LINUX_JAIL=0
|
||||
if [ "$(grep -c "^linprocfs" "${bastille_jailsdir}/${JAIL_NAME}/fstab" 2> /dev/null)" -gt 0 ]; then IS_LINUX_JAIL=1; fi
|
||||
IS_LINUX_JAIL=${IS_LINUX_JAIL:-0}
|
||||
if [ "$(/usr/sbin/jls name | awk "/^${JAIL_NAME}$/")" ]; then
|
||||
JAIL_STATE="Up"
|
||||
if [ "$(awk '$1 == "vnet;" { print $1 }' "${bastille_jailsdir}/${JAIL_NAME}/jail.conf" 2> /dev/null)" ]; then
|
||||
JAIL_IP=$(jexec -l ${JAIL_NAME} ifconfig -n vnet0 inet 2> /dev/null | sed -n "/.inet /{s///;s/ .*//;p;}")
|
||||
if [ ! ${JAIL_IP} ]; then JAIL_IP=$(jexec -l ${JAIL_NAME} ifconfig -n vnet0 inet6 2> /dev/null | awk '/inet6 / && (!/fe80::/ || !/%vnet0/)' | sed -n "/.inet6 /{s///;s/ .*//;p;}"); fi
|
||||
else
|
||||
JAIL_IP=$(/usr/sbin/jls -j ${JAIL_NAME} ip4.addr 2> /dev/null)
|
||||
if [ ${JAIL_IP} = "-" ]; then JAIL_IP=$(/usr/sbin/jls -j ${JAIL_NAME} ip6.addr 2> /dev/null); fi
|
||||
fi
|
||||
JAIL_HOSTNAME=$(/usr/sbin/jls -j ${JAIL_NAME} host.hostname 2> /dev/null)
|
||||
JAIL_PORTS=$(pfctl -a "rdr/${JAIL_NAME}" -Psn 2> /dev/null | awk '{ printf "%s/%s:%s"",",$7,$14,$18 }' | sed "s/,$//")
|
||||
JAIL_PATH=$(/usr/sbin/jls -j ${JAIL_NAME} path 2> /dev/null)
|
||||
if [ ${IS_FREEBSD_JAIL} -eq 1 ]; then
|
||||
JAIL_RELEASE=$(jexec -l ${JAIL_NAME} freebsd-version -u 2> /dev/null)
|
||||
fi
|
||||
if [ ${IS_LINUX_JAIL} -eq 1 ]; then
|
||||
JAIL_RELEASE=$(grep -hE "^NAME=.*$|^VERSION_ID=.*$|^VERSION_CODENAME=.*$" "${JAIL_PATH}/etc/os-release" 2> /dev/null | sed "s/\"//g" | sed "s/ GNU\/Linux//g" | awk -F'=' '{ a[$1] = $2; o++ } o%3 == 0 { print a["VERSION_CODENAME"] " (" a["NAME"] " " a["VERSION_ID"] ")" }')
|
||||
fi
|
||||
JAIL_NAME=$(grep -h -m 1 -e "^.* {$" "${bastille_jailsdir}/${_JAIL}/jail.conf" 2> /dev/null | awk '{ print $1 }')
|
||||
IS_FREEBSD_JAIL=0
|
||||
if [ -f "${bastille_jailsdir}/${JAIL_NAME}/root/bin/freebsd-version" -o -f "${bastille_jailsdir}/${JAIL_NAME}/root/.bastille/bin/freebsd-version" -o "$(grep -c "/releases/.*/root/.bastille.*nullfs" "${bastille_jailsdir}/${JAIL_NAME}/fstab" 2> /dev/null)" -gt 0 ]; then IS_FREEBSD_JAIL=1; fi
|
||||
IS_FREEBSD_JAIL=${IS_FREEBSD_JAIL:-0}
|
||||
IS_LINUX_JAIL=0
|
||||
if [ "$(grep -c "^linprocfs" "${bastille_jailsdir}/${JAIL_NAME}/fstab" 2> /dev/null)" -gt 0 ]; then IS_LINUX_JAIL=1; fi
|
||||
IS_LINUX_JAIL=${IS_LINUX_JAIL:-0}
|
||||
if [ "$(/usr/sbin/jls name | awk "/^${JAIL_NAME}$/")" ]; then
|
||||
JAIL_STATE="Up"
|
||||
if [ "$(awk '$1 == "vnet;" { print $1 }' "${bastille_jailsdir}/${JAIL_NAME}/jail.conf" 2> /dev/null)" ]; then
|
||||
JAIL_IP=$(jexec -l ${JAIL_NAME} ifconfig -n vnet0 inet 2> /dev/null | sed -n "/.inet /{s///;s/ .*//;p;}")
|
||||
if [ ! "${JAIL_IP}" ]; then JAIL_IP=$(jexec -l ${JAIL_NAME} ifconfig -n vnet0 inet6 2> /dev/null | awk '/inet6 / && (!/fe80::/ || !/%vnet0/)' | sed -n "/.inet6 /{s///;s/ .*//;p;}"); fi
|
||||
else
|
||||
JAIL_STATE=$(if [ "$(sed -n "/^${JAIL_NAME} {$/,/^}$/p" "${bastille_jailsdir}/${JAIL_NAME}/jail.conf" 2> /dev/null | awk '$0 ~ /^'${JAIL_NAME}' \{|\}/ { printf "%s",$0 }')" == "${JAIL_NAME} {}" ]; then echo "Down"; else echo "n/a"; fi)
|
||||
if [ "$(awk '$1 == "vnet;" { print $1 }' "${bastille_jailsdir}/${JAIL_NAME}/jail.conf" 2> /dev/null)" ]; then
|
||||
JAIL_IP=$(sed -n 's/^ifconfig_vnet0="\(.*\)"$/\1/p' "${bastille_jailsdir}/${JAIL_NAME}/root/etc/rc.conf" 2> /dev/null | sed "s/\// /g" | awk '{ if ($1 ~ /^[inet|inet6]/) print $2; else print $1 }')
|
||||
else
|
||||
JAIL_IP=$(sed -n "s/^[ ]*ip[4,6].addr[ ]*=[ ]*\(.*\);$/\1/p" "${bastille_jailsdir}/${JAIL_NAME}/jail.conf" 2> /dev/null | sed "s/\// /g" | awk '{ print $1 }')
|
||||
JAIL_IP=$(/usr/sbin/jls -j ${JAIL_NAME} ip4.addr 2> /dev/null)
|
||||
if [ "${JAIL_IP}" = "-" ]; then JAIL_IP=$(/usr/sbin/jls -j ${JAIL_NAME} ip6.addr 2> /dev/null); fi
|
||||
fi
|
||||
JAIL_HOSTNAME=$(/usr/sbin/jls -j ${JAIL_NAME} host.hostname 2> /dev/null)
|
||||
JAIL_PORTS=$(pfctl -a "rdr/${JAIL_NAME}" -Psn 2> /dev/null | awk '{ printf "%s/%s:%s"",",$7,$14,$18 }' | sed "s/,$//")
|
||||
JAIL_PATH=$(/usr/sbin/jls -j ${JAIL_NAME} path 2> /dev/null)
|
||||
if [ "${IS_FREEBSD_JAIL}" -eq 1 ]; then
|
||||
JAIL_RELEASE=$(jexec -l ${JAIL_NAME} freebsd-version -u 2> /dev/null)
|
||||
fi
|
||||
if [ "${IS_LINUX_JAIL}" -eq 1 ]; then
|
||||
JAIL_RELEASE=$(grep -hE "^NAME=.*$|^VERSION_ID=.*$|^VERSION_CODENAME=.*$" "${JAIL_PATH}/etc/os-release" 2> /dev/null | sed "s/\"//g" | sed "s/ GNU\/Linux//g" | awk -F'=' '{ a[$1] = $2; o++ } o%3 == 0 { print a["VERSION_CODENAME"] " (" a["NAME"] " " a["VERSION_ID"] ")" }')
|
||||
fi
|
||||
else
|
||||
JAIL_STATE=$(if [ "$(sed -n "/^${JAIL_NAME} {$/,/^}$/p" "${bastille_jailsdir}/${JAIL_NAME}/jail.conf" 2> /dev/null | awk '$0 ~ /^'${JAIL_NAME}' \{|\}/ { printf "%s",$0 }')" == "${JAIL_NAME} {}" ]; then echo "Down"; else echo "n/a"; fi)
|
||||
if [ "$(awk '$1 == "vnet;" { print $1 }' "${bastille_jailsdir}/${JAIL_NAME}/jail.conf" 2> /dev/null)" ]; then
|
||||
JAIL_IP=$(sed -n 's/^ifconfig_vnet0="\(.*\)"$/\1/p' "${bastille_jailsdir}/${JAIL_NAME}/root/etc/rc.conf" 2> /dev/null | sed "s/\// /g" | awk '{ if ($1 ~ /^[inet|inet6]/) print $2; else print $1 }')
|
||||
else
|
||||
JAIL_IP=$(sed -n "s/^[ ]*ip[4,6].addr[ ]*=[ ]*\(.*\);$/\1/p" "${bastille_jailsdir}/${JAIL_NAME}/jail.conf" 2> /dev/null | sed "s/\// /g" | awk '{ print $1 }')
|
||||
fi
|
||||
JAIL_HOSTNAME=$(sed -n "s/^[ ]*host.hostname[ ]*=[ ]*\(.*\);$/\1/p" "${bastille_jailsdir}/${JAIL_NAME}/jail.conf" 2> /dev/null)
|
||||
if [ -f "${bastille_jailsdir}/${JAIL_NAME}/rdr.conf" ]; then JAIL_PORTS=$(awk '$1 ~ /^[tcp|udp]/ { printf "%s/%s:%s,",$1,$2,$3 }' "${bastille_jailsdir}/${JAIL_NAME}/rdr.conf" 2> /dev/null | sed "s/,$//"); else JAIL_PORTS=""; fi
|
||||
JAIL_PATH=$(sed -n "s/^[ ]*path[ ]*=[ ]*\(.*\);$/\1/p" "${bastille_jailsdir}/${JAIL_NAME}/jail.conf" 2> /dev/null)
|
||||
if [ "${JAIL_PATH}" ]; then
|
||||
if [ "${IS_FREEBSD_JAIL}" -eq 1 ]; then
|
||||
if [ -f "${JAIL_PATH}/bin/freebsd-version" ]; then
|
||||
JAIL_RELEASE=$(grep -hE "^USERLAND_VERSION=" "${JAIL_PATH}/bin/freebsd-version" 2> /dev/null | sed "s/[\"\'\^]//g;s/ .*$//g" | sed -n "s/^USERLAND_VERSION=\(.*\)$/\1/p")
|
||||
else
|
||||
JAIL_RELEASE=$(grep -h "/releases/.*/root/.bastille.*nullfs" "${bastille_jailsdir}/${JAIL_NAME}/fstab" 2> /dev/null | grep -hE "^USERLAND_VERSION=" $(sed -n "s/^\(.*\) \/.*$/\1\/bin\/freebsd-version/p" | awk '!_[$0]++') | sed "s/[\"\'\^]//g;s/ .*$//g" | sed -n "s/^USERLAND_VERSION=\(.*\)$/\1/p")
|
||||
fi
|
||||
fi
|
||||
JAIL_HOSTNAME=$(sed -n "s/^[ ]*host.hostname[ ]*=[ ]*\(.*\);$/\1/p" "${bastille_jailsdir}/${JAIL_NAME}/jail.conf" 2> /dev/null)
|
||||
if [ -f "${bastille_jailsdir}/${JAIL_NAME}/rdr.conf" ]; then JAIL_PORTS=$(awk '$1 ~ /^[tcp|udp]/ { printf "%s/%s:%s,",$1,$2,$3 }' "${bastille_jailsdir}/${JAIL_NAME}/rdr.conf" 2> /dev/null | sed "s/,$//"); else JAIL_PORTS=""; fi
|
||||
JAIL_PATH=$(sed -n "s/^[ ]*path[ ]*=[ ]*\(.*\);$/\1/p" "${bastille_jailsdir}/${JAIL_NAME}/jail.conf" 2> /dev/null)
|
||||
if [ ${JAIL_PATH} ]; then
|
||||
if [ ${IS_FREEBSD_JAIL} -eq 1 ]; then
|
||||
if [ -f "${JAIL_PATH}/bin/freebsd-version" ]; then
|
||||
JAIL_RELEASE=$(grep -hE "^USERLAND_VERSION=" "${JAIL_PATH}/bin/freebsd-version" 2> /dev/null | sed "s/[\"\'\^]//g;s/ .*$//g" | sed -n "s/^USERLAND_VERSION=\(.*\)$/\1/p")
|
||||
else
|
||||
JAIL_RELEASE=$(grep -h "/releases/.*/root/.bastille.*nullfs" "${bastille_jailsdir}/${JAIL_NAME}/fstab" 2> /dev/null | grep -hE "^USERLAND_VERSION=" $(sed -n "s/^\(.*\) \/.*$/\1\/bin\/freebsd-version/p" | awk '!_[$0]++') | sed "s/[\"\'\^]//g;s/ .*$//g" | sed -n "s/^USERLAND_VERSION=\(.*\)$/\1/p")
|
||||
fi
|
||||
fi
|
||||
if [ ${IS_LINUX_JAIL} -eq 1 ]; then
|
||||
JAIL_RELEASE=$(grep -hE "^NAME=.*$|^VERSION_ID=.*$|^VERSION_CODENAME=.*$" "${JAIL_PATH}/etc/os-release" 2> /dev/null | sed "s/\"//g" | sed "s/ GNU\/Linux//g" | awk -F'=' '{ a[$1] = $2; o++ } o%3 == 0 { print a["VERSION_CODENAME"] " (" a["NAME"] " " a["VERSION_ID"] ")" }')
|
||||
fi
|
||||
else
|
||||
JAIL_RELEASE=""
|
||||
if [ "${IS_LINUX_JAIL}" -eq 1 ]; then
|
||||
JAIL_RELEASE=$(grep -hE "^NAME=.*$|^VERSION_ID=.*$|^VERSION_CODENAME=.*$" "${JAIL_PATH}/etc/os-release" 2> /dev/null | sed "s/\"//g" | sed "s/ GNU\/Linux//g" | awk -F'=' '{ a[$1] = $2; o++ } o%3 == 0 { print a["VERSION_CODENAME"] " (" a["NAME"] " " a["VERSION_ID"] ")" }')
|
||||
fi
|
||||
else
|
||||
JAIL_RELEASE=""
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ${#JAIL_PORTS} -gt ${MAX_LENGTH_JAIL_PORTS} ]; then JAIL_PORTS="$(echo ${JAIL_PORTS} | cut -c-$((${MAX_LENGTH_JAIL_PORTS} - 3)))..."; fi
|
||||
if [ "${#JAIL_PORTS}" -gt "${MAX_LENGTH_JAIL_PORTS}" ]; then JAIL_PORTS="$(echo ${JAIL_PORTS} | cut -c-$((${MAX_LENGTH_JAIL_PORTS} - 3)))..."; fi
|
||||
JAIL_NAME=${JAIL_NAME:-${DEFAULT_VALUE}}
|
||||
JAIL_STATE=${JAIL_STATE:-${DEFAULT_VALUE}}
|
||||
JAIL_IP=${JAIL_IP:-${DEFAULT_VALUE}}
|
||||
@@ -148,48 +156,85 @@ if [ $# -gt 0 ]; then
|
||||
else
|
||||
error_exit "unfortunately there are no jails here (${bastille_jailsdir})"
|
||||
fi
|
||||
}
|
||||
|
||||
list_release(){
|
||||
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" -o -d "${bastille_releasesdir}/${_REL}/debootstrap" ]; then
|
||||
if [ "${2}" == "-p" -a -f "${bastille_releasesdir}/${_REL}/bin/freebsd-version" ]; then
|
||||
REL_PATCH_LEVEL=$(sed -n "s/^USERLAND_VERSION=\"\(.*\)\"$/\1/p" "${bastille_releasesdir}/${_REL}/bin/freebsd-version" 2> /dev/null)
|
||||
REL_PATCH_LEVEL=${REL_PATCH_LEVEL:-${_REL}}
|
||||
echo "${REL_PATCH_LEVEL}"
|
||||
else
|
||||
echo "${_REL}"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
list_template(){
|
||||
find "${bastille_templatesdir}" -type d -maxdepth 2
|
||||
}
|
||||
|
||||
list_jail(){
|
||||
if [ -d "${bastille_jailsdir}" ]; then
|
||||
JAIL_LIST=$(ls "${bastille_jailsdir}" | sed "s/\n//g")
|
||||
for _JAIL in ${JAIL_LIST}; do
|
||||
if [ -f "${bastille_jailsdir}/${_JAIL}/jail.conf" ]; then
|
||||
echo "${_JAIL}"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
list_log(){
|
||||
find "${bastille_logsdir}" -type f -maxdepth 1
|
||||
}
|
||||
|
||||
list_limit(){
|
||||
rctl -h jail:
|
||||
}
|
||||
|
||||
list_import(){
|
||||
ls "${bastille_backupsdir}" | grep -v ".sha256$"
|
||||
}
|
||||
|
||||
if [ $# -gt 0 ]; then
|
||||
# Handle special-case commands first.
|
||||
case "${1}" in
|
||||
all|-a|--all)
|
||||
list_all
|
||||
;;
|
||||
release|releases)
|
||||
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" -o -d "${bastille_releasesdir}/${_REL}/debootstrap" ]; then
|
||||
if [ "$2" == "-p" -a -f "${bastille_releasesdir}/${_REL}/bin/freebsd-version" ]; then
|
||||
REL_PATCH_LEVEL=$(sed -n "s/^USERLAND_VERSION=\"\(.*\)\"$/\1/p" "${bastille_releasesdir}/${_REL}/bin/freebsd-version" 2> /dev/null)
|
||||
REL_PATCH_LEVEL=${REL_PATCH_LEVEL:-${_REL}}
|
||||
echo "${REL_PATCH_LEVEL}"
|
||||
else
|
||||
echo "${_REL}"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
list_release
|
||||
;;
|
||||
template|templates)
|
||||
find "${bastille_templatesdir}" -type d -maxdepth 2
|
||||
list_template
|
||||
;;
|
||||
jail|jails|container|containers)
|
||||
if [ -d "${bastille_jailsdir}" ]; then
|
||||
JAIL_LIST=$(ls "${bastille_jailsdir}" | sed "s/\n//g")
|
||||
for _JAIL in ${JAIL_LIST}; do
|
||||
if [ -f "${bastille_jailsdir}/${_JAIL}/jail.conf" ]; then
|
||||
echo "${_JAIL}"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
list_jail
|
||||
;;
|
||||
log|logs)
|
||||
find "${bastille_logsdir}" -type f -maxdepth 1
|
||||
list_log
|
||||
;;
|
||||
limit|limits)
|
||||
rctl -h jail:
|
||||
list_limit
|
||||
;;
|
||||
import|imports|export|exports|backup|backups)
|
||||
ls "${bastille_backupsdir}" | grep -v ".sha256$"
|
||||
list_import
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
# Check if we want to query all info for a specific jail instead.
|
||||
if [ -f "${bastille_jailsdir}/${1}/jail.conf" ]; then
|
||||
TARGET="${1}"
|
||||
list_all
|
||||
else
|
||||
usage
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -50,6 +50,8 @@ else
|
||||
_fstab="$@"
|
||||
fi
|
||||
|
||||
bastille_root_check
|
||||
|
||||
## assign needed variables
|
||||
_hostpath=$(echo "${_fstab}" | awk '{print $1}')
|
||||
_jailpath=$(echo "${_fstab}" | awk '{print $2}')
|
||||
@@ -65,8 +67,10 @@ if [ -z "${_hostpath}" ] || [ -z "${_jailpath}" ] || [ -z "${_type}" ] || [ -z "
|
||||
exit 1
|
||||
fi
|
||||
|
||||
## if host path doesn't exist or type is not "nullfs"
|
||||
if [ ! -d "${_hostpath}" ] || [ "${_type}" != "nullfs" ]; then
|
||||
## if host path doesn't exist, type is not "nullfs" or are using advanced mount type "tmpfs,linprocfs,linsysfs, fdescfs, procfs"
|
||||
if [ "${_hostpath}" == "tmpfs" -a "$_type" == "tmpfs" ] || [ "${_hostpath}" == "linprocfs" -a "${_type}" == "linprocfs" ] || [ "${_hostpath}" == "linsysfs" -a "${_type}" == "linsysfs" ] || [ "${_hostpath}" == "proc" -a "${_type}" == "procfs" ] || [ "${_hostpath}" == "fdesc" -a "${_type}" == "fdescfs" ] ; then
|
||||
warn "Detected advanced mount type ${_hostpath}"
|
||||
elif [ ! -d "${_hostpath}" ] || [ "${_type}" != "nullfs" ]; then
|
||||
error_notify "Detected invalid host path or incorrect mount type in FSTAB."
|
||||
warn "Format: /host/path jail/path nullfs ro 0 0"
|
||||
warn "Read: ${_fstab}"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -45,17 +45,34 @@ if [ $# -lt 1 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
bastille_root_check
|
||||
|
||||
errors=0
|
||||
|
||||
for _jail in ${JAILS}; do
|
||||
info "[${_jail}]:"
|
||||
bastille_jail_path=$(/usr/sbin/jls -j "${_jail}" path)
|
||||
if [ -f "/usr/sbin/mport" ]; then
|
||||
jexec -l -U root "${_jail}" /usr/sbin/mport "$@"
|
||||
if ! jexec -l -U root "${_jail}" /usr/sbin/mport "$@"; then
|
||||
errors=1
|
||||
fi
|
||||
elif [ -f "${bastille_jail_path}/usr/bin/apt" ]; then
|
||||
jexec -l "${_jail}" /usr/bin/apt "$@"
|
||||
if ! jexec -l "${_jail}" /usr/bin/apt "$@"; then
|
||||
errors=1
|
||||
fi
|
||||
elif [ "${USE_HOST_PKG}" = 1 ]; then
|
||||
/usr/sbin/pkg -j "${_jail}" "$@"
|
||||
if ! /usr/sbin/pkg -j "${_jail}" "$@"; then
|
||||
errors=1
|
||||
fi
|
||||
else
|
||||
jexec -l -U root "${_jail}" /usr/sbin/pkg "$@"
|
||||
if ! jexec -l -U root "${_jail}" /usr/sbin/pkg "$@"; then
|
||||
errors=1
|
||||
fi
|
||||
fi
|
||||
echo
|
||||
done
|
||||
|
||||
if [ $errors -ne 0 ]; then
|
||||
error_exit "Failed to apply on some jails, please check logs"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
77
usr/local/share/bastille/rcp.sh
Normal file
77
usr/local/share/bastille/rcp.sh
Normal file
@@ -0,0 +1,77 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice, this
|
||||
# list of conditions and the following disclaimer.
|
||||
#
|
||||
# * Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
#
|
||||
# * Neither the name of the copyright holder nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
. /usr/local/share/bastille/common.sh
|
||||
. /usr/local/etc/bastille/bastille.conf
|
||||
|
||||
usage() {
|
||||
error_exit "Usage: bastille rcp [OPTION] TARGET CONTAINER_PATH HOST_PATH"
|
||||
}
|
||||
|
||||
CPSOURCE="${1}"
|
||||
CPDEST="${2}"
|
||||
|
||||
# Handle special-case commands first.
|
||||
case "$1" in
|
||||
help|-h|--help)
|
||||
usage
|
||||
;;
|
||||
-q|--quiet)
|
||||
OPTION="${1}"
|
||||
CPSOURCE="${2}"
|
||||
CPDEST="${3}"
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ $# -ne 2 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
if [ "${TARGET}" = "ALL" ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
case "${OPTION}" in
|
||||
-q|--quiet)
|
||||
OPTION="-a"
|
||||
;;
|
||||
*)
|
||||
OPTION="-av"
|
||||
;;
|
||||
esac
|
||||
|
||||
for _jail in ${JAILS}; do
|
||||
info "[${_jail}]:"
|
||||
bastille_jail_path="${bastille_jailsdir}/${_jail}/root"
|
||||
cp "${OPTION}" "${bastille_jail_path}/${CPSOURCE}" "${CPDEST}"
|
||||
RETURN="$?"
|
||||
echo
|
||||
return "${RETURN}"
|
||||
done
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -32,7 +32,7 @@
|
||||
. /usr/local/etc/bastille/bastille.conf
|
||||
|
||||
usage() {
|
||||
error_exit "Usage: bastille rdr TARGET [clear|list|(tcp|udp host_port jail_port)]"
|
||||
error_exit "Usage: bastille rdr TARGET [clear|list|(tcp|udp host_port jail_port [log ['(' logopts ')'] ] )]"
|
||||
}
|
||||
|
||||
# Handle special-case commands first.
|
||||
@@ -46,9 +46,12 @@ if [ $# -lt 2 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
bastille_root_check
|
||||
|
||||
TARGET="${1}"
|
||||
JAIL_NAME=""
|
||||
JAIL_IP=""
|
||||
JAIL_IP6=""
|
||||
EXT_IF=""
|
||||
shift
|
||||
|
||||
@@ -71,6 +74,13 @@ check_jail_validity() {
|
||||
error_exit "Jail IP not found: ${TARGET}"
|
||||
fi
|
||||
fi
|
||||
# Check if jail ip6 address (ip6.addr) is valid (non-VNET only)
|
||||
if [ "$(bastille config $TARGET get vnet)" != 'enabled' ]; then
|
||||
if [ "$(bastille config $TARGET get ip6)" != 'disable' ] && [ "$(bastille config $TARGET get ip6)" != 'not set' ]; then
|
||||
JAIL_IP6=$(/usr/sbin/jls -j "${TARGET}" ip6.addr 2>/dev/null)
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
# Check if rdr-anchor is defined in pf.conf
|
||||
if ! (pfctl -sn | grep rdr-anchor | grep 'rdr/\*' >/dev/null); then
|
||||
@@ -78,9 +88,11 @@ check_jail_validity() {
|
||||
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"
|
||||
if [ -n "${bastille_pf_conf}" ]; then
|
||||
EXT_IF=$(grep "^[[:space:]]*${bastille_network_pf_ext_if}[[:space:]]*=" ${bastille_pf_conf})
|
||||
if [ -z "${EXT_IF}" ]; then
|
||||
error_exit "bastille_network_pf_ext_if (${bastille_network_pf_ext_if}) not defined in pf.conf"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -91,11 +103,42 @@ if ! grep -qs "$1 $2 $3" "${bastille_jailsdir}/${JAIL_NAME}/rdr.conf"; then
|
||||
fi
|
||||
}
|
||||
|
||||
persist_rdr_log_rule() {
|
||||
proto=$1;host_port=$2;jail_port=$3;
|
||||
shift 3;
|
||||
log=$@;
|
||||
if ! grep -qs "$proto $host_port $jail_port $log" "${bastille_jailsdir}/${JAIL_NAME}/rdr.conf"; then
|
||||
echo "$proto $host_port $jail_port $log" >> "${bastille_jailsdir}/${JAIL_NAME}/rdr.conf"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# function: load rdr rule via pfctl
|
||||
load_rdr_rule() {
|
||||
( pfctl -a "rdr/${JAIL_NAME}" -Psn;
|
||||
printf '%s\nrdr pass on $ext_if inet proto %s to port %s -> %s port %s\n' "$EXT_IF" "$1" "$2" "$JAIL_IP" "$3" ) \
|
||||
printf '%s\nrdr pass on $%s inet proto %s to port %s -> %s port %s\n' "$EXT_IF" "${bastille_network_pf_ext_if}" "$1" "$2" "$JAIL_IP" "$3" ) \
|
||||
| pfctl -a "rdr/${JAIL_NAME}" -f-
|
||||
if [ -n "$JAIL_IP6" ]; then
|
||||
( pfctl -a "rdr/${JAIL_NAME}" -Psn;
|
||||
printf '%s\nrdr pass on $%s inet proto %s to port %s -> %s port %s\n' "$EXT_IF" "${bastille_network_pf_ext_if}" "$1" "$2" "$JAIL_IP6" "$3" ) \
|
||||
| pfctl -a "rdr/${JAIL_NAME}" -f-
|
||||
fi
|
||||
}
|
||||
|
||||
# function: load rdr rule with log via pfctl
|
||||
load_rdr_log_rule() {
|
||||
proto=$1;host_port=$2;jail_port=$3;
|
||||
shift 3;
|
||||
log=$@
|
||||
( pfctl -a "rdr/${JAIL_NAME}" -Psn;
|
||||
printf '%s\nrdr pass %s on $%s inet proto %s to port %s -> %s port %s\n' "$EXT_IF" "$log" "${bastille_network_pf_ext_if}" "$proto" "$host_port" "$JAIL_IP" "$jail_port" ) \
|
||||
| pfctl -a "rdr/${JAIL_NAME}" -f-
|
||||
if [ -n "$JAIL_IP6" ]; then
|
||||
( pfctl -a "rdr/${JAIL_NAME}" -Psn;
|
||||
printf '%s\nrdr pass %s on $%s inet proto %s to port %s -> %s port %s\n' "$EXT_IF" "$log" "${bastille_network_pf_ext_if}" "$proto" "$host_port" "$JAIL_IP6" "$jail_port" ) \
|
||||
| pfctl -a "rdr/${JAIL_NAME}" -f-
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
@@ -127,11 +170,44 @@ while [ $# -gt 0 ]; do
|
||||
tcp|udp)
|
||||
if [ $# -lt 3 ]; then
|
||||
usage
|
||||
elif [ $# -eq 3 ]; then
|
||||
check_jail_validity
|
||||
persist_rdr_rule $1 $2 $3
|
||||
load_rdr_rule $1 $2 $3
|
||||
shift 3
|
||||
else
|
||||
case "$4" in
|
||||
log)
|
||||
proto=$1
|
||||
host_port=$2
|
||||
jail_port=$3
|
||||
shift 3
|
||||
if [ $# -gt 3 ]; then
|
||||
for last in $@; do
|
||||
true
|
||||
done
|
||||
if [ $2 == "(" ] && [ $last == ")" ] ; then
|
||||
check_jail_validity
|
||||
persist_rdr_log_rule $proto $host_port $jail_port $@
|
||||
load_rdr_log_rule $proto $host_port $jail_port $@
|
||||
shift $#
|
||||
else
|
||||
usage
|
||||
fi
|
||||
elif [ $# -eq 1 ]; then
|
||||
check_jail_validity
|
||||
persist_rdr_log_rule $proto $host_port $jail_port $@
|
||||
load_rdr_log_rule $proto $host_port $jail_port $@
|
||||
shift 1
|
||||
else
|
||||
usage
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
check_jail_validity
|
||||
persist_rdr_rule $1 $2 $3
|
||||
load_rdr_rule $1 $2 $3
|
||||
shift 3
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -56,6 +56,8 @@ if [ $# -ne 1 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
bastille_root_check
|
||||
|
||||
NEWNAME="${1}"
|
||||
|
||||
update_jailconf() {
|
||||
@@ -68,6 +70,9 @@ update_jailconf() {
|
||||
sed -i '' "s|path.*=.*;|path = ${bastille_jailsdir}/${NEWNAME}/root;|" "${JAIL_CONFIG}"
|
||||
sed -i '' "s|mount.fstab.*=.*;|mount.fstab = ${bastille_jailsdir}/${NEWNAME}/fstab;|" "${JAIL_CONFIG}"
|
||||
sed -i '' "s|${TARGET}.*{|${NEWNAME} {|" "${JAIL_CONFIG}"
|
||||
# Rename vnet interface
|
||||
sed -i '' "/vnet.interface/s|_${TARGET}\";|_${NEWNAME}\";|" "${JAIL_CONFIG}"
|
||||
sed -i '' "/ifconfig/s|_${TARGET}|_${NEWNAME}|" "${JAIL_CONFIG}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -45,6 +45,8 @@ if [ $# -lt 1 -o $# -gt 2 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
bastille_root_check
|
||||
|
||||
for _jail in ${JAILS}; do
|
||||
info "[${_jail}]:"
|
||||
jexec -l "${_jail}" /usr/sbin/service "$@"
|
||||
|
||||
131
usr/local/share/bastille/setup.sh
Normal file
131
usr/local/share/bastille/setup.sh
Normal file
@@ -0,0 +1,131 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice, this
|
||||
# list of conditions and the following disclaimer.
|
||||
#
|
||||
# * Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
#
|
||||
# * Neither the name of the copyright holder nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
. /usr/local/share/bastille/common.sh
|
||||
. /usr/local/etc/bastille/bastille.conf
|
||||
|
||||
usage() {
|
||||
error_exit "Usage: bastille setup [pf|bastille0|zfs|vnet]"
|
||||
}
|
||||
|
||||
# Check for too many args
|
||||
if [ $# -gt 1 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
# Configure bastille0 network interface
|
||||
configure_bastille0() {
|
||||
info "Configuring bastille0 loopback interface"
|
||||
sysrc cloned_interfaces+=lo1
|
||||
sysrc ifconfig_lo1_name="bastille0"
|
||||
|
||||
info "Bringing up new interface: bastille0"
|
||||
service netif cloneup
|
||||
}
|
||||
|
||||
configure_vnet() {
|
||||
info "Configuring bridge interface"
|
||||
sysrc cloned_interfaces+=bridge1
|
||||
sysrc ifconfig_bridge1_name=bastille1
|
||||
|
||||
info "Bringing up new interface: bastille1"
|
||||
service netif cloneup
|
||||
}
|
||||
|
||||
# Configure pf firewall
|
||||
configure_pf() {
|
||||
if [ ! -f "${bastille_pf_conf}" ]; then
|
||||
local ext_if
|
||||
ext_if=$(netstat -rn | awk '/default/ {print $4}' | head -n1)
|
||||
info "Determined default network interface: ($ext_if)"
|
||||
info "${bastille_pf_conf} does not exist: creating..."
|
||||
|
||||
## creating pf.conf
|
||||
cat << EOF > ${bastille_pf_conf}
|
||||
## generated by bastille setup
|
||||
ext_if="$ext_if"
|
||||
|
||||
set block-policy return
|
||||
scrub in on \$ext_if all fragment reassemble
|
||||
set skip on lo
|
||||
|
||||
table <jails> persist
|
||||
nat on \$ext_if from <jails> to any -> (\$ext_if:0)
|
||||
rdr-anchor "rdr/*"
|
||||
|
||||
block in all
|
||||
pass out quick keep state
|
||||
antispoof for \$ext_if inet
|
||||
pass in inet proto tcp from any to any port ssh flags S/SA keep state
|
||||
EOF
|
||||
sysrc pf_enable=YES
|
||||
else
|
||||
error_exit "${bastille_pf_conf} already exists. Exiting."
|
||||
fi
|
||||
}
|
||||
|
||||
# Configure ZFS
|
||||
configure_zfs() {
|
||||
if [ ! "$(kldstat -q -m zfs)" ]; then
|
||||
info "ZFS module not loaded; skipping..."
|
||||
else
|
||||
## attempt to determine bastille_zroot from `zpool list`
|
||||
bastille_zroot=$(zpool list | grep -v NAME | awk '{print $1}')
|
||||
sysrc -f "${bastille_prefix}/bastille.conf" bastille_zfs_enable=YES
|
||||
sysrc -f "${bastille_prefix}/bastille.conf" bastille_zfs_zpool="${bastille_zroot}"
|
||||
fi
|
||||
}
|
||||
|
||||
# Run all base functions (w/o vnet) if no args
|
||||
if [ $# -eq 0 ]; then
|
||||
sysrc bastille_enable=YES
|
||||
configure_bastille0
|
||||
configure_pf
|
||||
configure_zfs
|
||||
fi
|
||||
|
||||
# Handle special-case commands first.
|
||||
case "$1" in
|
||||
help|-h|--help)
|
||||
usage
|
||||
;;
|
||||
pf|firewall)
|
||||
configure_pf
|
||||
;;
|
||||
bastille0|loopback)
|
||||
configure_bastille0
|
||||
;;
|
||||
zfs|storage)
|
||||
configure_zfs
|
||||
;;
|
||||
bastille1|vnet|bridge)
|
||||
configure_vnet
|
||||
;;
|
||||
esac
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -46,6 +46,8 @@ if [ $# -gt 1 ] || [ $# -lt 1 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
bastille_root_check
|
||||
|
||||
TARGET="${1}"
|
||||
shift
|
||||
|
||||
@@ -77,14 +79,14 @@ for _jail in ${JAILS}; do
|
||||
fi
|
||||
|
||||
## warn if matching configured (but not online) ip4.addr, ignore if there's no ip4.addr entry
|
||||
ip=$(grep 'ip4.addr' "${bastille_jailsdir}/${_jail}/jail.conf" | awk '{print $3}' | sed 's/\;//g')
|
||||
ip=$(bastille config "${_jail}" get ip4.addr)
|
||||
if [ -n "${ip}" ]; then
|
||||
if ifconfig | grep -w "${ip}" >/dev/null; then
|
||||
if ifconfig | grep -wF "${ip}" >/dev/null; then
|
||||
error_notify "Error: IP address (${ip}) already in use."
|
||||
continue
|
||||
fi
|
||||
## add ip4.addr to firewall table:jails
|
||||
pfctl -q -t jails -T add "${ip}"
|
||||
## add ip4.addr to firewall table
|
||||
pfctl -q -t "${bastille_network_pf_table}" -T add "${ip}"
|
||||
fi
|
||||
|
||||
## start the container
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -46,15 +46,13 @@ if [ $# -ne 0 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
bastille_root_check
|
||||
|
||||
for _jail in ${JAILS}; do
|
||||
## test if running
|
||||
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 "$(/usr/sbin/jls -j ${_jail} ip4.addr)"
|
||||
fi
|
||||
fi
|
||||
## Capture ip4.addr address while still running
|
||||
_ip="$(/usr/sbin/jls -j ${_jail} ip4.addr)"
|
||||
|
||||
# Check if pfctl is present
|
||||
if which -s pfctl; then
|
||||
@@ -73,6 +71,13 @@ for _jail in ${JAILS}; do
|
||||
## stop container
|
||||
info "[${_jail}]:"
|
||||
jail -f "${bastille_jailsdir}/${_jail}/jail.conf" -r "${_jail}"
|
||||
|
||||
## remove (captured above) ip4.addr from firewall table
|
||||
if [ -n "${bastille_network_loopback}" -a ! -z "${_ip}" ]; then
|
||||
if grep -qw "interface.*=.*${bastille_network_loopback}" "${bastille_jailsdir}/${_jail}/jail.conf"; then
|
||||
pfctl -q -t "${bastille_network_pf_table}" -T delete "${_ip}"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
echo
|
||||
done
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -45,6 +45,8 @@ if [ $# -lt 1 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
bastille_root_check
|
||||
|
||||
for _jail in ${JAILS}; do
|
||||
info "[${_jail}]:"
|
||||
jexec -l "${_jail}" /usr/sbin/sysrc "$@"
|
||||
|
||||
104
usr/local/share/bastille/tags.sh
Normal file
104
usr/local/share/bastille/tags.sh
Normal file
@@ -0,0 +1,104 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
# Ressource limits added by Lars Engels github.com/bsdlme
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice, this
|
||||
# list of conditions and the following disclaimer.
|
||||
#
|
||||
# * Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
#
|
||||
# * Neither the name of the copyright holder nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
. /usr/local/share/bastille/common.sh
|
||||
. /usr/local/etc/bastille/bastille.conf
|
||||
|
||||
usage() {
|
||||
error_notify "Usage: bastille tags TARGET add tag1[,tag2,...]"
|
||||
error_notify " bastille tags TARGET delete tag1[,tag2,...]"
|
||||
error_notify " bastille tags TARGET list [tag]"
|
||||
echo -e "Example: bastille tags JAILNAME add database,mysql"
|
||||
echo -e " bastille tags JAILNAME delete mysql"
|
||||
echo -e " bastille tags ALL list"
|
||||
echo -e " bastille tags ALL list mysql"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Handle special-case commands first.
|
||||
case "$1" in
|
||||
help|-h|--help)
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ $# -lt 1 -o $# -gt 2 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
bastille_root_check
|
||||
|
||||
ACTION="${1}"
|
||||
TAGS="${2}"
|
||||
|
||||
for _jail in ${JAILS}; do
|
||||
bastille_jail_tags="${bastille_jailsdir}/${_jail}/tags"
|
||||
case ${ACTION} in
|
||||
add)
|
||||
for _tag in $(echo ${TAGS} | tr , ' '); do
|
||||
echo ${_tag} >> "${bastille_jail_tags}"
|
||||
tmpfile="$(mktemp)"
|
||||
sort "${bastille_jail_tags}" | uniq > "${tmpfile}"
|
||||
mv "${tmpfile}" "${bastille_jail_tags}"
|
||||
done
|
||||
;;
|
||||
del*)
|
||||
for _tag in $(echo ${TAGS} | tr , ' '); do
|
||||
[ ! -f "${bastille_jail_tags}" ] && break # skip if no tags file
|
||||
tmpfile="$(mktemp)"
|
||||
grep -Ev "^${_tag}\$" "${bastille_jail_tags}" > "${tmpfile}"
|
||||
mv "${tmpfile}" "${bastille_jail_tags}"
|
||||
# delete tags file if empty
|
||||
[ ! -s "${bastille_jail_tags}" ] && rm "${bastille_jail_tags}"
|
||||
done
|
||||
;;
|
||||
list)
|
||||
if [ -n "${TAGS}" ]; then
|
||||
[ -n "$(echo ${TAGS} | grep ,)" ] && usage # Only one tag per query
|
||||
[ ! -f "${bastille_jail_tags}" ] && continue # skip if there is no tags file
|
||||
grep -qE "^${TAGS}\$" "${bastille_jail_tags}"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "${_jail}"
|
||||
continue
|
||||
fi
|
||||
else
|
||||
if [ -f "${bastille_jail_tags}" ]; then
|
||||
echo -n "${_jail}: "
|
||||
xargs < "${bastille_jail_tags}"
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -116,6 +116,8 @@ if [ $# -lt 1 ]; then
|
||||
bastille_usage
|
||||
fi
|
||||
|
||||
bastille_root_check
|
||||
|
||||
## global variables
|
||||
TEMPLATE="${1}"
|
||||
bastille_template=${bastille_templatesdir}/${TEMPLATE}
|
||||
@@ -229,6 +231,7 @@ for _jail in ${JAILS}; do
|
||||
bastille_jail_path=$(/usr/sbin/jls -j "${_jail}" path)
|
||||
if [ "$(bastille config $TARGET get vnet)" != 'enabled' ]; then
|
||||
_jail_ip=$(/usr/sbin/jls -j "${_jail}" ip4.addr 2>/dev/null)
|
||||
_jail_ip6=$(/usr/sbin/jls -j "${_jail}" ip6.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
|
||||
@@ -251,7 +254,7 @@ for _jail in ${JAILS}; do
|
||||
|
||||
# Build a list of sed commands like this: -e 's/${username}/root/g' -e 's/${domain}/example.com/g'
|
||||
# Values provided by default (without being defined by the user) are listed here. -- cwells
|
||||
ARG_REPLACEMENTS="-e 's/\${JAIL_IP}/${_jail_ip}/g' -e 's/\${JAIL_NAME}/${_jail}/g'"
|
||||
ARG_REPLACEMENTS="-e 's/\${JAIL_IP}/${_jail_ip}/g' -e 's/\${JAIL_IP6}/${_jail_ip6}/g' -e 's/\${JAIL_NAME}/${_jail}/g'"
|
||||
# This is parsed outside the HOOKS loop so an ARG file can be used with a Bastillefile. -- cwells
|
||||
if [ -s "${bastille_template}/ARG" ]; then
|
||||
while read _line; do
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -45,6 +45,8 @@ if [ $# -ne 0 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
bastille_root_check
|
||||
|
||||
for _jail in ${JAILS}; do
|
||||
info "[${_jail}]:"
|
||||
jexec -l "${_jail}" /usr/bin/top
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -46,6 +46,8 @@ if [ $# -ne 1 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
bastille_root_check
|
||||
|
||||
MOUNT_PATH=$1
|
||||
|
||||
for _jail in ${JAILS}; do
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -46,6 +46,8 @@ if [ $# -gt 2 ] || [ $# -lt 1 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
bastille_root_check
|
||||
|
||||
TARGET="${1}"
|
||||
OPTION="${2}"
|
||||
|
||||
@@ -116,7 +118,9 @@ release_update() {
|
||||
fi
|
||||
|
||||
env PAGER="/bin/cat" freebsd-update ${OPTION} --not-running-from-cron -b "${bastille_releasesdir}/${TARGET}" \
|
||||
fetch install --currently-running "${TARGET_TRIM}"
|
||||
fetch --currently-running "${TARGET_TRIM}"
|
||||
env PAGER="/bin/cat" freebsd-update ${OPTION} --not-running-from-cron -b "${bastille_releasesdir}/${TARGET}" \
|
||||
install --currently-running "${TARGET_TRIM}"
|
||||
else
|
||||
error_exit "${TARGET} not found. See 'bastille bootstrap'."
|
||||
fi
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -46,6 +46,8 @@ if [ $# -gt 3 ] || [ $# -lt 2 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
bastille_root_check
|
||||
|
||||
TARGET="$1"
|
||||
NEWRELEASE="$2"
|
||||
OPTION="$3"
|
||||
@@ -87,7 +89,7 @@ jail_check() {
|
||||
|
||||
release_check() {
|
||||
# Validate the release
|
||||
if ! echo "${NEWRELEASE}" | grep -q "[0-9]\{2\}.[0-9]-RELEASE"; then
|
||||
if ! echo "${NEWRELEASE}" | grep -q "[0-9]\{2\}.[0-9]-[RELEASE,BETA,RC]"; then
|
||||
error_exit "${NEWRELEASE} is not a valid release."
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -154,6 +154,8 @@ if [ $# -gt 1 ] || [ $# -lt 1 ]; then
|
||||
bastille_usage
|
||||
fi
|
||||
|
||||
bastille_root_check
|
||||
|
||||
case "$1" in
|
||||
*-RELEASE|*-release|*-RC1|*-rc1|*-RC2|*-rc2)
|
||||
RELEASE=$1
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -43,6 +43,14 @@ for _jail in ${JAILS}; do
|
||||
done
|
||||
}
|
||||
|
||||
zfs_destroy_snapshot() {
|
||||
for _jail in ${JAILS}; do
|
||||
info "[${_jail}]:"
|
||||
zfs destroy -r "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${_jail}"@"${TAG}"
|
||||
echo
|
||||
done
|
||||
}
|
||||
|
||||
zfs_set_value() {
|
||||
for _jail in ${JAILS}; do
|
||||
info "[${_jail}]:"
|
||||
@@ -74,6 +82,8 @@ help|-h|--help)
|
||||
;;
|
||||
esac
|
||||
|
||||
bastille_root_check
|
||||
|
||||
## check ZFS enabled
|
||||
if [ ! "${bastille_zfs_enable}" = "YES" ]; then
|
||||
error_exit "ZFS not enabled."
|
||||
@@ -101,6 +111,10 @@ snap|snapshot)
|
||||
TAG=$2
|
||||
zfs_snapshot
|
||||
;;
|
||||
destroy_snap|destroy_snapshot)
|
||||
TAG=$2
|
||||
zfs_destroy_snapshot
|
||||
;;
|
||||
df|usage)
|
||||
zfs_disk_usage
|
||||
;;
|
||||
|
||||
Reference in New Issue
Block a user