Compare commits
102 Commits
0.3.201901
...
0.5.201911
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e4c4d0df2e | ||
|
|
7668927f6d | ||
|
|
635ce83d20 | ||
|
|
62b295f009 | ||
|
|
a8d6fe41d3 | ||
|
|
806654eae0 | ||
|
|
f892bab1b2 | ||
|
|
8409c356a8 | ||
|
|
864cfd31b8 | ||
|
|
4c6acc5b17 | ||
|
|
77114ba818 | ||
|
|
5d2954feb9 | ||
|
|
cd4f9ee22e | ||
|
|
3ee2af3b03 | ||
|
|
a14d9cffdd | ||
|
|
4dd5579149 | ||
|
|
72cbac6504 | ||
|
|
c68efdfb3d | ||
|
|
62a3821223 | ||
|
|
49065ca95a | ||
|
|
036def57e2 | ||
|
|
4ff0e34a66 | ||
|
|
1740ef4e49 | ||
|
|
9d352588f1 | ||
|
|
03be9fc033 | ||
|
|
3297457129 | ||
|
|
d9f4972f59 | ||
|
|
6a7a08b714 | ||
|
|
c4172250c0 | ||
|
|
29a8b8a671 | ||
|
|
6c32bccbe6 | ||
|
|
50ba68935e | ||
|
|
2616611780 | ||
|
|
47a3003f41 | ||
|
|
28c2115974 | ||
|
|
ebcf0831dc | ||
|
|
4a7b4a6bb0 | ||
|
|
b443427ec3 | ||
|
|
b75f2601db | ||
|
|
03186aefa2 | ||
|
|
19c5796920 | ||
|
|
1fd259e34b | ||
|
|
2439ebd25e | ||
|
|
2af895e204 | ||
|
|
3b97572acf | ||
|
|
7e721ab085 | ||
|
|
c2cb31decd | ||
|
|
0cf4fd85a6 | ||
|
|
e68bd1b3ae | ||
|
|
7e2b03b73b | ||
|
|
8a104ea379 | ||
|
|
b16bed276e | ||
|
|
4eb5d1b9ba | ||
|
|
4fb2cc1247 | ||
|
|
3191a9cc1c | ||
|
|
74117629aa | ||
|
|
481dc5111f | ||
|
|
5bb61a8c7e | ||
|
|
8efd4740ca | ||
|
|
9bc8837f77 | ||
|
|
4f67515157 | ||
|
|
3c5d961925 | ||
|
|
ae2b0ea0cb | ||
|
|
973c2bc7b2 | ||
|
|
487d2aba43 | ||
|
|
341469a1db | ||
|
|
3af9b59077 | ||
|
|
5c1074fa16 | ||
|
|
3acdb911ab | ||
|
|
cbe04f2f68 | ||
|
|
fd92827735 | ||
|
|
c22b508d25 | ||
|
|
9b5a71bd0a | ||
|
|
38727457fc | ||
|
|
86b7ba9c49 | ||
|
|
bd1f9b94e5 | ||
|
|
5540b22cb1 | ||
|
|
e857093979 | ||
|
|
95cb13739d | ||
|
|
8935b59635 | ||
|
|
4dd6a910d4 | ||
|
|
001a78912d | ||
|
|
903805465d | ||
|
|
07e9056c9c | ||
|
|
2ab81d47f4 | ||
|
|
3d3fd9881b | ||
|
|
02a14e28d2 | ||
|
|
6a082113d6 | ||
|
|
6d69c82a04 | ||
|
|
e74bbd089c | ||
|
|
90707cd5c9 | ||
|
|
2b2012f1be | ||
|
|
652c8f095e | ||
|
|
344837689d | ||
|
|
52c8df69e3 | ||
|
|
e5ae4d0743 | ||
|
|
c9ebc886fd | ||
|
|
cccf4ff31f | ||
|
|
6f1da4b265 | ||
|
|
57bd13c9ce | ||
|
|
957465dfa4 | ||
|
|
e2b4f84cfe |
30
AUTHORS.md
Normal file
30
AUTHORS.md
Normal file
@@ -0,0 +1,30 @@
|
||||
# AUTHORS
|
||||
|
||||
## Lead
|
||||
|
||||
Christer Edwards [christer.edwards@gmail.com]
|
||||
|
||||
## Contributors
|
||||
|
||||
Barry McCormick
|
||||
Jose Rivera
|
||||
Giacomo Olgeni
|
||||
Jan-Piet Mens
|
||||
|
||||
### Special thanks
|
||||
Software doesn't happen in a vacuum. Thank you to the following people who may
|
||||
not be found in the commit history.
|
||||
|
||||
Barry McCormick
|
||||
Carlos Meza
|
||||
Casandra Woodcox
|
||||
Clint Savage
|
||||
G. Clifford Williams
|
||||
Jack Thomasson
|
||||
Jun C Park
|
||||
Justin Desilets
|
||||
Larry Raab
|
||||
Nate Taylor
|
||||
Ryan Simpkins
|
||||
Tim Gelter
|
||||
Trevor Sharpe
|
||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
||||
BSD 3-Clause License
|
||||
|
||||
Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
|
||||
Copyright (c) 2018-2019, Christer Edwards <christer.edwards@gmail.com>
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
Installation
|
||||
============
|
||||
Bastille is available in the official FreeBSD ports tree at
|
||||
`sysutils/bastille`. Binary packages available in `quarterly` and `latest`
|
||||
repositories.
|
||||
|
||||
Bastille is not (yet) in the official ports tree, but I have built and
|
||||
verified binary packages.
|
||||
Current version is `0.5.20191125`.
|
||||
|
||||
To install using one of the BETA binary packages, copy the URL for the
|
||||
latest release here (TXZ file):
|
||||
https://github.com/bastillebsd/bastille/releases
|
||||
To install from the FreeBSD package repository:
|
||||
|
||||
Then, install via pkg.
|
||||
Example:
|
||||
* quarterly repository may be older version
|
||||
* latest repository will match recent ports
|
||||
|
||||
|
||||
PKG
|
||||
---
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
pkg add https://github.com/BastilleBSD/bastille/releases/download/0.3.20181124/bastille-0.3.20181124.txz
|
||||
pkg install bastille
|
||||
|
||||
BETA binary packages are signed. These can be verified with this pubkey:
|
||||
|
||||
To install from source (don't worry, no compiling):
|
||||
|
||||
ports
|
||||
-----
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAq28OLDhJ12JmsKKcJpnn
|
||||
pCW3fFYBNI1BtdvTvFx57ZXvQ2qecBvnR9+XWi83hKS9ALTKZI6CLC2uTv1fIsZl
|
||||
u6rDRRNZwZFfITACSfwI+7UObMXz3oBZjk94J3rIegk49EyjDswKdVWv5k1EiVXF
|
||||
SAwXSl2kA2hGfQJkj5NS4nrfoRBc0z6fm+BGdNuHKSTmeZh1dbLEHt9EArD20DJ7
|
||||
HIr8vUSPLwONeqJCBFA/MeDO+GpwtwA/ldc2ZZy1RCPctdC2NeiGW7oy1yVDu6wp
|
||||
mHCq8qDfmCx5Aex84rWUf9iH8TM92AWmegTaz2p+BgESctpjNRCUuSEwOCBIO6g5
|
||||
3wIDAQAB
|
||||
-----END PUBLIC KEY-----
|
||||
make -C /usr/ports/sysutils/bastille install clean
|
||||
|
||||
208
docs/chapters/jail-config.rst
Normal file
208
docs/chapters/jail-config.rst
Normal file
@@ -0,0 +1,208 @@
|
||||
Note: FreeBSD introduced container technology twenty years ago, long before the
|
||||
industry standardized on the term "container". Internally, FreeBSD refers to
|
||||
these containers as "jails".
|
||||
|
||||
jail.conf
|
||||
=========
|
||||
In this section we'll look at the default config for a new container. The
|
||||
defaults are sane for most applications, but if you want to tweak the settings
|
||||
here they are.
|
||||
|
||||
A `jail.conf` template is used each time a new container is created. This
|
||||
template looks like this:
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
interface = {interface};
|
||||
host.hostname = {name};
|
||||
exec.consolelog = /usr/local/bastille/logs/{name}_console.log;
|
||||
path = /usr/local/bastille/jails/{name}/root;
|
||||
ip6 = disable;
|
||||
securelevel = 2;
|
||||
devfs_ruleset = 4;
|
||||
enforce_statfs = 2;
|
||||
exec.start = '/bin/sh /etc/rc';
|
||||
exec.stop = '/bin/sh /etc/rc.shutdown';
|
||||
exec.clean;
|
||||
mount.devfs;
|
||||
mount.fstab = /usr/local/bastille/jails/{name}/fstab;
|
||||
|
||||
{name} {
|
||||
ip4.addr = x.x.x.x;
|
||||
}
|
||||
|
||||
|
||||
interface
|
||||
---------
|
||||
.. code-block:: shell
|
||||
|
||||
interface
|
||||
A network interface to add the jail's IP addresses (ip4.addr and
|
||||
ip6.addr) to. An alias for each address will be added to the
|
||||
interface before the jail is created, and will be removed from
|
||||
the interface after the jail is removed.
|
||||
|
||||
|
||||
host.hostname
|
||||
-------------
|
||||
.. code-block:: shell
|
||||
|
||||
host.hostname
|
||||
The hostname of the jail. Other similar parameters are
|
||||
host.domainname, host.hostuuid and host.hostid.
|
||||
|
||||
|
||||
exec.consolelog
|
||||
---------------
|
||||
.. code-block:: shell
|
||||
|
||||
exec.consolelog
|
||||
A file to direct command output (stdout and stderr) to.
|
||||
|
||||
|
||||
path
|
||||
----
|
||||
.. code-block:: shell
|
||||
|
||||
path
|
||||
The directory which is to be the root of the jail. Any commands
|
||||
run inside the jail, either by jail or from jexec(8), are run
|
||||
from this directory.
|
||||
|
||||
|
||||
securelevel
|
||||
-----------
|
||||
By default, Bastille containers run at `securelevel = 2;`. See below for the
|
||||
implications of kernel security levels and when they might be altered.
|
||||
|
||||
Note: Bastille does not currently have any mechanism to automagically change
|
||||
securelevel settings. My recommendation is this only be altered manually on a
|
||||
case-by-case basis and that "Highly secure mode" is a sane default for most use
|
||||
cases.
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
The kernel runs with five different security levels. Any super-user
|
||||
process can raise the level, but no process can lower it. The security
|
||||
levels are:
|
||||
|
||||
-1 Permanently insecure mode - always run the system in insecure mode.
|
||||
This is the default initial value.
|
||||
|
||||
0 Insecure mode - immutable and append-only flags may be turned off.
|
||||
All devices may be read or written subject to their permissions.
|
||||
|
||||
1 Secure mode - the system immutable and system append-only flags may
|
||||
not be turned off; disks for mounted file systems, /dev/mem and
|
||||
/dev/kmem may not be opened for writing; /dev/io (if your platform
|
||||
has it) may not be opened at all; kernel modules (see kld(4)) may
|
||||
not be loaded or unloaded. The kernel debugger may not be entered
|
||||
using the debug.kdb.enter sysctl. A panic or trap cannot be forced
|
||||
using the debug.kdb.panic and other sysctl's.
|
||||
|
||||
2 Highly secure mode - same as secure mode, plus disks may not be
|
||||
opened for writing (except by mount(2)) whether mounted or not.
|
||||
This level precludes tampering with file systems by unmounting
|
||||
them, but also inhibits running newfs(8) while the system is multi-
|
||||
user.
|
||||
|
||||
In addition, kernel time changes are restricted to less than or
|
||||
equal to one second. Attempts to change the time by more than this
|
||||
will log the message "Time adjustment clamped to +1 second".
|
||||
|
||||
3 Network secure mode - same as highly secure mode, plus IP packet
|
||||
filter rules (see ipfw(8), ipfirewall(4) and pfctl(8)) cannot be
|
||||
changed and dummynet(4) or pf(4) configuration cannot be adjusted.
|
||||
|
||||
|
||||
devfs_ruleset
|
||||
-------------
|
||||
.. code-block:: shell
|
||||
|
||||
devfs_ruleset
|
||||
The number of the devfs ruleset that is enforced for mounting
|
||||
devfs in this jail. A value of zero (default) means no ruleset
|
||||
is enforced. Descendant jails inherit the parent jail's devfs
|
||||
ruleset enforcement. Mounting devfs inside a jail is possible
|
||||
only if the allow.mount and allow.mount.devfs permissions are
|
||||
effective and enforce_statfs is set to a value lower than 2.
|
||||
Devfs rules and rulesets cannot be viewed or modified from inside
|
||||
a jail.
|
||||
|
||||
NOTE: It is important that only appropriate device nodes in devfs
|
||||
be exposed to a jail; access to disk devices in the jail may
|
||||
permit processes in the jail to bypass the jail sandboxing by
|
||||
modifying files outside of the jail. See devfs(8) for
|
||||
information on how to use devfs rules to limit access to entries
|
||||
in the per-jail devfs. A simple devfs ruleset for jails is
|
||||
available as ruleset #4 in /etc/defaults/devfs.rules.
|
||||
|
||||
|
||||
enforce_statfs
|
||||
--------------
|
||||
.. code-block:: shell
|
||||
|
||||
enforce_statfs
|
||||
This determines what information processes in a jail are able to
|
||||
get about mount points. It affects the behaviour of the
|
||||
following syscalls: statfs(2), fstatfs(2), getfsstat(2), and
|
||||
fhstatfs(2) (as well as similar compatibility syscalls). When
|
||||
set to 0, all mount points are available without any
|
||||
restrictions. When set to 1, only mount points below the jail's
|
||||
chroot directory are visible. In addition to that, the path to
|
||||
the jail's chroot directory is removed from the front of their
|
||||
pathnames. When set to 2 (default), above syscalls can operate
|
||||
only on a mount-point where the jail's chroot directory is
|
||||
located.
|
||||
|
||||
|
||||
exec.start
|
||||
----------
|
||||
.. code-block:: shell
|
||||
|
||||
exec.start
|
||||
Command(s) to run in the jail environment when a jail is created.
|
||||
A typical command to run is "sh /etc/rc".
|
||||
|
||||
|
||||
exec.stop
|
||||
---------
|
||||
.. code-block:: shell
|
||||
|
||||
exec.stop
|
||||
Command(s) to run in the jail environment before a jail is
|
||||
removed, and after any exec.prestop commands have completed. A
|
||||
typical command to run is "sh /etc/rc.shutdown".
|
||||
|
||||
|
||||
exec.clean
|
||||
----------
|
||||
.. code-block:: shell
|
||||
|
||||
exec.clean
|
||||
Run commands in a clean environment. The environment is
|
||||
discarded except for HOME, SHELL, TERM and USER. HOME and SHELL
|
||||
are set to the target login's default values. USER is set to the
|
||||
target login. TERM is imported from the current environment.
|
||||
The environment variables from the login class capability
|
||||
database for the target login are also set.
|
||||
|
||||
|
||||
mount.devfs
|
||||
-----------
|
||||
.. code-block:: shell
|
||||
|
||||
mount.devfs
|
||||
Mount a devfs(5) filesystem on the chrooted /dev directory, and
|
||||
apply the ruleset in the devfs_ruleset parameter (or a default of
|
||||
ruleset 4: devfsrules_jail) to restrict the devices visible
|
||||
inside the jail.
|
||||
|
||||
|
||||
mount.fstab
|
||||
-----------
|
||||
.. code-block:: shell
|
||||
|
||||
mount.fstab
|
||||
An fstab(5) format file containing filesystems to mount before
|
||||
creating a jail.
|
||||
@@ -1,71 +1,135 @@
|
||||
====================
|
||||
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?
|
||||
|
||||
In order to segregate jails from the network and from the world, Bastille
|
||||
attaches jails to a loopback interface only. The host system then acts as
|
||||
the firewall, permitting and denying traffic as needed.
|
||||
Bastille tries to be flexible about how to network containerized applications.
|
||||
The two most common methods are described here. Consider both options to decide
|
||||
which design work best for your needs. One of the methods works better across
|
||||
clouds while the other is simpler if used in local area networks.
|
||||
|
||||
As you've probably seen, Bastille containers require certain information when
|
||||
they are created. An IP address has to be assigned to the container through
|
||||
which all network traffic will flow.
|
||||
|
||||
When the container is started the IP address assigned at creation will be bound
|
||||
to a network interface. In FreeBSD these interfaces have different names, but
|
||||
look something like `em0`, `bge0`, `re0`, etc. On a virtual machine it may be
|
||||
`vtnet0`. You get the idea...
|
||||
|
||||
**Note: if you are running in the cloud and only have a single public IP you
|
||||
may want the Public Network option. See below.**
|
||||
|
||||
|
||||
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.
|
||||
|
||||
Bastille allows you to define the interface you want the IP attached to when
|
||||
you create it. An example:
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
bastille create alcatraz 12.1-RELEASE 192.168.1.50 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
|
||||
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.
|
||||
|
||||
(Bastille does try to verify that the interface name you provide it is a valid
|
||||
interface. This validation has not been exhaustively tested yet in Bastille's
|
||||
beta state.)
|
||||
|
||||
|
||||
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 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
|
||||
network.
|
||||
|
||||
What I 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
|
||||
because I've created my own private network. The host system then acts as the
|
||||
firewall, permitting and denying traffic as needed.
|
||||
|
||||
I find this setup the most flexible across all types of networks. It can be
|
||||
used in public and private networks just the same and it allows me to keep
|
||||
containers off the network until I allow access.
|
||||
|
||||
Having said all that here are instructions I used to configure the network with
|
||||
a private loopback interface and system firewall. The system firewall NATs
|
||||
traffic out of containers and can selectively redirect traffic into containers
|
||||
based on connection ports (ie; 80, 443, etc.)
|
||||
|
||||
First, create the loopback interface:
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
ishmael ~ # sysrc cloned_interfaces+=lo1
|
||||
ishmael ~ # sysrc ifconfig_lo1_name="bastille0"
|
||||
ishmael ~ # service netif cloneup
|
||||
ishmael ~ # ifconfig bastille0 inet 10.17.89.10
|
||||
|
||||
Second, enable NAT through the firewall:
|
||||
Second, enable the firewall:
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
ishmael ~ # sysrc pf_enable="YES"
|
||||
|
||||
Create the firewall rules:
|
||||
|
||||
/etc/pf.conf
|
||||
------------
|
||||
|
||||
Create the firewall config, or merge as necessary.
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
ext_if="vtnet0"
|
||||
|
||||
set block-policy drop
|
||||
set block-policy return
|
||||
scrub in on $ext_if all fragment reassemble
|
||||
|
||||
set skip on lo
|
||||
nat on $ext_if from !($ext_if) -> ($ext_if:0)
|
||||
nat on $ext_if from bastille0:network to any -> ($ext_if)
|
||||
|
||||
## rdr example
|
||||
## rdr pass inet proto tcp from any to any port {80, 443} -> 10.88.9.45
|
||||
## rdr pass inet proto tcp from any to any port {80, 443} -> 10.17.89.45
|
||||
|
||||
block in log all
|
||||
block in all
|
||||
pass out quick modulate state
|
||||
antispoof for $ext_if inet
|
||||
pass in inet proto tcp from any to any port ssh flags S/SA keep state
|
||||
|
||||
pass in inet proto tcp from any to any port ssh flags S/SA modulate state
|
||||
|
||||
- Make sure to change the `ext_if` variable to match your host system interface.
|
||||
- Make sure to include the last line (`port ssh`) or you'll end up locked out.
|
||||
|
||||
|
||||
Note: if you have an existing firewall, the key lines for in/out traffic
|
||||
to jails are:
|
||||
to containers are:
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
nat on $ext_if from lo1:network to any -> ($ext_if)
|
||||
nat on $ext_if from bastille0:network to any -> ($ext_if)
|
||||
|
||||
## rdr example
|
||||
## rdr pass inet proto tcp from any to any port {80, 443} -> 10.88.9.45
|
||||
## rdr pass inet proto tcp from any to any port {80, 443} -> 10.17.89.45
|
||||
|
||||
The `nat` routes traffic from the loopback interface to the external
|
||||
interface for outbound access.
|
||||
|
||||
The `rdr pass ...` will redirect traffic from the host firewall on port X
|
||||
to the ip of Jail Y. The example shown redirects web traffic (80 & 443) to
|
||||
the jails at `10.88.9.45`.
|
||||
|
||||
We'll get to that later, but when you're ready to allow traffic inbound to
|
||||
your jails, that's where you'd do it.
|
||||
The `rdr pass ...` will redirect traffic from the host firewall on port X to
|
||||
the ip of Container Y. The example shown redirects web traffic (80 & 443) to the
|
||||
containers at `10.17.89.45`.
|
||||
|
||||
Finally, start up the firewall:
|
||||
|
||||
|
||||
@@ -1,34 +1,100 @@
|
||||
=========
|
||||
bootstrap
|
||||
=========
|
||||
|
||||
The first step is to "bootstrap" a release. Current supported release is
|
||||
11.2-RELEASE, but you can bootstrap anything in the ftp.FreeBSD.org
|
||||
RELEASES directory.
|
||||
The bootstrap sub-command is used to download and extract releases and
|
||||
templates for use with Bastille containers. A valid release is needed before
|
||||
containers can be created. Templates are optional but are managed in the same
|
||||
manner.
|
||||
|
||||
Note: your mileage may vary with unsupported releases and releases newer
|
||||
than the host system likely will NOT work at all.
|
||||
than the host system likely will NOT work at all. Bastille tries to filter for
|
||||
valid release names. If you find it will not bootstrap a valid release, please
|
||||
let us know.
|
||||
|
||||
In this document we will describe using the `bootstrap` sub-command with both
|
||||
releases and templates. We begin with releases.
|
||||
|
||||
|
||||
Releases
|
||||
========
|
||||
|
||||
Example
|
||||
-------
|
||||
|
||||
To `bootstrap` a release, run the bootstrap sub-command with the
|
||||
release version as the argument.
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
ishmael ~ # bastille bootstrap 11.2-RELEASE
|
||||
ishmael ~ # bastille bootstrap 11.3-RELEASE [update]
|
||||
ishmael ~ # bastille bootstrap 12.0-RELEASE
|
||||
ishmael ~ # bastille bootstrap 12.1-RELEASE
|
||||
|
||||
This command will ensure the required directory structures are in place
|
||||
and download the requested release. For each requested release,
|
||||
`bootstrap` will download the base.txz and lib32.txz. These are both
|
||||
verified (sha256 via MANIFEST file) before they are extracted for use.
|
||||
This command will ensure the required directory structures are in place and
|
||||
download the requested release. For each requested release, `bootstrap` will
|
||||
download the base.txz. These files are verified (sha256 via MANIFEST file)
|
||||
before they are extracted for use.
|
||||
|
||||
Downloaded artifacts are stored in the `cache` directory. "bootstrapped"
|
||||
releases are stored in `releases/version`.
|
||||
Tips
|
||||
----
|
||||
|
||||
The bootstrap subcommand is generally only used once to prepare the
|
||||
system. The only other use case for the bootstrap command is when a new
|
||||
FreeBSD version is released and you want to start building jails on that
|
||||
version.
|
||||
The `bootstrap` sub-command can now take (0.5.20191125+) an optional second
|
||||
argument of "update". If this argument is used, `bastille update` will be run
|
||||
immediately after the bootstrap, effectively bootstrapping and applying
|
||||
security patches and errata in one motion.
|
||||
|
||||
To update a release as patches are made available, see the `bastille
|
||||
update` command.
|
||||
Notes
|
||||
-----
|
||||
|
||||
The bootstrap subcommand is generally only used once to prepare the system. The
|
||||
only other use case for the bootstrap command is when a new FreeBSD version is
|
||||
released and you want to start deploying containers on that version.
|
||||
|
||||
To update a release as patches are made available, see the `bastille update`
|
||||
command.
|
||||
|
||||
Downloaded artifacts are stored in the `bastille/cache/version` directory.
|
||||
"bootstrapped" releases are stored in `bastille/releases/version`.
|
||||
|
||||
To manually bootstrap a release (aka bring your own archive), place your
|
||||
archive in bastille/cache/name and extract to bastille/releases/name. Your
|
||||
mileage may vary; let me know what happens.
|
||||
|
||||
|
||||
Templates
|
||||
=========
|
||||
|
||||
Bastille aims to integrate container automation into the platform while
|
||||
maintaining a simple, uncomplicated design. Templates are git repositories with
|
||||
automation definitions for packages, services, file overlays, etc.
|
||||
|
||||
To download one of these templates see the example below.
|
||||
|
||||
Example
|
||||
-------
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
ishmael ~ # bastille bootstrap https://gitlab.com/bastillebsd-templates/nginx
|
||||
ishmael ~ # bastille bootstrap https://gitlab.com/bastillebsd-templates/mariadb-server
|
||||
ishmael ~ # bastille bootstrap https://gitlab.com/bastillebsd-templates/python3
|
||||
|
||||
Tips
|
||||
----
|
||||
See the documentation on templates for more information on how they work and
|
||||
how you can create or customize your own. Templates are a powerful part of
|
||||
Bastille and facilitate full container automation.
|
||||
|
||||
Notes
|
||||
-----
|
||||
If you don't want to bother with git to use templates you can create them
|
||||
manually on the Bastille system and apply them.
|
||||
|
||||
Templates are stored in `bastille/templates/namespace/name`. If you'd like to
|
||||
create a new template on your local system, simply create a new namespace
|
||||
within the templates directory and then one for the template. This namespacing
|
||||
allows users and groups to have templates without conflicting template names.
|
||||
|
||||
Once you've created the directory structure you can begin filling it with
|
||||
template hooks. Once you have a minimum number of hooks (at least one) you can
|
||||
begin applying your template.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
cmd
|
||||
===
|
||||
|
||||
To execute commands within the jail you can use `bastille cmd`.
|
||||
To execute commands within the container you can use `bastille cmd`.
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
console
|
||||
=======
|
||||
|
||||
This sub-command launches a login shell into the jail. Default is
|
||||
password-less root login.
|
||||
This sub-command launches a login shell into the container. Default is password-less
|
||||
root login.
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
ishmael ~ # bastille console folsom
|
||||
[folsom]:
|
||||
FreeBSD 11.2-RELEASE-p4 (GENERIC) #0: Thu Sep 27 08:16:24 UTC 2018
|
||||
FreeBSD 12.1-RELEASE-p1 GENERIC
|
||||
|
||||
Welcome to FreeBSD!
|
||||
|
||||
@@ -31,6 +31,6 @@ password-less root login.
|
||||
Edit /etc/motd to change this login announcement.
|
||||
root@folsom:~ #
|
||||
|
||||
At this point you are logged in to the jail and have full shell access.
|
||||
The system is yours to use and/or abuse as you like. Any changes made
|
||||
inside the jail are limited to the jail.
|
||||
At this point you are logged in to the container and have full shell access. The
|
||||
system is yours to use and/or abuse as you like. Any changes made inside the
|
||||
container are limited to the container.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
cp
|
||||
==
|
||||
|
||||
This command allows efficiently copying files from host to jail(s).
|
||||
This command allows efficiently copying files from host to container(s).
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
======
|
||||
create
|
||||
======
|
||||
|
||||
Bastille create uses any available bootstrapped release to create a
|
||||
lightweight jailed system. To create a jail simply provide a name,
|
||||
lightweight container system. To create a container simply provide a name,
|
||||
bootstrapped release and a private (rfc1918) IP address.
|
||||
|
||||
- name
|
||||
- release
|
||||
- ip
|
||||
- interface (optional)
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
ishmael ~ # bastille create folsom 11.2-RELEASE 10.8.62.1
|
||||
ishmael ~ # bastille create folsom 11.3-RELEASE 10.17.89.10 [interface]
|
||||
|
||||
RELEASE: 11.2-RELEASE.
|
||||
RELEASE: 11.3-RELEASE.
|
||||
NAME: folsom.
|
||||
IP: 10.8.62.1.
|
||||
IP: 10.17.89.10.
|
||||
|
||||
This command will create a 11.2-RELEASE jail assigning the 10.8.62.1 ip
|
||||
This command will create a 11.3-RELEASE container assigning the 10.17.89.10 ip
|
||||
address to the new system.
|
||||
|
||||
I recommend using private (rfc1918) ip address ranges for your jails.
|
||||
These ranges include:
|
||||
I recommend using private (rfc1918) ip address ranges for your container. These
|
||||
ranges include:
|
||||
|
||||
- 10.0.0.0/8
|
||||
- 172.16.0.0/12
|
||||
- 192.168.0.0/16
|
||||
|
||||
Bastille does its best to validate the submitted ip is valid. This has not
|
||||
been thouroughly tested--I generally use the 10/8 range.
|
||||
Bastille does its best to validate the submitted ip is valid. This has not been
|
||||
thouroughly tested--I generally use the 10/8 range.
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
destroy
|
||||
=======
|
||||
|
||||
Jails can be destroyed and thrown away just as easily as they were
|
||||
created. Note: jails must be stopped before destroyed.
|
||||
Containers can be destroyed and thrown away just as easily as they were
|
||||
created. Note: containers must be stopped before destroyed.
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
@@ -13,6 +13,6 @@ created. Note: jails must be stopped before destroyed.
|
||||
.. code-block:: shell
|
||||
|
||||
ishmael ~ # bastille destroy folsom
|
||||
Deleting Jail: folsom.
|
||||
Note: jail console logs not destroyed.
|
||||
Deleting Container: folsom.
|
||||
Note: containers console logs not destroyed.
|
||||
/usr/local/bastille/logs/folsom_console.log
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
htop
|
||||
====
|
||||
|
||||
This one runs `htop` inside the jail.
|
||||
note: won't work if you don't have htop installed in the jail.
|
||||
This one runs `htop` inside the container.
|
||||
note: won't work if you don't have htop installed in the container.
|
||||
|
||||
|
||||
.. image:: ../../images/htop.png
|
||||
:align: center
|
||||
:alt: bastille htop jail
|
||||
:alt: bastille htop container
|
||||
|
||||
@@ -14,6 +14,7 @@ Bastille sub-commands
|
||||
htop
|
||||
pkg
|
||||
restart
|
||||
service
|
||||
start
|
||||
stop
|
||||
sysrc
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
pkg
|
||||
===
|
||||
|
||||
To manage binary packages within the jail use `bastille pkg`.
|
||||
To manage binary packages within the container use `bastille pkg`.
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
@@ -87,11 +87,11 @@ expectation is that you can fully leverage the pkg manager. This means,
|
||||
|
||||
ishmael ~ # bastille pkg ALL upgrade
|
||||
[bastion]:
|
||||
Updating iniquity.io repository catalogue...
|
||||
Updating pkg.bastillebsd.org repository catalogue...
|
||||
[bastion] Fetching meta.txz: 100% 560 B 0.6kB/s 00:01
|
||||
[bastion] Fetching packagesite.txz: 100% 118 KiB 121.3kB/s 00:01
|
||||
Processing entries: 100%
|
||||
iniquity.io repository update completed. 493 packages processed.
|
||||
pkg.bastillebsd.org repository update completed. 493 packages processed.
|
||||
All repositories are up to date.
|
||||
Checking for upgrades (1 candidates): 100%
|
||||
Processing candidates (1 candidates): 100%
|
||||
@@ -99,11 +99,11 @@ expectation is that you can fully leverage the pkg manager. This means,
|
||||
Your packages are up to date.
|
||||
|
||||
[unbound0]:
|
||||
Updating iniquity.io repository catalogue...
|
||||
Updating pkg.bastillebsd.org repository catalogue...
|
||||
[unbound0] Fetching meta.txz: 100% 560 B 0.6kB/s 00:01
|
||||
[unbound0] Fetching packagesite.txz: 100% 118 KiB 121.3kB/s 00:01
|
||||
Processing entries: 100%
|
||||
iniquity.io repository update completed. 493 packages processed.
|
||||
pkg.bastillebsd.org repository update completed. 493 packages processed.
|
||||
All repositories are up to date.
|
||||
Checking for upgrades (0 candidates): 100%
|
||||
Processing candidates (0 candidates): 100%
|
||||
@@ -111,11 +111,11 @@ expectation is that you can fully leverage the pkg manager. This means,
|
||||
Your packages are up to date.
|
||||
|
||||
[unbound1]:
|
||||
Updating iniquity.io repository catalogue...
|
||||
Updating pkg.bastillebsd.org repository catalogue...
|
||||
[unbound1] Fetching meta.txz: 100% 560 B 0.6kB/s 00:01
|
||||
[unbound1] Fetching packagesite.txz: 100% 118 KiB 121.3kB/s 00:01
|
||||
Processing entries: 100%
|
||||
iniquity.io repository update completed. 493 packages processed.
|
||||
pkg.bastillebsd.org repository update completed. 493 packages processed.
|
||||
All repositories are up to date.
|
||||
Checking for upgrades (0 candidates): 100%
|
||||
Processing candidates (0 candidates): 100%
|
||||
@@ -123,11 +123,11 @@ expectation is that you can fully leverage the pkg manager. This means,
|
||||
Your packages are up to date.
|
||||
|
||||
[squid]:
|
||||
Updating iniquity.io repository catalogue...
|
||||
Updating pkg.bastillebsd.org repository catalogue...
|
||||
[squid] Fetching meta.txz: 100% 560 B 0.6kB/s 00:01
|
||||
[squid] Fetching packagesite.txz: 100% 118 KiB 121.3kB/s 00:01
|
||||
Processing entries: 100%
|
||||
iniquity.io repository update completed. 493 packages processed.
|
||||
pkg.bastillebsd.org repository update completed. 493 packages processed.
|
||||
All repositories are up to date.
|
||||
Checking for upgrades (0 candidates): 100%
|
||||
Processing candidates (0 candidates): 100%
|
||||
@@ -135,11 +135,11 @@ expectation is that you can fully leverage the pkg manager. This means,
|
||||
Your packages are up to date.
|
||||
|
||||
[nginx]:
|
||||
Updating iniquity.io repository catalogue...
|
||||
Updating pkg.bastillebsd.org repository catalogue...
|
||||
[nginx] Fetching meta.txz: 100% 560 B 0.6kB/s 00:01
|
||||
[nginx] Fetching packagesite.txz: 100% 118 KiB 121.3kB/s 00:01
|
||||
Processing entries: 100%
|
||||
iniquity.io repository update completed. 493 packages processed.
|
||||
pkg.bastillebsd.org repository update completed. 493 packages processed.
|
||||
All repositories are up to date.
|
||||
Checking for upgrades (1 candidates): 100%
|
||||
Processing candidates (1 candidates): 100%
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
restart
|
||||
=======
|
||||
|
||||
To restart a jail you can use the `bastille restart` command.
|
||||
To restart a container you can use the `bastille restart` command.
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
|
||||
13
docs/chapters/subcommands/service.rst
Normal file
13
docs/chapters/subcommands/service.rst
Normal file
@@ -0,0 +1,13 @@
|
||||
=======
|
||||
service
|
||||
=======
|
||||
|
||||
The `service` sub-command allows for managing services within containers. This
|
||||
allows you to start, stop, restart, and otherwise interact with services
|
||||
running inside the containers.
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
ishmael ~ # bastille service web01 'nginx start'
|
||||
ishmael ~ # bastille service db01 'mysql-server restart'
|
||||
ishmael ~ # bastille service proxy 'nginx configtest'
|
||||
@@ -1,7 +1,7 @@
|
||||
start
|
||||
=====
|
||||
|
||||
To start a jail you can use the `bastille start` command.
|
||||
To start a container you can use the `bastille start` command.
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
stop
|
||||
====
|
||||
|
||||
To stop a jail you can use the `bastille stop` command.
|
||||
To stop a container you can use the `bastille stop` command.
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ sysrc
|
||||
=====
|
||||
|
||||
The `sysrc` sub-command allows for safely editing system configuration files.
|
||||
In jail terms, this allows us to toggle on/off services and options at startup.
|
||||
In container terms, this allows us to toggle on/off services and options at startup.
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
top
|
||||
===
|
||||
|
||||
This one runs `top` in that jail.
|
||||
This one runs `top` in that container.
|
||||
|
||||
|
||||
.. image:: ../../images/top.png
|
||||
:align: center
|
||||
:alt: bastille top jail
|
||||
:alt: bastille top container
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
update
|
||||
======
|
||||
|
||||
The `update` command targets a release instead of a jail. Because every jail is
|
||||
based on a release, when the release is updated all the jails are automatically
|
||||
The `update` command targets a release instead of a container. Because every container is
|
||||
based on a release, when the release is updated all the containers are automatically
|
||||
updated as well.
|
||||
|
||||
If no updates are available, a message will be shown:
|
||||
@@ -38,4 +38,4 @@ The older the release, however, the more updates will be available:
|
||||
The following files will be added as part of updating to 10.4-RELEASE-p13:
|
||||
...[snip]...
|
||||
|
||||
To be safe, you may want to restart any jails that have been updated live.
|
||||
To be safe, you may want to restart any containers that have been updated live.
|
||||
|
||||
@@ -1,50 +1,48 @@
|
||||
=========
|
||||
Targeting
|
||||
=========
|
||||
|
||||
Bastille uses a `command-target-args` syntax, meaning that each command
|
||||
requires a target. Targets are usually jails, but can also be releases.
|
||||
requires a target. Targets are usually containers, but can also be releases.
|
||||
|
||||
Targeting a jail is done by providing the exact jail name.
|
||||
Targeting a containers is done by providing the exact containers name.
|
||||
|
||||
Targeting a release is done by providing the release name. (Note: do note
|
||||
include the `-pX` point-release version.)
|
||||
|
||||
Bastille includes a pre-defined keyword ALL to target all running jails.
|
||||
Bastille includes a pre-defined keyword ALL to target all running containers.
|
||||
|
||||
In the future I would like to support more options, including globbing, lists
|
||||
and regular-expressions.
|
||||
|
||||
Examples: Jails
|
||||
===============
|
||||
Examples: Containers
|
||||
====================
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
ishmael ~ # bastille ...
|
||||
|
||||
|
||||
+-----------+--------+------------------+-------------------------------------------------------------+
|
||||
| command | target | args | description |
|
||||
+===========+========+==================+=============================================================+
|
||||
| cmd | ALL | 'sockstat -4' | execute `sockstat -4` in ALL jails (listening ip4 sockets) |
|
||||
| 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 jail |
|
||||
| pkg | web01 | 'install nginx' | install nginx package in web01 container |
|
||||
+-----------+--------+------------------+-------------------------------------------------------------+
|
||||
| pkg | ALL | upgrade | upgrade packages in ALL jails |
|
||||
| pkg | ALL | upgrade | upgrade packages in ALL containers |
|
||||
+-----------+--------+------------------+-------------------------------------------------------------+
|
||||
| pkg | ALL | audit | (CVE) audit packages in ALL jails |
|
||||
| pkg | ALL | audit | (CVE) audit packages in ALL containers |
|
||||
+-----------+--------+------------------+-------------------------------------------------------------+
|
||||
| sysrc | web01 | nginx_enable=YES | execute `sysrc nginx_enable=YES` in web01 jail |
|
||||
| sysrc | web01 | nginx_enable=YES | execute `sysrc nginx_enable=YES` in web01 container |
|
||||
+-----------+--------+------------------+-------------------------------------------------------------+
|
||||
| template | ALL | base | apply `base` template to ALL jails |
|
||||
| template | ALL | username/base | apply `username/base` template to ALL containers |
|
||||
+-----------+--------+------------------+-------------------------------------------------------------+
|
||||
| start | web02 | --- | start web02 jail |
|
||||
| start | web02 | --- | start web02 container |
|
||||
+-----------+--------+-----+------------+-------------------------------------------------------------+
|
||||
| cp | bastion03 | /tmp/resolv.conf-cf etc/resolv.conf | copy host-path to jail-path in bastion03 |
|
||||
| cp | bastion03 | /tmp/resolv.conf-cf etc/resolv.conf | copy host-path to container-path in bastion03|
|
||||
+----+------+----+---+------------------+--------------+----------------------------------------------+
|
||||
| create | folsom | 12.0-RELEASE 10.10.10.10 | create v12.0 jail named `folsom` with IP |
|
||||
| create | folsom | 12.0-RELEASE 10.17.89.10 | create 12.0 container named `folsom` with IP |
|
||||
+-----------+--------+------------------+--------------+----------------------------------------------+
|
||||
|
||||
|
||||
@@ -55,15 +53,14 @@ Examples: Releases
|
||||
|
||||
ishmael ~ # bastille ...
|
||||
|
||||
|
||||
+-----------+--------------+--------------+-------------------------------------------------------------+
|
||||
| command | target | args | description |
|
||||
+===========+==============+==============+=============================================================+
|
||||
| bootstrap | 12.0-RELEASE | --- | bootstrap 12.0-RELEASE release |
|
||||
+-----------+--------------+--------------+-------------------------------------------------------------+
|
||||
| update | 11.2-RELEASE | --- | update 11.2-RELEASE release |
|
||||
| update | 11.3-RELEASE | --- | update 11.2-RELEASE release |
|
||||
+-----------+--------------+--------------+-------------------------------------------------------------+
|
||||
| upgrade | 11.1-RELEASE | 11.2-RELEASE | update 11.2-RELEASE release |
|
||||
| upgrade | 11.2-RELEASE | 11.3-RELEASE | update 11.2-RELEASE release |
|
||||
+-----------+--------------+--------------+-------------------------------------------------------------+
|
||||
| verify | 11.2-RELEASE | --- | update 11.2-RELEASE release |
|
||||
| verify | 11.3-RELEASE | --- | update 11.2-RELEASE release |
|
||||
+-----------+--------------+--------------+-------------------------------------------------------------+
|
||||
|
||||
@@ -3,26 +3,26 @@ Template
|
||||
========
|
||||
|
||||
Bastille supports a templating system allowing you to apply files, pkgs and
|
||||
execute commands inside the jail automatically.
|
||||
execute commands inside the containers automatically.
|
||||
|
||||
Currently supported template hooks are: `PRE`, `CONFIG`, `PKG`, `SYSRC`, `CMD`.
|
||||
Planned template hooks include: `FSTAB`, `PF`
|
||||
Currently supported template hooks are: `PRE`, `OVERLAY`, `PKG`, `SYSRC`, `CMD`.
|
||||
Planned template hooks include: `FSTAB`, `PF`, `LOG`.
|
||||
|
||||
Templates are created in `${bastille_prefix}/templates` and can leverage any of
|
||||
the template hooks. Simply create a new directory named after the template. eg;
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
mkdir -p /usr/local/bastille/templates/base
|
||||
mkdir -p /usr/local/bastille/templates/username/base
|
||||
|
||||
To leverage a template hook, create an UPPERCASE file in the root of the
|
||||
template directory named after the hook you want to execute. eg;
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
echo "zsh vim-console git-lite htop" > /usr/local/bastille/templates/base/PKG
|
||||
echo "/usr/bin/chsh -s /usr/local/bin/zsh" > /usr/local/bastille/templates/base/CMD
|
||||
echo "etc root usr" > /usr/local/bastille/templates/base/CONFIG
|
||||
echo "zsh vim-console git-lite htop" > /usr/local/bastille/templates/username/base/PKG
|
||||
echo "/usr/bin/chsh -s /usr/local/bin/zsh" > /usr/local/bastille/templates/username/base/CMD
|
||||
echo "etc\nrootjn usr" > /usr/local/bastille/templates/username/base/OVERLAY
|
||||
|
||||
Template hooks are executed in specific order and require specific syntax to
|
||||
work as expected. This table outlines those requirements:
|
||||
@@ -31,46 +31,52 @@ work as expected. This table outlines those requirements:
|
||||
+---------+------------------+--------------------------------------+
|
||||
| HOOK | format | example |
|
||||
+=========+==================+======================================+
|
||||
| PRE/CMD | /bin/sh command | /usr/bin/chsh -s /usr/local/bin/zsh |
|
||||
| PRE | /bin/sh command | mkdir -p /usr/local/my_app/html |
|
||||
+---------+------------------+--------------------------------------+
|
||||
| CONFIG | path | etc root usr |
|
||||
| OVERLAY | path(s) | etc root usr (one per line) |
|
||||
+---------+------------------+--------------------------------------+
|
||||
| PKG | port/pkg name(s) | vim-console zsh git-lite tree htop |
|
||||
+---------+------------------+--------------------------------------+
|
||||
| SYSRC | sysrc command(s) | nginx_enable=YES |
|
||||
+---------+------------------+--------------------------------------+
|
||||
| SERVICE | service command | 'nginx start' OR 'postfix reload' |
|
||||
+---------+------------------+--------------------------------------+
|
||||
| CMD | /bin/sh command | /usr/bin/chsh -s /usr/local/bin/zsh |
|
||||
+---------+------------------+--------------------------------------+
|
||||
|
||||
Note: SYSRC requires NO quotes or that quotes (`"`) be escaped. ie; `\"`)
|
||||
Note: SYSRC requires that NO quotes be used or that quotes (`"`) be escaped.
|
||||
ie; `\"`)
|
||||
|
||||
In addition to supporting template hooks, Bastille supports overlaying
|
||||
files into the jail. This is done by placing the files in their full path,
|
||||
files into the container. This is done by placing the files in their full path,
|
||||
using the template directory as "/".
|
||||
|
||||
An example here may help. Think of `/usr/local/bastille/templates/base`,
|
||||
our example template, as the root of our filesystem overlay. If you create
|
||||
an `etc/hosts` or `etc/resolv.conf` *inside* the base template directory,
|
||||
these can be overlayed into your jail.
|
||||
An example here may help. Think of `bastille/templates/username/base`, our
|
||||
example template, as the root of our filesystem overlay. If you create an
|
||||
`etc/hosts` or `etc/resolv.conf` *inside* the base template directory, these
|
||||
can be overlayed into your container.
|
||||
|
||||
Note: due to the way FreeBSD segregates user-space, the majority of your
|
||||
overlayed template files will be in `usr/local`. The few general
|
||||
exceptions are the `etc/hosts`, `etc/resolv.conf`, and
|
||||
`etc/rc.conf.local`.
|
||||
|
||||
After populating `usr/local/` with custom config files that your jail will
|
||||
use, be sure to include `usr` in the template CONFIG definition. eg;
|
||||
After populating `usr/local/` with custom config files that your container will
|
||||
use, be sure to include `usr` in the template OVERLAY definition. eg;
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
echo "etc usr" > /usr/local/bastille/templates/base/CONFIG
|
||||
echo "etc\nusr" > /usr/local/bastille/templates/username/base/OVERLAY
|
||||
|
||||
The above example "etc usr" will include anything under "etc" and "usr"
|
||||
inside the template. You do not need to list individual files. Just
|
||||
include the top-level directory name.
|
||||
include the top-level directory name. List these top-level directories one per
|
||||
line.
|
||||
|
||||
Applying Templates
|
||||
------------------
|
||||
|
||||
Jails must be running to apply templates.
|
||||
Containers must be running to apply templates.
|
||||
|
||||
Bastille includes a `template` command. This command requires a target and a
|
||||
template name. As covered in the previous section, template names correspond to
|
||||
@@ -78,19 +84,19 @@ directory names in the `bastille/templates` directory.
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
ishmael ~ # bastille template ALL base
|
||||
[cdn]:
|
||||
ishmael ~ # bastille template ALL username/base
|
||||
[proxy01]:
|
||||
Copying files...
|
||||
Copy complete.
|
||||
Installing packages.
|
||||
pkg already bootstrapped at /usr/local/sbin/pkg
|
||||
vulnxml file up-to-date
|
||||
0 problem(s) in the installed packages found.
|
||||
Updating iniquity.io repository catalogue...
|
||||
Updating bastillebsd.org repository catalogue...
|
||||
[cdn] Fetching meta.txz: 100% 560 B 0.6kB/s 00:01
|
||||
[cdn] Fetching packagesite.txz: 100% 121 KiB 124.3kB/s 00:01
|
||||
Processing entries: 100%
|
||||
iniquity.io repository update completed. 499 packages processed.
|
||||
bastillebsd.org repository update completed. 499 packages processed.
|
||||
All repositories are up to date.
|
||||
Checking integrity... done (0 conflicting)
|
||||
The most recent version of packages are already installed
|
||||
@@ -102,23 +108,23 @@ directory names in the `bastille/templates` directory.
|
||||
chsh: user information updated
|
||||
Template Complete.
|
||||
|
||||
[poudriere]:
|
||||
[web01]:
|
||||
Copying files...
|
||||
Copy complete.
|
||||
Installing packages.
|
||||
pkg already bootstrapped at /usr/local/sbin/pkg
|
||||
vulnxml file up-to-date
|
||||
0 problem(s) in the installed packages found.
|
||||
Updating cdn.iniquity.io repository catalogue...
|
||||
Updating pkg.bastillebsd.org repository catalogue...
|
||||
[poudriere] Fetching meta.txz: 100% 560 B 0.6kB/s 00:01
|
||||
[poudriere] Fetching packagesite.txz: 100% 121 KiB 124.3kB/s 00:01
|
||||
Processing entries: 100%
|
||||
cdn.iniquity.io repository update completed. 499 packages processed.
|
||||
Updating iniquity.io repository catalogue...
|
||||
pkg.bastillebsd.org repository update completed. 499 packages processed.
|
||||
Updating bastillebsd.org repository catalogue...
|
||||
[poudriere] Fetching meta.txz: 100% 560 B 0.6kB/s 00:01
|
||||
[poudriere] Fetching packagesite.txz: 100% 121 KiB 124.3kB/s 00:01
|
||||
Processing entries: 100%
|
||||
iniquity.io repository update completed. 499 packages processed.
|
||||
bastillebsd.org repository update completed. 499 packages processed.
|
||||
All repositories are up to date.
|
||||
Checking integrity... done (0 conflicting)
|
||||
The most recent version of packages are already installed
|
||||
|
||||
@@ -1,32 +1,37 @@
|
||||
=====
|
||||
Usage
|
||||
=====
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
ishmael ~ # bastille -h
|
||||
Bastille is an open-source system for automating deployment and management of
|
||||
containerized applications on FreeBSD.
|
||||
|
||||
Usage:
|
||||
bastille command [ALL|glob] [args]
|
||||
|
||||
Available Commands:
|
||||
bootstrap Bootstrap a FreeBSD release for jail base.
|
||||
cmd Execute arbitrary command on targeted jail(s).
|
||||
console Console into a running jail.
|
||||
cp cp(1) files from host to targeted jail(s).
|
||||
create Create a new jail.
|
||||
destroy Destroy a stopped jail.
|
||||
bootstrap Bootstrap a FreeBSD release for container base.
|
||||
cmd Execute arbitrary command on targeted container(s).
|
||||
console Console into a running container.
|
||||
cp cp(1) files from host to targeted container(s).
|
||||
create Create a new thin container or a thick container if -T|--thick option specified.
|
||||
destroy Destroy a stopped container or a FreeBSD release.
|
||||
help Help about any command
|
||||
htop Interactive process viewer (requires htop).
|
||||
list List jails (running and stopped).
|
||||
pkg Manipulate binary packages within targeted jail(s). See pkg(8).
|
||||
restart Restart a running jail.
|
||||
start Start a stopped jail.
|
||||
stop Stop a running jail.
|
||||
sysrc Safely edit rc files within targeted jail(s).
|
||||
template Apply Bastille template to running jail(s).
|
||||
list List containers, releases, templates, or logs.
|
||||
pkg Manipulate binary packages within targeted container(s). See pkg(8).
|
||||
restart Restart a running container.
|
||||
service Manage services within targeted containers(s).
|
||||
start Start a stopped container.
|
||||
stop Stop a running container.
|
||||
sysrc Safely edit rc files within targeted container(s).
|
||||
template Apply file templates to targeted container(s).
|
||||
top Display and update information about the top(1) cpu processes.
|
||||
update Update jail base -pX release.
|
||||
upgrade Upgrade jail release to X.Y-RELEASE.
|
||||
update Update container base -pX release.
|
||||
upgrade Upgrade container release to X.Y-RELEASE.
|
||||
verify Compare release against a "known good" index.
|
||||
zfs Manage (get|set) zfs attributes on targeted container(s).
|
||||
|
||||
Use "bastille -v|--version" for version information.
|
||||
Use "bastille command -h|--help" for more information about a command.
|
||||
|
||||
@@ -8,13 +8,13 @@ else:
|
||||
# -- Project information -----------------------------------------------------
|
||||
|
||||
project = 'Bastille'
|
||||
copyright = '2018, Christer Edwards'
|
||||
copyright = '2018-2019, Christer Edwards'
|
||||
author = 'Christer Edwards'
|
||||
|
||||
# The short X.Y version
|
||||
version = '0.3.20181124'
|
||||
version = '0.5.20191125'
|
||||
# The full version, including alpha/beta/rc tags
|
||||
release = '0.3.20181124-beta'
|
||||
release = '0.5.20191125-beta'
|
||||
|
||||
|
||||
# -- General configuration ---------------------------------------------------
|
||||
@@ -67,7 +67,7 @@ man_pages = [
|
||||
|
||||
texinfo_documents = [
|
||||
(master_doc, 'Bastille', 'Bastille Documentation',
|
||||
author, 'Bastille', 'Bastille is a jail automation framework that allows you to quickly and easily create and manage FreeBSD jails.',
|
||||
author, 'Bastille', 'Bastille is an open-source system for automating deployment and management of containerized applications on FreeBSD.',
|
||||
'Miscellaneous'),
|
||||
]
|
||||
|
||||
|
||||
BIN
docs/images/bastillebsd-twitter-poll.png
Normal file
BIN
docs/images/bastillebsd-twitter-poll.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
@@ -17,6 +17,7 @@ https://docs.bastillebsd.org.
|
||||
chapters/targeting
|
||||
chapters/subcommands/index
|
||||
chapters/template
|
||||
chapters/jail-config
|
||||
|
||||
copyright
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
|
||||
#
|
||||
# Copyright (c) 2018-2019, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -28,39 +28,77 @@
|
||||
# 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.
|
||||
|
||||
## root check first.
|
||||
bastille_root_check() {
|
||||
if [ $(id -u) -ne 0 ]; then
|
||||
## so we can make it colorful
|
||||
. /usr/local/share/bastille/colors.pre.sh
|
||||
|
||||
## permission denied
|
||||
echo -e "${COLOR_RED}Bastille: Permission Denied${COLOR_RESET}" 1>&2
|
||||
echo -e "${COLOR_RED}root / sudo / doas required${COLOR_RESET}" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
bastille_root_check
|
||||
|
||||
## we only load the config if root_check passes
|
||||
. /usr/local/etc/bastille/bastille.conf
|
||||
. /usr/local/share/bastille/colors.pre.sh
|
||||
|
||||
## bastille_prefix should be 0750
|
||||
## this restricts file system access to privileged users
|
||||
bastille_perms_check() {
|
||||
if [ -d "${bastille_prefix}" ]; then
|
||||
BASTILLE_PREFIX_PERMS=$(stat -f "%Op" "${bastille_prefix}")
|
||||
if [ "${BASTILLE_PREFIX_PERMS}" != 40750 ]; then
|
||||
echo -e "${COLOR_RED}Insecure permissions on ${bastille_prefix}${COLOR_RESET}" 1>&2
|
||||
echo -e "${COLOR_RED}Try: chmod 0750 ${bastille_prefix}${COLOR_RESET}" 1>&2
|
||||
echo
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
bastille_perms_check
|
||||
|
||||
## we only load the config if root_check passes
|
||||
. /usr/local/etc/bastille/bastille.conf
|
||||
|
||||
## version
|
||||
BASTILLE_VERSION="0.3.20190102"
|
||||
BASTILLE_VERSION="0.5.20191125RC"
|
||||
|
||||
usage() {
|
||||
cat << EOF
|
||||
Bastille is a jail automation framework that allows you to quickly and easily
|
||||
create and manage FreeBSD jails.
|
||||
Bastille is an open-source system for automating deployment and management of
|
||||
containerized applications on FreeBSD.
|
||||
|
||||
Usage:
|
||||
bastille command [ALL|glob] [args]
|
||||
bastille command TARGET [args]
|
||||
|
||||
Available Commands:
|
||||
bootstrap Bootstrap a FreeBSD release for container base.
|
||||
cmd Execute arbitrary command on targeted container(s).
|
||||
console Console into a running container.
|
||||
cp cp(1) files from host to targeted container(s).
|
||||
create Create a new container.
|
||||
destroy Destroy a stopped container.
|
||||
create Create a new thin container or a thick container if -T|--thick option specified.
|
||||
destroy Destroy a stopped container or a FreeBSD release.
|
||||
help Help about any command
|
||||
htop Interactive process viewer (requires htop).
|
||||
list List containers (running and stopped).
|
||||
pkg Manipulate binary packages within targeted container(s). See pkg(8).
|
||||
restart Restart a running container.
|
||||
service Manage services within targeted container(s).
|
||||
start Start a stopped container.
|
||||
stop Stop a running container.
|
||||
sysrc Safely edit rc files within targeted container(s).
|
||||
template Apply file templates to targeted jail(s).
|
||||
template Apply file templates to targeted container(s).
|
||||
top Display and update information about the top(1) cpu processes.
|
||||
update Update container base -pX release.
|
||||
upgrade Upgrade container release to X.Y-RELEASE.
|
||||
verify Compare release against a "known good" index.
|
||||
zfs Manage (get|set) zfs attributes on targeted container(s).
|
||||
|
||||
Use "bastille -v|--version" for version information.
|
||||
Use "bastille command -h|--help" for more information about a command.
|
||||
@@ -77,34 +115,37 @@ shift
|
||||
# Handle special-case commands first.
|
||||
case "${CMD}" in
|
||||
version|-v|--version)
|
||||
echo -e "${COLOR_GREEN}${BASTILLE_VERSION}${COLOR_RESET}"
|
||||
exit 0
|
||||
;;
|
||||
echo -e "${COLOR_GREEN}${BASTILLE_VERSION}${COLOR_RESET}"
|
||||
exit 0
|
||||
;;
|
||||
help|-h|--help)
|
||||
usage
|
||||
;;
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
|
||||
# Filter out all non-commands
|
||||
case "${CMD}" in
|
||||
cmd|cp|create|destroy|list|pkg|restart|start|stop|sysrc|template|verify)
|
||||
;;
|
||||
update|upgrade)
|
||||
;;
|
||||
console|bootstrap|htop|top)
|
||||
;;
|
||||
bootstrap|update|upgrade)
|
||||
;;
|
||||
update|upgrade)
|
||||
;;
|
||||
service|console|bootstrap|htop|top)
|
||||
;;
|
||||
bootstrap|update|upgrade|zfs)
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
;;
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
|
||||
SCRIPTPATH="${bastille_sharedir}/${CMD}.sh"
|
||||
if [ -f "${SCRIPTPATH}" ]; then
|
||||
: ${UMASK:=022}
|
||||
umask ${UMASK}
|
||||
|
||||
: ${UMASK:=022}
|
||||
umask ${UMASK}
|
||||
: ${SH:=sh}
|
||||
|
||||
: ${SH:=sh}
|
||||
|
||||
exec ${SH} "${SCRIPTPATH}" "$@"
|
||||
exec ${SH} "${SCRIPTPATH}" "$@"
|
||||
else
|
||||
echo -e "${COLOR_RED}${SCRIPTPATH} not found.${COLOR_RESET}" 1>&2
|
||||
fi
|
||||
|
||||
@@ -1,11 +1,37 @@
|
||||
#####################
|
||||
## [ BastilleBSD ] ##
|
||||
#####################
|
||||
|
||||
## default paths
|
||||
bastille_prefix=/usr/local/bastille
|
||||
bastille_cachedir=${bastille_prefix}/cache
|
||||
bastille_jailsdir=${bastille_prefix}/jails
|
||||
bastille_logsdir=${bastille_prefix}/logs
|
||||
bastille_releasesdir=${bastille_prefix}/releases
|
||||
bastille_templatesdir=${bastille_prefix}/templates
|
||||
bastille_sharedir=/usr/local/share/bastille
|
||||
bastille_prefix=/usr/local/bastille ## default: "/usr/local/bastille"
|
||||
bastille_cachedir=${bastille_prefix}/cache ## default: ${bastille_prefix}/cache
|
||||
bastille_jailsdir=${bastille_prefix}/jails ## default: ${bastille_prefix}/jails
|
||||
bastille_logsdir=${bastille_prefix}/logs ## default: ${bastille_prefix}/logs
|
||||
bastille_releasesdir=${bastille_prefix}/releases ## default: ${bastille_prefix}/releases
|
||||
bastille_templatesdir=${bastille_prefix}/templates ## default: ${bastille_prefix}/templates
|
||||
|
||||
## bastille scripts directory (assumed by bastille pkg)
|
||||
bastille_sharedir=/usr/local/share/bastille ## default: "/usr/local/share/bastille"
|
||||
|
||||
## bootstrap archives (base, lib32, ports, src, test)
|
||||
bastille_bootstrap_archives="base" ## default: "base"
|
||||
|
||||
## default timezone
|
||||
bastille_tzdata="etc/UTC" ## default: "etc/UTC"
|
||||
|
||||
## default jail resolv.conf
|
||||
bastille_resolv_conf="/etc/resolv.conf" ## default: "/etc/resolv.conf"
|
||||
|
||||
## ZFS options
|
||||
bastille_zfs_enable="" ## default: ""
|
||||
bastille_zfs_zpool="" ## default: ""
|
||||
bastille_zfs_prefix="bastille" ## default: "${bastille_zfs_zpool}/bastille"
|
||||
bastille_zfs_mountpoint=${bastille_prefix} ## default: "${bastille_prefix}"
|
||||
bastille_zfs_options="-o compress=lz4 -o atime=off" ## default: "-o compress=lz4 -o atime=off"
|
||||
|
||||
## Networking
|
||||
bastille_jail_loopback="lo1" ## default: "lo1"
|
||||
bastille_jail_interface="bastille0" ## default: "bastille0"
|
||||
bastille_jail_external="" ## default: ""
|
||||
bastille_jail_addr="10.17.89.10" ## default: "10.17.89.10"
|
||||
bastille_jail_gateway="" ## default: ""
|
||||
|
||||
@@ -37,7 +37,7 @@ bastille_start()
|
||||
local _jail
|
||||
|
||||
for _jail in ${bastille_list}; do
|
||||
echo "Starting Bastille Jail: ${_jail}"
|
||||
echo "Starting Bastille Container: ${_jail}"
|
||||
${command} start ${_jail}
|
||||
done
|
||||
}
|
||||
@@ -52,7 +52,7 @@ bastille_stop()
|
||||
local _jail
|
||||
|
||||
for _jail in ${bastille_list}; do
|
||||
echo "Stopping Bastille Jail: ${_jail}"
|
||||
echo "Stopping Bastille Container: ${_jail}"
|
||||
${command} stop ${_jail}
|
||||
done
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2019, 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() {
|
||||
echo -e "${COLOR_RED}Usage: bastille bootstrap [release|template].${COLOR_RESET}"
|
||||
echo -e "${COLOR_RED}Usage: bastille bootstrap [release|template] [update].${COLOR_RESET}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -43,71 +43,327 @@ help|-h|--help)
|
||||
;;
|
||||
esac
|
||||
|
||||
bootstrap_release() {
|
||||
## ensure required directories are in place
|
||||
if [ ! -d ${bastille_jailsdir} ]; then
|
||||
mkdir -p ${bastille_jailsdir}
|
||||
fi
|
||||
if [ ! -d ${bastille_logsdir} ]; then
|
||||
mkdir -p ${bastille_logsdir}
|
||||
fi
|
||||
if [ ! -d ${bastille_templatesdir} ]; then
|
||||
mkdir -p ${bastille_templatesdir}
|
||||
fi
|
||||
if [ ! -d "${bastille_cachedir}/${RELEASE}" ]; then
|
||||
mkdir -p "${bastille_cachedir}/${RELEASE}"
|
||||
fi
|
||||
|
||||
### create $bastille_base/release/$release directory
|
||||
### fetch $release/base.txz -o $bastille_base/cache/$release/base.txz
|
||||
### fetch $release/lib32.txz -o $bastille_base/cache/$release/lib32.txz
|
||||
### extract $release/base.txz to $bastille_base/release/$release
|
||||
### extract $release/lib32.txz to $bastille_base/release/$release
|
||||
if [ ! -d "${bastille_releasesdir}/${RELEASE}" ]; then
|
||||
mkdir -p "${bastille_releasesdir}/${RELEASE}"
|
||||
sh ${bastille_sharedir}/freebsd_dist_fetch.sh -r ${RELEASE} base lib32
|
||||
|
||||
echo
|
||||
echo -e "${COLOR_GREEN}Extracting FreeBSD ${RELEASE} base.txz.${COLOR_RESET}"
|
||||
/usr/bin/tar -C "${bastille_releasesdir}/${RELEASE}" -xf "${bastille_cachedir}/${RELEASE}/base.txz"
|
||||
|
||||
echo -e "${COLOR_GREEN}Extracting FreeBSD ${RELEASE} lib32.txz.${COLOR_RESET}"
|
||||
/usr/bin/tar -C "${bastille_releasesdir}/${RELEASE}" -xf "${bastille_cachedir}/${RELEASE}/lib32.txz"
|
||||
|
||||
echo -e "${COLOR_GREEN}Bootstrap successful.${COLOR_RESET}"
|
||||
echo -e "${COLOR_GREEN}See 'bastille --help' for available commands.${COLOR_RESET}"
|
||||
echo
|
||||
else
|
||||
echo -e "${COLOR_RED}Bootstrap appears complete.${COLOR_RESET}"
|
||||
# Validate ZFS parameters first.
|
||||
if [ "${bastille_zfs_enable}" = "YES" ]; then
|
||||
## check for the ZFS pool and bastille prefix
|
||||
if [ -z "${bastille_zfs_zpool}" ]; then
|
||||
echo -e "${COLOR_RED}ERROR: Missing ZFS parameters, see bastille_zfs_zpool.${COLOR_RESET}"
|
||||
exit 1
|
||||
elif [ -z "${bastille_zfs_prefix}" ]; then
|
||||
echo -e "${COLOR_RED}ERROR: Missing ZFS parameters, see bastille_zfs_prefix.${COLOR_RESET}"
|
||||
exit 1
|
||||
elif ! zfs list "${bastille_zfs_zpool}" > /dev/null 2>&1; then
|
||||
echo -e "${COLOR_RED}ERROR: ${bastille_zfs_zpool} is not a ZFS pool.${COLOR_RESET}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
## check for the ZFS dataset prefix if already exist
|
||||
if [ -d "/${bastille_zfs_zpool}/${bastille_zfs_prefix}" ]; then
|
||||
if ! zfs list "${bastille_zfs_zpool}/${bastille_zfs_prefix}" > /dev/null 2>&1; then
|
||||
echo -e "${COLOR_RED}ERROR: ${bastille_zfs_zpool}/${bastille_zfs_prefix} is not a ZFS dataset.${COLOR_RESET}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
bootstrap_network_interfaces() {
|
||||
|
||||
## test for both options empty
|
||||
if [ -z ${bastille_jail_loopback} ] && [ -z ${bastille_jail_external} ]; then
|
||||
echo -e "${COLOR_RED}Please set preferred loopback or external interface.${COLOR_RESET}"
|
||||
echo -e "${COLOR_RED}See bastille.conf.${COLOR_RESET}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
## test for required variables -- external
|
||||
if [ -z ${bastille_jail_loopback} ] && [ ! -z ${bastille_jail_external} ]; then
|
||||
|
||||
## test for existing interface
|
||||
ifconfig ${bastille_jail_external} 2>&1 >/dev/null
|
||||
if [ $? = 0 ]; then
|
||||
|
||||
## create ifconfig alias
|
||||
ifconfig ${bastille_jail_external} inet ${bastille_jail_addr} alias && \
|
||||
echo -e "${COLOR_GREEN}IP alias added to ${bastille_jail_external} successfully.${COLOR_RESET}"
|
||||
echo
|
||||
|
||||
## attempt to ping gateway
|
||||
echo -e "${COLOR_YELLOW}Attempting to ping default gateway...${COLOR_RESET}"
|
||||
ping -c3 -t3 -S ${bastille_jail_addr} ${bastille_jail_gateway}
|
||||
if [ $? = 0 ]; then
|
||||
echo
|
||||
echo -e "${COLOR_GREEN}External networking appears functional.${COLOR_RESET}"
|
||||
echo
|
||||
else
|
||||
echo -e "${COLOR_RED}Unable to ping default gateway.${COLOR_RESET}"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
## test for required variables -- loopback
|
||||
if [ -z ${bastille_jail_external} ] && [ ! -z ${bastille_jail_loopback} ] && \
|
||||
[ ! -z ${bastille_jail_addr} ]; then
|
||||
|
||||
echo -e "${COLOR_GREEN}Detecting...${COLOR_RESET}"
|
||||
## test for existing interface
|
||||
ifconfig ${bastille_jail_interface} >&2 >/dev/null
|
||||
|
||||
## if above return code is 1; create interface
|
||||
if [ $? = 1 ]; then
|
||||
sysrc ifconfig_${bastille_jail_loopback}_name | grep ${bastille_jail_interface} >&2 >/dev/null
|
||||
if [ $? = 1 ]; then
|
||||
echo
|
||||
echo -e "${COLOR_GREEN}Defining secure loopback interface.${COLOR_RESET}"
|
||||
sysrc cloned_interfaces+="${bastille_jail_loopback}" &&
|
||||
sysrc ifconfig_${bastille_jail_loopback}_name="${bastille_jail_interface}"
|
||||
sysrc ifconfig_${bastille_jail_interface}_aliases+="inet ${bastille_jail_addr}/32"
|
||||
|
||||
## create and name interface; assign address
|
||||
echo
|
||||
echo -e "${COLOR_GREEN}Creating secure loopback interface.${COLOR_RESET}"
|
||||
ifconfig ${bastille_jail_loopback} create name ${bastille_jail_interface}
|
||||
ifconfig ${bastille_jail_interface} up
|
||||
ifconfig ${bastille_jail_interface} inet ${bastille_jail_addr}/32
|
||||
|
||||
## reload firewall
|
||||
pfctl -f /etc/pf.conf
|
||||
|
||||
## look for nat rule for bastille_jail_addr
|
||||
echo -e "${COLOR_GREEN}Detecting NAT from bastille0 interface...${COLOR_RESET}"
|
||||
pfctl -s nat | grep nat | grep ${bastille_jail_addr}
|
||||
if [ $? = 0 ]; then
|
||||
## test connectivity; ping from bastille_jail_addr
|
||||
echo
|
||||
echo -e "${COLOR_YELLOW}Attempting to ping default gateway...${COLOR_RESET}"
|
||||
ping -c3 -t3 -S ${bastille_jail_addr} ${bastille_jail_gateway}
|
||||
if [ $? = 0 ]; then
|
||||
echo
|
||||
echo -e "${COLOR_GREEN}Private networking appears functional.${COLOR_RESET}"
|
||||
echo
|
||||
else
|
||||
echo -e "${COLOR_RED}Unable to ping default gateway.${COLOR_RESET}"
|
||||
echo -e "${COLOR_YELLOW}See https://github.com/BastilleBSD/bastille/blob/master/README.md#etcpfconf.${COLOR_RESET}"
|
||||
echo -e
|
||||
fi
|
||||
else
|
||||
echo -e "${COLOR_RED}Unable to detect firewall 'nat' rule.${COLOR_RESET}"
|
||||
echo -e "${COLOR_YELLOW}See https://github.com/BastilleBSD/bastille/blob/master/README.md#etcpfconf.${COLOR_RESET}"
|
||||
fi
|
||||
else
|
||||
echo -e "${COLOR_RED}Interface ${bastille_jail_loopback} already configured; bailing out.${COLOR_RESET}"
|
||||
fi
|
||||
else
|
||||
echo -e "${COLOR_RED}Interface ${bastille_jail_interface} already active; bailing out.${COLOR_RESET}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
bootstrap_directories() {
|
||||
## ensure required directories are in place
|
||||
|
||||
## ${bastille_prefix}
|
||||
if [ ! -d "${bastille_prefix}" ]; then
|
||||
if [ "${bastille_zfs_enable}" = "YES" ];then
|
||||
if [ ! -z "${bastille_zfs_zpool}" ]; then
|
||||
zfs create ${bastille_zfs_options} -o mountpoint=${bastille_prefix} ${bastille_zfs_zpool}/${bastille_zfs_prefix}
|
||||
fi
|
||||
else
|
||||
mkdir -p "${bastille_prefix}"
|
||||
chmod 0750 "${bastille_prefix}"
|
||||
fi
|
||||
fi
|
||||
|
||||
## ${bastille_cachedir}
|
||||
if [ ! -d "${bastille_cachedir}" ]; then
|
||||
if [ "${bastille_zfs_enable}" = "YES" ]; then
|
||||
if [ ! -z "${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}
|
||||
fi
|
||||
else
|
||||
mkdir -p "${bastille_cachedir}/${RELEASE}"
|
||||
fi
|
||||
## create subsequent cache/XX.X-RELEASE datasets
|
||||
elif [ ! -d "${bastille_cachedir}/${RELEASE}" ]; then
|
||||
if [ "${bastille_zfs_enable}" = "YES" ]; then
|
||||
if [ ! -z "${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
|
||||
fi
|
||||
|
||||
## ${bastille_jailsdir}
|
||||
if [ ! -d "${bastille_jailsdir}" ]; then
|
||||
if [ "${bastille_zfs_enable}" = "YES" ]; then
|
||||
if [ ! -z "${bastille_zfs_zpool}" ]; then
|
||||
zfs create ${bastille_zfs_options} -o mountpoint=${bastille_jailsdir} ${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails
|
||||
fi
|
||||
else
|
||||
mkdir -p "${bastille_jailsdir}"
|
||||
fi
|
||||
fi
|
||||
|
||||
## ${bastille_logsdir}
|
||||
if [ ! -d "${bastille_logsdir}" ]; then
|
||||
if [ "${bastille_zfs_enable}" = "YES" ]; then
|
||||
if [ ! -z "${bastille_zfs_zpool}" ]; then
|
||||
zfs create ${bastille_zfs_options} -o mountpoint=${bastille_logsdir} ${bastille_zfs_zpool}/${bastille_zfs_prefix}/logs
|
||||
fi
|
||||
else
|
||||
mkdir -p "${bastille_logsdir}"
|
||||
fi
|
||||
fi
|
||||
|
||||
## ${bastille_templatesdir}
|
||||
if [ ! -d "${bastille_templatesdir}" ]; then
|
||||
if [ "${bastille_zfs_enable}" = "YES" ]; then
|
||||
if [ ! -z "${bastille_zfs_zpool}" ]; then
|
||||
zfs create ${bastille_zfs_options} -o mountpoint=${bastille_templatesdir} ${bastille_zfs_zpool}/${bastille_zfs_prefix}/templates
|
||||
fi
|
||||
else
|
||||
mkdir -p "${bastille_templatesdir}"
|
||||
fi
|
||||
fi
|
||||
|
||||
## ${bastille_releasesdir}
|
||||
if [ ! -d "${bastille_releasesdir}" ]; then
|
||||
if [ "${bastille_zfs_enable}" = "YES" ]; then
|
||||
if [ ! -z "${bastille_zfs_zpool}" ]; then
|
||||
zfs create ${bastille_zfs_options} -o mountpoint=${bastille_releasesdir} ${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases
|
||||
zfs create ${bastille_zfs_options} -o mountpoint=${bastille_releasesdir}/${RELEASE} ${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${RELEASE}
|
||||
fi
|
||||
else
|
||||
mkdir -p "${bastille_releasesdir}/${RELEASE}"
|
||||
fi
|
||||
## create subsequent releases/XX.X-RELEASE datasets
|
||||
elif [ ! -d "${bastille_releasesdir}/${RELEASE}" ]; then
|
||||
if [ "${bastille_zfs_enable}" = "YES" ]; then
|
||||
if [ ! -z "${bastille_zfs_zpool}" ]; then
|
||||
zfs create ${bastille_zfs_options} -o mountpoint=${bastille_releasesdir}/${RELEASE} ${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${RELEASE}
|
||||
fi
|
||||
else
|
||||
mkdir -p "${bastille_releasesdir}/${RELEASE}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
bootstrap_release() {
|
||||
## if release exists, quit
|
||||
if [ -f "${bastille_releasesdir}/${RELEASE}/COPYRIGHT" ]; then
|
||||
echo -e "${COLOR_RED}Bootstrap appears complete.${COLOR_RESET}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for _archive in ${bastille_bootstrap_archives}; do
|
||||
## check if the dist files already exists then extract
|
||||
FETCH_VALIDATION="0"
|
||||
if [ -f "${bastille_cachedir}/${RELEASE}/${_archive}.txz" ]; then
|
||||
echo -e "${COLOR_GREEN}Extracting FreeBSD ${RELEASE} ${_archive}.txz.${COLOR_RESET}"
|
||||
/usr/bin/tar -C "${bastille_releasesdir}/${RELEASE}" -xf "${bastille_cachedir}/${RELEASE}/${_archive}.txz"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo -e "${COLOR_RED}Failed to extract ${_archive}.txz.${COLOR_RESET}"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
## get the manifest for dist files checksum validation
|
||||
if [ ! -f "${bastille_cachedir}/${RELEASE}/MANIFEST" ]; then
|
||||
fetch ${UPSTREAM_URL}/MANIFEST -o ${bastille_cachedir}/${RELEASE}/MANIFEST || FETCH_VALIDATION="1"
|
||||
fi
|
||||
|
||||
if [ "${FETCH_VALIDATION}" -ne "0" ]; then
|
||||
## perform cleanup only for stale/empty directories on failure
|
||||
if [ "${bastille_zfs_enable}" = "YES" ]; then
|
||||
if [ ! -z "${bastille_zfs_zpool}" ]; then
|
||||
if [ ! "$(ls -A ${bastille_cachedir}/${RELEASE})" ]; then
|
||||
zfs destroy ${bastille_zfs_zpool}/${bastille_zfs_prefix}/cache/${RELEASE}
|
||||
fi
|
||||
if [ ! "$(ls -A ${bastille_releasesdir}/${RELEASE})" ]; then
|
||||
zfs destroy ${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${RELEASE}
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
if [ -d "${bastille_cachedir}/${RELEASE}" ]; then
|
||||
if [ ! "$(ls -A ${bastille_cachedir}/${RELEASE})" ]; then
|
||||
rm -rf ${bastille_cachedir}/${RELEASE}
|
||||
fi
|
||||
fi
|
||||
if [ -d "${bastille_releasesdir}/${RELEASE}" ]; then
|
||||
if [ ! "$(ls -A ${bastille_releasesdir}/${RELEASE})" ]; then
|
||||
rm -rf ${bastille_releasesdir}/${RELEASE}
|
||||
fi
|
||||
fi
|
||||
echo -e "${COLOR_RED}Bootstrap failed.${COLOR_RESET}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
## fetch for missing dist files
|
||||
if [ ! -f "${bastille_cachedir}/${RELEASE}/${_archive}.txz" ]; then
|
||||
fetch ${UPSTREAM_URL}/${_archive}.txz -o ${bastille_cachedir}/${RELEASE}/${_archive}.txz
|
||||
if [ $? -ne 0 ]; then
|
||||
## alert only if unable to fetch additional dist files
|
||||
echo -e "${COLOR_RED}Failed to fetch ${_archive}.txz.${COLOR_RESET}"
|
||||
fi
|
||||
fi
|
||||
|
||||
## compare checksums on the fetched dist files
|
||||
if [ -f "${bastille_cachedir}/${RELEASE}/${_archive}.txz" ]; then
|
||||
SHA256_DIST=$(grep -w "${_archive}.txz" ${bastille_cachedir}/${RELEASE}/MANIFEST | awk '{print $2}')
|
||||
SHA256_FILE=$(sha256 -q ${bastille_cachedir}/${RELEASE}/${_archive}.txz)
|
||||
if [ "${SHA256_FILE}" != "${SHA256_DIST}" ]; then
|
||||
echo -e "${COLOR_RED}Failed validation for ${_archive}.txz, please retry bootstrap!${COLOR_RESET}"
|
||||
rm ${bastille_cachedir}/${RELEASE}/${_archive}.txz
|
||||
exit 1
|
||||
else
|
||||
echo -e "${COLOR_GREEN}Validated checksum for ${RELEASE}:${_archive}.txz.${COLOR_RESET}"
|
||||
echo -e "${COLOR_GREEN}MANIFEST:${SHA256_DIST}${COLOR_RESET}"
|
||||
echo -e "${COLOR_GREEN}DOWNLOAD:${SHA256_FILE}${COLOR_RESET}"
|
||||
fi
|
||||
fi
|
||||
|
||||
## extract the fetched dist files
|
||||
if [ -f "${bastille_cachedir}/${RELEASE}/${_archive}.txz" ]; then
|
||||
echo -e "${COLOR_GREEN}Extracting FreeBSD ${RELEASE} ${_archive}.txz.${COLOR_RESET}"
|
||||
/usr/bin/tar -C "${bastille_releasesdir}/${RELEASE}" -xf "${bastille_cachedir}/${RELEASE}/${_archive}.txz"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo -e "${COLOR_RED}Failed to extract ${_archive}.txz.${COLOR_RESET}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done
|
||||
echo
|
||||
|
||||
echo -e "${COLOR_GREEN}Bootstrap successful.${COLOR_RESET}"
|
||||
echo -e "${COLOR_GREEN}See 'bastille --help' for available commands.${COLOR_RESET}"
|
||||
echo
|
||||
}
|
||||
|
||||
bootstrap_template() {
|
||||
|
||||
## ${bastille_templatesdir}
|
||||
if [ ! -d "${bastille_templatesdir}" ]; then
|
||||
if [ "${bastille_zfs_enable}" = "YES" ]; then
|
||||
if [ ! -z "${bastille_zfs_zpool}" ]; then
|
||||
zfs create ${bastille_zfs_options} -o mountpoint=${bastille_templatesdir} ${bastille_zfs_zpool}/${bastille_zfs_prefix}/templates
|
||||
fi
|
||||
else
|
||||
mkdir -p "${bastille_templatesdir}"
|
||||
fi
|
||||
fi
|
||||
|
||||
## define basic variables
|
||||
_url=${BASTILLE_TEMPLATE_URL}
|
||||
_user=${BASTILLE_TEMPLATE_USER}
|
||||
_repo=${BASTILLE_TEMPLATE_REPO}
|
||||
_template=${bastille_templatesdir}/${_user}/${_repo}
|
||||
|
||||
## verify essential directories are in place
|
||||
if [ ! -d ${bastille_jailsdir} ]; then
|
||||
mkdir -p ${bastille_jailsdir}
|
||||
fi
|
||||
if [ ! -d ${bastille_logsdir} ]; then
|
||||
mkdir -p ${bastille_logsdir}
|
||||
fi
|
||||
if [ ! -d ${bastille_templatesdir} ]; then
|
||||
mkdir -p ${bastille_templatesdir}
|
||||
fi
|
||||
if [ ! -d ${_template} ]; then
|
||||
mkdir -p ${_template}
|
||||
fi
|
||||
|
||||
## support for non-git
|
||||
if [ ! -x /usr/local/bin/git ]; then
|
||||
echo -e "${COLOR_RED}We're gonna have to use fetch. Strap in.${COLOR_RESET}"
|
||||
echo -e "${COLOR_RED}Not yet implemented...${COLOR_RESET}"
|
||||
echo -e "${COLOR_RED}We're gonna have to use fetch. Strap in.${COLOR_RESET}"
|
||||
echo -e "${COLOR_RED}Not yet implemented...${COLOR_RESET}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
## support for git
|
||||
@@ -135,22 +391,36 @@ bootstrap_template() {
|
||||
echo
|
||||
fi
|
||||
done
|
||||
if [ -s ${_template}/CONFIG ]; then
|
||||
|
||||
# template overlay
|
||||
if [ -s ${_template}/OVERLAY ]; then
|
||||
_hook_validate=$((_hook_validate+1))
|
||||
echo -e "${COLOR_GREEN}Detected CONFIG hook.${COLOR_RESET}"
|
||||
echo -e "${COLOR_GREEN}Detected OVERLAY hook.${COLOR_RESET}"
|
||||
while read _dir; do
|
||||
echo -e "${COLOR_GREEN}[${_dir}]:${COLOR_RESET}"
|
||||
tree -a ${_template}/${_dir}
|
||||
done < ${_template}/CONFIG
|
||||
if [ -x $(which tree) ]; then
|
||||
tree -a ${_template}/${_dir}
|
||||
fi
|
||||
done < ${_template}/OVERLAY
|
||||
echo
|
||||
fi
|
||||
if [ -s ${_template}/CONFIG ]; then
|
||||
echo -e "${COLOR_GREEN}Detected CONFIG hook.${COLOR_RESET}"
|
||||
echo -e "${COLOR_YELLOW}CONFIG deprecated; rename to OVERLAY.${COLOR_RESET}"
|
||||
while read _dir; do
|
||||
echo -e "${COLOR_GREEN}[${_dir}]:${COLOR_RESET}"
|
||||
if [ -x $(which tree) ]; then
|
||||
tree -a ${_template}/${_dir}
|
||||
fi
|
||||
done < ${_template}/CONFIG
|
||||
fi
|
||||
|
||||
## remove bad templates
|
||||
if [ ${_hook_validate} -lt 1 ]; then
|
||||
echo -e "${COLOR_GREEN}Template validation failed.${COLOR_RESET}"
|
||||
echo -e "${COLOR_GREEN}Deleting template.${COLOR_RESET}"
|
||||
rm -rf ${_template}
|
||||
exit 1
|
||||
exit 1
|
||||
fi
|
||||
|
||||
## if validated; ready to use
|
||||
@@ -160,29 +430,37 @@ bootstrap_template() {
|
||||
fi
|
||||
}
|
||||
|
||||
#Usage: bastille bootstrap [release|template].${COLOR_RESET}"
|
||||
HW_MACHINE=$(sysctl hw.machine | awk '{ print $2 }')
|
||||
HW_MACHINE_ARCH=$(sysctl hw.machine_arch | awk '{ print $2 }')
|
||||
RELEASE="${1}"
|
||||
|
||||
# Filter sane release names
|
||||
## Filter sane release names
|
||||
case "${1}" in
|
||||
10.1-RELEASE|10.2-RELEASE|10.3-RELEASE|10.4-RELEASE)
|
||||
RELEASE="${1}"
|
||||
*-RELEASE|*-release|*-RC1|*-rc1|*-RC2|*-rc2)
|
||||
## check for FreeBSD releases name
|
||||
NAME_VERIFY=$(echo "${RELEASE}" | grep -iwE '^([1-9]{2,2})\.[0-9](-RELEASE|-RC[1-2])$' | tr '[:lower:]' '[:upper:]')
|
||||
if [ -n "${NAME_VERIFY}" ]; then
|
||||
RELEASE="${NAME_VERIFY}"
|
||||
UPSTREAM_URL="http://ftp.freebsd.org/pub/FreeBSD/releases/${HW_MACHINE}/${HW_MACHINE_ARCH}/${RELEASE}"
|
||||
bootstrap_directories
|
||||
bootstrap_release
|
||||
echo -e "${COLOR_RED}WARNING: FreeBSD 10.1-RELEASE HAS PASSED ITS END-OF-LIFE DATE.${COLOR_RESET}"
|
||||
else
|
||||
usage
|
||||
fi
|
||||
;;
|
||||
11.0-RELEASE|11.1-RELEASE)
|
||||
RELEASE="${1}"
|
||||
*-stable-LAST|*-STABLE-last|*-stable-last|*-STABLE-LAST)
|
||||
## check for HardenedBSD releases name
|
||||
NAME_VERIFY=$(echo "${RELEASE}" | grep -iwE '^([1-9]{2,2})(-stable-LAST|-STABLE-last|-stable-last|-STABLE-LAST)$' | sed 's/STABLE/stable/g' | sed 's/last/LAST/g')
|
||||
if [ -n "${NAME_VERIFY}" ]; then
|
||||
RELEASE="${NAME_VERIFY}"
|
||||
UPSTREAM_URL="https://installer.hardenedbsd.org/pub/HardenedBSD/releases/${HW_MACHINE}/${HW_MACHINE_ARCH}/hardenedbsd-${RELEASE}"
|
||||
bootstrap_directories
|
||||
bootstrap_release
|
||||
echo -e "${COLOR_RED}WARNING: FreeBSD 11.0-RELEASE HAS PASSED ITS END-OF-LIFE DATE.${COLOR_RESET}"
|
||||
else
|
||||
usage
|
||||
fi
|
||||
;;
|
||||
11.2-RELEASE)
|
||||
RELEASE="${1}"
|
||||
bootstrap_release
|
||||
;;
|
||||
12.0-RELEASE)
|
||||
RELEASE="${1}"
|
||||
bootstrap_release
|
||||
;;
|
||||
http?://github.com/*/*)
|
||||
http?://github.com/*/*|http?://gitlab.com/*/*)
|
||||
BASTILLE_TEMPLATE_URL=${1}
|
||||
BASTILLE_TEMPLATE_USER=$(echo "${1}" | awk -F / '{ print $4 }')
|
||||
BASTILLE_TEMPLATE_REPO=$(echo "${1}" | awk -F / '{ print $5 }')
|
||||
@@ -190,7 +468,16 @@ http?://github.com/*/*)
|
||||
echo
|
||||
bootstrap_template
|
||||
;;
|
||||
network)
|
||||
bootstrap_network_interfaces
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
|
||||
case "${2}" in
|
||||
update)
|
||||
bastille update "${RELEASE}"
|
||||
;;
|
||||
esac
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2019, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -31,7 +31,7 @@
|
||||
. /usr/local/share/bastille/colors.pre.sh
|
||||
|
||||
usage() {
|
||||
echo -e "${COLOR_RED}Usage: bastille cmd [ALL|glob] 'quoted command'.${COLOR_RESET}"
|
||||
echo -e "${COLOR_RED}Usage: bastille cmd TARGET command.${COLOR_RESET}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -42,19 +42,22 @@ help|-h|--help)
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ $# -gt 2 ] || [ $# -lt 2 ]; then
|
||||
if [ $# -lt 2 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
if [ "$1" = 'ALL' ]; then
|
||||
TARGET="${1}"
|
||||
shift
|
||||
|
||||
if [ "${TARGET}" = 'ALL' ]; then
|
||||
JAILS=$(jls name)
|
||||
fi
|
||||
if [ "$1" != 'ALL' ]; then
|
||||
JAILS=$(jls name | grep -E "(^|\b)${1}($|\b)")
|
||||
if [ "${TARGET}" != 'ALL' ]; then
|
||||
JAILS=$(jls name | grep -w "${TARGET}")
|
||||
fi
|
||||
|
||||
for _jail in ${JAILS}; do
|
||||
echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}"
|
||||
jexec -l ${_jail} $2
|
||||
jexec -l ${_jail} $@
|
||||
echo
|
||||
done
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2019, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -31,7 +31,7 @@
|
||||
. /usr/local/share/bastille/colors.pre.sh
|
||||
|
||||
usage() {
|
||||
echo -e "${COLOR_RED}Usage: bastille console [ALL|glob]'.${COLOR_RESET}"
|
||||
echo -e "${COLOR_RED}Usage: bastille console TARGET [user]'.${COLOR_RESET}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -42,18 +42,27 @@ help|-h|--help)
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ $# -gt 1 ] || [ $# -lt 1 ]; then
|
||||
if [ $# -gt 2 ] || [ $# -lt 1 ]; then
|
||||
usage
|
||||
fi
|
||||
if [ "$1" = 'ALL' ]; then
|
||||
|
||||
TARGET="${1}"
|
||||
shift
|
||||
USER="${1}"
|
||||
|
||||
if [ "${TARGET}" = 'ALL' ]; then
|
||||
JAILS=$(jls name)
|
||||
fi
|
||||
if [ "$1" != 'ALL' ]; then
|
||||
JAILS=$(jls name | grep -E "(^|\b)${1}($|\b)")
|
||||
if [ "${TARGET}" != 'ALL' ]; then
|
||||
JAILS=$(jls name | grep -w "${TARGET}")
|
||||
fi
|
||||
|
||||
for _jail in ${JAILS}; do
|
||||
echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}"
|
||||
jexec -l ${_jail} /usr/bin/login -f root
|
||||
if [ ! -z "${USER}" ]; then
|
||||
jexec -l ${_jail} /usr/bin/login -f "${USER}"
|
||||
else
|
||||
jexec -l ${_jail} /usr/bin/login -f root
|
||||
fi
|
||||
echo
|
||||
done
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2019, 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() {
|
||||
echo -e "${COLOR_RED}Usage: bastille cp [ALL|glob] '/path/to/source' 'path/to/dest'.${COLOR_RESET}"
|
||||
echo -e "${COLOR_RED}Usage: bastille cp TARGET HOST_PATH CONTAINER_PATH${COLOR_RESET}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -47,16 +47,20 @@ if [ $# -gt 3 ] || [ $# -lt 3 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
if [ "$1" = 'ALL' ]; then
|
||||
TARGET="${1}"
|
||||
CPSOURCE="${2}"
|
||||
CPDEST="${3}"
|
||||
|
||||
if [ "${TARGET}" = 'ALL' ]; then
|
||||
JAILS=$(jls name)
|
||||
fi
|
||||
if [ "$1" != 'ALL' ]; then
|
||||
JAILS=$(jls name | grep -E "(^|\b)${1}($|\b)")
|
||||
if [ "${TARGET}" != 'ALL' ]; then
|
||||
JAILS=$(jls name | grep -w "${TARGET}")
|
||||
fi
|
||||
|
||||
for _jail in ${JAILS}; do
|
||||
bastille_jail_path="$(jls -j "${_jail}" path)"
|
||||
echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}"
|
||||
cp -a "$2" "${bastille_jail_path}/$3"
|
||||
cp -av "${CPSOURCE}" "${bastille_jail_path}/${CPDEST}"
|
||||
echo
|
||||
done
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2019, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -32,17 +32,17 @@
|
||||
. /usr/local/etc/bastille/bastille.conf
|
||||
|
||||
usage() {
|
||||
echo -e "${COLOR_RED}Usage: bastille create name release ip.${COLOR_RESET}"
|
||||
echo -e "${COLOR_RED}Usage: bastille create [option] name release ip [interface].${COLOR_RESET}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
running_jail() {
|
||||
jls name | grep -E "(^|\b)${NAME}($|\b)"
|
||||
jls name | grep -w "${NAME}"
|
||||
}
|
||||
|
||||
validate_ip() {
|
||||
local IFS
|
||||
ip=${IP}
|
||||
|
||||
if expr "$ip" : '[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$' >/dev/null; then
|
||||
IFS=.
|
||||
set $ip
|
||||
@@ -54,10 +54,39 @@ validate_ip() {
|
||||
done
|
||||
echo -e "${COLOR_GREEN}Valid: ($ip).${COLOR_RESET}"
|
||||
else
|
||||
echo -e "${COLOR_RED}Invalid: ($ip).${COLOR_RESET}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
validate_netif() {
|
||||
local LIST_INTERFACES=$(ifconfig -l)
|
||||
interface=${INTERFACE}
|
||||
if echo "${LIST_INTERFACES}" | grep -qwo "${INTERFACE}"; then
|
||||
echo -e "${COLOR_GREEN}Valid: ($interface).${COLOR_RESET}"
|
||||
else
|
||||
echo -e "${COLOR_RED}Invalid: ($interface).${COLOR_RESET}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
validate_netconf() {
|
||||
if [ ! -z "${bastille_jail_external}" ]; then
|
||||
break
|
||||
elif [ ! -z ${bastille_jail_loopback} ] && [ -z ${bastille_jail_external} ]; then
|
||||
if [ -z "${bastille_jail_interface}" ]; then
|
||||
echo -e "${COLOR_RED}Invalid network configuration.${COLOR_RESET}"
|
||||
exit 1
|
||||
fi
|
||||
elif [ -z ${bastille_jail_loopback} ] && [ ! -z ${bastille_jail_interface} ]; then
|
||||
echo -e "${COLOR_RED}Invalid network configuration.${COLOR_RESET}"
|
||||
exit 1
|
||||
elif [ -z ${bastille_jail_external} ]; then
|
||||
echo -e "${COLOR_RED}Invalid network configuration.${COLOR_RESET}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
create_jail() {
|
||||
bastille_jail_base="${bastille_jailsdir}/${NAME}/root/.bastille" ## dir
|
||||
bastille_jail_template="${bastille_jailsdir}/${NAME}/root/.template" ## dir
|
||||
@@ -65,12 +94,32 @@ create_jail() {
|
||||
bastille_jail_fstab="${bastille_jailsdir}/${NAME}/fstab" ## file
|
||||
bastille_jail_conf="${bastille_jailsdir}/${NAME}/jail.conf" ## file
|
||||
bastille_jail_log="${bastille_logsdir}/${NAME}_console.log" ## file
|
||||
bastille_jail_rc_conf="${bastille_jailsdir}/${NAME}/root/etc/rc.conf.local" ## file
|
||||
bastille_jail_rc_conf="${bastille_jailsdir}/${NAME}/root/etc/rc.conf" ## file
|
||||
bastille_jail_resolv_conf="${bastille_jailsdir}/${NAME}/root/etc/resolv.conf" ## file
|
||||
|
||||
if [ ! -d "${bastille_jailsdir}/${NAME}" ]; then
|
||||
if [ "${bastille_zfs_enable}" = "YES" ]; then
|
||||
if [ ! -z "${bastille_zfs_zpool}" ]; then
|
||||
## create required zfs datasets
|
||||
zfs create ${bastille_zfs_options} ${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NAME}
|
||||
if [ -z "${THICK_JAIL}" ]; then
|
||||
zfs create ${bastille_zfs_options} -o mountpoint=${bastille_jailsdir}/${NAME}/root ${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NAME}/root
|
||||
fi
|
||||
fi
|
||||
else
|
||||
mkdir -p "${bastille_jailsdir}/${NAME}"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -d "${bastille_jail_base}" ]; then
|
||||
mkdir -p "${bastille_jail_base}"
|
||||
fi
|
||||
|
||||
if [ ! -d "${bastille_jail_path}/usr/home" ]; then
|
||||
mkdir -p "${bastille_jail_path}/usr/home"
|
||||
fi
|
||||
|
||||
if [ ! -d "${bastille_jail_path}/usr/local" ]; then
|
||||
mkdir -p "${bastille_jail_path}/usr/local"
|
||||
fi
|
||||
|
||||
@@ -79,17 +128,44 @@ create_jail() {
|
||||
fi
|
||||
|
||||
if [ ! -f "${bastille_jail_fstab}" ]; then
|
||||
echo -e "${bastille_releasesdir}/${RELEASE} ${bastille_jail_base} nullfs ro 0 0" > ${bastille_jail_fstab}
|
||||
if [ -z "${THICK_JAIL}" ]; then
|
||||
echo -e "${bastille_releasesdir}/${RELEASE} ${bastille_jail_base} nullfs ro 0 0" > ${bastille_jail_fstab}
|
||||
else
|
||||
touch ${bastille_jail_fstab}
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -f "${bastille_jail_conf}" ]; then
|
||||
echo -e "interface = lo1;\nhost.hostname = ${NAME};\nexec.consolelog =\
|
||||
${bastille_jail_log};\npath = ${bastille_jail_path};\nip6 =\
|
||||
disable;\nsecurelevel = 2;\ndevfs_ruleset = 4;\nenforce_statfs =\
|
||||
2;\nexec.start = '/bin/sh /etc/rc';\nexec.stop = '/bin/sh\
|
||||
/etc/rc.shutdown';\nexec.clean;\nmount.devfs;\nmount.fstab =\
|
||||
${bastille_jail_fstab};\n\n${NAME} {\n\tip4.addr = ${IP};\n}" >\
|
||||
${bastille_jail_conf}
|
||||
if [ -z ${bastille_jail_loopback} ] && [ ! -z ${bastille_jail_external} ]; then
|
||||
local bastille_jail_conf_interface=${bastille_jail_external}
|
||||
fi
|
||||
if [ ! -z ${bastille_jail_loopback} ] && [ -z ${bastille_jail_external} ]; then
|
||||
local bastille_jail_conf_interface=${bastille_jail_interface}
|
||||
fi
|
||||
if [ ! -z ${INTERFACE} ]; then
|
||||
local bastille_jail_conf_interface=${INTERFACE}
|
||||
fi
|
||||
|
||||
## generate the jail configuration file
|
||||
cat << EOF > ${bastille_jail_conf}
|
||||
interface = ${bastille_jail_conf_interface};
|
||||
host.hostname = ${NAME};
|
||||
exec.consolelog = ${bastille_jail_log};
|
||||
path = ${bastille_jail_path};
|
||||
ip6 = disable;
|
||||
securelevel = 2;
|
||||
devfs_ruleset = 4;
|
||||
enforce_statfs = 2;
|
||||
exec.start = '/bin/sh /etc/rc';
|
||||
exec.stop = '/bin/sh /etc/rc.shutdown';
|
||||
exec.clean;
|
||||
mount.devfs;
|
||||
mount.fstab = ${bastille_jail_fstab};
|
||||
|
||||
${NAME} {
|
||||
ip4.addr = ${IP};
|
||||
}
|
||||
EOF
|
||||
fi
|
||||
|
||||
## using relative paths here
|
||||
@@ -98,48 +174,96 @@ create_jail() {
|
||||
echo
|
||||
echo -e "${COLOR_GREEN}NAME: ${NAME}.${COLOR_RESET}"
|
||||
echo -e "${COLOR_GREEN}IP: ${IP}.${COLOR_RESET}"
|
||||
if [ ! -z ${INTERFACE} ]; then
|
||||
echo -e "${COLOR_GREEN}INTERFACE: ${INTERFACE}.${COLOR_RESET}"
|
||||
fi
|
||||
echo -e "${COLOR_GREEN}RELEASE: ${RELEASE}.${COLOR_RESET}"
|
||||
echo
|
||||
|
||||
for _link in bin boot lib libexec rescue sbin usr/bin usr/include usr/lib usr/lib32 usr/libdata usr/libexec usr/sbin usr/share usr/src; do
|
||||
ln -sf /.bastille/${_link} ${_link}
|
||||
done
|
||||
if [ -z "${THICK_JAIL}" ]; then
|
||||
for _link in bin boot lib libexec rescue sbin usr/bin usr/include usr/lib usr/lib32 usr/libdata usr/libexec usr/sbin usr/share usr/src; do
|
||||
ln -sf /.bastille/${_link} ${_link}
|
||||
done
|
||||
fi
|
||||
|
||||
## link home properly
|
||||
ln -s usr/home home
|
||||
|
||||
## rw
|
||||
cp -a "${bastille_releasesdir}/${RELEASE}/.cshrc" "${bastille_jail_path}"
|
||||
cp -a "${bastille_releasesdir}/${RELEASE}/.profile" "${bastille_jail_path}"
|
||||
cp -a "${bastille_releasesdir}/${RELEASE}/COPYRIGHT" "${bastille_jail_path}"
|
||||
cp -a "${bastille_releasesdir}/${RELEASE}/dev" "${bastille_jail_path}"
|
||||
cp -a "${bastille_releasesdir}/${RELEASE}/etc" "${bastille_jail_path}"
|
||||
cp -a "${bastille_releasesdir}/${RELEASE}/media" "${bastille_jail_path}"
|
||||
cp -a "${bastille_releasesdir}/${RELEASE}/mnt" "${bastille_jail_path}"
|
||||
if [ "${RELEASE}" == "11.2-RELEASE" ]; then cp -a "${bastille_releasesdir}/${RELEASE}/net" "${bastille_jail_path}"; fi
|
||||
cp -a "${bastille_releasesdir}/${RELEASE}/proc" "${bastille_jail_path}"
|
||||
cp -a "${bastille_releasesdir}/${RELEASE}/root" "${bastille_jail_path}"
|
||||
cp -a "${bastille_releasesdir}/${RELEASE}/tmp" "${bastille_jail_path}"
|
||||
cp -a "${bastille_releasesdir}/${RELEASE}/var" "${bastille_jail_path}"
|
||||
cp -a "${bastille_releasesdir}/${RELEASE}/usr/obj" "${bastille_jail_path}"
|
||||
if [ "${RELEASE}" == "11.2-RELEASE" ]; then cp -a "${bastille_releasesdir}/${RELEASE}/usr/tests" "${bastille_jail_path}"; fi
|
||||
if [ -z "${THICK_JAIL}" ]; then
|
||||
## rw
|
||||
## copy only required files for thin jails
|
||||
FILE_LIST=".cshrc .profile COPYRIGHT dev etc media mnt net proc root tmp var usr/obj usr/tests"
|
||||
for files in ${FILE_LIST}; do
|
||||
if [ -f "${bastille_releasesdir}/${RELEASE}/${files}" ] || [ -d "${bastille_releasesdir}/${RELEASE}/${files}" ]; then
|
||||
cp -a "${bastille_releasesdir}/${RELEASE}/${files}" "${bastille_jail_path}/${files}"
|
||||
if [ $? -ne 0 ]; then
|
||||
## notify and clean stale files/directories
|
||||
echo -e "${COLOR_RED}Failed to copy release files, please retry create!${COLOR_RESET}"
|
||||
bastille destroy ${NAME}
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
done
|
||||
else
|
||||
echo -e "${COLOR_GREEN}Creating a thickjail, this may take a while...${COLOR_RESET}"
|
||||
if [ "${bastille_zfs_enable}" = "YES" ]; then
|
||||
if [ ! -z "${bastille_zfs_zpool}" ]; then
|
||||
## perform release base replication
|
||||
|
||||
## rc.conf.local
|
||||
## sane bastille zfs options
|
||||
ZFS_OPTIONS=$(echo ${bastille_zfs_options} | sed 's/-o//g')
|
||||
|
||||
## take a temp snapshot of the base release
|
||||
SNAP_NAME="bastille-$(date +%Y-%m-%d-%H%M%S)"
|
||||
zfs snapshot ${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${RELEASE}@${SNAP_NAME}
|
||||
|
||||
## replicate the release base to the new thickjail and set the default mountpoint
|
||||
zfs send -R ${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${RELEASE}@${SNAP_NAME} | \
|
||||
zfs receive ${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NAME}/root
|
||||
zfs set ${ZFS_OPTIONS} mountpoint=${bastille_jailsdir}/${NAME}/root ${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NAME}/root
|
||||
|
||||
## cleanup temp snapshots initially
|
||||
zfs destroy ${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${RELEASE}@${SNAP_NAME}
|
||||
zfs destroy ${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NAME}/root@${SNAP_NAME}
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
## notify and clean stale files/directories
|
||||
echo -e "${COLOR_RED}Failed release base replication, please retry create!${COLOR_RESET}"
|
||||
bastille destroy ${NAME}
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
else
|
||||
## copy all files for thick jails
|
||||
cp -a "${bastille_releasesdir}/${RELEASE}/" "${bastille_jail_path}"
|
||||
if [ $? -ne 0 ]; then
|
||||
## notify and clean stale files/directories
|
||||
echo -e "${COLOR_RED}Failed to copy release files, please retry create!${COLOR_RESET}"
|
||||
bastille destroy ${NAME}
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
## rc.conf
|
||||
## + syslogd_flags="-ss"
|
||||
## + sendmail_none="NONE"
|
||||
## + cron_flags="-J 60" ## cedwards 20181118
|
||||
## resolv.conf
|
||||
if [ ! -f "${bastille_jail_rc_conf}" ]; then
|
||||
echo -e "syslogd_flags=\"-ss\"\nsendmail_enable=\"NONE\"" > ${bastille_jail_rc_conf}
|
||||
echo -e "cron_flags=\"-J 60\"" >> ${bastille_jail_rc_conf}
|
||||
touch "${bastille_jail_rc_conf}"
|
||||
/usr/sbin/sysrc -f "${bastille_jail_rc_conf}" syslogd_flags=-ss
|
||||
/usr/sbin/sysrc -f "${bastille_jail_rc_conf}" sendmail_enable=NONE
|
||||
/usr/sbin/sysrc -f "${bastille_jail_rc_conf}" cron_flags='-J 60'
|
||||
echo
|
||||
fi
|
||||
|
||||
## resolv.conf (default: copy from host)
|
||||
if [ ! -f "${bastille_jail_resolv_conf}" ]; then
|
||||
echo -e "nameserver 1.1.1.1\nnameserver 1.0.0.1\noptions edns0 rotate" > ${bastille_jail_resolv_conf}
|
||||
cp -L ${bastille_resolv_conf} ${bastille_jail_resolv_conf}
|
||||
fi
|
||||
|
||||
## TZ: UTC
|
||||
ln -s /usr/share/zoneinfo/Etc/UTC etc/localtime
|
||||
## TZ: configurable (default: etc/UTC)
|
||||
ln -s /usr/share/zoneinfo/${bastille_tzdata} etc/localtime
|
||||
}
|
||||
|
||||
# Handle special-case commands first.
|
||||
@@ -149,60 +273,67 @@ help|-h|--help)
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ $# -gt 3 ] || [ $# -lt 3 ]; then
|
||||
usage
|
||||
if [ $(echo $3 | grep '@' ) ]; then
|
||||
BASTILLE_JAIL_IP=$(echo $3 | awk -F@ '{print $2}')
|
||||
BASTILLE_JAIL_INTERFACES=$( echo $3 | awk -F@ '{print $1}')
|
||||
fi
|
||||
|
||||
NAME="$1"
|
||||
RELEASE="$2"
|
||||
IP="$3"
|
||||
TYPE="$1"
|
||||
NAME="$2"
|
||||
RELEASE="$3"
|
||||
IP="$4"
|
||||
INTERFACE="$5"
|
||||
|
||||
## handle additional options
|
||||
case "${TYPE}" in
|
||||
-T|--thick|thick)
|
||||
if [ $# -gt 5 ] || [ $# -lt 4 ]; then
|
||||
usage
|
||||
fi
|
||||
THICK_JAIL="0"
|
||||
break
|
||||
;;
|
||||
-*)
|
||||
echo -e "${COLOR_RED}Unknown Option.${COLOR_RESET}"
|
||||
usage
|
||||
;;
|
||||
*)
|
||||
if [ $# -gt 4 ] || [ $# -lt 3 ]; then
|
||||
usage
|
||||
fi
|
||||
THICK_JAIL=""
|
||||
NAME="$1"
|
||||
RELEASE="$2"
|
||||
IP="$3"
|
||||
INTERFACE="$4"
|
||||
;;
|
||||
esac
|
||||
|
||||
## don't allow for dots(.) in container names
|
||||
if [ $(echo "${NAME}" | grep "[.]") ]; then
|
||||
echo -e "${COLOR_RED}Container names may not contain a dot(.)!${COLOR_RESET}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
## verify release
|
||||
case "${RELEASE}" in
|
||||
10.1-RELEASE)
|
||||
RELEASE="10.1-RELEASE"
|
||||
;;
|
||||
10.2-RELEASE)
|
||||
RELEASE="10.2-RELEASE"
|
||||
;;
|
||||
10.3-RELEASE)
|
||||
RELEASE="10.3-RELEASE"
|
||||
;;
|
||||
10.4-RELEASE)
|
||||
RELEASE="10.4-RELEASE"
|
||||
*-RELEASE|*-release|*-RC1|*-rc1|*-RC2|*-rc2)
|
||||
## check for FreeBSD releases name
|
||||
NAME_VERIFY=$(echo "${RELEASE}" | grep -iwE '^([1-9]{2,2})\.[0-9](-RELEASE|-RC[1-2])$' | tr '[:lower:]' '[:upper:]')
|
||||
if [ -n "${NAME_VERIFY}" ]; then
|
||||
RELEASE="${NAME_VERIFY}"
|
||||
else
|
||||
usage
|
||||
fi
|
||||
;;
|
||||
11.0-RELEASE)
|
||||
RELEASE="11.0-RELEASE"
|
||||
;;
|
||||
11.1-RELEASE)
|
||||
RELEASE="11.1-RELEASE"
|
||||
;;
|
||||
11.2-RELEASE)
|
||||
RELEASE="11.2-RELEASE"
|
||||
;;
|
||||
12.0-RELEASE)
|
||||
RELEASE="12.0-RELEASE"
|
||||
;;
|
||||
12.0-BETA1)
|
||||
RELEASE="12.0-BETA1"
|
||||
;;
|
||||
12.0-BETA2)
|
||||
RELEASE="12.0-BETA2"
|
||||
;;
|
||||
12.0-BETA3)
|
||||
RELEASE="12.0-BETA3"
|
||||
;;
|
||||
12.0-BETA4)
|
||||
RELEASE="12.0-BETA4"
|
||||
;;
|
||||
12.0-RC1)
|
||||
RELEASE="12.0-RC1"
|
||||
;;
|
||||
12.0-RC2)
|
||||
RELEASE="12.0-RC2"
|
||||
;;
|
||||
12.0-RC3)
|
||||
RELEASE="12.0-RC3"
|
||||
*-stable-LAST|*-STABLE-last|*-stable-last|*-STABLE-LAST)
|
||||
## check for HardenedBSD releases name
|
||||
NAME_VERIFY=$(echo "${RELEASE}" | grep -iwE '^([1-9]{2,2})(-stable-LAST|-STABLE-last|-stable-last|-STABLE-LAST)$' | sed 's/STABLE/stable/g' | sed 's/last/LAST/g')
|
||||
if [ -n "${NAME_VERIFY}" ]; then
|
||||
RELEASE="${NAME_VERIFY}"
|
||||
else
|
||||
usage
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo -e "${COLOR_RED}Unknown Release.${COLOR_RESET}"
|
||||
@@ -216,6 +347,12 @@ if [ -d "${bastille_jailsdir}/${NAME}/root/.bastille" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
## check for required release
|
||||
if [ ! -d "${bastille_releasesdir}/${RELEASE}" ]; then
|
||||
echo -e "${COLOR_RED}Release must be bootstrapped first; see `bastille bootstrap`.${COLOR_RESET}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
## check if a running jail matches name
|
||||
if running_jail ${NAME}; then
|
||||
echo -e "${COLOR_RED}A running jail matches name.${COLOR_RESET}"
|
||||
@@ -224,8 +361,17 @@ if running_jail ${NAME}; then
|
||||
fi
|
||||
|
||||
## check if ip address is valid
|
||||
if ! validate_ip ${IP}; then
|
||||
echo -e "${COLOR_RED}Invalid: ($ip).${COLOR_RESET}"
|
||||
if [ ! -z ${IP} ]; then
|
||||
validate_ip
|
||||
else
|
||||
usage
|
||||
fi
|
||||
|
||||
create_jail ${NAME} ${RELEASE} ${IP}
|
||||
## check if interface is valid
|
||||
if [ ! -z ${INTERFACE} ]; then
|
||||
validate_netif
|
||||
else
|
||||
validate_netconf
|
||||
fi
|
||||
|
||||
create_jail ${NAME} ${RELEASE} ${IP} ${INTERFACE}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2019, 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() {
|
||||
echo -e "${COLOR_RED}Usage: bastille destroy name.${COLOR_RESET}"
|
||||
echo -e "${COLOR_RED}Usage: bastille destroy [container|release]${COLOR_RESET}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ destroy_jail() {
|
||||
bastille_jail_base="${bastille_jailsdir}/${NAME}" ## dir
|
||||
bastille_jail_log="${bastille_logsdir}/${NAME}_console.log" ## file
|
||||
|
||||
if [ $(jls name | grep ${NAME}) ]; then
|
||||
if [ $(jls name | grep -w "${NAME}") ]; then
|
||||
echo -e "${COLOR_RED}Jail running.${COLOR_RESET}"
|
||||
echo -e "${COLOR_RED}See 'bastille stop ${NAME}'.${COLOR_RESET}"
|
||||
exit 1
|
||||
@@ -53,14 +53,74 @@ destroy_jail() {
|
||||
|
||||
if [ -d "${bastille_jail_base}" ]; then
|
||||
echo -e "${COLOR_GREEN}Deleting Jail: ${NAME}.${COLOR_RESET}"
|
||||
chflags -R noschg ${bastille_jail_base}
|
||||
rm -rf ${bastille_jail_base}
|
||||
echo -e "${COLOR_GREEN}Note: jail console logs not destroyed.${COLOR_RESET}"
|
||||
echo -e "${COLOR_GREEN}${bastille_jail_log}${COLOR_RESET}"
|
||||
if [ "${bastille_zfs_enable}" = "YES" ]; then
|
||||
if [ ! -z "${bastille_zfs_zpool}" ]; then
|
||||
if [ ! -z "${NAME}" ]; then
|
||||
## remove jail zfs dataset recursively
|
||||
zfs destroy -r ${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NAME}
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -d "${bastille_jail_base}" ]; then
|
||||
## removing all flags
|
||||
chflags -R noschg ${bastille_jail_base}
|
||||
|
||||
## remove jail base
|
||||
rm -rf ${bastille_jail_base}
|
||||
fi
|
||||
|
||||
## archive jail log
|
||||
if [ -f "${bastille_jail_log}" ]; then
|
||||
mv ${bastille_jail_log} ${bastille_jail_log}-$(date +%F)
|
||||
echo -e "${COLOR_GREEN}Note: jail console logs archived.${COLOR_RESET}"
|
||||
echo -e "${COLOR_GREEN}${bastille_jail_log}-$(date +%F)${COLOR_RESET}"
|
||||
fi
|
||||
echo
|
||||
fi
|
||||
}
|
||||
|
||||
destroy_rel() {
|
||||
bastille_rel_base="${bastille_releasesdir}/${NAME}" ## dir
|
||||
|
||||
## check if this release have containers child
|
||||
BASE_HASCHILD="0"
|
||||
if [ -d "${bastille_jailsdir}" ]; then
|
||||
JAIL_LIST=$(ls "${bastille_jailsdir}" | sed "s/\n//g")
|
||||
for _jail in ${JAIL_LIST}; do
|
||||
if grep -qwo "${NAME}" ${bastille_jailsdir}/${_jail}/fstab 2>/dev/null; then
|
||||
echo -e "${COLOR_RED}Notice: (${_jail}) depends on ${NAME} base.${COLOR_RESET}"
|
||||
BASE_HASCHILD="1"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ ! -d "${bastille_rel_base}" ]; then
|
||||
echo -e "${COLOR_RED}Release base not found.${COLOR_RESET}"
|
||||
exit 1
|
||||
else
|
||||
if [ "${BASE_HASCHILD}" -eq "0" ]; then
|
||||
echo -e "${COLOR_GREEN}Deleting base: ${NAME}.${COLOR_RESET}"
|
||||
if [ "${bastille_zfs_enable}" = "YES" ]; then
|
||||
if [ ! -z "${bastille_zfs_zpool}" ]; then
|
||||
zfs destroy ${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${NAME}
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -d "${bastille_rel_base}" ]; then
|
||||
## removing all flags
|
||||
chflags -R noschg ${bastille_rel_base}
|
||||
|
||||
## remove jail base
|
||||
rm -rf ${bastille_rel_base}
|
||||
fi
|
||||
echo
|
||||
else
|
||||
echo -e "${COLOR_RED}Cannot destroy base with containers child.${COLOR_RESET}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Handle special-case commands first.
|
||||
case "$1" in
|
||||
help|-h|--help)
|
||||
@@ -74,4 +134,32 @@ fi
|
||||
|
||||
NAME="$1"
|
||||
|
||||
destroy_jail
|
||||
## check what should we clean
|
||||
case "${NAME}" in
|
||||
*-RELEASE|*-release|*-RC1|*-rc1|*-RC2|*-rc2)
|
||||
## check for FreeBSD releases name
|
||||
NAME_VERIFY=$(echo "${NAME}" | grep -iwE '^([1-9]{2,2})\.[0-9](-RELEASE|-RC[1-2])$' | tr '[:lower:]' '[:upper:]')
|
||||
if [ -n "${NAME_VERIFY}" ]; then
|
||||
NAME="${NAME_VERIFY}"
|
||||
destroy_rel
|
||||
else
|
||||
usage
|
||||
fi
|
||||
;;
|
||||
|
||||
*-stable-LAST|*-STABLE-last|*-stable-last|*-STABLE-LAST)
|
||||
## check for HardenedBSD releases name
|
||||
NAME_VERIFY=$(echo "${NAME}" | grep -iwE '^([1-9]{2,2})(-stable-LAST|-STABLE-last|-stable-last|-STABLE-LAST)$' | sed 's/STABLE/stable/g' | sed 's/last/LAST/g')
|
||||
if [ -n "${NAME_VERIFY}" ]; then
|
||||
NAME="${NAME_VERIFY}"
|
||||
destroy_rel
|
||||
else
|
||||
usage
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
|
||||
## just destroy a jail
|
||||
destroy_jail
|
||||
;;
|
||||
esac
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
#!/bin/sh
|
||||
# https://pastebin.com/T6eThbKu
|
||||
|
||||
. /usr/local/etc/bastille/bastille.conf
|
||||
|
||||
DEVICE_SELF_SCAN_ALL=NO
|
||||
[ "$_SCRIPT_SUBR" ] || . /usr/share/bsdconfig/script.subr
|
||||
usage(){ echo "Usage: ${0##*/} [-r releaseName] [dists ...]" >&2; exit 1; }
|
||||
while getopts hr: flag; do
|
||||
case "$flag" in
|
||||
r) releaseName="$OPTARG" ;;
|
||||
*) usage
|
||||
esac
|
||||
done
|
||||
shift $(( $OPTIND - 1 ))
|
||||
nonInteractive=1
|
||||
MEDIA_TIMEOUT=3 # because ftp.f.o has no SRV records
|
||||
_ftpPath=ftp://ftp.freebsd.org
|
||||
mediaSetFTP
|
||||
mediaOpen
|
||||
set -e
|
||||
#debug=1
|
||||
REL_DIST=${bastille_cachedir}/$releaseName
|
||||
download() # $src to $dest
|
||||
{
|
||||
size=$( f_device_get device_media "$1" $PROBE_SIZE )
|
||||
f_device_get device_media "$1" | dpv -kb "BastilleBSD" \
|
||||
-t "bootstrap" -p "Downloading $releaseName" \
|
||||
-o "$3" "$size:$1"
|
||||
}
|
||||
sign() # $file
|
||||
{
|
||||
dpv -kb "BastilleBSD" -t "bootstrap" \
|
||||
-p "Signing $releaseName" -mx "sha256 >&2" \
|
||||
"$size:${1##*/}" "$1" 2>&1 >&$TERMINAL_STDOUT_PASSTHRU
|
||||
}
|
||||
mkdir -p $REL_DIST
|
||||
MANIFEST=$REL_DIST/MANIFEST
|
||||
download MANIFEST to $MANIFEST
|
||||
dists="$*"
|
||||
for dist in ${dists:-$( awk '$0=$4' $MANIFEST )}; do
|
||||
eval "$( awk -v dist=$dist '$4 == dist {
|
||||
print "distfile=" $1
|
||||
print "sig=" $2
|
||||
exit found = 1
|
||||
} END { exit ! found }' $MANIFEST )"
|
||||
destfile=$REL_DIST/$distfile
|
||||
download $distfile to $destfile
|
||||
[ "$( sign $destfile )" = $sig ] ||
|
||||
f_die "$distfile signature mismatch!"
|
||||
done
|
||||
f_dialog_info "All dists successfully downloaded/verified."
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2019, 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() {
|
||||
echo -e "${COLOR_RED}Usage: bastille htop [ALL|glob]'.${COLOR_RESET}"
|
||||
echo -e "${COLOR_RED}Usage: bastille htop TARGET${COLOR_RESET}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -47,11 +47,14 @@ if [ $# -gt 1 ] || [ $# -lt 1 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
if [ "$1" = 'ALL' ]; then
|
||||
TARGET="${1}"
|
||||
shift
|
||||
|
||||
if [ "${TARGET}" = 'ALL' ]; then
|
||||
JAILS=$(jls name)
|
||||
fi
|
||||
if [ "$1" != 'ALL' ]; then
|
||||
JAILS=$(jls name | grep -E "(^|\b)${1}($|\b)")
|
||||
if [ "${TARGET}" != 'ALL' ]; then
|
||||
JAILS=$(jls name | grep -w "${TARGET}")
|
||||
fi
|
||||
|
||||
for _jail in ${JAILS}; do
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2019, 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() {
|
||||
echo -e "${COLOR_RED}Usage: bastille list [release|template|jail|log].${COLOR_RESET}"
|
||||
echo -e "${COLOR_RED}Usage: bastille list [release|template|(jail|container)|log].${COLOR_RESET}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -47,16 +47,31 @@ if [ $# -gt 0 ]; then
|
||||
usage
|
||||
;;
|
||||
release|releases)
|
||||
ls "${bastille_releasesdir}" | sed "s/\n//g"
|
||||
if [ -d "${bastille_releasesdir}" ]; then
|
||||
REL_LIST=$(ls "${bastille_releasesdir}" | sed "s/\n//g")
|
||||
for _REL in ${REL_LIST}; do
|
||||
if [ -f "${bastille_releasesdir}/${_REL}/root/.profile" ]; then
|
||||
#echo "${bastille_releasesdir}/${_REL}"
|
||||
echo "${_REL}"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
;;
|
||||
template|templates)
|
||||
ls "${bastille_templatesdir}" | sed "s/\n//g"
|
||||
find "${bastille_templatesdir}" -type d -maxdepth 2
|
||||
;;
|
||||
jail|jails)
|
||||
ls "${bastille_jailsdir}" | sed "s/\n//g"
|
||||
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
|
||||
;;
|
||||
log|logs)
|
||||
ls "${bastille_logsdir}" | sed "s/\n//g"
|
||||
find "${bastille_logsdir}" -type f -maxdepth 1
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2019, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -31,7 +31,7 @@
|
||||
. /usr/local/share/bastille/colors.pre.sh
|
||||
|
||||
usage() {
|
||||
echo -e "${COLOR_RED}Usage: bastille pkg [ALL|glob] 'pkg command'${COLOR_RESET}"
|
||||
echo -e "${COLOR_RED}Usage: bastille pkg TARGET command [args]${COLOR_RESET}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -42,19 +42,22 @@ help|-h|--help)
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ $# -gt 2 ] || [ $# -lt 2 ]; then
|
||||
if [ $# -lt 2 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
if [ "$1" = 'ALL' ]; then
|
||||
TARGET="${1}"
|
||||
shift
|
||||
|
||||
if [ "${TARGET}" = 'ALL' ]; then
|
||||
JAILS=$(jls name)
|
||||
fi
|
||||
if [ "$1" != 'ALL' ]; then
|
||||
JAILS=$(jls name | grep -E "(^|\b)${1}($|\b)")
|
||||
if [ "${TARGET}" != 'ALL' ]; then
|
||||
JAILS=$(jls name | grep -w "${TARGET}")
|
||||
fi
|
||||
|
||||
for _jail in ${JAILS}; do
|
||||
echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}"
|
||||
jexec -l ${_jail} /usr/sbin/pkg $2
|
||||
jexec -l ${_jail} /usr/sbin/pkg $@
|
||||
echo
|
||||
done
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2019, 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, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2019, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -31,7 +31,7 @@
|
||||
. /usr/local/share/bastille/colors.pre.sh
|
||||
|
||||
usage() {
|
||||
echo -e "${COLOR_RED}Usage: bastille service [ALL|glob] 'service command'.${COLOR_RESET}"
|
||||
echo -e "${COLOR_RED}Usage: bastille service TARGET service_name action${COLOR_RESET}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -42,20 +42,23 @@ help|-h|--help)
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ $# -gt 2 ] || [ $# -lt 2 ]; then
|
||||
if [ $# -lt 2 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
if [ "$1" = 'ALL' ]; then
|
||||
TARGET=$1
|
||||
shift
|
||||
|
||||
if [ "${TARGET}" = 'ALL' ]; then
|
||||
JAILS=$(jls name)
|
||||
fi
|
||||
|
||||
if [ "$1" != 'ALL' ]; then
|
||||
JAILS=$(jls name | grep -E "(^|\b)${1}($|\b)")
|
||||
if [ "${TARGET}" != 'ALL' ]; then
|
||||
JAILS=$(jls name | grep -w "${TARGET}")
|
||||
fi
|
||||
|
||||
for _jail in ${JAILS}; do
|
||||
echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}"
|
||||
jexec -l ${_jail} /usr/sbin/service $2
|
||||
jexec -l ${_jail} /usr/sbin/service $@
|
||||
echo
|
||||
done
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2019, 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() {
|
||||
echo -e "${COLOR_RED}Usage: bastille start [ALL|glob].${COLOR_RESET}"
|
||||
echo -e "${COLOR_RED}Usage: bastille start TARGET${COLOR_RESET}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -47,20 +47,30 @@ if [ $# -gt 1 ] || [ $# -lt 1 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
if [ "$1" = 'ALL' ]; then
|
||||
TARGET="${1}"
|
||||
shift
|
||||
|
||||
if [ "${TARGET}" = 'ALL' ]; then
|
||||
JAILS=$(/usr/local/bin/bastille list jails)
|
||||
fi
|
||||
if [ "$1" != 'ALL' ]; then
|
||||
JAILS=$(/usr/local/bin/bastille list jails | grep "$1")
|
||||
if [ "${TARGET}" != 'ALL' ]; then
|
||||
JAILS=$(/usr/local/bin/bastille list jails | grep -w "${TARGET}")
|
||||
fi
|
||||
|
||||
for _jail in ${JAILS}; do
|
||||
if [ $(jls name | grep ${_jail}) ]; then
|
||||
## test if running
|
||||
if [ $(jls name | grep -w ${_jail}) ]; then
|
||||
echo -e "${COLOR_RED}[${_jail}]: Already started.${COLOR_RESET}"
|
||||
elif [ ! $(jls name | grep ${_jail}) ]; then
|
||||
|
||||
## test if not running
|
||||
elif [ ! $(jls name | grep -w ${_jail}) ]; then
|
||||
echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}"
|
||||
jail -f "${bastille_jailsdir}/${_jail}/jail.conf" -c ${_jail}
|
||||
pfctl -f /etc/pf.conf
|
||||
|
||||
## update ${bastille_jail_loopback}:network with added/removed addresses
|
||||
if [ ! -z ${bastille_jail_loopback} ]; then
|
||||
pfctl -f /etc/pf.conf
|
||||
fi
|
||||
fi
|
||||
echo
|
||||
done
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2019, 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() {
|
||||
echo -e "${COLOR_RED}Usage: bastille stop [ALL|glob].${COLOR_RESET}"
|
||||
echo -e "${COLOR_RED}Usage: bastille stop TARGET${COLOR_RESET}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -47,16 +47,30 @@ if [ $# -gt 1 ] || [ $# -lt 1 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
if [ "$1" = 'ALL' ]; then
|
||||
TARGET="${1}"
|
||||
shift
|
||||
|
||||
if [ "${TARGET}" = 'ALL' ]; then
|
||||
JAILS=$(jls name)
|
||||
fi
|
||||
if [ "$1" != 'ALL' ]; then
|
||||
JAILS=$(jls name | grep -E "(^|\b)${1}($|\b)")
|
||||
if [ "${TARGET}" != 'ALL' ]; then
|
||||
JAILS=$(jls name | grep -w "${TARGET}")
|
||||
fi
|
||||
|
||||
for _jail in ${JAILS}; do
|
||||
echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}"
|
||||
jail -f "${bastille_jailsdir}/${_jail}/jail.conf" -r ${_jail}
|
||||
pfctl -f /etc/pf.conf
|
||||
## test if not running
|
||||
if [ ! $(jls name | grep -w "${_jail}") ]; then
|
||||
echo -e "${COLOR_RED}[${_jail}]: Not started.${COLOR_RESET}"
|
||||
|
||||
## test if running
|
||||
elif [ $(jls name | grep -w "${_jail}") ]; then
|
||||
echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}"
|
||||
jail -f "${bastille_jailsdir}/${_jail}/jail.conf" -r ${_jail}
|
||||
|
||||
## update ${bastille_jail_loopback}:network with added/removed addresses
|
||||
if [ ! -z ${bastille_jail_loopback} ]; then
|
||||
pfctl -f /etc/pf.conf
|
||||
fi
|
||||
fi
|
||||
echo
|
||||
done
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2019, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -31,7 +31,7 @@
|
||||
. /usr/local/share/bastille/colors.pre.sh
|
||||
|
||||
usage() {
|
||||
echo -e "${COLOR_RED}Usage: bastille sysrc [ALL|glob] 'sysrc command'${COLOR_RESET}"
|
||||
echo -e "${COLOR_RED}Usage: bastille sysrc TARGET args${COLOR_RESET}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -42,20 +42,23 @@ help|-h|--help)
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ $# -gt 2 ] || [ $# -lt 2 ]; then
|
||||
if [ $# -lt 2 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
if [ "$1" = 'ALL' ]; then
|
||||
TARGET="${1}"
|
||||
shift
|
||||
|
||||
if [ "${TARGET}" = 'ALL' ]; then
|
||||
JAILS=$(jls name)
|
||||
fi
|
||||
|
||||
if [ "$1" != 'ALL' ]; then
|
||||
JAILS=$(jls name | grep -E "(^|\b)${1}($|\b)")
|
||||
if [ "${TARGET}" != 'ALL' ]; then
|
||||
JAILS=$(jls name | grep -w "${TARGET}")
|
||||
fi
|
||||
|
||||
for _jail in ${JAILS}; do
|
||||
echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}"
|
||||
jexec -l ${_jail} /usr/sbin/sysrc $2
|
||||
jexec -l ${_jail} /usr/sbin/sysrc $@
|
||||
echo -e "${COLOR_RESET}"
|
||||
done
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2019, 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() {
|
||||
echo -e "${COLOR_RED}Usage: bastille template [ALL|glob] template.${COLOR_RESET}"
|
||||
echo -e "${COLOR_RED}Usage: bastille template TARGET project/template.${COLOR_RESET}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -47,24 +47,35 @@ if [ $# -gt 2 ] || [ $# -lt 2 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
if [ "$1" = 'ALL' ]; then
|
||||
TARGET="${1}"
|
||||
shift
|
||||
|
||||
if [ "${TARGET}" = 'ALL' ]; then
|
||||
JAILS=$(jls name)
|
||||
fi
|
||||
if [ "$1" != 'ALL' ]; then
|
||||
JAILS=$(jls name | grep -E "(^|\b)${1}($|\b)")
|
||||
if [ "${TARGET}" != 'ALL' ]; then
|
||||
JAILS=$(jls name | grep -w "${TARGET}")
|
||||
fi
|
||||
|
||||
TEMPLATE="${1}"
|
||||
shift
|
||||
|
||||
if [ ! -d "${bastille_templatesdir}"/"${TEMPLATE}" ]; then
|
||||
echo -e "${COLOR_RED}${TEMPLATE} not found.${COLOR_RESET}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
## global variables
|
||||
TEMPLATE=$2
|
||||
bastille_template=${bastille_templatesdir}/${TEMPLATE}
|
||||
bastille_template_TARGET=${bastille_template}/TARGET
|
||||
bastille_template_INCLUDE=${bastille_template}/INCLUDE
|
||||
bastille_template_PRE=${bastille_template}/PRE
|
||||
bastille_template_CONFIG=${bastille_template}/CONFIG
|
||||
bastille_template_OVERLAY=${bastille_template}/OVERLAY
|
||||
bastille_template_FSTAB=${bastille_template}/FSTAB
|
||||
bastille_template_PF=${bastille_template}/PF
|
||||
bastille_template_PKG=${bastille_template}/PKG
|
||||
bastille_template_SYSRC=${bastille_template}/SYSRC
|
||||
bastille_template_SERVICE=${bastille_template}/SERVICE
|
||||
bastille_template_CMD=${bastille_template}/CMD
|
||||
|
||||
for _jail in ${JAILS}; do
|
||||
@@ -75,7 +86,7 @@ for _jail in ${JAILS}; do
|
||||
|
||||
## TARGET
|
||||
if [ -s "${bastille_template_TARGET}" ]; then
|
||||
if [ $(grep -E "(^|\b)\!${_jail}($|\b)" ${bastille_template_TARGET}) ]; then
|
||||
if [ $(grep -w "${_jail}" ${bastille_template_TARGET}) ]; then
|
||||
echo -e "${COLOR_GREEN}TARGET: !${_jail}.${COLOR_RESET}"
|
||||
echo
|
||||
continue
|
||||
@@ -89,62 +100,102 @@ for _jail in ${JAILS}; do
|
||||
|
||||
## INCLUDE
|
||||
if [ -s "${bastille_template_INCLUDE}" ]; then
|
||||
echo -e "${COLOR_GREEN}Detected INCLUDE.${COLOR_RESET}"
|
||||
echo -e "${COLOR_GREEN}[${_jail}]:INCLUDE -- START${COLOR_RESET}"
|
||||
while read _include; do
|
||||
echo -e "${COLOR_GREEN}${_include}${COLOR_RESET}"
|
||||
echo
|
||||
echo -e "${COLOR_GREEN}INCLUDE: ${_include}${COLOR_RESET}"
|
||||
echo -e "${COLOR_GREEN}Bootstrapping ${_include}...${COLOR_RESET}"
|
||||
bastille bootstrap ${_include}
|
||||
|
||||
echo
|
||||
echo -e "${COLOR_GREEN}Applying ${_include}...${COLOR_RESET}"
|
||||
BASTILLE_TEMPLATE_PROJECT=$(echo "${_include}" | awk -F / '{ print $4}')
|
||||
BASTILLE_TEMPLATE_REPO=$(echo "${_include}" | awk -F / '{ print $5}')
|
||||
bastille template ${_jail} ${BASTILLE_TEMPLATE_PROJECT}/${BASTILLE_TEMPLATE_REPO}
|
||||
done < "${bastille_template_INCLUDE}"
|
||||
echo -e "${COLOR_GREEN}[${_jail}]:INCLUDE -- END${COLOR_RESET}"
|
||||
echo
|
||||
fi
|
||||
|
||||
## pre
|
||||
## PRE
|
||||
if [ -s "${bastille_template_PRE}" ]; then
|
||||
echo -e "${COLOR_GREEN}Executing PRE-command(s).${COLOR_RESET}"
|
||||
jexec -l ${_jail} /bin/sh < "${bastille_template_PRE}"
|
||||
echo -e "${COLOR_GREEN}[${_jail}]:PRE -- START${COLOR_RESET}"
|
||||
jexec -l ${_jail} /bin/sh < "${bastille_template_PRE}" || exit 1
|
||||
echo -e "${COLOR_GREEN}[${_jail}]:PRE -- END${COLOR_RESET}"
|
||||
echo
|
||||
fi
|
||||
|
||||
## config
|
||||
if [ -s "${bastille_template_CONFIG}" ]; then
|
||||
echo -e "${COLOR_GREEN}Copying files...${COLOR_RESET}"
|
||||
## CONFIG / OVERLAY
|
||||
if [ -s "${bastille_template_OVERLAY}" ]; then
|
||||
echo -e "${COLOR_GREEN}[${_jail}]:OVERLAY -- START${COLOR_RESET}"
|
||||
while read _dir; do
|
||||
cp -a "${bastille_template}/${_dir}" "${bastille_jail_path}"
|
||||
done < ${bastille_template_CONFIG}
|
||||
echo -e "${COLOR_GREEN}Copy complete.${COLOR_RESET}"
|
||||
cp -av "${bastille_template}/${_dir}" "${bastille_jail_path}" || exit 1
|
||||
done < ${bastille_template_OVERLAY}
|
||||
echo -e "${COLOR_GREEN}[${_jail}]:OVERLAY -- END${COLOR_RESET}"
|
||||
echo
|
||||
fi
|
||||
if [ -s "${bastille_template}/CONFIG" ]; then
|
||||
echo -e "${COLOR_YELLOW}CONFIG deprecated; rename to OVERLAY.${COLOR_RESET}"
|
||||
echo -e "${COLOR_GREEN}[${_jail}]:CONFIG -- START${COLOR_RESET}"
|
||||
while read _dir; do
|
||||
cp -av "${bastille_template}/${_dir}" "${bastille_jail_path}" || exit 1
|
||||
done < ${bastille_template}/CONFIG
|
||||
echo -e "${COLOR_GREEN}[${_jail}]:CONFIG -- END${COLOR_RESET}"
|
||||
echo
|
||||
fi
|
||||
|
||||
## fstab
|
||||
## FSTAB
|
||||
if [ -s "${bastille_template_FSTAB}" ]; then
|
||||
bastille_templatefstab=$(cat "${bastille_template_FSTAB}")
|
||||
echo -e "${COLOR_GREEN}Updating fstab.${COLOR_RESET}"
|
||||
echo -e "${COLOR_GREEN}NOT YET IMPLEMENTED.${COLOR_RESET}"
|
||||
fi
|
||||
|
||||
## pf
|
||||
## PF
|
||||
if [ -s "${bastille_template_PF}" ]; then
|
||||
bastille_templatepf=$(cat "${bastille_template_PF}")
|
||||
echo -e "${COLOR_GREEN}Generating PF profile.${COLOR_RESET}"
|
||||
echo -e "${COLOR_GREEN}NOT YET IMPLEMENTED.${COLOR_RESET}"
|
||||
fi
|
||||
|
||||
## pkg (bootstrap + pkg)
|
||||
## PKG (bootstrap + pkg)
|
||||
if [ -s "${bastille_template_PKG}" ]; then
|
||||
echo -e "${COLOR_GREEN}Installing packages.${COLOR_RESET}"
|
||||
jexec -l "${_jail}" env ASSUME_ALWAYS_YES=YES /usr/sbin/pkg bootstrap
|
||||
echo -e "${COLOR_GREEN}[${_jail}]:PKG -- START${COLOR_RESET}"
|
||||
jexec -l "${_jail}" env ASSUME_ALWAYS_YES=YES /usr/sbin/pkg bootstrap || exit 1
|
||||
jexec -l "${_jail}" env ASSUME_ALWAYS_YES=YES /usr/sbin/pkg audit -F
|
||||
jexec -l "${_jail}" env ASSUME_ALWAYS_YES=YES /usr/sbin/pkg install $(cat ${bastille_template_PKG})
|
||||
jexec -l "${_jail}" env ASSUME_ALWAYS_YES=YES /usr/sbin/pkg install $(cat ${bastille_template_PKG}) || exit 1
|
||||
echo -e "${COLOR_GREEN}[${_jail}]:PKG -- END${COLOR_RESET}"
|
||||
echo
|
||||
fi
|
||||
|
||||
## sysrc
|
||||
## SYSRC
|
||||
if [ -s "${bastille_template_SYSRC}" ]; then
|
||||
echo -e "${COLOR_GREEN}Updating services.${COLOR_RESET}"
|
||||
echo -e "${COLOR_GREEN}[${_jail}]:SYSRC -- START${COLOR_RESET}"
|
||||
while read _sysrc; do
|
||||
jexec -l ${_jail} /usr/sbin/sysrc "${_sysrc}"
|
||||
jexec -l ${_jail} /usr/sbin/sysrc "${_sysrc}" || exit 1
|
||||
done < "${bastille_template_SYSRC}"
|
||||
echo -e "${COLOR_GREEN}[${_jail}]:SYSRC -- END${COLOR_RESET}"
|
||||
echo
|
||||
fi
|
||||
|
||||
## cmd
|
||||
if [ -s "${bastille_template_CMD}" ]; then
|
||||
echo -e "${COLOR_GREEN}Executing final command(s).${COLOR_RESET}"
|
||||
jexec -l ${_jail} /bin/sh < "${bastille_template_CMD}"
|
||||
## SERVICE
|
||||
if [ -s "${bastille_template_SERVICE}" ]; then
|
||||
echo -e "${COLOR_GREEN}[${_jail}]:SERVICE -- START${COLOR_RESET}"
|
||||
while read _service; do
|
||||
jexec -l ${_jail} /usr/sbin/service ${_service} || exit 1
|
||||
done < "${bastille_template_SERVICE}"
|
||||
echo -e "${COLOR_GREEN}[${_jail}]:SERVICE -- END${COLOR_RESET}"
|
||||
echo
|
||||
fi
|
||||
|
||||
## CMD
|
||||
if [ -s "${bastille_template_CMD}" ]; then
|
||||
echo -e "${COLOR_GREEN}[${_jail}]:CMD -- START${COLOR_RESET}"
|
||||
jexec -l ${_jail} /bin/sh < "${bastille_template_CMD}" || exit 1
|
||||
echo -e "${COLOR_GREEN}[${_jail}]:CMD -- END${COLOR_RESET}"
|
||||
echo
|
||||
fi
|
||||
|
||||
echo -e "${COLOR_GREEN}Template Complete.${COLOR_RESET}"
|
||||
echo
|
||||
done
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2019, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -31,7 +31,7 @@
|
||||
. /usr/local/share/bastille/colors.pre.sh
|
||||
|
||||
usage() {
|
||||
echo -e "${COLOR_RED}Usage: bastille top [ALL|glob]'.${COLOR_RESET}"
|
||||
echo -e "${COLOR_RED}Usage: bastille top TARGET${COLOR_RESET}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -46,12 +46,15 @@ if [ $# -gt 1 ] || [ $# -lt 1 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
if [ "$1" = 'ALL' ]; then
|
||||
TARGET="${1}"
|
||||
shift
|
||||
|
||||
if [ "${TARGET}" = 'ALL' ]; then
|
||||
JAILS=$(jls name)
|
||||
fi
|
||||
|
||||
if [ "$1" != 'ALL' ]; then
|
||||
JAILS=$(jls name | grep -E "(^|\b)${1}($|\b)")
|
||||
if [ "${TARGET}" != 'ALL' ]; then
|
||||
JAILS=$(jls name | grep -w "${TARGET}")
|
||||
fi
|
||||
|
||||
for _jail in ${JAILS}; do
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2019, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -47,10 +47,16 @@ if [ $# -gt 1 ] || [ $# -lt 1 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
RELEASE=$1
|
||||
RELEASE="${1}"
|
||||
shift
|
||||
|
||||
if [ ! -z "$(freebsd-version | grep -i HBSD)" ]; then
|
||||
echo -e "${COLOR_RED}Not yet supported on HardenedBSD.${COLOR_RESET}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -d "${bastille_releasesdir}/${RELEASE}" ]; then
|
||||
freebsd-update -b "${bastille_releasesdir}/${RELEASE}" fetch install --currently-running ${RELEASE}
|
||||
freebsd-update -b "${bastille_releasesdir}/${RELEASE}" fetch install --currently-running "${RELEASE}"
|
||||
else
|
||||
echo -e "${COLOR_RED}${RELEASE} not found. See bootstrap.${COLOR_RESET}"
|
||||
exit 1
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2019, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -47,11 +47,18 @@ if [ $# -gt 2 ] || [ $# -lt 2 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
RELEASE=$1
|
||||
NEWRELEASE=$2
|
||||
RELEASE="$1"
|
||||
shift
|
||||
NEWRELEASE="$1"
|
||||
|
||||
if [ ! -z "$(freebsd-version | grep -i HBSD)" ]; then
|
||||
echo -e "${COLOR_RED}Not yet supported on HardenedBSD.${COLOR_RESET}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
if [ -d "${bastille_releasesdir}/${RELEASE}" ]; then
|
||||
freebsd-update -b "${bastille_releasesdir}/${RELEASE}" -r ${NEWRELEASE} upgrade
|
||||
freebsd-update -b "${bastille_releasesdir}/${RELEASE}" -r "${NEWRELEASE}" upgrade
|
||||
else
|
||||
echo -e "${COLOR_RED}${RELEASE} not found. See bootstrap.${COLOR_RESET}"
|
||||
exit 1
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
|
||||
# Copyright (c) 2018-2019, Christer Edwards <christer.edwards@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -49,6 +49,11 @@ fi
|
||||
|
||||
RELEASE=$1
|
||||
|
||||
if [ ! -z "$(freebsd-version | grep -i HBSD)" ]; then
|
||||
echo -e "${COLOR_RED}Not yet supported on HardenedBSD.${COLOR_RESET}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -d "${bastille_releasesdir}/${RELEASE}" ]; then
|
||||
freebsd-update -b "${bastille_releasesdir}/${RELEASE}" IDS
|
||||
else
|
||||
|
||||
123
usr/local/share/bastille/zfs.sh
Normal file
123
usr/local/share/bastille/zfs.sh
Normal file
@@ -0,0 +1,123 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018-2019, 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/colors.pre.sh
|
||||
. /usr/local/etc/bastille/bastille.conf
|
||||
|
||||
usage() {
|
||||
echo -e "${COLOR_RED}Usage: bastille zfs TARGET [set|get|snap] [key=value|date]'${COLOR_RESET}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
zfs_snapshot() {
|
||||
for _jail in ${JAILS}; do
|
||||
echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}"
|
||||
zfs snapshot ${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${_jail}@${TAG}
|
||||
echo
|
||||
done
|
||||
}
|
||||
|
||||
zfs_set_value() {
|
||||
for _jail in ${JAILS}; do
|
||||
echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}"
|
||||
zfs $ATTRIBUTE ${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${_jail}
|
||||
echo
|
||||
done
|
||||
}
|
||||
|
||||
zfs_get_value() {
|
||||
for _jail in ${JAILS}; do
|
||||
echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}"
|
||||
zfs get $ATTRIBUTE ${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${_jail}
|
||||
echo
|
||||
done
|
||||
}
|
||||
|
||||
zfs_disk_usage() {
|
||||
for _jail in ${JAILS}; do
|
||||
echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}"
|
||||
zfs list -t all -o name,used,avail,refer,mountpoint,compress,ratio -r ${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${_jail}
|
||||
echo
|
||||
done
|
||||
}
|
||||
|
||||
# Handle special-case commands first.
|
||||
case "$1" in
|
||||
help|-h|--help)
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
|
||||
## check ZFS enabled
|
||||
if [ ! "${bastille_zfs_enable}" = "YES" ]; then
|
||||
echo -e "${COLOR_RED}ZFS not enabled.${COLOR_RESET}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
## check zpool defined
|
||||
if [ -z "${bastille_zfs_zpool}" ]; then
|
||||
echo -e "${COLOR_RED}ZFS zpool not defined.${COLOR_RESET}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ $# -lt 2 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
TARGET="${1}"
|
||||
|
||||
if [ "${TARGET}" = 'ALL' ]; then
|
||||
JAILS=$(jls name)
|
||||
fi
|
||||
|
||||
if [ "${TARGET}" != 'ALL' ]; then
|
||||
JAILS=$(jls name | grep -w "${TARGET}")
|
||||
fi
|
||||
|
||||
case "$2" in
|
||||
set)
|
||||
ATTRIBUTE=$3
|
||||
JAILS=${JAILS}
|
||||
zfs_set_value
|
||||
;;
|
||||
get)
|
||||
ATTRIBUTE=$3
|
||||
JAILS=${JAILS}
|
||||
zfs_get_value
|
||||
;;
|
||||
snap|snapshot)
|
||||
TAG=$3
|
||||
JAILS=${JAILS}
|
||||
zfs_snapshot
|
||||
;;
|
||||
df|usage)
|
||||
zfs_disk_usage
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user