Compare commits

..

1017 Commits

Author SHA1 Message Date
7711702256 usr/local/share/bastille/common.sh aktualisiert 2024-11-29 22:22:29 +01:00
c49c2bbaeb Merge pull request 'usr/local/share/bastille/common.sh aktualisiert' (#1) from matthiasberner-patch-1 into master
Reviewed-on: #1
2024-10-09 18:36:18 +02:00
6bb3d7110a usr/local/share/bastille/common.sh aktualisiert 2024-10-09 18:34:33 +02:00
Juan David Hurtado G
cee6f20aa5 Merge pull request #711 from yaazkal/fix-conf-zpool
[FIX] correctly use bastille_zfs_prefix to also work on pools != zroot
2024-07-14 23:14:33 -05:00
yaazkal
1a27a7e0d4 [FIX] correctly use bastille_zfs_prefix to also work on pools different than zroot see PR #685 2024-07-14 18:32:32 -05:00
Juan David Hurtado G
c7f46c3fbb Merge pull request #710 from yaazkal/fix-cp-rcp
[FIX] cp and rcp commands not handling the quiet option correctly
2024-07-14 15:46:29 -05:00
yaazkal
bfe413e8ec [FIX] cp and rcp commands not handling the quiet option correctly 2024-07-14 15:45:03 -05:00
Juan David Hurtado G
9aeb0ea10c Merge pull request #643 from draga79/master
Adjust devfs_ruleset for hierarchical jails compatibility
2024-07-14 09:00:54 -05:00
Juan David Hurtado G
9f2cf6651b Merge pull request #686 from deadbeef2000/master
[FIX] Fixed rcorder startup
2024-07-13 21:05:59 -05:00
Juan David Hurtado G
cb5697acdd Merge pull request #709 from yaazkal/bastille-day-24
Review for PR#650
2024-07-13 17:32:19 -05:00
yaazkal
09dcdd0ec7 [REF] clean code for PR#650 2024-07-13 17:29:30 -05:00
Juan David Hurtado G
b7b2efca12 Merge pull request #650 from em-winterschon/fbsd-140R-setup-bootstrap-fixes
diff patches applied to resolve errors on setup.sh and bootstrap.sh
2024-07-13 17:20:23 -05:00
Juan David Hurtado G
e441850f81 Merge pull request #665 from andrewhotlab/master
restore check_fib() call
2024-07-13 08:01:20 -05:00
Juan David Hurtado G
87febb6407 Merge pull request #689 from Vertalo/work/bugfix_zfs_export
Fix to correctly check ZFS on/off closes #661
2024-07-08 20:26:27 -05:00
Juan David Hurtado G
3fff3d371d Merge pull request #649 from tedhen/master
Fix one letter spelling mistake.
2024-07-08 08:32:34 -05:00
Stefano Marinelli
7750a1b927 Merge pull request #1 from BastilleBSD/master
Sync from original repo
2024-06-30 14:52:43 +02:00
Juan David Hurtado G
ee96a206aa Merge pull request #705 from yaazkal/fix-rc-depends
[FIX] bastille rc script to require jail closes #698
2024-06-14 12:14:34 -05:00
yaazkal
6568a28c15 [FIX] bastille rc script to require jail closes #698 2024-06-05 22:33:38 -05:00
Martin Stoyanov
4859b56050 fix for https://github.com/BastilleBSD/bastille/issues/661 2024-03-13 10:24:54 -05:00
Christopher Kepes
1d14badc4a Fixed rcorder startup (added -a to basename) 2024-02-29 11:40:55 +01:00
Andrew
5faac5e7a4 restore check_fib() calls
This is needed to respect the "exec.fib" parameter in bastille "console" command, which has been deleted by commit b997be5
2024-01-18 19:55:58 +01:00
Eva Winterschön
19c8c021c4 diff patches applied to resolve errors on setup.sh and bootstrap.sh 2023-12-25 11:39:02 -08:00
Ted Henriksson
9d55c2ceb0 Fix one letter spelling mistake. 2023-12-25 18:36:02 +01:00
Stefano Marinelli
6ca8ea578e Adjust devfs_ruleset for hierarchical jails compatibility
Hierarchical jails inherit the parent jail's permissions and don't support setting devfs_ruleset to a non-zero value. This update adds a check to determine if the script is running inside a jail. If so, it sets devfs_ruleset to 0 to comply with this constraint.
2023-11-27 18:45:09 +01:00
Christer Edwards
3a4ebc63bb Merge pull request #642 from BastilleBSD/support_lowercase
fix logic for rc.conf + bastille.conf ZFS check
2023-11-25 19:15:16 -07:00
Christer Edwards
c627b1f7fa fix logic for rc.conf + bastille.conf ZFS check 2023-11-25 19:11:57 -07:00
Christer Edwards
bce28bf89a Merge pull request #641 from BastilleBSD/setup_vnet
add support for bastille_vnet devfs.rules in bastille setup
2023-11-25 17:21:49 -07:00
Christer Edwards
dd60e7f175 add support for bastille_vnet devfs.rules in bastille setup 2023-11-25 17:19:57 -07:00
Christer Edwards
32d67aea40 Merge pull request #640 from BastilleBSD/eol_patch
fix for recent EOL support patch
2023-11-25 17:07:56 -07:00
Christer Edwards
b30a7484bb fix for recent EOL support patch 2023-11-25 17:06:05 -07:00
Christer Edwards
86cb374732 Merge pull request #639 from BastilleBSD/support_lowercase
support upper & lowercase values in bastille.conf
2023-11-25 16:16:47 -07:00
Christer Edwards
622c926917 support lowercase values in bastille.conf (issue #368) 2023-11-25 15:09:11 -07:00
Christer Edwards
b05493bc8e Merge pull request #638 from BastilleBSD/create_matrix
support combining options for bastille create
2023-11-24 16:42:40 -07:00
Christer Edwards
97a0e692d9 standardize options in create matrix 2023-11-24 16:41:25 -07:00
Christer Edwards
3df39078bf support combining options for bastille create 2023-11-24 16:28:31 -07:00
Christer Edwards
620ad465d6 Merge pull request #637 from BastilleBSD/20231125_prep
update documentation for 14.0-RELEASE
2023-11-24 16:04:21 -07:00
Christer Edwards
d44c85637e update documentation for 14.0-RELEASE 2023-11-24 15:20:15 -07:00
Christer Edwards
c2b17f346d Merge pull request #635 from BastilleBSD/readthedocs
fix more readthedocs build info
2023-11-21 13:22:44 -07:00
Christer Edwards
94656350a1 fix more readthedocs build info 2023-11-21 13:20:16 -07:00
Christer Edwards
d0ff97057e Merge pull request #634 from BastilleBSD/readthedocs
fix readthedocs build info
2023-11-21 13:13:22 -07:00
Christer Edwards
dc6e755c2b fix readthedocs build info 2023-11-21 13:12:21 -07:00
Christer Edwards
c8b3fb3bc1 Merge pull request #633 from BastilleBSD/eol_patch
initial support & docs to bootstrap EOL releases
2023-11-20 16:21:31 -07:00
Christer Edwards
8906e491d0 initial support & docs to bootstrap EOL releases 2023-11-20 16:07:11 -07:00
Christer Edwards
51f9003016 Merge pull request #629 from dsh2dsh/rcordered
rcorder(8)-ed startup script
2023-11-20 15:15:13 -07:00
Christer Edwards
2de0766b54 Merge pull request #632 from BastilleBSD/osrelease_patch
add osrelease to jail.conf for new jails
2023-11-19 14:41:11 -07:00
Christer Edwards
ace7bdce2f add osrelease to jail.conf for new jails 2023-11-19 14:37:31 -07:00
Christer Edwards
9e71332876 Merge pull request #630 from brendans-bits/readme-upgrading
Added note on updating bastille.conf when upgrading
2023-11-14 10:17:22 -07:00
Brendan
2b6eb3c9f4 Added note on updating bastille.conf when upgrading 2023-11-13 20:00:41 +11:00
Denis Shaposhnikov
a38403b028 rcorder(8)-ed startup script
With

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

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

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

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

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

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

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

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

With this configuration jail `db` will start first and stop last.
2023-11-11 19:35:56 +01:00
Christer Edwards
8c04f1d110 Merge pull request #628 from smortex/relax-beta-rc-validation
Relax validation of -BETA / -RC releases
2023-11-10 11:32:50 -07:00
Romain Tartière
157125c4af Relax validation of -BETA / -RC releases
Accross the code, release names are checked against some variation of
-BETAx / -RCx which are inconsistent in the range of accepted values for
`x`.

As  a consequence, some commands cannot be successfuly run while they
are valid, e.g. `bastille create test 14.0-RC4 10.0.0.2` is rejected
because only `*-RC1` and `*-RC2` are accepted as a RC release name.

Find out these lists of specific BETA and RC patterns and adjust them to
allow any one-digit value at the end.  We generaly do up to 4 BETA / RC
releases, so a one digit limit is probably enough for the time being.
2023-11-10 08:09:51 -10:00
Barry McCormick
b7d741b5cd Merge pull request #615 from BastilleBSD/issue-399
CIDR documentation on create command
2023-11-01 10:14:05 -07:00
Barry McCormick
1e849d41af resolving to use /24 in docs 2023-11-01 10:13:01 -07:00
Barry McCormick
df00a7939e Merge pull request #623 from adriel-tech/patch-1
fix configure_zfs() to properly return status of zfs module.
2023-11-01 08:38:17 -07:00
Barry McCormick
49f6402a00 Merge pull request #624 from majsterkoo/vnet_rename_fix
Fix generated interface name in rc.conf for vnet jail
2023-10-30 16:01:19 -07:00
Michal Procházka
cf928f1237 Fix generated interface name in rc.conf for vnet jail 2023-10-30 20:39:58 +01:00
adriel-tech
11367238ec Update setup.sh
Removed -q from kldstat in function configure_zfs().
on FreeBSD 14 (maybe earlier) this causes kldstat to return in such
a way that BastilleBSD assumes zfs is not loaded.
2023-10-29 15:16:39 -07:00
Barry McCormick
78c77b7e26 Merge pull request #622 from BastilleBSD/updatejail
Updatejail
2023-10-26 19:00:25 -07:00
Barry McCormick
bf98acd330 upgrading documentation try2 2023-10-26 18:58:46 -07:00
Barry McCormick
01ee385384 upgrading documentation 2023-10-26 18:56:48 -07:00
Barry McCormick
22b3c3cd69 Merge pull request #620 from BastilleBSD/issue-157
documenting the use of ports in a template
2023-10-26 16:37:57 -07:00
Barry McCormick
3ac2921559 documenting the use of ports in a template 2023-10-26 16:36:32 -07:00
Barry McCormick
0354baa6d5 Merge pull request #575 from NikosChondros/master
Add rcp (reverse copy) command
2023-10-26 11:00:30 -07:00
Nikos Chondros
445b42ed39 Merge branch 'master' into master 2023-10-26 20:51:15 +03:00
Barry McCormick
00d5c97f64 Merge pull request #619 from BastilleBSD/issue-393
documentation of uname and MOTD & hushlogin
2023-10-25 21:45:26 -07:00
Barry McCormick
4ea6f00077 Merge branch 'master' into issue-393 2023-10-25 21:41:48 -07:00
Barry McCormick
10fe9df412 Merge pull request #616 from BastilleBSD/issue-527
added iocage migration doc
2023-10-25 21:39:05 -07:00
Barry McCormick
440b24371b update filenames 2023-10-25 21:36:01 -07:00
Barry McCormick
8b38497cb1 documentation of uname and MOTD & hushlogin 2023-10-25 21:26:23 -07:00
Barry McCormick
b0ba336d7e documented .hushlogin and uname in jails 2023-10-25 21:14:40 -07:00
Christer Edwards
fe31dbdca8 Merge pull request #614 from BastilleBSD/vnet-bridge
vnet bridging definitions
2023-10-25 16:19:53 -06:00
Christer Edwards
4bebca9a69 Merge pull request #617 from tucoinfo/patch-2
Update template.rst
2023-10-25 16:13:14 -06:00
tucoinfo
864d8d03f5 Update template.rst
Fix template CP example
2023-10-25 10:30:00 +02:00
Barry McCormick
ca2b75e8c0 added iocage migration doc 2023-10-20 22:28:00 -07:00
Barry McCormick
0a93940442 CIDR documentation on create command 2023-10-20 21:51:20 -07:00
Barry McCormick
b76df46cd1 vnet bridging definitions 2023-10-20 21:35:51 -07:00
Barry McCormick
2c932cf281 Merge pull request #613 from tucoinfo/patch-1
fix-issue-601
2023-10-19 08:26:10 -07:00
tucoinfo
e7eb9b7717 fix-issue-601
#601
2023-10-19 15:16:37 +02:00
Barry McCormick
27e88d45d5 Merge pull request #612 from BastilleBSD/JID-fix
fix for JID instead of jail name in list printout
2023-10-18 18:29:23 -07:00
Barry McCormick
721a5ca6a0 fix for JID instead of jail name in list printout 2023-10-18 18:26:55 -07:00
Barry McCormick
91f479e5d7 Merge pull request #598 from JRGTH/import_enhancements
Validate jib during jail import
2023-10-18 08:55:10 -07:00
Barry McCormick
f35de69b28 Merge pull request #605 from JRGTH/rdr_fixes
Add rdr pf conf check
2023-10-18 08:53:47 -07:00
Barry McCormick
e078aed54a Merge pull request #608 from tub5ta/patch-1
Permit jail upgrades to use BETA and RC branches
2023-10-18 08:53:26 -07:00
Christer Edwards
848be8d8e3 Merge pull request #606 from JRGTH/config_update
Update bastille.conf.sample
2023-10-18 09:52:55 -06:00
Christer Edwards
a0d6d58a6b Merge pull request #611 from BastilleBSD/20231013_release
prep & cleanup for 0.10.20231013 release
2023-10-17 12:10:54 -06:00
Christer Edwards
40e4b817d8 prep & cleanup for 0.10.20231013 release 2023-10-10 19:51:10 -06:00
Christer Edwards
6be0f23256 Merge pull request #610 from BastilleBSD/rdr_fix
rdr disable directive fix
2023-10-04 11:16:14 -06:00
Barry McCormick
3355c07dbf rdr disable directive fix 2023-10-04 10:13:08 -07:00
Jason Tubnor
aa688f7072 Update upgrade.sh
Allow the uplift of jails to test BETA and RC branches before release
2023-09-20 09:44:28 +10:00
JRGTH
9fc8804f97 Update bastille.conf.sample
Update config file for bastille export options.
2023-09-07 09:05:47 -04:00
JRGTH
d6b5733d48 Add rdr pf conf check
Prevent shutdown/rdr command stalls.
2023-09-07 08:34:28 -04:00
JRGTH
72bd211f7b Validate jib during jail import 2023-07-19 10:56:20 -04:00
Christer Edwards
61e7084b33 Merge pull request #596 from cedwards/2023_release
2023 release
2023-07-14 21:59:49 -06:00
Christer Edwards
3ea553086f source bastille.conf for pf path support 2023-07-14 21:53:02 -06:00
Christer Edwards
2fd1f2c812 update versions and dates 2023-07-14 21:35:18 -06:00
Christer Edwards
e15a481e46 setup now references bastille_pf_conf variable 2023-07-14 21:07:36 -06:00
Christer Edwards
15f2ea8574 Merge branch 'master' of https://github.com/bastillebsd/bastille into 2023_release 2023-07-14 21:02:30 -06:00
Christer Edwards
4efcc5021c update copyright dates 2023-07-14 21:02:14 -06:00
Christer Edwards
a2e1befa80 Merge pull request #587 from JRGTH/list_cmd_update
list cmd enhancement
2023-07-14 16:37:01 -06:00
Christer Edwards
15c43ee214 Merge pull request #590 from tobiastom/feature/upgrade-documentation
Added initial upgrading documentation.
2023-07-14 16:34:52 -06:00
Christer Edwards
a406654e18 Merge pull request #593 from gqgunhed/gqgunhed-linux-releases
Updated supported Linux releases
2023-07-14 16:34:24 -06:00
Christer Edwards
7f41973f43 Merge pull request #595 from skenizen/fix-rdr-pf-path
/etc/pf.conf path for rdr.sh set by a variable in bastille configuration
2023-07-14 16:32:43 -06:00
skenizen
373ccd45d9 changed the occurence of path /etc/pf.conf in the rdr.sh script for reading it as a variable from the bastille configuration. 2023-07-12 10:57:46 +02:00
gqgunhed
6e78be22f0 added focal+jammy to Apt::Cache-Start
Ran into an error without the change when using the "universe" repos, so I included these.
2023-07-10 13:04:25 +02:00
gqgunhed
cf569eaeeb Updated supported Linux releases
Added
- Ubuntu2204
- Debian12
Removed
- Debian9
2023-07-10 12:19:30 +02:00
gqgunhed
8d16399e50 Added NAME_VERIFY=Ubuntu_2204 section 2023-07-10 12:13:22 +02:00
gqgunhed
bea80db898 Exchanged entry for Debian9 with Debian12 2023-07-10 12:08:47 +02:00
gqgunhed
a89f42242c Added ubuntu-jammy and bookworm releases
removed "stretch" release
2023-07-10 12:04:40 +02:00
gqgunhed
16fae72518 Added Ubuntu Jammy 22.04 LTS 2023-07-10 12:01:01 +02:00
gqgunhed
4891ce69e7 Update bootstrap.sh
Changes to include more recent Linux/Debian releases
2023-07-10 11:57:29 +02:00
Christer Edwards
e64a6af214 Merge pull request #592 from BastilleBSD/rdr_fix
fix rdr issue detecting IP6 when disabled or not set
2023-06-21 20:36:45 -06:00
Christer Edwards
72b8000347 fix rdr issue detecting IP6 when disabled or not set 2023-06-21 20:34:19 -06:00
Tobias Tom
a0140e18bb Added initial upgrading documentation.
Source: https://gist.github.com/cedwards/1e00c3d0aa6fbb14bc5b16fca8df0c35
2023-05-24 14:15:04 +01:00
Christer Edwards
bc9f4d7e90 Merge pull request #588 from yaazkal/all-target-fix
[FIX] Support `ALL` in `pkg` command when using the -H or --host option.
2023-05-12 09:04:34 -06:00
Yaazkal
0b7ed7850a [FIX] Support ALL in pkg command when using the -H or --host option. 2023-05-09 21:24:42 -05:00
JRGTH
e454f1c826 list cmd enhancement 2023-05-03 09:02:55 -04:00
Christer Edwards
cb840684ab Merge pull request #586 from JRGTH/create_fixes
Add missing spaces for consistency
2023-05-02 08:08:46 -06:00
JRGTH
2e583cf9ab Add missing spaces for consistency
Add missing spaces for jail.conf  content consistency.
2023-05-02 09:55:35 -04:00
Christer Edwards
6ec7ae99f0 Merge pull request #585 from JRGTH/add_version
Fix missing version
2023-05-01 11:35:22 -06:00
JRGTH
8f803d511e Fix missing version 2023-05-01 13:30:54 -04:00
Christer Edwards
c760b817bd Merge pull request #581 from shirkdog/master
Updates for HardenedBSD Installer URL updates
2023-04-05 12:16:51 -06:00
M.Shirk
be50bd2359 Update to default conf 2023-04-05 14:08:37 -04:00
M.Shirk
228420049c Updates to the hardenedbsd installer URLs for bootstrapping releases. 2023-04-05 14:06:00 -04:00
Christer Edwards
d7609c2bc1 Merge pull request #580 from android-ucet/patch-1
add ipv6 rdr support
2023-03-28 15:31:23 -06:00
android-ucet
bf6fbed2b5 add ipv6 rdr support 2023-03-28 15:03:53 +02:00
Christer Edwards
2e2032fee8 Merge pull request #579 from bsdlme/master
Sort bastille usage ouput and update README.md for newer FreeBSD releases
2023-03-23 19:58:26 -06:00
Lars E
a9d8ae2cf1 Merge branch 'BastilleBSD:master' into master 2023-03-23 23:16:41 +01:00
Lars Engels
f936afeae6 Sort bastille usage ouput and update README.md for newer FreeBSD
releases
2023-03-23 23:14:39 +01:00
Christer Edwards
5aa98a8dae Merge pull request #578 from bsdlme/master
Add "tags" subcommand to add /delete / list tags
2023-03-23 13:36:35 -06:00
Lars Engels
64c3b6045e Allow running bastille and subcomands with help flags as regular user 2023-03-16 20:58:11 +01:00
Lars Engels
6776427e5a Drop "search" in favor of "list" 2023-03-16 18:06:44 +01:00
Lars Engels
10d94668fc Re-work "list" command / output and add "search" command. 2023-03-15 15:47:54 +01:00
Lars Engels
91d1768740 Add "tags" subcommand 2023-03-14 22:04:06 +01:00
Lars Engels
c94f653e0b Refactor 2023-03-14 22:03:16 +01:00
Lars Engels
09a1d306dc Add "bastille tags" subcommand to add tag strings to jails 2023-03-14 21:34:07 +01:00
Nikos Chondros
b60bc10537 Add rcp (reverse copy) command
Allows to copy files from a single jail back to the host.
Usuful when building jails ad-hoc, to get back to the host files you create directly inside the jail.
2023-03-04 12:34:09 +02:00
Christer Edwards
7b63059d03 Merge pull request #573 from drbrain/patch-1
Fix link
2023-02-25 07:09:11 -07:00
Eric Hodel
34669ce2e6 Fix link 2023-02-25 00:37:46 -08:00
Christer Edwards
5c94c283fb Merge pull request #564 from Efiartes/zfs_destroy_snapshot
Added zfs_destroy_snapshot functionality
2023-02-15 07:48:42 -07:00
Christer Edwards
5c84731cd4 Merge pull request #572 from UrsusDominatus/rename_command_vnet_interfaces
Rename command now affects name of created vnet interfaces
2023-02-15 07:47:44 -07:00
Roman Marchenko
c016bc0667 Blank line removal 2023-02-15 13:51:46 +01:00
Roman Marchenko
3f665e4738 Rename command now affects name of created vnet interfaces 2023-02-15 13:36:26 +01:00
Christer Edwards
9588d52686 Merge pull request #566 from nwisemanII/SSHIdentBootstrap
Accept ssh git addresses in bootstrap
2023-01-16 11:46:16 -07:00
Nico Wiseman
5adc75abed Clean up the git template name by removing .git from the end - this looks weird in the filesystem 2023-01-16 17:12:03 +00:00
Nico Wiseman
9a00ae5323 Added git endpoint for bastille bootstrap 2023-01-16 16:40:21 +00:00
kr0m
124902d6ba Added zfs_destroy_snapshot functionality 2022-12-27 08:03:58 +01:00
Christer Edwards
0629233f25 Merge pull request #534 from cqexbesd/config_rebased
Make parsing on jail.conf more robust
2022-12-13 20:58:30 -07:00
Christer Edwards
c00d8a4e05 Merge pull request #561 from Vertalo/ip-in-use
Fix bug in ip-in-use test
2022-12-13 20:54:58 -07:00
Christer Edwards
bfce059225 Merge pull request #560 from chriswells0/pf-config
Make pf table name and external interface configurable.
2022-12-13 20:54:33 -07:00
Christer Edwards
ec7a6d8f6d Merge pull request #559 from chriswells0/pf-jails
Use "bastille config" to get ipv4.addr.
2022-12-13 20:54:11 -07:00
Christer Edwards
0240d6532b Merge pull request #546 from PythonLinks/master
Updating the documentation for public clouds with IPV6 networking.
2022-12-13 20:53:38 -07:00
William Erik Baxter
ec18847f3e Fix bug in ip-in-use test
Need grep -wF instead of grep -w for IP test to avoid spurious match
against broadcast address in ifconfig output.
2022-12-04 05:47:15 -06:00
Chris Wells
dd7f195c1e Make pf table name and external interface configurable.
Closes #508
2022-11-26 23:24:33 -05:00
Chris Wells
bdae170529 Use "bastille config" to get ipv4.addr.
Fixes issue with jails not being added to pf table.
2022-11-23 22:41:45 -05:00
Christer Edwards
0ee17be875 Merge pull request #558 from BastilleBSD/linux_create_bugfix
fixing regression in create.sh for Linux containers
2022-11-02 21:18:00 -06:00
Christer Edwards
778ef6e581 fixing regression in create.sh for Linux containers 2022-11-02 21:17:05 -06:00
Christer Edwards
a73b9972e3 Merge pull request #556 from BastilleBSD/start_stop_order
fixes #389 regarding shutdown order
2022-11-01 17:24:44 -06:00
Christer Edwards
6a7ab04d9b fixes #389 regarding shutdown order 2022-11-01 17:23:00 -06:00
Christer Edwards
937986f4b6 Merge pull request #554 from BastilleBSD/makefile_install_version
Makefile install target updates version to match git rev of HEAD
2022-10-27 17:13:55 -06:00
Christer Edwards
a4102c7f61 Makefile install target updates version to match git rev of HEAD 2022-10-27 17:10:54 -06:00
Christer Edwards
3702066864 Merge pull request #536 from cqexbesd/minor
Minor Changes
2022-10-27 11:32:27 -06:00
Christer Edwards
79897e9af7 Merge pull request #539 from patmaddox/gcp-docs
Document Bastille VNET on GCP
2022-10-27 11:30:34 -06:00
Christer Edwards
55c7c4c6be Merge pull request #550 from Stormle/master
Fixed typo in README.md
2022-10-27 11:26:18 -06:00
Christer Edwards
e5c71c794a Merge pull request #553 from frikilax/pkg_report_errors
PKG::ADDED:: return error code and print error message when 'bastille pkg' fails
2022-10-27 11:25:54 -06:00
Christer Edwards
e04aee2617 Merge pull request #549 from JartX/advanced_mount_types
Advanced Mount Types Support
2022-10-27 11:10:38 -06:00
Christer Edwards
0dcefae18c Merge pull request #435 from CamilionEU/evilham-improve-ipv6-and-dualstack-creation
[WIP] [feedback required] Improve dualstack and IPv6 support on jail creation
2022-10-17 20:35:32 -06:00
Théo Bertin
37e607c055 PKG::ADDED:: return error code and print error message when 'bastille pkg' fails
This allows better integration of 'bastille pkg' in scripts, and permits to catch errors during 'bastille template' commands
2022-10-14 16:10:52 +00:00
Evilham
f6f179b6c3 Updates for latest commits 2022-10-13 10:49:26 +02:00
Evilham
fdfbb8287f Improve dualstack and IPv6 support on jail creation
This is still WIP / PoC and would require documentation changes, opening PR to
gather feedback as this is a first-time contribution.

Important changes:
- instead of relying on 0.0.0.0 to signal DHCP, we now support passing "DHCP" in
the IP parameter.
- we also support "SLAAC" as a value for the IP parameter, which enables
accepting route advertisement
- fixed an oddity in the way the gateway was being handled for IPv6 (in certain
cases it was being passed as the GATEWAY template parameter
- allow passing multiple values to the IP parameter, this would work as a quoted
parameter
- that means that, e.g. bastille create -V test 13.0-RELEASE "SLAAC DHCP" wan is
possible and creates a dual-stack jail
- passing both DHCP, SLAAC and fixed IPs is also possible, but only one IP per
protocol number is supported; last one wins
2022-10-13 10:49:26 +02:00
Stormle
44cc3c0b91 Fixed typo in README.md 2022-10-08 01:55:26 +03:00
PythonLinks
2f35d07e58 Update networking.rst
Vultr supports FreeBSD and gives us both a single ipv4 and a range of ipv6 addresses.    So the simple thing to do is to give each container its own public ipv6 address.   No need to mess with vnet.   At least that is the theory.  Wish me luck in getting this working.   Am I really the first person to be using this approach?
2022-10-04 15:58:52 +02:00
Sagformas
d451573889 Advanced Mount Types Support 2022-10-04 11:05:05 +02:00
PythonLinks
64fcda2533 Update networking.rst
Polished up this Document.
2022-09-30 07:38:46 +02:00
PythonLinks
ca3303fd4d Updating the Docs for Coulds with IPV6 networking.
I hope I got this all correct.  I did get the containers networked correctly on vultr, but I am not a networking guy so I hope I did not misstate anything.    Any edits I am happy to fix.  And now I have to run, I am late for the multi lingual meetup.  But this stuff is way more fun.
2022-09-21 19:27:47 +02:00
Christer Edwards
f1d73a0c02 Merge pull request #543 from tofazzz/master
Updated "export" sub-command docs (0.9.20220216)
2022-09-02 09:58:35 -06:00
tofaz
a0abac97ff Update export.rst 2022-09-02 11:36:43 -04:00
tofaz
6f739229cb Update export.rst
Updated with syntax from 0.9.20220216 as if running just bastille export TARGET it errors with:

"Error: Stream can not be written to a terminal.
You must redirect standard output.

Error: An export option is required, see 'bastille export, otherwise the user must redirect to standard output."
2022-09-02 11:35:45 -04:00
Pat Maddox
427128b9f0 Explain permissive NAT 2022-07-31 00:03:57 -07:00
Pat Maddox
cf6e555ce9 Update GCP docs for default gateway and resolver
Bastille can handle it, no need to configure inside the jail.
2022-07-30 23:52:36 -07:00
Pat Maddox
c9d28ceed1 Document Bastille VNET on GCP 2022-07-30 20:59:50 -07:00
Andrew Stevenson
797f406a31 Convert tab to spaces
Spaces seem to be the convention for these files, for better or worse, so make
things consistent.
2022-07-24 22:16:38 +00:00
Andrew Stevenson
a352fd6507 Expand comment
(this should have gone in a previous commit)
2022-07-24 22:16:04 +00:00
Andrew Stevenson
a4ac5e961f Make parsing on jail.conf more robust
jail.conf has a few tricky things about it's format (such as supporting
variable expansion) so it is easiest to get jail to do the parsing for us.

The changes to get required changes to set as well as we no longer are calling
grep so that became a single awk script as well.
2022-07-24 10:27:54 +00:00
Christer Edwards
c50e99b3e7 Merge pull request #533 from cqexbesd/colour
Enable colour only when writing to a tty
2022-07-23 21:23:16 -06:00
Andrew Stevenson
a0b7bc54e0 Enable colour only when writing to a tty
The escape codes can confuse other scripts and things in pipes
2022-07-23 09:29:42 +00:00
Christer Edwards
639334052f Merge pull request #532 from cedwards/update_doc_version
update versions from 12.x to 13.x
2022-07-22 07:56:32 -06:00
Christer Edwards
40c99ef979 update versions from 12.x to 13.x 2022-07-22 07:55:22 -06:00
Christer Edwards
260149c2a9 Merge pull request #530 from JRGTH/clone_cmd_fixes
Update the exec.* with uniq_epair when cloning jails
2022-07-18 10:31:59 -06:00
Christer Edwards
722adc44cb Merge pull request #531 from cedwards/cmd_bugfix
bugfix for cmd when using ALL target
2022-07-18 10:28:11 -06:00
Christer Edwards
e35c59330d bugfix for cmd when using ALL target 2022-07-17 18:43:13 -06:00
JRGTH
74b6eb76e7 Update the exec.* with uniq_epair when cloning jails
This update will fix the startup error after cloning a jail, this was because the exec.prestart/poststop not being properly updated.
2022-07-14 21:41:52 -04:00
Christer Edwards
da377f4735 Merge pull request #529 from BastilleBSD/fete_nationale_2022
prepare for fete nationale 2022
2022-07-13 21:32:33 -06:00
Christer Edwards
f5b47d8f9e prepare for fete nationale 2022 2022-07-13 21:30:04 -06:00
Christer Edwards
6de6e7bc6f Merge pull request #519 from JRGTH/bootstrap_fixes
Avoid cache/RELEASE dirs creation on Linux jails
2022-07-10 20:23:44 -06:00
Christer Edwards
533d108d91 Merge pull request #526 from boogiewookie/master
The text speaks of defining an OVERLAY but the example uses CP.
2022-07-10 20:23:22 -06:00
Kevet Duncombe
a5bf6eca16 Merge pull request #1 from boogiewookie/boogiewookie-patch-1
Update README.md
2022-06-20 06:35:02 -05:00
Kevet Duncombe
10468cd08f Update README.md 2022-06-20 06:30:42 -05:00
Christer Edwards
e8a72bcd75 Merge pull request #520 from JRGTH/cmd_fixes
Allow 'bastille cmd' on Linux jails
2022-05-31 13:36:31 -06:00
JRGTH
b69eedc066 Allow 'bastille cmd' on Linux jails
Allow executing commands on Linux jails with `bastille cmd`.
2022-05-16 09:34:37 -04:00
JRGTH
62d038049d Avoid cache/RELEASE dirs creation on Linux jails
Don't create unused/stale cache/RELEASE directory/datasets on Linux jails creation.
2022-05-15 04:15:39 -04:00
Christer Edwards
3ba1024704 Merge pull request #510 from cyrilst/patch-1
Repair table, fix incorrect descriptions
2022-05-04 14:50:24 -06:00
Christer Edwards
dbb720fef4 Merge pull request #500 from eborisch/graceful_network_stop
Permit outgoing network connections during stop action
2022-05-04 14:49:26 -06:00
Christer Edwards
d0903347a6 Merge pull request #502 from nmurali94/master
Extend RDR to support logging
2022-05-04 14:47:30 -06:00
Christer Edwards
b9d38a5d01 Merge pull request #505 from ctuffli/patch-1
Allow Linux jails to see their mount points
2022-05-04 14:46:38 -06:00
Christer Edwards
f14eddc958 Merge pull request #507 from ellislm/fix_vnet_epair
fix non-unique epair creation when using vnet
2022-05-04 14:45:33 -06:00
Christer Edwards
e64c81d18a Merge pull request #515 from ddowse/template-ip6
Add variable JAIL_IP6 to access ip6.addr in templates
2022-05-04 14:44:00 -06:00
Christer Edwards
674a34d69c Merge pull request #511 from fellmoon/patch-1
Update bootstrap.rst
2022-05-04 14:38:39 -06:00
fellmoon
a97ac27a46 Update bootstrap.rst 2022-05-04 22:27:15 +02:00
Daniel Dowse - Freelancer
4302445eb5 Add variable JAIL_IP6 to access ip6.addr in templates 2022-04-08 15:26:53 +02:00
fellmoon
d9f1dfdc2f Update bootstrap.rst
added example how to bootstrap hardenedbsd
2022-03-21 00:42:39 +01:00
cyrilst
ebb93c795e Repair table, fix incorrect descriptions 2022-03-16 13:55:51 +01:00
Logan Ellis
dbd4b5edc5 fix non-unique epair creation when using vnet 2022-03-10 00:08:38 -08:00
Chuck Tuffli
abc8a6b280 Allow Linux jails to see their mount points
Some Linux packages (shakes fist angrily at Java) look to see if `/proc` is mounted as a part of the installation by running
   `mountpoint /proc`
While the Linux jail can see the contents of its `/proc` directory, the linprocfs driver will not generate the correct contents for `/proc/mounts` or `/proc/self/mountinfo` as `kern_getfsstat()` will, by default, filter all mount points other than the jail's chroot directory.

Fix is to set `enforce_statfs` to allow mount points below the jail's chroot directory to be visible.
2022-03-04 08:16:33 -08:00
Niketh Murali
6e5a566d7f Extend RDR to support logging
PF allows us to log rdr rules. The syntax to enable this is found in
pf.conf under the syntax grammar section for rdr-rule.

This commit extends Bastille's command line interface to allow users
to choose to log their rdr rules using the pf.conf syntax -

``````````````````````````````````````````````````````
tcp|udp host_port jail_port [log ['(' logopts ')'] ]
``````````````````````````````````````````````````````
Here, the syntax after jail_port is optional. This is sufficient to
provide backwards compatibility. The keyword 'log' enables logging with
the default options. The user can also provide custom options -
logopts - whose the syntax and allowed keywords are defined in pf.conf.
It's left to the user to supply correct logopts as the code does not
verify those values or their syntax.
2022-03-01 21:54:34 -05:00
Eric A. Borisch
24eb03c2e6 Permit outgoing connections during stop action 2022-02-24 09:42:40 -06:00
Christer Edwards
ff7de9167a Merge pull request #498 from cedwards/master
0.9.20220216 release
2022-02-16 23:34:59 -07:00
Christer Edwards
aafc2b3323 0.9.20220216 release 2022-02-16 23:28:09 -07:00
Christer Edwards
efed673e76 Merge pull request #490 from noracenofun/new-option--p-for-list-release
added the new option -p for list release
2022-02-16 23:05:03 -07:00
Christer Edwards
6aa6e40db1 Merge pull request #485 from JRGTH/clonejail_support
Initial support for clone jails
2022-02-16 23:02:41 -07:00
Christer Edwards
4726c48813 Merge pull request #491 from JRGTH/rename_fixes
Consistency improvements
2022-02-16 22:59:31 -07:00
Christer Edwards
920ca1fba0 Merge pull request #497 from frikilax/fix_fstab_clone
CLONE.SH::FIXED:: update fstab paths with new jail path
2022-02-16 22:58:52 -07:00
Theo BERTIN
6ca0369072 CLONE.SH::ADDED:: Complete FSTAB_RELEASE grep from fstab to get all release names
some release names (such as 14.0-CURRENT) were not correctly extracted from the fstab during fstab modification
2022-02-11 10:16:59 +01:00
Theo BERTIN
66d830a55f CLONE.SH::ADDED:: update fstab paths with new jail path 2022-02-11 09:41:02 +01:00
Christer Edwards
e4e1fadf35 Merge pull request #495 from gogolok/readme_fix_formatting
README: Fix formatting
2022-02-02 12:35:47 -07:00
Robert Gogolok
6b43067d86 README: Fix formatting 2022-02-02 09:03:55 +01:00
JRGTH
9052271232 Consistency improvements 2022-01-17 20:47:48 -04:00
noracenofun
4be7795f0a added the new option -p for list release
This new option lists the patch level of FreeBSD releases.
2022-01-18 01:05:29 +01:00
Christer Edwards
ab43a7569f Merge pull request #488 from JRGTH/rename_fixes
Update Linuxjail name entries upon jail renaming
2022-01-17 16:21:37 -07:00
Christer Edwards
d7d0d864c3 Merge pull request #489 from noracenofun/bootstrap-aarch64/arm64-Debian/Ubuntu
bootstrap aarch64/arm64 Debian/Ubuntu support
2022-01-17 16:20:38 -07:00
Christer Edwards
5d9ea33889 Merge pull request #486 from noracenofun/patch-1
optimizing command `list -a`
2022-01-17 16:19:24 -07:00
noracenofun
dc9b5fb9bd bootstrap aarch64/arm64 Debian/Ubuntu
added support to bootstrap aarch64/arm64 Debian or Ubuntu for ARM64 hosts
2022-01-16 19:51:58 +01:00
JRGTH
a62f36333d Update Linuxjail name entries upon jail renaming 2022-01-16 14:00:23 -04:00
noracenofun
29e72cd34d various optimization and added linux release
various optimization as well as determine and display of linux release added
2022-01-16 16:06:20 +01:00
JRGTH
03b9817f5a Initial support for clone jails 2022-01-15 11:32:28 -04:00
Christer Edwards
38bb7faabf Merge pull request #483 from robarnold/import_vnet
Import basic vnet settings from iocage
2022-01-14 20:22:04 -07:00
Christer Edwards
cc8e9f24a1 Merge pull request #482 from JRGTH/update_fixes
Fix to allow 32-Bit base releases to be updated
2022-01-14 20:18:16 -07:00
Christer Edwards
268d00be1f Merge pull request #484 from JRGTH/bootstrap_fixes
Bugfix to prevent double directory creation when bootstrapping Linux …
2022-01-14 20:04:18 -07:00
JRGTH
91bb955dd5 Bugfix to prevent double directory creation when bootstrapping Linux releases 2022-01-14 09:07:32 -04:00
Rob Arnold
c98d03a8e5 Import basic vnet settings from iocage
There's quite a bit more we could do here, but this hits my basic usage
with vnets. Future work here would be things like ipv6 support or trying
to infer what a custom `interfaces` setting means.
2022-01-13 21:04:15 -08:00
JRGTH
e11ed392f6 Fix to allow 32-Bit base releases to be updated 2022-01-13 20:39:07 -04:00
Christer Edwards
548ab2e250 Merge pull request #479 from JRGTH/master
Make sure to check/bootstrap directories first
2022-01-13 12:20:51 -07:00
Christer Edwards
9fa07ae24e Merge pull request #480 from robarnold/import
Import iocage basejails as Bastille thin jails
2022-01-13 12:20:32 -07:00
Rob Arnold
523c3f0bde Import iocage basejails as Bastille thin jails
I think these are the same concept, but with slightly different execution.
The main idea is to have a central base system that is shared (readonly) among
multiple jails. When this base system is updated, all the jails that reference
it immediately see the new system files.

This is implemented in iocage as a set of individual zfs mounts, one per
system directory. In Bastille, each system directory is symlinked into a
subdirectory of a single zfs mount.

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

This can also helps speeding up boot time if for instance some jails in bastille provide some kind of networking role like acting as a DNS server.
2021-08-07 18:23:10 -05:00
JRGTH
125b829872 Small cosmetic changes/readability 2021-08-07 13:33:57 -04:00
JRGTH
e92451b37c Add debian stretch/buster, small changes 2021-08-07 13:17:32 -04:00
JRGTH
9967a56e64 Improvements for Linux releases and code maintenance 2021-08-06 19:44:25 -04:00
JRGTH
9d3cb5f5e3 Merge remote-tracking branch 'upstream/master' 2021-08-06 17:22:22 -04:00
Christer Edwards
fdc688bafe Merge pull request #433 from cedwards/linux-pkg-support
basic PKG support for ubuntu/debian containers
2021-07-31 19:49:09 -06:00
Christer Edwards
03c830bea4 basic PKG support for ubuntu/debian containers 2021-07-31 19:47:01 -06:00
Christer Edwards
cd93e139a2 Merge pull request #432 from cedwards/mount_all_fix
fix overloaded variable in mount command
2021-07-31 15:24:12 -06:00
Christer Edwards
cc38fabd31 fix overloaded variable in mount command 2021-07-31 15:22:17 -06:00
Christer Edwards
c77ffb9617 Merge pull request #431 from cedwards/no_color_improvement
improve NO_COLOR detection
2021-07-31 15:06:05 -06:00
Christer Edwards
3a7e720e82 improve NO_COLOR detection 2021-07-31 15:04:08 -06:00
Christer Edwards
30ba4bbb69 revert double-slash fix
this causes issues if the user doesn't provide a starting /. cosmetic only.
2021-07-31 14:42:24 -06:00
Christer Edwards
7f1dbc17c9 Merge pull request #303 from yerrysherry/cmdbug
bastille cmd exit code not respected #272
2021-07-31 14:40:05 -06:00
Christer Edwards
5c89ac5a27 Merge branch 'master' into cmdbug 2021-07-31 14:39:24 -06:00
Christer Edwards
c02a8735d8 Merge pull request #430 from yaazkal/debian10
Adds: Debian 10 (Buster) as a release for linux jails
2021-07-30 13:00:23 -06:00
Yaazkal
5fcc56367d Fix: Debian 10 (Buster) path for increasing apt cache-start 2021-07-30 07:41:24 -05:00
Yaazkal
a21be862d8 Adds: Debian 10 (Buster) as a release for linux jails 2021-07-30 07:40:01 -05:00
Christer Edwards
4be0143de5 Merge pull request #429 from FloGatt/vnet_ipv6
Added logic for setting ipv6_defaultrouter for vnet template
2021-07-27 10:38:49 -06:00
Florian Gattermeier
2581218f82 Added logic for setting ipv6_defaultrouter for vnet template 2021-07-26 11:13:04 +02:00
Christer Edwards
47fed3a76d Merge pull request #427 from yaazkal/linux-debian-distros
Adds: Debian 9 (Stretch) as a release for linux jails
2021-07-23 15:53:24 -06:00
Yaazkal
f6b2e57051 Adds: Debian 9 (Stretch) as a release for linux jails 2021-07-23 12:07:21 -05:00
Christer Edwards
7c8c324a17 Merge pull request #426 from yaazkal/linux-bootstrap-functions
Refactor: Creates Linux jails bootstrap functions
2021-07-23 10:46:40 -06:00
Christer Edwards
e99fc5de6c Merge pull request #425 from yaazkal/patch-3
Fix minor typo in README
2021-07-23 10:44:38 -06:00
Yaazkal
403d6739bc Fix: removes unwanted line in esure_debootstrap 2021-07-23 05:56:00 -05:00
Yaazkal
295e57ac04 Refactor: removes cosmetic whitelines 2021-07-23 05:51:35 -05:00
Yaazkal
85b5c204c4 Refactor: Creates ensure_debootstrap an change logic to prevent typing errors because of duplicated code 2021-07-23 05:50:23 -05:00
Yaazkal
f9018047ea Refactor: check_linux_prerequisites indentation 2021-07-23 05:42:04 -05:00
Yaazkal
116014d191 Refactor: creates check_linux_prerequisites function 2021-07-23 05:33:49 -05:00
yaazkal
261fdd7dc9 Fix minor typo in README 2021-07-23 05:05:20 -05:00
JRGTH
c90fea3066 Extra validation on Linux Jails, revert cp.sh to avoid issues with templates 2021-07-15 16:30:36 -04:00
JRGTH
494d811c32 Use statement here 2021-07-15 12:32:37 -04:00
JRGTH
d8f925b1c8 Merge remote-tracking branch 'upstream/master' 2021-07-15 12:26:28 -04:00
Christer Edwards
93bb9a5048 Merge pull request #422 from cynix/fix_linux_jail
Fix creation of Linux jails
2021-07-15 07:25:31 -06:00
cynix
387fe3cf91 Avoid mounting devfs twice 2021-07-15 23:01:13 +10:00
cynix
857414f410 Fix missing redirection 2021-07-15 21:26:35 +10:00
cynix
b294a45bb9 Fix fstab creation for Linux jails 2021-07-15 20:52:16 +10:00
Christer Edwards
cc60df5cec Merge pull request #421 from cedwards/bastille-day-2021-release-prep
release preparation for 0.9.x
2021-07-14 16:09:25 -06:00
Christer Edwards
8ecded5cdb update README for new release 2021-07-14 16:00:13 -06:00
Christer Edwards
6d5da561bd release preparation for 0.9.x 2021-07-14 15:49:12 -06:00
JRGTH
2caf01b722 Cosmetics changes to prevent double "/" 2021-07-14 16:50:35 -04:00
Christer Edwards
c6491710fc Merge pull request #419 from JRGTH/master
Code review/cleanup routine
2021-07-14 14:18:32 -06:00
JRGTH
f39168b9c2 Be more specific with export/import command options 2021-07-14 15:02:12 -04:00
JRGTH
e564d50b2c Code review/cleanup routine 2021-07-14 13:57:09 -04:00
Christer Edwards
fb74bcb047 Merge pull request #418 from cedwards/fix-410-cmd-use-jail-env
fix issue #410 so CMD properly uses jailed env (root)
2021-07-13 21:39:14 -06:00
Christer Edwards
43a33739a3 fix issue #410 so CMD properly uses jailed env (root) 2021-07-13 21:38:03 -06:00
Christer Edwards
4d75ee6b2b Merge pull request #415 from JRGTH/master
Revision for create cmd and cleanup, fixed regressions and enhanced usage
2021-07-13 20:58:38 -06:00
JRGTH
c80b9da9ef Revert changes, colors will be disabled by env variable 2021-07-13 09:05:15 -04:00
JRGTH
64cc7747c8 Disable colors if "NO_COLOR" env variable present 2021-07-13 09:02:55 -04:00
JRGTH
50c09d0359 Feature to disable output colors 2021-07-13 04:49:25 -04:00
Christer Edwards
eeecffa93a Merge pull request #417 from cedwards/docs_quickfix
documentation fix for pkg (remove quotes)
2021-07-12 19:11:46 -06:00
Christer Edwards
4eb95f18ee documentation fix for pkg (remove quotes) 2021-07-12 19:10:33 -06:00
JRGTH
b1258378ab Revision for create cmd, fixed regressions and enhanced usage
This update fixes for previous regressions in the `create.sh` file and code cleanup, also enhances the usage display.
2021-07-12 14:54:00 -04:00
JRGTH
4999f0968f Merge remote-tracking branch 'upstream/master' 2021-07-12 14:52:36 -04:00
JRGTH
92e9579e04 Revert first as conflict with older one 2021-07-12 14:52:25 -04:00
JRGTH
a932abe0e3 Revision for create cmd, fixed regressions and enhanced usage.
This update fixes for previous regressions and code cleanup, also enhances the usage display.
2021-07-12 14:45:37 -04:00
Christer Edwards
8005dd2081 Merge pull request #414 from hackacad/linux_compat
Fix VNET issue causes by Linux compat
2021-07-12 08:14:35 -06:00
Bike Dude
9ff87f2904 reset LINUX_JAIL option 2021-07-12 10:02:51 +02:00
Bike Dude
9bb11c5d54 linux vs. /usr/home fix 2021-07-12 09:42:07 +02:00
Bike Dude
d20f5829c3 fix vnet issue 2021-07-12 09:25:52 +02:00
Christer Edwards
6977a42432 Merge pull request #411 from JRGTH/master
New features and improvements re-revised/re-tested for upcoming release
2021-07-11 19:12:12 -06:00
Christer Edwards
f8b50561ec Merge pull request #413 from hackacad/posix
fix list.sh for BSD grep
2021-07-11 14:34:10 -06:00
Christer Edwards
b997be51ae Merge pull request #340 from hackacad/linux_compat
Linux compat RC1
2021-07-11 14:31:29 -06:00
Bike Dude
f4738cb65d posix 2021-07-11 12:50:08 +02:00
Bike Dude
1b319c9bb9 posix 2021-07-11 10:46:21 +02:00
JRGTH
ee2c25697c Cleanup obsolete code 2021-07-10 09:01:28 -04:00
JRGTH
0a7db32490 Restored usage after file debug 2021-07-10 08:52:08 -04:00
JRGTH
f0c3620fac Add export/import standard I/O redirection
This update enhances the export and import command to fully support jail export/import user standard input/output redirection
2021-07-10 08:35:50 -04:00
Bike Dude
778b82949a posix 2021-07-09 22:32:09 +02:00
Bike Dude
140f02e140 fix 2021-07-09 18:04:28 +02:00
Bike Dude
a1d6e7b50d posix 2021-07-09 15:39:03 +02:00
JRGTH
d73645facb Add the new tgz compress format to UFS systems too 2021-07-08 17:41:27 -04:00
JRGTH
17ea19bf65 Deprecate command parameters not starting with dash here too 2021-07-08 15:37:36 -04:00
JRGTH
5c4d69775f Deprecate command parameters not starting with dash 2021-07-08 15:29:31 -04:00
JRGTH
b0f947ca00 Standardized options position in export/import commands, improve option checks 2021-07-08 13:48:02 -04:00
Bike Dude
b768daf616 docs for 0.9 Linux support 2021-07-07 16:30:49 +02:00
JRGTH
9e3ad27ecf Re-added new and improved create.sh file 2021-07-07 05:22:35 -04:00
JRGTH
8938d03f47 Revert to original file before re-add new 2021-07-07 05:21:28 -04:00
JRGTH
961731b063 New features and improvements revised and re-added 2021-07-07 05:05:38 -04:00
JRGTH
2f63bf3bbc Merge remote-tracking branch 'upstream/master' 2021-07-07 04:53:57 -04:00
JRGTH
b517d3aece File reverted due conflicts 2021-07-07 04:53:33 -04:00
Christer Edwards
9f8b2514b3 Merge pull request #394 from adyxax/network-access-on-startup
Fixes #338 Network access on jail startup
2021-07-04 08:48:59 -06:00
Christer Edwards
ada9352e1f Merge pull request #384 from gtz42/master
Don't include jail path twice
2021-07-04 08:41:03 -06:00
Christer Edwards
091a0f336c Merge pull request #390 from aeifn/master
Lint bootstrap.sh
2021-07-04 08:40:11 -06:00
Egor Kuzmichev
ad4c92055f Update bootstrap.sh
https://github.com/BastilleBSD/bastille/pull/390#discussion_r650394708

https://github.com/BastilleBSD/bastille/pull/390#discussion_r650396080

https://github.com/BastilleBSD/bastille/pull/390#discussion_r650396339
2021-06-13 20:03:25 +03:00
Julien Dessaux
1a522cb3a8 Fixes #338 Network access on jail startup 2021-06-09 18:03:27 +02:00
Egor Kuzmichev
9347fd0eae Lint bootstrap.sh
Lint with https://github.com/koalaman/shellcheck/wiki
2021-06-09 11:03:03 +03:00
Götz Salzmann
f8f508f6f6 Fix wrong mountpoint
In ed50e3fa04 _jailpath was updated to include the full path on the host.
The test and if required mkdir were then done with the jail’s root pirectory perpended to that full path.
2021-05-25 23:12:34 +02:00
Christer Edwards
b85d6347de Merge pull request #380 from noracenofun/master
fixed displaying issue
2021-05-25 07:13:08 -06:00
Christer Edwards
91aee11b54 Merge pull request #381 from hackacad/open_templates
allow alternative template servers
2021-05-25 07:12:09 -06:00
Bike Dude
e48ef60cd6 Merge remote-tracking branch 'origin/open_templates' into open_templates 2021-05-25 12:33:52 +02:00
Bike Dude
b2a4dcdd49 add verify
add verify.sh as well as in PR #383
2021-05-25 12:29:06 +02:00
Sven R
5241f9b03f Merge branch 'BastilleBSD:master' into open_templates 2021-05-18 21:15:45 +02:00
Bike Dude
585fd76ae2 alternative git template servers 2021-05-18 21:14:03 +02:00
Bike Dude
df5cd02472 remove home mountpoint (X11 support) 2021-05-18 19:42:15 +02:00
noracenofun
a3544343a8 fixed displaying issue older releases
release determination completely rebuilt
2021-05-16 00:29:02 +02:00
Jose
89c6ce9e78 Revert the improved import command due conflicts, later re add. 2021-05-15 08:16:10 -04:00
Jose
bfaa2681e0 Revert the improved export command due conflicts, later re add. 2021-05-15 08:13:14 -04:00
noracenofun
b0167028e8 fixed displaying issue
fixed wrong display if there are no jails existing
2021-05-15 13:23:16 +02:00
Christer Edwards
814201fa9f Merge pull request #379 from noracenofun/fixes-issue-#361
fixes issue #361
2021-05-05 13:02:45 -06:00
noracenofun
ac01384810 fixes issue #361
[BUG] IPv6 not respected when creating VNET jails #361
2021-05-05 12:45:47 +02:00
Christer Edwards
9a0d01da74 Merge pull request #305 from hackacad/thick_upgrade
Thick Upgrade
2021-05-04 19:04:29 -06:00
Christer Edwards
a311379afa Merge pull request #357 from ddowse/master
Help output to show real value for options instead of just [options]
2021-05-04 19:02:14 -06:00
Christer Edwards
c37006ec69 Merge pull request #376 from noracenofun/new-list-option
added the new option -a (aka all, --all) for list
2021-05-04 18:57:21 -06:00
noracenofun
9c4b39bb40 corrected length and value determination
determination of the width of the column 'Release' corrected and unnecessary line for determining the value of the release deleted
2021-05-02 12:29:33 +02:00
noracenofun
7bf605cf9f added release patch displaying
determine and display of release patch added
2021-05-02 09:01:25 +02:00
noracenofun
e5d2bc00a5 added ipv6 addresses displaying
determine and display of ipv6 addresses for bastille0, host alias and vnet0 added
2021-05-01 10:32:08 +02:00
Jose
2c87c58a5b Prevent mount command fstab entry nesting 2021-04-29 16:35:38 -04:00
Jose
0c699ea68d Merge remote-tracking branch 'upstream/master' 2021-04-29 16:33:26 -04:00
noracenofun
70f567ec43 ignore additional mount points in the fstab
ignore additional mount points in the fstab when determining the length and the value of release
2021-04-28 17:36:14 +02:00
noracenofun
4690805dbc truncated netmask from ip addresses
netmask from ip addresses truncated and displaying SYNCDHCP added
2021-04-23 00:01:50 +02:00
noracenofun
32f861e67a fixed issue no vnet ip address if jail down
issue with no vnet ip address being displayed when jail is down fixed
2021-04-22 20:35:25 +02:00
noracenofun
71fd2a7ce7 corrected length determination
determination length of vnet ip address and release corrected
2021-04-21 22:59:32 +02:00
noracenofun
e0f8848bd5 added ip address of vnet jails
ip address for running jails determined via jexec ifconfig and for stopped jails via jail rc.conf
2021-04-21 01:57:20 +02:00
noracenofun
0fe341add8 prevents multiline output
trim multiline output in case additional lines included in fstab
2021-04-20 19:54:40 +02:00
noracenofun
2bfa5abedb new option -a (aka all, --all)
the new option -a lists all jails, show state 'Up' or 'Down', published ports (rdr) and release, used command jls -j <jail> to collect infos for active jails and the files jail.conf, rdr.conf for inactive jails
2021-04-19 23:19:32 +02:00
Bike Dude
0b16acd939 fixes 2021-04-15 10:55:02 +02:00
Bike Dude
8d488b78c6 fixes 2021-04-15 10:39:38 +02:00
Christer Edwards
e7c6149d5a Merge pull request #370 from hackacad/rc3-4
add RC3/4 support
2021-04-03 10:07:43 -06:00
Bike Dude
2278b3b4d5 RC5 2021-04-03 18:01:29 +02:00
Bike Dude
f0d41580b8 add RC3/4 support 2021-04-03 17:47:50 +02:00
Christer Edwards
d6d9d14820 Merge pull request #355 from laffer1/master
Add preliminary support for MidnightBSD.
2021-03-22 13:56:58 -06:00
Christer Edwards
f8489beea5 Merge pull request #359 from ddowse/issue-358
Issue 358 - wrong gw selection
2021-03-22 13:54:13 -06:00
Christer Edwards
f02743fbd8 Merge pull request #362 from hackacad/ipv6_pf
IPv6 rules in pf.conf
2021-03-22 13:53:24 -06:00
Christer Edwards
d9283b44b2 Merge pull request #363 from hackacad/fstab_fix
Warn if fstab exists
2021-03-22 13:52:58 -06:00
Bike Dude
53ae7fe744 Warn if fstab exists 2021-03-22 20:48:50 +01:00
Jose
9984101e1b Don't share ports across the jails, just copy them
A security concern into the jail could affect the shared ports for all the child, and/or multiple jails accessing/managing/updating the same source could lead into conflicts.

Due the above mentioned issues, the optional distfiles will be copied to the newly created thinjail if they exist on the base release, thus being secure and more granular management.
2021-03-20 06:12:07 -04:00
Bike Dude
b5044a2ddb IPv6 hint for pf.conf 2021-03-18 14:01:57 +01:00
Bike Dude
15ef005337 IPv6 hint for pf.conf 2021-03-18 14:00:21 +01:00
Daniel Dowse
296236f793 Tabs to spaces 2021-03-03 18:56:24 +01:00
Daniel Dowse
dd3b2e8e62 If dual stack ip6 gw will be last will be the last output line of netstat ... comand in _gateway 2021-03-03 15:20:55 +01:00
Daniel Dowse
8cb20e4457 Help output to show real value for options instead of [options] 2021-03-03 00:30:17 +01:00
Christer Edwards
2e5d5b4be1 Merge pull request #356 from cedwards/default-template-fix
revert default template link; error->notify for bootstrap
2021-02-28 13:10:13 -07:00
Christer Edwards
f5e93e4b1a revert default template link; error->notify for bootstrap 2021-02-28 13:08:42 -07:00
Lucas Holt
54697cf77a Fix the file test for FreeBSD/HBSD 2021-02-27 00:13:01 -05:00
Lucas Holt
1710a09f6a Add preliminary support for MidnightBSD. 2021-02-26 16:55:56 -05:00
Christer Edwards
3fe03807ef Merge pull request #350 from zilti/master
Added option to have CP be quiet
2021-02-23 09:51:28 -07:00
Christer Edwards
c7a84a4a4e Merge pull request #351 from tuffnatty/patch-1
Reflect bastille_zfs_mountpoint deprecation in README.md
2021-02-19 09:52:40 -07:00
Daniel Ziltener
2aa92042fd Adjustment for consistency 2021-02-19 17:11:19 +01:00
Phil Krylov
39990b584b Reflect bastille_zfs_mountpoint deprecation in README.md 2021-02-19 17:34:34 +03:00
Daniel Ziltener
214a3e9894 Added option to have CP be quiet 2021-02-18 20:13:28 +01:00
Jose
674e8ff087 More validation/checks for export command 2021-02-18 06:48:43 -04:00
Christer Edwards
f7ef58cc19 Merge pull request #344 from hackacad/include_beta
allow boostrapping BETA build
2021-02-15 13:33:43 -07:00
Bike Dude
e35024508e allow boostrapping BETA build 2021-02-14 17:35:23 +01:00
Bike Dude
baa362c69b allow boostrapping BETA build 2021-02-14 17:29:29 +01:00
Bike Dude
440db5f82a typo 2021-02-14 17:27:09 +01:00
Bike Dude
4373b8b8d9 lint 2021-02-10 15:07:53 +01:00
Bike Dude
056b0237ad Ubuntu Focal support
incl. minor fixes
2021-02-10 14:33:04 +01:00
Bike Dude
0b80c59744 minor fixes 2021-02-10 10:27:49 +01:00
Bike Dude
373eafa4d6 POC RC1
POC for Bastille Linux Compat
2021-02-10 10:09:15 +01:00
Bike Dude
e7959a3f67 Alpha1
w/o bastille console
2021-02-09 22:00:07 +01:00
Bike Dude
519fe77fbb debug
v0.1
2021-02-08 22:11:33 +01:00
Jose
211a268c36 Use which since shell built-in and search for paths 2021-02-08 05:31:16 -04:00
Jose
75ed5b3ce4 Add quick check for pfctl command 2021-02-08 04:17:32 -04:00
Jose
80639062d7 Fix and improve the convert command 2021-02-05 13:59:09 -04:00
Jose
b31c8d514b Simplify options parsing and better handling for combined options 2021-02-03 20:39:30 -04:00
Jose
5583ab1d78 Add support bastille RAW image exports/imports, also extended help usage 2021-02-03 18:31:41 -04:00
Christer Edwards
af8d766b0e Merge pull request #333 from BastilleBSD/issue-332
fixes issue #332
2021-01-29 12:32:33 -07:00
Christer Edwards
9a5a1f960e fixes issue #332 2021-01-29 09:27:39 -07:00
Christer Edwards
ec24d7a897 Merge pull request #329 from BastilleBSD/docs-fix
minor fixes to previous doc updates
2021-01-27 13:55:12 -07:00
Christer Edwards
a450dd1de8 minor fixes to previous doc updates 2021-01-27 13:53:23 -07:00
Christer Edwards
4b27614ad7 Merge pull request #328 from BastilleBSD/docs-fix
fix formatting in network documentation
2021-01-27 13:49:50 -07:00
Christer Edwards
c3130f0eec fix formatting in network documentation 2021-01-27 13:46:05 -07:00
Christer Edwards
b5f1f15c45 Merge pull request #327 from fbarthez/patch-1
Minor md syntax fixes, adding missing spaces
2021-01-27 13:39:47 -07:00
Fabian Peters
c141f31dbd Minor md syntax fixes, adding missing spaces 2021-01-27 19:28:38 +01:00
Christer Edwards
584839fd78 Merge pull request #319 from hackacad/pf_keep
Update README / pf.conf
2021-01-19 12:59:08 -07:00
Bike Dude
627d1af284 update pf.conf 2021-01-19 20:10:53 +01:00
Bike Dude
8311a66b94 update pf.conf 2021-01-19 18:27:45 +01:00
Christer Edwards
113beb54e7 Merge pull request #317 from cedwards/release-prep-20210115
version bump for 0.8.20210115
2021-01-15 20:31:11 -07:00
Christer Edwards
2c5fff7ec7 version bump for 0.8.20210115 2021-01-15 20:28:34 -07:00
Christer Edwards
ae5feaa3df Merge pull request #316 from cedwards/2021-updates
update 2021 copyright
2021-01-15 20:11:04 -07:00
Christer Edwards
6fa744bbda update 2021 copyright 2021-01-15 20:00:26 -07:00
Christer Edwards
5b8fcf5a4d Merge pull request #311 from JRGTH/master
Don't start empty jails, don't apply template if Bastillefile is empty
2021-01-15 19:51:40 -07:00
Jose
15c1505187 Revert jail enable|disable feature by now, requested for later review 2021-01-15 22:28:08 -04:00
Christer Edwards
49e24c9ec9 Merge pull request #313 from cedwards/rdr-standardization
rdr now persists rules by default; rdr.sh cleanup
2021-01-14 19:16:35 -07:00
Jose
2474382756 Improve interface validation on vnet jail creation 2021-01-12 23:15:39 -04:00
Jose
87944a0fd0 Don't allow underscore in jail name beginning, remove jail from bastille_list on destroy 2021-01-10 18:55:02 -04:00
Jose
6aa84cb3f5 Small cosmetic/typo corrections 2021-01-10 02:26:40 -04:00
Jose
ed8ff8bd80 Fix to properly upgrade base releases 2021-01-09 21:24:05 -04:00
Christer Edwards
74fdcbdcb5 rdr now persists rules by default; rdr.sh cleanup 2021-01-09 15:42:24 -07:00
Jose
996e7e2b40 Option to enable/disable jail auto-start using sysrc 2021-01-09 16:18:11 -04:00
Jose
665cc19ce6 Properly link shared ports on thin jails 2021-01-08 22:37:18 -04:00
Jose
d2fcc011be Feature option for safe ZFS jail exports, config update 2021-01-08 20:30:03 -04:00
Jose
b528289815 Don't start empty jails unless templates defined, code improvements 2021-01-08 20:26:31 -04:00
Christer Edwards
110346f9f7 Merge pull request #312 from yaazkal/patch-2
export: Clarifies that UFS jails must be stopped
2021-01-08 17:13:23 -07:00
yaazkal
099f09c8b0 export: Clarifies that UFS jails must be stopped 2021-01-08 17:54:31 -05:00
Jose
083e019081 Don't start empty jails, don't apply template if Bastillefile is empty 2021-01-08 02:05:30 -04:00
Gerrit Sere
bc143f8fe2 Merge branch 'master' of https://github.com/BastilleBSD/bastille into cmdbug 2021-01-06 13:42:39 +01:00
Christer Edwards
4824d95d68 Merge pull request #307 from cedwards/rdr-fix-20210101
fix %s->%d regression
2021-01-05 18:30:46 -07:00
Christer Edwards
cc870b2667 fix %s->%d regression 2021-01-05 18:24:02 -07:00
Christer Edwards
67362ff309 Merge pull request #306 from cedwards/rdr-fix-20210101
add required 'pass' to rdr rules
2021-01-05 18:07:05 -07:00
Christer Edwards
6f043d62e5 add required 'pass' to rdr rules 2021-01-05 18:00:28 -07:00
Bike Dude
03ab9fd203 Thick Upgrade 2021-01-05 20:38:08 +01:00
Gerrit Sere
b2134145a2 bastille cmd exit code not respected #272 2021-01-05 00:30:06 +01:00
Christer Edwards
7c271df2f5 Merge pull request #301 from cedwards/release-prep-20210101
version bumps for release preparation
2021-01-01 09:32:55 -07:00
Christer Edwards
c9b02fa1dd Merge pull request #302 from cedwards/vnet-checks
adding a couple vnet exceptions for ip4.addr checks
2021-01-01 09:27:16 -07:00
Christer Edwards
83a83e087e adding a couple vnet exceptions for ip4.addr checks 2021-01-01 09:23:26 -07:00
Christer Edwards
a0feac3f66 version bumps for release preparation 2021-01-01 09:13:44 -07:00
Christer Edwards
4136f8fff4 Merge pull request #296 from chriswells0/require-interface
Verify interface exists when starting jail.
2020-12-31 15:00:46 -07:00
Christer Edwards
1120a0eebd Merge pull request #279 from chriswells0/default-templates
Use templates for configuring new jails.
2020-12-31 15:00:13 -07:00
Christer Edwards
c337994414 Merge pull request #297 from hackacad/zfs_bootstrap
Check if ZFS is enabled in rc.conf and bastille.conf
2020-12-23 09:56:20 -07:00
Christer Edwards
d9ee2e190d Merge pull request #298 from hackacad/stop_rdr
stop.sh: clear rdr
2020-12-23 09:55:32 -07:00
Bike Dude
ca8819d7b6 stop.sh: clear rdr 2020-12-15 10:21:11 +01:00
Bike Dude
32a1278326 add ZFS check on bootstrap 2020-12-15 09:21:26 +01:00
Bike Dude
cbd60032fc add ZFS check on bootstrap 2020-12-15 09:12:02 +01:00
Chris Wells
a56c37983c Verify interface exists when starting non-vnet jail.
Closes #128.
2020-12-14 12:24:22 -05:00
Christer Edwards
2e5811b1ee Merge pull request #294 from BastilleBSD/247-fix-documentation
update devfs.rules documentation
2020-12-13 11:14:27 -07:00
Christer Edwards
857b5d430b cleanup patch; vnet specific 2020-12-13 11:11:15 -07:00
Christer Edwards
a3d2f69b71 cleanup patch; vnet specific 2020-12-13 11:10:29 -07:00
Christer Edwards
7150b63391 update VNET devfs documentation 2020-12-13 11:05:25 -07:00
Christer Edwards
31dfa2bfba Merge pull request #293 from chriswells0/grep-fixes
Fix grep when UTF-8 is not used.
2020-12-13 09:10:36 -07:00
Chris Wells
7675286cd3 Fix grep when UTF-8 is not used.
Support tabs and spaces in templates/config.
2020-12-12 19:17:20 -05:00
Christer Edwards
be6b1adfb9 Merge pull request #285 from chriswells0/hook-conversion
Add ability to convert "hook" files to Bastillefile format.
2020-12-12 12:05:35 -07:00
Christer Edwards
4e843be9e3 Merge pull request #276 from chriswells0/render-message
Display message about file/directory being rendered.
2020-12-12 11:55:04 -07:00
Christer Edwards
62c8060b53 Merge pull request #286 from chriswells0/document-limits
Add missing subcommands (limits/config) to docs.
2020-12-12 11:54:25 -07:00
Christer Edwards
01494ad3fd Merge pull request #289 from chriswells0/limits-fixes
Update existing limit when a new value is provided.
2020-12-12 11:54:05 -07:00
Christer Edwards
574f655cc8 Merge pull request #290 from andrewhotlab/master
Respect exec.fib parameter in console command
2020-12-12 11:53:38 -07:00
Christer Edwards
160040d2e9 Merge pull request #291 from JRGTH/master
Update help usage on update command
2020-12-12 11:52:46 -07:00
Christer Edwards
73c500ce3e Merge pull request #288 from chriswells0/config-fixes
Properly escape config property and value.
2020-12-12 11:52:04 -07:00
Christer Edwards
81ff4a3243 Merge pull request #287 from chriswells0/default-args
Provide JAIL_NAME and JAIL_IP as default template args.
2020-12-12 11:51:05 -07:00
Christer Edwards
7c134184c6 Merge pull request #292 from PetruGarstea/feature/rctl-logging
log rctl events to /var/log/messages
2020-12-12 11:48:07 -07:00
Chris Wells
54f6ef62cd Properly escape config property and value. 2020-12-11 18:27:58 -05:00
Petru Garstea
02f9df6cc0 log rctl events to /var/log/messages 2020-12-11 15:47:48 -05:00
Jose
c6ad100d8a Update help usage on update command 2020-12-02 06:41:45 -04:00
Andrew
7d44a39a01 Respect jexec.fib parameter in console command
If parameter "exec.fib" exists in jail.conf, use it when jexec'ing into the jail.
2020-12-01 13:03:15 +01:00
Chris Wells
c2839f859e Use templates for configuring new jails.
Allow user to override default templates.

Closes #205.
2020-11-29 14:19:41 -05:00
Chris Wells
b90d8c60f7 Update existing limit when a new value is provided.
Closes #233.
2020-11-29 11:34:18 -05:00
Chris Wells
5518273881 Provide JAIL_NAME and JAIL_IP as default template args.
Closes #280.
2020-11-28 19:55:41 -05:00
Chris Wells
a47b0a43c9 Add missing subcommands (limits/config) to docs. 2020-11-28 19:03:46 -05:00
Chris Wells
30a8a93fe9 Display message about file/directory being rendered. 2020-11-28 18:54:14 -05:00
Chris Wells
554f2293c1 Add ability to convert "hook" files to Bastillefile format. 2020-11-28 17:50:39 -05:00
Christer Edwards
b0c27329c9 Merge pull request #284 from chriswells0/stopped-jail-actions
Fix bug preventing commands against stopped jails.
2020-11-28 13:12:52 -07:00
Chris Wells
351020d137 Fix bug preventing commands against stopped jails. 2020-11-28 14:04:15 -05:00
Christer Edwards
ce57d05081 Merge pull request #282 from chriswells0/zfs-case
Use uppercase ZFS when appropriate.
2020-11-28 11:05:09 -07:00
Christer Edwards
0a9ae633e3 Merge pull request #283 from chriswells0/edit-config
Add 'config' command to get/set jail config properties.
2020-11-28 11:01:13 -07:00
Chris Wells
4c9f1aca25 Add 'config' command to get/set jail config properties. 2020-11-28 12:09:56 -05:00
Chris Wells
5e9578ca5e Use uppercase ZFS when appropriate. 2020-11-27 19:20:47 -05:00
Christer Edwards
a9ea02b743 Merge pull request #281 from tobiastom/patch-1
Clarified the `RENDER` functionality.
2020-11-27 10:10:25 -07:00
Christer Edwards
1ffa999f08 Merge pull request #278 from chriswells0/warn-function
Create info() and warn() for cleaner print statements.
2020-11-27 10:09:29 -07:00
Christer Edwards
e1cda4ba15 Merge pull request #273 from JRGTH/master
Upgrade thick jails from bastille
2020-11-27 10:07:35 -07:00
Tobias Tom
64b869e295 Clarified the RENDER functionality. 2020-11-27 12:01:05 +00:00
Christer Edwards
8d3b83bd44 Merge pull request #277 from chriswells0/rdr-ranges
Allow port ranges in RDR parameters.
2020-11-26 07:54:18 -07:00
Chris Wells
8b4d18f8f3 Create info() and warn() for cleaner print statements. 2020-11-25 21:19:08 -05:00
Chris Wells
cc513c3bed Allow port ranges in RDR parameters. 2020-11-25 20:29:15 -05:00
Jose
dd9e55bb9b Update command enhancement and code improvements 2020-11-24 08:38:49 -04:00
Jose
52643c7e07 Add upgrade release validation 2020-11-22 20:01:14 -04:00
Jose
3dc2db84b0 Upgrade thick jails from bastille 2020-11-21 00:33:06 -04:00
Christer Edwards
3c79e1d82b Merge pull request #267 from JRGTH/master
Option to create standard backups on ZFS setups
2020-11-10 13:10:22 -07:00
Christer Edwards
67d2fdcbbb Merge pull request #261 from cbaecker/non-bastille_vs_ALL
Prevent acting on non-bastille jails when using target ALL
2020-11-10 13:07:28 -07:00
Christer Edwards
2483fdd0f0 Merge pull request #255 from chriswells0/template-args
Add support for template args
2020-11-10 13:05:33 -07:00
Chris Wells
2225f48f05 Add support for template args
Closes 211.
2020-10-30 16:05:06 -04:00
Christer Edwards
5b096e82ed Merge pull request #269 from mattaudesse/normalize-template-sh-indentation
Normalize indentation in usr/local/share/bastille/template.sh
2020-10-23 07:31:09 -06:00
Matt Audesse
8bef2bfe63 Normalize indentation in usr/local/share/bastille/template.sh 2020-10-23 07:58:40 -04:00
Christer Edwards
20b6f2ffe6 Merge pull request #268 from tobiastom/feature/persistent-rdr
Make RDR rules persistent between bastille restarts.
2020-10-19 09:08:52 -06:00
Tobias Tom
7d78358f9f Make RDR rules persistent between bastille restarts. 2020-10-19 15:17:46 +01:00
Jose
855dcf3eae Fix to use SYNCDHCP by default while cloning jails 2020-10-17 17:34:25 -04:00
Jose
bc07ff2389 Export command bug fixes and enhancements 2020-10-16 14:48:36 -04:00
Jose
67a9c65912 Option to create standard backups on ZFS setups 2020-10-15 16:20:25 -04:00
Christer Edwards
917b4d8d0b Merge pull request #266 from JRGTH/master
Don't create or modify etc/fstab and etc/crontab on empty jail creation
2020-10-15 11:48:59 -06:00
Jose
ace6c9ab29 Don't create or modify etc/fstab and etc/crontab on empty jail creation 2020-10-15 13:18:55 -04:00
Christer Edwards
5e9e58dd92 Merge pull request #264 from bsdlme/patch-2
Fix pass in rule comment for dynamic rdr
2020-10-13 07:45:17 -06:00
Lars E
2b9aa0ecd3 Fix pass in rule comment for dynamic rdr 2020-10-13 15:43:08 +02:00
Carsten BÃcker
0c5225571f Fix whitespace 2020-09-30 10:41:14 +00:00
Carsten BÃcker
9fd83714c8 Restrict to running jails 2020-09-30 10:36:58 +00:00
Carsten BÃcker
8725e9ccac Prevent acting on non-bastille jails when using target ALL 2020-09-30 09:05:44 +00:00
Christer Edwards
bf5fd4ef2a Merge pull request #258 from yaazkal/patch-1
Update README.md clarifying pf config example
2020-09-22 09:50:21 -06:00
Christer Edwards
5b36a9e762 Merge pull request #257 from chriswells0/rdr-typo
Fix typo in rdr documentation
2020-09-22 09:49:19 -06:00
Christer Edwards
5766d66078 Merge pull request #256 from chriswells0/dev-permissions
Use root as owner when installing from Makefile
2020-09-22 09:49:05 -06:00
Christer Edwards
935118fc99 Merge pull request #251 from chriswells0/require-running-jail
Require target to be running for specific commands
2020-09-22 09:48:28 -06:00
Christer Edwards
976aa077b6 Merge pull request #250 from chriswells0/error-functions
Create and leverage global error functions
2020-09-22 09:47:23 -06:00
yaazkal
cbff4e326d Update README.md clarifying pf config example
Change the pf.conf example in order to prevent issues (jails not allowed to access internet correctly) when the network interface has IP aliases. Many thanks to @cedwards and @chriswells0 for the hints.
2020-09-18 17:53:05 -05:00
Chris Wells
3ca32fa1bc Fix typo in rdr documentation 2020-09-05 21:19:51 -04:00
Chris Wells
fddb762b45 Use root as owner when installing from Makefile 2020-09-05 21:15:01 -04:00
Christer Edwards
a4fcf0100b Merge pull request #249 from chriswells0/cp-alias-fix
Map COPY alias in Bastillefile to use cp subcommand
2020-08-30 20:24:59 -06:00
Chris Wells
c6aded8d0a Ensure target is specified and exists in 1 place instead of many.
Require target to be running for commands that need it.
Closes #239.
2020-08-30 20:15:22 -04:00
Chris Wells
aaffc882f9 Create and leverage global error functions 2020-08-30 10:57:14 -04:00
Chris Wells
94df833e6b Map COPY alias in Bastillefile to use cp subcommand 2020-08-29 19:22:26 -04:00
Christer Edwards
3c070bf908 Merge pull request #248 from cedwards/support-current
initial support for X-current (dev) containers
2020-08-28 14:32:54 -06:00
Christer Edwards
a369ed399d initial support for X-current (dev) containers 2020-08-28 14:13:54 -06:00
Christer Edwards
0ce53f4c4e Merge pull request #246 from JRGTH/master
Fix for bastille bootstrap + update command
2020-08-27 13:33:37 -06:00
Jose
abd80b151f Fix for bastille bootstrap + update command 2020-08-26 14:47:27 -04:00
Christer Edwards
8b196ffaeb Merge pull request #231 from tobiastom/bugfix/templates
Fixed the overlay command in Bastillefile
2020-08-20 16:26:08 -06:00
Tobias Tom
5a9034ff18 Added overlay command to be compatibile with the hooks. 2020-08-20 17:03:21 +01:00
Christer Edwards
7e27bcd36c Merge pull request #242 from tobiastom/feature/fstab-in-template
Added fstab alias to mount command in Bastillefiles.
2020-08-19 11:52:29 -06:00
Christer Edwards
3ebfb69305 Merge pull request #229 from JRGTH/master
Initial alternate architecture fetch/create support
2020-08-19 11:49:11 -06:00
Christer Edwards
d09644dc23 Merge pull request #243 from tobiastom/feature/display-failed-command
Use the correct variable to display the failed template command.
2020-08-19 11:40:19 -06:00
Tobias Tom
1dd2280e2c Use the correct variable to display the failed template command. 2020-08-18 15:02:23 +01:00
Tobias Tom
14dbc09b7c Added fstab alias to mount command in Bastillefiles. 2020-08-18 14:58:19 +01:00
Christer Edwards
388cb39607 Merge pull request #232 from hackacad/master
limits needs 3 args
2020-08-10 20:01:42 -06:00
Christer Edwards
ad749e8a75 Merge pull request #236 from bmac2/master
update to include Bastillefile as a valid HOOK in verify process
2020-08-07 10:26:51 -06:00
Barry McCormick
85176e35da update to include Bastillefile as a valid HOOK in verify process 2020-08-07 09:24:24 -07:00
Jose
a0b0eadc68 Display return status on bastille cp batch/loop 2020-07-31 08:51:47 -04:00
Jose
709f00a2ac Improve bastille/cp return status 2020-07-31 04:07:58 -04:00
hackacad
dc1b1f838a limits needs 3 args 2020-07-28 19:15:43 +02:00
Tobias Tom
24b4985371 Renamed cp command to overlay to match the documentation. 2020-07-27 15:06:19 +01:00
Jose
3872f93063 Post-creation jail misc configuration 2020-07-24 15:37:50 -04:00
Jose
3c19c5b183 Initial alternate architecture fetch/create support 2020-07-24 10:47:28 -04:00
Christer Edwards
5edf9cbe51 Merge pull request #224 from cedwards/update-20200714
update to 0.7.20200714
2020-07-13 21:49:31 -06:00
Christer Edwards
845bb9106f update to 0.7.20200714 2020-07-13 21:48:03 -06:00
Christer Edwards
9150da4a5f Merge pull request #223 from cedwards/docs_update-20200714
update docs for 0.7.20200714 release
2020-07-13 21:45:51 -06:00
Christer Edwards
d3d4a9c030 updating subcommand index 2020-07-13 19:32:44 -06:00
Christer Edwards
da15b4f59a update docs for 0.7.20200714 release 2020-07-13 19:27:23 -06:00
Christer Edwards
93bc945e90 Merge pull request #222 from cedwards/BUG-195
update bastille log path
2020-07-13 12:50:01 -06:00
Christer Edwards
b9efa0ad04 update bastille log path 2020-07-10 08:18:21 -06:00
Christer Edwards
579cf76a38 Merge pull request #221 from JRGTH/master
Force unmount any filesystems before jail rename, error handling
2020-07-10 08:10:36 -06:00
Christer Edwards
328112c74e Merge pull request #218 from chriswells0/template-subcommands
Execute template hooks using Bastille subcommands
2020-07-10 08:10:16 -06:00
Jose
428fd59925 Recursively destroy base release to deal with previous snapshots 2020-07-09 22:26:06 -04:00
Chris Wells
0fd46b50e5 Merge branch 'master' into template-subcommands 2020-07-09 20:38:43 -04:00
Jose
77274adb95 Force unmount any filesystems before jail rename, error handling 2020-07-09 20:00:25 -04:00
Christer Edwards
af6f0064d6 Merge pull request #220 from cynix/fix_template_fstab
Deduplicate template fstab entries using their full paths.
2020-07-08 19:30:02 -06:00
cynix
ed50e3fa04 Fix deduplication in 'mount' command as well 2020-06-22 00:19:02 +10:00
cynix
d01ca09eaa Deduplicate template fstab entries using their full paths.
This allows a fstab entry that happens to be a substring of the
jail path (or that of an existing entry) to be added correctly.
2020-06-22 00:06:40 +10:00
Chris Wells
7cdbe9ac3d Merge branch 'master' into template-subcommands 2020-06-20 15:15:14 -04:00
Jose
012510e312 Append PATH over defined PATH, fix colors.pre on bastille command 2020-06-20 11:53:38 -04:00
Jose
d7413d29ec Define local variables just once 2020-06-20 11:53:38 -04:00
Jose
8d98b8f6ec User option to force destroy jail in ZFS 2020-06-20 11:53:38 -04:00
Chris Wells
016523253a Add mount and umount commands to manage volumes inside containers. 2020-06-20 11:53:38 -04:00
X86BSD
a0f4752287 Correct a typo
Compatibility was spelled wrong.
2020-06-20 11:53:38 -04:00
X86BSD
7514e800f4 Clarify description of bastille_bootstrap_archives
Make it clear its a white space separated list not a ',' separated list.
2020-06-20 11:53:38 -04:00
Marius van Witzenburg
b98b841a1c Add vagrant support for testing 2020-06-20 11:53:38 -04:00
Chris Wells
26c41543c2 Add Bastillefile support to templates. 2020-06-20 11:53:35 -04:00
Gleb Popov
d92aeb3f70 clone cmd is listed twice, fix it 2020-06-20 11:50:15 -04:00
Christer Edwards
99bd323897 Merge pull request #215 from JRGTH/master
Option to force destroy jail in ZFS
2020-06-19 08:45:36 -06:00
Christer Edwards
3fccba30d6 Merge pull request #216 from chriswells0/mount
Add mount and umount commands to manage volumes inside containers.
2020-06-19 08:44:18 -06:00
Christer Edwards
547aa27816 Merge pull request #213 from X86BSD/patch-1
Clarify description of bastille_bootstrap_archives
2020-06-19 08:43:21 -06:00
Christer Edwards
e9c2a4d7b6 Merge pull request #209 from mariusvw/feature/vagrant
Add vagrant support for testing
2020-06-19 08:42:31 -06:00
Christer Edwards
8b00e0adf4 Merge pull request #217 from chriswells0/bastillefile
Add Bastillefile support to templates.
2020-06-19 08:42:03 -06:00
Christer Edwards
457e95a08b Merge pull request #219 from arrowd/patch-1
clone cmd is listed twice, fix it
2020-06-19 08:40:57 -06:00
Gleb Popov
0cbf8e93dd clone cmd is listed twice, fix it 2020-06-17 10:19:12 +04:00
Jose
932f1afae1 Append PATH over defined PATH, fix colors.pre on bastille command 2020-05-25 22:09:17 -04:00
Jose
6fb6e49c6c Define local variables just once 2020-05-25 19:35:38 -04:00
Chris Wells
42bafe7619 Execute template hooks using Bastille subcommands 2020-05-24 20:41:11 -04:00
Chris Wells
61ee522f18 Add Bastillefile support to templates. 2020-05-23 21:03:12 -04:00
Chris Wells
1d21ff58fe Add mount and umount commands to manage volumes inside containers. 2020-05-23 18:35:00 -04:00
Jose
0658a343d3 Merge remote-tracking branch 'upstream/master' 2020-05-22 21:47:52 -04:00
Jose
147e7d5db3 User option to force destroy jail in ZFS 2020-05-22 21:46:03 -04:00
Christer Edwards
b515565bde Merge pull request #210 from mariusvw/feature/config-check
Feature/config check
2020-05-20 09:52:46 -06:00
Christer Edwards
a28201f53e Merge pull request #207 from JRGTH/master
Feature add, create empty jail and minor maintenance
2020-05-20 09:51:16 -06:00
Jose
c98ea0a380 Improve checks in rename, update any spaces/tabs in jail.conf, remove redundant code 2020-05-12 02:47:26 -04:00
Jose
9344b2f647 Allow rename legacy jail directory even if zfs is explicitly configured 2020-05-10 11:03:38 -04:00
Jose
33588397ad Error handling, don't delete legacy directory unless really empty 2020-05-10 10:09:17 -04:00
Jose
d47e2a7cfb Bugfix on bastille rename, let zfs inherit mountpoint 2020-05-10 08:12:19 -04:00
Jose
8826f53d9a Minor code cleanup 2020-05-09 15:41:34 -04:00
Jose
f84fd4ad85 Improve name validation for create and rename, add error_notify function 2020-05-09 15:31:15 -04:00
Jose
e07f6cb0ed Add proper name valoidation in rename command, don't allow blanks in names 2020-05-09 13:59:58 -04:00
Jose
a607dc2719 Properly check for home dir and symlink 2020-05-07 22:50:43 -04:00
X86BSD
b6b76fb7ae Correct a typo
Compatibility was spelled wrong.
2020-05-03 17:21:08 -05:00
X86BSD
3035e86d55 Clarify description of bastille_bootstrap_archives
Make it clear its a white space separated list not a ',' separated list.
2020-05-03 16:59:33 -05:00
Jose
702a0b8318 Update config, missing quotes added 2020-04-25 08:43:59 -04:00
Jose
9617a2ab9a Update sendmail rcvars, code consistency maintenance. 2020-04-25 08:26:12 -04:00
Marius van Witzenburg
b80bbfe838 Add check for config existance and readable 2020-04-21 02:34:02 +02:00
Marius van Witzenburg
cdda90fa69 Remove duplicate config loading 2020-04-21 02:33:38 +02:00
Marius van Witzenburg
5c0e5dea35 Removed duplicate for colors.pre.sh 2020-04-21 00:23:17 +02:00
Marius van Witzenburg
4d9d4f61ef Add vagrant support for testing 2020-04-21 00:02:30 +02:00
Jose
a98032e912 Feature add, create empty jail and minor maintenance 2020-04-18 18:02:11 -04:00
Christer Edwards
268008b967 Merge pull request #206 from JRGTH/master
Fix for pfctl on start/stop commands, clean up excess double quotes
2020-04-16 08:16:26 -06:00
Jose
f54151cf94 Fix for pfctl on start/stop commands, clean up excess double quotes 2020-04-16 07:53:53 -04:00
Christer Edwards
5249e2580a Merge pull request #204 from cedwards/0_6_hotfix
start/stop hotfix and version bump
2020-04-14 22:26:13 -06:00
Christer Edwards
ef320ebcdc start/stop hotfix and version bump 2020-04-14 22:18:21 -06:00
Christer Edwards
0378e3f5bd Merge pull request #201 from mariusvw/hotfix/whitespace
Hotfix/whitespace
2020-04-14 08:46:31 -06:00
Christer Edwards
e989af8144 Merge pull request #202 from mariusvw/hotfix/zoneinfo-path-1
Correct capital E in zonepath to UTC
2020-04-14 08:43:07 -06:00
Marius van Witzenburg
9e6028eba4 Use list style for contributor names 2020-04-14 11:56:45 +02:00
Marius van Witzenburg
f28054b47e Cleanup whitespace 2020-04-14 11:53:11 +02:00
Marius van Witzenburg
597175bafb Correct capital E in zonepath to UTC 2020-04-14 11:38:47 +02:00
Christer Edwards
0ed07b4ee2 Merge pull request #200 from cedwards/0_6_fixes
fix route auto-detect and SERVICE template
2020-04-13 19:42:30 -06:00
Christer Edwards
21937ddbe8 update VNET DHCP to SYNCDHCP 2020-04-13 19:41:50 -06:00
Christer Edwards
72857be9d0 fix route auto-detect and SERVICE template 2020-04-13 18:01:52 -06:00
Christer Edwards
a95040ac62 Merge pull request #198 from cedwards/0_6_release_validation
updating release version
2020-04-12 19:41:44 -06:00
Christer Edwards
9173674256 updating release version 2020-04-12 19:39:46 -06:00
Christer Edwards
0ca7c467ec Merge pull request #197 from cedwards/0_6_release_validation
release validation fixes
2020-04-12 19:15:13 -06:00
Christer Edwards
6558fdc403 Merge pull request #196 from cedwards/network_cleanup
network cleanup; default route addition for vnet
2020-04-12 19:12:38 -06:00
Christer Edwards
945944feb4 release validation fixes 2020-04-12 19:06:27 -06:00
Christer Edwards
106c566c88 network cleanup; default route addition for vnet 2020-04-12 17:04:37 -06:00
Christer Edwards
84b091474d Merge pull request #191 from JRGTH/master
Support for 'qjail' imports, import cmd improvements and fixes
2020-04-11 11:02:31 -06:00
Jose
4d538da4f8 Support for 'qjail' imports, import cmd improvements and fixes 2020-04-11 11:12:03 -04:00
Christer Edwards
f211fd268c Merge pull request #187 from hackacad/fix_man7
updated man page
2020-04-11 07:25:07 -06:00
Bike Dude
2f8128b160 updated 0.6.20200412 2020-04-10 21:19:39 +02:00
Christer Edwards
4e3b972cf7 Merge pull request #190 from JRGTH/master
Code cleanup, don't delete snapshot recursively
2020-04-09 09:20:41 -06:00
Jose
00443ccdd1 Destroy related datasets on target, simplify snapshot naming 2020-04-09 06:32:00 -04:00
Jose
d4dc133e19 Revert to recursive, mandatory here 2020-04-08 23:33:43 -04:00
Jose
4788e78436 Code cleanup, don't delete snapshot recursively 2020-04-08 23:21:13 -04:00
Christer Edwards
7ab17c2355 Merge pull request #184 from JRGTH/master
Support for 'ezjail' archive import, improvements and fixes
2020-04-08 12:57:06 -06:00
Christer Edwards
e436b36168 Merge pull request #182 from hackacad/rdr_destroy
add_rdr_destroy
2020-04-08 12:50:04 -06:00
Christer Edwards
7933d02d47 Merge pull request #173 from hackacad/clone.sh
RFC [NEW FEATURE] clone.sh
2020-04-08 12:45:43 -06:00
Christer Edwards
537cd66fd4 Merge pull request #188 from hackacad/fix_zfs_snap
fix zfs snapshot recursive
2020-04-08 08:19:52 -06:00
Bike Dude
3f386056a9 fix zfs snapshot recursive 2020-04-08 14:10:38 +02:00
Jose
241ce01074 Let zfs mountpoints be inherited on standard archive imports 2020-04-08 06:47:33 -04:00
svru
4de6f59e63 updated man page
Signed-off-by: svru <svru@svrus-MacBook-Pro.local>
2020-04-08 11:24:36 +02:00
Jose
bfa500a183 Always check if user specified path exist 2020-04-04 10:23:43 -04:00
Jose
7db47f3dac Allow the user specify path for Export/Import on-the-fly 2020-04-04 09:46:56 -04:00
Jose
c2fefc5f16 Support for 'ezjail' archive import, improvements and fixes 2020-04-03 07:56:28 -04:00
Bike Dude
0f4597a2c6 add_rdr_destroy 2020-03-30 22:33:32 +02:00
Christer Edwards
67964a7fbb Merge pull request #181 from cynix/fix_first_vnet_jail
Fix empty interface name when creating the first VNET jail.
2020-03-30 13:51:06 -06:00
cynix
ced148bcc7 Clean up code 2020-03-30 08:48:04 +00:00
cynix
6e850785a2 Fix empty interface name when creating the first VNET jail.
Fixes #170.
2020-03-30 08:41:33 +00:00
Christer Edwards
384ba3b82e Merge pull request #177 from hackacad/chmod_issue
Chmod issue
2020-03-10 15:13:39 -06:00
Bike Dude
512f973950 chmod issue fixed 2020-03-10 20:47:33 +01:00
Bike Dude
2240211f6a fix merge conflict 2020-03-10 20:46:09 +01:00
Sven R
afc363d72d Merge branch 'master' into chmod_issue 2020-03-10 20:41:19 +01:00
Christer Edwards
e804afa2b5 Merge pull request #174 from hackacad/rename_fix
no dots allowed in rename.sh
2020-03-10 10:48:58 -06:00
Christer Edwards
148dba4b22 Merge pull request #176 from hackacad/issue_templates
Create issue templates
2020-03-10 10:48:29 -06:00
Sven R
102fbc7d51 bootstrap chmod 2020-03-10 17:15:46 +01:00
Sven R
ac96e8b6ec bootstrap chmod 2020-03-10 17:14:18 +01:00
Sven R
0cbc8ff8e7 Create issue templates 2020-03-10 15:31:18 +01:00
Bike Dude
af06250c1d no dots allowed in rename.sh 2020-03-06 23:34:18 +01:00
Bike Dude
ed90760f68 several fixes 2020-03-06 23:12:09 +01:00
hackacad
c03d43af09 fix 2020-03-04 12:22:24 +01:00
hackacad
bc82da9aaa [NEW FEATURE] clone.sh 2020-03-04 10:52:17 +01:00
Christer Edwards
a3c40b2727 Merge pull request #169 from hackacad/import_fix
fix renaming on bastille import
2020-03-02 10:57:17 -07:00
Sven R
4bd0a9d00d Merge branch 'master' into import_fix 2020-02-27 07:43:52 +01:00
hackacad
a3311c5aa9 Merge branch 'master' of github.com:/hackacad/bastille into import_fix 2020-02-27 07:39:16 +01:00
Sven R
659517b595 fix_import 2020-02-25 12:48:52 +01:00
Sven R
73e97ab18f fix_import 2020-02-25 12:43:16 +01:00
Sven R
c342b5cdc0 fix_import 2020-02-25 12:37:01 +01:00
Christer Edwards
644b5319a1 Merge pull request #168 from cedwards/hushlogin
quiet login message on container login
2020-02-24 19:39:27 -07:00
Christer Edwards
be6a0e1b5f quiet login message on container login 2020-02-24 19:27:51 -07:00
Christer Edwards
d0f5b31e42 Merge pull request #166 from cedwards/quoting_fixes
overzealous quoting
2020-02-21 20:05:10 -07:00
Christer Edwards
8350af9c4f overzealous quoting 2020-02-21 20:04:17 -07:00
Christer Edwards
3945e82213 Merge pull request #162 from JRGTH/master
code standardization/cleanup; import improvements
2020-02-21 19:45:12 -07:00
Jose
9b3fde59b8 Fix Thickjail mountpoint inheritance in the root dataset 2020-02-21 11:35:35 -04:00
Jose
8e30774235 Merge remote-tracking branch 'upstream/master' 2020-02-21 11:31:12 -04:00
Christer Edwards
a18927fb7a Merge pull request #164 from hackacad/bastille_export_fix
remove colon from filename
2020-02-21 07:30:22 -07:00
Sven R
a0b522c48e remove colon from filename 2020-02-21 13:58:45 +01:00
Jose
29016faf20 Just return 0 if bastille_jail_external is set 2020-02-20 21:08:04 -04:00
Jose
01eaccc1da Add double quotes to prevent globbing/word splitting, general code consistency improvements 2020-02-20 18:06:31 -04:00
Christer Edwards
9481b6a1e6 Merge pull request #161 from JRGTH/master
Workaround  to combine options first, code cleanup/maintenance
2020-02-20 09:29:24 -07:00
Jose
8c1f9cd57a Just grep globally if jail list not empty 2020-02-20 12:22:25 -04:00
Jose
6b7b506c83 Simplify destroy options, no need to shift 1 on single options 2020-02-20 10:41:41 -04:00
Jose
e26fe60fe4 Keep options simple yet support for long options 2020-02-19 19:53:25 -04:00
Sven R
2fa9f34be6 lint
remove EOL release (reduce size of README)
2020-02-19 08:34:23 +01:00
Jose
5b25dbcdc5 Initial support to import foreign containers, ignore fstab update if don't exist. 2020-02-18 19:58:59 -04:00
Jose
3b8c339dfa Workaround to combine options first, code cleanup/maintenance 2020-02-18 17:04:06 -04:00
Christer Edwards
c6357127ea Merge pull request #160 from cedwards/quoting_fixes
properly quoting variables
2020-02-17 09:42:37 -07:00
Christer Edwards
950342f54e properly quoting variables 2020-02-17 09:41:33 -07:00
Christer Edwards
f271547e23 Merge pull request #159 from cedwards/documentation
basic VNET example + devfs.rules
2020-02-16 15:44:20 -07:00
Christer Edwards
c4ede0a829 basic VNET example + devfs.rules 2020-02-16 15:43:13 -07:00
Christer Edwards
64a4dd5987 Merge pull request #158 from cedwards/vnet_initial
Ability to create VNET containers
2020-02-16 15:28:13 -07:00
Christer Edwards
814dc6d926 properly set ip6 mode 2020-02-16 15:22:32 -07:00
Christer Edwards
273acb6e50 initial support to create vnet container 2020-02-16 15:20:31 -07:00
Christer Edwards
099c45422d Merge pull request #156 from cedwards/ip6_README
update README with ip6 example
2020-02-16 14:24:10 -07:00
Christer Edwards
863c3cacc5 update README with ip6 example 2020-02-16 14:23:05 -07:00
Christer Edwards
b1380b30e5 Merge pull request #154 from JRGTH/master
Initial IPv6 support
2020-02-16 10:26:08 -07:00
Jose
75fc18fec9 Initial IPv6 support 2020-02-16 13:22:32 -04:00
Christer Edwards
32ddcd5439 Merge pull request #153 from cedwards/edit_fixes
fixes for new edit sub-command; supports stopped as it should
2020-02-16 09:57:49 -07:00
Christer Edwards
26846d510e fixes for new edit sub-command; supports stopped as it should 2020-02-16 09:56:04 -07:00
Christer Edwards
44989660d2 Merge pull request #152 from JRGTH/master
Ignore IPv4 check if there is no entry at all
2020-02-15 13:43:44 -07:00
Jose
015558c4bc Don't set jail ZFS dataset mountpoint, let be inherited from the system 2020-02-15 07:57:33 -04:00
Jose
53e7856d28 Ignore IPv4 check if there is no entry at all 2020-02-14 19:01:08 -04:00
Christer Edwards
0e39f7cabb Merge pull request #151 from JRGTH/master
Return proper warning messages, code cleanup
2020-02-14 08:46:18 -07:00
Jose
19cadec03e Add quoted variables to rctl 2020-02-14 11:43:26 -04:00
Jose
7ef65036c6 Return proper warning messages, code cleanup 2020-02-14 11:00:02 -04:00
Christer Edwards
ee81a73264 Merge pull request #148 from hackacad/Makefile_bastilleconf
make deinstall: avoid removing bastille.conf
2020-02-13 06:58:05 -07:00
Sven R
fd90a21777 make deinstall: avoid removing bastille.conf 2020-02-13 07:37:38 +01:00
Sven R
a3494c1007 make deinstall: avoid removing bastille.conf 2020-02-13 07:34:31 +01:00
Christer Edwards
d667f93bc5 Merge pull request #147 from cedwards/edit_jail_files
ability to edit TARGET files (jail.conf, fstab, etc)
2020-02-12 16:48:46 -07:00
Christer Edwards
1e2bbcd3b7 Merge pull request #146 from JRGTH/master
Cleanup unused code, display related platform OS while bootstrapping …
2020-02-12 16:47:51 -07:00
Jose
1d1ea761fe Display corresponding platform OS while extracting distfiles 2020-02-11 17:43:52 -04:00
Jose
bf0bffd30f Update HardenedBSD options in bootstrap command too 2020-02-11 17:27:02 -04:00
Jose
fe012c44f0 Update HardenedBSD options in destroy command too 2020-02-10 15:39:14 -04:00
Jose
d1709b7199 Add HardenedBSD support for convert, import and rename commands 2020-02-10 15:22:41 -04:00
Jose
0e93832a30 Minor change, update comment 2020-02-10 14:10:00 -04:00
Jose
206d6a59e9 Ability to rename containers in both ZFS and UFS platforms 2020-02-10 14:03:28 -04:00
Christer Edwards
e3492d4087 ability to edit TARGET files (jail.conf, fstab, etc) 2020-02-10 10:42:09 -07:00
Jose
84cc8cb103 Cleanup unused code, display related platform OS while bootstrapping for reference 2020-02-08 09:10:17 -04:00
Christer Edwards
7b706f83f4 Merge pull request #144 from cedwards/0_6_release_prep
preparation for 0.6x initial release
2020-02-05 19:04:23 -07:00
Christer Edwards
62c77b4e71 preparation for 0.6x initial release 2020-02-05 19:02:19 -07:00
Christer Edwards
488b6b614b Merge pull request #142 from hackacad/man_page_0.6
update man page for 0.6
2020-02-05 12:35:54 -07:00
Christer Edwards
e6fb8ba45f Merge pull request #143 from JRGTH/master
Code improvements, use awk for exact match
2020-02-05 12:25:36 -07:00
Jose
498029a13c Code improvements, use awk for exact match 2020-02-05 07:00:11 -04:00
hackacad
c9db9b41d0 update man page for 0.6 2020-02-05 09:12:31 +01:00
Christer Edwards
9a1b673721 Merge pull request #141 from cedwards/fixes
Few fixes
2020-02-04 14:54:10 -07:00
Christer Edwards
11d7524446 checks needs to run before jail starts 2020-02-04 14:52:19 -07:00
Christer Edwards
b1e44e39ce add missing fi 2020-02-04 14:51:59 -07:00
Christer Edwards
70eb3e6aa2 Merge pull request #139 from JRGTH/master
Compare/update fstab if both variables are set
2020-02-04 13:01:13 -07:00
Jose
96fcc6b591 Remove unneeded cat command 2020-02-04 15:56:52 -04:00
Jose
b3f4064d08 Compare/update fstab if both variables are set 2020-02-04 13:37:20 -04:00
Christer Edwards
7e43c10281 Merge pull request #138 from hackacad/ip_check
Check if IP address is in use
2020-02-04 09:38:26 -07:00
Christer Edwards
210a4f5018 Merge pull request #137 from hackacad/moveconfigfilesample
move bastille.config file to bastille.config.sample
2020-02-04 06:47:21 -07:00
hackacad
3171015ea3 move config file to .sample to avoid overwriting it when updating/upgrading bastille 2020-02-04 09:32:45 +01:00
hackacad
45f9247be9 Check if IP address is in use. 2020-02-04 09:30:03 +01:00
Christer Edwards
f61c530265 Merge pull request #121 from JRGTH/master
Add HardenedBSD CURRENT and LATEST download options, and code improve…
2020-02-02 20:52:07 -07:00
Jose
b3a30a8951 Delete cache files on destroy if force option, remove alternate urls 2020-02-02 19:55:18 -04:00
Christer Edwards
031a23400e Merge pull request #122 from cedwards/doc_updates
preparing docs for 0.6.x release
2020-02-02 14:00:35 -07:00
Christer Edwards
830de68bf9 preparing docs for 0.6.x release 2020-02-02 13:56:02 -07:00
Jose
9517d9608e Fix typo in bootstrap.sh 2020-02-02 12:03:35 -04:00
Jose
874e3696e3 Do not hardcode alternate url's in bootstrap.sh 2020-02-02 12:00:09 -04:00
Jose
013987f7e1 Fix minor bootstrap.sh regression 2020-02-02 07:24:16 -04:00
Jose
9681254d76 Add force stop option to bastille destroy, minor code cleanup 2020-02-02 06:50:58 -04:00
Jose
5aba0d36f5 Do not use suffix version number in HardenedBSD "CURRENT" releases 2020-02-02 04:08:24 -04:00
Jose
7620d61e49 Add HardenedBSD CURRENT and LATEST download options, and code improvements 2020-02-02 02:42:22 -04:00
Christer Edwards
503f787d69 Merge pull request #119 from paulc/master
Add support for dynamic redirection of host/container ports
2020-02-01 18:11:48 -07:00
pc
d8914f9892 Switch from --option to option and fix typos 2020-02-02 00:28:02 +00:00
pc
fe16a25cee Update README 2020-02-01 16:12:20 +00:00
Christer Edwards
f5ddc434a3 Merge pull request #118 from cedwards/115-Makefile-fix
reverting Makefile; resolves #115
2020-02-01 09:08:40 -07:00
pc
e408254448 Update README 2020-02-01 16:06:13 +00:00
Christer Edwards
56f2f9afb6 reverting mkdir; resolves #115 2020-02-01 09:05:29 -07:00
pc
f65fe999cc Add dynamic rdr 2020-02-01 15:58:02 +00:00
Christer Edwards
eb38963752 Merge pull request #113 from cedwards/little_fixes
Minor fixes to create and import
2020-01-28 17:41:59 -07:00
Christer Edwards
97417b5b4f updating import usage output 2020-01-28 17:36:30 -07:00
Christer Edwards
2cfcc4b8ad simplify variable usage in interface validation 2020-01-28 17:36:17 -07:00
Christer Edwards
d9d52f09e3 Merge pull request #109 from JRGTH/master
Initial support for container export and import
2020-01-28 17:17:19 -07:00
Christer Edwards
08d9449f42 Merge branch 'master' into master 2020-01-28 16:05:23 -07:00
Jose
38ae0ed4a6 Update list command and config 2020-01-28 18:57:51 -04:00
Christer Edwards
19e1cbf0fe Merge pull request #112 from hackacad/master
bootstrap_urls in bastille.conf
2020-01-28 09:31:41 -07:00
Sven R
eedcaf9abb bootstrap_url in bastille.conf 2020-01-28 17:25:41 +01:00
Sven R
0f20ae255f bootstrap_url in bastille.conf 2020-01-28 09:51:26 +01:00
Sven R
4a94dd53f8 bootstrap_url in bastille.conf 2020-01-28 09:14:14 +01:00
Jose
095075b142 Initial support for container export and import 2020-01-26 19:45:26 -04:00
Christer Edwards
af15a39160 Merge pull request #108 from cedwards/documentation
updating template docs to include limits support
2020-01-26 12:46:01 -07:00
Christer Edwards
a60c678036 updating template docs to include limits 2020-01-26 12:43:45 -07:00
Christer Edwards
7c5436c740 Merge pull request #107 from cedwards/list_update
support listing currently enabled container resource limits
2020-01-26 11:49:44 -07:00
Christer Edwards
27393f8db4 support listing current defined container resource limits 2020-01-26 11:48:21 -07:00
Christer Edwards
9917550093 Merge pull request #106 from cedwards/template_support_limits
add/remove rctl limits on container start/stop
2020-01-26 10:10:36 -07:00
Christer Edwards
02d0e94ef6 add/remove rctl limits on container start/stop 2020-01-26 10:08:42 -07:00
Christer Edwards
49c60f9896 Merge pull request #105 from cedwards/template_support_limits
Initial support for LIMITS in template automation
2020-01-26 09:56:48 -07:00
Christer Edwards
8b9760b0a5 initial support for limits automation; updated copyright year 2020-01-26 09:51:02 -07:00
Christer Edwards
798d182e21 Merge pull request #104 from jpmens/patch-3
remove duplicate entry in sub-command list
2020-01-26 07:30:12 -07:00
Christer Edwards
04303353f2 Merge pull request #103 from jpmens/patch-2
make escaped quote visible
2020-01-26 07:29:50 -07:00
JP Mens
aa15b13594 remove duplicate entry 2020-01-26 15:26:15 +01:00
JP Mens
9299670126 make escaped quote visible 2020-01-26 15:18:29 +01:00
Christer Edwards
0940d86d62 Merge pull request #96 from hackacad/master
initial man page
2020-01-19 19:15:12 -07:00
Christer Edwards
b16d32e673 Merge pull request #97 from JRGTH/master
Add support for thinjail to thickjail conversion, minor code fixes
2020-01-19 19:14:21 -07:00
Jose
e0d722203a Bootstrap additional distfiles after updating bootstrap_archives 2020-01-18 16:17:10 -04:00
Jose
39b3c25bb5 Add support for thinjail to thickjail conversion, minor code fixes 2020-01-16 15:03:05 -04:00
Sven R
39a12abe25 initial man page 2020-01-15 19:56:25 +01:00
Sven R
04b19ccc2b initial man page 2020-01-15 19:49:15 +01:00
Sven R
c588f54156 initial man page 2020-01-15 19:42:58 +01:00
Christer Edwards
19a838921f Merge pull request #95 from bsdlme/master
use find + sed if `tree` not installed
2020-01-15 09:54:18 -07:00
Lars Engels
35717ada4e Print a simple directory tree to verify a template's contents using find + sed if tree(1) is not installed 2020-01-15 17:27:03 +01:00
Christer Edwards
a6b4ede0fa updating contributors 2020-01-15 09:21:29 -07:00
Christer Edwards
4ce6b41c7c Merge pull request #94 from skunkwerks/master
build: fix manual install path
2020-01-15 08:12:18 -07:00
Dave Cottlehuber
6641baad51 build: fix manual install path 2020-01-15 09:52:16 +00:00
Christer Edwards
65855ecd80 Merge pull request #92 from cedwards/cedwards_fstab
cedwards FSTAB template hook
2020-01-12 07:47:26 -07:00
Christer Edwards
ab67cb82d0 fixing README ver (for now) 2020-01-12 07:33:24 -07:00
Christer Edwards
edc6308001 Initial working FSTAB hook and documentation 2020-01-12 07:32:10 -07:00
Christer Edwards
9778a24870 Merge pull request #89 from JRGTH/master
Minor changes, fix notify if container not started
2020-01-08 13:31:34 -07:00
Jose
2eb91e2f95 Improved jail validation and deal with dashes 2019-12-29 23:04:19 -04:00
Jose
f3615a3380 Minor changes, fix notify if container not started 2019-12-27 14:48:06 -04:00
Christer Edwards
9421cc59a0 Merge pull request #88 from JRGTH/master
Fix to match exact container name, add missing quotes
2019-12-27 10:43:07 -07:00
Jose
0c78ebae88 Fix to match exact container name, add missing quotes 2019-12-27 13:15:58 -04:00
Christer Edwards
de1590d709 Merge pull request #86 from hackacad/master
support for ressource limits; small Makefile improvemts
2019-12-26 08:58:17 -07:00
Christer Edwards
ff9313a2ca Merge pull request #85 from JRGTH/master
Improved container update process, add support for Thickjail updates
2019-12-26 08:57:31 -07:00
Sven R
bac677dc41 added ressource limits 2019-12-23 10:54:09 +01:00
Sven R
8770e5dd4c Merge branch 'master' of https://github.com/hackacad/bastille 2019-12-23 09:59:00 +01:00
Sven R
861953734f added chmod to Makefile
Signed-off-by: Sven R <admin@hackacad.net>
2019-12-23 09:57:56 +01:00
Sven R
b16b393717 Update Makefile 2019-12-23 09:48:02 +01:00
Sven R
9b859f84ed added all to Makefile
Signed-off-by: Sven R <admin@hackacad.net>
2019-12-23 09:46:32 +01:00
Jose
ddff440b4f Simplify grep search, add full path to jexec 2019-12-19 11:23:46 -04:00
Jose
61f49e5d02 Merge remote-tracking branch 'upstream/master' 2019-12-19 11:20:47 -04:00
Christer Edwards
eb13d48eac Merge pull request #84 from briandowns/master
Add JSON output for list command
2019-12-18 18:04:23 -07:00
Jose
1b522522af Improved container update process, add support for Thickjail updates 2019-12-17 18:11:22 -04:00
Brian Downs
71873e9389 readme update 2019-12-15 21:20:34 -07:00
Brian Downs
ffe6efd0e5 add json output for jail list 2019-12-15 21:16:57 -07:00
Christer Edwards
d95d815949 Merge pull request #79 from JRGTH/master
Minor code cleanup/formatting
2019-12-12 20:41:22 -08:00
Christer Edwards
0fd6cd0fd9 Merge pull request #81 from bsdlme/patch-1
Add more examples to service documentation
2019-12-12 20:39:34 -08:00
Christer Edwards
4a1e769036 Merge pull request #82 from bsdlme/master
Add "" around variables in test(1) cases to prevent errors when a variable is empty
2019-12-12 20:38:27 -08:00
Lars Engels
a57ae3ff46 Bail out when you try to apply a template to a container that is not started. 2019-12-11 21:17:09 +01:00
Lars Engels
5b11f81a1b Add "" around variables in test(1) cases to prevent errors when a variable is unset 2019-12-11 20:35:05 +01:00
Lars E
ed60f9c409 Add more examples
Since FreeBSD 12.0 service(8) supports enable/disable/delete keywords. This also works with the 'bastille service' command.
2019-12-11 19:04:58 +01:00
Jose
23b96bd82a Minor code cleanup/formatting 2019-12-08 17:46:15 -04:00
Christer Edwards
3f7573825d Merge pull request #78 from cedwards/template_work
template validation improvements
2019-12-07 17:57:03 -07:00
Christer Edwards
265b8480e1 support for local templates and stricter validation 2019-12-07 17:48:39 -07:00
Christer Edwards
abbec0652d clarifying template docs 2019-12-07 17:48:06 -07:00
Christer Edwards
1608d7f226 Merge pull request #76 from JRGTH/master
Added support for:
- HardenedBSD new link structure
- basic mirror support
- console user validation
2019-12-07 16:53:43 -07:00
Jose
172baa8c32 Validate user/shell to prevent stuck login 2019-12-05 16:52:57 -04:00
Jose
cfcad20f4a Simplify URL validation, don't use ping/ICMP 2019-12-05 03:38:33 -04:00
Jose
6e8279ecd4 Wait just 2 secs before switch to a mirror and be quite 2019-12-03 01:20:34 -04:00
Jose
9a30610d1a Provide alternative fetch urls 2019-12-03 00:57:47 -04:00
Jose
f68ed2ecfd Added support for HardenedBSD new link structure 2019-12-02 03:10:45 -04:00
Christer Edwards
29565b22c8 Merge pull request #75 from cedwards/firewall
0.5.20191128 release
2019-11-28 09:23:13 -07:00
Christer Edwards
8414865355 0.5.20191128 release 2019-11-28 09:21:13 -07:00
Christer Edwards
90c0c1d4c0 Merge pull request #74 from cedwards/improvements
updating version string
2019-11-25 21:44:55 -07:00
Christer Edwards
80412679a7 updating version string 2019-11-25 21:44:23 -07:00
Christer Edwards
61eb7f5625 Merge pull request #73 from cedwards/improvements
quieting pfctl output in start/stop
2019-11-25 17:46:00 -07:00
Christer Edwards
fbb99470ec quieting pfctl output in start/stop 2019-11-25 17:45:17 -07:00
Christer Edwards
f2a968a065 Merge pull request #71 from cedwards/improvements
Improvements to firewalling for loopback containers
2019-11-25 17:13:32 -07:00
Christer Edwards
0a708c3dc7 clarification to README on firewall settings 2019-11-25 17:12:27 -07:00
Christer Edwards
f6653a6a48 Merge pull request #72 from JRGTH/master
Additional network config checks
2019-11-25 17:07:46 -07:00
Jose
03597e1489 Additional network config checks 2019-11-25 20:02:56 -04:00
Christer Edwards
f36744f2a0 accidentally a word 2019-11-25 15:41:11 -07:00
Christer Edwards
43da7b25a1 standardizing comments 2019-11-25 15:40:10 -07:00
Christer Edwards
b5c8330502 add PATH; improve firewall 2019-11-25 15:38:40 -07:00
Christer Edwards
e4c4d0df2e Merge pull request #70 from cedwards/RC-test
regression in not using full path to bastille
2019-11-25 08:11:01 -07:00
Christer Edwards
7668927f6d regression in not using full path to bastille 2019-11-25 08:10:29 -07:00
Christer Edwards
635ce83d20 Merge pull request #69 from cedwards/RC-test
updated docs to reflect latest version
2019-11-24 21:04:59 -07:00
Christer Edwards
62b295f009 updated docs to reflect latest version 2019-11-24 21:04:19 -07:00
Christer Edwards
a8d6fe41d3 Merge pull request #68 from cedwards/RC-test
bastille0 bootstrap commands out of order
2019-11-23 16:02:26 -07:00
Christer Edwards
806654eae0 bastille0 bootstrap commands out of order 2019-11-23 16:01:52 -07:00
Christer Edwards
f892bab1b2 Merge pull request #67 from cedwards/RC-test
minor updates to README
2019-11-23 13:52:13 -07:00
Christer Edwards
8409c356a8 minor updates to README 2019-11-23 13:50:55 -07:00
Christer Edwards
864cfd31b8 Merge pull request #66 from cedwards/RC-test
minor fixes discovered during 0.5.20191125 RC
2019-11-23 12:58:39 -07:00
Christer Edwards
4c6acc5b17 minor fixes discovered during 0.5.20191125 RC 2019-11-23 12:56:21 -07:00
Christer Edwards
77114ba818 Merge pull request #65 from cedwards/RC-test
0.5.20191125 RC fixes and formatting
2019-11-22 22:11:53 -07:00
Christer Edwards
5d2954feb9 updating Usage output and standardizing target variable 2019-11-22 22:07:14 -07:00
Christer Edwards
cd4f9ee22e updating Usage output and standardizing target variable 2019-11-22 22:06:50 -07:00
Christer Edwards
3ee2af3b03 updating variable and quoting for coding standards 2019-11-22 22:06:34 -07:00
Christer Edwards
a14d9cffdd updating Usage output and standardizing target variable 2019-11-22 22:05:53 -07:00
Christer Edwards
4dd5579149 updating Usage output and standardizing target variable 2019-11-22 22:05:37 -07:00
Christer Edwards
72cbac6504 updating Usage output and standardizing target variable 2019-11-22 22:05:21 -07:00
Christer Edwards
c68efdfb3d updating Usage output and standardizing target variable 2019-11-22 22:05:02 -07:00
Christer Edwards
62a3821223 updating Usage output and standardizing target variable 2019-11-22 22:04:38 -07:00
Christer Edwards
49065ca95a updating Usage output and standardizing target variable 2019-11-22 22:04:16 -07:00
Christer Edwards
036def57e2 updating Usage output format 2019-11-22 22:03:48 -07:00
Christer Edwards
4ff0e34a66 updating Usage output and adding 'container' to list 2019-11-22 22:03:26 -07:00
Christer Edwards
1740ef4e49 updating Usage output and standardizing target variable 2019-11-22 22:02:58 -07:00
Christer Edwards
9d352588f1 updating Usage output and formatting case statements 2019-11-22 22:02:34 -07:00
Christer Edwards
03be9fc033 updating Usage output 2019-11-22 22:02:09 -07:00
Christer Edwards
3297457129 updating usage and standardizing target variable 2019-11-22 22:01:43 -07:00
Christer Edwards
d9f4972f59 updating Usage format; allowing non-root console option 2019-11-22 22:00:58 -07:00
Christer Edwards
6a7a08b714 updating Usage format and standardizing target variable 2019-11-22 22:00:10 -07:00
Christer Edwards
c4172250c0 updating output to RC script 2019-11-22 21:59:39 -07:00
Christer Edwards
29a8b8a671 brought README up to date with 0.5.20191125 RC 2019-11-22 21:59:11 -07:00
Christer Edwards
6c32bccbe6 Merge pull request #64 from cedwards/cedwards_patches
updating version & usage
2019-11-21 16:59:47 -07:00
Christer Edwards
50ba68935e updating version 2019-11-21 16:58:21 -07:00
Christer Edwards
2616611780 Merge pull request #63 from cedwards/cedwards_patches
patches for 0.5.20191125
2019-11-21 16:52:38 -07:00
Christer Edwards
47a3003f41 update for 0.5.20191125 2019-11-21 16:49:00 -07:00
Christer Edwards
28c2115974 Merge pull request #62 from cedwards/bugfixes
bugfixes for 0.4.20191025
2019-11-20 20:02:09 -07:00
Christer Edwards
ebcf0831dc renaming loop variable to _service 2019-11-20 20:00:26 -07:00
Christer Edwards
4a7b4a6bb0 bugfixes for 0.4.20191025 2019-11-20 19:57:18 -07:00
Christer Edwards
b443427ec3 Merge pull request #61 from cedwards/docs_update
add missing sysrc
2019-11-20 19:52:52 -07:00
Christer Edwards
b75f2601db add missing sysrc 2019-11-20 19:52:11 -07:00
Christer Edwards
03186aefa2 Merge pull request #60 from cedwards/docs_update
updating network documentation with seeded IP
2019-11-20 19:51:11 -07:00
Christer Edwards
19c5796920 updating network documentation with seeded IP 2019-11-20 19:49:39 -07:00
Christer Edwards
1fd259e34b Merge pull request #59 from cedwards/docs_update
updating networking reference
2019-11-20 19:41:10 -07:00
Christer Edwards
2439ebd25e updating networking reference 2019-11-20 19:34:21 -07:00
Christer Edwards
2af895e204 Merge pull request #58 from cedwards/docs_update
s/markdown/rst/ - oops
2019-11-20 19:25:47 -07:00
Christer Edwards
3b97572acf s/markdown/rst/ - oops 2019-11-20 19:24:11 -07:00
Christer Edwards
7e721ab085 Merge pull request #57 from cedwards/docs_update
fixing version string
2019-11-20 19:20:56 -07:00
Christer Edwards
c2cb31decd fixing version string 2019-11-20 19:19:48 -07:00
Christer Edwards
0cf4fd85a6 Merge pull request #56 from cedwards/docs_update
updating documentation for 0.4.20191025
2019-11-20 19:17:24 -07:00
Christer Edwards
e68bd1b3ae standardizing on container vs jail 2019-11-20 19:16:21 -07:00
Christer Edwards
7e2b03b73b updating documentation for 0.4.20191025 2019-11-20 18:54:05 -07:00
Christer Edwards
8a104ea379 Merge pull request #55 from JRGTH/master
Add "thick" container type, improve container name matching, validate network configuration
2019-11-20 16:33:19 -07:00
Jose
b16bed276e Validate network config if external NIC is unspecified 2019-11-20 16:09:26 -04:00
Jose
4eb5d1b9ba Match exact jail name for start/stop commands, don't allow for dots during create 2019-11-19 13:10:24 -04:00
Jose
4fb2cc1247 Apply sane bastille zfs options on thick jails 2019-11-18 13:24:18 -04:00
Jose
3191a9cc1c Use data replication for Thickjail on ZFS systems 2019-11-18 03:51:06 -04:00
Jose
74117629aa Add Thickjail create option and overall improvements and fixes 2019-11-17 18:15:19 -04:00
Christer Edwards
481dc5111f Merge pull request #51 from jpmens/patch-1
CONFIG -> OVERLAY
2019-11-15 08:42:46 -07:00
JP Mens
5bb61a8c7e CONFIG -> OVERLAY
according to 0.4.20190714 the name has changed
2019-11-15 16:38:00 +01:00
Christer Edwards
8efd4740ca Merge pull request #48 from JRGTH/master
Added bootstrap checksum validation and minor fixes
2019-11-09 15:23:05 -07:00
Jose
9bc8837f77 Simplify release name handling, code improvements and fixes 2019-11-08 02:37:45 -04:00
Jose
4f67515157 Create required jail/root dataset on ZFS setups 2019-11-03 01:58:29 -04:00
Jose
3c5d961925 Scan only related jails before base release deletion 2019-11-03 00:15:02 -04:00
Jose
ae2b0ea0cb Added bootstrap checksum validation and minor fixes 2019-11-02 16:05:49 -04:00
Christer Edwards
973c2bc7b2 Merge pull request #47 from cedwards/master
Release cleanup
2019-10-25 19:39:28 -06:00
Christer Edwards
487d2aba43 add support for 11.3-RELEASE, 12.1-RC1, 12.1-RC2, 12.1-RELEASE 2019-10-25 19:33:35 -06:00
Christer Edwards
341469a1db added previously undocumented networking config options 2019-10-25 19:33:16 -06:00
Christer Edwards
3af9b59077 update version to 0.4.20191025 2019-10-25 19:32:52 -06:00
Christer Edwards
5c1074fa16 Merge pull request #45 from JRGTH/master
Add support for FreeBSD 11.3-RELEASE + other checks & fixes
2019-10-25 10:08:35 -06:00
Christer Edwards
3acdb911ab Merge pull request #46 from olgeni/whitespace
Alignment fix in 'bastille.conf'.
2019-10-25 10:05:55 -06:00
Jose
cbe04f2f68 Bastille improvements and fixes 2019-10-24 17:02:50 -04:00
olgeni
fd92827735 Alignment fix in 'bastille.conf'. 2019-10-15 20:23:05 +02:00
Jose
c22b508d25 Fix jail and releases output listing 2019-10-08 03:00:32 -04:00
Jose
9b5a71bd0a Add support for FreeBSD 11.3-RELEASE 2019-10-01 20:11:47 -04:00
Christer Edwards
38727457fc Update README.md
update BastilleBSD-Templates link
2019-08-12 20:15:13 -06:00
Christer Edwards
86b7ba9c49 Merge pull request #44 from cedwards/master
added link to BastilleBSD-Templates
2019-08-02 10:01:40 -06:00
Christer Edwards
bd1f9b94e5 added link to BastilleBSD-Templates 2019-08-02 10:00:03 -06:00
Christer Edwards
5540b22cb1 Merge pull request #43 from cedwards/master
Bastille Day Update
2019-07-15 07:55:23 -06:00
Christer Edwards
e857093979 minor fix in create.sh 2019-07-15 07:51:43 -06:00
Christer Edwards
95cb13739d version rev 2019-07-15 07:47:43 -06:00
Christer Edwards
8935b59635 Bastille Day update 2019-07-15 07:44:45 -06:00
Christer Edwards
4dd6a910d4 Merge pull request #42 from bmac2/master
fixed the version number from 0.3 to 0.4
2019-07-03 06:05:51 -06:00
bmac2
001a78912d fixed the version number from 0.3 to 0.4 2019-07-02 22:47:41 -06:00
Christer Edwards
903805465d Merge pull request #39 from cedwards/master
update README for verify and service
2019-06-23 08:53:21 -06:00
Christer Edwards
07e9056c9c update README for verify and service 2019-06-23 08:51:47 -06:00
Christer Edwards
2ab81d47f4 Merge pull request #38 from cedwards/master
fix bootstrap regression, make cp verbose, code cleanup
2019-06-23 08:37:44 -06:00
Christer Edwards
3d3fd9881b fix bootstrap regression, make cp verbose, code cleanup 2019-06-23 08:33:41 -06:00
Christer Edwards
02a14e28d2 Merge pull request #37 from cedwards/master
new zfs sub-command and documentation
2019-06-22 14:16:37 -06:00
Christer Edwards
6a082113d6 new zfs sub-command and documentation 2019-06-22 14:15:20 -06:00
Christer Edwards
6d69c82a04 Merge pull request #36 from cedwards/master
update bastille.conf for updated options
2019-06-22 09:56:47 -06:00
Christer Edwards
e74bbd089c update bastille.conf for updated options 2019-06-22 09:55:28 -06:00
Christer Edwards
90707cd5c9 Merge pull request #35 from cedwards/master
remove unused freebsd_dist_fetch.sh
2019-06-22 09:40:11 -06:00
Christer Edwards
2b2012f1be remove unused freebsd_dist_fetch.sh 2019-06-22 09:39:16 -06:00
Christer Edwards
652c8f095e Merge pull request #34 from cedwards/master
Bastille 0.4.20190622
2019-06-22 09:36:37 -06:00
Christer Edwards
344837689d makes create.sh less case-sensitive for release name 2019-06-22 09:32:46 -06:00
Christer Edwards
52c8df69e3 Bastille 0.4.20190622 - ZFS plus bugfixes 2019-06-22 09:28:42 -06:00
Christer Edwards
e5ae4d0743 Merge pull request #33 from cedwards/master
May 2019 update: HardenedBSD, tzdata, NS
2019-05-22 21:59:01 -06:00
Christer Edwards
c9ebc886fd May 2019 update: HardenedBSD, tzdata, NS
- closes #32: support HardenedBSD
 - adds support for defined nameservers in new jails (up to three)
 - adds support for defined nameserver options (eg; options edns0 rotate)
 - adds support for defined tzdata in new jails (eg; America/Denver, etc/UTC)
 - adds support for dynamic hw.machine/hw.machine_arch downloads
 - new jails now output default rc.conf settings (sysrc) at creation
 - no longer use freebsd_dist_fetch.sh; replaced with simpler fetch
2019-05-22 21:50:29 -06:00
Christer Edwards
cccf4ff31f Merge pull request #31 from cedwards/master
updated README.md
2019-03-11 17:54:41 -06:00
Christer Edwards
6f1da4b265 updated README.md to include ports tree support 2019-03-11 17:51:32 -06:00
Christer Edwards
57bd13c9ce Merge pull request #29 from cedwards/master
update copyright; fixes #28
2019-02-04 21:32:21 -07:00
Christer Edwards
957465dfa4 update bootstrap to support configurable archives 2019-02-04 21:31:34 -07:00
Christer Edwards
e2b4f84cfe update copyright; fixes #28 2019-02-04 21:08:00 -07:00
Christer Edwards
29e98b554f Merge pull request #27 from cedwards/master
bootstrap fix
2019-01-02 20:10:46 -07:00
Christer Edwards
655f8d0fe9 bootstrap fix 2019-01-02 20:08:49 -07:00
Christer Edwards
d35b2cc119 Merge pull request #26 from cedwards/master
0.3.20181202 template targets
2018-12-02 08:27:38 -07:00
Christer Edwards
6a8c2f8e53 0.3.20181202 template targets 2018-12-02 08:23:27 -07:00
Christer Edwards
2e6b8f355e Merge pull request #25 from cedwards/master
0.3.2018113001 updated readme; add pkg
2018-11-30 11:39:51 -07:00
Christer Edwards
78bc3cb9c4 0.3.2018113001 updated readme; add pkg 2018-11-30 11:39:05 -07:00
Christer Edwards
46bfa62cb9 Merge pull request #24 from cedwards/master
0.3.20181130 damned typos
2018-11-30 09:13:49 -07:00
Christer Edwards
a495350d26 0.3.20181130 damned typos 2018-11-30 09:12:43 -07:00
Christer Edwards
7d40be61dd Merge pull request #23 from cedwards/master
0.3.20181128 go go gadget git clone templates
2018-11-28 21:05:30 -07:00
Christer Edwards
eb4aab01f9 0.3.20181128 go go gadget git clone templates 2018-11-28 21:02:42 -07:00
Christer Edwards
f84317f7e4 Merge pull request #22 from cedwards/master
0.3.2018112401 bastille.rtfd.org
2018-11-24 20:09:00 -07:00
Christer Edwards
9431af5eb0 0.3.2018112401 bastille.rtfd.org 2018-11-24 20:07:20 -07:00
Christer Edwards
06e3fdacd4 Merge pull request #21 from cedwards/master
0.3.2018112400 README updated for release
2018-11-24 10:20:20 -07:00
Christer Edwards
093bcaa4f4 0.3.2018112400 README updated for release 2018-11-24 10:19:01 -07:00
Christer Edwards
118d403183 Merge pull request #20 from cedwards/master
0.3.20181124 patch
2018-11-24 10:05:15 -07:00
Christer Edwards
c98229066d 0.3.20181124 patch 2018-11-24 09:55:16 -07:00
Christer Edwards
1c0f261a7b Merge pull request #18 from cedwards/master
0.3.2018112003 bugfix release pkg docs
2018-11-20 22:05:42 -07:00
Christer Edwards
e0e71e1040 0.3.2018112003 bugfix release pkg docs 2018-11-20 22:04:58 -07:00
Christer Edwards
18eec0d5b8 Merge pull request #17 from cedwards/master
0.3.2018112002 bugfix release
2018-11-20 21:49:36 -07:00
Christer Edwards
f38eff56fc 0.3.2018112002 bugfix release 2018-11-20 21:43:54 -07:00
Christer Edwards
55268d84ac Merge pull request #16 from cedwards/master
0.3.2018112001 RTD theme
2018-11-20 21:13:12 -07:00
Christer Edwards
1e6e0f3376 0.3.2018112001 RTD theme 2018-11-20 21:12:26 -07:00
Christer Edwards
9738472245 Merge pull request #15 from cedwards/master
0.3.20181120 initial RTD build
2018-11-20 21:04:32 -07:00
Christer Edwards
a77dc8ef9d 0.3.20181120 initial RTD build 2018-11-20 21:03:08 -07:00
Christer Edwards
d15a1d166f Merge pull request #13 from cedwards/master
0.3.2018111801 added chat.bastillebsd.org to README
2018-11-18 23:12:10 -07:00
Christer Edwards
b70d002c4b 0.3.2018111801 added chat.bastillebsd.org to README 2018-11-18 23:11:02 -07:00
Christer Edwards
c6c3b8c52e Merge pull request #9 from cedwards/master
0.3.20181118 how to pkg BETA
2018-11-18 20:39:05 -07:00
Christer Edwards
58da217e77 0.3.20181118 how to pkg BETA 2018-11-18 20:37:03 -07:00
Christer Edwards
ca8dad3bc3 Merge pull request #8 from cedwards/master
0.3.20181114 fix all the things
2018-11-13 21:42:09 -07:00
Christer Edwards
8b7fb790e4 0.3.20181114 fix all the things 2018-11-13 21:40:11 -07:00
107 changed files with 8361 additions and 1538 deletions

26
.github/ISSUE_TEMPLATE/bug_report.md vendored Normal file
View File

@@ -0,0 +1,26 @@
---
name: Bug report
about: Create a report to help us improve
title: "[BUG]"
labels: bug
assignees: ''
---
**[MANDATORY] Describe the bug [MANDATORY]**
A clear and concise description of what the bug is.
**[MANDATORY] Bastille and FreeBSD version (paste ``bastille -v && freebsd-version -kru`` output)**
**[MANDATORY] How did you install bastille? (port/pkg/git)**
**[optional] Steps to reproduce?**
**[optional] Expected behavior**
A clear and concise description of what you expected to happen.
**[optional] Screenshots**
If applicable, add screenshots to help explain your problem.
**[optional] Additional context**
Add any other context about the problem here.

View File

@@ -0,0 +1,20 @@
---
name: Feature request
about: Enhancement & Feature Request
title: "[ENHANCEMENT]"
labels: enhancement
assignees: ''
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
docs/_build

9
.readthedocs.yaml Normal file
View File

@@ -0,0 +1,9 @@
version: 2
sphinx:
configuration: docs/conf.py
build:
os: "ubuntu-22.04"
tools:
python: "3.11"

49
AUTHORS.md Normal file
View File

@@ -0,0 +1,49 @@
# AUTHORS
## Lead
Christer Edwards [christer.edwards@gmail.com]
## Contributors (code)
- Barry McCormick
- Brian Downs
- Carsten Bäcker
- Chris Wells
- Dave Cottlehuber
- Giacomo Olgeni
- Gleb Popov
- JP Mens
- Jose Rivera
- Juan David Hurtado G.
- Lars E.
- Marius van Witzenburg
- Matt Audesse
- Paul C.
- Petru T. Garstea
- Sven R.
- Tobias Tom
- Stefano Marinelli
- Logan Ellis
- Chuck Tuffli
- Niketh Murali
- Eric Borisch
- Kevet Duncombe
### Special thanks
Software doesn't happen in a vacuum. Thank you to the following people who may
not be found in the commit history but have influenced Bastille's development
in some way.
- Carlos Meza
- Casandra Woodcox
- Clint Savage
- G. Clifford Williams
- Jack Thomasson
- Jun C Park
- Justin Desilets
- Larry Raab
- Nate Taylor
- Peter Czanik
- Ryan Simpkins
- Tim Gelter
- Trevor Sharpe

View File

@@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at conduct@bastillebsd.org. All
reported by contacting the project team lead at christer.edwards@gmail.com. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
@@ -71,4 +71,3 @@ This Code of Conduct is adapted from the [Contributor Covenant][homepage], versi
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
[homepage]: https://www.contributor-covenant.org

View File

@@ -1,6 +1,6 @@
BSD 3-Clause License
Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without

34
Makefile Normal file
View File

@@ -0,0 +1,34 @@
BASTILLE_VERSION=$$(git rev-parse HEAD)
.PHONY: all
all:
@echo "Nothing to be done. Please use make install or make uninstall"
.PHONY: install
install:
@echo "Installing Bastille"
@echo
@echo "Updating Bastille version to match git revision."
@echo "BASTILLE_VERSION: ${BASTILLE_VERSION}"
@sed -i.orig "s/BASTILLE_VERSION=.*/BASTILLE_VERSION=${BASTILLE_VERSION}/" usr/local/bin/bastille
@cp -Rv usr /
@echo
@echo "This method is for testing & development."
@echo "Please report any issues to https://github.com/BastilleBSD/bastille/issues"
.PHONY: uninstall
uninstall:
@echo "Removing Bastille command"
@rm -vf /usr/local/bin/bastille
@echo
@echo "Removing Bastille sub-commands"
@rm -rvf /usr/local/share/bastille
@echo
@echo "removing man page"
@rm -rvf /usr/local/share/man/man1/bastille.1.gz
@echo
@echo "removing configuration file"
@rm -rvf /usr/local/etc/bastille/bastille.conf.sample
@echo
@echo "removing startup script"
@rm -vf /usr/local/etc/rc.d/bastille
@echo "You may need to manually remove /usr/local/etc/bastille/bastille.conf if it is no longer needed."

882
README.md
View File

@@ -1,735 +1,150 @@
Bastille
========
Bastille is a jail automation framework that allows you to quickly and
easily create and manage FreeBSD jail.
[Bastille](https://bastillebsd.org/) is an open-source system for automating
deployment and management of containerized applications on FreeBSD.
[Bastille Documentation](https://bastille.readthedocs.io/en/latest/)
Installation
============
Bastille is available for installation from the official FreeBSD ports tree.
**pkg**
```shell
pkg install bastille
```
**ports**
```shell
portsnap fetch auto
make -C /usr/ports/sysutils/bastille install clean
```
**Git** (bleeding edge / unstable -- primarily for developers)
```shell
git clone https://github.com/bastillebsd/bastille.git
cd bastille
make install
```
**enable at boot**
```shell
sysrc bastille_enable=YES
sysrc bastille_rcorder=YES
```
Upgrading from a previous version
---------------------------------
When upgrading from a previous version of bastille (e.g. 0.10.20230714 to
0.10.20231013) you will need to update your bastille.conf
```shell
cd /usr/local/etc/bastille
diff -u bastille.conf bastille.conf.sample
```
Merge the lines that are present in the new bastille.conf.sample into
your bastille.conf
Basic Usage
-----------
```
ishmael ~ # bastille -h
```shell
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 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.
help Help about any command
bootstrap Bootstrap a FreeBSD release for container base.
clone Clone an existing container.
cmd Execute arbitrary command on targeted container(s).
config Get or set a config value for the targeted container(s).
console Console into a running container.
convert Convert a Thin container into a Thick container.
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.
edit Edit container configuration files (advanced).
export Exports a specified container.
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).
import Import a specified container.
limits Apply resources limits to targeted container(s). See rctl(8).
list List containers (running and stopped).
mount Mount a volume inside the targeted container(s).
pkg Manipulate binary packages within targeted container(s). See pkg(8).
rdr Redirect host port to container port.
rcp reverse cp(1) files from a single container to the host.
rename Rename a container.
restart Restart a running container.
service Manage services within targeted container(s).
setup Attempt to auto-configure network, firewall and storage on new installs.
start Start a stopped container.
stop Stop a running container.
sysrc Safely edit rc files within targeted container(s).
tags Add or remove tags to targeted container(s).
template Apply file templates to targeted container(s).
top Display and update information about the top(1) cpu processes.
update Update jail base -pX release.
upgrade Upgrade jail release to X.Y-RELEASE.
umount Unmount a volume from within the targeted container(s).
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.
```
## 0.10-beta
This document outlines the basic usage of the Bastille container management
framework. This release is still considered beta.
## 0.3-beta
This document outlines the basic usage of the Bastille jail management
framework. This release, obviously, is beta quality. I make no guarantees of
quality, and if it screws up your system... Sorry, bro.
Setup Requirements
==================
Bastille can now (attempt) to configure the networking, firewall and storage
automatically. This feature is new since version 0.10.20231013.
With all that said, here's how to use this tool in its current beta state...
## Network Requirements
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.
First, create the loopback interface:
**bastille setup**
```shell
ishmael ~ # sysrc cloned_interfaces="lo1"
ishmael ~ # service netif cloneup
ishmael ~ # bastille setup -h
ishmael ~ # Usage: bastille setup [pf|bastille0|zfs|vnet]
```
Second, enable NAT through the firewall:
On fresh installations it is likely safe to run `bastille setup` with no
arguments. This will configure the firewall, the loopback interface and attempt
to determine ZFS vs UFS storage.
```shell
ishmael ~ # sysrc pf_enable="YES"
```
If you have an existing firewall, or customized network design, you may want to
run individual options; eg `bastille setup zfs` or `bastille setup vnet`.
Create the firewall config, or merge as necessary.
### /etc/pf.conf
```
ext_if="vtnet0"
set block-policy drop
scrub in on $ext_if all fragment reassemble
set skip on lo
nat on $ext_if from !($ext_if) -> ($ext_if:0)
## rdr example
## rdr pass inet proto tcp from any to any port {80, 443} -> 10.88.9.45
block in log 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
```
* 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:
```
nat on $ext_if from lo1:network to any -> ($ext_if)
## rdr example
## rdr pass inet proto tcp from any to any port {80, 443} -> 10.88.9.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.
Finally, start up the firewall:
```shell
ishmael ~ # service pf restart
```
At this point you'll likely be disconnected from the host. Reconnect the ssh
session and continue.
Note: The `bastille setup` command can configure and enable PF but it does not
automatically reload the firewall. You will still need to manually `service pf
start`. At that point you'll likely be disconnected if configuring a remote
host. Simply reconnect the ssh session and continue.
This step only needs to be done once in order to prepare the host.
bastille 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.
Note: your mileage may vary with unsupported releases and releases newer than
the host system likely will NOT work at all.
To `bootstrap` a release, run the bootstrap sub-command with the
release version as the argument.
```shell
ishmael ~ # bastille bootstrap 11.2-RELEASE
ishmael ~ # bastille bootstrap 12.0-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.
Downloaded artifacts are stored in the `cache` directory. "bootstrapped"
releases are stored in `releases/version`.
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.
To update a release as patches are made available, see the `bastille update`
command.
bastille create
---------------
Bastille create uses any available bootstrapped release to create a lightweight
jailized system. To create a jail simply provide a name, release and
a private (rfc1918) IP address.
- name
- release (bootstrapped)
- ip
```shell
ishmael ~ # bastille create folsom 11.2-RELEASE 10.8.62.1
RELEASE: 11.2-RELEASE.
NAME: folsom.
IP: 10.8.62.1.
```
This command will create a 11.2-RELEASE jail assigning the 10.8.62.1 ip address
to the new system.
I recommend using private (rfc1918) ip address ranges for your jails.
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 start
--------------
To start a jail you can use the `bastille start` command.
```shell
ishmael ~ # bastille start folsom
Targeting specified jails.
folsom
[folsom]:
folsom: created
```
bastille stop
-------------
To stop a jail you can use the `bastille stop` command.
```shell
ishmael ~ # bastille stop folsom
Targeting specified jails.
folsom
[folsom]:
folsom: removed
```
bastille restart
----------------
To restart a jail you can use the `bastille restart` command.
```shell
ishmael ~ # bastille restart folsom
Targeting specified jails.
folsom
[folsom]:
folsom: removed
Targeting specified jails.
folsom
[folsom]:
folsom: created
```
bastille cmd
------------
To execute commands within the jail you can use `bastille cmd`.
```shell
ishmael ~ # bastille cmd folsom 'ps -auxw'
Targeting specified jails.
folsom
[folsom]:
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
root 71464 0.0 0.0 14536 2000 - IsJ 4:52PM 0:00.00 /usr/sbin/syslogd -ss
root 77447 0.0 0.0 16632 2140 - SsJ 4:52PM 0:00.00 /usr/sbin/cron -s
root 80591 0.0 0.0 18784 2340 1 R+J 4:53PM 0:00.00 ps -auxw
```
bastille pkg
------------
To manage binary packages within the jail use `bastille pkg`.
```shell
ishmael ~ # bastille pkg folsom 'install vim-console git-lite zsh'
Targeting specified jails.
folsom
[folsom]:
The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]: y
Bootstrapping pkg from pkg+http://pkg.FreeBSD.org/FreeBSD:10:amd64/quarterly, please wait...
Verifying signature with trusted certificate pkg.freebsd.org.2013102301... done
[folsom] Installing pkg-1.10.5_5...
[folsom] Extracting pkg-1.10.5_5: 100%
Updating FreeBSD repository catalogue...
pkg: Repository FreeBSD load error: access repo file(/var/db/pkg/repo-FreeBSD.sqlite) failed: No such file or directory
[folsom] Fetching meta.txz: 100% 944 B 0.9kB/s 00:01
[folsom] Fetching packagesite.txz: 100% 6 MiB 3.4MB/s 00:02
Processing entries: 100%
FreeBSD repository update completed. 32550 packages processed.
All repositories are up to date.
Updating database digests format: 100%
The following 10 package(s) will be affected (of 0 checked):
New packages to be INSTALLED:
vim-console: 8.1.0342
git-lite: 2.19.1
zsh: 5.6.2
expat: 2.2.6_1
curl: 7.61.1
libnghttp2: 1.33.0
ca_root_nss: 3.40
pcre: 8.42
gettext-runtime: 0.19.8.1_1
indexinfo: 0.3.1
Number of packages to be installed: 10
The process will require 77 MiB more space.
17 MiB to be downloaded.
Proceed with this action? [y/N]: y
[folsom] [1/10] Fetching vim-console-8.1.0342.txz: 100% 5 MiB 5.8MB/s 00:01
[folsom] [2/10] Fetching git-lite-2.19.1.txz: 100% 4 MiB 2.1MB/s 00:02
[folsom] [3/10] Fetching zsh-5.6.2.txz: 100% 4 MiB 4.4MB/s 00:01
[folsom] [4/10] Fetching expat-2.2.6_1.txz: 100% 109 KiB 111.8kB/s 00:01
[folsom] [5/10] Fetching curl-7.61.1.txz: 100% 1 MiB 1.2MB/s 00:01
[folsom] [6/10] Fetching libnghttp2-1.33.0.txz: 100% 107 KiB 109.8kB/s 00:01
[folsom] [7/10] Fetching ca_root_nss-3.40.txz: 100% 287 KiB 294.3kB/s 00:01
[folsom] [8/10] Fetching pcre-8.42.txz: 100% 1 MiB 1.2MB/s 00:01
[folsom] [9/10] Fetching gettext-runtime-0.19.8.1_1.txz: 100% 148 KiB 151.3kB/s 00:01
[folsom] [10/10] Fetching indexinfo-0.3.1.txz: 100% 6 KiB 5.7kB/s 00:01
Checking integrity... done (0 conflicting)
[folsom] [1/10] Installing libnghttp2-1.33.0...
[folsom] [1/10] Extracting libnghttp2-1.33.0: 100%
[folsom] [2/10] Installing ca_root_nss-3.40...
[folsom] [2/10] Extracting ca_root_nss-3.40: 100%
[folsom] [3/10] Installing indexinfo-0.3.1...
[folsom] [3/10] Extracting indexinfo-0.3.1: 100%
[folsom] [4/10] Installing expat-2.2.6_1...
[folsom] [4/10] Extracting expat-2.2.6_1: 100%
[folsom] [5/10] Installing curl-7.61.1...
[folsom] [5/10] Extracting curl-7.61.1: 100%
[folsom] [6/10] Installing pcre-8.42...
[folsom] [6/10] Extracting pcre-8.42: 100%
[folsom] [7/10] Installing gettext-runtime-0.19.8.1_1...
[folsom] [7/10] Extracting gettext-runtime-0.19.8.1_1: 100%
[folsom] [8/10] Installing vim-console-8.1.0342...
[folsom] [8/10] Extracting vim-console-8.1.0342: 100%
[folsom] [9/10] Installing git-lite-2.19.1...
===> Creating groups.
Creating group 'git_daemon' with gid '964'.
===> Creating users
Creating user 'git_daemon' with uid '964'.
[folsom] [9/10] Extracting git-lite-2.19.1: 100%
[folsom] [10/10] Installing zsh-5.6.2...
[folsom] [10/10] Extracting zsh-5.6.2: 100%
```
The PKG sub-command can, of course, do more than just `install`. The
expectation is that you can fully leverage the pkg manager. This means,
`install`, `update`, `upgrade`, `audit`, `clean`, `autoremove`, etc., etc.
```shell
ishmael ~ # bastille pkg ALL upgrade
Targeting all jails.
[bastion]:
Updating iniquity.io 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.
All repositories are up to date.
Checking for upgrades (1 candidates): 100%
Processing candidates (1 candidates): 100%
Checking integrity... done (0 conflicting)
Your packages are up to date.
[unbound0]:
Updating iniquity.io 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.
All repositories are up to date.
Checking for upgrades (0 candidates): 100%
Processing candidates (0 candidates): 100%
Checking integrity... done (0 conflicting)
Your packages are up to date.
[unbound1]:
Updating iniquity.io 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.
All repositories are up to date.
Checking for upgrades (0 candidates): 100%
Processing candidates (0 candidates): 100%
Checking integrity... done (0 conflicting)
Your packages are up to date.
[squid]:
Updating iniquity.io 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.
All repositories are up to date.
Checking for upgrades (0 candidates): 100%
Processing candidates (0 candidates): 100%
Checking integrity... done (0 conflicting)
Your packages are up to date.
[nginx]:
Updating iniquity.io 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.
All repositories are up to date.
Checking for upgrades (1 candidates): 100%
Processing candidates (1 candidates): 100%
The following 1 package(s) will be affected (of 0 checked):
Installed packages to be UPGRADED:
nginx-lite: 1.14.0_14,2 -> 1.14.1,2
Number of packages to be upgraded: 1
315 KiB to be downloaded.
Proceed with this action? [y/N]: y
[nginx] [1/1] Fetching nginx-lite-1.14.1,2.txz: 100% 315 KiB 322.8kB/s 00:01
Checking integrity... done (0 conflicting)
[nginx] [1/1] Upgrading nginx-lite from 1.14.0_14,2 to 1.14.1,2...
===> Creating groups.
Using existing group 'www'.
===> Creating users
Using existing user 'www'.
[nginx] [1/1] Extracting nginx-lite-1.14.1,2: 100%
You may need to manually remove /usr/local/etc/nginx/nginx.conf if it is no longer needed.
```
bastille destroy
----------------
Jails can be destroyed and thrown away just as easily as they were created.
Note: jails must be stopped before destroyed.
```shell
ishmael ~ # bastille stop folsom
Targeting specified jails.
folsom
[folsom]:
folsom: removed
ishmael ~ # bastille destroy folsom
Deleting Jail: folsom.
Note: jail console logs not destroyed.
/usr/local/bastille/logs/folsom_console.log
```
bastille template
-----------------
Bastille supports a templating system allowing you to apply files, pkgs and
execute commands inside the jail automatically.
Currently supported template hooks are: `PRE`, `CONFIG`, `PKG`, `SYSRC`, `CMD`.
Planned template hooks include: `FSTAB`, `PF`
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;
```shell
mkdir -p /usr/local/bastille/templates/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;
```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
```
Template hooks are executed in specific order and require specific syntax to
work as expected. This table outlines those requirements:
| HOOK | format | example |
|---------|------------------|--------------------------------------|
| PRE/CMD | /bin/sh command | /usr/bin/chsh -s /usr/local/bin/zsh |
| CONFIG | path | etc root usr |
| PKG | port/pkg name(s) | vim-console zsh git-lite tree htop |
| SYSRC | sysrc command(s) | nginx_enable="YES" nginx_flags="..." |
In addition to supporting template hooks, Bastille supports overlaying files
into the jail. 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.
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;
```shell
echo "etc usr" > /usr/local/bastille/templates/base/CONFIG
```
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.
Applying Templates
------------------
Jails must be running to apply templates.
Bastille includes a `template` sub-command. This sub-command requires a target
and a template name. As covered in the previous section, template names
correspond to directory names in the `bastille/templates` directory.
```shell
ishmael ~ # bastille template folsom base
[folsom]:
Copying files...
Copy complete.
Installing packages.
...[snip]...
Executing final command(s).
chsh: user information updated
Template Complete.
```
bastille top
------------
This one simply runs `top` in that jail. This command is interactive, as `top`
is interactive.
bastille htop
-------------
This one simply runs `htop` inside the jail. This one is a quick and dirty
addition. note: won't work if you don't have htop installed in the jail.
bastille 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.
```shell
ishmael ~ # bastille sysrc nginx nginx_enable="YES"
Targeting specified jails.
nginx
[nginx]:
nginx_enable: NO -> YES
```
See `man sysrc(8)` for more info.
bastille console
----------------
This sub-command launches a login shell into the jail. Default is
password-less root login.
```shell
ishmael ~ # bastille console folsom
Targeting specified jails.
folsom
[folsom]:
FreeBSD 11.2-RELEASE-p4 (GENERIC) #0: Thu Sep 27 08:16:24 UTC 2018
Welcome to FreeBSD!
Release Notes, Errata: https://www.FreeBSD.org/releases/
Security Advisories: https://www.FreeBSD.org/security/
FreeBSD Handbook: https://www.FreeBSD.org/handbook/
FreeBSD FAQ: https://www.FreeBSD.org/faq/
Questions List: https://lists.FreeBSD.org/mailman/listinfo/freebsd-questions/
FreeBSD Forums: https://forums.FreeBSD.org/
Documents installed with the system are in the /usr/local/share/doc/freebsd/
directory, or can be installed later with: pkg install en-freebsd-doc
For other languages, replace "en" with a language code like de or fr.
Show the version of FreeBSD installed: freebsd-version ; uname -a
Please include that output and any error messages when posting questions.
Introduction to manual pages: man man
FreeBSD directory layout: man hier
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.
bastille cp
-----------
Note: this sub-command may need a little work.
This sub-command allows efficiently copying files from host to jail(s).
```shell
ishmael ~ # bastille cp ALL /tmp/resolv.conf-cf etc/resolv.conf
Targeting all jails.
[bastion]:
[unbound0]:
[unbound1]:
[squid]:
[nginx]:
[folsom]:
```
Unless you see errors reported in the output the `cp` was successful.
bastille list
-------------
This sub-command will show you the running jails on your system.
```shell
ishmael ~ # bastille list
JID IP Address Hostname Path
bastion 10.88.9.65 bastion /usr/local/bastille/jails/bastion/root
unbound0 10.88.9.60 unbound0 /usr/local/bastille/jails/unbound0/root
unbound1 10.88.9.61 unbound1 /usr/local/bastille/jails/unbound1/root
squid 10.88.9.30 squid /usr/local/bastille/jails/squid/root
nginx 10.88.9.45 nginx /usr/local/bastille/jails/nginx/root
folsom 10.8.62.1 folsom /usr/local/bastille/jails/folsom/root
```
bastille 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 updated as well.
To update all jails based on the 11.2-RELEASE `release`:
Up to date 11.2-RELEASE:
```shell
ishmael ~ # bastille update 11.2-RELEASE
Targeting specified release.
11.2-RELEASE
Looking up update.FreeBSD.org mirrors... 2 mirrors found.
Fetching metadata signature for 11.2-RELEASE from update4.freebsd.org... done.
Fetching metadata index... done.
Inspecting system... done.
Preparing to download files... done.
No updates needed to update system to 11.2-RELEASE-p4.
No updates are available to install.
```
Updating 10.4-RELEASE:
```shell
ishmael ~ # bastille update 10.4-RELEASE
Targeting specified release.
10.4-RELEASE
Looking up update.FreeBSD.org mirrors... 2 mirrors found.
Fetching metadata signature for 10.4-RELEASE from update1.freebsd.org... done.
Fetching metadata index... done.
Fetching 2 metadata patches.. done.
Applying metadata patches... done.
Fetching 2 metadata files... done.
Inspecting system... done.
Preparing to download files... done.
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.
bastille upgrade
----------------
This sub-command lets you upgrade a release to a new release. Depending on the
workflow this can be similar to a `bootstrap`.
```shell
ishmael ~ # bastille upgrade 11.2-RELEASE 12.0-RELEASE
...
```
bastille verify
---------------
This sub-command scans a bootstrapped release and validates that everything
looks in order. This is not a 100% comprehensive check, but it compares the
release against a "known good" index.
If you see errors or issues here, consider deleting and re-bootstrapping the
release.
Example (create, start, console)
================================
This example creates, starts and consoles into the jail.
This example creates, starts and consoles into the container.
```shell
ishmael ~ # bastille create alcatraz 11.2-RELEASE 10.9.8.7
RELEASE: 11.2-RELEASE.
NAME: alcatraz.
IP: 10.9.8.7.
ishmael ~ # bastille create alcatraz 14.0-RELEASE 10.17.89.10/24
```
```shell
ishmael ~ # bastille start alcatraz
Targeting specified jails.
alcatraz
[alcatraz]:
alcatraz: created
```
```shell
ishmael ~ # bastille console alcatraz
Targeting specified jails.
alcatraz
[alcatraz]:
FreeBSD 11.2-RELEASE-p4 (GENERIC) #0: Thu Sep 27 08:16:24 UTC 2018
FreeBSD 14.0-RELEASE GENERIC
Welcome to FreeBSD!
@@ -737,7 +152,7 @@ Release Notes, Errata: https://www.FreeBSD.org/releases/
Security Advisories: https://www.FreeBSD.org/security/
FreeBSD Handbook: https://www.FreeBSD.org/handbook/
FreeBSD FAQ: https://www.FreeBSD.org/faq/
Questions List: https://lists.FreeBSD.org/mailman/listinfo/freebsd-questions/
Questions List: https://www.FreeBSD.org/lists/questions/
FreeBSD Forums: https://forums.FreeBSD.org/
Documents installed with the system are in the /usr/local/share/doc/freebsd/
@@ -749,7 +164,7 @@ Please include that output and any error messages when posting questions.
Introduction to manual pages: man man
FreeBSD directory layout: man hier
Edit /etc/motd to change this login announcement.
To change this login announcement, see motd(5).
root@alcatraz:~ #
```
@@ -764,82 +179,7 @@ root 92565 0.0 0.0 7412 3756 3 SJ 02:21 0:00.01 -csh (csh)
root@alcatraz:~ #
```
Project Goals
=============
These tools are created initially with the mindset of function over form. I
want to simply prove the concept is sound for real work. The real work is a
sort of meta-jail-port system. Instead of installing the MySQL port directly on
a system, you would use Bastille to install the MySQL port within a jail
template built for MySQL. The same goes for DNS servers, and everything else in
the ports tree.
Eventually I would like to have Bastille templates created for popular
FreeBSD-based services. From Plex Media Servers to ad-blocking DNS resolvers.
From tiny SSH jails to dynamic web servers.
I don't want to tell you what you can and can't run within this framework.
There are no arbitrary limitations based on what I think may or may not be the
best way to design systems. This is not my goal.
My goal is to provide a secure framework where processes and services can run
isolated. I want to limit the scope and reach of bad actors. I want to severely
limit the target areas available to anyone that has (or has gained!) access.
Possible Jail names
-------------------
prisons:
- arkham
- ashecliffe
- azkaban
- coldmountain
- dolguldur
- foxriver
- litchfield
- oswald
- shawshank
- stockton
- stormcage
- ziggurat
- astralqueen
- alcatraz
- rikers
- leavenworth
- folsom
- attica
- singsing
- sanquentin
- corcoran
- pelicanbay
Networking Tips
===============
Tip #1:
-------
Ports and destinations can be defined as lists. eg;
```
rdr pass inet proto tcp from any to any port {80, 443} -> {10.88.9.45, 10.88.9.46, 10.88.9.47, 10.88.9.48}
```
This rule would redirect any traffic to the host on ports 80 or 443 and
round-robin between jails with ips 45, 46, 47, and 48 (on ports 80 or 443).
Tip #2:
-------
Ports can redirect to other ports. eg;
```
rdr pass inet proto tcp from any to any port 8080 -> 10.7.6.5 port 80
rdr pass inet proto tcp from any to any port 8081 -> 10.7.6.5 port 8080
rdr pass inet proto tcp from any to any port 8181 -> 10.7.6.5 port 443
```
Tip: Initially I spent time worrying about what IP addresses to assign. In the
end I've come to the conclusion that it _really_ doesn't matter. Pick *any*
private address and be done with it. These are all isolated networks. In the
end, what matters is you can map host:port to jail:port reliably, and we
can.
Community Support
=================
If you've found a bug in Bastille, please submit it to the [Bastille Issue
Tracker](https://github.com/bastillebsd/bastille/issues/new).

View File

@@ -1,45 +1,55 @@
Bastille Roadmap
================
This is the general roadmap for the next nine months. I would like the
near-term done by the end of 2018. The mid-term should be done by March 2019.
The long-term by summer 2019.
2020 Bastille Roadmap
=====================
At that point, if the templating is mature, and the top 50 is complete, the
platform is ready for general purpose use.
1. Virtual Networking
1. Bastille CI/CD
1. Template Maturity & Consolidation
1. Container Monitoring
1. Bastille API
Rough timeline and description below.
near-term
---------
1. zfs support (configurable)
2. bastille-dev template (see below):
```shell
## jail -c name=foo host.hostname=foo allow.raw_sockets children.max=99
## ip4.addr=10.20.12.68 persist
## jexec foo /bin/csh
## foo# jail -c name=bar host.hostname=bar allow.raw_sockets
## ip4.addr=10.20.12.68 persist
## foo# jexec bar /bin/csh
## bar# ping gritton.org
```
3. branding
Virtual Networking (Jan-Feb) ~ 0.6.x-beta
-----------------------------------------
VNET (Virtual Networking) will allow fully virtualized network stacks. This
would bring the total network options to three (loopback, LAN, VNET). The
anticipated design would use a bridge device connected to containers via epair
interfaces.
Bastille CI/CD (March-May) ~ 0.7.x-beta
---------------------------------------
While we have many of the templates validated by automatic CI/CD, we are not
validating updates to Bastille itself. This automated validation of Pull
Requests should be a priority early in the year with a full test suite designed
to validate all expected uses of Bastille sub-commands.
mid-term
--------
1. templating
2. ssh-to-jail demo (ie; ldap + .authorized_keys + command)
```shell
## TODO: .ssh/authorized_keys auto-launch into user jail
## jail_create_login_hook() {
## echo "permit nopass ${user} cmd /usr/sbin/jexec args ${name} /usr/bin/login -f ${user}" >> /usr/local/etc/doas.conf
## echo "command='/usr/local/bin/doas /usr/sbin/jexec ${name} /usr/bin/login -f ${user}' ${pubkey}" >> $HOME/.ssh/authorized_keys
## }
```
3. additional modules: ps, sockstat, pf, fstab.
Template Maturity & Consolidation (June-Aug) ~ 0.8.x-beta
---------------------------------------------------------
Put the 101 templates found in GitHub's BastilleBSD-Templates repository into
GitLab CI/CD pipeline until fully covered. This is a great place for community
contribution. Templates are easy to create and verify and we'd love to
replicate as much of the FreeBSD ports tree as possible!
In addition, it would be nice to create a consolidated repository of curated
templates similar in design to the FreeBSD ports tree. This would contain all
templates in a single repository and mimick ports behavior where appropriate.
long-term
---------
1. top 50
2. monitoring
3. rctl
Container Monitoring (Sept-Oct) ~ 0.9.x-beta
--------------------------------------------
The ability to monitor processes, services, mounts, sockets, etc from the host.
Auto-remediation would be simple enough to define. Notifications would probably
require a plugin system for methods/endpoints.
Possible monitoring modules: ps, sockstat, pf, fstab
Possible notification modules: pagerduty, slack, splunk, ELK, etc.
Bastille API (Nov-Dec) ~ 1.0.x-beta
-----------------------------------
I have thoughts about a lightweight API for Bastille that would accept (json?)
payloads of Bastille commands. The API should be lightweight just as Bastille
is.
The API is scheduled later in the roadmap because I want to have the other
components stable before we implement an API on top of it. The addition of the
API should match up with Bastille 1.0-stable.

25
Vagrantfile vendored Normal file
View File

@@ -0,0 +1,25 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define "bastille" do |vm_config|
vm_config.ssh.shell = "sh"
vm_config.vm.box = "freebsd/FreeBSD-13.0-RELEASE"
vm_config.vm.box_version = "2021.04.09"
vm_config.vm.provider "virtualbox" do |vb|
vb.name = "bastille"
vb.cpus = "1"
vb.memory = "1024"
end
vm_config.vm.provision "shell", inline: "cd /vagrant; make install"
vm_config.vm.provision "shell", inline: "pkg install -y git-lite"
end
end

19
docs/Makefile Normal file
View File

@@ -0,0 +1,19 @@
# Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SOURCEDIR = .
BUILDDIR = _build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

93
docs/chapters/gcp.rst Normal file
View File

@@ -0,0 +1,93 @@
Bastille VNET on GCP
====================
Bastille VNET runs on GCP with a few small tweaks. In summary, they are:
- change MTU setting in jib script
- add an IP address to the bridge interface
- configure host pf to NAT and allow bridge traffic
- set defaultrouter and nameserver in the host
## Change MTU in the jib script
GCP uses ``vtnet`` with MTU 1460, which [jib fails on](https://github.com/BastilleBSD/bastille/issues/538).
Apply the below patch to set the correct MTU. You may need to ``cp /usr/share/examples/jails/jib /usr/local/bin/`` first.
``patch /usr/local/bin/jib jib.patch``
.. code-block:: text
--- /usr/local/bin/jib 2022-07-31 03:27:04.163245000 +0000
+++ jib.fixed 2022-07-31 03:41:16.710401000 +0000
@@ -299,14 +299,14 @@
# Make sure the interface has been bridged
if ! ifconfig "$iface$bridge" > /dev/null 2>&1; then
- new=$( ifconfig bridge create ) || return
+ new=$( ifconfig bridge create mtu 1460 ) || return
ifconfig $new addm $iface || return
ifconfig $new name "$iface$bridge" || return
ifconfig "$iface$bridge" up || return
fi
# Create a new interface to the bridge
- new=$( ifconfig epair create ) || return
+ new=$( ifconfig epair create mtu 1460 ) || return
ifconfig "$iface$bridge" addm $new || return
# Rename the new interface
## Configure bridge interface
Configure the bridge interface in /etc/rc.conf so it is available in the firewall rules.
.. code-block:: shell
sysrc cloned_interfaces="bridge0"
sysrc ifconfig_bridge0="inet 192.168.1.1/24 mtu 1460 addm vtnet0 name vtnet0bridge up"
sysrc gateway_enable="yes"
sysrc pf_enable="yes"
## Configure host pf
This basic /etc/pf.conf allow incoming packets on the bridge interface, and NATs them through the external interface:
.. code-block:: text
ext_if="vtnet0"
bridge_if="vtnet0bridge"
set skip on lo
scrub in
# permissive NAT allows jail bridge and wireguard tunnels
nat on $ext_if inet from !($ext_if) -> ($ext_if:0)
block in
pass out
pass in proto tcp to port {22}
pass in inet proto icmp icmp-type { echoreq }
pass in on $bridge_if
Restart the host and make sure everything comes up correctly. You should see the following ifconfig:
.. code-block:: text
vtnet0bridge: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1460
ether 58:9c:fc:10:ff:90
inet 192.168.1.1 netmask 0xffffff00 broadcast 192.168.1.255
id 00:00:00:00:00:00 priority 32768 hellotime 2 fwddelay 15
maxage 20 holdcnt 6 proto rstp maxaddr 2000 timeout 1200
root id 00:00:00:00:00:00 priority 32768 ifcost 0 port 0
member: vtnet0 flags=143<LEARNING,DISCOVER,AUTOEDGE,AUTOPTP>
ifmaxaddr 0 port 1 priority 128 path cost 2000
groups: bridge
## Configure router and resolver for new jails
Set the default network gateway for new jails as described in the Networking chapter, and configure a default resolver.
.. code-block:: shell
sysrc -f /usr/local/etc/bastille/bastille.conf bastille_network_gateway="192.168.1.1"
echo "nameserver 8.8.8.8" > /usr/local/etc/bastille/resolv.conf
sysrc -f /usr/local/etc/bastille/bastille.conf bastille_resolv_conf="/usr/local/etc/bastille/resolv.conf"
You can now create a VNET jail with ``bastille create -V myjail 13.2-RELEASE 192.168.1.50/24 vtnet0``

View File

@@ -0,0 +1,55 @@
Installation
============
Bastille is available in the official FreeBSD ports tree at
`sysutils/bastille`. Binary packages available in `quarterly` and `latest`
repositories.
Current version is `0.10.20231125`.
To install from the FreeBSD package repository:
* quarterly repository may be older version
* latest repository will match recent ports
PKG
---
.. code-block:: shell
pkg install bastille
sysrc bastille_enable=YES
sysrc bastille_rcorder=YES
To install from source (don't worry, no compiling):
ports
-----
.. code-block:: shell
make -C /usr/ports/sysutils/bastille install clean
sysrc bastille_enable=YES
sysrc bastille_rcorder=YES
GIT
---
.. code-block:: shell
git clone https://github.com/BastilleBSD/bastille.git
cd bastille
make install
sysrc bastille_enable=YES
sysrc bastille_rcorder=YES
This method will install the latest files from GitHub directly onto your
system. It is verbose about the files it installs (for later removal), and also
has a `make uninstall` target. You may need to manually copy the `.sample`
config into place before Bastille will run. (ie;
`/usr/local/etc/bastille/bastille.conf.sample`)
Note: installing using this method overwrites the version variable to match
that of the source revision commit hash.

View 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
{name} {
devfs_ruleset = 4;
enforce_statfs = 2;
exec.clean;
exec.consolelog = /var/log/bastille/{name}_console.log;
exec.start = '/bin/sh /etc/rc';
exec.stop = '/bin/sh /etc/rc.shutdown';
host.hostname = {name};
interface = {interface};
mount.devfs;
mount.fstab = /usr/local/bastille/jails/{name}/fstab;
path = /usr/local/bastille/jails/{name}/root;
securelevel = 2;
ip4.addr = x.x.x.x;
ip6 = disable;
}
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.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.
exec.consolelog
---------------
.. code-block:: shell
exec.consolelog
A file to direct command output (stdout and stderr) to.
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".
host.hostname
-------------
.. code-block:: shell
host.hostname
The hostname of the jail. Other similar parameters are
host.domainname, host.hostuuid and host.hostid.
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.
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.
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.

View File

@@ -0,0 +1,36 @@
Stop the running jail and export it:
.. code-block:: shell
iocage stop jailname
iocage export jailname
Move the backup files (.zip and .sha256) into Bastille backup dir (default: /usr/local/bastille/backups/):
.. code-block:: shell
mv /iocage/images/jailname_$(date +%F).* /usr/local/bastille/backups/
for remote systems you could use rsync:
.. code-block:: shell
rsync -avh /iocage/images/jailname_$(date +%F).* root@10.0.1.10:/usr/local/bastille/backups/
Import the iocage backup file (use zip file name)
.. code-block:: shell
bastille import jailname_$(date +%F).zip
Set your new ip address and interface:
.. code-block:: shell
vim /usr/local/bastille/jails/jailname/jail.conf
interface = bastille0;
ip4.addr = "192.168.0.1";
You can use you primary network interface instead of the virtual bastille0 interface as well if you know what youre doing.

View File

@@ -0,0 +1,307 @@
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 you
get these containers on the network? Bastille tries to be flexible about how to
network containerized applications. Four methods are described here.
1. Home or Small Office
2. Cloud with IPV4 and multiple IPV6
3. Cloud with single IPV4 (internal bridge)
4. Cloud with a single IPV4 (external bridge)
Please choose the option which is most appropriate for your environment.
First a few notes. Bastille tries to verify that the interface name you provide
is a valid interface. In FreeBSD network interfaces have different names, but
look something like `em0`, `bge0`, `re0`, `vtnet0` etc. Running the ifconfig
commend will tell you the name of your existing interfaces. Bastille also
checks for a valid syntax IP4 or IP6 address. When you are testing calling out
from your containers, please note that the ping command is disabled within the
containers, because raw socket access are a security hole. Instead, install and
test with `wget`/`curl`/`fetch` instead.
Shared Interface on Home or Small Office Network
================================================
If you have just one computer, or a home or small office network, where you are
separated from the rest of the internet by a router. So you are free to use
`private IP addresses
<https://www.lifewire.com/what-is-a-private-ip-address-2625970>`_.
In this environment, to use Bastille, just create the container, give it a
unique private ip address, and attach its ip address to your primary interface.
.. code-block:: shell
bastille create alcatraz 13.2-RELEASE 192.168.1.50 em0
You may have to change em0
When the `alcatraz` container is started it will add `192.168.1.50` as an IP
alias to the `em0` interface. It will then simply be another member of the
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 local network.
Shared Interface on IPV6 network (vultr.com)
============================================
Some ISP's, such as `Vultr <https://vultr.com>`_, give you a single ipv4 address,
and a large block of ipv6 addresses. You can then assign a unique ipv6 address
to each Bastille Container.
On a virtual machine such as vultr.com the virtual interface may be `vtnet0`.
So we issue the command:
.. code-block:: shell
bastille create alcatraz 13.2-RELEASE 2001:19f0:6c01:114c::100 vtnet0
We could also write the ipv6 address as 2001:19f0:6c01:114c:0:100
The tricky part are the ipv6 addresses. IPV6 is a string of 8 4 digit
hexadecimal characters. At vultr they said:
Your server was assigned the following six section subnet:
2001:19f0:6c01:114c:: / 64
The `vultr ipv6 subnet calculator
<https://www.vultr.com/resources/subnet-calculator-ipv6/?prefix_length=64&display=long&ipv6_address=2001%3Adb8%3Aacad%3Ae%3A%3A%2F64>`_
is helpful in making sense of that ipv6 address.
We could have also written that IPV6 address as 2001:19f0:6c01:114c:0:0
Where the /64 basicaly means that the first 64 bits of the address (4x4
character hexadecimal) values define the network, and the remaining characters,
we can assign as we want to the Bastille Container. In the actual bastille
create command given above, it was defined to be 100. But we also have to tell
the host operating system that we are now using this address. This is done on
freebsd with the following command
.. code-block:: shell
ifconfig_vtnet0_alias0="inet6 2001:19f0:6c01:114c::100 prefixlen 64"
At that point your container can talk to the world, and the world can ping your
container. Of course when you reboot the machine, that command will be
forgotten. To make it permanent, prefix the same command with `sysrc`
Just remember you cannot ping out from the container. Instead, install and
use `wget`/`curl`/`fetch` to test the connectivity.
Virtual Network (VNET)
======================
(Added in 0.6.x) VNET is supported on FreeBSD 12+ only.
Virtual Network (VNET) creates a private network interface for a container.
This includes a unique hardware address. This is required for VPN, DHCP, and
similar containers.
To create a VNET based container use the `-V` option, an IP/netmask and
external interface.
.. code-block:: shell
bastille create -V azkaban 13.2-RELEASE 192.168.1.50/24 em0
Bastille will automagically create the bridge interface and connect /
disconnect containers as they are started and stopped. A new interface will be
created on the host matching the pattern `interface0bridge`. In the example
here, `em0bridge`.
The `em0` interface will be attached to the bridge along with the unique
container interfaces as they are started and stopped. These interface names
match the pattern `eXb_bastilleX`. Internally to the containers these
interfaces are presented as `vnet0`.
VNET also requires a custom devfs ruleset. Create the file as needed on the
host system:
.. code-block:: shell
## /etc/devfs.rules (NOT .conf)
[bastille_vnet=13]
add include $devfsrules_hide_all
add include $devfsrules_unhide_basic
add include $devfsrules_unhide_login
add include $devfsrules_jail
add include $devfsrules_jail_vnet
add path 'bpf*' unhide
Lastly, you may want to consider these three `sysctl` values:
.. code-block:: shell
net.link.bridge.pfil_bridge=0
net.link.bridge.pfil_onlyip=0
net.link.bridge.pfil_member=0
Below is the definition of what these three parameters are used for and mean:
net.link.bridge.pfil_onlyip Controls the handling of non-IP packets
which are not passed to pfil(9). Set to 1
to only allow IP packets to pass (subject
to firewall rules), set to 0 to uncondi-
tionally pass all non-IP Ethernet frames.
net.link.bridge.pfil_member Set to 1 to enable filtering on the incom-
ing and outgoing member interfaces, set to
0 to disable it.
net.link.bridge.pfil_bridge Set to 1 to enable filtering on the bridge
interface, set to 0 to disable it.
**Regarding Routes**
Bastille will attempt to auto-detect the default route from the host system and
assign it to the VNET container. This auto-detection may not always be accurate
for your needs for the particular container. In this case you'll need to add a
default route manually or define the preferred default route in the
`bastille.conf`.
.. code-block:: shell
bastille sysrc TARGET defaultrouter=aa.bb.cc.dd
bastille service TARGET routing restart
To define a default route / gateway for all VNET containers define the value in
`bastille.conf`:
.. code-block:: shell
bastille_network_gateway=aa.bb.cc.dd
This config change will apply the defined gateway to any new containers.
Existing containers will need to be manually updated.
Virtual Network (VNET) on External Bridge
=========================================
To create a VNET based container and attach it to an external, already existing
bridge, use the `-B` option, an IP/netmask and external bridge.
.. code-block:: shell
bastille create -B azkaban 13.2-RELEASE 192.168.1.50/24 bridge0
Bastille will automagically create the interface, attach it to the specified
bridge and connect / disconnect containers as they are started and stopped.
The bridge needs to be created/enabled before creating and starting the jail.
Public Network
==============
In this section we describe how to network containers in a public network
such as a cloud hosting provider who only provides you with a single ip address.
(AWS, Digital Ocean, etc) (The exception is vultr.com, which does
provide you with lots of IPV6 addresses and does a great job supporting FreeBSD!)
So if you only have a single IP address and if you want to create multiple
containers and assign them all unique IP addresses, you'll need to create a new
network.
loopback (bastille0)
--------------------
What we recommend is creating a cloned loopback interface (`bastille0`) and
assigning all the containers private (rfc1918) addresses on that interface. The
setup I develop on and use Bastille day-to-day uses the `10.0.0.0/8` address
range. I have the ability to use whatever address I want within that range
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
Second, enable the firewall:
.. code-block:: shell
ishmael ~ # sysrc pf_enable="YES"
Create the firewall rules:
/etc/pf.conf
------------
.. code-block:: shell
ext_if="vtnet0"
set block-policy return
scrub in on $ext_if all fragment reassemble
set skip on lo
table <jails> persist
nat on $ext_if from <jails> to any -> ($ext_if:0)
rdr-anchor "rdr/*"
block in all
pass out quick keep state
antispoof for $ext_if inet
pass in inet proto tcp from any to any port ssh flags S/SA 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 containers are:
.. code-block:: shell
nat on $ext_if from <jails> to any -> ($ext_if:0)
The `nat` routes traffic from the loopback interface to the external
interface for outbound access.
.. code-block:: shell
rdr-anchor "rdr/*"
The `rdr-anchor "rdr/*"` enables dynamic rdr rules to be setup using the
`bastille rdr` command at runtime - eg.
.. code-block:: shell
bastille rdr TARGET tcp 2001 22 # Redirects tcp port 2001 on host to 22 on jail
bastille rdr TARGET udp 2053 53 # Same for udp
bastille rdr TARGET list # List dynamic rdr rules
bastille rdr TARGET clear # Clear dynamic rdr rules
Note that if you are redirecting ports where the host is also listening (eg.
ssh) you should make sure that the host service is not listening on the cloned
interface - eg. for ssh set sshd_flags in rc.conf
.. code-block:: shell
sshd_flags="-o ListenAddress=<host-address>"
Finally, start up the firewall:
.. code-block:: shell
ishmael ~ # service pf restart
At this point you'll likely be disconnected from the host. Reconnect the
ssh session and continue.
This step only needs to be done once in order to prepare the host.

View File

@@ -0,0 +1,123 @@
=========
bootstrap
=========
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. 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 FreeBSD release, run the bootstrap sub-command with the
release version as the argument.
.. code-block:: shell
ishmael ~ # bastille bootstrap 14.0-RELEASE [update]
ishmael ~ # bastille bootstrap 13.2-RELEASE [update]
To `bootstrap` a HardenedBSD release, run the bootstrap sub-command with the
build version as the argument.
.. code-block:: shell
ishmael ~ # bastille bootstrap 13-stable-build-latest
This command will ensure the required directory structures are in place and
download the requested release. For each requested release, `bootstrap` will
download the base.txz. These files are verified (sha256 via MANIFEST file)
before they are extracted for use.
EOL Releases
------------
It is sometimes necessary to run end-of-life releases for testing or legacy
application support. By default Bastille will only install supported releases
but you can bootstrap EOL / unsupported releases with a simple trick.
.. code-block:: shell
ishmael ~ # export BASTILLE_URL_FREEBSD=http://ftp-archive.freebsd.org/pub/FreeBSD-Archive/old-releases/
ishmael ~ # bastille bootstrap 11.2-RELEASE
By overriding the BASTILLE_URL_FREEBSD variable you can now bootstrap archived
releases from the FTP archive.
Tips
----
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.
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.

View File

@@ -0,0 +1,17 @@
=====
clone
=====
To clone a container and make a duplicate use the `bastille clone`
sub-command..
.. code-block:: shell
ishmael ~ # bastille clone azkaban rikers ip
[azkaban]:
Syntax requires a name for the new container and an IP address assignment.
.. code-block:: shell
Usage: bastille clone [TARGET] [NEW_NAME] [IPADRESS].

View File

@@ -0,0 +1,14 @@
===
cmd
===
To execute commands within the container you can use `bastille cmd`.
.. code-block:: shell
ishmael ~ # bastille cmd folsom ps -auxw
[folsom]:
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
root 71464 0.0 0.0 14536 2000 - IsJ 4:52PM 0:00.00 /usr/sbin/syslogd -ss
root 77447 0.0 0.0 16632 2140 - SsJ 4:52PM 0:00.00 /usr/sbin/cron -J 60 -s
root 80591 0.0 0.0 18784 2340 1 R+J 4:53PM 0:00.00 ps -auxw

View File

@@ -0,0 +1,16 @@
=======
console
=======
This sub-command launches a login shell into the container. Default is password-less
root login.
.. code-block:: shell
ishmael ~ # bastille console folsom
[folsom]:
root@folsom:~ #
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.

View File

@@ -0,0 +1,16 @@
=======
convert
=======
To convert a thin container to a thick container use `bastille convert`.
.. code-block:: shell
ishmael ~ # bastille convert azkaban
[azkaban]:
Syntax requires only the target container to convert.
.. code-block:: shell
Usage: bastille convert TARGET

View File

@@ -0,0 +1,22 @@
==
cp
==
This command allows efficiently copying files from host to container(s).
.. code-block:: shell
ishmael ~ # bastille cp ALL /tmp/resolv.conf-cf etc/resolv.conf
[bastion]:
[unbound0]:
[unbound1]:
[squid]:
[nginx]:
[folsom]:
Unless you see errors reported in the output the `cp` was successful.

View File

@@ -0,0 +1,52 @@
======
create
======
Bastille create uses any available bootstrapped release to create a
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.3-RELEASE 10.17.89.10 [interface]
RELEASE: 11.3-RELEASE.
NAME: folsom.
IP: 10.17.89.10.
This command will create a 11.3-RELEASE container assigning the 10.17.89.10 ip
address to the new system.
.. code-block:: shell
ishmael ~ # bastille create alcatraz 13.2-RELEASE 10.17.89.113/24
The above code will create a jail with a /24 mask. At the time of this documentation you
can only use CIDR notation, and not use a netmask 255.255.255.0 to accomplish this.
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.
A couple of notes about the created jails. First, MOTD has been disabled inside
of the jails because it does not give information about the jail, but about the host
system. This caused confusion for some users, so we implemented the .hushlogin which
silences the MOTD at login.
Also, uname does not work from within a jail. Much like MOTD, it gives you the version
information about the host system instead of the jail. If you need to check the version
of freebsd running on the jail use the freebsd-version command to get accurate information.

View File

@@ -0,0 +1,19 @@
=======
destroy
=======
Containers can be destroyed and thrown away just as easily as they were
created. Note: containers must be stopped before destroyed.
.. code-block:: shell
ishmael ~ # bastille stop folsom
[folsom]:
folsom: removed
.. code-block:: shell
ishmael ~ # bastille destroy folsom
Deleting Container: folsom.
Note: containers console logs not destroyed.
/usr/local/bastille/logs/folsom_console.log

View File

@@ -0,0 +1,16 @@
====
edit
====
To edit container configuration use `bastille edit`.
.. code-block:: shell
ishmael ~ # bastille edit azkaban [filename]
Syntax requires a target an optional filename. By default the file edited will
be `jail.conf`. Other common filenames are `fstab` or `rctl.conf`.
.. code-block:: shell
Usage: bastille edit TARGET

View File

@@ -0,0 +1,31 @@
======
export
======
Exporting a container creates an archive or image that can be sent to a
different machine to be imported later. These exported archives can be used as
container backups.
.. code-block:: shell
ishmael ~ # bastille export azkaban
The export sub-command supports both UFS and ZFS storage. ZFS based containers
will use ZFS snapshots. UFS based containers will use `txz` archives and they
can be exported only when the jail is not running.
.. code-block:: shell
Usage: bastille export | option(s) | TARGET | PATH
Available options are:
.. code-block:: shell
--gz -- Export a ZFS jail using GZIP(.gz) compressed image.
-r | --raw -- Export a ZFS jail to an uncompressed RAW image.
-s | --safe -- Safely stop and start a ZFS jail before the exporting process.
--tgz -- Export a jail using simple .tgz compressed archive instead.
--txz -- Export a jail using simple .txz compressed archive instead.
-v | --verbose -- Be more verbose during the ZFS send operation.
--xz -- Export a ZFS jail using XZ(.xz) compressed image.

View File

@@ -0,0 +1,11 @@
====
htop
====
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 container

View File

@@ -0,0 +1,16 @@
======
import
======
Import a container backup image or archive.
.. code-block:: shell
ishmael ~ # bastille import /path/to/archive.file
The import sub-command supports both UFS and ZFS storage. ZFS based containers
will use ZFS snapshots. UFS based containers will use `txz` archives.
.. code-block:: shell
Usage: bastille import file [option]

View File

@@ -0,0 +1,35 @@
Bastille sub-commands
=====================
.. toctree::
:maxdepth: 2
:caption: Contents:
bootstrap
cmd
clone
console
convert
cp
create
destroy
edit
export
htop
import
mount
pkg
rdr
rename
restart
service
setup
start
stop
sysrc
tags
top
umount
update
upgrade
verify

View File

@@ -0,0 +1,16 @@
=====
mount
=====
To mount storage within the container use `bastille mount`.
.. code-block:: shell
ishmael ~ # bastille mount azkaban /storage/foo /media/foo nullfs ro 0 0
[azkaban]:
Syntax follows standard `/etc/fstab` format:
.. code-block:: shell
Usage: bastille mount TARGET host_path container_path [filesystem_type options dump pass_number]

View File

@@ -0,0 +1,106 @@
===
pkg
===
To manage binary packages within the container use `bastille pkg`.
.. code-block:: shell
ishmael ~ # bastille pkg folsom install vim-console git-lite zsh
[folsom]:
The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]: y
...[snip]...
Number of packages to be installed: 10
The process will require 77 MiB more space.
17 MiB to be downloaded.
Proceed with this action? [y/N]: y
...[snip]...
The PKG sub-command can, of course, do more than just `install`. The
expectation is that you can fully leverage the pkg manager. This means,
`install`, `update`, `upgrade`, `audit`, `clean`, `autoremove`, etc., etc.
.. code-block:: shell
ishmael ~ # bastille pkg ALL upgrade
[bastion]:
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%
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%
Checking integrity... done (0 conflicting)
Your packages are up to date.
[unbound0]:
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%
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%
Checking integrity... done (0 conflicting)
Your packages are up to date.
[unbound1]:
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%
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%
Checking integrity... done (0 conflicting)
Your packages are up to date.
[squid]:
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%
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%
Checking integrity... done (0 conflicting)
Your packages are up to date.
[nginx]:
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%
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%
The following 1 package(s) will be affected (of 0 checked):
Installed packages to be UPGRADED:
nginx-lite: 1.23.0 -> 1.24.0_12,3
Number of packages to be upgraded: 1
315 KiB to be downloaded.
Proceed with this action? [y/N]: y
[nginx] [1/1] Fetching nginx-lite-1.14.1,2.txz: 100% 315 KiB 322.8kB/s 00:01
Checking integrity... done (0 conflicting)
[nginx] [1/1] Upgrading nginx-lite from 1.23.0 to 1.24.0_12,3...
===> Creating groups.
Using existing group 'www'.
===> Creating users
Using existing user 'www'.
[nginx] [1/1] Extracting nginx-lite-1.24.0_12: 100%
You may need to manually remove /usr/local/etc/nginx/nginx.conf if it is no longer needed.

View File

@@ -0,0 +1,26 @@
===
rdr
===
`bastille rdr` allows you to configure dynamic rdr rules for your containers
without modifying pf.conf (assuming you are using the `bastille0` interface
for a private network and have enabled `rdr-anchor 'rdr/*'` in /etc/pf.conf
as described in the Networking section).
Note: you need to be careful if host services are configured to run
on all interfaces as this will include the jail interface - you should
specify the interface they run on in rc.conf (or other config files)
.. code-block:: shell
# bastille rdr --help
Usage: bastille rdr TARGET [clear] | [list] | [tcp <host_port> <jail_port>] | [udp <host_port> <jail_port>]
# bastille rdr dev1 tcp 2001 22
# bastille rdr dev1 list
rdr on em0 inet proto tcp from any to any port = 2001 -> 10.17.89.1 port 22
# bastille rdr dev1 udp 2053 53
# bastille rdr dev1 list
rdr on em0 inet proto tcp from any to any port = 2001 -> 10.17.89.1 port 22
rdr on em0 inet proto udp from any to any port = 2053 -> 10.17.89.1 port 53
# bastille rdr dev1 clear
nat cleared

View File

@@ -0,0 +1,13 @@
======
rename
======
Rename a container.
.. code-block:: shell
ishmael ~ # bastille rename azkaban arkham
.. code-block:: shell
Usage: bastille rename TARGET new_name

View File

@@ -0,0 +1,14 @@
=======
restart
=======
To restart a container you can use the `bastille restart` command.
.. code-block:: shell
ishmael ~ # bastille restart folsom
[folsom]:
folsom: removed
[folsom]:
folsom: created

View File

@@ -0,0 +1,16 @@
=======
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'
ishmael ~ # bastille service proxy 'nginx enable'
ishmael ~ # bastille service proxy 'nginx disable'
ishmael ~ # bastille service proxy 'nginx delete'

View File

@@ -0,0 +1,16 @@
=====
setup
=====
The `setup` sub-command attempts to automatically configure a host system for
Bastille containers. This allows you to configure networking, firewall, and storage
options for a Bastille host with one command.
.. code-block:: shell
ishmael ~ # bastille setup -h ## display setup help
ishmael ~ # bastille setup bastille0 ## only configure loopback interface
ishmael ~ # bastille setup pf ## only configure default firewall
ishmael ~ # bastille setup zfs ## only configure ZFS storage
ishmael ~ # bastille setup vnet ## only configure VNET bridge
ishmael ~ # bastille setup ## configure all of the above

View File

@@ -0,0 +1,11 @@
=====
start
=====
To start a container you can use the `bastille start` command.
.. code-block:: shell
ishmael ~ # bastille start folsom
[folsom]:
folsom: created

View File

@@ -0,0 +1,11 @@
====
stop
====
To stop a container you can use the `bastille stop` command.
.. code-block:: shell
ishmael ~ # bastille stop folsom
[folsom]:
folsom: removed

View File

@@ -0,0 +1,14 @@
=====
sysrc
=====
The `sysrc` sub-command allows for safely editing system configuration files.
In container terms, this allows us to toggle on/off services and options at startup.
.. code-block:: shell
ishmael ~ # bastille sysrc nginx nginx_enable="YES"
[nginx]:
nginx_enable: NO -> YES
See `man sysrc(8)` for more info.

View File

@@ -0,0 +1,13 @@
====
tags
====
The `tags` sub-command adds, removes or lists arbitrary tags on your containers.
.. code-block:: shell
ishmael ~ # bastille tags -h ## display tags help
ishmael ~ # bastille tags TARGET add tag1,tag2 ## add the tags "tag1" and "tag2" to TARGET
ishmael ~ # bastille tags TARGET delete tag2 ## delete tag "tag2" from TARGET
ishmael ~ # bastille tags TARGET list ## list tags assigned to TARGET
ishmael ~ # bastille tags ALL list ## list tags from ALL containers

View File

@@ -0,0 +1,10 @@
===
top
===
This one runs `top` in that container.
.. image:: ../../images/top.png
:align: center
:alt: bastille top container

View File

@@ -0,0 +1,16 @@
======
umount
======
To unmount storage from a container use `bastille umount`.
.. code-block:: shell
ishmael ~ # bastille umount azkaban /media/foo
[azkaban]:
Syntax requires only the container path to unmount:
.. code-block:: shell
Usage: bastille umount TARGET container_path

View File

@@ -0,0 +1,41 @@
======
update
======
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:
.. code-block:: shell
ishmael ~ # bastille update 11.4-RELEASE
Looking up update.FreeBSD.org mirrors... 2 mirrors found.
Fetching metadata signature for 11.4-RELEASE from update4.freebsd.org... done.
Fetching metadata index... done.
Inspecting system... done.
Preparing to download files... done.
No updates needed to update system to 11.4-RELEASE-p4.
No updates are available to install.
The older the release, however, the more updates will be available:
.. code-block:: shell
ishmael ~ # bastille update 13.2-RELEASE
Looking up update.FreeBSD.org mirrors... 2 mirrors found.
Fetching metadata signature for 13.2-RELEASE from update1.freebsd.org... done.
Fetching metadata index... done.
Fetching 2 metadata patches.. done.
Applying metadata patches... done.
Fetching 2 metadata files... done.
Inspecting system... done.
Preparing to download files... done.
The following files will be added as part of updating to 13.2-RELEASE-p4:
...[snip]...
To be safe, you may want to restart any containers that have been updated live.

View File

@@ -0,0 +1,21 @@
======
verify
======
This command scans a bootstrapped release and validates that everything looks
in order. This is not a 100% comprehensive check, but it compares the release
against a "known good" index.
If you see errors or issues here, consider deleting and re-bootstrapping
the release.
.. code-block:: shell
ishmael ~ # bastille verify 11.2-RELEASE
Looking up update.FreeBSD.org mirrors... 2 mirrors found.
Fetching metadata signature for 11.2-RELEASE from update1.freebsd.org... done.
Fetching metadata index... done.
Fetching 1 metadata patches. done.
Applying metadata patches... done.
Fetching 1 metadata files... done.
Inspecting system... done.

View File

@@ -0,0 +1,64 @@
Targeting
=========
Bastille uses a `command target arguments` syntax, meaning that each command
requires a target. Targets are usually containers, but can also be releases.
Targeting a container is done by providing the exact containers name.
Targeting a release is done by providing the release name. (Note: do not
include the `-pX` point-release version.)
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: Containers
====================
.. code-block:: shell
ishmael ~ # bastille ...
+-----------+--------+------------------+-------------------------------------------------------------+
| command | target | args | description |
+===========+========+==================+=============================================================+
| cmd | ALL | 'sockstat -4' | execute `sockstat -4` in ALL containers (ip4 sockets) |
+-----------+--------+-----+------------+-------------------------------------------------------------+
| console | mariadb02 | --- | console (shell) access to mariadb02 |
+----+------+--------+-----+------------+-------------------------------------------------------------+
| pkg | web01 | 'install nginx' | install nginx package in web01 container |
+-----------+--------+------------------+-------------------------------------------------------------+
| pkg | ALL | upgrade | upgrade packages in ALL containers |
+-----------+--------+------------------+-------------------------------------------------------------+
| pkg | ALL | audit | (CVE) audit packages in ALL containers |
+-----------+--------+------------------+-------------------------------------------------------------+
| sysrc | web01 | nginx_enable=YES | execute `sysrc nginx_enable=YES` in web01 container |
+-----------+--------+------------------+-------------------------------------------------------------+
| template | ALL | username/base | apply `username/base` template to ALL containers |
+-----------+--------+------------------+-------------------------------------------------------------+
| start | web02 | --- | start web02 container |
+----+------+----+---+------------------+--------------+----------------------------------------------+
| cp | bastion03 | /tmp/resolv.conf-cf etc/resolv.conf | copy host-path to container-path in bastion03|
+----+------+----+---+---------------------------------+----------------------------------------------+
| create | folsom | 13.2-RELEASE 10.17.89.10 | create 13.2 container named `folsom` with IP |
+-----------+--------+---------------------------------+----------------------------------------------+
Examples: Releases
==================
.. code-block:: shell
ishmael ~ # bastille ...
+-----------+--------------+--------------+-------------------------------------------------------------+
| command | target | args | description |
+===========+==============+==============+=============================================================+
| bootstrap | 13.2-RELEASE | --- | bootstrap 13.2-RELEASE release |
+-----------+--------------+--------------+-------------------------------------------------------------+
| update | 12.4-RELEASE | --- | update 12.4-RELEASE release |
+-----------+--------------+--------------+-------------------------------------------------------------+
| verify | 12.4-RELEASE | --- | verify 12.4-RELEASE release |
+-----------+--------------+--------------+-------------------------------------------------------------+

175
docs/chapters/template.rst Normal file
View File

@@ -0,0 +1,175 @@
========
Template
========
Looking for ready made CI/CD validated `Bastille Templates`_?
Bastille supports a templating system allowing you to apply files, pkgs and
execute commands inside the containers automatically.
Currently supported template hooks are: `CMD`, `CP`, `INCLUDE`, `LIMITS`, `MOUNT`,
`PKG`, `RDR`, `SERVICE`, `SYSRC`.
Templates are created in `${bastille_prefix}/templates` and can leverage any of
the template hooks.
Bastille 0.7.x+
---------------
Bastille 0.7.x introduces a template syntax that is more flexible and allows
any-order scripting. Previous versions had a hard template execution order and
instructions were spread across multiple files. The new syntax is done in a
`Bastillefile` and the template hook (see below) files are replaced with
template hook commands.
Template Automation Hooks
-------------------------
+---------+-------------------+-----------------------------------------+
| HOOK | format | example |
+=========+===================+=========================================+
| CMD | /bin/sh command | /usr/bin/chsh -s /usr/local/bin/zsh |
+---------+-------------------+-----------------------------------------+
| CP | path(s) | etc root usr (one per line) |
+---------+-------------------+-----------------------------------------+
| INCLUDE | template path/URL | http?://TEMPLATE_URL or project/path |
+---------+-------------------+-----------------------------------------+
| LIMITS | resource value | memoryuse 1G |
+---------+-------------------+-----------------------------------------+
| MOUNT | fstab syntax | /host/path container/path nullfs ro 0 0 |
+---------+-------------------+-----------------------------------------+
| PKG | port/pkg name(s) | vim-console zsh git-lite tree htop |
+---------+-------------------+-----------------------------------------+
| RDR | tcp port port | tcp 2200 22 (hostport jailport) |
+---------+-------------------+-----------------------------------------+
| SERVICE | service command | 'nginx start' OR 'postfix reload' |
+---------+-------------------+-----------------------------------------+
| SYSRC | sysrc command(s) | nginx_enable=YES |
+---------+-------------------+-----------------------------------------+
Note: SYSRC requires that NO quotes be used or that quotes (`"`) be escaped
ie; (`\\"`)
Place these uppercase template hook commands into a `Bastillefile` in any order
and automate container setup as needed.
In addition to supporting template hooks, Bastille supports overlaying
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 `bastille/templates/username/template`, our
example template, as the root of our filesystem overlay. If you create an
`etc/hosts` or `etc/resolv.conf` *inside* the 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 container will
use, be sure to include `usr` in the template OVERLAY definition. eg;
.. code-block:: shell
echo "CP usr /" >> /usr/local/bastille/templates/username/template/Bastillefile
The above example "usr" will include anything under "usr" inside the template.
You do not need to list individual files. Just include the top-level directory
name. List these top-level directories one per line.
Applying 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
directory names in the `bastille/templates` directory.
.. code-block:: shell
ishmael ~ # bastille template ALL username/template
[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 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%
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
Updating services.
cron_flags: -J 60 -> -J 60
sendmail_enable: NONE -> NONE
syslogd_flags: -ss -> -ss
Executing final command(s).
chsh: user information updated
Template Complete.
[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 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%
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%
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
Updating services.
cron_flags: -J 60 -> -J 60
sendmail_enable: NONE -> NONE
syslogd_flags: -ss -> -ss
Executing final command(s).
chsh: user information updated
Template Complete.
.. _Bastille Templates: https://gitlab.com/BastilleBSD-Templates
Using Ports in Templates
------------------------
Sometimes when you make a template you need special options for a package, or you need a newer version than what is in the pkgs. The solution for these cases, or a case like minecraft server that has NO compiled option, is to use the ports. A working example of this is the minecraft server template in the template repo. The main lines needed to use this is first to mount the ports directory, then compile the port. Below is an example of the minecraft template where this was used.
.. code-block:: shell
ARG MINECRAFT_MEMX="1024M"
ARG MINECRAFT_MEMS="1024M"
ARG MINECRAFT_ARGS=""
CONFIG set enforce_statfs=1;
CONFIG set allow.mount.fdescfs;
CONFIG set allow.mount.procfs;
RESTART
PKG dialog4ports tmux openjdk17
MOUNT /usr/ports usr/ports nullfs ro 0 0
CP etc /
CP var /
CMD make -C /usr/ports/games/minecraft-server install clean
CP usr /
SYSRC minecraft_enable=YES
SYSRC minecraft_memx=${MINECRAFT_MEMX}
SYSRC minecraft_mems=${MINECRAFT_MEMS}
SYSRC minecraft_args=${MINECRAFT_ARGS}
SERVICE minecraft restart
RDR tcp 25565 25565
The MOUNT line mounts the ports directory, then the CMD make line makes the port. This can be modified to use any port in the port tree.

View File

@@ -0,0 +1,41 @@
=========
Upgrading
=========
This document outlines upgrading jails hosted using Bastille.
Bastille can "bootstrap" multiple versions of FreeBSD to be used by jails. All jails do not NEED to be the same version (even if they often are), the only requirement here is that the "bootstrapped" versions are less than or equal to the host version of FreeBSD.
To upgrade Bastille jails for a minor release (ie; 13.1→13.2) you can do the following:
1. ensure the new release version is bootstrapped and updated to the latest patch release: `bastille bootstrap 13.2-RELEASE update`
2. stop the jail(s) that need to be updated.
3. use `bastille edit TARGET fstab` to manually update the jail mounts from 13.1 to 13.2 release path.
4. start the jail(s) that were edited
5. upgrade complete!
To upgrade Bastille jails for a major release (ie; 12.4→13.2) you can do the following:
1. ensure the new version is bootstrapped and update to the latest patch release: `bastille bootstrap 13.2-RELEASE update`
2. stop the jail(s) that need to be updated.
3. use `bastille edit TARGET fstab` to manually update the jail mounts from 12.4 to 13.2 release path.
4. start the jail(s) that were edited
5. Force the reinstallation or upgrade of all installed packages (ABI change): `pkg upgrade -f` within each jail (or `bastille pkg ALL upgrade -f`)
6. restart the affected jail(s)
7. upgrade complete!
Revert Upgrade / Downgrade Process
----------------------------------
The downgrade process (not usually needed) is similar to the upgrade process only in reverse.
If you did a minor upgrade changing the release path from 13.1 to 13.2, stop the jail and revert that change. Downgrade complete.
If you did a major upgrade changing the release path from 12.4 to 13.2, stop the jail and revert that change. The pkg reinstallation will also need to be repeated after the jail restarts on the previous release.
Old Releases
----------------------------------
After upgrading all jails from one release to the next you may find that you now have bootstrapped a release that is no longer used. Once you've decided that you no longer need the option to revert the change you can destroy the old release.
`bastille list releases` to list all bootstrapped releases.
`bastille destroy X.Y-RELEASE` to fully delete the release.

49
docs/chapters/usage.rst Normal file
View File

@@ -0,0 +1,49 @@
Usage
=====
.. code-block:: shell
ishmael ~ # bastille help
Bastille is an open-source system for automating deployment and management of
containerized applications on FreeBSD.
Usage:
bastille command TARGET [args]
Available Commands:
bootstrap Bootstrap a FreeBSD release for container base.
cmd Execute arbitrary command on targeted container(s).
clone Clone an existing container.
config Get or set a config value for the targeted container(s).
console Console into a running container.
convert Convert a Thin container into a Thick container.
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.
edit Edit container configuration files (advanced).
export Exports a specified container.
help Help about any command.
htop Interactive process viewer (requires htop).
import Import a specified container.
limits Apply resources limits to targeted container(s). See rctl(8).
list List containers (running and stopped).
mount Mount a volume inside the targeted container(s).
pkg Manipulate binary packages within targeted container(s). See pkg(8).
rdr Redirect host port to container port.
rename Rename a container.
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 container(s).
top Display and update information about the top(1) cpu processes.
umount Unmount a volume from within the targeted container(s).
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.

View File

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

79
docs/conf.py Normal file
View File

@@ -0,0 +1,79 @@
import os
on_rtd = os.environ.get('READTHEDOCS') == 'True'
if on_rtd:
html_theme = 'default'
else:
html_theme = 'sphinx_rtd_theme'
# -- Project information -----------------------------------------------------
project = 'Bastille'
copyright = '2018-2023, Christer Edwards'
author = 'Christer Edwards'
# The short X.Y version
version = '0.10.20231125'
# The full version, including alpha/beta/rc tags
release = '0.10.20231125-beta'
# -- General configuration ---------------------------------------------------
extensions = [
]
templates_path = ['_templates']
source_suffix = ['.rst', '.md']
#from recommonmark.parser import CommonMarkParser
#source_parsers = {
# '.md': CommonMarkParser,
#}
master_doc = 'index'
language = None
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
pygments_style = None
# -- Options for HTML output -------------------------------------------------
html_static_path = ['_static']
# -- Options for HTMLHelp output ---------------------------------------------
htmlhelp_basename = 'Bastilledoc'
# -- Options for LaTeX output ------------------------------------------------
latex_elements = {
}
latex_documents = [
(master_doc, 'Bastille.tex', 'Bastille Documentation',
'Christer Edwards', 'manual'),
]
# -- Options for manual page output ------------------------------------------
man_pages = [
(master_doc, 'bastille', 'Bastille Documentation',
[author], 1)
]
# -- Options for Texinfo output ----------------------------------------------
texinfo_documents = [
(master_doc, 'Bastille', 'Bastille Documentation',
author, 'Bastille', 'Bastille is an open-source system for automating deployment and management of containerized applications on FreeBSD.',
'Miscellaneous'),
]
# -- Options for Epub output -------------------------------------------------
epub_title = project
# A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html']

8
docs/copyright.rst Normal file
View File

@@ -0,0 +1,8 @@
=========
Copyright
=========
This content is copyright Christer Edwards. All rights reserved.
Duplication of this content without the express written permission of the
author is not permitted.

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

BIN
docs/images/htop.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 263 KiB

BIN
docs/images/top.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 KiB

29
docs/index.rst Normal file
View File

@@ -0,0 +1,29 @@
Bastille
========
Welcome to the official Bastille documentation. This collection of documents
will outline installation and usage of Bastille.
The latest version of this documentation can always be found at
https://docs.bastillebsd.org.
.. toctree::
:maxdepth: 2
:caption: Contents:
chapters/installation
chapters/upgrading
chapters/networking
chapters/usage
chapters/targeting
chapters/upgrading
chapters/subcommands/index
chapters/template
chapters/jail-config
chapters/zfs-support
chapters/gcp
chapters/migration
copyright
Note: this documentation is included with the source code in `docs`.

1
docs/requirements.txt Normal file
View File

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

View File

@@ -1,22 +1,22 @@
#!/bin/sh
#
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
#
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
#
# Redistribution and use in source and binary forms, with or without
# 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
@@ -28,42 +28,86 @@
# 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.
SAVED_TERM=$TERM
PATH=${PATH}:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
. /usr/local/share/bastille/colors.pre.sh
. /usr/local/share/bastille/common.sh
## check for config existance
bastille_conf_check() {
if [ ! -r "/usr/local/etc/bastille/bastille.conf" ]; then
error_exit "Missing Configuration"
fi
}
bastille_conf_check
## we only load the config if conf_check passes
. /usr/local/etc/bastille/bastille.conf
# Set default values for config properties added during the current major version:
: "${bastille_network_pf_ext_if:=ext_if}"
: "${bastille_network_pf_table:=jails}"
## bastille_prefix should be 0750
## this restricts file system access to privileged users
bastille_perms_check() {
if [ -d "${bastille_prefix}" ]; then
BASTILLE_PREFIX_PERMS=$(stat -f "%Op" "${bastille_prefix}")
if [ "${BASTILLE_PREFIX_PERMS}" != 40750 ]; then
error_notify "Insecure permissions on ${bastille_prefix}"
error_exit "Try: chmod 0750 ${bastille_prefix}"
fi
fi
}
bastille_perms_check
## version
BASTILLE_VERSION="0.3.20181112"
BASTILLE_VERSION="0.10.20231125"
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.
clone Clone an existing container.
cmd Execute arbitrary command on targeted container(s).
config Get or set a config value for the targeted container(s).
console Console into a running container.
convert Convert a Thin container into a Thick container.
cp cp(1) files from host to targeted container(s).
create Create a new container.
destroy Destroy a stopped container.
help Help about any command
create Create a new thin container or a thick container if -T|--thick option specified.
destroy Destroy a stopped container or a FreeBSD release.
edit Edit container configuration files (advanced).
export Exports a specified container.
help Help about any command.
htop Interactive process viewer (requires htop).
import Import a specified container.
limits Apply resources limits to targeted container(s). See rctl(8).
list List containers (running and stopped).
mount Mount a volume inside the targeted container(s).
pkg Manipulate binary packages within targeted container(s). See pkg(8).
rcp reverse cp(1) files from a single container to the host.
rdr Redirect host port to container port.
rename Rename a container.
restart Restart a running container.
service Manage services within targeted container(s).
setup Attempt to auto-configure network, firewall and storage on new installs.
start Start a stopped container.
stop Stop a running container.
sysrc Safely edit rc files within targeted container(s).
template Apply file templates to targeted jail(s).
tags Add or remove tags to targeted container(s).
template Apply file templates to targeted container(s).
top Display and update information about the top(1) cpu processes.
umount Unmount a volume from within the targeted container(s).
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,48 +121,112 @@ EOF
CMD=$1
shift
target_all_jails() {
_JAILS=$(/usr/sbin/jls name)
JAILS=""
for _jail in ${_JAILS}; do
_JAILPATH=$(/usr/sbin/jls -j "${_jail}" path)
if [ -z ${_JAILPATH##${bastille_jailsdir}*} ]; then
JAILS="${JAILS} ${_jail}"
fi
done
}
check_target_is_running() {
if [ ! "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
error_exit "[${TARGET}]: Not started. See 'bastille start ${TARGET}'."
fi
}
# Handle special-case commands first.
case "${CMD}" in
version|-v|--version)
echo -e "${COLOR_GREEN}${BASTILLE_VERSION}${COLOR_RESET}"
exit 0
;;
help|-h|--help)
usage
;;
esac
# Filter out all non-commands
case "${CMD}" in
cmd|cp|create|destroy|list|pkg|restart|start|stop|sysrc|template|verify)
;;
update|upgrade)
CMD_ENV="${CMD_ENV} PAGER=cat"
;;
console|bootstrap|htop|top)
info "${BASTILLE_VERSION}"
exit 0
;;
bootstrap|update|upgrade)
while read envvar envvalue; do
case "${envvar}" in
FETCH_BIND_ADDRESS|FTP_*|ftp_*|HTTP_*|http_*|SSL_|NO_PROXY|no_proxy|MAKEOBJDIRPREFIX)
CMD_ENV="${CMD_ENV} ${envvar}=${envvalue}"
;;
esac
done <<-EOF
$(env | sed -Ee 's,^([^=]*)=(.*),\1 \2,')
EOF
;;
*)
usage
;;
esac
help|-h|--help)
usage
;;
bootstrap|create|destroy|export|import|list|rdr|restart|setup|start|update|upgrade|verify)
# Nothing "extra" to do for these commands. -- cwells
;;
clone|config|cmd|console|convert|cp|edit|htop|limits|mount|pkg|rcp|rename|service|stop|sysrc|tags|template|top|umount|zfs)
# Parse the target and ensure it exists. -- cwells
if [ $# -eq 0 ]; then # No target was given, so show the command's help. -- cwells
PARAMS='help'
elif [ "${1}" != 'help' ] && [ "${1}" != '-h' ] && [ "${1}" != '--help' ]; then
TARGET="${1}"
shift
# This is needed to handle the special case of 'bastille rcp' and 'bastille cp' with the '-q' or '--quiet'
# option specified before the TARGET. Also seems the cp and rcp commands does not support ALL as a target, so
# that's why is handled here. Maybe this behaviour needs an improvement later. -- yaazkal
if { [ "${CMD}" = 'rcp' ] || [ "${CMD}" = 'cp' ]; } && \
{ [ "${TARGET}" = '-q' ] || [ "${TARGET}" = '--quiet' ]; }; then
TARGET="${1}"
JAILS="${TARGET}"
OPTION="-q"
export OPTION
shift
fi
if [ "${TARGET}" = 'ALL' ]; then
target_all_jails
elif [ "${CMD}" = "pkg" ] && [ "${TARGET}" = '-H' ] || [ "${TARGET}" = '--host' ]; then
TARGET="${1}"
USE_HOST_PKG=1
if [ "${TARGET}" = 'ALL' ]; then
target_all_jails
else
JAILS="${TARGET}"
check_target_is_running
fi
shift
elif [ "${CMD}" = 'template' ] && [ "${TARGET}" = '--convert' ]; then
# This command does not act on a jail, so we are temporarily bypassing the presence/started
# checks. The command will simply convert a template from hooks to a Bastillefile. -- cwells
else
JAILS="${TARGET}"
# Ensure the target exists. -- cwells
if [ ! -d "${bastille_jailsdir}/${TARGET}" ]; then
error_exit "[${TARGET}]: Not found."
fi
case "${CMD}" in
cmd|console|htop|pkg|service|stop|sysrc|template|top)
check_target_is_running
;;
convert|rename)
# Require the target to be stopped. -- cwells
if [ "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
error_exit "${TARGET} is running. See 'bastille stop ${TARGET}'."
fi
;;
esac
fi
export USE_HOST_PKG
export TARGET
export JAILS
fi
;;
*) # Filter out all non-commands
usage
;;
esac
SCRIPTPATH="${bastille_sharedir}/${CMD}.sh"
if [ -f "${SCRIPTPATH}" ]; then
: "${UMASK:=022}"
umask "${UMASK}"
: ${UMASK:=022}
umask ${UMASK}
: "${SH:=sh}"
: ${SH:=sh}
exec env -i ${CMD_ENV} ${SH} "${SCRIPTPATH}" "$@"
if [ -n "${PARAMS}" ]; then
exec "${SH}" "${SCRIPTPATH}" "${PARAMS}"
else
exec "${SH}" "${SCRIPTPATH}" "$@"
fi
else
error_exit "${SCRIPTPATH} not found."
fi

View File

@@ -1,11 +0,0 @@
## [ 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

View File

@@ -0,0 +1,68 @@
#####################
## [ BastilleBSD ] ##
#####################
## default paths
bastille_prefix="/usr/local/bastille" ## default: "/usr/local/bastille"
bastille_backupsdir="${bastille_prefix}/backups" ## default: "${bastille_prefix}/backups"
bastille_cachedir="${bastille_prefix}/cache" ## default: "${bastille_prefix}/cache"
bastille_jailsdir="${bastille_prefix}/jails" ## default: "${bastille_prefix}/jails"
bastille_releasesdir="${bastille_prefix}/releases" ## default: "${bastille_prefix}/releases"
bastille_templatesdir="${bastille_prefix}/templates" ## default: "${bastille_prefix}/templates"
bastille_logsdir="/var/log/bastille" ## default: "/var/log/bastille"
## pf configuration path
bastille_pf_conf="/etc/pf.conf" ## default: "/etc/pf.conf"
## bastille scripts directory (assumed by bastille pkg)
bastille_sharedir="/usr/local/share/bastille" ## default: "/usr/local/share/bastille"
## bootstrap archives, which components of the OS to install.
## base - The base OS, kernel + userland
## lib32 - Libraries for compatibility with 32 bit binaries
## ports - The FreeBSD ports (3rd party applications) tree
## src - The source code to the kernel + userland
## test - The FreeBSD test suite
## this is a whitespace separated list:
## bastille_bootstrap_archives="base lib32 ports src test"
bastille_bootstrap_archives="base" ## default: "base"
## default timezone
bastille_tzdata="" ## default: empty to use host's time zone
## default jail resolv.conf
bastille_resolv_conf="/etc/resolv.conf" ## default: "/etc/resolv.conf"
## bootstrap urls
bastille_url_freebsd="http://ftp.freebsd.org/pub/FreeBSD/releases/" ## default: "http://ftp.freebsd.org/pub/FreeBSD/releases/"
bastille_url_hardenedbsd="https://installers.hardenedbsd.org/pub/" ## default: "https://installer.hardenedbsd.org/pub/HardenedBSD/releases/"
bastille_url_midnightbsd="https://www.midnightbsd.org/ftp/MidnightBSD/releases/" ## default: "https://www.midnightbsd.org/pub/MidnightBSD/releases/"
## ZFS options
bastille_zfs_enable="" ## default: ""
bastille_zfs_zpool="" ## default: ""
bastille_zfs_prefix="${bastille_zfs_zpool}/bastille" ## default: "${bastille_zfs_zpool}/bastille"
bastille_zfs_options="-o compress=lz4 -o atime=off" ## default: "-o compress=lz4 -o atime=off"
## Export/Import options
bastille_compress_xz_options="-0 -v" ## default "-0 -v"
bastille_decompress_xz_options="-c -d -v" ## default "-c -d -v"
bastille_compress_gz_options="-1 -v" ## default "-1 -v"
bastille_decompress_gz_options="-k -d -c -v" ## default "-k -d -c -v"
bastille_export_options="" ## default "" predefined export options, e.g. "--safe --gz"
## Networking
bastille_network_loopback="bastille0" ## default: "bastille0"
bastille_network_pf_ext_if="ext_if" ## default: "ext_if"
bastille_network_pf_table="jails" ## default: "jails"
bastille_network_shared="" ## default: ""
bastille_network_gateway="" ## default: ""
bastille_network_gateway6="" ## default: ""
## Default Templates
bastille_template_base="default/base" ## default: "default/base"
bastille_template_empty="" ## default: "default/empty"
bastille_template_thick="default/thick" ## default: "default/thick"
bastille_template_clone="default/clone" ## default: "default/clone"
bastille_template_thin="default/thin" ## default: "default/thin"
bastille_template_vnet="default/vnet" ## default: "default/vnet"

87
usr/local/etc/rc.d/bastille Normal file → Executable file
View File

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

Binary file not shown.

View File

@@ -1,22 +1,22 @@
#!/bin/sh
#
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
#
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
#
# Redistribution and use in source and binary forms, with or without
# 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
@@ -28,12 +28,11 @@
# 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/share/bastille/common.sh
. /usr/local/etc/bastille/bastille.conf
usage() {
echo -e "${COLOR_RED}Usage: bastille bootstrap release.${COLOR_RESET}"
exit 1
error_exit "Usage: bastille bootstrap [release|template] [update|arch]"
}
# Handle special-case commands first.
@@ -43,89 +42,571 @@ help|-h|--help)
;;
esac
RELEASE=$1
bastille_root_check
bootstrap() {
### create $bastille_base/release/$release directory
### fetch $release/base.txz -o $bastille_base/cache/$release/base.txz
### extract $release/base.txz to $bastille_base/release/$release
if [ ! -d ${bastille_jailsdir} ]; then
mkdir -p ${bastille_jailsdir}
fi
if [ ! -d ${bastille_logsdir} ]; then
mkdir -p ${bastille_logsdir}
fi
if [ ! -d ${bastille_cachedir}/${RELEASE} ]; then
mkdir -p ${bastille_cachedir}/${RELEASE}
#Validate if ZFS is enabled in rc.conf and bastille.conf.
if [ "$(sysrc -n zfs_enable)" = "YES" ] && ! checkyesno bastille_zfs_enable; then
warn "ZFS is enabled in rc.conf but not bastille.conf. Do you want to continue? (N|y)"
read answer
case $answer in
no|No|n|N|"")
error_exit "ERROR: Missing ZFS parameters. See bastille_zfs_enable."
;;
yes|Yes|y|Y) ;;
esac
fi
# Validate ZFS parameters.
if checkyesno bastille_zfs_enable; then
## check for the ZFS pool and bastille prefix
if [ -z "${bastille_zfs_zpool}" ]; then
error_exit "ERROR: Missing ZFS parameters. See bastille_zfs_zpool."
elif [ -z "${bastille_zfs_prefix}" ]; then
error_exit "ERROR: Missing ZFS parameters. See bastille_zfs_prefix."
elif ! zfs list "${bastille_zfs_zpool}" > /dev/null 2>&1; then
error_exit "ERROR: ${bastille_zfs_zpool} is not a ZFS pool."
fi
if [ ! -d ${bastille_releasesdir}/${RELEASE} ]; then
mkdir -p ${bastille_releasesdir}/${RELEASE}
sh ${bastille_sharedir}/freebsd_dist_fetch.sh -r ${RELEASE} base lib32
## 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
error_exit "ERROR: ${bastille_zfs_zpool}/${bastille_zfs_prefix} is not a ZFS dataset."
fi
fi
fi
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
validate_release_url() {
## check upstream url, else warn user
if [ -n "${NAME_VERIFY}" ]; then
RELEASE="${NAME_VERIFY}"
if ! fetch -qo /dev/null "${UPSTREAM_URL}/MANIFEST" 2>/dev/null; then
error_exit "Unable to fetch MANIFEST. See 'bootstrap urls'."
fi
info "Bootstrapping ${PLATFORM_OS} distfiles..."
echo -e "${COLOR_GREEN}Extracting FreeBSD ${RELEASE} lib32.txz.${COLOR_RESET}"
/usr/bin/tar -C ${bastille_releasesdir}/${RELEASE} -xf ${bastille_cachedir}/${RELEASE}/lib32.txz
# Alternate RELEASE/ARCH fetch support
if [ "${OPTION}" = "--i386" ] || [ "${OPTION}" = "--32bit" ]; then
ARCH="i386"
RELEASE="${RELEASE}-${ARCH}"
fi
echo -e "${COLOR_GREEN}Bootstrap successful.${COLOR_RESET}"
echo -e "${COLOR_GREEN}See 'bastille --help' for available commands.${COLOR_RESET}"
echo
bootstrap_directories
bootstrap_release
else
echo -e "${COLOR_RED}Bootstrap appears complete.${COLOR_RESET}"
exit 1
usage
fi
}
# Filter sane release names
case "${RELEASE}" in
10.1-RELEASE)
bootstrap
echo -e "${COLOR_RED}This release is End of Life. No security updates.${COLOR_RESET}"
;;
10.2-RELEASE)
bootstrap
echo -e "${COLOR_RED}This release is End of Life. No security updates.${COLOR_RESET}"
;;
10.3-RELEASE)
bootstrap
echo -e "${COLOR_RED}This release is End of Life. No security updates.${COLOR_RESET}"
;;
10.4-RELEASE)
bootstrap
echo -e "${COLOR_RED}This release is End of Life. No security updates.${COLOR_RESET}"
;;
11.0-RELEASE)
bootstrap
echo -e "${COLOR_RED}This release is End of Life. No security updates.${COLOR_RESET}"
;;
11.1-RELEASE)
bootstrap
echo -e "${COLOR_RED}This release is End of Life. No security updates.${COLOR_RESET}"
;;
11.2-RELEASE)
bootstrap
;;
12.0-BETA1)
bootstrap
echo -e "${COLOR_RED}BETA releases are complete untested.${COLOR_RESET}"
;;
12.0-BETA2)
bootstrap
echo -e "${COLOR_RED}BETA releases are complete untested.${COLOR_RESET}"
;;
12.0-BETA3)
bootstrap
echo -e "${COLOR_RED}BETA releases are complete untested.${COLOR_RESET}"
;;
12.0-BETA4)
bootstrap
echo -e "${COLOR_RED}BETA releases are complete untested.${COLOR_RESET}"
;;
bootstrap_directories() {
## ensure required directories are in place
## ${bastille_prefix}
if [ ! -d "${bastille_prefix}" ]; then
if checkyesno bastille_zfs_enable; then
if [ -n "${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}"
fi
chmod 0750 "${bastille_prefix}"
fi
## ${bastille_backupsdir}
if [ ! -d "${bastille_backupsdir}" ]; then
if checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then
zfs create ${bastille_zfs_options} -o mountpoint="${bastille_backupsdir}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/backups"
fi
else
mkdir -p "${bastille_backupsdir}"
fi
chmod 0750 "${bastille_backupsdir}"
fi
## ${bastille_cachedir}
if [ ! -d "${bastille_cachedir}" ]; then
if checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then
zfs create ${bastille_zfs_options} -o mountpoint="${bastille_cachedir}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/cache"
# Don't create unused/stale cache/RELEASE directory on Linux jails creation.
if [ -z "${NOCACHEDIR}" ]; then
zfs create ${bastille_zfs_options} -o mountpoint="${bastille_cachedir}/${RELEASE}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/cache/${RELEASE}"
fi
fi
else
mkdir -p "${bastille_cachedir}"
# Don't create unused/stale cache/RELEASE directory on Linux jails creation.
if [ -z "${NOCACHEDIR}" ]; then
mkdir -p "${bastille_cachedir}/${RELEASE}"
fi
fi
## create subsequent cache/XX.X-RELEASE datasets
elif [ ! -d "${bastille_cachedir}/${RELEASE}" ]; then
# Don't create unused/stale cache/RELEASE directory on Linux jails creation.
if [ -z "${NOCACHEDIR}" ]; then
if checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then
zfs create ${bastille_zfs_options} -o mountpoint="${bastille_cachedir}/${RELEASE}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/cache/${RELEASE}"
fi
else
mkdir -p "${bastille_cachedir}/${RELEASE}"
fi
fi
fi
## ${bastille_jailsdir}
if [ ! -d "${bastille_jailsdir}" ]; then
if checkyesno bastille_zfs_enable; then
if [ -n "${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 checkyesno bastille_zfs_enable; then
if [ -n "${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 checkyesno bastille_zfs_enable; then
if [ -n "${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 checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then
zfs create ${bastille_zfs_options} -o mountpoint="${bastille_releasesdir}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases"
zfs create ${bastille_zfs_options} -o mountpoint="${bastille_releasesdir}/${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 checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then
zfs create ${bastille_zfs_options} -o mountpoint="${bastille_releasesdir}/${RELEASE}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${RELEASE}"
fi
else
mkdir -p "${bastille_releasesdir}/${RELEASE}"
fi
fi
}
bootstrap_release() {
## if release exists quit, else bootstrap additional distfiles
if [ -f "${bastille_releasesdir}/${RELEASE}/COPYRIGHT" ]; then
## check distfiles list and skip existing cached files
bastille_bootstrap_archives=$(echo "${bastille_bootstrap_archives}" | sed "s/base//")
bastille_cached_files=$(ls "${bastille_cachedir}/${RELEASE}" | grep -v "MANIFEST" | tr -d ".txz")
for distfile in ${bastille_cached_files}; do
bastille_bootstrap_archives=$(echo "${bastille_bootstrap_archives}" | sed "s/${distfile}//")
done
## check if release already bootstrapped, else continue bootstrapping
if [ -z "${bastille_bootstrap_archives}" ]; then
error_notify "Bootstrap appears complete."
else
info "Bootstrapping additional distfiles..."
fi
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
info "Extracting ${PLATFORM_OS} ${RELEASE} ${_archive}.txz."
if /usr/bin/tar -C "${bastille_releasesdir}/${RELEASE}" -xf "${bastille_cachedir}/${RELEASE}/${_archive}.txz"; then
## silence motd at container login
touch "${bastille_releasesdir}/${RELEASE}/root/.hushlogin"
touch "${bastille_releasesdir}/${RELEASE}/usr/share/skel/dot.hushlogin"
else
error_exit "Failed to extract ${_archive}.txz."
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 checkyesno bastille_zfs_enable; then
if [ -n "${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
error_exit "Bootstrap failed."
fi
## fetch for missing dist files
if [ ! -f "${bastille_cachedir}/${RELEASE}/${_archive}.txz" ]; then
if ! fetch "${UPSTREAM_URL}/${_archive}.txz" -o "${bastille_cachedir}/${RELEASE}/${_archive}.txz"; then
## alert only if unable to fetch additional dist files
error_notify "Failed to fetch ${_archive}.txz."
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
rm "${bastille_cachedir}/${RELEASE}/${_archive}.txz"
error_exit "Failed validation for ${_archive}.txz. Please retry bootstrap!"
else
info "Validated checksum for ${RELEASE}: ${_archive}.txz"
info "MANIFEST: ${SHA256_DIST}"
info "DOWNLOAD: ${SHA256_FILE}"
fi
fi
## extract the fetched dist files
if [ -f "${bastille_cachedir}/${RELEASE}/${_archive}.txz" ]; then
info "Extracting ${PLATFORM_OS} ${RELEASE} ${_archive}.txz."
if /usr/bin/tar -C "${bastille_releasesdir}/${RELEASE}" -xf "${bastille_cachedir}/${RELEASE}/${_archive}.txz"; then
## silence motd at container login
touch "${bastille_releasesdir}/${RELEASE}/root/.hushlogin"
touch "${bastille_releasesdir}/${RELEASE}/usr/share/skel/dot.hushlogin"
else
error_exit "Failed to extract ${_archive}.txz."
fi
fi
fi
done
echo
info "Bootstrap successful."
info "See 'bastille --help' for available commands."
echo
}
debootstrap_release() {
# Make sure to check/bootstrap directories first.
NOCACHEDIR=1
RELEASE="${DIR_BOOTSTRAP}"
bootstrap_directories
#check and install OS dependencies @hackacad
#ToDo: add function 'linux_pre' for sysrc etc.
required_mods="fdescfs linprocfs linsysfs tmpfs"
linuxarc_mods="linux linux64"
for _req_kmod in ${required_mods}; do
if [ ! "$(sysrc -f /boot/loader.conf -qn ${_req_kmod}_load)" = "YES" ] && \
[ ! "$(sysrc -f /boot/loader.conf.local -qn ${_req_kmod}_load)" = "YES" ]; then
warn "${_req_kmod} not enabled in /boot/loader.conf, Should I do that for you? (N|y)"
read answer
case "${answer}" in
[Nn][Oo]|[Nn]|"")
error_exit "Exiting."
;;
[Yy][Ee][Ss]|[Yy])
# Skip already loaded known modules.
if ! kldstat -m ${_req_kmod} >/dev/null 2>&1; then
info "Loading kernel module: ${_req_kmod}"
kldload -v ${_req_kmod}
fi
info "Persisting module: ${_req_kmod}"
sysrc -f /boot/loader.conf ${_req_kmod}_load=YES
;;
esac
else
# If already set in /boot/loader.conf, check and try to load the module.
if ! kldstat -m ${_req_kmod} >/dev/null 2>&1; then
info "Loading kernel module: ${_req_kmod}"
kldload -v ${_req_kmod}
fi
fi
done
# Mandatory Linux modules/rc.
for _lin_kmod in ${linuxarc_mods}; do
if ! kldstat -n ${_lin_kmod} >/dev/null 2>&1; then
info "Loading kernel module: ${_lin_kmod}"
kldload -v ${_lin_kmod}
fi
done
if [ ! "$(sysrc -qn linux_enable)" = "YES" ] && \
[ ! "$(sysrc -f /etc/rc.conf.local -qn linux_enable)" = "YES" ]; then
sysrc linux_enable=YES
fi
if ! which -s debootstrap; then
warn "Debootstrap not found. Should it be installed? (N|y)"
read answer
case $answer in
[Nn][Oo]|[Nn]|"")
error_exit "Exiting. You need to install debootstap before boostrapping a Linux jail."
;;
[Yy][Ee][Ss]|[Yy])
pkg install -y debootstrap
;;
esac
fi
# Fetch the Linux flavor
info "Bootstrapping ${PLATFORM_OS} distfiles..."
if ! debootstrap --foreign --arch=${ARCH_BOOTSTRAP} --no-check-gpg ${LINUX_FLAVOR} "${bastille_releasesdir}"/${DIR_BOOTSTRAP}; then
## perform cleanup only for stale/empty directories on failure
if checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then
if [ ! "$(ls -A "${bastille_releasesdir}/${DIR_BOOTSTRAP}")" ]; then
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${DIR_BOOTSTRAP}"
fi
fi
fi
if [ -d "${bastille_releasesdir}/${DIR_BOOTSTRAP}" ]; then
if [ ! "$(ls -A "${bastille_releasesdir}/${DIR_BOOTSTRAP}")" ]; then
rm -rf "${bastille_releasesdir:?}/${DIR_BOOTSTRAP}"
fi
fi
error_exit "Bootstrap failed."
fi
case "${LINUX_FLAVOR}" in
bionic|focal|jammy|buster|bullseye|bookworm)
info "Increasing APT::Cache-Start"
echo "APT::Cache-Start 251658240;" > "${bastille_releasesdir}"/${DIR_BOOTSTRAP}/etc/apt/apt.conf.d/00aptitude
;;
esac
info "Bootstrap successful."
info "See 'bastille --help' for available commands."
echo
}
bootstrap_template() {
## ${bastille_templatesdir}
if [ ! -d "${bastille_templatesdir}" ]; then
if checkyesno bastille_zfs_enable; then
if [ -n "${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
ln -s "${bastille_sharedir}/templates/default" "${bastille_templatesdir}/default"
fi
## define basic variables
_url=${BASTILLE_TEMPLATE_URL}
_user=${BASTILLE_TEMPLATE_USER}
_repo=${BASTILLE_TEMPLATE_REPO%.*} # Remove the trailing ".git"
_template=${bastille_templatesdir}/${_user}/${_repo}
## support for non-git
if ! which -s git; then
error_notify "Git not found."
error_exit "Not yet implemented."
else
if [ ! -d "${_template}/.git" ]; then
git clone "${_url}" "${_template}" ||\
error_notify "Clone unsuccessful."
elif [ -d "${_template}/.git" ]; then
git -C "${_template}" pull ||\
error_notify "Template update unsuccessful."
fi
fi
bastille verify "${_user}/${_repo}"
}
HW_MACHINE=$(sysctl hw.machine | awk '{ print $2 }')
HW_MACHINE_ARCH=$(sysctl hw.machine_arch | awk '{ print $2 }')
# bootstrapping from aarch64/arm64 Debian or Ubuntu require a different value for ARCH
# create a new variable
if [ "${HW_MACHINE_ARCH}" == "aarch64" ]; then
HW_MACHINE_ARCH_LINUX="arm64"
else
HW_MACHINE_ARCH_LINUX=${HW_MACHINE_ARCH}
fi
NOCACHEDIR=
RELEASE="${1}"
OPTION="${2}"
# Alternate RELEASE/ARCH fetch support(experimental)
if [ -n "${OPTION}" ] && [ "${OPTION}" != "${HW_MACHINE}" ] && [ "${OPTION}" != "update" ]; then
# Supported architectures
if [ "${OPTION}" = "--i386" ] || [ "${OPTION}" = "--32bit" ]; then
HW_MACHINE="i386"
HW_MACHINE_ARCH="i386"
else
error_exit "Unsupported architecture."
fi
fi
## allow override bootstrap URLs via environment variables
[ -n "${BASTILLE_URL_FREEBSD}" ] && bastille_url_freebsd="${BASTILLE_URL_FREEBSD}"
[ -n "${BASTILLE_URL_HARDENEDBSD}" ] && bastille_url_hardenedbsd="${BASTILLE_URL_HARDENEDBSD}"
[ -n "${BASTILLE_URL_MIDNIGHTBSD}" ] && bastille_url_midnightbsd="${BASTILLE_URL_MIDNIGHTBSD}"
## Filter sane release names
case "${1}" in
2.[0-9]*)
## check for MidnightBSD releases name
NAME_VERIFY=$(echo "${RELEASE}")
UPSTREAM_URL="${bastille_url_midnightbsd}${HW_MACHINE_ARCH}/${NAME_VERIFY}"
PLATFORM_OS="MidnightBSD"
validate_release_url
;;
*-CURRENT|*-current)
## check for FreeBSD releases name
NAME_VERIFY=$(echo "${RELEASE}" | grep -iwE '^([1-9]{2,2})\.[0-9](-CURRENT)$' | tr '[:lower:]' '[:upper:]')
UPSTREAM_URL=$(echo "${bastille_url_freebsd}${HW_MACHINE}/${HW_MACHINE_ARCH}/${NAME_VERIFY}" | sed 's/releases/snapshots/')
PLATFORM_OS="FreeBSD"
validate_release_url
;;
*-RELEASE|*-release|*-RC[1-9]|*-rc[1-9]|*-BETA[1-9])
## check for FreeBSD releases name
NAME_VERIFY=$(echo "${RELEASE}" | grep -iwE '^([0-9]{1,2})\.[0-9](-RELEASE|-RC[1-9]|-BETA[1-9])$' | tr '[:lower:]' '[:upper:]')
UPSTREAM_URL="${bastille_url_freebsd}${HW_MACHINE}/${HW_MACHINE_ARCH}/${NAME_VERIFY}"
PLATFORM_OS="FreeBSD"
validate_release_url
;;
*-stable-LAST|*-STABLE-last|*-stable-last|*-STABLE-LAST)
## check for HardenedBSD releases name(previous infrastructure, keep for reference)
NAME_VERIFY=$(echo "${RELEASE}" | grep -iwE '^([1-9]{2,2})(-stable-last)$' | sed 's/STABLE/stable/g' | sed 's/last/LAST/g')
UPSTREAM_URL="${bastille_url_hardenedbsd}${HW_MACHINE}/${HW_MACHINE_ARCH}/hardenedbsd-${NAME_VERIFY}"
PLATFORM_OS="HardenedBSD"
validate_release_url
;;
*-stable-build-[0-9]*|*-STABLE-BUILD-[0-9]*)
## check for HardenedBSD(specific stable build releases)
NAME_VERIFY=$(echo "${RELEASE}" | grep -iwE '([0-9]{1,2})(-stable-build)-([0-9]{1,3})$' | sed 's/BUILD/build/g' | sed 's/STABLE/stable/g')
NAME_RELEASE=$(echo "${NAME_VERIFY}" | sed 's/-build-[0-9]\{1,3\}//g')
NAME_BUILD=$(echo "${NAME_VERIFY}" | sed 's/[0-9]\{1,2\}-stable-//g')
UPSTREAM_URL="${bastille_url_hardenedbsd}${NAME_RELEASE}/${HW_MACHINE}/${HW_MACHINE_ARCH}/${NAME_BUILD}"
PLATFORM_OS="HardenedBSD"
validate_release_url
;;
*-stable-build-latest|*-stable-BUILD-LATEST|*-STABLE-BUILD-LATEST)
## check for HardenedBSD(latest stable build release)
NAME_VERIFY=$(echo "${RELEASE}" | grep -iwE '([0-9]{1,2})(-stable-build-latest)$' | sed 's/STABLE/stable/g' | sed 's/build/BUILD/g' | sed 's/latest/LATEST/g')
NAME_RELEASE=$(echo "${NAME_VERIFY}" | sed 's/-BUILD-LATEST//g')
NAME_BUILD=$(echo "${NAME_VERIFY}" | sed 's/[0-9]\{1,2\}-stable-BUILD-//g')
UPSTREAM_URL="${bastille_url_hardenedbsd}${NAME_RELEASE}/${HW_MACHINE}/${HW_MACHINE_ARCH}/installer/${NAME_BUILD}"
PLATFORM_OS="HardenedBSD"
validate_release_url
;;
current-build-[0-9]*|CURRENT-BUILD-[0-9]*)
## check for HardenedBSD(specific current build releases)
NAME_VERIFY=$(echo "${RELEASE}" | grep -iwE '(current-build)-([0-9]{1,3})' | sed 's/BUILD/build/g' | sed 's/CURRENT/current/g')
NAME_RELEASE=$(echo "${NAME_VERIFY}" | sed 's/current-.*/current/g')
NAME_BUILD=$(echo "${NAME_VERIFY}" | sed 's/current-//g')
UPSTREAM_URL="${bastille_url_hardenedbsd}${NAME_RELEASE}/${HW_MACHINE}/${HW_MACHINE_ARCH}/${NAME_BUILD}"
PLATFORM_OS="HardenedBSD"
validate_release_url
;;
current-build-latest|current-BUILD-LATEST|CURRENT-BUILD-LATEST)
## check for HardenedBSD(latest current build release)
NAME_VERIFY=$(echo "${RELEASE}" | grep -iwE '(current-build-latest)' | sed 's/CURRENT/current/g' | sed 's/build/BUILD/g' | sed 's/latest/LATEST/g')
NAME_RELEASE=$(echo "${NAME_VERIFY}" | sed 's/current-.*/current/g')
NAME_BUILD=$(echo "${NAME_VERIFY}" | sed 's/current-BUILD-//g')
UPSTREAM_URL="${bastille_url_hardenedbsd}${NAME_RELEASE}/${HW_MACHINE}/${HW_MACHINE_ARCH}/installer/${NAME_BUILD}"
PLATFORM_OS="HardenedBSD"
validate_release_url
;;
http?://*/*/*)
BASTILLE_TEMPLATE_URL=${1}
BASTILLE_TEMPLATE_USER=$(echo "${1}" | awk -F / '{ print $4 }')
BASTILLE_TEMPLATE_REPO=$(echo "${1}" | awk -F / '{ print $5 }')
bootstrap_template
;;
git@*:*/*)
BASTILLE_TEMPLATE_URL=${1}
git_repository=$(echo "${1}" | awk -F : '{ print $2 }')
BASTILLE_TEMPLATE_USER=$(echo "${git_repository}" | awk -F / '{ print $1 }')
BASTILLE_TEMPLATE_REPO=$(echo "${git_repository}" | awk -F / '{ print $2 }')
bootstrap_template
;;
#adding Ubuntu Bionic as valid "RELEASE" for POC @hackacad
ubuntu_bionic|bionic|ubuntu-bionic)
PLATFORM_OS="Ubuntu/Linux"
LINUX_FLAVOR="bionic"
DIR_BOOTSTRAP="Ubuntu_1804"
ARCH_BOOTSTRAP=${HW_MACHINE_ARCH_LINUX}
debootstrap_release
;;
ubuntu_focal|focal|ubuntu-focal)
PLATFORM_OS="Ubuntu/Linux"
LINUX_FLAVOR="focal"
DIR_BOOTSTRAP="Ubuntu_2004"
ARCH_BOOTSTRAP=${HW_MACHINE_ARCH_LINUX}
debootstrap_release
;;
ubuntu_jammy|jammy|ubuntu-jammy)
PLATFORM_OS="Ubuntu/Linux"
LINUX_FLAVOR="jammy"
DIR_BOOTSTRAP="Ubuntu_2204"
ARCH_BOOTSTRAP=${HW_MACHINE_ARCH_LINUX}
debootstrap_release
;;
debian_buster|buster|debian-buster)
PLATFORM_OS="Debian/Linux"
LINUX_FLAVOR="buster"
DIR_BOOTSTRAP="Debian10"
ARCH_BOOTSTRAP=${HW_MACHINE_ARCH_LINUX}
debootstrap_release
;;
debian_bullseye|bullseye|debian-bullseye)
PLATFORM_OS="Debian/Linux"
LINUX_FLAVOR="bullseye"
DIR_BOOTSTRAP="Debian11"
ARCH_BOOTSTRAP=${HW_MACHINE_ARCH_LINUX}
debootstrap_release
;;
debian_bookworm|bookworm|debian-bookworm)
PLATFORM_OS="Debian/Linux"
LINUX_FLAVOR="bookworm"
DIR_BOOTSTRAP="Debian12"
ARCH_BOOTSTRAP=${HW_MACHINE_ARCH_LINUX}
debootstrap_release
;;
*)
echo -e "${COLOR_RED}BETA releases are complete untested.${COLOR_RESET}"
usage
;;
esac
case "${OPTION}" in
update)
bastille update "${RELEASE}"
;;
esac

View File

@@ -0,0 +1,210 @@
#!/bin/sh
#
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
. /usr/local/share/bastille/common.sh
. /usr/local/etc/bastille/bastille.conf
usage() {
error_exit "Usage: bastille clone [TARGET] [NEW_NAME] [IPADRESS]"
}
# Handle special-case commands first
case "$1" in
help|-h|--help)
usage
;;
esac
if [ $# -ne 2 ]; then
usage
fi
bastille_root_check
NEWNAME="${1}"
IP="${2}"
validate_ip() {
IPX_ADDR="ip4.addr"
IP6_MODE="disable"
ip6=$(echo "${IP}" | grep -E '^(([a-fA-F0-9:]+$)|([a-fA-F0-9:]+\/[0-9]{1,3}$))')
if [ -n "${ip6}" ]; then
info "Valid: (${ip6})."
IPX_ADDR="ip6.addr"
IP6_MODE="new"
else
local IFS
if echo "${IP}" | grep -Eq '^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))?$'; then
TEST_IP=$(echo "${IP}" | cut -d / -f1)
IFS=.
set ${TEST_IP}
for quad in 1 2 3 4; do
if eval [ \$$quad -gt 255 ]; then
error_exit "Invalid: (${TEST_IP})"
fi
done
if ifconfig | grep -qwF "${TEST_IP}"; then
warn "Warning: IP address already in use (${TEST_IP})."
else
info "Valid: (${IP})."
fi
else
error_exit "Invalid: (${IP})."
fi
fi
}
update_jailconf() {
# Update jail.conf
JAIL_CONFIG="${bastille_jailsdir}/${NEWNAME}/jail.conf"
if [ -f "${JAIL_CONFIG}" ]; then
if ! grep -qw "path = ${bastille_jailsdir}/${NEWNAME}/root;" "${JAIL_CONFIG}"; then
sed -i '' "s|host.hostname = ${TARGET};|host.hostname = ${NEWNAME};|" "${JAIL_CONFIG}"
sed -i '' "s|exec.consolelog = .*;|exec.consolelog = ${bastille_logsdir}/${NEWNAME}_console.log;|" "${JAIL_CONFIG}"
sed -i '' "s|path = .*;|path = ${bastille_jailsdir}/${NEWNAME}/root;|" "${JAIL_CONFIG}"
sed -i '' "s|mount.fstab = .*;|mount.fstab = ${bastille_jailsdir}/${NEWNAME}/fstab;|" "${JAIL_CONFIG}"
sed -i '' "s|${TARGET} {|${NEWNAME} {|" "${JAIL_CONFIG}"
sed -i '' "s|${IPX_ADDR} = .*;|${IPX_ADDR} = ${IP};|" "${JAIL_CONFIG}"
fi
fi
if grep -qw "vnet;" "${JAIL_CONFIG}"; then
update_jailconf_vnet
fi
}
update_jailconf_vnet() {
bastille_jail_rc_conf="${bastille_jailsdir}/${NEWNAME}/root/etc/rc.conf"
# Determine number of containers and define an uniq_epair
local list_jails_num=$(bastille list jails | wc -l | awk '{print $1}')
local num_range=$(expr "${list_jails_num}" + 1)
jail_list=$(bastille list jail)
for _num in $(seq 0 "${num_range}"); do
if [ -n "${jail_list}" ]; then
if ! grep -q "e0b_bastille${_num}" "${bastille_jailsdir}"/*/jail.conf; then
uniq_epair="bastille${_num}"
# Update the exec.* with uniq_epair when cloning jails.
sed -i '' "s|vnet.interface = e0b_bastille.*;|vnet.interface = e0b_${uniq_epair};|" "${JAIL_CONFIG}"
sed -i '' "s|exec.prestart += \"jib addm bastille[0-9]|exec.prestart += \"jib addm ${uniq_epair}|" "${JAIL_CONFIG}"
sed -i '' "s|exec.prestart += \"ifconfig e0a_bastille[0-9].*|exec.prestart += \"ifconfig e0a_${uniq_epair} description \\\\\"vnet host interface for Bastille jail ${NEWNAME}\\\\\"\";|" "${JAIL_CONFIG}"
sed -i '' "s|exec.poststop += \"jib destroy bastille[0-9]\";|exec.poststop += \"jib destroy ${uniq_epair}\";|" "${JAIL_CONFIG}"
break
fi
fi
done
# Rename interface to new uniq_epair
sed -i '' "s|ifconfig_e0b_bastille.*_name|ifconfig_e0b_${uniq_epair}_name|" "${bastille_jail_rc_conf}"
# If 0.0.0.0 set DHCP, else set static IP address
if [ "${IP}" == "0.0.0.0" ]; then
sysrc -f "${bastille_jail_rc_conf}" ifconfig_vnet0="SYNCDHCP"
else
sysrc -f "${bastille_jail_rc_conf}" ifconfig_vnet0="inet ${IP}"
fi
}
update_fstab() {
# Update fstab to use the new name
FSTAB_CONFIG="${bastille_jailsdir}/${NEWNAME}/fstab"
if [ -f "${FSTAB_CONFIG}" ]; then
FSTAB_RELEASE=$(grep -owE '([1-9]{2,2})\.[0-9](-RELEASE|-RELEASE-i386|-RC[1-9]|-BETA[1-9]|-CURRENT)|([0-9]{1,2}(-stable-build-[0-9]{1,3}|-stable-LAST))|(current-build)-([0-9]{1,3})|(current-BUILD-LATEST)|([0-9]{1,2}-stable-BUILD-LATEST)' "${FSTAB_CONFIG}" | uniq)
FSTAB_CURRENT=$(grep -w ".*/releases/.*/jails/${TARGET}/root/.bastille" "${FSTAB_CONFIG}")
FSTAB_NEWCONF="${bastille_releasesdir}/${FSTAB_RELEASE} ${bastille_jailsdir}/${NEWNAME}/root/.bastille nullfs ro 0 0"
if [ -n "${FSTAB_CURRENT}" ] && [ -n "${FSTAB_NEWCONF}" ]; then
# If both variables are set, update as needed
if ! grep -qw "${bastille_releasesdir}/${FSTAB_RELEASE}.*${bastille_jailsdir}/${NEWNAME}/root/.bastille" "${FSTAB_CONFIG}"; then
sed -i '' "s|${FSTAB_CURRENT}|${FSTAB_NEWCONF}|" "${FSTAB_CONFIG}"
fi
fi
# Update additional fstab paths with new jail path
sed -i '' "s|${bastille_jailsdir}/${TARGET}/root/|${bastille_jailsdir}/${NEWNAME}/root/|" "${FSTAB_CONFIG}"
fi
}
clone_jail() {
# Attempt container clone
info "Attempting to clone '${TARGET}' to ${NEWNAME}..."
if ! [ -d "${bastille_jailsdir}/${NEWNAME}" ]; then
if checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then
# Replicate the existing container
DATE=$(date +%F-%H%M%S)
zfs snapshot -r "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_clone_${DATE}"
zfs send -R "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_clone_${DATE}" | zfs recv "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NEWNAME}"
# Cleanup source temporary snapshots
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}/root@bastille_clone_${DATE}"
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_clone_${DATE}"
# Cleanup target temporary snapshots
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NEWNAME}/root@bastille_clone_${DATE}"
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NEWNAME}@bastille_clone_${DATE}"
fi
else
# Just clone the jail directory
# Check if container is running
if [ -n "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
error_exit "${TARGET} is running. See 'bastille stop ${TARGET}'."
fi
# Perform container file copy(archive mode)
cp -a "${bastille_jailsdir}/${TARGET}" "${bastille_jailsdir}/${NEWNAME}"
fi
else
error_exit "${NEWNAME} already exists."
fi
# Generate jail configuration files
update_jailconf
update_fstab
# Display the exist status
if [ "$?" -ne 0 ]; then
error_exit "An error has occurred while attempting to clone '${TARGET}'."
else
info "Cloned '${TARGET}' to '${NEWNAME}' successfully."
fi
}
## don't allow for dots(.) in container names
if echo "${NEWNAME}" | grep -q "[.]"; then
error_exit "Container names may not contain a dot(.)!"
fi
## check if ip address is valid
if [ -n "${IP}" ]; then
validate_ip
else
usage
fi
clone_jail

View File

@@ -1,22 +1,22 @@
#!/bin/sh
#
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
#
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
#
# Redistribution and use in source and binary forms, with or without
# 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
@@ -28,11 +28,11 @@
# 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/share/bastille/common.sh
. /usr/local/etc/bastille/bastille.conf
usage() {
echo -e "${COLOR_RED}Usage: bastille cmd [ALL|glob] 'quoted command'.${COLOR_RESET}"
exit 1
error_exit "Usage: bastille cmd TARGET command"
}
# Handle special-case commands first.
@@ -42,18 +42,41 @@ help|-h|--help)
;;
esac
if [ $# -gt 2 ] || [ $# -lt 2 ]; then
if [ $# -eq 0 ]; then
usage
fi
if [ "$1" = 'ALL' ]; then
JAILS=$(jls -N name)
fi
if [ "$1" != 'ALL' ]; then
JAILS=$(jls -N name | grep "$1")
fi
bastille_root_check
COUNT=0
RETURN=0
for _jail in ${JAILS}; do
echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}"
jexec -l ${_jail} $2
COUNT=$(($COUNT+1))
info "[${_jail}]:"
if grep -qw "linsysfs" "${bastille_jailsdir}/${_jail}/fstab"; then
# Allow executing commands on Linux jails.
jexec -l -u root "${_jail}" "$@"
else
jexec -l -U root "${_jail}" "$@"
fi
ERROR_CODE=$?
info "[${_jail}]: ${ERROR_CODE}"
if [ "$COUNT" -eq 1 ]; then
RETURN=${ERROR_CODE}
else
RETURN=$(($RETURN+$ERROR_CODE))
fi
echo
done
# Check when a command is executed in all running jails. (bastille cmd ALL ...)
if [ "${COUNT}" -gt 1 ] && [ "${RETURN}" -gt 0 ]; then
RETURN=1
fi
return "${RETURN}"

View File

@@ -1,8 +1,8 @@
#!/bin/sh
#
#
# Copyright (c) 2014-2015 Bryan Drewery <bdrewery@FreeBSD.org>
# All rights reserved.
#
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
@@ -11,7 +11,7 @@
# 2. 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.
#
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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

View File

@@ -0,0 +1,141 @@
#!/bin/sh
#
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
COLOR_RED=
COLOR_GREEN=
COLOR_YELLOW=
COLOR_RESET=
bastille_root_check() {
if [ "$(id -u)" -ne 0 ]; then
## permission denied
error_notify "Bastille: Permission Denied"
error_exit "root / sudo / doas required"
fi
}
enable_color() {
. /usr/local/share/bastille/colors.pre.sh
}
# If "NO_COLOR" environment variable is present, or we aren't speaking to a
# tty, disable output colors.
if [ -z "${NO_COLOR}" -a -t 1 ]; then
enable_color
fi
# Notify message on error, but do not exit
error_notify() {
echo -e "${COLOR_RED}$*${COLOR_RESET}" 1>&2
}
# Notify message on error and exit
error_exit() {
error_notify $@
exit 1
}
info() {
echo -e "${COLOR_GREEN}$*${COLOR_RESET}"
}
warn() {
echo -e "${COLOR_YELLOW}$*${COLOR_RESET}"
}
generate_vnet_jail_netblock() {
local jail_name="$1"
local use_unique_bridge="$2"
local external_interface="$3"
## determine number of containers + 1
## iterate num and grep all jail configs
## define uniq_epair
local jail_list=$(bastille list jails)
if [ -n "${jail_list}" ]; then
# local list_jails_num=$(echo "${jail_list}" | wc -l | awk '{print $1}')
local list_jails_num=$(grep -e "e[0-9]b_bastille" "${bastille_jailsdir}"/*/jail.conf | grep -Eo '(bastille)([0-9]{1,3});' | grep -Eo '[0-9]{1,2}' | sort -hr | head -1 | awk '{print $1}')
local num_range=$((list_jails_num + 1))
for _num in $(seq 0 "${num_range}"); do
if ! grep -q "e[0-9]b_bastille${_num}" "${bastille_jailsdir}"/*/jail.conf; then
if ! grep -q "epair${_num}" "${bastille_jailsdir}"/*/jail.conf; then
local uniq_epair="bastille${_num}"
local uniq_epair_bridge="${_num}"
break
fi
fi
done
else
local uniq_epair="bastille0"
local uniq_epair_bridge="0"
fi
if [ -n "${use_unique_bridge}" ]; then
## generate bridge config
cat <<-EOF
vnet;
vnet.interface = "e${uniq_epair_bridge}b_${jail_name}";
exec.prestart += "ifconfig epair${uniq_epair_bridge} create";
exec.prestart += "ifconfig ${external_interface} addm epair${uniq_epair_bridge}a";
exec.prestart += "ifconfig epair${uniq_epair_bridge}a up name e${uniq_epair_bridge}a_${jail_name}";
exec.prestart += "ifconfig epair${uniq_epair_bridge}b up name e${uniq_epair_bridge}b_${jail_name}";
exec.poststop += "ifconfig ${external_interface} deletem e${uniq_epair_bridge}a_${jail_name}";
exec.poststop += "ifconfig e${uniq_epair_bridge}a_${jail_name} destroy";
EOF
else
## generate config
cat <<-EOF
vnet;
vnet.interface = e0b_${uniq_epair};
exec.prestart += "jib addm ${uniq_epair} ${external_interface}";
exec.prestart += "ifconfig e0a_${uniq_epair} description \'vnet host interface for Bastille jail ${jail_name}\'";
exec.poststop += "jib destroy ${uniq_epair}";
EOF
fi
}
checkyesno() {
## copied from /etc/rc.subr -- cedwards (20231125)
## issue #368 (lowercase values should be parsed)
## now used for all bastille_zfs_enable=YES|NO tests
## example: if checkyesno bastille_zfs_enable; then ...
## returns 0 for enabled; returns 1 for disabled
eval _value=\$${1}
case $_value in
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
return 0
;;
[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0)
return 1
;;
*)
warn "\$${1} is not set properly - see rc.conf(5)."
return 1
;;
esac
}

View File

@@ -0,0 +1,172 @@
#!/bin/sh
#
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
. /usr/local/share/bastille/common.sh
. /usr/local/etc/bastille/bastille.conf
usage() {
error_exit "Usage: bastille config TARGET get|set propertyName [newValue]"
}
# we need jail(8) to parse the config file so it can expand variables etc
print_jail_conf() {
# we need to pass a literal \n to jail to get each parameter on its own
# line
jail -f "$1" -e '
'
}
# Handle special-case commands first.
case "$1" in
help|-h|--help)
usage
;;
esac
if [ $# -eq 1 ] || [ $# -gt 3 ]; then
usage
fi
bastille_root_check
ACTION=$1
shift
case $ACTION in
get)
if [ $# -ne 1 ]; then
error_notify 'Too many parameters for a "get" operation.'
usage
fi
;;
set) ;;
*) error_exit 'Only get and set are supported.' ;;
esac
PROPERTY=$1
shift
VALUE="$@"
for _jail in ${JAILS}; do
FILE="${bastille_jailsdir}/${_jail}/jail.conf"
if [ ! -f "${FILE}" ]; then
error_notify "jail.conf does not exist for jail: ${_jail}"
continue
fi
if [ "${ACTION}" = 'get' ]; then
_output=$(
print_jail_conf "${FILE}" | awk -F= -v property="${PROPERTY}" '
$1 == property {
# note that we have found the property
found = 1;
# check if there is a value for this property
if (NF == 2) {
# remove any quotes surrounding the string
sub(/^"/, "", $2);
sub(/"$/, "", $2);
print $2;
} else {
# no value, just the property name
print "enabled";
}
exit 0;
}
END {
# if we have not found anything we need to print a special
# string
if (! found) {
print("not set");
# let the caller know that this is a warn condition
exit(120);
}
}'
)
# check if our output is a warning or regular
if [ $? -eq 120 ]; then
warn "${_output}"
else
echo "${_output}"
fi
else # Setting the value. -- cwells
if [ -n "${VALUE}" ]; then
VALUE=$(echo "${VALUE}" | sed 's/\//\\\//g')
if echo "${VALUE}" | grep ' ' > /dev/null 2>&1; then # Contains a space, so wrap in quotes. -- cwells
VALUE="'${VALUE}'"
fi
LINE=" ${PROPERTY} = ${VALUE};"
else
LINE=" ${PROPERTY};"
fi
# add the value to the config file, replacing any existing value or, if
# there is none, at the end
#
# awk doesn't have "inplace" editing so we use a temp file
_tmpfile=$(mktemp) || error_exit "unable to set because mktemp failed"
cp "${FILE}" "${_tmpfile}" && \
awk -F= -v line="${LINE}" -v property="${PROPERTY}" '
BEGIN {
# build RE as string as we can not expand vars in RE literals
prop_re = "^[[:space:]]*" property "[[:space:]]*$";
}
$1 ~ prop_re && !found {
# we already have an entry in the config for this property so
# we need to substitute our line here rather than keep the
# existing line
print(line);
# note we have already found the property
found = 1;
# move onto the next line
next;
}
$1 == "}" {
# reached the end of the stanza so if we have not already
# added our line we need to do so now
if (! found) {
print(line);
}
}
{
# print each uninteresting line unchanged
print;
}
' "${_tmpfile}" > "${FILE}"
rm "${_tmpfile}"
fi
done
# Only display this message once at the end (not for every jail). -- cwells
if [ "${ACTION}" = 'set' ]; then
info "A restart is required for the changes to be applied. See 'bastille restart ${TARGET}'."
fi
exit 0

View File

@@ -1,22 +1,22 @@
#!/bin/sh
#
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
#
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
#
# Redistribution and use in source and binary forms, with or without
# 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
@@ -28,11 +28,11 @@
# 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/share/bastille/common.sh
. /usr/local/etc/bastille/bastille.conf
usage() {
echo -e "${COLOR_RED}Usage: bastille console [ALL|glob]'.${COLOR_RESET}"
exit 1
error_exit "Usage: bastille console TARGET [user]"
}
# Handle special-case commands first.
@@ -42,18 +42,49 @@ help|-h|--help)
;;
esac
if [ $# -gt 1 ] || [ $# -lt 1 ]; then
if [ $# -gt 1 ]; then
usage
fi
if [ "$1" = 'ALL' ]; then
JAILS=$(jls -N name)
fi
if [ "$1" != 'ALL' ]; then
JAILS=$(jls -N name | grep "$1")
fi
bastille_root_check
USER="${1}"
validate_user() {
if jexec -l "${_jail}" id "${USER}" >/dev/null 2>&1; then
USER_SHELL="$(jexec -l "${_jail}" getent passwd "${USER}" | cut -d: -f7)"
if [ -n "${USER_SHELL}" ]; then
if jexec -l "${_jail}" grep -qwF "${USER_SHELL}" /etc/shells; then
jexec -l "${_jail}" $LOGIN -f "${USER}"
else
echo "Invalid shell for user ${USER}"
fi
else
echo "User ${USER} has no shell"
fi
else
echo "Unknown user ${USER}"
fi
}
check_fib() {
fib=$(grep 'exec.fib' "${bastille_jailsdir}/${_jail}/jail.conf" | awk '{print $3}' | sed 's/\;//g')
if [ -n "${fib}" ]; then
_setfib="setfib -F ${fib}"
else
_setfib=""
fi
}
for _jail in ${JAILS}; do
echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}"
jexec -l ${_jail} /usr/bin/login -fp root
info "[${_jail}]:"
LOGIN="$(jexec -l "${_jail}" which login)"
if [ -n "${USER}" ]; then
validate_user
else
check_fib
LOGIN="$(jexec -l "${_jail}" which login)"
${_setfib} jexec -l "${_jail}" $LOGIN -f root
fi
echo
done

View File

@@ -0,0 +1,157 @@
#!/bin/sh
#
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
. /usr/local/share/bastille/common.sh
. /usr/local/etc/bastille/bastille.conf
usage() {
error_exit "Usage: bastille convert TARGET"
}
# Handle special-case commands first.
case "$1" in
help|-h|--help)
usage
;;
esac
if [ $# -ne 0 ]; then
usage
fi
bastille_root_check
convert_symlinks() {
# Work with the symlinks, revert on first cp error
if [ -d "${bastille_releasesdir}/${RELEASE}" ]; then
# Retrieve old symlinks temporarily
for _link in ${SYMLINKS}; do
if [ -L "${_link}" ]; then
mv "${_link}" "${_link}.old"
fi
done
# Copy new files to destination jail
info "Copying required base files to container..."
for _link in ${SYMLINKS}; do
if [ ! -d "${_link}" ]; then
if [ -d "${bastille_releasesdir}/${RELEASE}/${_link}" ]; then
cp -a "${bastille_releasesdir}/${RELEASE}/${_link}" "${bastille_jailsdir}/${TARGET}/root/${_link}"
fi
if [ "$?" -ne 0 ]; then
revert_convert
fi
fi
done
# Remove the old symlinks on success
for _link in ${SYMLINKS}; do
if [ -L "${_link}.old" ]; then
rm -r "${_link}.old"
fi
done
else
error_exit "Release must be bootstrapped first. See 'bastille bootstrap'."
fi
}
revert_convert() {
# Revert the conversion on first cp error
error_notify "A problem has occurred while copying the files. Reverting changes..."
for _link in ${SYMLINKS}; do
if [ -d "${_link}" ]; then
chflags -R noschg "${bastille_jailsdir}/${TARGET}/root/${_link}"
rm -rf "${bastille_jailsdir}/${TARGET}/root/${_link}"
fi
done
# Restore previous symlinks
for _link in ${SYMLINKS}; do
if [ -L "${_link}.old" ]; then
mv "${_link}.old" "${_link}"
fi
done
error_exit "Changes for '${TARGET}' has been reverted."
}
start_convert() {
# Attempt container conversion and handle some errors
DATE=$(date)
if [ -d "${bastille_jailsdir}/${TARGET}" ]; then
info "Converting '${TARGET}' into a thickjail. This may take a while..."
# Set some variables
RELEASE=$(grep -w "${bastille_releasesdir}/.* ${bastille_jailsdir}/${TARGET}/root/.bastille" ${bastille_jailsdir}/${TARGET}/fstab | sed "s|${bastille_releasesdir}/||;s| .*||")
FSTABMOD=$(grep -w "${bastille_releasesdir}/${RELEASE} ${bastille_jailsdir}/${TARGET}/root/.bastille" "${bastille_jailsdir}/${TARGET}/fstab")
SYMLINKS="bin boot lib libexec rescue sbin usr/bin usr/include usr/lib usr/lib32 usr/libdata usr/libexec usr/ports usr/sbin usr/share usr/src"
HASPORTS=$(grep -w ${bastille_releasesdir}/${RELEASE}/usr/ports ${bastille_jailsdir}/${TARGET}/fstab)
if [ -n "${RELEASE}" ]; then
cd "${bastille_jailsdir}/${TARGET}/root"
# Work with the symlinks
convert_symlinks
# Comment the line containing .bastille and rename mountpoint
sed -i '' -E "s|${FSTABMOD}|# Converted from thin to thick container on ${DATE}|g" "${bastille_jailsdir}/${TARGET}/fstab"
if [ -n "${HASPORTS}" ]; then
sed -i '' -E "s|${HASPORTS}|# Ports copied from base to container on ${DATE}|g" "${bastille_jailsdir}/${TARGET}/fstab"
info "Copying ports to container..."
cp -a "${bastille_releasesdir}/${RELEASE}/usr/ports" "${bastille_jailsdir}/${TARGET}/root/usr"
fi
mv "${bastille_jailsdir}/${TARGET}/root/.bastille" "${bastille_jailsdir}/${TARGET}/root/.bastille.old"
info "Conversion of '${TARGET}' completed successfully!"
exit 0
else
error_exit "Can't determine release version. See 'bastille bootstrap'."
fi
else
error_exit "${TARGET} not found. See 'bastille create'."
fi
}
# Check if is a thin container
if [ ! -d "${bastille_jailsdir}/${TARGET}/root/.bastille" ]; then
error_exit "${TARGET} is not a thin container."
elif ! grep -qw ".bastille" "${bastille_jailsdir}/${TARGET}/fstab"; then
error_exit "${TARGET} is not a thin container."
fi
# Make sure the user agree with the conversion
# Be interactive here since this cannot be easily undone
while :; do
error_notify "Warning: container conversion from thin to thick can't be undone!"
read -p "Do you really wish to convert '${TARGET}' into a thick container? [y/N]:" yn
case ${yn} in
[Yy]) start_convert;;
[Nn]) exit 0;;
esac
done

View File

@@ -1,22 +1,22 @@
#!/bin/sh
#
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
#
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
#
# Redistribution and use in source and binary forms, with or without
# 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
@@ -28,35 +28,53 @@
# 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/share/bastille/common.sh
. /usr/local/etc/bastille/bastille.conf
usage() {
echo -e "${COLOR_RED}Usage: bastille cp [ALL|glob] '/path/to/source' 'path/to/dest'.${COLOR_RESET}"
exit 1
error_exit "Usage: bastille cp [OPTION] TARGET HOST_PATH CONTAINER_PATH"
}
CPSOURCE="${1}"
CPDEST="${2}"
# Handle special-case commands first.
case "$1" in
help|-h|--help)
usage
;;
-q|--quiet)
OPTION="${1}"
CPSOURCE="${2}"
CPDEST="${3}"
;;
esac
if [ $# -gt 3 ] || [ $# -lt 3 ]; then
if [ $# -ne 2 ]; then
usage
fi
if [ "$1" != 'ALL' ]; then
JAILS=$(jls -N name | grep "$1")
fi
if [ "$1" = 'ALL' ]; then
JAILS=$(jls -N name)
fi
bastille_root_check
case "${OPTION}" in
-q|--quiet)
OPTION="-a"
;;
*)
OPTION="-av"
;;
esac
for _jail in ${JAILS}; do
info "[${_jail}]:"
bastille_jail_path="${bastille_jailsdir}/${_jail}/root"
echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}"
cp -a "$2" "${bastille_jail_path}/$3"
echo -e "${COLOR_RESET}"
cp "${OPTION}" "${CPSOURCE}" "${bastille_jail_path}/${CPDEST}"
RETURN="$?"
if [ "${TARGET}" = "ALL" ]; then
# Display the return status for reference
echo -e "Returned: ${RETURN}\n"
else
echo
return "${RETURN}"
fi
done

File diff suppressed because it is too large Load Diff

View File

@@ -1,22 +1,22 @@
#!/bin/sh
#
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
#
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
#
# Redistribution and use in source and binary forms, with or without
# 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
@@ -28,39 +28,160 @@
# 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/share/bastille/common.sh
. /usr/local/etc/bastille/bastille.conf
usage() {
echo -e "${COLOR_RED}Usage: bastille destroy name.${COLOR_RESET}"
exit 1
error_exit "Usage: bastille destroy [force] | [container|release]"
}
destroy_jail() {
bastille_jail_base="${bastille_jailsdir}/${NAME}" ## dir
bastille_jail_log="${bastille_logsdir}/${NAME}_console.log" ## file
local OPTIONS
bastille_jail_base="${bastille_jailsdir}/${TARGET}" ## dir
bastille_jail_log="${bastille_logsdir}/${TARGET}_console.log" ## file
if [ $(jls -N name | grep ${NAME}) ]; then
echo -e "${COLOR_RED}Jail running.${COLOR_RESET}"
echo -e "${COLOR_RED}See 'bastille stop ${NAME}'.${COLOR_RESET}"
exit 1
if [ "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
if [ "${FORCE}" = "1" ]; then
bastille stop "${TARGET}"
else
error_notify "Jail running."
error_exit "See 'bastille stop ${TARGET}'."
fi
fi
if [ ! -d "${bastille_jail_base}" ]; then
echo -e "${COLOR_RED}Jail not found.${COLOR_RESET}"
exit 1
error_exit "Jail not found."
fi
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}"
info "Deleting Jail: ${TARGET}."
if checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then
if [ -n "${TARGET}" ]; then
OPTIONS="-r"
if [ "${FORCE}" = "1" ]; then
OPTIONS="-rf"
fi
## remove jail zfs dataset recursively
zfs destroy "${OPTIONS}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}"
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
# Remove target from bastille_list if exist
# Mute sysrc output here as it may be undesirable on large startup list
if [ -n "$(sysrc -qn bastille_list | tr -s " " "\n" | awk "/^${TARGET}$/")" ]; then
sysrc bastille_list-="${TARGET}" > /dev/null
fi
## archive jail log
if [ -f "${bastille_jail_log}" ]; then
mv "${bastille_jail_log}" "${bastille_jail_log}"-"$(date +%F)"
info "Note: jail console logs archived."
info "${bastille_jail_log}-$(date +%F)"
fi
## clear any active rdr rules
if [ ! -z "$(pfctl -a "rdr/${TARGET}" -Psn 2>/dev/null)" ]; then
info "Clearing RDR rules:"
pfctl -a "rdr/${TARGET}" -Fn
fi
echo
fi
}
destroy_rel() {
local OPTIONS
## check release name match before destroy
if [ -n "${NAME_VERIFY}" ]; then
TARGET="${NAME_VERIFY}"
else
usage
fi
bastille_rel_base="${bastille_releasesdir}/${TARGET}" ## 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 "${TARGET}" "${bastille_jailsdir}/${_jail}/fstab" 2>/dev/null; then
error_notify "Notice: (${_jail}) depends on ${TARGET} base."
BASE_HASCHILD="1"
elif checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then
## check if this release have child clones
if zfs list -H -t snapshot -r "${bastille_rel_base}" > /dev/null 2>&1; then
SNAP_CLONE=$(zfs list -H -t snapshot -r "${bastille_rel_base}" 2> /dev/null | awk '{print $1}')
for _snap_clone in ${SNAP_CLONE}; do
if zfs list -H -o clones "${_snap_clone}" > /dev/null 2>&1; then
CLONE_JAIL=$(zfs list -H -o clones "${_snap_clone}" | tr ',' '\n')
CLONE_CHECK="${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${_jail}/root"
if echo "${CLONE_JAIL}" | grep -qw "${CLONE_CHECK}"; then
error_notify "Notice: (${_jail}) depends on ${TARGET} base."
BASE_HASCHILD="1"
fi
fi
done
fi
fi
fi
done
fi
if [ ! -d "${bastille_rel_base}" ]; then
error_exit "Release base not found."
else
if [ "${BASE_HASCHILD}" -eq "0" ]; then
info "Deleting base: ${TARGET}"
if checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then
if [ -n "${TARGET}" ]; then
OPTIONS="-r"
if [ "${FORCE}" = "1" ]; then
OPTIONS="-rf"
fi
zfs destroy "${OPTIONS}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${TARGET}"
if [ "${FORCE}" = "1" ]; then
if [ -d "${bastille_cachedir}/${TARGET}" ]; then
zfs destroy "${OPTIONS}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/cache/${TARGET}"
fi
fi
fi
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
if [ "${FORCE}" = "1" ]; then
## remove cache on force
if [ -d "${bastille_cachedir}/${TARGET}" ]; then
rm -rf "${bastille_cachedir}/${TARGET}"
fi
fi
echo
else
error_notify "Cannot destroy base with child containers."
fi
fi
}
# Handle special-case commands first.
case "$1" in
help|-h|--help)
@@ -68,10 +189,78 @@ help|-h|--help)
;;
esac
## reset this options
FORCE=""
## handle additional options
case "${1}" in
-f|--force|force)
FORCE="1"
shift
;;
-*)
error_notify "Unknown Option."
usage
;;
esac
TARGET="${1}"
if [ $# -gt 1 ] || [ $# -lt 1 ]; then
usage
fi
NAME="$1"
bastille_root_check
destroy_jail
## check what should we clean
case "${TARGET}" in
*-CURRENT|*-CURRENT-I386|*-CURRENT-i386|*-current)
## check for FreeBSD releases name
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '^([1-9]{2,2})\.[0-9](-CURRENT|-CURRENT-i386)$' | tr '[:lower:]' '[:upper:]' | sed 's/I/i/g')
destroy_rel
;;
*-RELEASE|*-RELEASE-I386|*-RELEASE-i386|*-release|*-RC[1-9]|*-rc[1-9]|*-BETA[1-9])
## check for FreeBSD releases name
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '^([1-9]{2,2})\.[0-9](-RELEASE|-RELEASE-i386|-RC[1-9]|-BETA[1-9])$' | tr '[:lower:]' '[:upper:]' | sed 's/I/i/g')
destroy_rel
;;
*-stable-LAST|*-STABLE-last|*-stable-last|*-STABLE-LAST)
## check for HardenedBSD releases name
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '^([1-9]{2,2})(-stable-last)$' | sed 's/STABLE/stable/g;s/last/LAST/g')
destroy_rel
;;
*-stable-build-[0-9]*|*-STABLE-BUILD-[0-9]*)
## check for HardenedBSD(specific stable build releases)
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '([0-9]{1,2})(-stable-build)-([0-9]{1,3})$' | sed 's/BUILD/build/g;s/STABLE/stable/g')
destroy_rel
;;
*-stable-build-latest|*-stable-BUILD-LATEST|*-STABLE-BUILD-LATEST)
## check for HardenedBSD(latest stable build release)
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '([0-9]{1,2})(-stable-build-latest)$' | sed 's/STABLE/stable/;s/build/BUILD/g;s/latest/LATEST/g')
destroy_rel
;;
current-build-[0-9]*|CURRENT-BUILD-[0-9]*)
## check for HardenedBSD(specific current build releases)
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '(current-build)-([0-9]{1,3})' | sed 's/BUILD/build/g;s/CURRENT/current/g')
destroy_rel
;;
current-build-latest|current-BUILD-LATEST|CURRENT-BUILD-LATEST)
## check for HardenedBSD(latest current build release)
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '(current-build-latest)$' | sed 's/CURRENT/current/;s/build/BUILD/g;s/latest/LATEST/g')
destroy_rel
;;
Ubuntu_1804|Ubuntu_2004|Ubuntu_2204|UBUNTU_1804|UBUNTU_2004|UBUNTU_2204)
## check for Linux releases
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '(Ubuntu_1804)$|(Ubuntu_2004)$|(Ubuntu_2204)$' | sed 's/UBUNTU/Ubuntu/g;s/ubuntu/Ubuntu/g')
destroy_rel
;;
Debian10|Debian11|Debian12|DEBIAN10|DEBIAN11|DEBIAN12)
## check for Linux releases
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '(Debian10)$|(Debian11)$|(Debian12)$' | sed 's/DEBIAN/Debian/g')
destroy_rel
;;
*)
## just destroy a jail
destroy_jail
;;
esac

View File

@@ -0,0 +1,63 @@
#!/bin/sh
#
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
. /usr/local/share/bastille/common.sh
. /usr/local/etc/bastille/bastille.conf
usage() {
error_exit "Usage: bastille edit TARGET [filename]"
}
# Handle special-case commands first.
case "$1" in
help|-h|--help)
usage
;;
esac
if [ $# -gt 1 ]; then
usage
elif [ $# -eq 1 ]; then
TARGET_FILENAME="${1}"
fi
bastille_root_check
if [ -z "${EDITOR}" ]; then
EDITOR=vi
fi
for _jail in ${JAILS}; do
if [ -n "${TARGET_FILENAME}" ]; then
"${EDITOR}" "${bastille_jailsdir}/${_jail}/${TARGET_FILENAME}"
else
"${EDITOR}" "${bastille_jailsdir}/${_jail}/jail.conf"
fi
done

View File

@@ -0,0 +1,394 @@
#!/bin/sh
#
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
. /usr/local/share/bastille/common.sh
. /usr/local/etc/bastille/bastille.conf
usage() {
# Build an independent usage for the export command
# Valid compress/options for ZFS systems are raw, .gz, .tgz, .txz and .xz
# Valid compress/options for non ZFS configured systems are .tgz and .txz
# If no compression option specified, user must redirect standard output
error_notify "Usage: bastille export | option(s) | TARGET | PATH"
cat << EOF
Options:
--gz -- Export a ZFS jail using GZIP(.gz) compressed image.
-r | --raw -- Export a ZFS jail to an uncompressed RAW image.
-s | --safe -- Safely stop and start a ZFS jail before the exporting process.
--tgz -- Export a jail using simple .tgz compressed archive instead.
--txz -- Export a jail using simple .txz compressed archive instead.
-v | --verbose -- Be more verbose during the ZFS send operation.
--xz -- Export a ZFS jail using XZ(.xz) compressed image.
Note: If no export option specified, the container should be redirected to standard output.
EOF
exit 1
}
# Handle special-case commands first
case "$1" in
help|-h|--help)
usage
;;
esac
# Check for unsupported actions
if [ "${TARGET}" = "ALL" ]; then
error_exit "Batch export is unsupported."
fi
if [ $# -gt 5 ] || [ $# -lt 1 ]; then
usage
fi
bastille_root_check
zfs_enable_check() {
# Temporarily disable ZFS so we can create a standard backup archive
if checkyesno bastille_zfs_enable; then
bastille_zfs_enable="NO"
fi
}
TARGET="${1}"
GZIP_EXPORT=
XZ_EXPORT=
SAFE_EXPORT=
USER_EXPORT=
RAW_EXPORT=
DIR_EXPORT=
TXZ_EXPORT=
TGZ_EXPORT=
OPT_ZSEND="-R"
COMP_OPTION="0"
opt_count() {
COMP_OPTION=$(expr ${COMP_OPTION} + 1)
}
if [ -n "${bastille_export_options}" ]; then
# Overrides the case options by the user defined option(s) automatically.
# Add bastille_export_options="--optionA --optionB" to bastille.conf, or simply `export bastille_export_options="--optionA --optionB"` environment variable.
# To restore the standard case options, empty bastille_export_options="" in bastille.conf, or `unset bastille_export_options` environment variable.
# Reference "/bastille/issues/443"
DEFAULT_EXPORT_OPTS="${bastille_export_options}"
info "Default export option(s): '${DEFAULT_EXPORT_OPTS}'"
for opt in ${DEFAULT_EXPORT_OPTS}; do
case "${opt}" in
--gz)
GZIP_EXPORT="1"
opt_count
shift;;
--xz)
XZ_EXPORT="1"
opt_count
shift;;
--tgz)
TGZ_EXPORT="1"
opt_count
zfs_enable_check
shift;;
--txz)
TXZ_EXPORT="1"
opt_count
zfs_enable_check
shift;;
--safe)
SAFE_EXPORT="1"
shift;;
--raw)
RAW_EXPORT="1"
opt_count
shift ;;
--verbose)
OPT_ZSEND="-Rv"
shift;;
-*|--*) error_notify "Unknown Option."
usage;;
esac
done
else
# Handle and parse option args
while [ $# -gt 0 ]; do
case "${1}" in
--gz)
GZIP_EXPORT="1"
TARGET="${2}"
opt_count
shift
;;
--xz)
XZ_EXPORT="1"
TARGET="${2}"
opt_count
shift
;;
--tgz)
TGZ_EXPORT="1"
TARGET="${2}"
opt_count
zfs_enable_check
shift
;;
--txz)
TXZ_EXPORT="1"
TARGET="${2}"
opt_count
zfs_enable_check
shift
;;
-s|--safe)
SAFE_EXPORT="1"
TARGET="${2}"
shift
;;
-r|--raw)
RAW_EXPORT="1"
TARGET="${2}"
opt_count
shift
;;
-v|--verbose)
OPT_ZSEND="-Rv"
TARGET="${2}"
shift
;;
-*|--*)
error_notify "Unknown Option."
usage
;;
*)
if echo "${1}" | grep -q "\/"; then
DIR_EXPORT="${1}"
else
if [ $# -gt 2 ] || [ $# -lt 1 ]; then
usage
fi
fi
shift
;;
esac
done
fi
# Validate for combined options
if [ "${COMP_OPTION}" -gt "1" ]; then
error_exit "Error: Only one compression format can be used during export."
fi
if [ -n "${TXZ_EXPORT}" -o -n "${TGZ_EXPORT}" ] && [ -n "${SAFE_EXPORT}" ]; then
error_exit "Error: Simple archive modes with safe ZFS export can't be used together."
fi
if ! checkyesno bastille_zfs_enable; then
if [ -n "${GZIP_EXPORT}" -o -n "${RAW_EXPORT}" -o -n "${SAFE_EXPORT}" -o "${OPT_ZSEND}" = "-Rv" ]; then
error_exit "Options --gz, --raw, --safe, --verbose are valid for ZFS configured systems only."
fi
fi
if [ -n "${SAFE_EXPORT}" ]; then
# Check if container is running, otherwise just ignore
if [ -z "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
SAFE_EXPORT=
fi
fi
# Export directory check
if [ -n "${DIR_EXPORT}" ]; then
if [ -d "${DIR_EXPORT}" ]; then
# Set the user defined export directory
bastille_backupsdir="${DIR_EXPORT}"
else
error_exit "Error: Path not found."
fi
fi
# Fallback to default if missing config parameters
if [ -z "${bastille_compress_xz_options}" ]; then
bastille_compress_xz_options="-0 -v"
fi
if [ -z "${bastille_compress_gz_options}" ]; then
bastille_compress_gz_options="-1 -v"
fi
create_zfs_snap() {
# Take a recursive temporary snapshot
if [ -z "${USER_EXPORT}" ]; then
info "Creating temporary ZFS snapshot for export..."
fi
zfs snapshot -r "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_${TARGET}_${DATE}"
}
clean_zfs_snap() {
# Cleanup the recursive temporary snapshot
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}/root@bastille_${TARGET}_${DATE}"
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_${TARGET}_${DATE}"
}
export_check() {
# Inform the user about the exporting method
if [ -z "${USER_EXPORT}" ]; then
if [ -n "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
if [ -n "${SAFE_EXPORT}" ]; then
EXPORT_AS="Safely exporting"
else
EXPORT_AS="Hot exporting"
fi
else
EXPORT_AS="Exporting"
fi
if [ "${FILE_EXT}" = ".xz" -o "${FILE_EXT}" = ".gz" -o "${FILE_EXT}" = "" ]; then
EXPORT_TYPE="image"
else
EXPORT_TYPE="archive"
fi
if [ -n "${RAW_EXPORT}" ]; then
EXPORT_INFO="to a raw ${EXPORT_TYPE}"
else
EXPORT_INFO="to a compressed ${FILE_EXT} ${EXPORT_TYPE}"
fi
info "${EXPORT_AS} '${TARGET}' ${EXPORT_INFO}..."
fi
# Safely stop and snapshot the jail
if [ -n "${SAFE_EXPORT}" ]; then
bastille stop ${TARGET}
create_zfs_snap
bastille start ${TARGET}
else
create_zfs_snap
fi
if checkyesno bastille_zfs_enable; then
if [ -z "${USER_EXPORT}" ]; then
info "Sending ZFS data stream..."
fi
fi
}
jail_export() {
# Attempt to export the container
DATE=$(date +%F-%H%M%S)
if checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then
if [ -n "${RAW_EXPORT}" ]; then
FILE_EXT=""
export_check
# Export the raw container recursively and cleanup temporary snapshots
zfs send ${OPT_ZSEND} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_${TARGET}_${DATE}" \
> "${bastille_backupsdir}/${TARGET}_${DATE}"
clean_zfs_snap
elif [ -n "${GZIP_EXPORT}" ]; then
FILE_EXT=".gz"
export_check
# Export the raw container recursively and cleanup temporary snapshots
zfs send ${OPT_ZSEND} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_${TARGET}_${DATE}" | \
gzip ${bastille_compress_gz_options} > "${bastille_backupsdir}/${TARGET}_${DATE}${FILE_EXT}"
clean_zfs_snap
elif [ -n "${XZ_EXPORT}" ]; then
FILE_EXT=".xz"
export_check
# Export the container recursively and cleanup temporary snapshots
zfs send ${OPT_ZSEND} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_${TARGET}_${DATE}" | \
xz ${bastille_compress_xz_options} > "${bastille_backupsdir}/${TARGET}_${DATE}${FILE_EXT}"
clean_zfs_snap
else
FILE_EXT=""
USER_EXPORT="1"
export_check
# Quietly export the container recursively, user must redirect standard output
if ! zfs send ${OPT_ZSEND} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_${TARGET}_${DATE}"; then
clean_zfs_snap
error_notify "\nError: An export option is required, see 'bastille export, otherwise the user must redirect to standard output."
fi
fi
fi
else
if [ -n "${TGZ_EXPORT}" ]; then
FILE_EXT=".tgz"
# Create standard tgz backup archive
info "Exporting '${TARGET}' to a compressed ${FILE_EXT} archive..."
cd "${bastille_jailsdir}" && tar -cf - "${TARGET}" | gzip ${bastille_compress_gz_options} > "${bastille_backupsdir}/${TARGET}_${DATE}${FILE_EXT}"
elif [ -n "${TXZ_EXPORT}" ]; then
FILE_EXT=".txz"
# Create standard txz backup archive
info "Exporting '${TARGET}' to a compressed ${FILE_EXT} archive..."
cd "${bastille_jailsdir}" && tar -cf - "${TARGET}" | xz ${bastille_compress_xz_options} > "${bastille_backupsdir}/${TARGET}_${DATE}${FILE_EXT}"
else
error_exit "Error: export option required"
fi
fi
if [ "$?" -ne 0 ]; then
error_exit "Failed to export '${TARGET}' container."
else
if [ -z "${USER_EXPORT}" ]; then
# Generate container checksum file
cd "${bastille_backupsdir}"
sha256 -q "${TARGET}_${DATE}${FILE_EXT}" > "${TARGET}_${DATE}.sha256"
info "Exported '${bastille_backupsdir}/${TARGET}_${DATE}${FILE_EXT}' successfully."
fi
exit 0
fi
}
# Check if backups directory/dataset exist
if [ ! -d "${bastille_backupsdir}" ]; then
error_exit "Backups directory/dataset does not exist. See 'bastille bootstrap'."
fi
if [ -n "${TARGET}" ]; then
if [ ! -d "${bastille_jailsdir}/${TARGET}" ]; then
error_exit "[${TARGET}]: Not found."
fi
# Check if is a ZFS system
if ! checkyesno bastille_zfs_enable; then
# Check if container is running and ask for stop in non ZFS systems
if [ -n "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
error_exit "${TARGET} is running. See 'bastille stop'."
fi
fi
jail_export
fi

View File

@@ -1,49 +0,0 @@
#!/bin/sh
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=/usr/local/bastille/cache/$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."

View File

@@ -1,22 +1,22 @@
#!/bin/sh
#
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
#
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
#
# Redistribution and use in source and binary forms, with or without
# 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
@@ -28,12 +28,11 @@
# 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/share/bastille/common.sh
. /usr/local/etc/bastille/bastille.conf
usage() {
echo -e "${COLOR_RED}Usage: bastille htop [ALL|glob]'.${COLOR_RESET}"
exit 1
error_exit "Usage: bastille htop TARGET"
}
# Handle special-case commands first.
@@ -43,26 +42,19 @@ help|-h|--help)
;;
esac
if [ $# -gt 1 ] || [ $# -lt 1 ]; then
if [ $# -ne 0 ]; then
usage
fi
if [ "$1" = 'ALL' ]; then
JAILS=$(jls -N name)
fi
if [ "$1" != 'ALL' ]; then
JAILS=$(jls -N name | grep "$1")
fi
bastille_root_check
for _jail in ${JAILS}; do
if [ ! -x "${bastille_jailsdir}/${_jail}/root/usr/local/bin/htop" ]; then
echo -e "${COLOR_RED}htop not found on ${_jail}.${COLOR_RESET}"
fi
if [ -x "${bastille_jailsdir}/${_jail}/root/usr/local/bin/htop" ]; then
echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}"
bastille_jail_path=$(/usr/sbin/jls -j "${_jail}" path)
if [ ! -x "${bastille_jail_path}/usr/local/bin/htop" ]; then
error_notify "htop not found on ${_jail}."
elif [ -x "${bastille_jail_path}/usr/local/bin/htop" ]; then
info "[${_jail}]:"
jexec -l ${_jail} /usr/local/bin/htop
fi
echo -e "${COLOR_RESET}"
done
TERM=${SAVED_TERM}

View File

@@ -0,0 +1,640 @@
#!/bin/sh
#
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
. /usr/local/share/bastille/common.sh
. /usr/local/etc/bastille/bastille.conf
usage() {
# Build an independent usage for the import command
# If no file/extension specified, will import from standard input
error_notify "Usage: bastille import [option(s)] FILE"
cat << EOF
Options:
-f | --force -- Force an archive import regardless if the checksum file does not match or missing.
-v | --verbose -- Be more verbose during the ZFS receive operation.
Tip: If no option specified, container should be imported from standard input.
EOF
exit 1
}
# Handle special-case commands first
case "$1" in
help|-h|--help)
usage
;;
esac
if [ $# -gt 3 ] || [ $# -lt 1 ]; then
usage
fi
bastille_root_check
TARGET="${1}"
OPT_FORCE=
USER_IMPORT=
OPT_ZRECV="-u"
# Handle and parse option args
while [ $# -gt 0 ]; do
case "${1}" in
-f|--force)
OPT_FORCE="1"
TARGET="${2}"
shift
;;
-v|--verbose)
OPT_ZRECV="-u -v"
TARGET="${2}"
shift
;;
-*|--*)
error_notify "Unknown Option."
usage
;;
*)
if [ $# -gt 1 ] || [ $# -lt 1 ]; then
usage
fi
shift
;;
esac
done
# Fallback to default if missing config parameters
if [ -z "${bastille_decompress_xz_options}" ]; then
bastille_decompress_xz_options="-c -d -v"
fi
if [ -z "${bastille_decompress_gz_options}" ]; then
bastille_decompress_gz_options="-k -d -c -v"
fi
validate_archive() {
# Compare checksums on the target archive
# Skip validation for unsupported archive
if [ -f "${bastille_backupsdir}/${TARGET}" ]; then
if [ -f "${bastille_backupsdir}/${FILE_TRIM}.sha256" ]; then
info "Validating file: ${TARGET}..."
SHA256_DIST=$(cat "${bastille_backupsdir}/${FILE_TRIM}.sha256")
SHA256_FILE=$(sha256 -q "${bastille_backupsdir}/${TARGET}")
if [ "${SHA256_FILE}" != "${SHA256_DIST}" ]; then
error_exit "Failed validation for ${TARGET}."
else
info "File validation successful!"
fi
else
# Check if user opt to force import
if [ -n "${OPT_FORCE}" ]; then
warn "Warning: Skipping archive validation!"
else
error_exit "Checksum file not found. See 'bastille import [option(s)] FILE'."
fi
fi
fi
}
update_zfsmount() {
# Update the mountpoint property on the received ZFS data stream
OLD_ZFS_MOUNTPOINT=$(zfs get -H mountpoint "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}/root" | awk '{print $3}')
NEW_ZFS_MOUNTPOINT="${bastille_jailsdir}/${TARGET_TRIM}/root"
if [ "${NEW_ZFS_MOUNTPOINT}" != "${OLD_ZFS_MOUNTPOINT}" ]; then
info "Updating ZFS mountpoint..."
zfs set mountpoint="${bastille_jailsdir}/${TARGET_TRIM}/root" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}/root"
fi
# Mount new container ZFS datasets
if ! zfs mount | grep -qw "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}$"; then
zfs mount "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}"
fi
if ! zfs mount | grep -qw "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}/root$"; then
zfs mount "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}/root"
fi
}
update_jailconf() {
# Update jail.conf paths
JAIL_CONFIG="${bastille_jailsdir}/${TARGET_TRIM}/jail.conf"
if [ -f "${JAIL_CONFIG}" ]; then
if ! grep -qw "path = ${bastille_jailsdir}/${TARGET_TRIM}/root;" "${JAIL_CONFIG}"; then
info "Updating jail.conf..."
sed -i '' "s|exec.consolelog.*=.*;|exec.consolelog = ${bastille_logsdir}/${TARGET_TRIM}_console.log;|" "${JAIL_CONFIG}"
sed -i '' "s|path.*=.*;|path = ${bastille_jailsdir}/${TARGET_TRIM}/root;|" "${JAIL_CONFIG}"
sed -i '' "s|mount.fstab.*=.*;|mount.fstab = ${bastille_jailsdir}/${TARGET_TRIM}/fstab;|" "${JAIL_CONFIG}"
fi
# Check for the jib script
if grep -qw "vnet" "${JAIL_CONFIG}"; then
vnet_requirements
fi
fi
}
update_fstab() {
# Update fstab .bastille mountpoint on thin containers only
# Set some variables
FSTAB_CONFIG="${bastille_jailsdir}/${TARGET_TRIM}/fstab"
FSTAB_RELEASE=$(grep -owE '([1-9]{2,2})\.[0-9](-RELEASE|-RELEASE-i386|-RC[1-9])|([0-9]{1,2}-stable-build-[0-9]{1,3})|(current-build)-([0-9]{1,3})|(current-BUILD-LATEST)|([0-9]{1,2}-stable-BUILD-LATEST)|(current-BUILD-LATEST)' "${FSTAB_CONFIG}")
FSTAB_CURRENT=$(grep -w ".*/releases/.*/jails/${TARGET_TRIM}/root/.bastille" "${FSTAB_CONFIG}")
FSTAB_NEWCONF="${bastille_releasesdir}/${FSTAB_RELEASE} ${bastille_jailsdir}/${TARGET_TRIM}/root/.bastille nullfs ro 0 0"
if [ -n "${FSTAB_CURRENT}" ] && [ -n "${FSTAB_NEWCONF}" ]; then
# If both variables are set, compare and update as needed
if ! grep -qw "${bastille_releasesdir}/${FSTAB_RELEASE}.*${bastille_jailsdir}/${TARGET_TRIM}/root/.bastille" "${FSTAB_CONFIG}"; then
info "Updating fstab..."
sed -i '' "s|${FSTAB_CURRENT}|${FSTAB_NEWCONF}|" "${FSTAB_CONFIG}"
fi
fi
}
generate_config() {
# Attempt to read previous config file and set required variables accordingly
# If we can't get a valid interface, fallback to lo1 and warn user
info "Generating jail.conf..."
DEVFS_RULESET=4
if [ "${FILE_EXT}" = ".zip" ]; then
# Gather some bits from foreign/iocage config files
JSON_CONFIG="${bastille_jailsdir}/${TARGET_TRIM}/config.json"
if [ -n "${JSON_CONFIG}" ]; then
IPV4_CONFIG=$(grep -wo '\"ip4_addr\": \".*\"' "${JSON_CONFIG}" | tr -d '" ' | sed 's/ip4_addr://')
IPV6_CONFIG=$(grep -wo '\"ip6_addr\": \".*\"' "${JSON_CONFIG}" | tr -d '" ' | sed 's/ip6_addr://')
DEVFS_RULESET=$(grep -wo '\"devfs_ruleset\": \".*\"' "${JSON_CONFIG}" | tr -d '" ' | sed 's/devfs_ruleset://')
DEVFS_RULESET=${DEVFS_RULESET:-4}
IS_THIN_JAIL=$(grep -wo '\"basejail\": .*' "${JSON_CONFIG}" | tr -d '" ,' | sed 's/basejail://')
CONFIG_RELEASE=$(grep -wo '\"release\": \".*\"' "${JSON_CONFIG}" | tr -d '" ' | sed 's/release://' | sed 's/\-[pP].*//')
IS_VNET_JAIL=$(grep -wo '\"vnet\": .*' "${JSON_CONFIG}" | tr -d '" ,' | sed 's/vnet://')
VNET_DEFAULT_INTERFACE=$(grep -wo '\"vnet_default_interface\": \".*\"' "${JSON_CONFIG}" | tr -d '" ' | sed 's/vnet_default_interface://')
ALLOW_EMPTY_DIRS_TO_BE_SYMLINKED=1
if [ "${VNET_DEFAULT_INTERFACE}" = "auto" ]; then
# Grab the default ipv4 route from netstat and pull out the interface
VNET_DEFAULT_INTERFACE=$(netstat -nr4 | grep default | cut -w -f 4)
fi
fi
elif [ "${FILE_EXT}" = ".tar.gz" ]; then
# Gather some bits from foreign/ezjail config files
PROP_CONFIG="${bastille_jailsdir}/${TARGET_TRIM}/prop.ezjail-${FILE_TRIM}-*"
if [ -n "${PROP_CONFIG}" ]; then
IPVX_CONFIG=$(grep -wo "jail_${TARGET_TRIM}_ip=.*" ${PROP_CONFIG} | tr -d '" ' | sed "s/jail_${TARGET_TRIM}_ip=//")
CONFIG_RELEASE=$(echo ${PROP_CONFIG} | grep -o '[0-9]\{2\}\.[0-9]_RELEASE' | sed 's/_/-/g')
fi
# Always assume it's thin for ezjail
IS_THIN_JAIL=1
fi
# See if we need to generate a vnet network section
if [ "${IS_VNET_JAIL:-0}" = "1" ]; then
NETBLOCK=$(generate_vnet_jail_netblock "${TARGET_TRIM}" "" "${VNET_DEFAULT_INTERFACE}")
vnet_requirements
else
# If there are multiple IP/NIC let the user configure network
if [ -n "${IPV4_CONFIG}" ]; then
if ! echo "${IPV4_CONFIG}" | grep -q '.*,.*'; then
NETIF_CONFIG=$(echo "${IPV4_CONFIG}" | grep '.*|' | sed 's/|.*//g')
if [ -z "${NETIF_CONFIG}" ]; then
config_netif
fi
IPX_ADDR="ip4.addr"
IP_CONFIG="${IPV4_CONFIG}"
IP6_MODE="disable"
fi
elif [ -n "${IPV6_CONFIG}" ]; then
if ! echo "${IPV6_CONFIG}" | grep -q '.*,.*'; then
NETIF_CONFIG=$(echo "${IPV6_CONFIG}" | grep '.*|' | sed 's/|.*//g')
if [ -z "${NETIF_CONFIG}" ]; then
config_netif
fi
IPX_ADDR="ip6.addr"
IP_CONFIG="${IPV6_CONFIG}"
IP6_MODE="new"
fi
elif [ -n "${IPVX_CONFIG}" ]; then
if ! echo "${IPVX_CONFIG}" | grep -q '.*,.*'; then
NETIF_CONFIG=$(echo "${IPVX_CONFIG}" | grep '.*|' | sed 's/|.*//g')
if [ -z "${NETIF_CONFIG}" ]; then
config_netif
fi
IPX_ADDR="ip4.addr"
IP_CONFIG="${IPVX_CONFIG}"
IP6_MODE="disable"
if echo "${IPVX_CONFIG}" | sed 's/.*|//' | grep -Eq '^(([a-fA-F0-9:]+$)|([a-fA-F0-9:]+\/[0-9]{1,3}$))'; then
IPX_ADDR="ip6.addr"
IP6_MODE="new"
fi
fi
fi
# Let the user configure network manually
if [ -z "${NETIF_CONFIG}" ]; then
NETIF_CONFIG="lo1"
IPX_ADDR="ip4.addr"
IP_CONFIG="-"
IP6_MODE="disable"
warn "Warning: See 'bastille edit ${TARGET_TRIM} jail.conf' for manual network configuration."
fi
NETBLOCK=$(cat <<-EOF
interface = ${NETIF_CONFIG};
${IPX_ADDR} = ${IP_CONFIG};
ip6 = ${IP6_MODE};
EOF
)
fi
if [ "${IS_THIN_JAIL:-0}" = "1" ]; then
if [ -z "${CONFIG_RELEASE}" ]; then
# Fallback to host version
CONFIG_RELEASE=$(freebsd-version | sed 's/\-[pP].*//')
warn "Warning: ${CONFIG_RELEASE} was set by default!"
fi
mkdir "${bastille_jailsdir}/${TARGET_TRIM}/root/.bastille"
echo "${bastille_releasesdir}/${CONFIG_RELEASE} ${bastille_jailsdir}/${TARGET_TRIM}/root/.bastille nullfs ro 0 0" \
>> "${bastille_jailsdir}/${TARGET_TRIM}/fstab"
# Work with the symlinks
cd "${bastille_jailsdir}/${TARGET_TRIM}/root"
update_symlinks
else
# Generate new empty fstab file
touch "${bastille_jailsdir}/${TARGET_TRIM}/fstab"
fi
# Generate a basic jail configuration file on foreign imports
cat << EOF > "${bastille_jailsdir}/${TARGET_TRIM}/jail.conf"
${TARGET_TRIM} {
devfs_ruleset = ${DEVFS_RULESET};
enforce_statfs = 2;
exec.clean;
exec.consolelog = ${bastille_logsdir}/${TARGET_TRIM}_console.log;
exec.start = '/bin/sh /etc/rc';
exec.stop = '/bin/sh /etc/rc.shutdown';
host.hostname = ${TARGET_TRIM};
mount.devfs;
mount.fstab = ${bastille_jailsdir}/${TARGET_TRIM}/fstab;
path = ${bastille_jailsdir}/${TARGET_TRIM}/root;
securelevel = 2;
${NETBLOCK}
}
EOF
}
update_config() {
# Update an existing jail configuration
# The config on select archives does not provide a clear way to determine
# the base release, so lets try to get it from the base/COPYRIGHT file,
# otherwise warn user and fallback to host system release
CONFIG_RELEASE=$(grep -wo 'releng/[0-9]\{2\}.[0-9]/COPYRIGHT' "${bastille_jailsdir}/${TARGET_TRIM}/root/COPYRIGHT" | sed 's|releng/||;s|/COPYRIGHT|-RELEASE|')
if [ -z "${CONFIG_RELEASE}" ]; then
# Fallback to host version
CONFIG_RELEASE=$(freebsd-version | sed 's/\-[pP].*//')
warn "Warning: ${CONFIG_RELEASE} was set by default!"
fi
mkdir "${bastille_jailsdir}/${TARGET_TRIM}/root/.bastille"
echo "${bastille_releasesdir}/${CONFIG_RELEASE} ${bastille_jailsdir}/${TARGET_TRIM}/root/.bastille nullfs ro 0 0" \
>> "${bastille_jailsdir}/${TARGET_TRIM}/fstab"
# Work with the symlinks
cd "${bastille_jailsdir}/${TARGET_TRIM}/root"
update_symlinks
}
workout_components() {
if [ "${FILE_EXT}" = ".tar" ]; then
# Workaround to determine the tarball path/components before extract(assumes path/jails/target)
JAIL_PATH=$(tar -tvf ${bastille_backupsdir}/${TARGET} | grep -wo "/.*/jails/${TARGET_TRIM}" | tail -n1)
JAIL_DIRS=$(echo ${JAIL_PATH} | grep -o '/' | wc -l)
DIRS_PLUS=$(expr ${JAIL_DIRS} + 1)
# Workaround to determine the jail.conf path before extract(assumes path/qjail.config/target)
JAIL_CONF=$(tar -tvf ${bastille_backupsdir}/${TARGET} | grep -wo "/.*/qjail.config/${TARGET_TRIM}")
CONF_TRIM=$(echo ${JAIL_CONF} | grep -o '/' | wc -l)
fi
}
vnet_requirements() {
# VNET jib script requirement
if [ ! "$(command -v jib)" ]; then
if [ -f "/usr/share/examples/jails/jib" ] && [ ! -f "/usr/local/bin/jib" ]; then
install -m 0544 /usr/share/examples/jails/jib /usr/local/bin/jib
else
warn "Warning: Unable to locate/install jib script required by VNET jails."
fi
fi
}
config_netif() {
# Get interface from bastille configuration
if [ -n "${bastille_network_loopback}" ]; then
NETIF_CONFIG="${bastille_network_loopback}"
elif [ -n "${bastille_network_shared}" ]; then
NETIF_CONFIG="${bastille_network_shared}"
else
NETIF_CONFIG=
fi
}
update_symlinks() {
# Work with the symlinks
SYMLINKS="bin boot lib libexec rescue sbin usr/bin usr/include usr/lib usr/lib32 usr/libdata usr/libexec usr/ports usr/sbin usr/share usr/src"
# Just warn user to bootstrap the release if missing
if [ ! -d "${bastille_releasesdir}/${CONFIG_RELEASE}" ]; then
warn "Warning: ${CONFIG_RELEASE} must be bootstrapped. See 'bastille bootstrap'."
fi
# Update old symlinks
info "Updating symlinks..."
for _link in ${SYMLINKS}; do
if [ -L "${_link}" ]; then
ln -sf /.bastille/${_link} ${_link}
elif [ "${ALLOW_EMPTY_DIRS_TO_BE_SYMLINKED:-0}" = "1" -a -d "${_link}" ]; then
# -F will enforce that the directory is empty and replaced by the symlink
ln -sfF /.bastille/${_link} ${_link} || EXIT_CODE=$?
if [ "${EXIT_CODE:-0}" != "0" ]; then
# Assume that the failure was due to the directory not being empty and explain the problem in friendlier terms
warn "Warning: directory ${_link} on imported jail was not empty and will not be updated by Bastille"
fi
fi
done
}
create_zfs_datasets() {
# Prepare the ZFS environment and restore from file
info "Importing '${TARGET_TRIM}' from foreign compressed ${FILE_EXT} archive."
info "Preparing ZFS environment..."
# Create required ZFS datasets, mountpoint inherited from system
zfs create ${bastille_zfs_options} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}"
zfs create ${bastille_zfs_options} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}/root"
}
remove_zfs_datasets() {
# Perform cleanup on failure
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}/root"
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}"
error_exit "Failed to extract files from '${TARGET}' archive."
}
jail_import() {
# Attempt to import container from file
FILE_TRIM=$(echo "${TARGET}" | sed 's/\.xz//g;s/\.gz//g;s/\.tgz//g;s/\.txz//g;s/\.zip//g;s/\.tar\.gz//g;s/\.tar//g')
FILE_EXT=$(echo "${TARGET}" | sed "s/${FILE_TRIM}//g")
if [ -d "${bastille_jailsdir}" ]; then
if checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then
if [ "${FILE_EXT}" = ".xz" ]; then
validate_archive
# Import from compressed xz on ZFS systems
info "Importing '${TARGET_TRIM}' from compressed ${FILE_EXT} image."
info "Receiving ZFS data stream..."
xz ${bastille_decompress_xz_options} "${bastille_backupsdir}/${TARGET}" | \
zfs receive ${OPT_ZRECV} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}"
# Update ZFS mountpoint property if required
update_zfsmount
elif [ "${FILE_EXT}" = ".gz" ]; then
validate_archive
# Import from compressed xz on ZFS systems
info "Importing '${TARGET_TRIM}' from compressed ${FILE_EXT} image."
info "Receiving ZFS data stream..."
gzip ${bastille_decompress_gz_options} "${bastille_backupsdir}/${TARGET}" | \
zfs receive ${OPT_ZRECV} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}"
# Update ZFS mountpoint property if required
update_zfsmount
elif [ "${FILE_EXT}" = ".txz" ]; then
validate_archive
# Prepare the ZFS environment and restore from existing .txz file
create_zfs_datasets
# Extract required files to the new datasets
info "Extracting files from '${TARGET}' archive..."
tar --exclude='root' -Jxf "${bastille_backupsdir}/${TARGET}" --strip-components 1 -C "${bastille_jailsdir}/${TARGET_TRIM}"
tar -Jxf "${bastille_backupsdir}/${TARGET}" --strip-components 2 -C "${bastille_jailsdir}/${TARGET_TRIM}/root" "${TARGET_TRIM}/root"
if [ "$?" -ne 0 ]; then
remove_zfs_datasets
fi
elif [ "${FILE_EXT}" = ".tgz" ]; then
validate_archive
# Prepare the ZFS environment and restore from existing .tgz file
create_zfs_datasets
# Extract required files to the new datasets
info "Extracting files from '${TARGET}' archive..."
tar --exclude='root' -xf "${bastille_backupsdir}/${TARGET}" --strip-components 1 -C "${bastille_jailsdir}/${TARGET_TRIM}"
tar -xf "${bastille_backupsdir}/${TARGET}" --strip-components 2 -C "${bastille_jailsdir}/${TARGET_TRIM}/root" "${TARGET_TRIM}/root"
if [ "$?" -ne 0 ]; then
remove_zfs_datasets
fi
elif [ "${FILE_EXT}" = ".zip" ]; then
validate_archive
# Attempt to import a foreign/iocage container
info "Importing '${TARGET_TRIM}' from foreign compressed ${FILE_EXT} archive."
# Sane bastille ZFS options
ZFS_OPTIONS=$(echo ${bastille_zfs_options} | sed 's/-o//g')
# Extract required files from the zip archive
cd "${bastille_backupsdir}" && unzip -j "${TARGET}"
if [ "$?" -ne 0 ]; then
error_exit "Failed to extract files from '${TARGET}' archive."
rm -f "${FILE_TRIM}" "${FILE_TRIM}_root"
fi
info "Receiving ZFS data stream..."
zfs receive ${OPT_ZRECV} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}" < "${FILE_TRIM}"
zfs set ${ZFS_OPTIONS} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}"
zfs receive ${OPT_ZRECV} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}/root" < "${FILE_TRIM}_root"
# Update ZFS mountpoint property if required
update_zfsmount
# Keep old configuration files for user reference
if [ -f "${bastille_jailsdir}/${TARGET_TRIM}/fstab" ]; then
mv "${bastille_jailsdir}/${TARGET_TRIM}/fstab" "${bastille_jailsdir}/${TARGET_TRIM}/fstab.old"
fi
# Cleanup unwanted files
rm -f "${FILE_TRIM}" "${FILE_TRIM}_root"
# Generate fstab and jail.conf files
generate_config
elif [ "${FILE_EXT}" = ".tar.gz" ]; then
# Attempt to import a foreign/ezjail container
# Prepare the ZFS environment and restore from existing .tar.gz file
create_zfs_datasets
# Extract required files to the new datasets
info "Extracting files from '${TARGET}' archive..."
tar --exclude='ezjail/' -xf "${bastille_backupsdir}/${TARGET}" -C "${bastille_jailsdir}/${TARGET_TRIM}"
tar -xf "${bastille_backupsdir}/${TARGET}" --strip-components 1 -C "${bastille_jailsdir}/${TARGET_TRIM}/root"
if [ "$?" -ne 0 ]; then
remove_zfs_datasets
else
generate_config
fi
elif [ "${FILE_EXT}" = ".tar" ]; then
# Attempt to import a foreign/qjail container
# Prepare the ZFS environment and restore from existing .tar file
create_zfs_datasets
workout_components
# Extract required files to the new datasets
info "Extracting files from '${TARGET}' archive..."
tar -xf "${bastille_backupsdir}/${TARGET}" --strip-components "${CONF_TRIM}" -C "${bastille_jailsdir}/${TARGET_TRIM}" "${JAIL_CONF}"
tar -xf "${bastille_backupsdir}/${TARGET}" --strip-components "${DIRS_PLUS}" -C "${bastille_jailsdir}/${TARGET_TRIM}/root" "${JAIL_PATH}"
if [ -f "${bastille_jailsdir}/${TARGET_TRIM}/${TARGET_TRIM}" ]; then
mv "${bastille_jailsdir}/${TARGET_TRIM}/${TARGET_TRIM}" "${bastille_jailsdir}/${TARGET_TRIM}/jail.conf"
fi
if [ "$?" -ne 0 ]; then
remove_zfs_datasets
else
update_config
fi
elif [ -z "${FILE_EXT}" ]; then
if echo "${TARGET}" | grep -q '_[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}-[0-9]\{6\}$'; then
validate_archive
# Based on the file name, looks like we are importing a raw bastille image
# Import from uncompressed image file
info "Importing '${TARGET_TRIM}' from uncompressed image archive."
info "Receiving ZFS data stream..."
zfs receive ${OPT_ZRECV} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}" < "${bastille_backupsdir}/${TARGET}"
# Update ZFS mountpoint property if required
update_zfsmount
else
# Based on the file name, looks like we are importing from previous redirected bastille image
# Quietly import from previous redirected bastille image
if ! zfs receive ${OPT_ZRECV} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}"; then
exit 1
else
# Update ZFS mountpoint property if required
update_zfsmount
fi
fi
else
error_exit "Unknown archive format."
fi
fi
else
# Import from standard supported archives on UFS systems
if [ "${FILE_EXT}" = ".txz" ]; then
info "Extracting files from '${TARGET}' archive..."
tar -Jxf "${bastille_backupsdir}/${TARGET}" -C "${bastille_jailsdir}"
elif [ "${FILE_EXT}" = ".tgz" ]; then
info "Extracting files from '${TARGET}' archive..."
tar -xf "${bastille_backupsdir}/${TARGET}" -C "${bastille_jailsdir}"
elif [ "${FILE_EXT}" = ".tar.gz" ]; then
# Attempt to import/configure foreign/ezjail container
info "Extracting files from '${TARGET}' archive..."
mkdir "${bastille_jailsdir}/${TARGET_TRIM}"
tar -xf "${bastille_backupsdir}/${TARGET}" -C "${bastille_jailsdir}/${TARGET_TRIM}"
mv "${bastille_jailsdir}/${TARGET_TRIM}/ezjail" "${bastille_jailsdir}/${TARGET_TRIM}/root"
generate_config
elif [ "${FILE_EXT}" = ".tar" ]; then
# Attempt to import/configure foreign/qjail container
info "Extracting files from '${TARGET}' archive..."
mkdir -p "${bastille_jailsdir}/${TARGET_TRIM}/root"
workout_components
tar -xf "${bastille_backupsdir}/${TARGET}" --strip-components "${CONF_TRIM}" -C "${bastille_jailsdir}/${TARGET_TRIM}" "${JAIL_CONF}"
tar -xf "${bastille_backupsdir}/${TARGET}" --strip-components "${DIRS_PLUS}" -C "${bastille_jailsdir}/${TARGET_TRIM}/root" "${JAIL_PATH}"
if [ -f "${bastille_jailsdir}/${TARGET_TRIM}/${TARGET_TRIM}" ]; then
mv "${bastille_jailsdir}/${TARGET_TRIM}/${TARGET_TRIM}" "${bastille_jailsdir}/${TARGET_TRIM}/jail.conf"
fi
update_config
else
error_exit "Unsupported archive format."
fi
fi
if [ "$?" -ne 0 ]; then
error_exit "Failed to import from '${TARGET}' archive."
else
# Update the jail.conf and fstab if required
# This is required on foreign imports only
update_jailconf
update_fstab
if [ -z "${USER_IMPORT}" ]; then
info "Container '${TARGET_TRIM}' imported successfully."
fi
exit 0
fi
else
error_exit "Jails directory/dataset does not exist. See 'bastille bootstrap'."
fi
}
# Check for user specified file location
if echo "${TARGET}" | grep -q '\/'; then
GETDIR="${TARGET}"
TARGET=$(echo ${TARGET} | awk -F '\/' '{print $NF}')
bastille_backupsdir=$(echo ${GETDIR} | sed "s/${TARGET}//")
fi
# Check if backups directory/dataset exist
if [ ! -d "${bastille_backupsdir}" ]; then
error_exit "Backups directory/dataset does not exist. See 'bastille bootstrap'."
fi
# Check if archive exist then trim archive name
if [ -f "${bastille_backupsdir}/${TARGET}" ]; then
# Filter unsupported/unknown archives
if echo "${TARGET}" | grep -q '_[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}-[0-9]\{6\}$\|_[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}-[0-9]\{6\}.xz$\|_[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}-[0-9]\{6\}$\|_[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}-[0-9]\{6\}.gz$\|_[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}-[0-9]\{6\}$\|_[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}-[0-9]\{6\}.tgz$\|_[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}-[0-9]\{6\}.txz$\|_[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}.zip$\|-[0-9]\{12\}.[0-9]\{2\}.tar.gz$\|@[0-9]\{12\}.[0-9]\{2\}.tar$'; then
if ls "${bastille_backupsdir}" | awk "/^${TARGET}$/" >/dev/null; then
TARGET_TRIM=$(echo "${TARGET}" | sed "s/_[0-9]*-[0-9]*-[0-9]*-[0-9]*.xz//;s/_[0-9]*-[0-9]*-[0-9]*-[0-9]*.gz//;s/_[0-9]*-[0-9]*-[0-9]*-[0-9]*.tgz//;s/_[0-9]*-[0-9]*-[0-9]*-[0-9]*.txz//;s/_[0-9]*-[0-9]*-[0-9]*.zip//;s/-[0-9]\{12\}.[0-9]\{2\}.tar.gz//;s/@[0-9]\{12\}.[0-9]\{2\}.tar//;s/_[0-9]*-[0-9]*-[0-9]*-[0-9]*//")
fi
else
error_exit "Unrecognized archive name."
fi
else
if echo "${TARGET}" | grep -q '_[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}-[0-9]\{6\}.*$'; then
error_exit "Archive '${TARGET}' not found."
else
# Assume user will import from standard input
TARGET_TRIM=${TARGET}
USER_IMPORT="1"
fi
fi
# Check if a running jail matches name or already exist
if [ -n "$(/usr/sbin/jls name | awk "/^${TARGET_TRIM}$/")" ]; then
error_exit "A running jail matches name."
elif [ -n "${TARGET_TRIM}" ]; then
if [ -d "${bastille_jailsdir}/${TARGET_TRIM}" ]; then
error_exit "Container: ${TARGET_TRIM} already exists."
fi
fi
if [ -n "${TARGET}" ]; then
jail_import
fi

View File

@@ -0,0 +1,82 @@
#!/bin/sh
#
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
# Ressource limits added by Sven R github.com/hackacad
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
. /usr/local/share/bastille/common.sh
. /usr/local/etc/bastille/bastille.conf
usage() {
error_notify "Usage: bastille limits TARGET option value"
echo -e "Example: bastille limits JAILNAME memoryuse 1G"
exit 1
}
RACCT_ENABLE=$(sysctl -n kern.racct.enable)
if [ "${RACCT_ENABLE}" != '1' ]; then
echo "Racct not enabled. Append 'kern.racct.enable=1' to /boot/loader.conf and reboot"
# exit 1
fi
# Handle special-case commands first.
case "$1" in
help|-h|--help)
usage
;;
esac
if [ $# -ne 2 ]; then
usage
fi
bastille_root_check
OPTION="${1}"
VALUE="${2}"
for _jail in ${JAILS}; do
info "[${_jail}]:"
_rctl_rule="jail:${_jail}:${OPTION}:deny=${VALUE}/jail"
_rctl_rule_log="jail:${_jail}:${OPTION}:log=${VALUE}/jail"
# Check whether the entry already exists and, if so, update it. -- cwells
if grep -qs "jail:${_jail}:${OPTION}:deny" "${bastille_jailsdir}/${_jail}/rctl.conf"; then
_escaped_option=$(echo "${OPTION}" | sed 's/\//\\\//g')
_escaped_rctl_rule=$(echo "${_rctl_rule}" | sed 's/\//\\\//g')
sed -i '' -E "s/jail:${_jail}:${_escaped_option}:deny.+/${_escaped_rctl_rule}/" "${bastille_jailsdir}/${_jail}/rctl.conf"
else # Just append the entry. -- cwells
echo "${_rctl_rule}" >> "${bastille_jailsdir}/${_jail}/rctl.conf"
echo "${_rctl_rule_log}" >> "${bastille_jailsdir}/${_jail}/rctl.conf"
fi
echo -e "${OPTION} ${VALUE}"
rctl -a "${_rctl_rule}" "${_rctl_rule_log}"
echo -e "${COLOR_RESET}"
done

View File

@@ -1,22 +1,22 @@
#!/bin/sh
#
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
#
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
#
# Redistribution and use in source and binary forms, with or without
# 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
@@ -28,25 +28,213 @@
# 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/share/bastille/common.sh
. /usr/local/etc/bastille/bastille.conf
usage() {
echo -e "${COLOR_RED}Usage: bastille list.${COLOR_RESET}"
exit 1
error_exit "Usage: bastille list [-j|-a] [release [-p]|template|(jail|container)|log|limit|(import|export|backup)]"
}
if [ $# -eq 0 ]; then
jls -N
if [ "${1}" = help -o "${1}" = "-h" -o "${1}" = "--help" ]; then
usage
fi
bastille_root_check
if [ $# -eq 0 ]; then
/usr/sbin/jls
fi
if [ "${1}" == "-j" ]; then
/usr/sbin/jls -N --libxo json
exit 0
fi
TARGET=
list_all(){
if [ -d "${bastille_jailsdir}" ]; then
DEFAULT_VALUE="-"
SPACER=2
MAX_LENGTH_JAIL_NAME=$(find ""${bastille_jailsdir}/*/jail.conf"" -maxdepth 1 -type f -print0 2> /dev/null | xargs -r0 -P0 grep -h -m 1 -e "^.* {$" | awk '{ print length($1) }' | sort -nr | head -n 1)
MAX_LENGTH_JAIL_NAME=${MAX_LENGTH_JAIL_NAME:-3}
if [ "${MAX_LENGTH_JAIL_NAME}" -lt 3 ]; then MAX_LENGTH_JAIL_NAME=3; fi
MAX_LENGTH_JAIL_IP=$(find ""${bastille_jailsdir}/*/jail.conf"" -maxdepth 1 -type f -print0 2> /dev/null | xargs -r0 -P0 sed -n "s/^[ ]*ip[4,6].addr[ ]*=[ ]*\(.*\);$/\1 /p" | sed 's/\// /g' | awk '{ print length($1) }' | sort -nr | head -n 1)
MAX_LENGTH_JAIL_IP=${MAX_LENGTH_JAIL_IP:-10}
MAX_LENGTH_JAIL_VNET_IP=$(find ""${bastille_jailsdir}/*/jail.conf"" -maxdepth 1 -type f -print0 2> /dev/null | xargs -r0 -P0 grep -l "vnet;" | grep -h "ifconfig_vnet0=" $(sed -n "s/\(.*\)jail.conf$/\1root\/etc\/rc.conf/p") | sed -n "s/^ifconfig_vnet0=\"\(.*\)\"$/\1/p"| sed "s/\// /g" | awk '{ if ($1 ~ /^[inet|inet6]/) print length($2); else print 15 }' | sort -nr | head -n 1)
MAX_LENGTH_JAIL_VNET_IP=${MAX_LENGTH_JAIL_VNET_IP:-10}
if [ "${MAX_LENGTH_JAIL_VNET_IP}" -gt "${MAX_LENGTH_JAIL_IP}" ]; then MAX_LENGTH_JAIL_IP=${MAX_LENGTH_JAIL_VNET_IP}; fi
if [ "${MAX_LENGTH_JAIL_IP}" -lt 10 ]; then MAX_LENGTH_JAIL_IP=10; fi
MAX_LENGTH_JAIL_HOSTNAME=$(find ""${bastille_jailsdir}/*/jail.conf"" -maxdepth 1 -type f -print0 2> /dev/null | xargs -r0 -P0 grep -h -m 1 -e "^[ ]*host.hostname[ ]*=[ ]*\(.*\);" | awk '{ print length(substr($3, 1, length($3)-1)) }' | sort -nr | head -n 1)
MAX_LENGTH_JAIL_HOSTNAME=${MAX_LENGTH_JAIL_HOSTNAME:-8}
if [ "${MAX_LENGTH_JAIL_HOSTNAME}" -lt 8 ]; then MAX_LENGTH_JAIL_HOSTNAME=8; fi
MAX_LENGTH_JAIL_PORTS=$(find ""${bastille_jailsdir}/*/rdr.conf"" -maxdepth 1 -type f -print0 2> /dev/null | xargs -r0 -P0 -n1 awk '{ lines++; chars += length($0)} END { chars += lines - 1; print chars }' | sort -nr | head -n 1)
MAX_LENGTH_JAIL_PORTS=${MAX_LENGTH_JAIL_PORTS:-15}
if [ "${MAX_LENGTH_JAIL_PORTS}" -lt 15 ]; then MAX_LENGTH_JAIL_PORTS=15; fi
if [ "${MAX_LENGTH_JAIL_PORTS}" -gt 30 ]; then MAX_LENGTH_JAIL_PORTS=30; fi
MAX_LENGTH_JAIL_RELEASE=$(find ""${bastille_jailsdir}/*/fstab"" -maxdepth 1 -type f -print0 2> /dev/null | xargs -r0 -P0 grep -h "/releases/.*/root/.bastille.*nullfs" | grep -hE "^USERLAND_VERSION=" $(sed -n "s/^\(.*\) \/.*$/\1\/bin\/freebsd-version/p" | awk '!_[$0]++') | sed "s/[\"\'\^]//g;s/ .*$//g" | sed -n "s/^USERLAND_VERSION=\(.*\)$/\1/p" | awk '{ print length($0) }' | sort -nr | head -n 1)
MAX_LENGTH_JAIL_RELEASE=${MAX_LENGTH_JAIL_RELEASE:-7}
MAX_LENGTH_THICK_JAIL_RELEASE=$(find ""${bastille_jailsdir}/*/root/bin/freebsd-version"" -maxdepth 1 -type f -print0 2> /dev/null | xargs -r0 -P0 grep -hE "^USERLAND_VERSION=" | sed "s/[\"\'\^]//g;s/ .*$//g" | sed -n "s/^USERLAND_VERSION=\(.*\)$/\1/p" | awk '{ print length($0) }' | sort -nr | head -n 1)
MAX_LENGTH_THICK_JAIL_RELEASE=${MAX_LENGTH_THICK_JAIL_RELEASE:-7}
MAX_LENGTH_LINUX_JAIL_RELEASE=$(find ""${bastille_jailsdir}/*/fstab"" -maxdepth 1 -type f -print0 2> /dev/null | xargs -r0 -P0 grep -h "/jails/.*/root/proc.*linprocfs" | grep -hE "^NAME=|^VERSION_ID=|^VERSION_CODENAME=" $(sed -n "s/^linprocfs *\(.*\)\/.*$/\1\/etc\/os-release/p") 2> /dev/null | sed "s/\"//g" | sed "s/ GNU\/Linux//g" | sed "N;N;s/\n/;/g" | sed -n "s/^NAME=\(.*\);VERSION_ID=\(.*\);VERSION_CODENAME=\(.*\)$/\1 \2 (\3)/p" | awk '{ print length($0) }' | sort -nr | head -n 1)
MAX_LENGTH_LINUX_JAIL_RELEASE=${MAX_LENGTH_LINUX_JAIL_RELEASE:-7}
if [ "${MAX_LENGTH_THICK_JAIL_RELEASE}" -gt "${MAX_LENGTH_JAIL_RELEASE}" ]; then MAX_LENGTH_JAIL_RELEASE=${MAX_LENGTH_THICK_JAIL_RELEASE}; fi
if [ "${MAX_LENGTH_LINUX_JAIL_RELEASE}" -gt "${MAX_LENGTH_JAIL_RELEASE}" ]; then MAX_LENGTH_JAIL_RELEASE=${MAX_LENGTH_LINUX_JAIL_RELEASE}; fi
if [ "${MAX_LENGTH_JAIL_RELEASE}" -lt 7 ]; then MAX_LENGTH_JAIL_RELEASE=7; fi
printf " JID%*sState%*sIP Address%*sPublished Ports%*sHostname%*sRelease%*sPath\n" "$((${MAX_LENGTH_JAIL_NAME} + ${SPACER} - 3))" "" "$((${SPACER}))" "" "$((${MAX_LENGTH_JAIL_IP} + ${SPACER} - 10))" "" "$((${MAX_LENGTH_JAIL_PORTS} + ${SPACER} - 15))" "" "$((${MAX_LENGTH_JAIL_HOSTNAME} + ${SPACER} - 8))" "" "$((${MAX_LENGTH_JAIL_RELEASE} + ${SPACER} - 7))" ""
if [ -n "${TARGET}" ]; then
# Query all info for a specific jail.
JAIL_LIST="${TARGET}"
else
# Query all info for all jails(default).
JAIL_LIST=$(ls "${bastille_jailsdir}" | sed "s/\n//g")
fi
for _JAIL in ${JAIL_LIST}; do
if [ -f "${bastille_jailsdir}/${_JAIL}/jail.conf" ]; then
JAIL_NAME=$(grep -h -m 1 -e "^.* {$" "${bastille_jailsdir}/${_JAIL}/jail.conf" 2> /dev/null | awk '{ print $1 }')
IS_FREEBSD_JAIL=0
if [ -f "${bastille_jailsdir}/${JAIL_NAME}/root/bin/freebsd-version" -o -f "${bastille_jailsdir}/${JAIL_NAME}/root/.bastille/bin/freebsd-version" -o "$(grep -c "/releases/.*/root/.bastille.*nullfs" "${bastille_jailsdir}/${JAIL_NAME}/fstab" 2> /dev/null)" -gt 0 ]; then IS_FREEBSD_JAIL=1; fi
IS_FREEBSD_JAIL=${IS_FREEBSD_JAIL:-0}
IS_LINUX_JAIL=0
if [ "$(grep -c "^linprocfs" "${bastille_jailsdir}/${JAIL_NAME}/fstab" 2> /dev/null)" -gt 0 ]; then IS_LINUX_JAIL=1; fi
IS_LINUX_JAIL=${IS_LINUX_JAIL:-0}
if [ "$(/usr/sbin/jls name | awk "/^${JAIL_NAME}$/")" ]; then
JAIL_STATE="Up"
if [ "$(awk '$1 == "vnet;" { print $1 }' "${bastille_jailsdir}/${JAIL_NAME}/jail.conf" 2> /dev/null)" ]; then
JAIL_IP=$(jexec -l ${JAIL_NAME} ifconfig -n vnet0 inet 2> /dev/null | sed -n "/.inet /{s///;s/ .*//;p;}")
if [ ! "${JAIL_IP}" ]; then JAIL_IP=$(jexec -l ${JAIL_NAME} ifconfig -n vnet0 inet6 2> /dev/null | awk '/inet6 / && (!/fe80::/ || !/%vnet0/)' | sed -n "/.inet6 /{s///;s/ .*//;p;}"); fi
else
JAIL_IP=$(/usr/sbin/jls -j ${JAIL_NAME} ip4.addr 2> /dev/null)
if [ "${JAIL_IP}" = "-" ]; then JAIL_IP=$(/usr/sbin/jls -j ${JAIL_NAME} ip6.addr 2> /dev/null); fi
fi
JAIL_HOSTNAME=$(/usr/sbin/jls -j ${JAIL_NAME} host.hostname 2> /dev/null)
JAIL_PORTS=$(pfctl -a "rdr/${JAIL_NAME}" -Psn 2> /dev/null | awk '{ printf "%s/%s:%s"",",$7,$14,$18 }' | sed "s/,$//")
JAIL_PATH=$(/usr/sbin/jls -j ${JAIL_NAME} path 2> /dev/null)
if [ "${IS_FREEBSD_JAIL}" -eq 1 ]; then
JAIL_RELEASE=$(jexec -l ${JAIL_NAME} freebsd-version -u 2> /dev/null)
fi
if [ "${IS_LINUX_JAIL}" -eq 1 ]; then
JAIL_RELEASE=$(grep -hE "^NAME=.*$|^VERSION_ID=.*$|^VERSION_CODENAME=.*$" "${JAIL_PATH}/etc/os-release" 2> /dev/null | sed "s/\"//g" | sed "s/ GNU\/Linux//g" | awk -F'=' '{ a[$1] = $2; o++ } o%3 == 0 { print a["VERSION_CODENAME"] " (" a["NAME"] " " a["VERSION_ID"] ")" }')
fi
else
JAIL_STATE=$(if [ "$(sed -n "/^${JAIL_NAME} {$/,/^}$/p" "${bastille_jailsdir}/${JAIL_NAME}/jail.conf" 2> /dev/null | awk '$0 ~ /^'${JAIL_NAME}' \{|\}/ { printf "%s",$0 }')" == "${JAIL_NAME} {}" ]; then echo "Down"; else echo "n/a"; fi)
if [ "$(awk '$1 == "vnet;" { print $1 }' "${bastille_jailsdir}/${JAIL_NAME}/jail.conf" 2> /dev/null)" ]; then
JAIL_IP=$(sed -n 's/^ifconfig_vnet0="\(.*\)"$/\1/p' "${bastille_jailsdir}/${JAIL_NAME}/root/etc/rc.conf" 2> /dev/null | sed "s/\// /g" | awk '{ if ($1 ~ /^[inet|inet6]/) print $2; else print $1 }')
else
JAIL_IP=$(sed -n "s/^[ ]*ip[4,6].addr[ ]*=[ ]*\(.*\);$/\1/p" "${bastille_jailsdir}/${JAIL_NAME}/jail.conf" 2> /dev/null | sed "s/\// /g" | awk '{ print $1 }')
fi
JAIL_HOSTNAME=$(sed -n "s/^[ ]*host.hostname[ ]*=[ ]*\(.*\);$/\1/p" "${bastille_jailsdir}/${JAIL_NAME}/jail.conf" 2> /dev/null)
if [ -f "${bastille_jailsdir}/${JAIL_NAME}/rdr.conf" ]; then JAIL_PORTS=$(awk '$1 ~ /^[tcp|udp]/ { printf "%s/%s:%s,",$1,$2,$3 }' "${bastille_jailsdir}/${JAIL_NAME}/rdr.conf" 2> /dev/null | sed "s/,$//"); else JAIL_PORTS=""; fi
JAIL_PATH=$(sed -n "s/^[ ]*path[ ]*=[ ]*\(.*\);$/\1/p" "${bastille_jailsdir}/${JAIL_NAME}/jail.conf" 2> /dev/null)
if [ "${JAIL_PATH}" ]; then
if [ "${IS_FREEBSD_JAIL}" -eq 1 ]; then
if [ -f "${JAIL_PATH}/bin/freebsd-version" ]; then
JAIL_RELEASE=$(grep -hE "^USERLAND_VERSION=" "${JAIL_PATH}/bin/freebsd-version" 2> /dev/null | sed "s/[\"\'\^]//g;s/ .*$//g" | sed -n "s/^USERLAND_VERSION=\(.*\)$/\1/p")
else
JAIL_RELEASE=$(grep -h "/releases/.*/root/.bastille.*nullfs" "${bastille_jailsdir}/${JAIL_NAME}/fstab" 2> /dev/null | grep -hE "^USERLAND_VERSION=" $(sed -n "s/^\(.*\) \/.*$/\1\/bin\/freebsd-version/p" | awk '!_[$0]++') | sed "s/[\"\'\^]//g;s/ .*$//g" | sed -n "s/^USERLAND_VERSION=\(.*\)$/\1/p")
fi
fi
if [ "${IS_LINUX_JAIL}" -eq 1 ]; then
JAIL_RELEASE=$(grep -hE "^NAME=.*$|^VERSION_ID=.*$|^VERSION_CODENAME=.*$" "${JAIL_PATH}/etc/os-release" 2> /dev/null | sed "s/\"//g" | sed "s/ GNU\/Linux//g" | awk -F'=' '{ a[$1] = $2; o++ } o%3 == 0 { print a["VERSION_CODENAME"] " (" a["NAME"] " " a["VERSION_ID"] ")" }')
fi
else
JAIL_RELEASE=""
fi
fi
if [ "${#JAIL_PORTS}" -gt "${MAX_LENGTH_JAIL_PORTS}" ]; then JAIL_PORTS="$(echo ${JAIL_PORTS} | cut -c-$((${MAX_LENGTH_JAIL_PORTS} - 3)))..."; fi
JAIL_NAME=${JAIL_NAME:-${DEFAULT_VALUE}}
JAIL_STATE=${JAIL_STATE:-${DEFAULT_VALUE}}
JAIL_IP=${JAIL_IP:-${DEFAULT_VALUE}}
JAIL_PORTS=${JAIL_PORTS:-${DEFAULT_VALUE}}
JAIL_HOSTNAME=${JAIL_HOSTNAME:-${DEFAULT_VALUE}}
JAIL_RELEASE=${JAIL_RELEASE:-${DEFAULT_VALUE}}
JAIL_PATH=${JAIL_PATH:-${DEFAULT_VALUE}}
printf " ${JAIL_NAME}%*s${JAIL_STATE}%*s${JAIL_IP}%*s${JAIL_PORTS}%*s${JAIL_HOSTNAME}%*s${JAIL_RELEASE}%*s${JAIL_PATH}\n" "$((${MAX_LENGTH_JAIL_NAME} - ${#JAIL_NAME} + ${SPACER}))" "" "$((5 - ${#JAIL_STATE} + ${SPACER}))" "" "$((${MAX_LENGTH_JAIL_IP} - ${#JAIL_IP} + ${SPACER}))" "" "$((${MAX_LENGTH_JAIL_PORTS} - ${#JAIL_PORTS} + ${SPACER}))" "" "$((${MAX_LENGTH_JAIL_HOSTNAME} - ${#JAIL_HOSTNAME} + ${SPACER}))" "" "$((${MAX_LENGTH_JAIL_RELEASE} - ${#JAIL_RELEASE} + ${SPACER}))" ""
fi
done
else
error_exit "unfortunately there are no jails here (${bastille_jailsdir})"
fi
}
list_release(){
if [ -d "${bastille_releasesdir}" ]; then
REL_LIST=$(ls "${bastille_releasesdir}" | sed "s/\n//g")
for _REL in ${REL_LIST}; do
if [ -f "${bastille_releasesdir}/${_REL}/root/.profile" -o -d "${bastille_releasesdir}/${_REL}/debootstrap" ]; then
if [ "${2}" == "-p" -a -f "${bastille_releasesdir}/${_REL}/bin/freebsd-version" ]; then
REL_PATCH_LEVEL=$(sed -n "s/^USERLAND_VERSION=\"\(.*\)\"$/\1/p" "${bastille_releasesdir}/${_REL}/bin/freebsd-version" 2> /dev/null)
REL_PATCH_LEVEL=${REL_PATCH_LEVEL:-${_REL}}
echo "${REL_PATCH_LEVEL}"
else
echo "${_REL}"
fi
fi
done
fi
}
list_template(){
find "${bastille_templatesdir}" -type d -maxdepth 2
}
list_jail(){
if [ -d "${bastille_jailsdir}" ]; then
JAIL_LIST=$(ls "${bastille_jailsdir}" | sed "s/\n//g")
for _JAIL in ${JAIL_LIST}; do
if [ -f "${bastille_jailsdir}/${_JAIL}/jail.conf" ]; then
echo "${_JAIL}"
fi
done
fi
}
list_log(){
find "${bastille_logsdir}" -type f -maxdepth 1
}
list_limit(){
rctl -h jail:
}
list_import(){
ls "${bastille_backupsdir}" | grep -v ".sha256$"
}
if [ $# -gt 0 ]; then
# Handle special-case commands first.
case "$1" in
help|-h|--help)
usage
case "${1}" in
all|-a|--all)
list_all
;;
release|releases)
list_release
;;
template|templates)
list_template
;;
jail|jails|container|containers)
list_jail
;;
log|logs)
list_log
;;
limit|limits)
list_limit
;;
import|imports|export|exports|backup|backups)
list_import
exit 0
;;
*)
usage
# Check if we want to query all info for a specific jail instead.
if [ -f "${bastille_jailsdir}/${1}/jail.conf" ]; then
TARGET="${1}"
list_all
else
usage
fi
;;
esac
fi

View File

@@ -0,0 +1,122 @@
#!/bin/sh
#
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
. /usr/local/share/bastille/common.sh
. /usr/local/etc/bastille/bastille.conf
usage() {
error_exit "Usage: bastille mount TARGET host_path container_path [filesystem_type options dump pass_number]"
}
# Handle special-case commands first.
case "$1" in
help|-h|--help)
usage
;;
esac
if [ $# -lt 2 ]; then
usage
elif [ $# -eq 2 ]; then
_fstab="$@ nullfs ro 0 0"
else
_fstab="$@"
fi
bastille_root_check
## assign needed variables
_hostpath=$(echo "${_fstab}" | awk '{print $1}')
_jailpath=$(echo "${_fstab}" | awk '{print $2}')
_type=$(echo "${_fstab}" | awk '{print $3}')
_perms=$(echo "${_fstab}" | awk '{print $4}')
_checks=$(echo "${_fstab}" | awk '{print $5" "$6}')
## if any variables are empty, bail out
if [ -z "${_hostpath}" ] || [ -z "${_jailpath}" ] || [ -z "${_type}" ] || [ -z "${_perms}" ] || [ -z "${_checks}" ]; then
error_notify "FSTAB format not recognized."
warn "Format: /host/path jail/path nullfs ro 0 0"
warn "Read: ${_fstab}"
exit 1
fi
## if host path doesn't exist, type is not "nullfs" or are using advanced mount type "tmpfs,linprocfs,linsysfs, fdescfs, procfs"
if [ "${_hostpath}" == "tmpfs" -a "$_type" == "tmpfs" ] || [ "${_hostpath}" == "linprocfs" -a "${_type}" == "linprocfs" ] || [ "${_hostpath}" == "linsysfs" -a "${_type}" == "linsysfs" ] || [ "${_hostpath}" == "proc" -a "${_type}" == "procfs" ] || [ "${_hostpath}" == "fdesc" -a "${_type}" == "fdescfs" ] ; then
warn "Detected advanced mount type ${_hostpath}"
elif [ ! -d "${_hostpath}" ] || [ "${_type}" != "nullfs" ]; then
error_notify "Detected invalid host path or incorrect mount type in FSTAB."
warn "Format: /host/path jail/path nullfs ro 0 0"
warn "Read: ${_fstab}"
exit 1
fi
## if mount permissions are not "ro" or "rw"
if [ "${_perms}" != "ro" ] && [ "${_perms}" != "rw" ]; then
error_notify "Detected invalid mount permissions in FSTAB."
warn "Format: /host/path jail/path nullfs ro 0 0"
warn "Read: ${_fstab}"
exit 1
fi
## if check & pass are not "0 0 - 1 1"; bail out
if [ "${_checks}" != "0 0" ] && [ "${_checks}" != "1 0" ] && [ "${_checks}" != "0 1" ] && [ "${_checks}" != "1 1" ]; then
error_notify "Detected invalid fstab options in FSTAB."
warn "Format: /host/path jail/path nullfs ro 0 0"
warn "Read: ${_fstab}"
exit 1
fi
for _jail in ${JAILS}; do
info "[${_jail}]:"
## aggregate variables into FSTAB entry
_fullpath="${bastille_jailsdir}/${_jail}/root/${_jailpath}"
_fstab_entry="${_hostpath} ${_fullpath} ${_type} ${_perms} ${_checks}"
## Create mount point if it does not exist. -- cwells
if [ ! -d "${_fullpath}" ]; then
if ! mkdir -p "${_fullpath}"; then
error_exit "Failed to create mount point inside jail."
fi
fi
## if entry doesn't exist, add; else show existing entry
if ! egrep -q "[[:blank:]]${_fullpath}[[:blank:]]" "${bastille_jailsdir}/${_jail}/fstab" 2> /dev/null; then
if ! echo "${_fstab_entry}" >> "${bastille_jailsdir}/${_jail}/fstab"; then
error_exit "Failed to create fstab entry: ${_fstab_entry}"
fi
echo "Added: ${_fstab_entry}"
else
warn "Mountpoint already present in ${bastille_jailsdir}/${_jail}/fstab"
egrep "[[:blank:]]${_fullpath}[[:blank:]]" "${bastille_jailsdir}/${_jail}/fstab"
fi
mount -F "${bastille_jailsdir}/${_jail}/fstab" -a
echo
done

View File

@@ -1,22 +1,22 @@
#!/bin/sh
#
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
#
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
#
# Redistribution and use in source and binary forms, with or without
# 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
@@ -28,11 +28,10 @@
# 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/share/bastille/common.sh
usage() {
echo -e "${COLOR_RED}Usage: bastille pkg [ALL|glob] 'pkg command'${COLOR_RESET}"
exit 1
error_exit "Usage: bastille pkg [-H|--host] TARGET command [args]"
}
# Handle special-case commands first.
@@ -42,18 +41,38 @@ help|-h|--help)
;;
esac
if [ $# -gt 2 ] || [ $# -lt 2 ]; then
if [ $# -lt 1 ]; then
usage
fi
if [ "$1" = 'ALL' ]; then
JAILS=$(jls -N name)
fi
if [ "$1" != 'ALL' ]; then
JAILS=$(jls -N name | grep "$1")
fi
bastille_root_check
errors=0
for _jail in ${JAILS}; do
echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}"
jexec -l ${_jail} /usr/sbin/pkg $2
info "[${_jail}]:"
bastille_jail_path=$(/usr/sbin/jls -j "${_jail}" path)
if [ -f "/usr/sbin/mport" ]; then
if ! jexec -l -U root "${_jail}" /usr/sbin/mport "$@"; then
errors=1
fi
elif [ -f "${bastille_jail_path}/usr/bin/apt" ]; then
if ! jexec -l "${_jail}" /usr/bin/apt "$@"; then
errors=1
fi
elif [ "${USE_HOST_PKG}" = 1 ]; then
if ! /usr/sbin/pkg -j "${_jail}" "$@"; then
errors=1
fi
else
if ! jexec -l -U root "${_jail}" /usr/sbin/pkg "$@"; then
errors=1
fi
fi
echo
done
if [ $errors -ne 0 ]; then
error_exit "Failed to apply on some jails, please check logs"
exit 1
fi

View File

@@ -0,0 +1,77 @@
#!/bin/sh
#
# Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
. /usr/local/share/bastille/common.sh
. /usr/local/etc/bastille/bastille.conf
usage() {
error_exit "Usage: bastille rcp [OPTION] TARGET CONTAINER_PATH HOST_PATH"
}
CPSOURCE="${1}"
CPDEST="${2}"
# Handle special-case commands first.
case "$1" in
help|-h|--help)
usage
;;
-q|--quiet)
OPTION="${1}"
CPSOURCE="${2}"
CPDEST="${3}"
;;
esac
if [ $# -ne 2 ]; then
usage
fi
if [ "${TARGET}" = "ALL" ]; then
usage
fi
case "${OPTION}" in
-q|--quiet)
OPTION="-a"
;;
*)
OPTION="-av"
;;
esac
for _jail in ${JAILS}; do
info "[${_jail}]:"
bastille_jail_path="${bastille_jailsdir}/${_jail}/root"
cp "${OPTION}" "${bastille_jail_path}/${CPSOURCE}" "${CPDEST}"
RETURN="$?"
echo
return "${RETURN}"
done

View File

@@ -0,0 +1,216 @@
#!/bin/sh
#
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
. /usr/local/share/bastille/common.sh
. /usr/local/etc/bastille/bastille.conf
usage() {
error_exit "Usage: bastille rdr TARGET [clear|list|(tcp|udp host_port jail_port [log ['(' logopts ')'] ] )]"
}
# Handle special-case commands first.
case "$1" in
help|-h|--help)
usage
;;
esac
if [ $# -lt 2 ]; then
usage
fi
bastille_root_check
TARGET="${1}"
JAIL_NAME=""
JAIL_IP=""
JAIL_IP6=""
EXT_IF=""
shift
check_jail_validity() {
# Can only redirect to single jail
if [ "${TARGET}" = 'ALL' ]; then
error_exit "Can only redirect to a single jail."
fi
# Check if jail name is valid
JAIL_NAME=$(/usr/sbin/jls -j "${TARGET}" name 2>/dev/null)
if [ -z "${JAIL_NAME}" ]; then
error_exit "Jail not found: ${TARGET}"
fi
# Check if jail ip4 address (ip4.addr) is valid (non-VNET only)
if [ "$(bastille config $TARGET get vnet)" != 'enabled' ]; then
JAIL_IP=$(/usr/sbin/jls -j "${TARGET}" ip4.addr 2>/dev/null)
if [ -z "${JAIL_IP}" -o "${JAIL_IP}" = "-" ]; then
error_exit "Jail IP not found: ${TARGET}"
fi
fi
# Check if jail ip6 address (ip6.addr) is valid (non-VNET only)
if [ "$(bastille config $TARGET get vnet)" != 'enabled' ]; then
if [ "$(bastille config $TARGET get ip6)" != 'disable' ] && [ "$(bastille config $TARGET get ip6)" != 'not set' ]; then
JAIL_IP6=$(/usr/sbin/jls -j "${TARGET}" ip6.addr 2>/dev/null)
fi
fi
# Check if rdr-anchor is defined in pf.conf
if ! (pfctl -sn | grep rdr-anchor | grep 'rdr/\*' >/dev/null); then
error_exit "rdr-anchor not found in pf.conf"
fi
# Check if ext_if is defined in pf.conf
if [ -n "${bastille_pf_conf}" ]; then
EXT_IF=$(grep "^[[:space:]]*${bastille_network_pf_ext_if}[[:space:]]*=" ${bastille_pf_conf})
if [ -z "${EXT_IF}" ]; then
error_exit "bastille_network_pf_ext_if (${bastille_network_pf_ext_if}) not defined in pf.conf"
fi
fi
}
# function: write rule to rdr.conf
persist_rdr_rule() {
if ! grep -qs "$1 $2 $3" "${bastille_jailsdir}/${JAIL_NAME}/rdr.conf"; then
echo "$1 $2 $3" >> "${bastille_jailsdir}/${JAIL_NAME}/rdr.conf"
fi
}
persist_rdr_log_rule() {
proto=$1;host_port=$2;jail_port=$3;
shift 3;
log=$@;
if ! grep -qs "$proto $host_port $jail_port $log" "${bastille_jailsdir}/${JAIL_NAME}/rdr.conf"; then
echo "$proto $host_port $jail_port $log" >> "${bastille_jailsdir}/${JAIL_NAME}/rdr.conf"
fi
}
# function: load rdr rule via pfctl
load_rdr_rule() {
( pfctl -a "rdr/${JAIL_NAME}" -Psn;
printf '%s\nrdr pass on $%s inet proto %s to port %s -> %s port %s\n' "$EXT_IF" "${bastille_network_pf_ext_if}" "$1" "$2" "$JAIL_IP" "$3" ) \
| pfctl -a "rdr/${JAIL_NAME}" -f-
if [ -n "$JAIL_IP6" ]; then
( pfctl -a "rdr/${JAIL_NAME}" -Psn;
printf '%s\nrdr pass on $%s inet proto %s to port %s -> %s port %s\n' "$EXT_IF" "${bastille_network_pf_ext_if}" "$1" "$2" "$JAIL_IP6" "$3" ) \
| pfctl -a "rdr/${JAIL_NAME}" -f-
fi
}
# function: load rdr rule with log via pfctl
load_rdr_log_rule() {
proto=$1;host_port=$2;jail_port=$3;
shift 3;
log=$@
( pfctl -a "rdr/${JAIL_NAME}" -Psn;
printf '%s\nrdr pass %s on $%s inet proto %s to port %s -> %s port %s\n' "$EXT_IF" "$log" "${bastille_network_pf_ext_if}" "$proto" "$host_port" "$JAIL_IP" "$jail_port" ) \
| pfctl -a "rdr/${JAIL_NAME}" -f-
if [ -n "$JAIL_IP6" ]; then
( pfctl -a "rdr/${JAIL_NAME}" -Psn;
printf '%s\nrdr pass %s on $%s inet proto %s to port %s -> %s port %s\n' "$EXT_IF" "$log" "${bastille_network_pf_ext_if}" "$proto" "$host_port" "$JAIL_IP6" "$jail_port" ) \
| pfctl -a "rdr/${JAIL_NAME}" -f-
fi
}
while [ $# -gt 0 ]; do
case "$1" in
list)
if [ "${TARGET}" = 'ALL' ]; then
for JAIL_NAME in $(ls "${bastille_jailsdir}" | sed "s/\n//g"); do
echo "${JAIL_NAME} redirects:"
pfctl -a "rdr/${JAIL_NAME}" -Psn 2>/dev/null
done
else
check_jail_validity
pfctl -a "rdr/${JAIL_NAME}" -Psn 2>/dev/null
fi
shift
;;
clear)
if [ "${TARGET}" = 'ALL' ]; then
for JAIL_NAME in $(ls "${bastille_jailsdir}" | sed "s/\n//g"); do
echo "${JAIL_NAME} redirects:"
pfctl -a "rdr/${JAIL_NAME}" -Fn
done
else
check_jail_validity
pfctl -a "rdr/${JAIL_NAME}" -Fn
fi
shift
;;
tcp|udp)
if [ $# -lt 3 ]; then
usage
elif [ $# -eq 3 ]; then
check_jail_validity
persist_rdr_rule $1 $2 $3
load_rdr_rule $1 $2 $3
shift 3
else
case "$4" in
log)
proto=$1
host_port=$2
jail_port=$3
shift 3
if [ $# -gt 3 ]; then
for last in $@; do
true
done
if [ $2 == "(" ] && [ $last == ")" ] ; then
check_jail_validity
persist_rdr_log_rule $proto $host_port $jail_port $@
load_rdr_log_rule $proto $host_port $jail_port $@
shift $#
else
usage
fi
elif [ $# -eq 1 ]; then
check_jail_validity
persist_rdr_log_rule $proto $host_port $jail_port $@
load_rdr_log_rule $proto $host_port $jail_port $@
shift 1
else
usage
fi
;;
*)
usage
;;
esac
fi
;;
*)
usage
;;
esac
done

View File

@@ -0,0 +1,164 @@
#!/bin/sh
#
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
. /usr/local/share/bastille/common.sh
. /usr/local/etc/bastille/bastille.conf
usage() {
error_exit "Usage: bastille rename TARGET NEW_NAME"
}
validate_name() {
local NAME_VERIFY=${NEWNAME}
local NAME_SANITY=$(echo "${NAME_VERIFY}" | tr -c -d 'a-zA-Z0-9-_')
if [ -n "$(echo "${NAME_SANITY}" | awk "/^[-_].*$/" )" ]; then
error_exit "Container names may not begin with (-|_) characters!"
elif [ "${NAME_VERIFY}" != "${NAME_SANITY}" ]; then
error_exit "Container names may not contain special characters!"
fi
}
# Handle special-case commands first
case "$1" in
help|-h|--help)
usage
;;
esac
if [ $# -ne 1 ]; then
usage
fi
bastille_root_check
NEWNAME="${1}"
update_jailconf() {
# Update jail.conf
JAIL_CONFIG="${bastille_jailsdir}/${NEWNAME}/jail.conf"
if [ -f "${JAIL_CONFIG}" ]; then
if ! grep -qw "path = ${bastille_jailsdir}/${NEWNAME}/root;" "${JAIL_CONFIG}"; then
sed -i '' "s|host.hostname.*=.*${TARGET};|host.hostname = ${NEWNAME};|" "${JAIL_CONFIG}"
sed -i '' "s|exec.consolelog.*=.*;|exec.consolelog = ${bastille_logsdir}/${NEWNAME}_console.log;|" "${JAIL_CONFIG}"
sed -i '' "s|path.*=.*;|path = ${bastille_jailsdir}/${NEWNAME}/root;|" "${JAIL_CONFIG}"
sed -i '' "s|mount.fstab.*=.*;|mount.fstab = ${bastille_jailsdir}/${NEWNAME}/fstab;|" "${JAIL_CONFIG}"
sed -i '' "s|${TARGET}.*{|${NEWNAME} {|" "${JAIL_CONFIG}"
# Rename vnet interface
sed -i '' "/vnet.interface/s|_${TARGET}\";|_${NEWNAME}\";|" "${JAIL_CONFIG}"
sed -i '' "/ifconfig/s|_${TARGET}|_${NEWNAME}|" "${JAIL_CONFIG}"
fi
fi
}
update_fstab() {
# Update fstab to use the new name
FSTAB_CONFIG="${bastille_jailsdir}/${NEWNAME}/fstab"
if [ -f "${FSTAB_CONFIG}" ]; then
# Skip if fstab is empty, e.g newly created thick or clone jails
if [ -s "${FSTAB_CONFIG}" ]; then
FSTAB_RELEASE=$(grep -owE '([1-9]{2,2})\.[0-9](-RELEASE|-RC[1-9])|([0-9]{1,2}-stable-build-[0-9]{1,3})|(current-build)-([0-9]{1,3})|(current-BUILD-LATEST)|([0-9]{1,2}-stable-BUILD-LATEST)|(current-BUILD-LATEST)' "${FSTAB_CONFIG}")
FSTAB_CURRENT=$(grep -w ".*/releases/.*/jails/${TARGET}/root/.bastille" "${FSTAB_CONFIG}")
FSTAB_NEWCONF="${bastille_releasesdir}/${FSTAB_RELEASE} ${bastille_jailsdir}/${NEWNAME}/root/.bastille nullfs ro 0 0"
if [ -n "${FSTAB_CURRENT}" ] && [ -n "${FSTAB_NEWCONF}" ]; then
# If both variables are set, update as needed
if ! grep -qw "${bastille_releasesdir}/${FSTAB_RELEASE}.*${bastille_jailsdir}/${NEWNAME}/root/.bastille" "${FSTAB_CONFIG}"; then
sed -i '' "s|${FSTAB_CURRENT}|${FSTAB_NEWCONF}|" "${FSTAB_CONFIG}"
fi
fi
# Update linuxjail fstab name entries
# Search for either linprocfs/linsysfs, if true assume is a linux jail
if grep -qwE "linprocfs|linsysfs" "${FSTAB_CONFIG}"; then
sed -i '' "s|.${bastille_jailsdir}/${TARGET}/|${bastille_jailsdir}/${NEWNAME}/|" "${FSTAB_CONFIG}"
fi
fi
fi
}
change_name() {
# Attempt container name change
info "Attempting to rename '${TARGET}' to ${NEWNAME}..."
if checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ] && [ -n "${bastille_zfs_prefix}" ]; then
# Check and rename container ZFS dataset accordingly
# Perform additional checks in case of non-ZFS existing containers
if zfs list | grep -qw "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}"; then
if ! zfs rename -f "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NEWNAME}"; then
error_exit "Can't rename '${TARGET}' dataset."
fi
else
# Check and rename container directory instead
if ! zfs list | grep -qw "jails/${TARGET}$"; then
mv "${bastille_jailsdir}/${TARGET}" "${bastille_jailsdir}/${NEWNAME}"
fi
fi
fi
else
# Check if container is a zfs/dataset before rename attempt
# Perform additional checks in case of bastille.conf miss-configuration
if zfs list | grep -qw "jails/${TARGET}$"; then
ZFS_DATASET_ORIGIN=$(zfs list | grep -w "jails/${TARGET}$" | awk '{print $1}')
ZFS_DATASET_TARGET=$(echo "${ZFS_DATASET_ORIGIN}" | sed "s|\/${TARGET}||")
if [ -n "${ZFS_DATASET_ORIGIN}" ] && [ -n "${ZFS_DATASET_TARGET}" ]; then
if ! zfs rename -f "${ZFS_DATASET_ORIGIN}" "${ZFS_DATASET_TARGET}/${NEWNAME}"; then
error_exit "Can't rename '${TARGET}' dataset."
fi
else
error_exit "Can't determine the ZFS origin path of '${TARGET}'."
fi
else
# Just rename the jail directory
mv "${bastille_jailsdir}/${TARGET}" "${bastille_jailsdir}/${NEWNAME}"
fi
fi
# Update jail configuration files accordingly
update_jailconf
update_fstab
# Check exit status and notify
if [ "$?" -ne 0 ]; then
error_exit "An error has occurred while attempting to rename '${TARGET}'."
else
info "Renamed '${TARGET}' to '${NEWNAME}' successfully."
fi
}
## validate jail name
if [ -n "${NEWNAME}" ]; then
validate_name
fi
## check if a jail already exists with the new name
if [ -d "${bastille_jailsdir}/${NEWNAME}" ]; then
error_exit "Jail: ${NEWNAME} already exists."
fi
change_name

View File

@@ -1,22 +1,22 @@
#!/bin/sh
#
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
#
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
#
# Redistribution and use in source and binary forms, with or without
# 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

View File

@@ -1,22 +1,22 @@
#!/bin/sh
#
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
#
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
#
# Redistribution and use in source and binary forms, with or without
# 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
@@ -28,11 +28,10 @@
# 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/share/bastille/common.sh
usage() {
echo -e "${COLOR_RED}Usage: bastille service [ALL|glob] 'service command'.${COLOR_RESET}"
exit 1
error_exit "Usage: bastille service TARGET service_name action"
}
# Handle special-case commands first.
@@ -42,20 +41,14 @@ help|-h|--help)
;;
esac
if [ $# -gt 2 ] || [ $# -lt 2 ]; then
if [ $# -lt 1 -o $# -gt 2 ]; then
usage
fi
if [ "$1" = 'ALL' ]; then
JAILS=$(jls -N name)
fi
if [ "$1" != 'ALL' ]; then
JAILS=$(jls -N name | grep "$1")
fi
bastille_root_check
for _jail in ${JAILS}; do
echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}"
jexec -l ${_jail} /usr/sbin/service $2
echo -e "${COLOR_RESET}"
info "[${_jail}]:"
jexec -l "${_jail}" /usr/sbin/service "$@"
echo
done

View File

@@ -0,0 +1,145 @@
#!/bin/sh
#
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
bastille_config="/usr/local/etc/bastille/bastille.conf"
. /usr/local/share/bastille/common.sh
. ${bastille_config}
usage() {
error_exit "Usage: bastille setup [pf|bastille0|zfs|vnet]"
}
# Check for too many args
if [ $# -gt 1 ]; then
usage
fi
# Configure bastille0 network interface
configure_bastille0() {
info "Configuring bastille0 loopback interface"
sysrc cloned_interfaces+=lo1
sysrc ifconfig_lo1_name="bastille0"
info "Bringing up new interface: bastille0"
service netif cloneup
}
configure_vnet() {
info "Configuring bridge interface"
sysrc cloned_interfaces+=bridge1
sysrc ifconfig_bridge1_name=bastille1
info "Bringing up new interface: bastille1"
service netif cloneup
if [ ! -f /etc/devfs.rules ]; then
info "Creating bastille_vnet devfs.rules"
cat << EOF > /etc/devfs.rules
[bastille_vnet=13]
add include \$devfsrules_hide_all
add include \$devfsrules_unhide_basic
add include \$devfsrules_unhide_login
add include \$devfsrules_jail
add include \$devfsrules_jail_vnet
add path 'bpf*' unhide
EOF
fi
}
# Configure pf firewall
configure_pf() {
if [ ! -f "${bastille_pf_conf}" ]; then
local ext_if
ext_if=$(netstat -rn | awk '/default/ {print $4}' | head -n1)
info "Determined default network interface: ($ext_if)"
info "${bastille_pf_conf} does not exist: creating..."
## creating pf.conf
cat << EOF > ${bastille_pf_conf}
## generated by bastille setup
ext_if="$ext_if"
set block-policy return
scrub in on \$ext_if all fragment reassemble
set skip on lo
table <jails> persist
nat on \$ext_if from <jails> to any -> (\$ext_if:0)
rdr-anchor "rdr/*"
block in all
pass out quick keep state
antispoof for \$ext_if inet
pass in inet proto tcp from any to any port ssh flags S/SA keep state
EOF
sysrc pf_enable=YES
else
error_exit "${bastille_pf_conf} already exists. Exiting."
fi
}
# Configure ZFS
configure_zfs() {
if [ ! "$(kldstat -m zfs)" ]; then
info "ZFS module not loaded; skipping..."
else
## attempt to determine bastille_zroot from `zpool list`
bastille_zroot=$(zpool list | grep -v NAME | awk '{print $1}')
sysrc -f "${bastille_config}" bastille_zfs_enable=YES
sysrc -f "${bastille_config}" bastille_zfs_zpool="${bastille_zroot}"
fi
}
# Run all base functions (w/o vnet) if no args
if [ $# -eq 0 ]; then
sysrc bastille_enable=YES
configure_bastille0
configure_pf
configure_zfs
fi
# Handle special-case commands first.
case "$1" in
help|-h|--help)
usage
;;
pf|firewall)
configure_pf
;;
bastille0|loopback)
configure_bastille0
;;
zfs|storage)
configure_zfs
;;
bastille1|vnet|bridge)
configure_vnet
;;
esac

View File

@@ -1,22 +1,22 @@
#!/bin/sh
#
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
#
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
#
# Redistribution and use in source and binary forms, with or without
# 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
@@ -28,12 +28,11 @@
# 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/share/bastille/common.sh
. /usr/local/etc/bastille/bastille.conf
usage() {
echo -e "${COLOR_RED}Usage: bastille start [ALL|glob].${COLOR_RESET}"
exit 1
error_exit "Usage: bastille start TARGET"
}
# Handle special-case commands first.
@@ -47,22 +46,66 @@ if [ $# -gt 1 ] || [ $# -lt 1 ]; then
usage
fi
if [ "$1" = 'ALL' ]; then
JAILS=$(find ${bastille_jailsdir} -d 1 | awk -F / '{ print $6 }')
fi
if [ "$1" != 'ALL' ]; then
JAILS=$(find ${bastille_jailsdir} -d 1 | awk -F / '{ print $6 }' | grep $1)
fi
bastille_root_check
if [ $(jls -N name | ${NAME}) ]; then
echo -e "${COLOR_RED}${NAME} already running.${COLOR_RESET}"
exit 1
TARGET="${1}"
shift
if [ "${TARGET}" = 'ALL' ]; then
JAILS=$(bastille list jails)
fi
if [ "${TARGET}" != 'ALL' ]; then
JAILS=$(bastille list jails | awk "/^${TARGET}$/")
## check if exist
if [ ! -d "${bastille_jailsdir}/${TARGET}" ]; then
error_exit "[${TARGET}]: Not found."
fi
fi
for _jail in ${JAILS}; do
echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}"
jail -f "${bastille_jailsdir}/${_jail}/jail.conf" -c ${_jail}
done
## test if running
if [ "$(/usr/sbin/jls name | awk "/^${_jail}$/")" ]; then
error_notify "[${_jail}]: Already started."
## HUP the firewall
pfctl -f /etc/pf.conf
## test if not running
elif [ ! "$(/usr/sbin/jls name | awk "/^${_jail}$/")" ]; then
# Verify that the configured interface exists. -- cwells
if [ "$(bastille config $_jail get vnet)" != 'enabled' ]; then
_interface=$(bastille config $_jail get interface)
if ! ifconfig | grep "^${_interface}:" >/dev/null; then
error_notify "Error: ${_interface} interface does not exist."
continue
fi
fi
## warn if matching configured (but not online) ip4.addr, ignore if there's no ip4.addr entry
ip=$(bastille config "${_jail}" get ip4.addr)
if [ -n "${ip}" ]; then
if ifconfig | grep -wF "${ip}" >/dev/null; then
error_notify "Error: IP address (${ip}) already in use."
continue
fi
## add ip4.addr to firewall table
pfctl -q -t "${bastille_network_pf_table}" -T add "${ip}"
fi
## start the container
info "[${_jail}]:"
jail -f "${bastille_jailsdir}/${_jail}/jail.conf" -c "${_jail}"
## add rctl limits
if [ -s "${bastille_jailsdir}/${_jail}/rctl.conf" ]; then
while read _limits; do
rctl -a "${_limits}"
done < "${bastille_jailsdir}/${_jail}/rctl.conf"
fi
## add rdr rules
if [ -s "${bastille_jailsdir}/${_jail}/rdr.conf" ]; then
while read _rules; do
bastille rdr "${_jail}" ${_rules}
done < "${bastille_jailsdir}/${_jail}/rdr.conf"
fi
fi
echo
done

View File

@@ -1,22 +1,22 @@
#!/bin/sh
#
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
#
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
#
# Redistribution and use in source and binary forms, with or without
# 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
@@ -28,12 +28,11 @@
# 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/share/bastille/common.sh
. /usr/local/etc/bastille/bastille.conf
usage() {
echo -e "${COLOR_RED}Usage: bastille stop [ALL|glob].${COLOR_RESET}"
exit 1
error_exit "Usage: bastille stop TARGET"
}
# Handle special-case commands first.
@@ -43,21 +42,42 @@ help|-h|--help)
;;
esac
if [ $# -gt 1 ] || [ $# -lt 1 ]; then
if [ $# -ne 0 ]; then
usage
fi
if [ "$1" = 'ALL' ]; then
JAILS=$(jls -N name)
fi
if [ "$1" != 'ALL' ]; then
JAILS=$(jls -N name | grep "$1")
fi
bastille_root_check
for _jail in ${JAILS}; do
echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}"
jail -f "${bastille_jailsdir}/${_jail}/jail.conf" -r ${_jail}
done
## test if running
if [ "$(/usr/sbin/jls name | awk "/^${_jail}$/")" ]; then
## Capture ip4.addr address while still running
_ip="$(/usr/sbin/jls -j ${_jail} ip4.addr)"
## HUP the firewall
pfctl -f /etc/pf.conf
# Check if pfctl is present
if which -s pfctl; then
if [ "$(bastille rdr ${_jail} list)" ]; then
bastille rdr ${_jail} clear
fi
fi
## remove rctl limits
if [ -s "${bastille_jailsdir}/${_jail}/rctl.conf" ]; then
while read _limits; do
rctl -r "${_limits}"
done < "${bastille_jailsdir}/${_jail}/rctl.conf"
fi
## stop container
info "[${_jail}]:"
jail -f "${bastille_jailsdir}/${_jail}/jail.conf" -r "${_jail}"
## remove (captured above) ip4.addr from firewall table
if [ -n "${bastille_network_loopback}" -a ! -z "${_ip}" ]; then
if grep -qw "interface.*=.*${bastille_network_loopback}" "${bastille_jailsdir}/${_jail}/jail.conf"; then
pfctl -q -t "${bastille_network_pf_table}" -T delete "${_ip}"
fi
fi
fi
echo
done

View File

@@ -1,22 +1,22 @@
#!/bin/sh
#
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
#
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
#
# Redistribution and use in source and binary forms, with or without
# 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
@@ -28,11 +28,10 @@
# 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/share/bastille/common.sh
usage() {
echo -e "${COLOR_RED}Usage: bastille sysrc [ALL|glob] 'sysrc command'${COLOR_RESET}"
exit 1
error_exit "Usage: bastille sysrc TARGET args"
}
# Handle special-case commands first.
@@ -42,20 +41,14 @@ help|-h|--help)
;;
esac
if [ $# -gt 2 ] || [ $# -lt 2 ]; then
if [ $# -lt 1 ]; then
usage
fi
if [ "$1" = 'ALL' ]; then
JAILS=$(jls -N name)
fi
if [ "$1" != 'ALL' ]; then
JAILS=$(jls -N name | grep "$1")
fi
bastille_root_check
for _jail in ${JAILS}; do
echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}"
jexec -l ${_jail} /usr/sbin/sysrc $2
info "[${_jail}]:"
jexec -l "${_jail}" /usr/sbin/sysrc "$@"
echo -e "${COLOR_RESET}"
done

View File

@@ -0,0 +1,104 @@
#!/bin/sh
#
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
# Ressource limits added by Lars Engels github.com/bsdlme
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
. /usr/local/share/bastille/common.sh
. /usr/local/etc/bastille/bastille.conf
usage() {
error_notify "Usage: bastille tags TARGET add tag1[,tag2,...]"
error_notify " bastille tags TARGET delete tag1[,tag2,...]"
error_notify " bastille tags TARGET list [tag]"
echo -e "Example: bastille tags JAILNAME add database,mysql"
echo -e " bastille tags JAILNAME delete mysql"
echo -e " bastille tags ALL list"
echo -e " bastille tags ALL list mysql"
exit 1
}
# Handle special-case commands first.
case "$1" in
help|-h|--help)
usage
;;
esac
if [ $# -lt 1 -o $# -gt 2 ]; then
usage
fi
bastille_root_check
ACTION="${1}"
TAGS="${2}"
for _jail in ${JAILS}; do
bastille_jail_tags="${bastille_jailsdir}/${_jail}/tags"
case ${ACTION} in
add)
for _tag in $(echo ${TAGS} | tr , ' '); do
echo ${_tag} >> "${bastille_jail_tags}"
tmpfile="$(mktemp)"
sort "${bastille_jail_tags}" | uniq > "${tmpfile}"
mv "${tmpfile}" "${bastille_jail_tags}"
done
;;
del*)
for _tag in $(echo ${TAGS} | tr , ' '); do
[ ! -f "${bastille_jail_tags}" ] && break # skip if no tags file
tmpfile="$(mktemp)"
grep -Ev "^${_tag}\$" "${bastille_jail_tags}" > "${tmpfile}"
mv "${tmpfile}" "${bastille_jail_tags}"
# delete tags file if empty
[ ! -s "${bastille_jail_tags}" ] && rm "${bastille_jail_tags}"
done
;;
list)
if [ -n "${TAGS}" ]; then
[ -n "$(echo ${TAGS} | grep ,)" ] && usage # Only one tag per query
[ ! -f "${bastille_jail_tags}" ] && continue # skip if there is no tags file
grep -qE "^${TAGS}\$" "${bastille_jail_tags}"
if [ $? -eq 0 ]; then
echo "${_jail}"
continue
fi
else
if [ -f "${bastille_jail_tags}" ]; then
echo -n "${_jail}: "
xargs < "${bastille_jail_tags}"
fi
fi
;;
*)
usage
;;
esac
done

View File

@@ -1,22 +1,22 @@
#!/bin/sh
#
# Copyright (c) 2018, Christer Edwards <christer.edwards@gmail.com>
#
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
#
# Redistribution and use in source and binary forms, with or without
# 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
@@ -28,89 +28,366 @@
# 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/share/bastille/common.sh
. /usr/local/etc/bastille/bastille.conf
usage() {
echo -e "${COLOR_RED}Usage: bastille template [ALL|glob] template.${COLOR_RESET}"
exit 1
bastille_usage() {
error_exit "Usage: bastille template TARGET|--convert project/template"
}
post_command_hook() {
_jail=$1
_cmd=$2
_args=$3
case $_cmd in
rdr)
echo -e ${_args}
esac
}
get_arg_name() {
echo "${1}" | sed -E 's/=.*//'
}
parse_arg_value() {
# Parses the value after = and then escapes back/forward slashes and single quotes in it. -- cwells
echo "${1}" | sed -E 's/[^=]+=?//' | sed -e 's/\\/\\\\/g' -e 's/\//\\\//g' -e 's/'\''/'\''\\'\'\''/g'
}
get_arg_value() {
_name_value_pair="${1}"
shift
_arg_name="$(get_arg_name "${_name_value_pair}")"
# Remaining arguments in $@ are the script arguments, which take precedence. -- cwells
for _script_arg in "$@"; do
case ${_script_arg} in
--arg)
# Parse whatever is next. -- cwells
_next_arg='true' ;;
*)
if [ "${_next_arg}" = 'true' ]; then # This is the parameter after --arg. -- cwells
_next_arg=''
if [ "$(get_arg_name "${_script_arg}")" = "${_arg_name}" ]; then
parse_arg_value "${_script_arg}"
return
fi
fi
;;
esac
done
# Check the ARG_FILE if one was provided. --cwells
if [ -n "${ARG_FILE}" ]; then
# To prevent a false empty value, only parse the value if this argument exists in the file. -- cwells
if grep "^${_arg_name}=" "${ARG_FILE}" > /dev/null 2>&1; then
parse_arg_value "$(grep "^${_arg_name}=" "${ARG_FILE}")"
return
fi
fi
# Return the default value, which may be empty, from the name=value pair. -- cwells
parse_arg_value "${_name_value_pair}"
}
render() {
_file_path="${1}/${2}"
if [ -d "${_file_path}" ]; then # Recursively render every file in this directory. -- cwells
echo "Rendering Directory: ${_file_path}"
find "${_file_path}" \( -type d -name .git -prune \) -o -type f
find "${_file_path}" \( -type d -name .git -prune \) -o -type f -print0 | $(eval "xargs -0 sed -i '' ${ARG_REPLACEMENTS}")
elif [ -f "${_file_path}" ]; then
echo "Rendering File: ${_file_path}"
eval "sed -i '' ${ARG_REPLACEMENTS} '${_file_path}'"
else
warn "Path not found for render: ${2}"
fi
}
# Handle special-case commands first.
case "$1" in
help|-h|--help)
usage
bastille_usage
;;
esac
if [ $# -gt 2 ] || [ $# -lt 2 ]; then
usage
if [ $# -lt 1 ]; then
bastille_usage
fi
if [ "$1" = 'ALL' ]; then
JAILS=$(jls -N name)
fi
if [ "$1" != 'ALL' ]; then
JAILS=$(jls -N name | grep "$1")
fi
bastille_root_check
TEMPLATE=$2
## global variables
TEMPLATE="${1}"
bastille_template=${bastille_templatesdir}/${TEMPLATE}
if [ -z "${HOOKS}" ]; then
HOOKS='LIMITS INCLUDE PRE FSTAB PF PKG OVERLAY CONFIG SYSRC SERVICE CMD RENDER'
fi
# Special case conversion of hook-style template files into a Bastillefile. -- cwells
if [ "${TARGET}" = '--convert' ]; then
if [ -d "${TEMPLATE}" ]; then # A relative path was provided. -- cwells
cd "${TEMPLATE}"
elif [ -d "${bastille_template}" ]; then
cd "${bastille_template}"
else
error_exit "Template not found: ${TEMPLATE}"
fi
echo "Converting template: ${TEMPLATE}"
HOOKS="ARG ${HOOKS}"
for _hook in ${HOOKS}; do
if [ -s "${_hook}" ]; then
# Default command is the hook name and default args are the line from the file. -- cwells
_cmd="${_hook}"
_args_template='${_line}'
# Replace old hook names with Bastille command names. -- cwells
case ${_hook} in
CONFIG|OVERLAY)
_cmd='CP'
_args_template='${_line} /'
;;
FSTAB)
_cmd='MOUNT' ;;
PF)
_cmd='RDR' ;;
PRE)
_cmd='CMD' ;;
esac
while read _line; do
if [ -z "${_line}" ]; then
continue
fi
eval "_args=\"${_args_template}\""
echo "${_cmd} ${_args}" >> Bastillefile
done < "${_hook}"
echo '' >> Bastillefile
rm "${_hook}"
fi
done
info "Template converted: ${TEMPLATE}"
exit 0
fi
case ${TEMPLATE} in
http?://*/*/*)
TEMPLATE_DIR=$(echo "${TEMPLATE}" | awk -F / '{ print $4 "/" $5 }')
if [ ! -d "${bastille_templatesdir}/${TEMPLATE_DIR}" ]; then
info "Bootstrapping ${TEMPLATE}..."
if ! bastille bootstrap "${TEMPLATE}"; then
error_exit "Failed to bootstrap template: ${TEMPLATE}"
fi
fi
TEMPLATE="${TEMPLATE_DIR}"
bastille_template=${bastille_templatesdir}/${TEMPLATE}
;;
*/*)
if [ ! -d "${bastille_templatesdir}/${TEMPLATE}" ]; then
if [ ! -d ${TEMPLATE} ]; then
error_exit "${TEMPLATE} not found."
else
bastille_template=${TEMPLATE}
fi
fi
;;
*)
error_exit "Template name/URL not recognized."
esac
if [ -z "${JAILS}" ]; then
error_exit "Container ${TARGET} is not running."
fi
# Check for an --arg-file parameter. -- cwells
for _script_arg in "$@"; do
case ${_script_arg} in
--arg-file)
# Parse whatever is next. -- cwells
_next_arg='true' ;;
*)
if [ "${_next_arg}" = 'true' ]; then # This is the parameter after --arg-file. -- cwells
_next_arg=''
ARG_FILE="${_script_arg}"
break
fi
;;
esac
done
if [ -n "${ARG_FILE}" ] && [ ! -f "${ARG_FILE}" ]; then
error_exit "File not found: ${ARG_FILE}"
fi
for _jail in ${JAILS}; do
echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}"
info "[${_jail}]:"
info "Applying template: ${TEMPLATE}..."
## pre
if [ -s "${bastille_template}/PRE" ]; then
echo -e "${COLOR_GREEN}Executing PRE-command(s).${COLOR_RESET}"
bastille_templatepre=$(cat "${bastille_template}/PRE")
jexec -l "${_jail}" "${bastille_templatepre}"
## jail-specific variables.
bastille_jail_path=$(/usr/sbin/jls -j "${_jail}" path)
if [ "$(bastille config $TARGET get vnet)" != 'enabled' ]; then
_jail_ip=$(/usr/sbin/jls -j "${_jail}" ip4.addr 2>/dev/null)
_jail_ip6=$(/usr/sbin/jls -j "${_jail}" ip6.addr 2>/dev/null)
if [ -z "${_jail_ip}" -o "${_jail_ip}" = "-" ]; then
error_notify "Jail IP not found: ${_jail}"
_jail_ip='' # In case it was -. -- cwells
fi
fi
## config
if [ -s "${bastille_template}/CONFIG" ]; then
echo -e "${COLOR_GREEN}Copying files...${COLOR_RESET}"
for _dir in $(cat "${bastille_template}/CONFIG"); do
cp -a "${bastille_template}/${_dir}" "${bastille_jailsdir}/${_jail}/root"
## TARGET
if [ -s "${bastille_template}/TARGET" ]; then
if grep -qw "${_jail}" "${bastille_template}/TARGET"; then
info "TARGET: !${_jail}."
echo
continue
fi
if ! grep -Eq "(^|\b)(${_jail}|ALL)($|\b)" "${bastille_template}/TARGET"; then
info "TARGET: ?${_jail}."
echo
continue
fi
fi
# Build a list of sed commands like this: -e 's/${username}/root/g' -e 's/${domain}/example.com/g'
# Values provided by default (without being defined by the user) are listed here. -- cwells
ARG_REPLACEMENTS="-e 's/\${JAIL_IP}/${_jail_ip}/g' -e 's/\${JAIL_IP6}/${_jail_ip6}/g' -e 's/\${JAIL_NAME}/${_jail}/g'"
# This is parsed outside the HOOKS loop so an ARG file can be used with a Bastillefile. -- cwells
if [ -s "${bastille_template}/ARG" ]; then
while read _line; do
if [ -z "${_line}" ]; then
continue
fi
_arg_name=$(get_arg_name "${_line}")
_arg_value=$(get_arg_value "${_line}" "$@")
if [ -z "${_arg_value}" ]; then
warn "No value provided for arg: ${_arg_name}"
fi
ARG_REPLACEMENTS="${ARG_REPLACEMENTS} -e 's/\${${_arg_name}}/${_arg_value}/g'"
done < "${bastille_template}/ARG"
fi
if [ -s "${bastille_template}/Bastillefile" ]; then
# Ignore blank lines and comments. -- cwells
SCRIPT=$(grep -v '^[[:blank:]]*$' "${bastille_template}/Bastillefile" | grep -v '^[[:blank:]]*#')
# Use a newline as the separator. -- cwells
IFS='
'
set -f
for _line in ${SCRIPT}; do
# First word converted to lowercase is the Bastille command. -- cwells
_cmd=$(echo "${_line}" | awk '{print tolower($1);}')
# Rest of the line with "arg" variables replaced will be the arguments. -- cwells
_args=$(echo "${_line}" | awk '{$1=""; sub(/^ */, ""); print;}' | eval "sed ${ARG_REPLACEMENTS}")
# Apply overrides for commands/aliases and arguments. -- cwells
case $_cmd in
arg) # This is a template argument definition. -- cwells
_arg_name=$(get_arg_name "${_args}")
_arg_value=$(get_arg_value "${_args}" "$@")
if [ -z "${_arg_value}" ]; then
warn "No value provided for arg: ${_arg_name}"
fi
# Build a list of sed commands like this: -e 's/${username}/root/g' -e 's/${domain}/example.com/g'
ARG_REPLACEMENTS="${ARG_REPLACEMENTS} -e 's/\${${_arg_name}}/${_arg_value}/g'"
continue
;;
cmd)
# Escape single-quotes in the command being executed. -- cwells
_args=$(echo "${_args}" | sed "s/'/'\\\\''/g")
# Allow redirection within the jail. -- cwells
_args="sh -c '${_args}'"
;;
cp|copy)
_cmd='cp'
# Convert relative "from" path into absolute path inside the template directory. -- cwells
if [ "${_args%${_args#?}}" != '/' ] && [ "${_args%${_args#??}}" != '"/' ]; then
_args="${bastille_template}/${_args}"
fi
;;
fstab|mount)
_cmd='mount' ;;
include)
_cmd='template' ;;
overlay)
_cmd='cp'
_args="${bastille_template}/${_args} /"
;;
pkg)
_args="install -y ${_args}" ;;
render) # This is a path to one or more files needing arguments replaced by values. -- cwells
render "${bastille_jail_path}" "${_args}"
continue
;;
esac
if ! eval "bastille ${_cmd} ${_jail} ${_args}"; then
set +f
unset IFS
error_exit "Failed to execute command: ${_cmd}"
fi
post_command_hook "${_jail}" "${_cmd}" "${_args}"
done
echo -e "${COLOR_GREEN}Copy complete.${COLOR_RESET}"
set +f
unset IFS
fi
## fstab
if [ -s "${bastille_template}/FSTAB" ]; then
bastille_templatefstab=$(cat "${bastille_template}/FSTAB")
echo -e "${COLOR_GREEN}Updating fstab.${COLOR_RESET}"
fi
for _hook in ${HOOKS}; do
if [ -s "${bastille_template}/${_hook}" ]; then
# Default command is the lowercase hook name and default args are the line from the file. -- cwells
_cmd=$(echo "${_hook}" | awk '{print tolower($1);}')
_args_template='${_line}'
## pf
if [ -s "${bastille_template}/PF" ]; then
bastille_templatepf=$(cat "${bastille_template}/PF")
echo -e "${COLOR_GREEN}Generating PF profile.${COLOR_RESET}"
fi
# Override default command/args for some hooks. -- cwells
case ${_hook} in
CONFIG)
warn "CONFIG deprecated; rename to OVERLAY."
_args_template='${bastille_template}/${_line} /'
_cmd='cp' ;;
FSTAB)
_cmd='mount' ;;
INCLUDE)
_cmd='template' ;;
OVERLAY)
_args_template='${bastille_template}/${_line} /'
_cmd='cp' ;;
PF)
info "NOT YET IMPLEMENTED."
continue ;;
PRE)
_cmd='cmd' ;;
RENDER) # This is a path to one or more files needing arguments replaced by values. -- cwells
render "${bastille_jail_path}" "${_line}"
continue
;;
esac
## pkg (bootstrap + pkg)
if [ -s "${bastille_template}/PKG" ]; then
bastille_templatepkg=$(cat "${bastille_template}/PKG")
echo -e "${COLOR_GREEN}Installing packages.${COLOR_RESET}"
jexec -l ${_jail} env ASSUME_ALWAYS_YES="YES" /usr/sbin/pkg bootstrap
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 -y ${bastille_templatepkg}
fi
info "[${_jail}]:${_hook} -- START"
if [ "${_hook}" = 'CMD' ] || [ "${_hook}" = 'PRE' ]; then
bastille cmd "${_jail}" /bin/sh < "${bastille_template}/${_hook}" || exit 1
elif [ "${_hook}" = 'PKG' ]; then
bastille pkg "${_jail}" install -y $(cat "${bastille_template}/PKG") || exit 1
bastille pkg "${_jail}" audit -F
else
while read _line; do
if [ -z "${_line}" ]; then
continue
fi
# Replace "arg" variables in this line with the provided values. -- cwells
_line=$(echo "${_line}" | eval "sed ${ARG_REPLACEMENTS}")
eval "_args=\"${_args_template}\""
bastille "${_cmd}" "${_jail}" ${_args} || exit 1
done < "${bastille_template}/${_hook}"
fi
info "[${_jail}]:${_hook} -- END"
echo
fi
done
## sysrc
if [ -s "${bastille_template}/SYSRC" ]; then
bastille_templatesys=$(cat "${bastille_template}/SYSRC")
echo -e "${COLOR_GREEN}Updating services.${COLOR_RESET}"
jexec -l ${_jail} /usr/sbin/sysrc ${bastille_templatesys}
fi
## cmd
if [ -s "${bastille_template}/CMD" ]; then
bastille_templatecmd=$(cat "${bastille_template}/CMD")
echo -e "${COLOR_GREEN}Executing final command(s).${COLOR_RESET}"
jexec -l ${_jail} ${bastille_templatecmd}
fi
echo -e "${COLOR_GREEN}Template Complete.${COLOR_RESET}"
echo
info "Template applied: ${TEMPLATE}"
echo
done

View File

@@ -0,0 +1,11 @@
ARG HOST_RESOLV_CONF=/etc/resolv.conf
CMD touch /etc/rc.conf
SYSRC syslogd_flags="-ss"
SYSRC sendmail_enable="NO"
SYSRC sendmail_submit_enable="NO"
SYSRC sendmail_outbound_enable="NO"
SYSRC sendmail_msp_queue_enable="NO"
SYSRC cron_flags="-J 60"
CP "${HOST_RESOLV_CONF}" etc/resolv.conf

View File

@@ -0,0 +1,4 @@
ARG BASE_TEMPLATE=default/base
ARG HOST_RESOLV_CONF=/etc/resolv.conf
INCLUDE ${BASE_TEMPLATE} --arg HOST_RESOLV_CONF="${HOST_RESOLV_CONF}"

View File

@@ -0,0 +1,14 @@
PRE mkdir -p home
PRE mkdir -p tmp
FSTAB devfs root/dev devfs rw 0 0
FSTAB tmpfs dev/shm tmpfs rw,size=1g,mode=1777 0 0
FSTAB fdescfs dev/fd fdescfs rw,linrdlnk 0 0
FSTAB linprocfs proc linprocfs rw 0 0
FSTAB linsysfs sys linsysfs rw 0 0
FSTAB /tmp tmp nullfs rw 0 0
FSTAB /home home nullfs rw 0 0
CMD mkdir etc/apt/apt.conf.d/00aptitude
CMD echo "APT::Cache-Start 251658240;" > etc/apt/apt.conf.d/00aptitude

View File

@@ -0,0 +1,4 @@
ARG BASE_TEMPLATE=default/base
ARG HOST_RESOLV_CONF=/etc/resolv.conf
INCLUDE ${BASE_TEMPLATE} --arg HOST_RESOLV_CONF="${HOST_RESOLV_CONF}"

View File

@@ -0,0 +1,4 @@
ARG BASE_TEMPLATE=default/base
ARG HOST_RESOLV_CONF=/etc/resolv.conf
INCLUDE ${BASE_TEMPLATE} --arg HOST_RESOLV_CONF="${HOST_RESOLV_CONF}"

Some files were not shown because too many files have changed in this diff Show More