Compare commits

...

253 Commits

Author SHA1 Message Date
Barry McCormick
0065a6b9f0 slash check added 2023-10-17 12:35:25 -07:00
Barry McCormick
10949c0eeb netmask checking for jail ip 2023-10-17 08:52:32 -07:00
Barry McCormick
3355c07dbf rdr disable directive fix 2023-10-04 10:13:08 -07: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
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
JRGTH
2caf01b722 Cosmetics changes to prevent double "/" 2021-07-14 16:50:35 -04:00
Gerrit Sere
bc143f8fe2 Merge branch 'master' of https://github.com/BastilleBSD/bastille into cmdbug 2021-01-06 13:42:39 +01:00
Gerrit Sere
b2134145a2 bastille cmd exit code not respected #272 2021-01-05 00:30:06 +01:00
60 changed files with 2020 additions and 678 deletions

9
.readthedocs.yaml Normal file
View File

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

View File

@@ -22,6 +22,12 @@ Christer Edwards [christer.edwards@gmail.com]
- 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

View File

@@ -1,6 +1,6 @@
BSD 3-Clause License
Copyright (c) 2018-2021, 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

View File

@@ -1,3 +1,5 @@
BASTILLE_VERSION=$$(git rev-parse HEAD)
.PHONY: all
all:
@echo "Nothing to be done. Please use make install or make uninstall"
@@ -5,9 +7,13 @@ all:
install:
@echo "Installing Bastille"
@echo
@echo "Updating Bastille version to match git revision."
@echo "BASTILLE_VERSION: ${BASTILLE_VERSION}"
@sed -i.orig "s/BASTILLE_VERSION=.*/BASTILLE_VERSION=${BASTILLE_VERSION}/" usr/local/bin/bastille
@cp -Rv usr /
@echo
@echo "This method is for testing / development."
@echo "This method is for testing & development."
@echo "Please report any issues to https://github.com/BastilleBSD/bastille/issues"
.PHONY: uninstall
uninstall:

View File

@@ -39,7 +39,7 @@ Bastille is an open-source system for automating deployment and management of
containerized applications on FreeBSD.
Usage:
bastille command TARGET args
bastille command TARGET [args]
Available Commands:
bootstrap Bootstrap a FreeBSD release for container base.
@@ -47,31 +47,33 @@ Available Commands:
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.
convert Convert a Thin container into a Thick container.
cp cp(1) files from host to targeted container(s).
create Create a new thin or thick container.
destroy Destroy a stopped container or a bootstrapped release.
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 container archive or image.
help Help about any command
export Exports a specified container.
help Help about any command.
htop Interactive process viewer (requires htop).
import Import a container archive or image.
import Import a specified container.
limits Apply resources limits to targeted container(s). See rctl(8).
list List containers, releases, templates, logs, limits or backups.
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 automation templates to targeted container(s).
tags Add or remove tags to targeted container(s).
template Apply file templates to targeted container(s).
top Display and update information about the top(1) cpu processes.
umount Unmount a volume from within the targeted container(s).
update Update container base -pX release.
upgrade Upgrade container release to X.Y-RELEASE.
verify Verify bootstrapped release or automation template.
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.
@@ -182,7 +184,7 @@ The `rdr-anchor "rdr/*"` enables dynamic rdr rules to be setup using the
bastille rdr <jail> clear # Clear dynamic rdr rules
```
Note that if you are rediirecting ports where the host is also listening
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
@@ -236,8 +238,8 @@ not using ZFS and can safely ignore these settings.
bastille bootstrap
------------------
Before you can begin creating containers, Bastille needs to "bootstrap" a
release. Current supported releases are 11.4-RELEASE, 12.2-RELEASE and
13.0-RELEASE.
release. Current supported releases are 12.3-RELEASE, 12.4-RELEASE and
13.1-RELEASE.
**Important: If you need ZFS support see the above section BEFORE
bootstrapping.**
@@ -245,14 +247,14 @@ bootstrapping.**
To `bootstrap` a release, run the bootstrap sub-command with the
release version as the argument.
**FreeBSD 11.4-RELEASE**
**FreeBSD 12.4-RELEASE**
```shell
ishmael ~ # bastille bootstrap 11.4-RELEASE
ishmael ~ # bastille bootstrap 12.4-RELEASE
```
**FreeBSD 12.2-RELEASE**
**FreeBSD 13.1-RELEASE**
```shell
ishmael ~ # bastille bootstrap 12.2-RELEASE
ishmael ~ # bastille bootstrap 13.1-RELEASE
```
**HardenedBSD 11-STABLE-BUILD-XX**
@@ -292,11 +294,11 @@ bootstrapping templates from GitHub or GitLab.
See `bastille update` to ensure your bootstrapped releases include the latest
patches.
** Ubuntu Linux [new since 0.9] **
**Ubuntu Linux [new since 0.9]**
The bootstrap process for Linux containers is very different from the BSD process.
You will need the package debootstrap and some kernel modules for that.
But don't worry, Bastille will do that for that for you.
But don't worry, Bastille will do that for you.
```shell
ishmael ~ # bastille bootstrap focal
@@ -380,7 +382,7 @@ Valid: (em0).
NAME: vnettest0.
IP: 192.168.87.55/24.
INTERFACE: em0.
RELEASE: 12.1-RELEASE.
RELEASE: 12.2-RELEASE.
syslogd_flags: -s -> -ss
sendmail_enable: NO -> NONE
@@ -735,8 +737,8 @@ After populating `usr/local/` with custom config files that your container will
use, be sure to include `usr` in the template OVERLAY definition. eg;
```shell
echo "CP etc" >> /usr/local/bastille/templates/username/base/Bastillefile
echo "CP usr" >> /usr/local/bastille/templates/username/base/Bastillefile
echo "OVERLAY etc" >> /usr/local/bastille/templates/username/base/Bastillefile
echo "OVERLAY usr" >> /usr/local/bastille/templates/username/base/Bastillefile
```
The above example will include anything under "etc" and "usr" inside

5
Vagrantfile vendored
View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

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.1-RELEASE 192.168.1.50/24 vtnet0``

View File

@@ -4,7 +4,7 @@ Bastille is available in the official FreeBSD ports tree at
`sysutils/bastille`. Binary packages available in `quarterly` and `latest`
repositories.
Current version is `0.9.20210714`.
Current version is `0.10.20230714`.
To install from the FreeBSD package repository:

View File

@@ -1,36 +1,41 @@
Network Requirements
====================
Here's the scenario. You've installed Bastille at home or in the cloud and want
to get started putting applications in secure little containers, but how do I
get these containers on the network?
to get started putting applications in secure little containers, but how do you
get these containers on the network? Bastille tries to be flexible about how to
network containerized applications. Four methods are described here.
Bastille tries to be flexible about how to network containerized applications.
Three methods are described here. Consider each options when deciding
which design work best for your needs. One of the methods works better in the
cloud while the others are simpler if used in local area networks.
1. Home or Small Office
**Note: if you are running in the cloud and only have a single public IP you
may want the Public Network option. See below.**
2. Cloud with IPV4 and multiple IPV6
3. Could with single IPV4 (internatl bridge)
4. Cloud with a single IPV4 (external bridge)
Local Area Network
==================
I will cover the local area network (LAN) method first. This method is simpler
to get going and works well in a home network (or similar) where adding alias
IP addresses is no problem.
Please choose the option which is most appropriate for your environment.
Shared Interface (IP alias)
---------------------------
In FreeBSD network interfaces have different names, but look something like
`em0`, `bge0`, `re0`, etc. On a virtual machine it may be `vtnet0`. You get the
idea...
Bastille allows you to define the interface you want the IP attached to when
you create it. An example:
First a few notes. Bastille tries to verify that the interface name you provide is a valid
interface. In FreeBSD network interfaces have different names, but look something like
`em0`, `bge0`, `re0`, `vtnet0` etc. Running the ifconfig commend will tell you the name
of your existing interfaces. Bastille also checks for a valid syntax IP4 or IP6 address.
When you are testing calling out from your containers, please note that the ping command is disabled within the containers, because raw socket access are a security hole. Instead I install and test with wget instead.
Shared Interface on Home or Small Office Network
================================================
If you have just one computer, or a home or small office network,
where you are separated from the rest of the internet by a router. So you are free to use
`private IP addresses <https://www.lifewire.com/what-is-a-private-ip-address-2625970>`.
In this environment, to use Bastille, just create the container, give it a unique private ip address, and attach its ip address to your primary interface.
.. code-block:: shell
bastille create alcatraz 12.1-RELEASE 192.168.1.50 em0
bastille create alcatraz 13.1-RELEASE 192.168.1.50 em0
You may have to change em0
When the `alcatraz` container is started it will add `192.168.1.50` as an IP
alias to the `em0` interface. It will then simply be another member of the
@@ -38,13 +43,53 @@ hosts network. Other networked systems (firewall permitting) should be able to
reach services at that address.
This method is the simplest. All you need to know is the name of your network
interface and a free IP on your current network.
interface and a free IP on your local network.
Shared Interface on IPV6 network (vultr.com)
=======================================
Some ISP's, such as `vultr.com <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.1-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,
you have to add it to the file /etc/rc.conf
Just remember you cannot ping out from the container. Instead I installed and used wget to test the connectivity.
Use the bastille pkg command to install wget.
.. code-block:: shell
bastille pkg alcatraz install wget
Bastille tries to verify that the interface name you provide it is a valid
interface. It also checks for a valid syntax IP4 or IP6 address.
Virtual Network (VNET)
----------------------
========================
(Added in 0.6.x) VNET is supported on FreeBSD 12+ only.
Virtual Network (VNET) creates a private network interface for a container.
@@ -56,7 +101,7 @@ external interface.
.. code-block:: shell
bastille create -V azkaban 12.1-RELEASE 192.168.1.50/24 em0
bastille create -V azkaban 13.1-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
@@ -109,20 +154,33 @@ To define a default route / gateway for all VNET containers define the value in
This config change will apply the defined gateway to any new containers.
Existing containers will need to be manually updated.
Virtual Network (VNET) on External Bridge
=======================================
To create a VNET based container and attach it to an external, already existing bridge, use the `-B` option, an IP/netmask and
external bridge.
.. code-block:: shell
bastille create -B azkaban 13.1-RELEASE 192.168.1.50/24 bridge0
Bastille will automagically create the interface, attach it to the specified bridge and connect /
disconnect containers as they are started and stopped.
The bridge needs to be created/enabled before creating and starting the jail.
Public Network
==============
In this section I'll describe how to network containers in a public network
such as a cloud hosting provider (AWS, digital ocean, vultr, etc)
In this section we describe how to network containers in a public network
such as a cloud hosting provider who only provides you with a single ip address.
(AWS, digital ocean, etc) (The exception is vultr.com, which does
provide you with lots of IPV6 addresses and does a great job supporting FreeBSD!)
In the public cloud you don't often have access to multiple private IP
addresses for your virtual machines. This means if you want to create multiple
containers and assign them all IP addresses, you'll need to create a new
So if you only have a single IP address and if you want to create multiple
containers and assign them all unique IP addresses, you'll need to create a new
network.
loopback (bastille0)
--------------------
What I recommend is creating a cloned loopback interface (`bastille0`) and
What we recommend is creating a cloned loopback interface (`bastille0`) and
assigning all the containers private (rfc1918) addresses on that interface. The
setup I develop on and use Bastille day-to-day uses the `10.0.0.0/8` address
range. I have the ability to use whatever address I want within that range

View File

@@ -22,13 +22,21 @@ Releases
Example
-------
To `bootstrap` a release, run the bootstrap sub-command with the
To `bootstrap` a FreeBSD release, run the bootstrap sub-command with the
release version as the argument.
.. code-block:: shell
ishmael ~ # bastille bootstrap 11.4-RELEASE [update]
ishmael ~ # bastille bootstrap 12.1-RELEASE
ishmael ~ # bastille bootstrap 12.3-RELEASE [update]
ishmael ~ # bastille bootstrap 13.1-RELEASE
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

View File

@@ -16,4 +16,16 @@ can be exported only when the jail is not running.
.. code-block:: shell
Usage: bastille export TARGET
Usage: bastille export | option(s) | TARGET | PATH
Available options are:
.. code-block:: shell
--gz -- Export a ZFS jail using GZIP(.gz) compressed image.
-r | --raw -- Export a ZFS jail to an uncompressed RAW image.
-s | --safe -- Safely stop and start a ZFS jail before the exporting process.
--tgz -- Export a jail using simple .tgz compressed archive instead.
--txz -- Export a jail using simple .txz compressed archive instead.
-v | --verbose -- Be more verbose during the ZFS send operation.
--xz -- Export a ZFS jail using XZ(.xz) compressed image.

View File

@@ -7,4 +7,4 @@ workflow this can be similar to a `bootstrap`.
.. code-block:: shell
ishmael ~ # bastille upgrade 12.0-RELEASE 12.1-RELEASE
ishmael ~ # bastille upgrade 13.0-RELEASE 13.1-RELEASE

View File

@@ -27,7 +27,7 @@ Examples: Containers
| cmd | ALL | 'sockstat -4' | execute `sockstat -4` in ALL containers (ip4 sockets) |
+-----------+--------+-----+------------+-------------------------------------------------------------+
| console | mariadb02 | --- | console (shell) access to mariadb02 |
+----+------+----+---------+------------+--------------+----------------------------------------------+
+----+------+--------+-----+------------+-------------------------------------------------------------+
| pkg | web01 | 'install nginx' | install nginx package in web01 container |
+-----------+--------+------------------+-------------------------------------------------------------+
| pkg | ALL | upgrade | upgrade packages in ALL containers |
@@ -39,11 +39,11 @@ Examples: Containers
| template | ALL | username/base | apply `username/base` template to ALL containers |
+-----------+--------+------------------+-------------------------------------------------------------+
| start | web02 | --- | start web02 container |
+-----------+--------+-----+------------+-------------------------------------------------------------+
| cp | bastion03 | /tmp/resolv.conf-cf etc/resolv.conf | copy host-path to container-path in bastion03|
+----+------+----+---+------------------+--------------+----------------------------------------------+
| create | folsom | 12.1-RELEASE 10.17.89.10 | create 12.1 container named `folsom` with IP |
+-----------+--------+------------------+--------------+----------------------------------------------+
| cp | bastion03 | /tmp/resolv.conf-cf etc/resolv.conf | copy host-path to container-path in bastion03|
+----+------+----+---+---------------------------------+----------------------------------------------+
| create | folsom | 13.1-RELEASE 10.17.89.10 | create 13.1 container named `folsom` with IP |
+-----------+--------+---------------------------------+----------------------------------------------+
Examples: Releases
@@ -56,11 +56,11 @@ Examples: Releases
+-----------+--------------+--------------+-------------------------------------------------------------+
| command | target | args | description |
+===========+==============+==============+=============================================================+
| bootstrap | 12.1-RELEASE | --- | bootstrap 12.1-RELEASE release |
| bootstrap | 13.1-RELEASE | --- | bootstrap 13.1-RELEASE release |
+-----------+--------------+--------------+-------------------------------------------------------------+
| update | 11.4-RELEASE | --- | update 11.4-RELEASE release |
+-----------+--------------+--------------+-------------------------------------------------------------+
| upgrade | 11.3-RELEASE | 11.4-RELEASE | update 11.4-RELEASE release |
| upgrade | 11.3-RELEASE | 11.4-RELEASE | upgrade 11.3-RELEASE release to 11.4-RELEASE |
+-----------+--------------+--------------+-------------------------------------------------------------+
| verify | 11.4-RELEASE | --- | update 11.4-RELEASE release |
| verify | 11.4-RELEASE | --- | verify 11.4-RELEASE release |
+-----------+--------------+--------------+-------------------------------------------------------------+

View File

@@ -1,8 +1,7 @@
========
Template
========
Looking for ready made CI/CD validated [Bastille
Templates](https://gitlab.com/BastilleBSD-Templates)?
Looking for ready made CI/CD validated `Bastille Templates`_?
Bastille supports a templating system allowing you to apply files, pkgs and
execute commands inside the containers automatically.
@@ -139,3 +138,5 @@ directory names in the `bastille/templates` directory.
Executing final command(s).
chsh: user information updated
Template Complete.
.. _Bastille Templates: https://gitlab.com/BastilleBSD-Templates

View File

@@ -0,0 +1,39 @@
=========
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.

View File

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

View File

@@ -8,13 +8,13 @@ else:
# -- Project information -----------------------------------------------------
project = 'Bastille'
copyright = '2018-2021, Christer Edwards'
copyright = '2018-2023, Christer Edwards'
author = 'Christer Edwards'
# The short X.Y version
version = '0.9.20210714'
version = '0.10.20230714'
# The full version, including alpha/beta/rc tags
release = '0.8.20210714-beta'
release = '0.10.20230714-beta'
# -- General configuration ---------------------------------------------------

View File

@@ -12,12 +12,15 @@ https://docs.bastillebsd.org.
:caption: Contents:
chapters/installation
chapters/upgrading
chapters/networking
chapters/usage
chapters/targeting
chapters/subcommands/index
chapters/template
chapters/jail-config
chapters/zfs-support
chapters/gcp
copyright

1
docs/requirements.txt Normal file
View File

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

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -32,17 +32,6 @@ PATH=${PATH}:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
. /usr/local/share/bastille/common.sh
## root check first.
bastille_root_check() {
if [ "$(id -u)" -ne 0 ]; then
## permission denied
error_notify "Bastille: Permission Denied"
error_exit "root / sudo / doas required"
fi
}
bastille_root_check
## check for config existance
bastille_conf_check() {
if [ ! -r "/usr/local/etc/bastille/bastille.conf" ]; then
@@ -54,6 +43,9 @@ bastille_conf_check
## we only load the config if conf_check passes
. /usr/local/etc/bastille/bastille.conf
# Set default values for config properties added during the current major version:
: "${bastille_network_pf_ext_if:=ext_if}"
: "${bastille_network_pf_table:=jails}"
## bastille_prefix should be 0750
## this restricts file system access to privileged users
@@ -70,7 +62,7 @@ bastille_perms_check() {
bastille_perms_check
## version
BASTILLE_VERSION="0.9.20210714"
BASTILLE_VERSION="0.10.20230714"
usage() {
cat << EOF
@@ -82,8 +74,8 @@ Usage:
Available Commands:
bootstrap Bootstrap a FreeBSD release for container base.
cmd Execute arbitrary command on targeted container(s).
clone Clone an existing container.
cmd Execute arbitrary command on targeted container(s).
config Get or set a config value for the targeted container(s).
console Console into a running container.
convert Convert a Thin container into a Thick container.
@@ -106,6 +98,7 @@ Available Commands:
start Start a stopped container.
stop Stop a running container.
sysrc Safely edit rc files within targeted container(s).
tags Add or remove tags to targeted container(s).
template Apply file templates to targeted container(s).
top Display and update information about the top(1) cpu processes.
umount Unmount a volume from within the targeted container(s).
@@ -126,6 +119,23 @@ EOF
CMD=$1
shift
target_all_jails() {
_JAILS=$(/usr/sbin/jls name)
JAILS=""
for _jail in ${_JAILS}; do
_JAILPATH=$(/usr/sbin/jls -j "${_jail}" path)
if [ -z ${_JAILPATH##${bastille_jailsdir}*} ]; then
JAILS="${JAILS} ${_jail}"
fi
done
}
check_target_is_running() {
if [ ! "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
error_exit "[${TARGET}]: Not started. See 'bastille start ${TARGET}'."
fi
}
# Handle special-case commands first.
case "${CMD}" in
version|-v|--version)
@@ -135,10 +145,10 @@ version|-v|--version)
help|-h|--help)
usage
;;
bootstrap|create|destroy|export|import|list|rdr|restart|start|update|upgrade|verify)
bootstrap|create|destroy|export|import|list|rdr|restart|setup|start|update|upgrade|verify)
# Nothing "extra" to do for these commands. -- cwells
;;
clone|config|cmd|console|convert|cp|edit|htop|limits|mount|pkg|rename|service|stop|sysrc|template|top|umount|zfs)
clone|config|cmd|console|convert|cp|edit|htop|limits|mount|pkg|rename|service|stop|sysrc|tags|template|top|umount|zfs)
# Parse the target and ensure it exists. -- cwells
if [ $# -eq 0 ]; then # No target was given, so show the command's help. -- cwells
PARAMS='help'
@@ -147,14 +157,17 @@ clone|config|cmd|console|convert|cp|edit|htop|limits|mount|pkg|rename|service|st
shift
if [ "${TARGET}" = 'ALL' ]; then
_JAILS=$(jls name)
JAILS=""
for _jail in ${_JAILS}; do
_JAILPATH=$(jls -j "${_jail}" path)
if [ -z ${_JAILPATH##${bastille_jailsdir}*} ]; then
JAILS="${JAILS} ${_jail}"
fi
done
target_all_jails
elif [ "${CMD}" = "pkg" ] && [ "${TARGET}" = '-H' ] || [ "${TARGET}" = '--host' ]; then
TARGET="${1}"
USE_HOST_PKG=1
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
@@ -168,19 +181,17 @@ clone|config|cmd|console|convert|cp|edit|htop|limits|mount|pkg|rename|service|st
case "${CMD}" in
cmd|console|htop|pkg|service|stop|sysrc|template|top)
# Require the target to be running. -- cwells
if [ ! "$(jls name | awk "/^${TARGET}$/")" ]; then
error_exit "[${TARGET}]: Not started. See 'bastille start ${TARGET}'."
fi
check_target_is_running
;;
convert|rename)
# Require the target to be stopped. -- cwells
if [ "$(jls name | awk "/^${TARGET}$/")" ]; then
if [ "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
error_exit "${TARGET} is running. See 'bastille stop ${TARGET}'."
fi
;;
esac
fi
export USE_HOST_PKG
export TARGET
export JAILS
fi

View File

@@ -11,6 +11,9 @@ bastille_releasesdir="${bastille_prefix}/releases" ## default
bastille_templatesdir="${bastille_prefix}/templates" ## default: "${bastille_prefix}/templates"
bastille_logsdir="/var/log/bastille" ## default: "/var/log/bastille"
## pf configuration path
bastille_pf_conf="/etc/pf.conf" ## default: "/etc/pf.conf"
## bastille scripts directory (assumed by bastille pkg)
bastille_sharedir="/usr/local/share/bastille" ## default: "/usr/local/share/bastille"
@@ -25,14 +28,14 @@ bastille_sharedir="/usr/local/share/bastille" ## default
bastille_bootstrap_archives="base" ## default: "base"
## default timezone
bastille_tzdata="Etc/UTC" ## default: "Etc/UTC"
bastille_tzdata="" ## default: empty to use host's time zone
## default jail resolv.conf
bastille_resolv_conf="/etc/resolv.conf" ## default: "/etc/resolv.conf"
## bootstrap urls
bastille_url_freebsd="http://ftp.freebsd.org/pub/FreeBSD/releases/" ## default: "http://ftp.freebsd.org/pub/FreeBSD/releases/"
bastille_url_hardenedbsd="http://installer.hardenedbsd.org/pub/hardenedbsd/" ## default: "https://installer.hardenedbsd.org/pub/HardenedBSD/releases/"
bastille_url_hardenedbsd="https://installers.hardenedbsd.org/pub/" ## default: "https://installer.hardenedbsd.org/pub/HardenedBSD/releases/"
bastille_url_midnightbsd="https://www.midnightbsd.org/ftp/MidnightBSD/releases/" ## default: "https://www.midnightbsd.org/pub/MidnightBSD/releases/"
## ZFS options
@@ -49,12 +52,16 @@ bastille_decompress_gz_options="-k -d -c -v" ## default
## 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"

View File

@@ -3,7 +3,7 @@
# Bastille jail startup script
#
# PROVIDE: bastille
# REQUIRE: LOGIN
# REQUIRE: NETWORKING
# KEYWORD: shutdown
# Add the following to /etc/rc.conf[.local] to enable this service
@@ -51,7 +51,9 @@ bastille_stop()
local _jail
for _jail in ${bastille_list}; do
## reverse order of list for shutdown ## fixes #389
bastille_revlist=$(echo "${bastille_list}" | awk '{ for (i=NF; i>1; i--) printf("%s ",$i); print $1; }')
for _jail in ${bastille_revlist}; do
echo "Stopping Bastille Container: ${_jail}"
${command} stop ${_jail}
done

Binary file not shown.

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -42,6 +42,8 @@ help|-h|--help)
;;
esac
bastille_root_check
#Validate if ZFS is enabled in rc.conf and bastille.conf.
if [ "$(sysrc -n zfs_enable)" = "YES" ] && [ ! "${bastille_zfs_enable}" = "YES" ]; then
warn "ZFS is enabled in rc.conf but not bastille.conf. Do you want to continue? (N|y)"
@@ -103,12 +105,11 @@ bootstrap_directories() {
if [ "${bastille_zfs_enable}" = "YES" ];then
if [ -n "${bastille_zfs_zpool}" ]; then
zfs create ${bastille_zfs_options} -o mountpoint="${bastille_prefix}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}"
chmod 0750 "${bastille_prefix}"
fi
else
mkdir -p "${bastille_prefix}"
chmod 0750 "${bastille_prefix}"
fi
chmod 0750 "${bastille_prefix}"
fi
## ${bastille_backupsdir}
@@ -116,12 +117,11 @@ bootstrap_directories() {
if [ "${bastille_zfs_enable}" = "YES" ];then
if [ -n "${bastille_zfs_zpool}" ]; then
zfs create ${bastille_zfs_options} -o mountpoint="${bastille_backupsdir}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/backups"
chmod 0750 "${bastille_backupsdir}"
fi
else
mkdir -p "${bastille_backupsdir}"
chmod 0750 "${bastille_backupsdir}"
fi
chmod 0750 "${bastille_backupsdir}"
fi
## ${bastille_cachedir}
@@ -129,19 +129,29 @@ bootstrap_directories() {
if [ "${bastille_zfs_enable}" = "YES" ]; then
if [ -n "${bastille_zfs_zpool}" ]; then
zfs create ${bastille_zfs_options} -o mountpoint="${bastille_cachedir}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/cache"
zfs create ${bastille_zfs_options} -o mountpoint="${bastille_cachedir}/${RELEASE}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/cache/${RELEASE}"
# Don't create unused/stale cache/RELEASE directory on Linux jails creation.
if [ -z "${NOCACHEDIR}" ]; then
zfs create ${bastille_zfs_options} -o mountpoint="${bastille_cachedir}/${RELEASE}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/cache/${RELEASE}"
fi
fi
else
mkdir -p "${bastille_cachedir}/${RELEASE}"
mkdir -p "${bastille_cachedir}"
# Don't create unused/stale cache/RELEASE directory on Linux jails creation.
if [ -z "${NOCACHEDIR}" ]; then
mkdir -p "${bastille_cachedir}/${RELEASE}"
fi
fi
## create subsequent cache/XX.X-RELEASE datasets
elif [ ! -d "${bastille_cachedir}/${RELEASE}" ]; then
if [ "${bastille_zfs_enable}" = "YES" ]; then
if [ -n "${bastille_zfs_zpool}" ]; then
zfs create ${bastille_zfs_options} -o mountpoint="${bastille_cachedir}/${RELEASE}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/cache/${RELEASE}"
# Don't create unused/stale cache/RELEASE directory on Linux jails creation.
if [ -z "${NOCACHEDIR}" ]; then
if [ "${bastille_zfs_enable}" = "YES" ]; then
if [ -n "${bastille_zfs_zpool}" ]; then
zfs create ${bastille_zfs_options} -o mountpoint="${bastille_cachedir}/${RELEASE}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/cache/${RELEASE}"
fi
else
mkdir -p "${bastille_cachedir}/${RELEASE}"
fi
else
mkdir -p "${bastille_cachedir}/${RELEASE}"
fi
fi
@@ -304,6 +314,102 @@ bootstrap_release() {
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 [ "${bastille_zfs_enable}" = "YES" ]; then
if [ -n "${bastille_zfs_zpool}" ]; then
if [ ! "$(ls -A "${bastille_releasesdir}/${DIR_BOOTSTRAP}")" ]; then
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${DIR_BOOTSTRAP}"
fi
fi
fi
if [ -d "${bastille_releasesdir}/${DIR_BOOTSTRAP}" ]; then
if [ ! "$(ls -A "${bastille_releasesdir}/${DIR_BOOTSTRAP}")" ]; then
rm -rf "${bastille_releasesdir:?}/${DIR_BOOTSTRAP}"
fi
fi
error_exit "Bootstrap failed."
fi
case "${LINUX_FLAVOR}" in
bionic|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}
@@ -321,7 +427,7 @@ bootstrap_template() {
## define basic variables
_url=${BASTILLE_TEMPLATE_URL}
_user=${BASTILLE_TEMPLATE_USER}
_repo=${BASTILLE_TEMPLATE_REPO}
_repo=${BASTILLE_TEMPLATE_REPO%.*} # Remove the trailing ".git"
_template=${bastille_templatesdir}/${_user}/${_repo}
## support for non-git
@@ -343,6 +449,16 @@ bootstrap_template() {
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}"
@@ -400,8 +516,8 @@ case "${1}" in
## check for HardenedBSD(latest stable build release)
NAME_VERIFY=$(echo "${RELEASE}" | grep -iwE '([0-9]{1,2})(-stable-build-latest)$' | sed 's/STABLE/stable/g' | sed 's/build/BUILD/g' | sed 's/latest/LATEST/g')
NAME_RELEASE=$(echo "${NAME_VERIFY}" | sed 's/-BUILD-LATEST//g')
NAME_BUILD=$(echo "${NAME_VERIFY}" | sed 's/[0-9]\{1,2\}-stable-//g')
UPSTREAM_URL="${bastille_url_hardenedbsd}${NAME_RELEASE}/${HW_MACHINE}/${HW_MACHINE_ARCH}/${NAME_BUILD}"
NAME_BUILD=$(echo "${NAME_VERIFY}" | sed 's/[0-9]\{1,2\}-stable-BUILD-//g')
UPSTREAM_URL="${bastille_url_hardenedbsd}${NAME_RELEASE}/${HW_MACHINE}/${HW_MACHINE_ARCH}/installer/${NAME_BUILD}"
PLATFORM_OS="HardenedBSD"
validate_release_url
;;
@@ -418,8 +534,8 @@ current-build-latest|current-BUILD-LATEST|CURRENT-BUILD-LATEST)
## check for HardenedBSD(latest current build release)
NAME_VERIFY=$(echo "${RELEASE}" | grep -iwE '(current-build-latest)' | sed 's/CURRENT/current/g' | sed 's/build/BUILD/g' | sed 's/latest/LATEST/g')
NAME_RELEASE=$(echo "${NAME_VERIFY}" | sed 's/current-.*/current/g')
NAME_BUILD=$(echo "${NAME_VERIFY}" | sed 's/current-//g')
UPSTREAM_URL="${bastille_url_hardenedbsd}${NAME_RELEASE}/${HW_MACHINE}/${HW_MACHINE_ARCH}/${NAME_BUILD}"
NAME_BUILD=$(echo "${NAME_VERIFY}" | sed 's/current-BUILD-//g')
UPSTREAM_URL="${bastille_url_hardenedbsd}${NAME_RELEASE}/${HW_MACHINE}/${HW_MACHINE_ARCH}/installer/${NAME_BUILD}"
PLATFORM_OS="HardenedBSD"
validate_release_url
;;
@@ -429,88 +545,61 @@ http?://*/*/*)
BASTILLE_TEMPLATE_REPO=$(echo "${1}" | awk -F / '{ print $5 }')
bootstrap_template
;;
git@*:*/*)
BASTILLE_TEMPLATE_URL=${1}
git_repository=$(echo "${1}" | awk -F : '{ print $2 }')
BASTILLE_TEMPLATE_USER=$(echo "${git_repository}" | awk -F / '{ print $1 }')
BASTILLE_TEMPLATE_REPO=$(echo "${git_repository}" | awk -F / '{ print $2 }')
bootstrap_template
;;
#adding Ubuntu Bionic as valid "RELEASE" for POC @hackacad
ubuntu_bionic|bionic|ubuntu-bionic)
#check and install OS dependencies @hackacad
if [ ! "$(sysrc -f /boot/loader.conf -n linprocfs_load)" = "YES" ] && [ ! "$(sysrc -f /boot/loader.conf -n linsysfs_load)" = "YES" ] && [ ! "$(sysrc -f /boot/loader.conf -n tmpfs_load)" = "YES" ]; then
warn "linprocfs_load, linsysfs_load, tmpfs_load not enabled in /boot/loader.conf or linux_enable not active. Should I do that for you? (N|y)"
read answer
case $answer in
[Nn][Oo]|[Nn]|"")
error_exit "Exiting."
;;
[Yy][Ee][Ss]|[Yy])
info "Loading modules"
kldload linux linux64 linprocfs linsysfs tmpfs
info "Persisting modules"
sysrc linux_enable=YES
sysrc -f /boot/loader.conf linprocfs_load=YES
sysrc -f /boot/loader.conf linsysfs_load=YES
sysrc -f /boot/loader.conf tmpfs_load=YES
;;
esac
fi
if which -s debootstrap; then
debootstrap --foreign --arch=amd64 --no-check-gpg bionic "${bastille_releasesdir}"/Ubuntu_1804
else
warn "Debootstrap not found. Should it be installed? (N|y)"
read answer
case $answer in
[Nn][Oo]|[Nn]|"")
error_exit "Exiting. You need to install debootstap before boostrapping a Linux jail."
;;
[Yy][Ee][Ss]|[Yy])
pkg install -y debootstrap
debootstrap --foreign --arch=amd64 --no-check-gpg bionic "${bastille_releasesdir}"/Ubuntu_1804
;;
esac
fi
echo "APT::Cache-Start 251658240;" > "${bastille_releasesdir}"/Ubuntu_1804/etc/apt/apt.conf.d/00aptitude
PLATFORM_OS="Ubuntu/Linux"
LINUX_FLAVOR="bionic"
DIR_BOOTSTRAP="Ubuntu_1804"
ARCH_BOOTSTRAP=${HW_MACHINE_ARCH_LINUX}
debootstrap_release
;;
ubuntu_focal|focal|ubuntu-focal)
#check and install OS dependencies @hackacad
#ToDo: add function 'linux_pre' for sysrc etc.
if [ ! "$(sysrc -f /boot/loader.conf -n linprocfs_load)" = "YES" ] && [ ! "$(sysrc -f /boot/loader.conf -n linsysfs_load)" = "YES" ] && [ ! "$(sysrc -f /boot/loader.conf -n tmpfs_load)" = "YES" ]; then
warn "linprocfs_load, linsysfs_load, tmpfs_load not enabled in /boot/loader.conf or linux_enable not active. Should I do that for you? (N|y)"
read answer
case $answer in
[Nn][Oo]|[Nn]|"")
error_exit "Exiting."
;;
[Yy][Ee][Ss]|[Yy])
info "Loading modules"
kldload linux linux64 linprocfs linsysfs tmpfs
info "Persisting modules"
sysrc linux_enable=YES
sysrc -f /boot/loader.conf linprocfs_load=YES
sysrc -f /boot/loader.conf linsysfs_load=YES
sysrc -f /boot/loader.conf tmpfs_load=YES
;;
esac
fi
if which -s debootstrap; then
debootstrap --foreign --arch=amd64 --no-check-gpg focal "${bastille_releasesdir}"/Ubuntu_2004
else
warn "Debootstrap not found. Should it be installed? (N|y)"
read answer
case $answer in
[Nn][Oo]|[Nn]|"")
error_exit "Exiting. You need to install debootstap before boostrapping a Linux jail."
;;
[Yy][Ee][Ss]|[Yy])
pkg install -y debootstrap
debootstrap --foreign --arch=amd64 --no-check-gpg focal "${bastille_releasesdir}"/Ubuntu_2004
;;
esac
fi
PLATFORM_OS="Ubuntu/Linux"
LINUX_FLAVOR="focal"
DIR_BOOTSTRAP="Ubuntu_2004"
ARCH_BOOTSTRAP=${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
;;
*)
usage
;;
esac
case "${OPTION}" in
update)
bastille update "${RELEASE}"

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -46,6 +46,8 @@ if [ $# -ne 2 ]; then
usage
fi
bastille_root_check
NEWNAME="${1}"
IP="${2}"
@@ -68,7 +70,7 @@ validate_ip() {
error_exit "Invalid: (${TEST_IP})"
fi
done
if ifconfig | grep -qw "${TEST_IP}"; then
if ifconfig | grep -qwF "${TEST_IP}"; then
warn "Warning: IP address already in use (${TEST_IP})."
else
info "Valid: (${IP})."
@@ -109,7 +111,11 @@ update_jailconf_vnet() {
if [ -n "${jail_list}" ]; then
if ! grep -q "e0b_bastille${_num}" "${bastille_jailsdir}"/*/jail.conf; then
uniq_epair="bastille${_num}"
# Update the exec.* with uniq_epair when cloning jails.
sed -i '' "s|vnet.interface = e0b_bastille.*;|vnet.interface = e0b_${uniq_epair};|" "${JAIL_CONFIG}"
sed -i '' "s|exec.prestart += \"jib addm bastille[0-9]|exec.prestart += \"jib addm ${uniq_epair}|" "${JAIL_CONFIG}"
sed -i '' "s|exec.prestart += \"ifconfig e0a_bastille[0-9].*|exec.prestart += \"ifconfig e0a_${uniq_epair} description \\\\\"vnet host interface for Bastille jail ${NEWNAME}\\\\\"\";|" "${JAIL_CONFIG}"
sed -i '' "s|exec.poststop += \"jib destroy bastille[0-9]\";|exec.poststop += \"jib destroy ${uniq_epair}\";|" "${JAIL_CONFIG}"
break
fi
fi
@@ -130,7 +136,7 @@ update_fstab() {
# Update fstab to use the new name
FSTAB_CONFIG="${bastille_jailsdir}/${NEWNAME}/fstab"
if [ -f "${FSTAB_CONFIG}" ]; then
FSTAB_RELEASE=$(grep -owE '([1-9]{2,2})\.[0-9](-RELEASE|-RELEASE-i386|-RC[1-2])|([0-9]{1,2}-stable-build-[0-9]{1,3})|(current-build)-([0-9]{1,3})|(current-BUILD-LATEST)|([0-9]{1,2}-stable-BUILD-LATEST)|(current-BUILD-LATEST)' "${FSTAB_CONFIG}")
FSTAB_RELEASE=$(grep -owE '([1-9]{2,2})\.[0-9](-RELEASE|-RELEASE-i386|-RC[1-5]|-BETA[1-5]|-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
@@ -139,6 +145,8 @@ update_fstab() {
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
}
@@ -164,7 +172,7 @@ clone_jail() {
else
# Just clone the jail directory
# Check if container is running
if [ -n "$(jls name | awk "/^${TARGET}$/")" ]; then
if [ -n "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
error_exit "${TARGET} is running. See 'bastille stop ${TARGET}'."
fi

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -29,6 +29,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
. /usr/local/share/bastille/common.sh
. /usr/local/etc/bastille/bastille.conf
usage() {
error_exit "Usage: bastille cmd TARGET command"
@@ -45,8 +46,37 @@ if [ $# -eq 0 ]; then
usage
fi
bastille_root_check
COUNT=0
RETURN=0
for _jail in ${JAILS}; do
COUNT=$(($COUNT+1))
info "[${_jail}]:"
jexec -l -U root "${_jail}" "$@"
if grep -qw "linsysfs" "${bastille_jailsdir}/${_jail}/fstab"; then
# Allow executing commands on Linux jails.
jexec -l -u root "${_jail}" "$@"
else
jexec -l -U root "${_jail}" "$@"
fi
ERROR_CODE=$?
info "[${_jail}]: ${ERROR_CODE}"
if [ "$COUNT" -eq 1 ]; then
RETURN=${ERROR_CODE}
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,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -33,12 +33,21 @@ COLOR_GREEN=
COLOR_YELLOW=
COLOR_RESET=
bastille_root_check() {
if [ "$(id -u)" -ne 0 ]; then
## permission denied
error_notify "Bastille: Permission Denied"
error_exit "root / sudo / doas required"
fi
}
enable_color() {
. /usr/local/share/bastille/colors.pre.sh
}
# If "NO_COLOR" environment variable is present, disable output colors.
if ! export | grep -q "NO_COLOR"; then
# If "NO_COLOR" environment variable is present, or we aren't speaking to a
# tty, disable output colors.
if [ -z "${NO_COLOR}" -a -t 1 ]; then
enable_color
fi
@@ -60,3 +69,51 @@ info() {
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 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
}

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -35,6 +35,15 @@ usage() {
error_exit "Usage: bastille config TARGET get|set propertyName [newValue]"
}
# we need jail(8) to parse the config file so it can expand variables etc
print_jail_conf() {
# we need to pass a literal \n to jail to get each parameter on its own
# line
jail -f "$1" -e '
'
}
# Handle special-case commands first.
case "$1" in
help|-h|--help)
@@ -46,6 +55,8 @@ if [ $# -eq 1 ] || [ $# -gt 3 ]; then
usage
fi
bastille_root_check
ACTION=$1
shift
@@ -71,22 +82,39 @@ for _jail in ${JAILS}; do
continue
fi
ESCAPED_PROPERTY=$(echo "${PROPERTY}" | sed 's/\./\\\./g')
MATCH_LINE=$(grep "^[[:blank:]]*${ESCAPED_PROPERTY}[[:blank:]=;]" "${FILE}" 2>/dev/null)
MATCH_FOUND=$?
if [ "${ACTION}" = 'get' ]; then
if [ "${MATCH_FOUND}" -ne 0 ]; then
warn "not set"
elif ! echo "${MATCH_LINE}" | grep '=' > /dev/null 2>&1; then
echo "enabled"
_output=$(
print_jail_conf "${FILE}" | awk -F= -v property="${PROPERTY}" '
$1 == property {
# note that we have found the property
found = 1;
# check if there is a value for this property
if (NF == 2) {
# remove any quotes surrounding the string
sub(/^"/, "", $2);
sub(/"$/, "", $2);
print $2;
} else {
# no value, just the property name
print "enabled";
}
exit 0;
}
END {
# if we have not found anything we need to print a special
# string
if (! found) {
print("not set");
# let the caller know that this is a warn condition
exit(120);
}
}'
)
# check if our output is a warning or regular
if [ $? -eq 120 ]; then
warn "${_output}"
else
VALUE=$(echo "${MATCH_LINE}" | sed -E 's/.+= *(.+) *;$/\1/' 2>/dev/null)
if [ $? -ne 0 ]; then
error_notify "Failed to get value."
else
echo "${VALUE}"
fi
echo "${_output}"
fi
else # Setting the value. -- cwells
if [ -n "${VALUE}" ]; then
@@ -99,11 +127,40 @@ for _jail in ${JAILS}; do
LINE=" ${PROPERTY};"
fi
if [ "${MATCH_FOUND}" -ne 0 ]; then # No match, so insert the property at the end. -- cwells
echo "$(awk -v line="${LINE}" '$0 == "}" { print line; } 1 { print $0; }' "${FILE}")" > "${FILE}"
else # Replace the existing value. -- cwells
sed -i '' -E "s/ *${ESCAPED_PROPERTY}[ =;].*/${LINE}/" "${FILE}"
fi
# add the value to the config file, replacing any existing value or, if
# there is none, at the end
#
# awk doesn't have "inplace" editing so we use a temp file
_tmpfile=$(mktemp) || error_exit "unable to set because mktemp failed"
cp "${FILE}" "${_tmpfile}" && \
awk -F= -v line="${LINE}" -v property="${PROPERTY}" '
BEGIN {
# build RE as string as we can not expand vars in RE literals
prop_re = "^[[:space:]]*" property "[[:space:]]*$";
}
$1 ~ prop_re && !found {
# we already have an entry in the config for this property so
# we need to substitute our line here rather than keep the
# existing line
print(line);
# note we have already found the property
found = 1;
# move onto the next line
next;
}
$1 == "}" {
# reached the end of the stanza so if we have not already
# added our line we need to do so now
if (! found) {
print(line);
}
}
{
# print each uninteresting line unchanged
print;
}
' "${_tmpfile}" > "${FILE}"
rm "${_tmpfile}"
fi
done

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -46,6 +46,8 @@ if [ $# -gt 1 ]; then
usage
fi
bastille_root_check
USER="${1}"
validate_user() {

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -46,6 +46,8 @@ if [ $# -ne 0 ]; then
usage
fi
bastille_root_check
convert_symlinks() {
# Work with the symlinks, revert on first cp error
if [ -d "${bastille_releasesdir}/${RELEASE}" ]; then

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -54,6 +54,8 @@ if [ $# -ne 2 ]; then
usage
fi
bastille_root_check
case "${OPTION}" in
-q|--quiet)
OPTION="-a"

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -43,13 +43,15 @@ usage() {
-L | --linux -- This option is intended for testing with Linux jails, this is considered experimental.
-T | --thick -- Creates a thick container, they consume more space as they are self contained and independent.
-V | --vnet -- Enables VNET, VNET containers are attached to a virtual bridge interface for connectivity.
-C | --clone -- Creates a clone container, they are duplicates of the base release, consume low space and preserves changing data.
-B | --bridge -- Enables VNET, VNET containers are attached to a specified, already existing external bridge.
EOF
exit 1
}
running_jail() {
if [ -n "$(jls name | awk "/^${NAME}$/")" ]; then
if [ -n "$(/usr/sbin/jls name | awk "/^${NAME}$/")" ]; then
error_exit "A running jail matches name."
elif [ -d "${bastille_jailsdir}/${NAME}" ]; then
error_exit "Jail: ${NAME} already created."
@@ -67,34 +69,66 @@ validate_name() {
}
validate_ip() {
IPX_ADDR="ip4.addr"
IP6_MODE="disable"
ip6=$(echo "${IP}" | grep -E '^(([a-fA-F0-9:]+$)|([a-fA-F0-9:]+\/[0-9]{1,3}$))')
ipx_addr="ip4.addr"
ip="$1"
ip6=$(echo "${ip}" | grep -E '^(([a-fA-F0-9:]+$)|([a-fA-F0-9:]+\/[0-9]{1,3}$)|SLAAC)')
if [ -n "${ip6}" ]; then
info "Valid: (${ip6})."
IPX_ADDR="ip6.addr"
ipx_addr="ip6.addr"
IP6_MODE="new"
else
local IFS
if echo "${IP}" | grep -Eq '^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))?$'; then
TEST_IP=$(echo "${IP}" | cut -d / -f1)
IFS=.
set ${TEST_IP}
for quad in 1 2 3 4; do
if eval [ \$$quad -gt 255 ]; then
echo "Invalid: (${TEST_IP})"
exit 1
fi
done
if ifconfig | grep -qw "${TEST_IP}"; then
warn "Warning: IP address already in use (${TEST_IP})."
else
info "Valid: (${IP})."
fi
if [ "${ip}" = "DHCP" ]; then
info "Valid: (${ip})."
else
error_exit "Invalid: (${IP})."
local IFS
if echo "${ip}" | grep -Eq '^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))?$'; then
CHARACTER="/"
TEST_SLASH=$(echo "${ip}"
if echo $TEST_SLASH | grep -q "$CHARACTER"
else
exit 1
TEST_MASK=$(echo "${ip}" | cut -d / -f2)
if TEST_MASK=""
echo "missing netmask"
exit 1
TEST_IP=$(echo "${ip}" | cut -d / -f1)
IFS=.
set ${TEST_IP}
for quad in 1 2 3 4; do
if eval [ \$$quad -gt 255 ]; then
echo "Invalid: (${TEST_IP})"
exit 1
fi
done
if ifconfig | grep -qwF "${TEST_IP}"; then
warn "Warning: IP address already in use (${TEST_IP})."
else
info "Valid: (${ip})."
fi
else
error_exit "Invalid: (${ip})."
fi
fi
fi
if echo "${ip}" | grep -qvE '(SLAAC|DHCP|0[.]0[.]0[.]0)'; then
if [ "${ipx_addr}" = "ip4.addr" ]; then
IP4_ADDR="${ip}"
IP4_DEFINITION="${ipx_addr} = ${ip};"
else
IP6_ADDR="${ip}"
IP6_DEFINITION="${ipx_addr} = ${ip};"
fi
fi
}
validate_ips() {
IP6_MODE="disable"
IP4_DEFINITION=""
IP6_DEFINITION=""
IP4_ADDR=""
IP6_ADDR=""
for ip in ${IP}; do
validate_ip "${ip}"
done
}
validate_netif() {
@@ -113,6 +147,13 @@ validate_netconf() {
}
validate_release() {
## ensure the user set the Linux(experimental) option explicitly
if [ -n "${UBUNTU}" ]; then
if [ -z "${LINUX_JAIL}" ]; then
usage
fi
fi
## check release name match, else show usage
if [ -n "${NAME_VERIFY}" ]; then
RELEASE="${NAME_VERIFY}"
@@ -148,7 +189,8 @@ ${NAME} {
securelevel = 2;
interface = ${bastille_jail_conf_interface};
${IPX_ADDR} = ${IP};
${IP4_DEFINITION}
${IP6_DEFINITION}
ip6 = ${IP6_MODE};
}
EOF
@@ -161,42 +203,24 @@ ${NAME} {
mount.fstab = ${bastille_jail_fstab};
path = ${bastille_jail_path};
devfs_ruleset = 4;
enforce_statfs = 1;
exec.start = '/bin/true';
exec.stop = '/bin/true';
persist;
mount.devfs;
allow.mount;
allow.mount.devfs;
interface = ${bastille_jail_conf_interface};
${IPX_ADDR} = ${IP};
${ipx_addr} = ${IP};
ip6 = ${IP6_MODE};
}
EOF
}
generate_vnet_jail_conf() {
## 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 num_range=$(expr "${list_jails_num}" + 1)
for _num in $(seq 0 "${num_range}"); do
if ! grep -q "e0b_bastille${_num}" "${bastille_jailsdir}"/*/jail.conf; then
uniq_epair="bastille${_num}"
break
fi
done
else
uniq_epair="bastille0"
fi
## generate config
NETBLOCK=$(generate_vnet_jail_netblock "$NAME" "${VNET_JAIL_BRIDGE}" "${bastille_jail_conf_interface}")
cat << EOF > "${bastille_jail_conf}"
${NAME} {
devfs_ruleset = 13;
@@ -211,14 +235,48 @@ ${NAME} {
path = ${bastille_jail_path};
securelevel = 2;
vnet;
vnet.interface = e0b_${uniq_epair};
exec.prestart += "jib addm ${uniq_epair} ${bastille_jail_conf_interface}";
exec.poststop += "jib destroy ${uniq_epair}";
${NETBLOCK}
}
EOF
}
post_create_jail() {
# Common config checks and settings.
# Using relative paths here.
# MAKE SURE WE'RE IN THE RIGHT PLACE.
cd "${bastille_jail_path}"
echo
if [ ! -f "${bastille_jail_conf}" ]; then
if [ -z "${bastille_network_loopback}" ] && [ -n "${bastille_network_shared}" ]; then
local bastille_jail_conf_interface=${bastille_network_shared}
fi
if [ -n "${bastille_network_loopback}" ] && [ -z "${bastille_network_shared}" ]; then
local bastille_jail_conf_interface=${bastille_network_loopback}
fi
if [ -n "${INTERFACE}" ]; then
local bastille_jail_conf_interface=${INTERFACE}
fi
fi
if [ ! -f "${bastille_jail_fstab}" ]; then
if [ -z "${THICK_JAIL}" ] && [ -z "${CLONE_JAIL}" ]; then
echo -e "${bastille_releasesdir}/${RELEASE} ${bastille_jail_base} nullfs ro 0 0" > "${bastille_jail_fstab}"
else
touch "${bastille_jail_fstab}"
fi
fi
# Generate the jail configuration file.
if [ -n "${VNET_JAIL}" ]; then
generate_vnet_jail_conf
else
generate_jail_conf
fi
}
create_jail() {
bastille_jail_base="${bastille_jailsdir}/${NAME}/root/.bastille" ## dir
bastille_jail_template="${bastille_jailsdir}/${NAME}/root/.template" ## dir
@@ -233,8 +291,10 @@ create_jail() {
if [ "${bastille_zfs_enable}" = "YES" ]; then
if [ -n "${bastille_zfs_zpool}" ]; then
## create required zfs datasets, mountpoint inherited from system
zfs create ${bastille_zfs_options} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NAME}"
if [ -z "${THICK_JAIL}" ]; then
if [ -z "${CLONE_JAIL}" ]; then
zfs create ${bastille_zfs_options} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NAME}"
fi
if [ -z "${THICK_JAIL}" ] && [ -z "${CLONE_JAIL}" ]; then
zfs create ${bastille_zfs_options} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NAME}/root"
fi
fi
@@ -242,8 +302,10 @@ create_jail() {
mkdir -p "${bastille_jailsdir}/${NAME}/root"
fi
fi
## PoC for Linux jails @hackacad
if [ -n "${LINUX_JAIL}" ]; then
info "\nCreating a linuxjail. This may take a while...\n"
if [ ! -d "${bastille_jail_base}" ]; then
mkdir -p "${bastille_jail_base}"
fi
@@ -255,7 +317,7 @@ create_jail() {
touch "${bastille_jail_path}/dev/shm"
touch "${bastille_jail_path}/dev/fd"
cp -RPf ${bastille_releasesdir}/${RELEASE}/* ${bastille_jail_path}/
echo ${NAME} ${bastille_jail_path}/etc/hostname
echo "${NAME}" > ${bastille_jail_path}/etc/hostname
if [ ! -d "${bastille_jail_template}" ]; then
mkdir -p "${bastille_jail_template}"
@@ -264,14 +326,14 @@ create_jail() {
if [ ! -f "${bastille_jail_fstab}" ]; then
touch "${bastille_jail_fstab}"
fi
echo -e "devfs ${bastille_jail_path}/dev devfs rw 0 0" > "${bastille_jail_fstab}"
echo -e "tmpfs ${bastille_jail_path}/dev/shm tmpfs rw,size=1g,mode=1777 0 0" > "${bastille_jail_fstab}"
echo -e "fdescfs ${bastille_jail_path}/dev/fd fdescfs rw,linrdlnk 0 0" > "${bastille_jail_fstab}"
echo -e "linprocfs ${bastille_jail_path}/proc linprocfs rw 0 0" > "${bastille_jail_fstab}"
echo -e "linsysfs ${bastille_jail_path}/sys linsysfs rw 0 0" > "${bastille_jail_fstab}"
echo -e "/tmp ${bastille_jail_path}/tmp nullfs rw 0 0" > "${bastille_jail_fstab}"
echo -e "devfs ${bastille_jail_path}/dev devfs rw 0 0" >> "${bastille_jail_fstab}"
echo -e "tmpfs ${bastille_jail_path}/dev/shm tmpfs rw,size=1g,mode=1777 0 0" >> "${bastille_jail_fstab}"
echo -e "fdescfs ${bastille_jail_path}/dev/fd fdescfs rw,linrdlnk 0 0" >> "${bastille_jail_fstab}"
echo -e "linprocfs ${bastille_jail_path}/proc linprocfs rw 0 0" >> "${bastille_jail_fstab}"
echo -e "linsysfs ${bastille_jail_path}/sys linsysfs rw 0 0" >> "${bastille_jail_fstab}"
echo -e "/tmp ${bastille_jail_path}/tmp nullfs rw 0 0" >> "${bastille_jail_fstab}"
## removed temporarely / only for X11 jails? @hackacad
#echo -e "/home ${bastille_jail_path}/home nullfs rw 0 0" > "${bastille_jail_fstab}"
#echo -e "/home ${bastille_jail_path}/home nullfs rw 0 0" >> "${bastille_jail_fstab}"
if [ ! -f "${bastille_jail_conf}" ]; then
if [ -z "${bastille_network_loopback}" ] && [ -n "${bastille_network_shared}" ]; then
@@ -287,55 +349,29 @@ create_jail() {
fi
if [ -z "${EMPTY_JAIL}" ] && [ -z "${LINUX_JAIL}" ]; then
if [ ! -d "${bastille_jail_base}" ]; then
mkdir -p "${bastille_jail_base}"
if [ -z "${THICK_JAIL}" ] && [ -z "${CLONE_JAIL}" ]; then
if [ ! -d "${bastille_jail_base}" ]; then
mkdir -p "${bastille_jail_base}"
fi
if [ ! -d "${bastille_jail_template}" ]; then
mkdir -p "${bastille_jail_template}"
fi
fi
if [ ! -d "${bastille_jail_path}/usr/local" ]; then
mkdir -p "${bastille_jail_path}/usr/local"
fi
if [ ! -d "${bastille_jail_template}" ]; then
mkdir -p "${bastille_jail_template}"
fi
# Check and apply required settings.
post_create_jail
if [ ! -f "${bastille_jail_fstab}" ]; then
if [ -z "${THICK_JAIL}" ]; then
echo -e "${bastille_releasesdir}/${RELEASE} ${bastille_jail_base} nullfs ro 0 0" > "${bastille_jail_fstab}"
else
touch "${bastille_jail_fstab}"
fi
fi
if [ ! -f "${bastille_jail_conf}" ]; then
if [ -z "${bastille_network_loopback}" ] && [ -n "${bastille_network_shared}" ]; then
local bastille_jail_conf_interface=${bastille_network_shared}
fi
if [ -n "${bastille_network_loopback}" ] && [ -z "${bastille_network_shared}" ]; then
local bastille_jail_conf_interface=${bastille_network_loopback}
fi
if [ -n "${INTERFACE}" ]; then
local bastille_jail_conf_interface=${INTERFACE}
fi
## generate the jail configuration file
if [ -n "${VNET_JAIL}" ]; then
generate_vnet_jail_conf
else
generate_jail_conf
fi
fi
## using relative paths here
## MAKE SURE WE'RE IN THE RIGHT PLACE
cd "${bastille_jail_path}"
echo
if [ -z "${THICK_JAIL}" ]; then
if [ -z "${THICK_JAIL}" ] && [ -z "${CLONE_JAIL}" ]; then
LINK_LIST="bin boot lib libexec rescue sbin usr/bin usr/include usr/lib usr/lib32 usr/libdata usr/libexec usr/sbin usr/share usr/src"
info "Creating a thinjail...\n"
for _link in ${LINK_LIST}; do
ln -sf /.bastille/${_link} ${_link}
done
# Properly link shared ports on thin jails in read-write.
if [ -d "${bastille_releasesdir}/${RELEASE}/usr/ports" ]; then
if [ ! -d "${bastille_jail_path}/usr/ports" ]; then
@@ -345,7 +381,7 @@ create_jail() {
fi
fi
if [ -z "${THICK_JAIL}" ]; then
if [ -z "${THICK_JAIL}" ] && [ -z "${CLONE_JAIL}" ]; then
## rw
## copy only required files for thin jails
FILE_LIST=".cshrc .profile COPYRIGHT dev etc media mnt net proc root tmp var usr/obj usr/tests"
@@ -359,27 +395,40 @@ create_jail() {
fi
done
else
info "Creating a thickjail. This may take a while..."
if [ "${bastille_zfs_enable}" = "YES" ]; then
if [ -n "${bastille_zfs_zpool}" ]; then
## perform release base replication
if [ -n "${CLONE_JAIL}" ]; then
info "Creating a clonejail...\n"
## clone the release base to the new basejail
SNAP_NAME="bastille-clone-$(date +%Y-%m-%d-%H%M%S)"
zfs snapshot "${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${RELEASE}"@"${SNAP_NAME}"
## sane bastille zfs options
ZFS_OPTIONS=$(echo ${bastille_zfs_options} | sed 's/-o//g')
zfs clone -p "${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${RELEASE}"@"${SNAP_NAME}" \
"${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NAME}/root"
## take a temp snapshot of the base release
SNAP_NAME="bastille-$(date +%Y-%m-%d-%H%M%S)"
zfs snapshot "${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${RELEASE}"@"${SNAP_NAME}"
# Check and apply required settings.
post_create_jail
elif [ -n "${THICK_JAIL}" ]; then
info "Creating a thickjail. This may take a while...\n"
## perform release base replication
## replicate the release base to the new thickjail and set the default mountpoint
zfs send -R "${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${RELEASE}"@"${SNAP_NAME}" | \
zfs receive "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NAME}/root"
zfs set ${ZFS_OPTIONS} mountpoint=none "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NAME}/root"
zfs inherit mountpoint "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NAME}/root"
## sane bastille zfs options
ZFS_OPTIONS=$(echo ${bastille_zfs_options} | sed 's/-o//g')
## cleanup temp snapshots initially
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${RELEASE}"@"${SNAP_NAME}"
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NAME}/root"@"${SNAP_NAME}"
## take a temp snapshot of the base release
SNAP_NAME="bastille-$(date +%Y-%m-%d-%H%M%S)"
zfs snapshot "${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${RELEASE}"@"${SNAP_NAME}"
## replicate the release base to the new thickjail and set the default mountpoint
zfs send -R "${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${RELEASE}"@"${SNAP_NAME}" | \
zfs receive "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NAME}/root"
zfs set ${ZFS_OPTIONS} mountpoint=none "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NAME}/root"
zfs inherit mountpoint "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NAME}/root"
## cleanup temp snapshots initially
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${RELEASE}"@"${SNAP_NAME}"
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NAME}/root"@"${SNAP_NAME}"
fi
if [ "$?" -ne 0 ]; then
## notify and clean stale files/directories
@@ -408,8 +457,16 @@ create_jail() {
ln -s usr/home home
fi
## TZ: configurable (default: Etc/UTC)
ln -s "/usr/share/zoneinfo/${bastille_tzdata}" etc/localtime
## TZ: configurable (default: empty to use host's time zone)
if [ -z "${bastille_tzdata}" ]; then
# Note that if host has no time zone, FreeBSD assumes UTC anyway
if [ -e /etc/localtime ]; then
# uses cp as a way to prevent issues with symlinks if the host happens to use that for tz configuration
cp /etc/localtime etc/localtime
fi
else
ln -s "/usr/share/zoneinfo/${bastille_tzdata}" etc/localtime
fi
# Post-creation jail misc configuration
# Create a dummy fstab file
@@ -454,29 +511,55 @@ create_jail() {
uniq_epair=$(grep vnet.interface "${bastille_jailsdir}/${NAME}/jail.conf" | awk '{print $3}' | sed 's/;//')
_gateway=''
_ifconfig=SYNCDHCP
if [ "${IP}" != "0.0.0.0" ]; then # not using DHCP, so set static address.
if [ -n "${ip6}" ]; then
_ifconfig="inet6 ${IP}"
else
_ifconfig="inet ${IP}"
fi
_gateway6=''
_ifconfig_inet=''
_ifconfig_inet6=''
if echo "${IP}" | grep -qE '(0[.]0[.]0[.]0|DHCP)'; then
# Enable DHCP if requested
_ifconfig_inet=SYNCDHCP
else
# Else apply the default gateway
if [ -n "${bastille_network_gateway}" ]; then
_gateway="${bastille_network_gateway}"
else
if [ -z ${ip6} ]; then
_gateway="$(netstat -4rn | awk '/default/ {print $2}')"
_gateway="$(netstat -rn | awk '/default/ {print $2}')"
fi
fi
# Add IPv4 address (this is empty if DHCP is used)
if [ -n "${IP4_ADDR}" ]; then
_ifconfig_inet="${_ifconfig_inet} inet ${IP4_ADDR}"
fi
# Enable IPv6 if used
if [ "${IP6_MODE}" != "disable" ]; then
_ifconfig_inet6='inet6 -ifdisabled'
if echo "${IP}" | grep -qE 'SLAAC'; then
# Enable SLAAC if requested
_ifconfig_inet6="${_ifconfig_inet6} accept_rtadv"
else
# Else apply the default gateway
if [ -n "${bastille_network_gateway6}" ]; then
_gateway6="${bastille_network_gateway6}"
else
_gateway="$(netstat -6rn | awk '/default/ {print $2}')"
_gateway6="$(netstat -6rn | awk '/default/ {print $2}')"
fi
fi
fi
bastille template "${NAME}" ${bastille_template_vnet} --arg BASE_TEMPLATE="${bastille_template_base}" --arg HOST_RESOLV_CONF="${bastille_resolv_conf}" --arg EPAIR="${uniq_epair}" --arg GATEWAY="${_gateway}" --arg IFCONFIG="${_ifconfig}"
# Add IPv6 address (this is empty if SLAAC is used)
if [ -n "${IP6_ADDR}" ]; then
_ifconfig_inet6="${_ifconfig_inet6} ${IP6_ADDR}"
fi
# Join together IPv4 and IPv6 parts of ifconfig
_ifconfig="${_ifconfig_inet} ${_ifconfig_inet6}"
bastille template "${NAME}" ${bastille_template_vnet} --arg BASE_TEMPLATE="${bastille_template_base}" --arg HOST_RESOLV_CONF="${bastille_resolv_conf}" --arg EPAIR="${uniq_epair}" --arg GATEWAY="${_gateway}" --arg GATEWAY6="${_gateway6}" --arg IFCONFIG="${_ifconfig}"
fi
elif [ -n "${THICK_JAIL}" ]; then
if [ -n "${bastille_template_thick}" ]; then
bastille template "${NAME}" ${bastille_template_thick} --arg BASE_TEMPLATE="${bastille_template_base}" --arg HOST_RESOLV_CONF="${bastille_resolv_conf}"
fi
elif [ -n "${CLONE_JAIL}" ]; then
if [ -n "${bastille_template_clone}" ]; then
bastille template "${NAME}" ${bastille_template_clone} --arg BASE_TEMPLATE="${bastille_template_base}" --arg HOST_RESOLV_CONF="${bastille_resolv_conf}"
fi
elif [ -n "${EMPTY_JAIL}" ]; then
if [ -n "${bastille_template_empty}" ]; then
bastille template "${NAME}" ${bastille_template_empty} --arg BASE_TEMPLATE="${bastille_template_base}" --arg HOST_RESOLV_CONF="${bastille_resolv_conf}"
@@ -514,6 +597,8 @@ help|-h|--help)
;;
esac
bastille_root_check
if echo "$3" | grep '@'; then
BASTILLE_JAIL_IP=$(echo "$3" | awk -F@ '{print $2}')
BASTILLE_JAIL_INTERFACES=$( echo "$3" | awk -F@ '{print $1}')
@@ -522,6 +607,7 @@ fi
## reset this options
EMPTY_JAIL=""
THICK_JAIL=""
CLONE_JAIL=""
VNET_JAIL=""
LINUX_JAIL=""
@@ -544,6 +630,15 @@ while [ $# -gt 0 ]; do
VNET_JAIL="1"
shift
;;
-B|--bridge|bridge)
VNET_JAIL="1"
VNET_JAIL_BRIDGE="1"
shift
;;
-C|--clone|clone)
CLONE_JAIL="1"
shift
;;
-*|--*)
error_notify "Unknown Option."
usage
@@ -556,13 +651,15 @@ done
## validate for combined options
if [ -n "${EMPTY_JAIL}" ]; then
if [ -n "${THICK_JAIL}" ] || [ -n "${VNET_JAIL}" ] || [ -n "${LINUX_JAIL}" ]; then
if [ -n "${CLONE_JAIL}" ] || [ -n "${THICK_JAIL}" ] || [ -n "${VNET_JAIL}" ] || [ -n "${LINUX_JAIL}" ]; then
error_exit "Error: Empty jail option can't be used with other options."
fi
elif [ -n "${LINUX_JAIL}" ]; then
if [ -n "${EMPTY_JAIL}" ] || [ -n "${VNET_JAIL}" ] || [ -n "${THICK_JAIL}" ]; then
if [ -n "${EMPTY_JAIL}" ] || [ -n "${VNET_JAIL}" ] || [ -n "${THICK_JAIL}" ] || [ -n "${CLONE_JAIL}" ]; then
error_exit "Error: Linux jail option can't be used with other options."
fi
elif [ -n "${CLONE_JAIL}" ] && [ -n "${THICK_JAIL}" ]; then
error_exit "Error: Clonejail and Thickjail can't be used together."
fi
NAME="$1"
@@ -595,6 +692,22 @@ if [ -n "${LINUX_JAIL}" ]; then
## check for FreeBSD releases name
NAME_VERIFY=ubuntu_focal
;;
jammy|ubuntu_jammy|ubuntu-jammy)
## check for FreeBSD releases name
NAME_VERIFY=ubuntu_jammy
;;
debian_buster|buster|debian-buster)
## check for FreeBSD releases name
NAME_VERIFY=buster
;;
debian_bullseye|bullseye|debian-bullseye)
## check for FreeBSD releases name
NAME_VERIFY=bullseye
;;
debian_bookworm|bookworm|debian-bookworm)
## check for FreeBSD releases name
NAME_VERIFY=bookworm
;;
*)
error_notify "Unknown Linux."
usage
@@ -646,13 +759,32 @@ if [ -z "${EMPTY_JAIL}" ]; then
validate_release
;;
ubuntu_bionic|bionic|ubuntu-bionic)
UBUNTU="1"
NAME_VERIFY=Ubuntu_1804
validate_release
;;
ubuntu_focal|focal|ubuntu-focal)
UBUNTU="1"
NAME_VERIFY=Ubuntu_2004
validate_release
;;
ubuntu_jammy|jammy|ubuntu-jammy)
UBUNTU="1"
NAME_VERIFY=Ubuntu_2204
validate_release
;;
debian_buster|buster|debian-buster)
NAME_VERIFY=Debian10
validate_release
;;
debian_bullseye|bullseye|debian-bullseye)
NAME_VERIFY=Debian11
validate_release
;;
debian_bookworm|bookworm|debian-bookworm)
NAME_VERIFY=Debian12
validate_release
;;
*)
error_notify "Unknown Release."
usage
@@ -671,7 +803,7 @@ if [ -z "${EMPTY_JAIL}" ]; then
## check if ip address is valid
if [ -n "${IP}" ]; then
validate_ip
validate_ips
else
usage
fi
@@ -720,6 +852,9 @@ fi
if [ -z ${bastille_template_thick+x} ]; then
bastille_template_thick='default/thick'
fi
if [ -z ${bastille_template_clone+x} ]; then
bastille_template_clone='default/clone'
fi
if [ -z ${bastille_template_thin+x} ]; then
bastille_template_thin='default/thin'
fi

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, 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
@@ -40,7 +40,7 @@ destroy_jail() {
bastille_jail_base="${bastille_jailsdir}/${TARGET}" ## dir
bastille_jail_log="${bastille_logsdir}/${TARGET}_console.log" ## file
if [ "$(jls name | awk "/^${TARGET}$/")" ]; then
if [ "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
if [ "${FORCE}" = "1" ]; then
bastille stop "${TARGET}"
else
@@ -118,6 +118,23 @@ destroy_rel() {
if grep -qwo "${TARGET}" "${bastille_jailsdir}/${_jail}/fstab" 2>/dev/null; then
error_notify "Notice: (${_jail}) depends on ${TARGET} base."
BASE_HASCHILD="1"
elif [ "${bastille_zfs_enable}" = "YES" ]; 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
@@ -193,6 +210,8 @@ if [ $# -gt 1 ] || [ $# -lt 1 ]; then
usage
fi
bastille_root_check
## check what should we clean
case "${TARGET}" in
*-CURRENT|*-CURRENT-I386|*-CURRENT-i386|*-current)
@@ -207,27 +226,37 @@ case "${TARGET}" in
;;
*-stable-LAST|*-STABLE-last|*-stable-last|*-STABLE-LAST)
## check for HardenedBSD releases name
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '^([1-9]{2,2})(-stable-last)$' | sed 's/STABLE/stable/g' | sed 's/last/LAST/g')
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '^([1-9]{2,2})(-stable-last)$' | sed 's/STABLE/stable/g;s/last/LAST/g')
destroy_rel
;;
*-stable-build-[0-9]*|*-STABLE-BUILD-[0-9]*)
## check for HardenedBSD(specific stable build releases)
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '([0-9]{1,2})(-stable-build)-([0-9]{1,3})$' | sed 's/BUILD/build/g' | sed 's/STABLE/stable/g')
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '([0-9]{1,2})(-stable-build)-([0-9]{1,3})$' | sed 's/BUILD/build/g;s/STABLE/stable/g')
destroy_rel
;;
*-stable-build-latest|*-stable-BUILD-LATEST|*-STABLE-BUILD-LATEST)
## check for HardenedBSD(latest stable build release)
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '([0-9]{1,2})(-stable-build-latest)$' | sed 's/STABLE/stable/g' | sed 's/build/BUILD/g' | sed 's/latest/LATEST/g')
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '([0-9]{1,2})(-stable-build-latest)$' | sed 's/STABLE/stable/;s/build/BUILD/g;s/latest/LATEST/g')
destroy_rel
;;
current-build-[0-9]*|CURRENT-BUILD-[0-9]*)
## check for HardenedBSD(specific current build releases)
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '(current-build)-([0-9]{1,3})' | sed 's/BUILD/build/g' | sed 's/CURRENT/current/g')
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '(current-build)-([0-9]{1,3})' | sed 's/BUILD/build/g;s/CURRENT/current/g')
destroy_rel
;;
current-build-latest|current-BUILD-LATEST|CURRENT-BUILD-LATEST)
## check for HardenedBSD(latest current build release)
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '(current-build-latest)$' | sed 's/CURRENT/current/g' | sed 's/build/BUILD/g' | sed 's/latest/LATEST/g')
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '(current-build-latest)$' | sed 's/CURRENT/current/;s/build/BUILD/g;s/latest/LATEST/g')
destroy_rel
;;
Ubuntu_1804|Ubuntu_2004|Ubuntu_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
;;
*)

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -48,6 +48,8 @@ elif [ $# -eq 1 ]; then
TARGET_FILENAME="${1}"
fi
bastille_root_check
if [ -z "${EDITOR}" ]; then
EDITOR=vi
fi

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, 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
@@ -49,7 +49,7 @@ usage() {
-v | --verbose -- Be more verbose during the ZFS send operation.
--xz -- Export a ZFS jail using XZ(.xz) compressed image.
Tip: If no option specified, container should be exported to standard output.
Note: If no export option specified, the container should be redirected to standard output.
EOF
exit 1
@@ -71,6 +71,8 @@ if [ $# -gt 5 ] || [ $# -lt 1 ]; then
usage
fi
bastille_root_check
zfs_enable_check() {
# Temporarily disable ZFS so we can create a standard backup archive
if [ "${bastille_zfs_enable}" = "YES" ]; then
@@ -80,6 +82,7 @@ zfs_enable_check() {
TARGET="${1}"
GZIP_EXPORT=
XZ_EXPORT=
SAFE_EXPORT=
USER_EXPORT=
RAW_EXPORT=
@@ -93,67 +96,112 @@ opt_count() {
COMP_OPTION=$(expr ${COMP_OPTION} + 1)
}
# 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
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
fi
shift
;;
esac
done
shift
;;
esac
done
fi
# Validate for combined options
if [ "${COMP_OPTION}" -gt "1" ]; then
@@ -172,7 +220,7 @@ fi
if [ -n "${SAFE_EXPORT}" ]; then
# Check if container is running, otherwise just ignore
if [ -z "$(jls name | awk "/^${TARGET}$/")" ]; then
if [ -z "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
SAFE_EXPORT=
fi
fi
@@ -200,19 +248,19 @@ create_zfs_snap() {
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_export_${DATE}"
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_export_${DATE}"
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_export_${DATE}"
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 "$(jls name | awk "/^${TARGET}$/")" ]; then
if [ -n "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
if [ -n "${SAFE_EXPORT}" ]; then
EXPORT_AS="Safely exporting"
else
@@ -263,7 +311,7 @@ jail_export() {
export_check
# Export the raw container recursively and cleanup temporary snapshots
zfs send ${OPT_ZSEND} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_export_${DATE}" \
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
@@ -271,7 +319,7 @@ jail_export() {
export_check
# Export the raw container recursively and cleanup temporary snapshots
zfs send ${OPT_ZSEND} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_export_${DATE}" | \
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
@@ -279,7 +327,7 @@ jail_export() {
export_check
# Export the container recursively and cleanup temporary snapshots
zfs send ${OPT_ZSEND} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_export_${DATE}" | \
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
@@ -288,8 +336,10 @@ jail_export() {
export_check
# Quietly export the container recursively, user must redirect standard output
zfs send ${OPT_ZSEND} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_export_${DATE}"
clean_zfs_snap
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
@@ -336,7 +386,7 @@ if [ -n "${TARGET}" ]; then
# Check if is a ZFS system
if [ "${bastille_zfs_enable}" != "YES" ]; then
# Check if container is running and ask for stop in non ZFS systems
if [ -n "$(jls name | awk "/^${TARGET}$/")" ]; then
if [ -n "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
error_exit "${TARGET} is running. See 'bastille stop'."
fi
fi

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -46,8 +46,10 @@ if [ $# -ne 0 ]; then
usage
fi
bastille_root_check
for _jail in ${JAILS}; do
bastille_jail_path=$(jls -j "${_jail}" path)
bastille_jail_path=$(/usr/sbin/jls -j "${_jail}" path)
if [ ! -x "${bastille_jail_path}/usr/local/bin/htop" ]; then
error_notify "htop not found on ${_jail}."
elif [ -x "${bastille_jail_path}/usr/local/bin/htop" ]; then

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -59,6 +59,8 @@ if [ $# -gt 3 ] || [ $# -lt 1 ]; then
usage
fi
bastille_root_check
TARGET="${1}"
OPT_FORCE=
USER_IMPORT=
@@ -173,6 +175,7 @@ generate_config() {
# Attempt to read previous config file and set required variables accordingly
# If we can't get a valid interface, fallback to lo1 and warn user
info "Generating jail.conf..."
DEVFS_RULESET=4
if [ "${FILE_EXT}" = ".zip" ]; then
# Gather some bits from foreign/iocage config files
@@ -180,63 +183,88 @@ generate_config() {
if [ -n "${JSON_CONFIG}" ]; then
IPV4_CONFIG=$(grep -wo '\"ip4_addr\": \".*\"' "${JSON_CONFIG}" | tr -d '" ' | sed 's/ip4_addr://')
IPV6_CONFIG=$(grep -wo '\"ip6_addr\": \".*\"' "${JSON_CONFIG}" | tr -d '" ' | sed 's/ip6_addr://')
DEVFS_RULESET=$(grep -wo '\"devfs_ruleset\": \".*\"' "${JSON_CONFIG}" | tr -d '" ' | sed 's/devfs_ruleset://')
DEVFS_RULESET=${DEVFS_RULESET:-4}
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
# 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
# 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}")
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
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
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
# 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
if [ "${FILE_EXT}" = ".tar.gz" ]; then
CONFIG_RELEASE=$(echo ${PROP_CONFIG} | grep -o '[0-9]\{2\}\.[0-9]_RELEASE' | sed 's/_/-/g')
if [ "${IS_THIN_JAIL:-0}" = "1" ]; then
if [ -z "${CONFIG_RELEASE}" ]; then
# Fallback to host version
CONFIG_RELEASE=$(freebsd-version | sed 's/\-[pP].*//')
@@ -257,7 +285,7 @@ generate_config() {
# Generate a basic jail configuration file on foreign imports
cat << EOF > "${bastille_jailsdir}/${TARGET_TRIM}/jail.conf"
${TARGET_TRIM} {
devfs_ruleset = 4;
devfs_ruleset = ${DEVFS_RULESET};
enforce_statfs = 2;
exec.clean;
exec.consolelog = ${bastille_logsdir}/${TARGET_TRIM}_console.log;
@@ -269,9 +297,7 @@ ${TARGET_TRIM} {
path = ${bastille_jailsdir}/${TARGET_TRIM}/root;
securelevel = 2;
interface = ${NETIF_CONFIG};
${IPX_ADDR} = ${IP_CONFIG};
ip6 = ${IP6_MODE};
${NETBLOCK}
}
EOF
}
@@ -334,6 +360,13 @@ update_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
}
@@ -577,7 +610,7 @@ else
fi
# Check if a running jail matches name or already exist
if [ -n "$(jls name | awk "/^${TARGET_TRIM}$/")" ]; then
if [ -n "$(/usr/sbin/jls name | awk "/^${TARGET_TRIM}$/")" ]; then
error_exit "A running jail matches name."
elif [ -n "${TARGET_TRIM}" ]; then
if [ -d "${bastille_jailsdir}/${TARGET_TRIM}" ]; then

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
# Ressource limits added by Sven R github.com/hackacad
#
@@ -55,6 +55,8 @@ if [ $# -ne 2 ]; then
usage
fi
bastille_root_check
OPTION="${1}"
VALUE="${2}"

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -32,88 +32,117 @@
. /usr/local/etc/bastille/bastille.conf
usage() {
error_exit "Usage: bastille list [-j|-a] [release|template|(jail|container)|log|limit|(import|export|backup)]"
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
if [ "$1" == "-j" ]; then
jls -N --libxo json
bastille_root_check
if [ $# -eq 0 ]; then
/usr/sbin/jls -N
fi
if [ "${1}" == "-j" ]; then
/usr/sbin/jls -N --libxo json
exit 0
fi
if [ $# -gt 0 ]; then
# Handle special-case commands first.
case "$1" in
help|-h|--help)
usage
;;
all|-a|--all)
TARGET=
list_all(){
if [ -d "${bastille_jailsdir}" ]; then
DEFAULT_VALUE="-"
SPACER=2
MAX_LENGTH_JAIL_NAME=$(find "${bastille_jailsdir}" -maxdepth 2 -type f -name jail.conf | sed "s/^.*\/\(.*\)\/jail.conf$/\1/" | awk '{ print length($0) }' | sort -nr | head -n 1)
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}" -maxdepth 2 -type f -name jail.conf -exec sed -n "s/^[ ]*ip[4,6].addr[ ]*=[ ]*\(.*\);$/\1/p" {} \; | sed 's/\// /g' | awk '{ print length($1) }' | sort -nr | head -n 1)
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}" -maxdepth 2 -type f -name jail.conf -exec grep -l "vnet;" {} + | sed 's/\(.*\)jail.conf$/grep "ifconfig_vnet0=" \1root\/etc\/rc.conf/' | sh | 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=$(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}" -maxdepth 2 -type f -name jail.conf -exec sed -n "s/^[ ]*host.hostname[ ]*=[ ]*\(.*\);$/\1/p" {} \; | awk '{ print length($0) }' | sort -nr | head -n 1)
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}" -maxdepth 2 -type f -name rdr.conf -exec awk '{ lines++; chars += length($0)} END { chars += lines - 1; print chars }' {} \; | sort -nr | head -n 1)
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}" -maxdepth 2 -type f -name fstab 2> /dev/null -exec grep "/releases/.*/root/.bastille nullfs" {} \; | sed -n "s/^\(.*\) \/.*$/grep \"\^USERLAND_VERSION=\" \1\/bin\/freebsd-version 2\> \/dev\/null/p" | awk '!_[$0]++' | sh | sed -n "s/^USERLAND_VERSION=\"\(.*\)\"$/\1/p" | awk '{ print length($0) }' | sort -nr | head -n 1)
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"" -maxdepth 1 -type f -name freebsd-version 2> /dev/null -exec grep "^USERLAND_VERSION=" {} \; | sed -n "s/^USERLAND_VERSION=\"\(.*\)\"$/\1/p" | awk '{ print length($0) }' | sort -nr | head -n 1)
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}
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_JAIL_RELEASE} -lt 7 ]; then MAX_LENGTH_JAIL_RELEASE=7; fi
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))" ""
JAIL_LIST=$(ls "${bastille_jailsdir}" | sed "s/\n//g")
if [ -n "${TARGET}" ]; then
# Query all info for a specific jail.
JAIL_LIST="${TARGET}"
else
# Query all info for all jails(default).
JAIL_LIST=$(ls "${bastille_jailsdir}" | sed "s/\n//g")
fi
for _JAIL in ${JAIL_LIST}; do
if [ -f "${bastille_jailsdir}/${_JAIL}/jail.conf" ]; then
if [ "$(jls name | awk "/^${_JAIL}$/")" ]; then
JAIL_STATE="Up"
if [ "$(awk '$1 == "vnet;" { print $1 }' "${bastille_jailsdir}/${_JAIL}/jail.conf")" ]; then
JAIL_IP=$(jexec -l ${_JAIL} ifconfig -n vnet0 inet 2> /dev/null | sed -n "/.inet /{s///;s/ .*//;p;}")
if [ ! ${JAIL_IP} ]; then JAIL_IP=$(jexec -l ${_JAIL} ifconfig -n vnet0 inet6 2> /dev/null | awk '/inet6 / && (!/fe80::/ || !/%vnet0/)' | sed -n "/.inet6 /{s///;s/ .*//;p;}"); fi
else
JAIL_IP=$(jls -j ${_JAIL} ip4.addr 2> /dev/null)
if [ ${JAIL_IP} = "-" ]; then JAIL_IP=$(jls -j ${_JAIL} ip6.addr 2> /dev/null); fi
fi
JAIL_HOSTNAME=$(jls -j ${_JAIL} host.hostname 2> /dev/null)
JAIL_PORTS=$(pfctl -a "rdr/${_JAIL}" -Psn 2> /dev/null | awk '{ printf "%s/%s:%s"",",$7,$14,$18 }' | sed "s/,$//")
JAIL_PATH=$(jls -j ${_JAIL} path 2> /dev/null)
JAIL_RELEASE=$(jexec -l ${_JAIL} freebsd-version -u 2> /dev/null)
JAIL_NAME=$(grep -h -m 1 -e "^.* {$" "${bastille_jailsdir}/${_JAIL}/jail.conf" 2> /dev/null | awk '{ print $1 }')
IS_FREEBSD_JAIL=0
if [ -f "${bastille_jailsdir}/${JAIL_NAME}/root/bin/freebsd-version" -o -f "${bastille_jailsdir}/${JAIL_NAME}/root/.bastille/bin/freebsd-version" -o "$(grep -c "/releases/.*/root/.bastille.*nullfs" "${bastille_jailsdir}/${JAIL_NAME}/fstab" 2> /dev/null)" -gt 0 ]; then IS_FREEBSD_JAIL=1; fi
IS_FREEBSD_JAIL=${IS_FREEBSD_JAIL:-0}
IS_LINUX_JAIL=0
if [ "$(grep -c "^linprocfs" "${bastille_jailsdir}/${JAIL_NAME}/fstab" 2> /dev/null)" -gt 0 ]; then IS_LINUX_JAIL=1; fi
IS_LINUX_JAIL=${IS_LINUX_JAIL:-0}
if [ "$(/usr/sbin/jls name | awk "/^${JAIL_NAME}$/")" ]; then
JAIL_STATE="Up"
if [ "$(awk '$1 == "vnet;" { print $1 }' "${bastille_jailsdir}/${JAIL_NAME}/jail.conf" 2> /dev/null)" ]; then
JAIL_IP=$(jexec -l ${JAIL_NAME} ifconfig -n vnet0 inet 2> /dev/null | sed -n "/.inet /{s///;s/ .*//;p;}")
if [ ! "${JAIL_IP}" ]; then JAIL_IP=$(jexec -l ${JAIL_NAME} ifconfig -n vnet0 inet6 2> /dev/null | awk '/inet6 / && (!/fe80::/ || !/%vnet0/)' | sed -n "/.inet6 /{s///;s/ .*//;p;}"); fi
else
JAIL_STATE=$(if [ "$(sed -n "/^${_JAIL} {$/,/^}$/p" "${bastille_jailsdir}/${_JAIL}/jail.conf" | awk '$0 ~ /^'${_JAIL}' \{|\}/ { printf "%s",$0 }')" == "${_JAIL} {}" ]; then echo "Down"; else echo "n/a"; fi)
if [ "$(awk '$1 == "vnet;" { print $1 }' "${bastille_jailsdir}/${_JAIL}/jail.conf")" ]; then
JAIL_IP=$(sed -n 's/^ifconfig_vnet0="\(.*\)"$/\1/p' "${bastille_jailsdir}/${_JAIL}/root/etc/rc.conf" | 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}/jail.conf" | sed "s/\// /g" | awk '{ print $1 }')
fi
JAIL_HOSTNAME=$(sed -n "s/^[ ]*host.hostname[ ]*=[ ]*\(.*\);$/\1/p" "${bastille_jailsdir}/${_JAIL}/jail.conf")
if [ -f "${bastille_jailsdir}/${_JAIL}/rdr.conf" ]; then JAIL_PORTS=$(awk '$1 ~ /^[tcp|udp]/ { printf "%s/%s:%s,",$1,$2,$3 }' "${bastille_jailsdir}/${_JAIL}/rdr.conf" | sed "s/,$//"); else JAIL_PORTS=""; fi
JAIL_PATH=$(sed -n "s/^[ ]*path[ ]*=[ ]*\(.*\);$/\1/p" "${bastille_jailsdir}/${_JAIL}/jail.conf")
if [ ${JAIL_PATH} ]; then
if [ -f "${JAIL_PATH}/bin/freebsd-version" ]; then
JAIL_RELEASE=$(sed -n "s/^USERLAND_VERSION=\"\(.*\)\"$/\1/p" "${JAIL_PATH}/bin/freebsd-version")
else
JAIL_RELEASE=$(grep "/releases/.*/root/.bastille nullfs" "${bastille_jailsdir}/${_JAIL}/fstab" 2> /dev/null | sed -n "s/^\(.*\) \/.*$/grep \"\^USERLAND_VERSION=\" \1\/bin\/freebsd-version 2\> \/dev\/null/p" | awk '!_[$0]++' | sh | sed -n "s/^USERLAND_VERSION=\"\(.*\)\"$/\1/p")
fi
else
JAIL_RELEASE=""
fi
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
if [ ${#JAIL_PORTS} -gt ${MAX_LENGTH_JAIL_PORTS} ]; then JAIL_PORTS="$(echo ${JAIL_PORTS} | cut -c-$((${MAX_LENGTH_JAIL_PORTS} - 3)))..."; 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}}
@@ -121,48 +150,91 @@ if [ $# -gt 0 ]; then
JAIL_HOSTNAME=${JAIL_HOSTNAME:-${DEFAULT_VALUE}}
JAIL_RELEASE=${JAIL_RELEASE:-${DEFAULT_VALUE}}
JAIL_PATH=${JAIL_PATH:-${DEFAULT_VALUE}}
printf " ${_JAIL}%*s${JAIL_STATE}%*s${JAIL_IP}%*s${JAIL_PORTS}%*s${JAIL_HOSTNAME}%*s${JAIL_RELEASE}%*s${JAIL_PATH}\n" "$((${MAX_LENGTH_JAIL_NAME} - ${#_JAIL} + ${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}))" ""
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
;;
release|releases)
if [ -d "${bastille_releasesdir}" ]; then
REL_LIST=$(ls "${bastille_releasesdir}" | sed "s/\n//g")
for _REL in ${REL_LIST}; do
if [ -f "${bastille_releasesdir}/${_REL}/root/.profile" ]; then
}
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
done
fi
fi
done
fi
}
list_template(){
find "${bastille_templatesdir}" -type d -maxdepth 2
}
list_jail(){
if [ -d "${bastille_jailsdir}" ]; then
JAIL_LIST=$(ls "${bastille_jailsdir}" | sed "s/\n//g")
for _JAIL in ${JAIL_LIST}; do
if [ -f "${bastille_jailsdir}/${_JAIL}/jail.conf" ]; then
echo "${_JAIL}"
fi
done
fi
}
list_log(){
find "${bastille_logsdir}" -type f -maxdepth 1
}
list_limit(){
rctl -h jail:
}
list_import(){
ls "${bastille_backupsdir}" | grep -v ".sha256$"
}
if [ $# -gt 0 ]; then
# Handle special-case commands first.
case "${1}" in
all|-a|--all)
list_all
;;
release|releases)
list_release
;;
template|templates)
find "${bastille_templatesdir}" -type d -maxdepth 2
list_template
;;
jail|jails|container|containers)
if [ -d "${bastille_jailsdir}" ]; then
JAIL_LIST=$(ls "${bastille_jailsdir}" | sed "s/\n//g")
for _JAIL in ${JAIL_LIST}; do
if [ -f "${bastille_jailsdir}/${_JAIL}/jail.conf" ]; then
echo "${_JAIL}"
fi
done
fi
list_jail
;;
log|logs)
find "${bastille_logsdir}" -type f -maxdepth 1
list_log
;;
limit|limits)
rctl -h jail:
list_limit
;;
import|imports|export|exports|backup|backups)
ls "${bastille_backupsdir}" | grep -v ".sha256$"
list_import
exit 0
;;
*)
usage
# Check if we want to query all info for a specific jail instead.
if [ -f "${bastille_jailsdir}/${1}/jail.conf" ]; then
TARGET="${1}"
list_all
else
usage
fi
;;
esac
fi

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -50,6 +50,8 @@ else
_fstab="$@"
fi
bastille_root_check
## assign needed variables
_hostpath=$(echo "${_fstab}" | awk '{print $1}')
_jailpath=$(echo "${_fstab}" | awk '{print $2}')
@@ -65,8 +67,10 @@ if [ -z "${_hostpath}" ] || [ -z "${_jailpath}" ] || [ -z "${_type}" ] || [ -z "
exit 1
fi
## if host path doesn't exist or type is not "nullfs"
if [ ! -d "${_hostpath}" ] || [ "${_type}" != "nullfs" ]; then
## if host path doesn't exist, type is not "nullfs" or are using advanced mount type "tmpfs,linprocfs,linsysfs, fdescfs, procfs"
if [ "${_hostpath}" == "tmpfs" -a "$_type" == "tmpfs" ] || [ "${_hostpath}" == "linprocfs" -a "${_type}" == "linprocfs" ] || [ "${_hostpath}" == "linsysfs" -a "${_type}" == "linsysfs" ] || [ "${_hostpath}" == "proc" -a "${_type}" == "procfs" ] || [ "${_hostpath}" == "fdesc" -a "${_type}" == "fdescfs" ] ; then
warn "Detected advanced mount type ${_hostpath}"
elif [ ! -d "${_hostpath}" ] || [ "${_type}" != "nullfs" ]; then
error_notify "Detected invalid host path or incorrect mount type in FSTAB."
warn "Format: /host/path jail/path nullfs ro 0 0"
warn "Read: ${_fstab}"
@@ -93,25 +97,25 @@ for _jail in ${JAILS}; do
info "[${_jail}]:"
## aggregate variables into FSTAB entry
_jailpath="${bastille_jailsdir}/${_jail}/root/${_jailpath}"
_fstab_entry="${_hostpath} ${_jailpath} ${_type} ${_perms} ${_checks}"
_fullpath="${bastille_jailsdir}/${_jail}/root/${_jailpath}"
_fstab_entry="${_hostpath} ${_fullpath} ${_type} ${_perms} ${_checks}"
## Create mount point if it does not exist. -- cwells
if [ ! -d "${_jailpath}" ]; then
if ! mkdir -p "${_jailpath}"; then
if [ ! -d "${_fullpath}" ]; then
if ! mkdir -p "${_fullpath}"; then
error_exit "Failed to create mount point inside jail."
fi
fi
## if entry doesn't exist, add; else show existing entry
if ! egrep -q "[[:blank:]]${_jailpath}[[:blank:]]" "${bastille_jailsdir}/${_jail}/fstab" 2> /dev/null; then
if ! egrep -q "[[:blank:]]${_fullpath}[[:blank:]]" "${bastille_jailsdir}/${_jail}/fstab" 2> /dev/null; then
if ! echo "${_fstab_entry}" >> "${bastille_jailsdir}/${_jail}/fstab"; then
error_exit "Failed to create fstab entry: ${_fstab_entry}"
fi
echo "Added: ${_fstab_entry}"
else
warn "Mountpoint already present in ${bastille_jailsdir}/${_jail}/fstab"
egrep "[[:blank:]]${_jailpath}[[:blank:]]" "${bastille_jailsdir}/${_jail}/fstab"
egrep "[[:blank:]]${_fullpath}[[:blank:]]" "${bastille_jailsdir}/${_jail}/fstab"
fi
mount -F "${bastille_jailsdir}/${_jail}/fstab" -a
echo

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, 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
@@ -31,7 +31,7 @@
. /usr/local/share/bastille/common.sh
usage() {
error_exit "Usage: bastille pkg TARGET command [args]"
error_exit "Usage: bastille pkg [-H|--host] TARGET command [args]"
}
# Handle special-case commands first.
@@ -45,12 +45,34 @@ if [ $# -lt 1 ]; then
usage
fi
bastille_root_check
errors=0
for _jail in ${JAILS}; do
info "[${_jail}]:"
if [ -f "/usr/sbin/pkg" ]; then
jexec -l "${_jail}" /usr/sbin/pkg "$@"
bastille_jail_path=$(/usr/sbin/jls -j "${_jail}" path)
if [ -f "/usr/sbin/mport" ]; then
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
jexec -l "${_jail}" /usr/sbin/mport "$@"
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

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -32,7 +32,7 @@
. /usr/local/etc/bastille/bastille.conf
usage() {
error_exit "Usage: bastille rdr TARGET [clear|list|(tcp|udp host_port jail_port)]"
error_exit "Usage: bastille rdr TARGET [clear|list|(tcp|udp host_port jail_port [log ['(' logopts ')'] ] )]"
}
# Handle special-case commands first.
@@ -46,38 +46,53 @@ if [ $# -lt 2 ]; then
usage
fi
bastille_root_check
TARGET="${1}"
JAIL_NAME=""
JAIL_IP=""
JAIL_IP6=""
EXT_IF=""
shift
# Can only redirect to single jail
if [ "${TARGET}" = 'ALL' ]; then
error_exit "Can only redirect to a single jail."
fi
# Check if jail name is valid
JAIL_NAME=$(jls -j "${TARGET}" name 2>/dev/null)
if [ -z "${JAIL_NAME}" ]; then
error_exit "Jail not found: ${TARGET}"
fi
# Check if jail ip4 address (ip4.addr) is valid (non-VNET only)
if [ "$(bastille config $TARGET get vnet)" != 'enabled' ]; then
JAIL_IP=$(jls -j "${TARGET}" ip4.addr 2>/dev/null)
if [ -z "${JAIL_IP}" -o "${JAIL_IP}" = "-" ]; then
error_exit "Jail IP not found: ${TARGET}"
check_jail_validity() {
# Can only redirect to single jail
if [ "${TARGET}" = 'ALL' ]; then
error_exit "Can only redirect to a single jail."
fi
fi
# Check if rdr-anchor is defined in pf.conf
if ! (pfctl -sn | grep rdr-anchor | grep 'rdr/\*' >/dev/null); then
error_exit "rdr-anchor not found in pf.conf"
fi
# Check if jail name is valid
JAIL_NAME=$(/usr/sbin/jls -j "${TARGET}" name 2>/dev/null)
if [ -z "${JAIL_NAME}" ]; then
error_exit "Jail not found: ${TARGET}"
fi
# Check if ext_if is defined in pf.conf
EXT_IF=$(grep '^[[:space:]]*ext_if[[:space:]]*=' /etc/pf.conf)
if [ -z "${EXT_IF}" ]; then
error_exit "ext_if not defined in pf.conf"
fi
# Check if jail ip4 address (ip4.addr) is valid (non-VNET only)
if [ "$(bastille config $TARGET get vnet)" != 'enabled' ]; then
JAIL_IP=$(/usr/sbin/jls -j "${TARGET}" ip4.addr 2>/dev/null)
if [ -z "${JAIL_IP}" -o "${JAIL_IP}" = "-" ]; then
error_exit "Jail IP not found: ${TARGET}"
fi
fi
# Check if 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
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
}
# function: write rule to rdr.conf
persist_rdr_rule() {
@@ -86,30 +101,111 @@ if ! grep -qs "$1 $2 $3" "${bastille_jailsdir}/${JAIL_NAME}/rdr.conf"; then
fi
}
persist_rdr_log_rule() {
proto=$1;host_port=$2;jail_port=$3;
shift 3;
log=$@;
if ! grep -qs "$proto $host_port $jail_port $log" "${bastille_jailsdir}/${JAIL_NAME}/rdr.conf"; then
echo "$proto $host_port $jail_port $log" >> "${bastille_jailsdir}/${JAIL_NAME}/rdr.conf"
fi
}
# function: load rdr rule via pfctl
load_rdr_rule() {
( pfctl -a "rdr/${JAIL_NAME}" -Psn;
printf '%s\nrdr pass on $ext_if inet proto %s to port %s -> %s port %s\n' "$EXT_IF" "$1" "$2" "$JAIL_IP" "$3" ) \
printf '%s\nrdr pass on $%s inet proto %s to port %s -> %s port %s\n' "$EXT_IF" "${bastille_network_pf_ext_if}" "$1" "$2" "$JAIL_IP" "$3" ) \
| pfctl -a "rdr/${JAIL_NAME}" -f-
if [ -n "$JAIL_IP6" ]; then
( pfctl -a "rdr/${JAIL_NAME}" -Psn;
printf '%s\nrdr pass on $%s inet proto %s to port %s -> %s port %s\n' "$EXT_IF" "${bastille_network_pf_ext_if}" "$1" "$2" "$JAIL_IP6" "$3" ) \
| pfctl -a "rdr/${JAIL_NAME}" -f-
fi
}
# function: load rdr rule with log via pfctl
load_rdr_log_rule() {
proto=$1;host_port=$2;jail_port=$3;
shift 3;
log=$@
( pfctl -a "rdr/${JAIL_NAME}" -Psn;
printf '%s\nrdr pass %s on $%s inet proto %s to port %s -> %s port %s\n' "$EXT_IF" "$log" "${bastille_network_pf_ext_if}" "$proto" "$host_port" "$JAIL_IP" "$jail_port" ) \
| pfctl -a "rdr/${JAIL_NAME}" -f-
if [ -n "$JAIL_IP6" ]; then
( pfctl -a "rdr/${JAIL_NAME}" -Psn;
printf '%s\nrdr pass %s on $%s inet proto %s to port %s -> %s port %s\n' "$EXT_IF" "$log" "${bastille_network_pf_ext_if}" "$proto" "$host_port" "$JAIL_IP6" "$jail_port" ) \
| pfctl -a "rdr/${JAIL_NAME}" -f-
fi
}
while [ $# -gt 0 ]; do
case "$1" in
list)
pfctl -a "rdr/${JAIL_NAME}" -Psn 2>/dev/null
if [ "${TARGET}" = 'ALL' ]; then
for JAIL_NAME in $(ls "${bastille_jailsdir}" | sed "s/\n//g"); do
echo "${JAIL_NAME} redirects:"
pfctl -a "rdr/${JAIL_NAME}" -Psn 2>/dev/null
done
else
check_jail_validity
pfctl -a "rdr/${JAIL_NAME}" -Psn 2>/dev/null
fi
shift
;;
clear)
pfctl -a "rdr/${JAIL_NAME}" -Fn
if [ "${TARGET}" = 'ALL' ]; then
for JAIL_NAME in $(ls "${bastille_jailsdir}" | sed "s/\n//g"); do
echo "${JAIL_NAME} redirects:"
pfctl -a "rdr/${JAIL_NAME}" -Fn
done
else
check_jail_validity
pfctl -a "rdr/${JAIL_NAME}" -Fn
fi
shift
;;
tcp|udp)
if [ $# -lt 3 ]; then
usage
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
persist_rdr_rule $1 $2 $3
load_rdr_rule $1 $2 $3
shift 3
;;
*)
usage

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -56,6 +56,8 @@ if [ $# -ne 1 ]; then
usage
fi
bastille_root_check
NEWNAME="${1}"
update_jailconf() {
@@ -68,6 +70,9 @@ update_jailconf() {
sed -i '' "s|path.*=.*;|path = ${bastille_jailsdir}/${NEWNAME}/root;|" "${JAIL_CONFIG}"
sed -i '' "s|mount.fstab.*=.*;|mount.fstab = ${bastille_jailsdir}/${NEWNAME}/fstab;|" "${JAIL_CONFIG}"
sed -i '' "s|${TARGET}.*{|${NEWNAME} {|" "${JAIL_CONFIG}"
# Rename vnet interface
sed -i '' "/vnet.interface/s|_${TARGET}\";|_${NEWNAME}\";|" "${JAIL_CONFIG}"
sed -i '' "/ifconfig/s|_${TARGET}|_${NEWNAME}|" "${JAIL_CONFIG}"
fi
fi
}
@@ -76,13 +81,22 @@ 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|-RC[1-2])|([0-9]{1,2}-stable-build-[0-9]{1,3})|(current-build)-([0-9]{1,3})|(current-BUILD-LATEST)|([0-9]{1,2}-stable-BUILD-LATEST)|(current-BUILD-LATEST)' "${FSTAB_CONFIG}")
FSTAB_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}"
# 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-2])|([0-9]{1,2}-stable-build-[0-9]{1,3})|(current-build)-([0-9]{1,3})|(current-BUILD-LATEST)|([0-9]{1,2}-stable-BUILD-LATEST)|(current-BUILD-LATEST)' "${FSTAB_CONFIG}")
FSTAB_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

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, 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

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -45,6 +45,8 @@ if [ $# -lt 1 -o $# -gt 2 ]; then
usage
fi
bastille_root_check
for _jail in ${JAILS}; do
info "[${_jail}]:"
jexec -l "${_jail}" /usr/sbin/service "$@"

View File

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

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -46,6 +46,8 @@ if [ $# -gt 1 ] || [ $# -lt 1 ]; then
usage
fi
bastille_root_check
TARGET="${1}"
shift
@@ -62,11 +64,11 @@ fi
for _jail in ${JAILS}; do
## test if running
if [ "$(jls name | awk "/^${_jail}$/")" ]; then
if [ "$(/usr/sbin/jls name | awk "/^${_jail}$/")" ]; then
error_notify "[${_jail}]: Already started."
## test if not running
elif [ ! "$(jls name | awk "/^${_jail}$/")" ]; then
elif [ ! "$(/usr/sbin/jls name | awk "/^${_jail}$/")" ]; then
# Verify that the configured interface exists. -- cwells
if [ "$(bastille config $_jail get vnet)" != 'enabled' ]; then
_interface=$(bastille config $_jail get interface)
@@ -77,14 +79,14 @@ for _jail in ${JAILS}; do
fi
## warn if matching configured (but not online) ip4.addr, ignore if there's no ip4.addr entry
ip=$(grep 'ip4.addr' "${bastille_jailsdir}/${_jail}/jail.conf" | awk '{print $3}' | sed 's/\;//g')
ip=$(bastille config "${_jail}" get ip4.addr)
if [ -n "${ip}" ]; then
if ifconfig | grep -w "${ip}" >/dev/null; then
if ifconfig | grep -wF "${ip}" >/dev/null; then
error_notify "Error: IP address (${ip}) already in use."
continue
fi
## add ip4.addr to firewall table:jails
pfctl -q -t jails -T add "${ip}"
## add ip4.addr to firewall table
pfctl -q -t "${bastille_network_pf_table}" -T add "${ip}"
fi
## start the container

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -46,15 +46,13 @@ if [ $# -ne 0 ]; then
usage
fi
bastille_root_check
for _jail in ${JAILS}; do
## test if running
if [ "$(jls name | awk "/^${_jail}$/")" ]; then
## remove ip4.addr from firewall table:jails
if [ -n "${bastille_network_loopback}" ]; then
if grep -qw "interface.*=.*${bastille_network_loopback}" "${bastille_jailsdir}/${_jail}/jail.conf"; then
pfctl -q -t jails -T delete "$(jls -j ${_jail} ip4.addr)"
fi
fi
if [ "$(/usr/sbin/jls name | awk "/^${_jail}$/")" ]; then
## Capture ip4.addr address while still running
_ip="$(/usr/sbin/jls -j ${_jail} ip4.addr)"
# Check if pfctl is present
if which -s pfctl; then
@@ -73,6 +71,13 @@ for _jail in ${JAILS}; do
## stop container
info "[${_jail}]:"
jail -f "${bastille_jailsdir}/${_jail}/jail.conf" -r "${_jail}"
## remove (captured above) ip4.addr from firewall table
if [ -n "${bastille_network_loopback}" -a ! -z "${_ip}" ]; then
if grep -qw "interface.*=.*${bastille_network_loopback}" "${bastille_jailsdir}/${_jail}/jail.conf"; then
pfctl -q -t "${bastille_network_pf_table}" -T delete "${_ip}"
fi
fi
fi
echo
done

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -45,6 +45,8 @@ if [ $# -lt 1 ]; then
usage
fi
bastille_root_check
for _jail in ${JAILS}; do
info "[${_jail}]:"
jexec -l "${_jail}" /usr/sbin/sysrc "$@"

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,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -116,6 +116,8 @@ if [ $# -lt 1 ]; then
bastille_usage
fi
bastille_root_check
## global variables
TEMPLATE="${1}"
bastille_template=${bastille_templatesdir}/${TEMPLATE}
@@ -186,7 +188,11 @@ case ${TEMPLATE} in
;;
*/*)
if [ ! -d "${bastille_templatesdir}/${TEMPLATE}" ]; then
error_exit "${TEMPLATE} not found."
if [ ! -d ${TEMPLATE} ]; then
error_exit "${TEMPLATE} not found."
else
bastille_template=${TEMPLATE}
fi
fi
;;
*)
@@ -222,9 +228,10 @@ for _jail in ${JAILS}; do
info "Applying template: ${TEMPLATE}..."
## jail-specific variables.
bastille_jail_path=$(jls -j "${_jail}" path)
bastille_jail_path=$(/usr/sbin/jls -j "${_jail}" path)
if [ "$(bastille config $TARGET get vnet)" != 'enabled' ]; then
_jail_ip=$(jls -j "${_jail}" ip4.addr 2>/dev/null)
_jail_ip=$(/usr/sbin/jls -j "${_jail}" ip4.addr 2>/dev/null)
_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
@@ -247,7 +254,7 @@ for _jail in ${JAILS}; do
# Build a list of sed commands like this: -e 's/${username}/root/g' -e 's/${domain}/example.com/g'
# Values provided by default (without being defined by the user) are listed here. -- cwells
ARG_REPLACEMENTS="-e 's/\${JAIL_IP}/${_jail_ip}/g' -e 's/\${JAIL_NAME}/${_jail}/g'"
ARG_REPLACEMENTS="-e 's/\${JAIL_IP}/${_jail_ip}/g' -e 's/\${JAIL_IP6}/${_jail_ip6}/g' -e 's/\${JAIL_NAME}/${_jail}/g'"
# This is parsed outside the HOOKS loop so an ARG file can be used with a Bastillefile. -- cwells
if [ -s "${bastille_template}/ARG" ]; then
while read _line; do

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

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

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -45,6 +45,8 @@ if [ $# -ne 0 ]; then
usage
fi
bastille_root_check
for _jail in ${JAILS}; do
info "[${_jail}]:"
jexec -l "${_jail}" /usr/bin/top

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -46,6 +46,8 @@ if [ $# -ne 1 ]; then
usage
fi
bastille_root_check
MOUNT_PATH=$1
for _jail in ${JAILS}; do

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -32,7 +32,7 @@
. /usr/local/etc/bastille/bastille.conf
usage() {
error_exit "Usage: bastille update [release|container] | [force]"
error_exit "Usage: bastille update [release|container|template] | [force]"
}
# Handle special-case commands first.
@@ -46,6 +46,8 @@ if [ $# -gt 2 ] || [ $# -lt 1 ]; then
usage
fi
bastille_root_check
TARGET="${1}"
OPTION="${2}"
@@ -73,9 +75,16 @@ if freebsd-version | grep -qi HBSD; then
error_exit "Not yet supported on HardenedBSD."
fi
# Check for alternate/unsupported archs
arch_check() {
if echo "${TARGET}" | grep -w "[0-9]\{1,2\}\.[0-9]\-RELEASE\-i386"; then
ARCH_I386="1"
fi
}
jail_check() {
# Check if the jail is thick and is running
if [ ! "$(jls name | awk "/^${TARGET}$/")" ]; then
if [ ! "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
error_exit "[${TARGET}]: Not started. See 'bastille start ${TARGET}'."
else
if grep -qw "${bastille_jailsdir}/${TARGET}/root/.bastille" "${bastille_jailsdir}/${TARGET}/fstab"; then
@@ -103,15 +112,61 @@ jail_update() {
release_update() {
# Update a release base(affects child containers)
if [ -d "${bastille_releasesdir}/${TARGET}" ]; then
TARGET_TRIM="${TARGET}"
if [ -n "${ARCH_I386}" ]; then
TARGET_TRIM=$(echo "${TARGET}" | sed 's/-i386//')
fi
env PAGER="/bin/cat" freebsd-update ${OPTION} --not-running-from-cron -b "${bastille_releasesdir}/${TARGET}" \
fetch install --currently-running "${TARGET}"
fetch install --currently-running "${TARGET_TRIM}"
else
error_exit "${TARGET} not found. See 'bastille bootstrap'."
fi
}
template_update() {
# Update a template
_template_path=${bastille_templatesdir}/${BASTILLE_TEMPLATE}
if [ -d $_template_path ]; then
info "[${BASTILLE_TEMPLATE}]:"
git -C $_template_path pull ||\
error_notify "${BASTILLE_TEMPLATE} update unsuccessful."
bastille verify "${BASTILLE_TEMPLATE}"
else
error_exit "${BASTILLE_TEMPLATE} not found. See 'bastille bootstrap'."
fi
}
templates_update() {
# Update all templates
_updated_templates=0
if [ -d ${bastille_templatesdir} ]; then
for _template_path in $(ls -d ${bastille_templatesdir}/*/*); do
if [ -d $_template_path/.git ]; then
BASTILLE_TEMPLATE=$(echo "$_template_path" | awk -F / '{ print $(NF-1) "/" $NF }')
template_update
_updated_templates=$((_updated_templates+1))
fi
done
fi
if [ "$_updated_templates" -ne "0" ]; then
info "$_updated_templates templates updated."
else
error_exit "no templates found. See 'bastille bootstrap'."
fi
}
# Check what we should update
if echo "${TARGET}" | grep -q "[0-9]\{2\}.[0-9]-RELEASE"; then
if [ "${TARGET}" = 'TEMPLATES' ]; then
templates_update
elif echo "${TARGET}" | grep -Eq '^[A-Za-z0-9_-]+/[A-Za-z0-9_-]+$'; then
BASTILLE_TEMPLATE="${TARGET}"
template_update
elif echo "${TARGET}" | grep -q "[0-9]\{2\}.[0-9]-RELEASE"; then
arch_check
release_update
else
jail_update

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -46,6 +46,8 @@ if [ $# -gt 3 ] || [ $# -lt 2 ]; then
usage
fi
bastille_root_check
TARGET="$1"
NEWRELEASE="$2"
OPTION="$3"
@@ -76,7 +78,7 @@ esac
jail_check() {
# Check if the jail is thick and is running
if [ ! "$(jls name | awk "/^${TARGET}$/")" ]; then
if [ ! "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
error_exit "[${TARGET}]: Not started. See 'bastille start ${TARGET}'."
else
if grep -qw "${bastille_jailsdir}/${TARGET}/root/.bastille" "${bastille_jailsdir}/${TARGET}/fstab"; then

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, 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
@@ -51,6 +51,22 @@ verify_release() {
fi
}
handle_template_include() {
case ${TEMPLATE_INCLUDE} in
http?://*/*/*)
bastille bootstrap "${TEMPLATE_INCLUDE}"
;;
*/*)
BASTILLE_TEMPLATE_USER=$(echo "${TEMPLATE_INCLUDE}" | awk -F / '{ print $1 }')
BASTILLE_TEMPLATE_REPO=$(echo "${TEMPLATE_INCLUDE}" | awk -F / '{ print $2 }')
bastille verify "${BASTILLE_TEMPLATE_USER}/${BASTILLE_TEMPLATE_REPO}"
;;
*)
error_exit "Template INCLUDE content not recognized."
;;
esac
}
verify_template() {
_template_path=${bastille_templatesdir}/${BASTILLE_TEMPLATE}
_hook_validate=0
@@ -75,20 +91,8 @@ verify_template() {
echo
while read _include; do
info "[${_hook}]:[${_include}]:"
case ${_include} in
http?://*/*/*)
bastille bootstrap "${_include}"
;;
*/*)
BASTILLE_TEMPLATE_USER=$(echo "${_include}" | awk -F / '{ print $1 }')
BASTILLE_TEMPLATE_REPO=$(echo "${_include}" | awk -F / '{ print $2 }')
bastille verify "${BASTILLE_TEMPLATE_USER}/${BASTILLE_TEMPLATE_REPO}"
;;
*)
error_exit "Template INCLUDE content not recognized."
;;
esac
TEMPLATE_INCLUDE="${_include}"
handle_template_include
done < "${_path}"
## if tree; tree -a bastille_template/_dir
@@ -105,6 +109,18 @@ verify_template() {
fi
echo
done < "${_path}"
elif [ "${_hook}" = 'Bastillefile' ]; then
info "[${_hook}]:"
cat "${_path}"
while read _line; do
_cmd=$(echo "${_line}" | awk '{print tolower($1);}')
## if include; recursive verify
if [ "${_cmd}" = 'include' ]; then
TEMPLATE_INCLUDE=$(echo "${_line}" | awk '{print $2;}')
handle_template_include
fi
done < "${_path}"
echo
else
info "[${_hook}]:"
cat "${_path}"
@@ -138,6 +154,8 @@ if [ $# -gt 1 ] || [ $# -lt 1 ]; then
bastille_usage
fi
bastille_root_check
case "$1" in
*-RELEASE|*-release|*-RC1|*-rc1|*-RC2|*-rc2)
RELEASE=$1

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2023, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -43,6 +43,14 @@ for _jail in ${JAILS}; do
done
}
zfs_destroy_snapshot() {
for _jail in ${JAILS}; do
info "[${_jail}]:"
zfs destroy -r "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${_jail}"@"${TAG}"
echo
done
}
zfs_set_value() {
for _jail in ${JAILS}; do
info "[${_jail}]:"
@@ -74,6 +82,8 @@ help|-h|--help)
;;
esac
bastille_root_check
## check ZFS enabled
if [ ! "${bastille_zfs_enable}" = "YES" ]; then
error_exit "ZFS not enabled."
@@ -101,6 +111,10 @@ snap|snapshot)
TAG=$2
zfs_snapshot
;;
destroy_snap|destroy_snapshot)
TAG=$2
zfs_destroy_snapshot
;;
df|usage)
zfs_disk_usage
;;