Compare commits

...

259 Commits

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

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

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

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

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

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

Due the above mentioned issues, the optional distfiles will be copied to the newly created thinjail if they exist on the base release, thus being secure and more granular management.
2021-03-20 06:12:07 -04:00
Bike Dude b5044a2ddb IPv6 hint for pf.conf 2021-03-18 14:01:57 +01:00
Bike Dude 15ef005337 IPv6 hint for pf.conf 2021-03-18 14:00:21 +01:00
Daniel Dowse 296236f793 Tabs to spaces 2021-03-03 18:56:24 +01:00
Daniel Dowse dd3b2e8e62 If dual stack ip6 gw will be last will be the last output line of netstat ... comand in _gateway 2021-03-03 15:20:55 +01:00
Daniel Dowse 8cb20e4457 Help output to show real value for options instead of [options] 2021-03-03 00:30:17 +01:00
Christer Edwards 2e5d5b4be1 Merge pull request #356 from cedwards/default-template-fix
revert default template link; error->notify for bootstrap
2021-02-28 13:10:13 -07:00
Christer Edwards f5e93e4b1a revert default template link; error->notify for bootstrap 2021-02-28 13:08:42 -07:00
Lucas Holt 54697cf77a Fix the file test for FreeBSD/HBSD 2021-02-27 00:13:01 -05:00
Lucas Holt 1710a09f6a Add preliminary support for MidnightBSD. 2021-02-26 16:55:56 -05:00
Christer Edwards 3fe03807ef Merge pull request #350 from zilti/master
Added option to have CP be quiet
2021-02-23 09:51:28 -07:00
Christer Edwards c7a84a4a4e Merge pull request #351 from tuffnatty/patch-1
Reflect bastille_zfs_mountpoint deprecation in README.md
2021-02-19 09:52:40 -07:00
Daniel Ziltener 2aa92042fd Adjustment for consistency 2021-02-19 17:11:19 +01:00
Phil Krylov 39990b584b Reflect bastille_zfs_mountpoint deprecation in README.md 2021-02-19 17:34:34 +03:00
Daniel Ziltener 214a3e9894 Added option to have CP be quiet 2021-02-18 20:13:28 +01:00
Jose 674e8ff087 More validation/checks for export command 2021-02-18 06:48:43 -04:00
Christer Edwards f7ef58cc19 Merge pull request #344 from hackacad/include_beta
allow boostrapping BETA build
2021-02-15 13:33:43 -07:00
Bike Dude e35024508e allow boostrapping BETA build 2021-02-14 17:35:23 +01:00
Bike Dude baa362c69b allow boostrapping BETA build 2021-02-14 17:29:29 +01:00
Bike Dude 440db5f82a typo 2021-02-14 17:27:09 +01:00
Bike Dude 4373b8b8d9 lint 2021-02-10 15:07:53 +01:00
Bike Dude 056b0237ad Ubuntu Focal support
incl. minor fixes
2021-02-10 14:33:04 +01:00
Bike Dude 0b80c59744 minor fixes 2021-02-10 10:27:49 +01:00
Bike Dude 373eafa4d6 POC RC1
POC for Bastille Linux Compat
2021-02-10 10:09:15 +01:00
Bike Dude e7959a3f67 Alpha1
w/o bastille console
2021-02-09 22:00:07 +01:00
Bike Dude 519fe77fbb debug
v0.1
2021-02-08 22:11:33 +01:00
Jose 211a268c36 Use which since shell built-in and search for paths 2021-02-08 05:31:16 -04:00
Jose 75ed5b3ce4 Add quick check for pfctl command 2021-02-08 04:17:32 -04:00
Jose 80639062d7 Fix and improve the convert command 2021-02-05 13:59:09 -04:00
Jose b31c8d514b Simplify options parsing and better handling for combined options 2021-02-03 20:39:30 -04:00
Jose 5583ab1d78 Add support bastille RAW image exports/imports, also extended help usage 2021-02-03 18:31:41 -04:00
Christer Edwards af8d766b0e Merge pull request #333 from BastilleBSD/issue-332
fixes issue #332
2021-01-29 12:32:33 -07:00
Christer Edwards 9a5a1f960e fixes issue #332 2021-01-29 09:27:39 -07:00
Christer Edwards ec24d7a897 Merge pull request #329 from BastilleBSD/docs-fix
minor fixes to previous doc updates
2021-01-27 13:55:12 -07:00
Christer Edwards a450dd1de8 minor fixes to previous doc updates 2021-01-27 13:53:23 -07:00
Christer Edwards 4b27614ad7 Merge pull request #328 from BastilleBSD/docs-fix
fix formatting in network documentation
2021-01-27 13:49:50 -07:00
Christer Edwards c3130f0eec fix formatting in network documentation 2021-01-27 13:46:05 -07:00
Christer Edwards b5f1f15c45 Merge pull request #327 from fbarthez/patch-1
Minor md syntax fixes, adding missing spaces
2021-01-27 13:39:47 -07:00
Fabian Peters c141f31dbd Minor md syntax fixes, adding missing spaces 2021-01-27 19:28:38 +01:00
Christer Edwards 584839fd78 Merge pull request #319 from hackacad/pf_keep
Update README / pf.conf
2021-01-19 12:59:08 -07:00
Bike Dude 627d1af284 update pf.conf 2021-01-19 20:10:53 +01:00
Bike Dude 8311a66b94 update pf.conf 2021-01-19 18:27:45 +01:00
Gerrit Sere bc143f8fe2 Merge branch 'master' of https://github.com/BastilleBSD/bastille into cmdbug 2021-01-06 13:42:39 +01:00
Bike Dude 03ab9fd203 Thick Upgrade 2021-01-05 20:38:08 +01:00
Gerrit Sere b2134145a2 bastille cmd exit code not respected #272 2021-01-05 00:30:06 +01:00
52 changed files with 1725 additions and 517 deletions
+9
View File
@@ -0,0 +1,9 @@
version: 2
sphinx:
configuration: docs/conf.py
python:
version: 3.7
install:
- requirements: docs/requirements.txt
+1
View File
@@ -22,6 +22,7 @@ Christer Edwards [christer.edwards@gmail.com]
- Petru T. Garstea - Petru T. Garstea
- Sven R. - Sven R.
- Tobias Tom - Tobias Tom
- Stefano Marinelli
### Special thanks ### Special thanks
Software doesn't happen in a vacuum. Thank you to the following people who may Software doesn't happen in a vacuum. Thank you to the following people who may
+1 -1
View File
@@ -1,6 +1,6 @@
BSD 3-Clause License BSD 3-Clause License
Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
+86 -43
View File
@@ -79,7 +79,7 @@ Use "bastille command -h|--help" for more information about a command.
``` ```
## 0.8-beta ## 0.9-beta
This document outlines the basic usage of the Bastille container management This document outlines the basic usage of the Bastille container management
framework. This release is still considered beta. framework. This release is still considered beta.
@@ -131,13 +131,15 @@ nat on $ext_if from <jails> to any -> ($ext_if:0)
rdr-anchor "rdr/*" rdr-anchor "rdr/*"
block in all block in all
pass out quick modulate state pass out quick keep state
antispoof for $ext_if inet antispoof for $ext_if inet
pass in inet proto tcp from any to any port ssh flags S/SA keep state pass in inet proto tcp from any to any port ssh flags S/SA keep state
## make sure you also open up ports that you are going to use for dynamic rdr ## make sure you also open up ports that you are going to use for dynamic rdr
# pass in inet proto tcp from any to any port <rdr-start>:<rdr-end> flags S/SA keep state # pass in inet proto tcp from any to any port <rdr-start>:<rdr-end> flags S/SA keep state
# pass in inet proto udp from any to any port <rdr-start>:<rdr-end> flags S/SA keep state # pass in inet proto udp from any to any port <rdr-start>:<rdr-end> flags S/SA keep state
## for IPv6 networks please uncomment the following rule
# pass inet6 proto icmp6 icmp6-type { echoreq, routersol, routeradv, neighbradv, neighbrsol }
``` ```
@@ -215,7 +217,7 @@ Two values are required for Bastille to use ZFS. The default values in the
bastille_zfs_enable="" ## default: "" bastille_zfs_enable="" ## default: ""
bastille_zfs_zpool="" ## default: "" bastille_zfs_zpool="" ## default: ""
bastille_zfs_prefix="bastille" ## default: "${bastille_zfs_zpool}/bastille" bastille_zfs_prefix="bastille" ## default: "${bastille_zfs_zpool}/bastille"
bastille_zfs_mountpoint=${bastille_prefix} ## default: "${bastille_prefix}" 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" bastille_zfs_options="-o compress=lz4 -o atime=off" ## default: "-o compress=lz4 -o atime=off"
``` ```
@@ -234,8 +236,8 @@ not using ZFS and can safely ignore these settings.
bastille bootstrap bastille bootstrap
------------------ ------------------
Before you can begin creating containers, Bastille needs to "bootstrap" a Before you can begin creating containers, Bastille needs to "bootstrap" a
release. Current supported releases are 11.3-RELEASE, 12.0-RELEASE and release. Current supported releases are 11.4-RELEASE, 12.2-RELEASE and
12.1-RELEASE. 13.0-RELEASE.
**Important: If you need ZFS support see the above section BEFORE **Important: If you need ZFS support see the above section BEFORE
bootstrapping.** bootstrapping.**
@@ -243,14 +245,14 @@ bootstrapping.**
To `bootstrap` a release, run the bootstrap sub-command with the To `bootstrap` a release, run the bootstrap sub-command with the
release version as the argument. release version as the argument.
**FreeBSD 11.3-RELEASE** **FreeBSD 11.4-RELEASE**
```shell ```shell
ishmael ~ # bastille bootstrap 11.3-RELEASE ishmael ~ # bastille bootstrap 11.4-RELEASE
``` ```
**FreeBSD 12.1-RELEASE** **FreeBSD 12.2-RELEASE**
```shell ```shell
ishmael ~ # bastille bootstrap 12.1-RELEASE ishmael ~ # bastille bootstrap 12.2-RELEASE
``` ```
**HardenedBSD 11-STABLE-BUILD-XX** **HardenedBSD 11-STABLE-BUILD-XX**
@@ -290,6 +292,37 @@ bootstrapping templates from GitHub or GitLab.
See `bastille update` to ensure your bootstrapped releases include the latest See `bastille update` to ensure your bootstrapped releases include the latest
patches. patches.
**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 you.
```shell
ishmael ~ # bastille bootstrap focal
sysrc: unknown variable 'linprocfs_load'
sysrc: unknown variable 'linsysfs_load'
sysrc: unknown variable 'tmpfs_load'
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)
#y
Loading modules
Persisting modules
linux_enable: -> YES
linprocfs_load: -> YES
linsysfs_load: -> YES
tmpfs_load: -> YES
Debootstrap not found. Should it be installed? (N|y)
#y
FreeBSD repository is up to date.
All repositories are up to date.
Checking integrity... done (0 conflicting)
The following 1 package(s) will be affected (of 0 checked):
New packages to be INSTALLED:
debootstrap: 1.0.123_4
[...]
```
As of 0.9.20210714 Bastille supports Ubuntu 18.04 (bionic) and Ubuntu 20.04 (focal).
bastille create bastille create
--------------- ---------------
@@ -306,24 +339,24 @@ IP at container creation.
**ip4** **ip4**
```shell ```shell
ishmael ~ # bastille create folsom 12.1-RELEASE 10.17.89.10 ishmael ~ # bastille create folsom 12.2-RELEASE 10.17.89.10
Valid: (10.17.89.10). Valid: (10.17.89.10).
NAME: folsom. NAME: folsom.
IP: 10.17.89.10. IP: 10.17.89.10.
RELEASE: 12.1-RELEASE. RELEASE: 12.2-RELEASE.
syslogd_flags: -s -> -ss syslogd_flags: -s -> -ss
sendmail_enable: NO -> NONE sendmail_enable: NO -> NONE
cron_flags: -> -J 60 cron_flags: -> -J 60
``` ```
This command will create a 12.1-RELEASE container assigning the 10.17.89.10 ip This command will create a 12.2-RELEASE container assigning the 10.17.89.10 ip
address to the new system. address to the new system.
**ip6** **ip6**
```shell ```shell
ishmael ~ # bastille create folsom 12.1-RELEASE fd35:f1fd:2cb6:6c5c::13 ishmael ~ # bastille create folsom 12.2-RELEASE fd35:f1fd:2cb6:6c5c::13
Valid: (fd35:f1fd:2cb6:6c5c::13). Valid: (fd35:f1fd:2cb6:6c5c::13).
NAME: folsom. NAME: folsom.
@@ -335,12 +368,12 @@ sendmail_enable: NO -> NONE
cron_flags: -> -J 60 cron_flags: -> -J 60
``` ```
This command will create a 12.1-RELEASE container assigning the This command will create a 12.2-RELEASE container assigning the
fd35:f1fd:2cb6:6c5c::13 ip address to the new system. fd35:f1fd:2cb6:6c5c::13 ip address to the new system.
**VNET** **VNET**
```shell ```shell
ishmael ~ # bastille create -V vnetjail 12.1-RELEASE 192.168.87.55/24 em0 ishmael ~ # bastille create -V vnetjail 12.2-RELEASE 192.168.87.55/24 em0
Valid: (192.168.87.55/24). Valid: (192.168.87.55/24).
Valid: (em0). Valid: (em0).
@@ -356,7 +389,7 @@ ifconfig_e0b_bastille0_name: -> vnet0
ifconfig_vnet0: -> inet 192.168.87.55/24 ifconfig_vnet0: -> inet 192.168.87.55/24
``` ```
This command will create a 12.1-RELEASE container assigning the This command will create a 12.2-RELEASE container assigning the
192.168.87.55/24 ip address to the new system. 192.168.87.55/24 ip address to the new system.
VNET-enabled containers are attached to a virtual bridge interface for VNET-enabled containers are attached to a virtual bridge interface for
@@ -376,9 +409,18 @@ private base. This is sometimes referred to as a "thick" container (whereas the
shared base container is a "thin"). shared base container is a "thin").
```shell ```shell
ishmael ~ # bastille create -T folsom 12.0-RELEASE 10.17.89.10 ishmael ~ # bastille create -T folsom 12.2-RELEASE 10.17.89.10
``` ```
**Linux**
```shell
ishmael ~ # bastille create folsom focal 10.17.89.10
```
Systemd is not supported due to the missing boot process.
I recommend using private (rfc1918) ip address ranges for your containers. I recommend using private (rfc1918) ip address ranges for your containers.
These ranges include: These ranges include:
@@ -628,9 +670,8 @@ Templates](https://gitlab.com/BastilleBSD-Templates)?
Bastille supports a templating system allowing you to apply files, pkgs and Bastille supports a templating system allowing you to apply files, pkgs and
execute commands inside the container automatically. execute commands inside the container automatically.
Currently supported template hooks are: `ARG`, `LIMITS`, `INCLUDE`, `PRE`, Currently supported template hooks are: `ARG`, `LIMITS`, `INCLUDE`,
`FSTAB`, `PKG`, `OVERLAY`, `SYSRC`, `SERVICE`, `CMD`, `RENDER`. `MOUNT`, `PKG`, `CP`, `SYSRC`, `SERVICE`, `RDR`, `CMD`, `RENDER`.
Planned template hooks include: `PF`, `LOG`
Templates are created in `${bastille_prefix}/templates` and can leverage any of Templates are created in `${bastille_prefix}/templates` and can leverage any of
the template hooks. Simply create a new directory in the format project/repo, the template hooks. Simply create a new directory in the format project/repo,
@@ -644,9 +685,9 @@ To leverage a template hook, create an UPPERCASE file in the root of the
template directory named after the hook you want to execute. eg; template directory named after the hook you want to execute. eg;
```shell ```shell
echo "zsh vim-console git-lite htop" > /usr/local/bastille/templates/username/base-template/PKG echo "PKG zsh vim-console git-lite htop" >> /usr/local/bastille/templates/username/base-template/Bastillefile
echo "/usr/bin/chsh -s /usr/local/bin/zsh" > /usr/local/bastille/templates/username/base-template/CMD echo "CMD /usr/bin/chsh -s /usr/local/bin/zsh" >> /usr/local/bastille/templates/username/base-template/Bastillefile
echo "usr" > /usr/local/bastille/templates/username/base-template/OVERLAY echo "CP usr" > /usr/local/bastille/templates/username/base-template/Bastillefile
``` ```
Template hooks are executed in specific order and require specific syntax to Template hooks are executed in specific order and require specific syntax to
@@ -665,11 +706,7 @@ work as expected. This table outlines that order and those requirements:
| SERVICE | service command(s) | nginx restart | | SERVICE | service command(s) | nginx restart |
| CMD | /bin/sh command | /usr/bin/chsh -s /usr/local/bin/zsh | | CMD | /bin/sh command | /usr/bin/chsh -s /usr/local/bin/zsh |
| RENDER | paths (one/line) | /usr/local/etc/nginx | | RENDER | paths (one/line) | /usr/local/etc/nginx |
| RDR | protocol port port | tcp 2200 22 |
| PLANNED | format | example |
|---------|------------------|----------------------------------------------------------------|
| RDR | pf rdr entry | rdr pass inet proto tcp from any to any port 80 -> 10.17.89.80 |
| LOG | path | /var/log/nginx/access.log |
Note: SYSRC requires NO quotes or that quotes (`"`) be escaped. ie; `\"`) Note: SYSRC requires NO quotes or that quotes (`"`) be escaped. ie; `\"`)
@@ -698,8 +735,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; use, be sure to include `usr` in the template OVERLAY definition. eg;
```shell ```shell
echo "etc" > /usr/local/bastille/templates/username/base/OVERLAY echo "CP etc" >> /usr/local/bastille/templates/username/base/Bastillefile
echo "usr" >> /usr/local/bastille/templates/username/base/OVERLAY echo "CP usr" >> /usr/local/bastille/templates/username/base/Bastillefile
``` ```
The above example will include anything under "etc" and "usr" inside The above example will include anything under "etc" and "usr" inside
@@ -890,21 +927,21 @@ The `update` command targets a release instead of a container. Because every
container is based on a release, when the release is updated all the containers container is based on a release, when the release is updated all the containers
are automatically updated as well. are automatically updated as well.
To update all containers based on the 11.2-RELEASE `release`: To update all containers based on the 11.4-RELEASE `release`:
Up to date 11.2-RELEASE: Up to date 11.4-RELEASE:
```shell ```shell
ishmael ~ # bastille update 11.2-RELEASE ishmael ~ # bastille update 11.4-RELEASE
Targeting specified release. Targeting specified release.
11.2-RELEASE 11.4-RELEASE
Looking up update.FreeBSD.org mirrors... 2 mirrors found. Looking up update.FreeBSD.org mirrors... 2 mirrors found.
Fetching metadata signature for 11.2-RELEASE from update4.freebsd.org... done. Fetching metadata signature for 11.4-RELEASE from update4.freebsd.org... done.
Fetching metadata index... done. Fetching metadata index... done.
Inspecting system... done. Inspecting system... done.
Preparing to download files... done. Preparing to download files... done.
No updates needed to update system to 11.2-RELEASE-p4. No updates needed to update system to 11.4-RELEASE-p4.
No updates are available to install. No updates are available to install.
``` ```
@@ -916,11 +953,21 @@ bastille upgrade
This sub-command lets you upgrade a release to a new release. Depending on the This sub-command lets you upgrade a release to a new release. Depending on the
workflow this can be similar to a `bootstrap`. workflow this can be similar to a `bootstrap`.
For standard containers you need to upgrade the shared base jail:
```shell ```shell
ishmael ~ # bastille upgrade 11.3-RELEASE 12.0-RELEASE ishmael ~ # bastille upgrade 12.1-RELEASE 12.2-RELEASE
... ...
``` ```
For thick jails you need to upgrade every single container (according the freebsd-update procedure):
```shell
ishmael ~ # bastille upgrade folsom 12.2-RELEASE
ishmael ~ # bastille upgrade folsom install
...
ishmael ~ # bastille restart folsom
ishmael ~ # bastille upgrade folsom install
```
bastille verify bastille verify
--------------- ---------------
@@ -1028,11 +1075,7 @@ Example (create, start, console)
This example creates, starts and consoles into the container. This example creates, starts and consoles into the container.
```shell ```shell
ishmael ~ # bastille create alcatraz 11.2-RELEASE 10.17.89.7 ishmael ~ # bastille create alcatraz 11.4-RELEASE 10.17.89.7
RELEASE: 11.2-RELEASE.
NAME: alcatraz.
IP: 10.17.89.7.
``` ```
```shell ```shell
@@ -1044,7 +1087,7 @@ alcatraz: created
```shell ```shell
ishmael ~ # bastille console alcatraz ishmael ~ # bastille console alcatraz
[alcatraz]: [alcatraz]:
FreeBSD 11.2-RELEASE-p4 (GENERIC) #0: Thu Sep 27 08:16:24 UTC 2018 FreeBSD 11.4-RELEASE-p4 (GENERIC) #0: Thu Sep 27 08:16:24 UTC 2018
Welcome to FreeBSD! Welcome to FreeBSD!
Vendored
+3 -2
View File
@@ -9,8 +9,8 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
vm_config.ssh.shell = "sh" vm_config.ssh.shell = "sh"
vm_config.vm.box = "freebsd/FreeBSD-12.1-RELEASE" vm_config.vm.box = "freebsd/FreeBSD-13.0-RELEASE"
vm_config.vm.box_version = "2019.11.01" vm_config.vm.box_version = "2021.04.09"
vm_config.vm.provider "virtualbox" do |vb| vm_config.vm.provider "virtualbox" do |vb|
vb.name = "bastille" vb.name = "bastille"
@@ -19,6 +19,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
end end
vm_config.vm.provision "shell", inline: "cd /vagrant; make install" vm_config.vm.provision "shell", inline: "cd /vagrant; make install"
vm_config.vm.provision "shell", inline: "pkg install -y git-lite"
end end
end end
Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

+1 -1
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` `sysutils/bastille`. Binary packages available in `quarterly` and `latest`
repositories. repositories.
Current version is `0.8.20210115`. Current version is `0.9.20220216`.
To install from the FreeBSD package repository: To install from the FreeBSD package repository:
+20 -21
View File
@@ -109,6 +109,18 @@ To define a default route / gateway for all VNET containers define the value in
This config change will apply the defined gateway to any new containers. This config change will apply the defined gateway to any new containers.
Existing containers will need to be manually updated. Existing containers will need to be manually updated.
Virtual Network (VNET) on External Bridge
--------------------------------------
To create a VNET based container and attach it to an external, already existing bridge, use the `-B` option, an IP/netmask and
external bridge.
.. code-block:: shell
bastille create -B azkaban 12.1-RELEASE 192.168.1.50/24 bridge0
Bastille will automagically create the interface, attach it to the specified bridge and connect /
disconnect containers as they are started and stopped.
The bridge needs to be created/enabled before creating and starting the jail.
Public Network Public Network
============== ==============
@@ -165,23 +177,14 @@ Create the firewall rules:
set skip on lo set skip on lo
table <jails> persist table <jails> persist
nat on $ext_if from <jails> to any -> ($ext_if) nat on $ext_if from <jails> to any -> ($ext_if:0)
## static rdr example
## rdr pass inet proto tcp from any to any port {80, 443} -> 10.17.89.45
## dynamic rdr anchor (see below)
rdr-anchor "rdr/*" rdr-anchor "rdr/*"
block in all block in all
pass out quick modulate state pass out quick keep state
antispoof for $ext_if inet antispoof for $ext_if inet
pass in inet proto tcp from any to any port ssh flags S/SA modulate state pass in inet proto tcp from any to any port ssh flags S/SA modulate state
# If you are using dynamic rdr also need to ensure that the external port
# range you are using is open
# pass in inet proto tcp from any to any port <rdr-start>:<rdr-end>
- Make sure to change the `ext_if` variable to match your host system interface. - Make sure to change the `ext_if` variable to match your host system interface.
- Make sure to include the last line (`port ssh`) or you'll end up locked out. - Make sure to include the last line (`port ssh`) or you'll end up locked out.
@@ -192,30 +195,26 @@ to containers are:
nat on $ext_if from <jails> to any -> ($ext_if) nat on $ext_if from <jails> to any -> ($ext_if)
## static rdr example
## rdr pass inet proto tcp from any to any port {80, 443} -> 10.17.89.45
The `nat` routes traffic from the loopback interface to the external The `nat` routes traffic from the loopback interface to the external
interface for outbound access. interface for outbound access.
The `rdr pass ...` will redirect traffic from the host firewall on port X to .. code-block:: shell
the ip of Container Y. The example shown redirects web traffic (80 & 443) to the
containers at `10.17.89.45`.
## dynamic rdr anchor (see below)
rdr-anchor "rdr/*" rdr-anchor "rdr/*"
The `rdr-anchor "rdr/*"` enables dynamic rdr rules to be setup using the The `rdr-anchor "rdr/*"` enables dynamic rdr rules to be setup using the
`bastille rdr` command at runtime - eg. `bastille rdr` command at runtime - eg.
.. code-block:: shell
bastille rdr <jail> tcp 2001 22 # Redirects tcp port 2001 on host to 22 on jail bastille rdr <jail> tcp 2001 22 # Redirects tcp port 2001 on host to 22 on jail
bastille rdr <jail> udp 2053 53 # Same for udp bastille rdr <jail> udp 2053 53 # Same for udp
bastille rdr <jail> list # List dynamic rdr rules bastille rdr <jail> list # List dynamic rdr rules
bastille rdr <jail> clear # Clear dynamic rdr rules bastille rdr <jail> clear # Clear dynamic rdr rules
Note that if you are redirecting ports where the host is also listening Note that if you are redirecting ports where the host is also listening (eg.
(eg. ssh) you should make sure that the host service is not listening on ssh) you should make sure that the host service is not listening on the cloned
the cloned interface - eg. for ssh set sshd_flags in rc.conf interface - eg. for ssh set sshd_flags in rc.conf
sshd_flags="-o ListenAddress=<hostname>" sshd_flags="-o ListenAddress=<hostname>"
+1 -1
View File
@@ -6,7 +6,7 @@ To manage binary packages within the container use `bastille pkg`.
.. code-block:: shell .. code-block:: shell
ishmael ~ # bastille pkg folsom 'install vim-console git-lite zsh' ishmael ~ # bastille pkg folsom install vim-console git-lite zsh
[folsom]: [folsom]:
The package management tool is not yet installed on your system. The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]: y Do you want to fetch and install it now? [y/N]: y
+12 -12
View File
@@ -7,14 +7,14 @@ Templates](https://gitlab.com/BastilleBSD-Templates)?
Bastille supports a templating system allowing you to apply files, pkgs and Bastille supports a templating system allowing you to apply files, pkgs and
execute commands inside the containers automatically. execute commands inside the containers automatically.
Currently supported template hooks are: `LIMITS`, `INCLUDE`, `PRE`, `FSTAB`, Currently supported template hooks are: `CMD`, `CP`, `INCLUDE`, `LIMITS`, `MOUNT`,
`PKG`, `OVERLAY`, `SYSRC`, `SERVICE`, `CMD`. `PKG`, `RDR`, `SERVICE`, `SYSRC`.
Templates are created in `${bastille_prefix}/templates` and can leverage any of Templates are created in `${bastille_prefix}/templates` and can leverage any of
the template hooks. the template hooks.
Bastille 0.7.x Bastille 0.7.x+
-------------- ---------------
Bastille 0.7.x introduces a template syntax that is more flexible and allows Bastille 0.7.x introduces a template syntax that is more flexible and allows
any-order scripting. Previous versions had a hard template execution order and any-order scripting. Previous versions had a hard template execution order and
instructions were spread across multiple files. The new syntax is done in a instructions were spread across multiple files. The new syntax is done in a
@@ -27,23 +27,23 @@ Template Automation Hooks
+---------+-------------------+-----------------------------------------+ +---------+-------------------+-----------------------------------------+
| HOOK | format | example | | HOOK | format | example |
+=========+===================+=========================================+ +=========+===================+=========================================+
| LIMITS | resource value | memoryuse 1G | | CMD | /bin/sh command | /usr/bin/chsh -s /usr/local/bin/zsh |
+---------+-------------------+-----------------------------------------+
| CP | path(s) | etc root usr (one per line) |
+---------+-------------------+-----------------------------------------+ +---------+-------------------+-----------------------------------------+
| INCLUDE | template path/URL | http?://TEMPLATE_URL or project/path | | INCLUDE | template path/URL | http?://TEMPLATE_URL or project/path |
+---------+-------------------+-----------------------------------------+ +---------+-------------------+-----------------------------------------+
| PRE | /bin/sh command | mkdir -p /usr/local/my_app/html | | LIMITS | resource value | memoryuse 1G |
+---------+-------------------+-----------------------------------------+ +---------+-------------------+-----------------------------------------+
| FSTAB | fstab syntax | /host/path container/path nullfs ro 0 0 | | MOUNT | fstab syntax | /host/path container/path nullfs ro 0 0 |
+---------+-------------------+-----------------------------------------+ +---------+-------------------+-----------------------------------------+
| PKG | port/pkg name(s) | vim-console zsh git-lite tree htop | | PKG | port/pkg name(s) | vim-console zsh git-lite tree htop |
+---------+-------------------+-----------------------------------------+ +---------+-------------------+-----------------------------------------+
| OVERLAY | path(s) | etc root usr (one per line) | | RDR | tcp port port | tcp 2200 22 (hostport jailport) |
+---------+-------------------+-----------------------------------------+
| SYSRC | sysrc command(s) | nginx_enable=YES |
+---------+-------------------+-----------------------------------------+ +---------+-------------------+-----------------------------------------+
| SERVICE | service command | 'nginx start' OR 'postfix reload' | | SERVICE | service command | 'nginx start' OR 'postfix reload' |
+---------+-------------------+-----------------------------------------+ +---------+-------------------+-----------------------------------------+
| CMD | /bin/sh command | /usr/bin/chsh -s /usr/local/bin/zsh | | SYSRC | sysrc command(s) | nginx_enable=YES |
+---------+-------------------+-----------------------------------------+ +---------+-------------------+-----------------------------------------+
Note: SYSRC requires that NO quotes be used or that quotes (`"`) be escaped Note: SYSRC requires that NO quotes be used or that quotes (`"`) be escaped
@@ -71,7 +71,7 @@ use, be sure to include `usr` in the template OVERLAY definition. eg;
.. code-block:: shell .. code-block:: shell
echo "usr" > /usr/local/bastille/templates/username/template/OVERLAY echo "CP usr" >> /usr/local/bastille/templates/username/template/Bastillefile
The above example "usr" will include anything under "usr" inside the template. The above example "usr" will include anything under "usr" inside the template.
You do not need to list individual files. Just include the top-level directory You do not need to list individual files. Just include the top-level directory
+28
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.
+3 -3
View File
@@ -8,13 +8,13 @@ else:
# -- Project information ----------------------------------------------------- # -- Project information -----------------------------------------------------
project = 'Bastille' project = 'Bastille'
copyright = '2018-2021, Christer Edwards' copyright = '2018-2022, Christer Edwards'
author = 'Christer Edwards' author = 'Christer Edwards'
# The short X.Y version # The short X.Y version
version = '0.8.20210115' version = '0.9.20220216'
# The full version, including alpha/beta/rc tags # The full version, including alpha/beta/rc tags
release = '0.8.20210115-beta' release = '0.9.20220216-beta'
# -- General configuration --------------------------------------------------- # -- General configuration ---------------------------------------------------
+1
View File
@@ -18,6 +18,7 @@ https://docs.bastillebsd.org.
chapters/subcommands/index chapters/subcommands/index
chapters/template chapters/template
chapters/jail-config chapters/jail-config
chapters/zfs-support
copyright copyright
+1
View File
@@ -0,0 +1 @@
docutils < 0.18
+19 -8
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> # Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@@ -70,7 +70,7 @@ bastille_perms_check() {
bastille_perms_check bastille_perms_check
## version ## version
BASTILLE_VERSION="0.8.20210115" BASTILLE_VERSION="0.9.20220216"
usage() { usage() {
cat << EOF cat << EOF
@@ -135,10 +135,10 @@ version|-v|--version)
help|-h|--help) help|-h|--help)
usage usage
;; ;;
bootstrap|create|destroy|import|list|rdr|restart|start|update|upgrade|verify) bootstrap|create|destroy|export|import|list|rdr|restart|start|update|upgrade|verify)
# Nothing "extra" to do for these commands. -- cwells # Nothing "extra" to do for these commands. -- cwells
;; ;;
clone|config|cmd|console|convert|cp|edit|export|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|template|top|umount|zfs)
# Parse the target and ensure it exists. -- cwells # Parse the target and ensure it exists. -- cwells
if [ $# -eq 0 ]; then # No target was given, so show the command's help. -- cwells if [ $# -eq 0 ]; then # No target was given, so show the command's help. -- cwells
PARAMS='help' PARAMS='help'
@@ -147,14 +147,24 @@ clone|config|cmd|console|convert|cp|edit|export|htop|limits|mount|pkg|rename|ser
shift shift
if [ "${TARGET}" = 'ALL' ]; then if [ "${TARGET}" = 'ALL' ]; then
_JAILS=$(jls name) _JAILS=$(/usr/sbin/jls name)
JAILS="" JAILS=""
for _jail in ${_JAILS}; do for _jail in ${_JAILS}; do
_JAILPATH=$(jls -j "${_jail}" path) _JAILPATH=$(/usr/sbin/jls -j "${_jail}" path)
if [ -z ${_JAILPATH##${bastille_jailsdir}*} ]; then if [ -z ${_JAILPATH##${bastille_jailsdir}*} ]; then
JAILS="${JAILS} ${_jail}" JAILS="${JAILS} ${_jail}"
fi fi
done done
elif [ "${CMD}" = "pkg" ] && [ "${TARGET}" = '-H' ] || [ "${TARGET}" = '--host' ]; then
TARGET="${1}"
USE_HOST_PKG=1
JAILS="${TARGET}"
shift
# Require the target to be running
if [ ! "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
error_exit "[${TARGET}]: Not started. See 'bastille start ${TARGET}'."
fi
elif [ "${CMD}" = 'template' ] && [ "${TARGET}" = '--convert' ]; then elif [ "${CMD}" = 'template' ] && [ "${TARGET}" = '--convert' ]; then
# This command does not act on a jail, so we are temporarily bypassing the presence/started # 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 # checks. The command will simply convert a template from hooks to a Bastillefile. -- cwells
@@ -169,18 +179,19 @@ clone|config|cmd|console|convert|cp|edit|export|htop|limits|mount|pkg|rename|ser
case "${CMD}" in case "${CMD}" in
cmd|console|htop|pkg|service|stop|sysrc|template|top) cmd|console|htop|pkg|service|stop|sysrc|template|top)
# Require the target to be running. -- cwells # Require the target to be running. -- cwells
if [ ! "$(jls name | awk "/^${TARGET}$/")" ]; then if [ ! "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
error_exit "[${TARGET}]: Not started. See 'bastille start ${TARGET}'." error_exit "[${TARGET}]: Not started. See 'bastille start ${TARGET}'."
fi fi
;; ;;
convert|rename) convert|rename)
# Require the target to be stopped. -- cwells # 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}'." error_exit "${TARGET} is running. See 'bastille stop ${TARGET}'."
fi fi
;; ;;
esac esac
fi fi
export USE_HOST_PKG
export TARGET export TARGET
export JAILS export JAILS
fi fi
+6 -1
View File
@@ -25,7 +25,7 @@ bastille_sharedir="/usr/local/share/bastille" ## default
bastille_bootstrap_archives="base" ## default: "base" bastille_bootstrap_archives="base" ## default: "base"
## default timezone ## default timezone
bastille_tzdata="Etc/UTC" ## default: "Etc/UTC" bastille_tzdata="" ## default: empty to use host's time zone
## default jail resolv.conf ## default jail resolv.conf
bastille_resolv_conf="/etc/resolv.conf" ## default: "/etc/resolv.conf" bastille_resolv_conf="/etc/resolv.conf" ## default: "/etc/resolv.conf"
@@ -33,6 +33,7 @@ bastille_resolv_conf="/etc/resolv.conf" ## default
## bootstrap urls ## bootstrap urls
bastille_url_freebsd="http://ftp.freebsd.org/pub/FreeBSD/releases/" ## default: "http://ftp.freebsd.org/pub/FreeBSD/releases/" 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="http://installer.hardenedbsd.org/pub/hardenedbsd/" ## 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 ## ZFS options
bastille_zfs_enable="" ## default: "" bastille_zfs_enable="" ## default: ""
@@ -43,15 +44,19 @@ bastille_zfs_options="-o compress=lz4 -o atime=off" ## default
## Export/Import options ## Export/Import options
bastille_compress_xz_options="-0 -v" ## default "-0 -v" bastille_compress_xz_options="-0 -v" ## default "-0 -v"
bastille_decompress_xz_options="-c -d -v" ## default "-c -d -v" bastille_decompress_xz_options="-c -d -v" ## default "-c -d -v"
bastille_compress_gz_options="-1 -v" ## default "-1 -v"
bastille_decompress_gz_options="-k -d -c -v" ## default "-k -d -c -v"
## Networking ## Networking
bastille_network_loopback="bastille0" ## default: "bastille0" bastille_network_loopback="bastille0" ## default: "bastille0"
bastille_network_shared="" ## default: "" bastille_network_shared="" ## default: ""
bastille_network_gateway="" ## default: "" bastille_network_gateway="" ## default: ""
bastille_network_gateway6="" ## default: ""
## Default Templates ## Default Templates
bastille_template_base="default/base" ## default: "default/base" bastille_template_base="default/base" ## default: "default/base"
bastille_template_empty="" ## default: "default/empty" bastille_template_empty="" ## default: "default/empty"
bastille_template_thick="default/thick" ## default: "default/thick" 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_thin="default/thin" ## default: "default/thin"
bastille_template_vnet="default/vnet" ## default: "default/vnet" bastille_template_vnet="default/vnet" ## default: "default/vnet"
+1 -1
View File
@@ -3,7 +3,7 @@
# Bastille jail startup script # Bastille jail startup script
# #
# PROVIDE: bastille # PROVIDE: bastille
# REQUIRE: LOGIN # REQUIRE: NETWORKING
# KEYWORD: shutdown # KEYWORD: shutdown
# Add the following to /etc/rc.conf[.local] to enable this service # Add the following to /etc/rc.conf[.local] to enable this service
+165 -24
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> # Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@@ -45,14 +45,12 @@ esac
#Validate if ZFS is enabled in rc.conf and bastille.conf. #Validate if ZFS is enabled in rc.conf and bastille.conf.
if [ "$(sysrc -n zfs_enable)" = "YES" ] && [ ! "${bastille_zfs_enable}" = "YES" ]; then 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)" warn "ZFS is enabled in rc.conf but not bastille.conf. Do you want to continue? (N|y)"
read answer read answer
case $answer in case $answer in
no|No|n|N|"") no|No|n|N|"")
error_exit "ERROR: Missing ZFS parameters. See bastille_zfs_enable." error_exit "ERROR: Missing ZFS parameters. See bastille_zfs_enable."
;; ;;
yes|Yes|y|Y) yes|Yes|y|Y) ;;
continue
;;
esac esac
fi fi
@@ -85,7 +83,7 @@ validate_release_url() {
info "Bootstrapping ${PLATFORM_OS} distfiles..." info "Bootstrapping ${PLATFORM_OS} distfiles..."
# Alternate RELEASE/ARCH fetch support # Alternate RELEASE/ARCH fetch support
if [ "${OPTION}" = "--i386" -o "${OPTION}" = "--32bit" ]; then if [ "${OPTION}" = "--i386" ] || [ "${OPTION}" = "--32bit" ]; then
ARCH="i386" ARCH="i386"
RELEASE="${RELEASE}-${ARCH}" RELEASE="${RELEASE}-${ARCH}"
fi fi
@@ -105,12 +103,11 @@ bootstrap_directories() {
if [ "${bastille_zfs_enable}" = "YES" ];then if [ "${bastille_zfs_enable}" = "YES" ];then
if [ -n "${bastille_zfs_zpool}" ]; then if [ -n "${bastille_zfs_zpool}" ]; then
zfs create ${bastille_zfs_options} -o mountpoint="${bastille_prefix}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}" zfs create ${bastille_zfs_options} -o mountpoint="${bastille_prefix}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}"
chmod 0750 "${bastille_prefix}"
fi fi
else else
mkdir -p "${bastille_prefix}" mkdir -p "${bastille_prefix}"
chmod 0750 "${bastille_prefix}"
fi fi
chmod 0750 "${bastille_prefix}"
fi fi
## ${bastille_backupsdir} ## ${bastille_backupsdir}
@@ -118,12 +115,11 @@ bootstrap_directories() {
if [ "${bastille_zfs_enable}" = "YES" ];then if [ "${bastille_zfs_enable}" = "YES" ];then
if [ -n "${bastille_zfs_zpool}" ]; then if [ -n "${bastille_zfs_zpool}" ]; then
zfs create ${bastille_zfs_options} -o mountpoint="${bastille_backupsdir}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/backups" zfs create ${bastille_zfs_options} -o mountpoint="${bastille_backupsdir}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/backups"
chmod 0750 "${bastille_backupsdir}"
fi fi
else else
mkdir -p "${bastille_backupsdir}" mkdir -p "${bastille_backupsdir}"
chmod 0750 "${bastille_backupsdir}"
fi fi
chmod 0750 "${bastille_backupsdir}"
fi fi
## ${bastille_cachedir} ## ${bastille_cachedir}
@@ -178,7 +174,6 @@ bootstrap_directories() {
else else
mkdir -p "${bastille_templatesdir}" mkdir -p "${bastille_templatesdir}"
fi fi
ln -s "${bastille_sharedir}/templates/default" "${bastille_templatesdir}/default"
fi fi
## ${bastille_releasesdir} ## ${bastille_releasesdir}
@@ -216,7 +211,7 @@ bootstrap_release() {
## check if release already bootstrapped, else continue bootstrapping ## check if release already bootstrapped, else continue bootstrapping
if [ -z "${bastille_bootstrap_archives}" ]; then if [ -z "${bastille_bootstrap_archives}" ]; then
error_exit "Bootstrap appears complete." error_notify "Bootstrap appears complete."
else else
info "Bootstrapping additional distfiles..." info "Bootstrapping additional distfiles..."
fi fi
@@ -254,12 +249,12 @@ bootstrap_release() {
fi fi
if [ -d "${bastille_cachedir}/${RELEASE}" ]; then if [ -d "${bastille_cachedir}/${RELEASE}" ]; then
if [ ! "$(ls -A "${bastille_cachedir}/${RELEASE}")" ]; then if [ ! "$(ls -A "${bastille_cachedir}/${RELEASE}")" ]; then
rm -rf "${bastille_cachedir}/${RELEASE}" rm -rf "${bastille_cachedir:?}/${RELEASE}"
fi fi
fi fi
if [ -d "${bastille_releasesdir}/${RELEASE}" ]; then if [ -d "${bastille_releasesdir}/${RELEASE}" ]; then
if [ ! "$(ls -A "${bastille_releasesdir}/${RELEASE}")" ]; then if [ ! "$(ls -A "${bastille_releasesdir}/${RELEASE}")" ]; then
rm -rf "${bastille_releasesdir}/${RELEASE}" rm -rf "${bastille_releasesdir:?}/${RELEASE}"
fi fi
fi fi
error_exit "Bootstrap failed." error_exit "Bootstrap failed."
@@ -267,8 +262,7 @@ bootstrap_release() {
## fetch for missing dist files ## fetch for missing dist files
if [ ! -f "${bastille_cachedir}/${RELEASE}/${_archive}.txz" ]; then if [ ! -f "${bastille_cachedir}/${RELEASE}/${_archive}.txz" ]; then
fetch "${UPSTREAM_URL}/${_archive}.txz" -o "${bastille_cachedir}/${RELEASE}/${_archive}.txz" if ! fetch "${UPSTREAM_URL}/${_archive}.txz" -o "${bastille_cachedir}/${RELEASE}/${_archive}.txz"; then
if [ "$?" -ne 0 ]; then
## alert only if unable to fetch additional dist files ## alert only if unable to fetch additional dist files
error_notify "Failed to fetch ${_archive}.txz." error_notify "Failed to fetch ${_archive}.txz."
fi fi
@@ -308,6 +302,101 @@ bootstrap_release() {
echo echo
} }
debootstrap_release() {
# Make sure to check/bootstrap directories first.
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|stretch|buster|bullseye)
info "Increasing APT::Cache-Start"
echo "APT::Cache-Start 251658240;" > "${bastille_releasesdir}"/${DIR_BOOTSTRAP}/etc/apt/apt.conf.d/00aptitude
;;
esac
info "Bootstrap successful."
info "See 'bastille --help' for available commands."
echo
}
bootstrap_template() { bootstrap_template() {
## ${bastille_templatesdir} ## ${bastille_templatesdir}
@@ -329,15 +418,15 @@ bootstrap_template() {
_template=${bastille_templatesdir}/${_user}/${_repo} _template=${bastille_templatesdir}/${_user}/${_repo}
## support for non-git ## support for non-git
if [ ! -x "$(which git)" ]; then if ! which -s git; then
error_notify "Git not found." error_notify "Git not found."
error_exit "Not yet implemented." error_exit "Not yet implemented."
elif [ -x "$(which git)" ]; then else
if [ ! -d "${_template}/.git" ]; then if [ ! -d "${_template}/.git" ]; then
$(which git) clone "${_url}" "${_template}" ||\ git clone "${_url}" "${_template}" ||\
error_notify "Clone unsuccessful." error_notify "Clone unsuccessful."
elif [ -d "${_template}/.git" ]; then elif [ -d "${_template}/.git" ]; then
cd "${_template}" && $(which git) pull ||\ git -C "${_template}" pull ||\
error_notify "Template update unsuccessful." error_notify "Template update unsuccessful."
fi fi
fi fi
@@ -347,13 +436,22 @@ bootstrap_template() {
HW_MACHINE=$(sysctl hw.machine | awk '{ print $2 }') HW_MACHINE=$(sysctl hw.machine | awk '{ print $2 }')
HW_MACHINE_ARCH=$(sysctl hw.machine_arch | 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
RELEASE="${1}" RELEASE="${1}"
OPTION="${2}" OPTION="${2}"
# Alternate RELEASE/ARCH fetch support(experimental) # Alternate RELEASE/ARCH fetch support(experimental)
if [ -n "${OPTION}" ] && [ "${OPTION}" != "${HW_MACHINE}" ] && [ "${OPTION}" != "update" ]; then if [ -n "${OPTION}" ] && [ "${OPTION}" != "${HW_MACHINE}" ] && [ "${OPTION}" != "update" ]; then
# Supported architectures # Supported architectures
if [ "${OPTION}" = "--i386" -o "${OPTION}" = "--32bit" ]; then if [ "${OPTION}" = "--i386" ] || [ "${OPTION}" = "--32bit" ]; then
HW_MACHINE="i386" HW_MACHINE="i386"
HW_MACHINE_ARCH="i386" HW_MACHINE_ARCH="i386"
else else
@@ -363,6 +461,13 @@ fi
## Filter sane release names ## Filter sane release names
case "${1}" in case "${1}" in
2.[0-9]*)
## check for MidnightBSD releases name
NAME_VERIFY=$(echo "${RELEASE}")
UPSTREAM_URL="${bastille_url_midnightbsd}${HW_MACHINE_ARCH}/${NAME_VERIFY}"
PLATFORM_OS="MidnightBSD"
validate_release_url
;;
*-CURRENT|*-current) *-CURRENT|*-current)
## check for FreeBSD releases name ## check for FreeBSD releases name
NAME_VERIFY=$(echo "${RELEASE}" | grep -iwE '^([1-9]{2,2})\.[0-9](-CURRENT)$' | tr '[:lower:]' '[:upper:]') NAME_VERIFY=$(echo "${RELEASE}" | grep -iwE '^([1-9]{2,2})\.[0-9](-CURRENT)$' | tr '[:lower:]' '[:upper:]')
@@ -370,9 +475,9 @@ case "${1}" in
PLATFORM_OS="FreeBSD" PLATFORM_OS="FreeBSD"
validate_release_url validate_release_url
;; ;;
*-RELEASE|*-release|*-RC1|*-rc1|*-RC2|*-rc2) *-RELEASE|*-release|*-RC1|*-rc1|*-RC2|*-rc2|*-RC3|*-rc3|*-RC4|*-rc4|*-RC5|*-rc5|*-BETA1|*-BETA2|*-BETA3|*-BETA4|*-BETA5)
## check for FreeBSD releases name ## check for FreeBSD releases name
NAME_VERIFY=$(echo "${RELEASE}" | grep -iwE '^([1-9]{2,2})\.[0-9](-RELEASE|-RC[1-2])$' | tr '[:lower:]' '[:upper:]') NAME_VERIFY=$(echo "${RELEASE}" | grep -iwE '^([1-9]{2,2})\.[0-9](-RELEASE|-RC[1-5]|-BETA[1-5])$' | tr '[:lower:]' '[:upper:]')
UPSTREAM_URL="${bastille_url_freebsd}${HW_MACHINE}/${HW_MACHINE_ARCH}/${NAME_VERIFY}" UPSTREAM_URL="${bastille_url_freebsd}${HW_MACHINE}/${HW_MACHINE_ARCH}/${NAME_VERIFY}"
PLATFORM_OS="FreeBSD" PLATFORM_OS="FreeBSD"
validate_release_url validate_release_url
@@ -420,12 +525,48 @@ current-build-latest|current-BUILD-LATEST|CURRENT-BUILD-LATEST)
PLATFORM_OS="HardenedBSD" PLATFORM_OS="HardenedBSD"
validate_release_url validate_release_url
;; ;;
http?://github.com/*/*|http?://gitlab.com/*/*) http?://*/*/*)
BASTILLE_TEMPLATE_URL=${1} BASTILLE_TEMPLATE_URL=${1}
BASTILLE_TEMPLATE_USER=$(echo "${1}" | awk -F / '{ print $4 }') BASTILLE_TEMPLATE_USER=$(echo "${1}" | awk -F / '{ print $4 }')
BASTILLE_TEMPLATE_REPO=$(echo "${1}" | awk -F / '{ print $5 }') BASTILLE_TEMPLATE_REPO=$(echo "${1}" | awk -F / '{ print $5 }')
bootstrap_template bootstrap_template
;; ;;
#adding Ubuntu Bionic as valid "RELEASE" for POC @hackacad
ubuntu_bionic|bionic|ubuntu-bionic)
PLATFORM_OS="Ubuntu/Linux"
LINUX_FLAVOR="bionic"
DIR_BOOTSTRAP="Ubuntu_1804"
ARCH_BOOTSTRAP=${HW_MACHINE_ARCH_LINUX}
debootstrap_release
;;
ubuntu_focal|focal|ubuntu-focal)
PLATFORM_OS="Ubuntu/Linux"
LINUX_FLAVOR="focal"
DIR_BOOTSTRAP="Ubuntu_2004"
ARCH_BOOTSTRAP=${HW_MACHINE_ARCH_LINUX}
debootstrap_release
;;
debian_stretch|stretch|debian-stretch)
PLATFORM_OS="Debian/Linux"
LINUX_FLAVOR="stretch"
DIR_BOOTSTRAP="Debian9"
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
;;
*) *)
usage usage
;; ;;
+5 -3
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> # Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@@ -130,7 +130,7 @@ update_fstab() {
# Update fstab to use the new name # Update fstab to use the new name
FSTAB_CONFIG="${bastille_jailsdir}/${NEWNAME}/fstab" FSTAB_CONFIG="${bastille_jailsdir}/${NEWNAME}/fstab"
if [ -f "${FSTAB_CONFIG}" ]; then 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_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" FSTAB_NEWCONF="${bastille_releasesdir}/${FSTAB_RELEASE} ${bastille_jailsdir}/${NEWNAME}/root/.bastille nullfs ro 0 0"
if [ -n "${FSTAB_CURRENT}" ] && [ -n "${FSTAB_NEWCONF}" ]; then if [ -n "${FSTAB_CURRENT}" ] && [ -n "${FSTAB_NEWCONF}" ]; then
@@ -139,6 +139,8 @@ update_fstab() {
sed -i '' "s|${FSTAB_CURRENT}|${FSTAB_NEWCONF}|" "${FSTAB_CONFIG}" sed -i '' "s|${FSTAB_CURRENT}|${FSTAB_NEWCONF}|" "${FSTAB_CONFIG}"
fi fi
fi fi
# Update additional fstab paths with new jail path
sed -i '' "s|${bastille_jailsdir}/${TARGET}/root/|${bastille_jailsdir}/${NEWNAME}/root/|" "${FSTAB_CONFIG}"
fi fi
} }
@@ -164,7 +166,7 @@ clone_jail() {
else else
# Just clone the jail directory # Just clone the jail directory
# Check if container is running # 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}'." error_exit "${TARGET} is running. See 'bastille stop ${TARGET}'."
fi fi
+22 -2
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> # Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@@ -45,8 +45,28 @@ if [ $# -eq 0 ]; then
usage usage
fi fi
COUNT=0
RETURN=0
for _jail in ${JAILS}; do for _jail in ${JAILS}; do
COUNT=$(($COUNT+1))
info "[${_jail}]:" info "[${_jail}]:"
jexec -l "${_jail}" "$@" jexec -l -U root "${_jail}" "$@"
ERROR_CODE=$?
info "[${_jail}]: ${ERROR_CODE}"
if [ "$COUNT" -eq 1 ]; then
RETURN=$ERROR_CODE
else
RETURN=$(($RETURN+$ERROR_CODE))
fi
echo echo
done 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"
+60 -2
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> # Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@@ -28,7 +28,19 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # 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. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
. /usr/local/share/bastille/colors.pre.sh COLOR_RED=
COLOR_GREEN=
COLOR_YELLOW=
COLOR_RESET=
enable_color() {
. /usr/local/share/bastille/colors.pre.sh
}
# If "NO_COLOR" environment variable is present, disable output colors.
if [ -z "${NO_COLOR}" ]; then
enable_color
fi
# Notify message on error, but do not exit # Notify message on error, but do not exit
error_notify() { error_notify() {
@@ -48,3 +60,49 @@ info() {
warn() { warn() {
echo -e "${COLOR_YELLOW}$*${COLOR_RESET}" 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
local uniq_epair="bastille${_num}"
local uniq_epair_bridge="${_num}"
break
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
}
+3 -3
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> # Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@@ -76,7 +76,7 @@ for _jail in ${JAILS}; do
MATCH_FOUND=$? MATCH_FOUND=$?
if [ "${ACTION}" = 'get' ]; then if [ "${ACTION}" = 'get' ]; then
if [ $MATCH_FOUND -ne 0 ]; then if [ "${MATCH_FOUND}" -ne 0 ]; then
warn "not set" warn "not set"
elif ! echo "${MATCH_LINE}" | grep '=' > /dev/null 2>&1; then elif ! echo "${MATCH_LINE}" | grep '=' > /dev/null 2>&1; then
echo "enabled" echo "enabled"
@@ -99,7 +99,7 @@ for _jail in ${JAILS}; do
LINE=" ${PROPERTY};" LINE=" ${PROPERTY};"
fi fi
if [ $MATCH_FOUND -ne 0 ]; then # No match, so insert the property at the end. -- cwells 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}" echo "$(awk -v line="${LINE}" '$0 == "}" { print line; } 1 { print $0; }' "${FILE}")" > "${FILE}"
else # Replace the existing value. -- cwells else # Replace the existing value. -- cwells
sed -i '' -E "s/ *${ESCAPED_PROPERTY}[ =;].*/${LINE}/" "${FILE}" sed -i '' -E "s/ *${ESCAPED_PROPERTY}[ =;].*/${LINE}/" "${FILE}"
+6 -5
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> # Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@@ -32,7 +32,7 @@
. /usr/local/etc/bastille/bastille.conf . /usr/local/etc/bastille/bastille.conf
usage() { usage() {
error_exit "Usage: bastille console TARGET [user]'" error_exit "Usage: bastille console TARGET [user]"
} }
# Handle special-case commands first. # Handle special-case commands first.
@@ -53,7 +53,7 @@ validate_user() {
USER_SHELL="$(jexec -l "${_jail}" getent passwd "${USER}" | cut -d: -f7)" USER_SHELL="$(jexec -l "${_jail}" getent passwd "${USER}" | cut -d: -f7)"
if [ -n "${USER_SHELL}" ]; then if [ -n "${USER_SHELL}" ]; then
if jexec -l "${_jail}" grep -qwF "${USER_SHELL}" /etc/shells; then if jexec -l "${_jail}" grep -qwF "${USER_SHELL}" /etc/shells; then
jexec -l "${_jail}" /usr/bin/login -f "${USER}" jexec -l "${_jail}" $LOGIN -f "${USER}"
else else
echo "Invalid shell for user ${USER}" echo "Invalid shell for user ${USER}"
fi fi
@@ -76,11 +76,12 @@ check_fib() {
for _jail in ${JAILS}; do for _jail in ${JAILS}; do
info "[${_jail}]:" info "[${_jail}]:"
LOGIN="$(jexec -l "${_jail}" which login)"
if [ -n "${USER}" ]; then if [ -n "${USER}" ]; then
validate_user validate_user
else else
check_fib LOGIN="$(jexec -l "${_jail}" which login)"
${_setfib} jexec -l "${_jail}" /usr/bin/login -f root ${_setfib} jexec -l "${_jail}" $LOGIN -f root
fi fi
echo echo
done done
+11 -3
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> # Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@@ -57,6 +57,7 @@ convert_symlinks() {
done done
# Copy new files to destination jail # Copy new files to destination jail
info "Copying required base files to container..."
for _link in ${SYMLINKS}; do for _link in ${SYMLINKS}; do
if [ ! -d "${_link}" ]; then if [ ! -d "${_link}" ]; then
if [ -d "${bastille_releasesdir}/${RELEASE}/${_link}" ]; then if [ -d "${bastille_releasesdir}/${RELEASE}/${_link}" ]; then
@@ -100,13 +101,15 @@ revert_convert() {
start_convert() { start_convert() {
# Attempt container conversion and handle some errors # Attempt container conversion and handle some errors
DATE=$(date)
if [ -d "${bastille_jailsdir}/${TARGET}" ]; then if [ -d "${bastille_jailsdir}/${TARGET}" ]; then
info "Converting '${TARGET}' into a thickjail. This may take a while..." info "Converting '${TARGET}' into a thickjail. This may take a while..."
# Set some variables # Set some variables
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)' "${bastille_jailsdir}/${TARGET}/fstab") RELEASE=$(grep -w "${bastille_releasesdir}/.* ${bastille_jailsdir}/${TARGET}/root/.bastille" ${bastille_jailsdir}/${TARGET}/fstab | sed "s|${bastille_releasesdir}/||;s| .*||")
FSTABMOD=$(grep -w "${bastille_releasesdir}/${RELEASE} ${bastille_jailsdir}/${TARGET}/root/.bastille" "${bastille_jailsdir}/${TARGET}/fstab") FSTABMOD=$(grep -w "${bastille_releasesdir}/${RELEASE} ${bastille_jailsdir}/${TARGET}/root/.bastille" "${bastille_jailsdir}/${TARGET}/fstab")
SYMLINKS="bin boot lib libexec rescue sbin usr/bin usr/include usr/lib usr/lib32 usr/libdata usr/libexec usr/ports usr/sbin usr/share usr/src" SYMLINKS="bin boot lib libexec rescue sbin usr/bin usr/include usr/lib usr/lib32 usr/libdata usr/libexec usr/ports usr/sbin usr/share usr/src"
HASPORTS=$(grep -w ${bastille_releasesdir}/${RELEASE}/usr/ports ${bastille_jailsdir}/${TARGET}/fstab)
if [ -n "${RELEASE}" ]; then if [ -n "${RELEASE}" ]; then
cd "${bastille_jailsdir}/${TARGET}/root" cd "${bastille_jailsdir}/${TARGET}/root"
@@ -115,7 +118,12 @@ start_convert() {
convert_symlinks convert_symlinks
# Comment the line containing .bastille and rename mountpoint # Comment the line containing .bastille and rename mountpoint
sed -i '' -E "s|${FSTABMOD}|# Converted from thin to thick container on $(date)|g" "${bastille_jailsdir}/${TARGET}/fstab" sed -i '' -E "s|${FSTABMOD}|# Converted from thin to thick container on ${DATE}|g" "${bastille_jailsdir}/${TARGET}/fstab"
if [ -n "${HASPORTS}" ]; then
sed -i '' -E "s|${HASPORTS}|# Ports copied from base to container on ${DATE}|g" "${bastille_jailsdir}/${TARGET}/fstab"
info "Copying ports to container..."
cp -a "${bastille_releasesdir}/${RELEASE}/usr/ports" "${bastille_jailsdir}/${TARGET}/root/usr"
fi
mv "${bastille_jailsdir}/${TARGET}/root/.bastille" "${bastille_jailsdir}/${TARGET}/root/.bastille.old" mv "${bastille_jailsdir}/${TARGET}/root/.bastille" "${bastille_jailsdir}/${TARGET}/root/.bastille.old"
info "Conversion of '${TARGET}' completed successfully!" info "Conversion of '${TARGET}' completed successfully!"
+19 -5
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> # Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@@ -32,27 +32,41 @@
. /usr/local/etc/bastille/bastille.conf . /usr/local/etc/bastille/bastille.conf
usage() { usage() {
error_exit "Usage: bastille cp TARGET HOST_PATH CONTAINER_PATH" error_exit "Usage: bastille cp [OPTION] TARGET HOST_PATH CONTAINER_PATH"
} }
CPSOURCE="${1}"
CPDEST="${2}"
# Handle special-case commands first. # Handle special-case commands first.
case "$1" in case "$1" in
help|-h|--help) help|-h|--help)
usage usage
;; ;;
-q|--quiet)
OPTION="${1}"
CPSOURCE="${2}"
CPDEST="${3}"
;;
esac esac
if [ $# -ne 2 ]; then if [ $# -ne 2 ]; then
usage usage
fi fi
CPSOURCE="${1}" case "${OPTION}" in
CPDEST="${2}" -q|--quiet)
OPTION="-a"
;;
*)
OPTION="-av"
;;
esac
for _jail in ${JAILS}; do for _jail in ${JAILS}; do
info "[${_jail}]:" info "[${_jail}]:"
bastille_jail_path="${bastille_jailsdir}/${_jail}/root" bastille_jail_path="${bastille_jailsdir}/${_jail}/root"
cp -av "${CPSOURCE}" "${bastille_jail_path}/${CPDEST}" cp "${OPTION}" "${CPSOURCE}" "${bastille_jail_path}/${CPDEST}"
RETURN="$?" RETURN="$?"
if [ "${TARGET}" = "ALL" ]; then if [ "${TARGET}" = "ALL" ]; then
# Display the return status for reference # Display the return status for reference
+317 -106
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> # Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@@ -32,11 +32,26 @@
. /usr/local/etc/bastille/bastille.conf . /usr/local/etc/bastille/bastille.conf
usage() { usage() {
error_exit "Usage: bastille create [option] name release ip [interface]" # Build an independent usage for the create command
# If no option specified, will create a thin container by default
error_notify "Usage: bastille create [option(s)] name release ip [interface]"
cat << EOF
Options:
-E | --empty -- Creates an empty container, intended for custom jail builds (thin/thick/linux or unsupported).
-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() { 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." error_exit "A running jail matches name."
elif [ -d "${bastille_jailsdir}/${NAME}" ]; then elif [ -d "${bastille_jailsdir}/${NAME}" ]; then
error_exit "Jail: ${NAME} already created." error_exit "Jail: ${NAME} already created."
@@ -100,6 +115,13 @@ validate_netconf() {
} }
validate_release() { 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 ## check release name match, else show usage
if [ -n "${NAME_VERIFY}" ]; then if [ -n "${NAME_VERIFY}" ]; then
RELEASE="${NAME_VERIFY}" RELEASE="${NAME_VERIFY}"
@@ -141,25 +163,30 @@ ${NAME} {
EOF EOF
} }
generate_vnet_jail_conf() { generate_linux_jail_conf() {
## determine number of containers + 1 cat << EOF > "${bastille_jail_conf}"
## iterate num and grep all jail configs ${NAME} {
## define uniq_epair host.hostname = ${NAME};
local jail_list=$(bastille list jails) mount.fstab = ${bastille_jail_fstab};
if [ -n "${jail_list}" ]; then path = ${bastille_jail_path};
local list_jails_num=$(echo "${jail_list}" | wc -l | awk '{print $1}') devfs_ruleset = 4;
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 exec.start = '/bin/true';
exec.stop = '/bin/true';
persist;
allow.mount;
allow.mount.devfs;
interface = ${bastille_jail_conf_interface};
${IPX_ADDR} = ${IP};
ip6 = ${IP6_MODE};
}
EOF
}
generate_vnet_jail_conf() {
NETBLOCK=$(generate_vnet_jail_netblock "$NAME" "${VNET_JAIL_BRIDGE}" "${bastille_jail_conf_interface}")
cat << EOF > "${bastille_jail_conf}" cat << EOF > "${bastille_jail_conf}"
${NAME} { ${NAME} {
devfs_ruleset = 13; devfs_ruleset = 13;
@@ -174,14 +201,48 @@ ${NAME} {
path = ${bastille_jail_path}; path = ${bastille_jail_path};
securelevel = 2; securelevel = 2;
vnet; ${NETBLOCK}
vnet.interface = e0b_${uniq_epair};
exec.prestart += "jib addm ${uniq_epair} ${bastille_jail_conf_interface}";
exec.poststop += "jib destroy ${uniq_epair}";
} }
EOF 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() { create_jail() {
bastille_jail_base="${bastille_jailsdir}/${NAME}/root/.bastille" ## dir bastille_jail_base="${bastille_jailsdir}/${NAME}/root/.bastille" ## dir
bastille_jail_template="${bastille_jailsdir}/${NAME}/root/.template" ## dir bastille_jail_template="${bastille_jailsdir}/${NAME}/root/.template" ## dir
@@ -196,8 +257,10 @@ create_jail() {
if [ "${bastille_zfs_enable}" = "YES" ]; then if [ "${bastille_zfs_enable}" = "YES" ]; then
if [ -n "${bastille_zfs_zpool}" ]; then if [ -n "${bastille_zfs_zpool}" ]; then
## create required zfs datasets, mountpoint inherited from system ## create required zfs datasets, mountpoint inherited from system
zfs create ${bastille_zfs_options} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NAME}" if [ -z "${CLONE_JAIL}" ]; then
if [ -z "${THICK_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" zfs create ${bastille_zfs_options} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NAME}/root"
fi fi
fi fi
@@ -206,26 +269,37 @@ create_jail() {
fi fi
fi fi
if [ -z "${EMPTY_JAIL}" ]; then ## 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 if [ ! -d "${bastille_jail_base}" ]; then
mkdir -p "${bastille_jail_base}" mkdir -p "${bastille_jail_base}"
fi fi
mkdir -p "${bastille_jail_path}/dev"
if [ ! -d "${bastille_jail_path}/usr/local" ]; then mkdir -p "${bastille_jail_path}/proc"
mkdir -p "${bastille_jail_path}/usr/local" mkdir -p "${bastille_jail_path}/sys"
fi mkdir -p "${bastille_jail_path}/home"
mkdir -p "${bastille_jail_path}/tmp"
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
if [ ! -d "${bastille_jail_template}" ]; then if [ ! -d "${bastille_jail_template}" ]; then
mkdir -p "${bastille_jail_template}" mkdir -p "${bastille_jail_template}"
fi fi
if [ ! -f "${bastille_jail_fstab}" ]; then if [ ! -f "${bastille_jail_fstab}" ]; then
if [ -z "${THICK_JAIL}" ]; then touch "${bastille_jail_fstab}"
echo -e "${bastille_releasesdir}/${RELEASE} ${bastille_jail_base} nullfs ro 0 0" > "${bastille_jail_fstab}"
else
touch "${bastille_jail_fstab}"
fi
fi 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}"
## removed temporarely / only for X11 jails? @hackacad
#echo -e "/home ${bastille_jail_path}/home nullfs rw 0 0" >> "${bastille_jail_fstab}"
if [ ! -f "${bastille_jail_conf}" ]; then if [ ! -f "${bastille_jail_conf}" ]; then
if [ -z "${bastille_network_loopback}" ] && [ -n "${bastille_network_shared}" ]; then if [ -z "${bastille_network_loopback}" ] && [ -n "${bastille_network_shared}" ]; then
@@ -237,32 +311,33 @@ create_jail() {
if [ -n "${INTERFACE}" ]; then if [ -n "${INTERFACE}" ]; then
local bastille_jail_conf_interface=${INTERFACE} local bastille_jail_conf_interface=${INTERFACE}
fi fi
fi
fi
## generate the jail configuration file if [ -z "${EMPTY_JAIL}" ] && [ -z "${LINUX_JAIL}" ]; then
if [ -n "${VNET_JAIL}" ]; then if [ -z "${THICK_JAIL}" ] && [ -z "${CLONE_JAIL}" ]; then
generate_vnet_jail_conf if [ ! -d "${bastille_jail_base}" ]; then
else mkdir -p "${bastille_jail_base}"
generate_jail_conf fi
if [ ! -d "${bastille_jail_template}" ]; then
mkdir -p "${bastille_jail_template}"
fi fi
fi fi
## using relative paths here if [ ! -d "${bastille_jail_path}/usr/local" ]; then
## MAKE SURE WE'RE IN THE RIGHT PLACE mkdir -p "${bastille_jail_path}/usr/local"
cd "${bastille_jail_path}"
echo
info "NAME: ${NAME}."
info "IP: ${IP}."
if [ -n "${INTERFACE}" ]; then
info "INTERFACE: ${INTERFACE}."
fi fi
info "RELEASE: ${RELEASE}."
echo
if [ -z "${THICK_JAIL}" ]; then # Check and apply required settings.
post_create_jail
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" 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 for _link in ${LINK_LIST}; do
ln -sf /.bastille/${_link} ${_link} ln -sf /.bastille/${_link} ${_link}
done done
# Properly link shared ports on thin jails in read-write. # Properly link shared ports on thin jails in read-write.
if [ -d "${bastille_releasesdir}/${RELEASE}/usr/ports" ]; then if [ -d "${bastille_releasesdir}/${RELEASE}/usr/ports" ]; then
if [ ! -d "${bastille_jail_path}/usr/ports" ]; then if [ ! -d "${bastille_jail_path}/usr/ports" ]; then
@@ -272,14 +347,13 @@ create_jail() {
fi fi
fi fi
if [ -z "${THICK_JAIL}" ]; then if [ -z "${THICK_JAIL}" ] && [ -z "${CLONE_JAIL}" ]; then
## rw ## rw
## copy only required files for thin jails ## 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" FILE_LIST=".cshrc .profile COPYRIGHT dev etc media mnt net proc root tmp var usr/obj usr/tests"
for files in ${FILE_LIST}; do for files in ${FILE_LIST}; do
if [ -f "${bastille_releasesdir}/${RELEASE}/${files}" ] || [ -d "${bastille_releasesdir}/${RELEASE}/${files}" ]; then if [ -f "${bastille_releasesdir}/${RELEASE}/${files}" ] || [ -d "${bastille_releasesdir}/${RELEASE}/${files}" ]; then
cp -a "${bastille_releasesdir}/${RELEASE}/${files}" "${bastille_jail_path}/${files}" if ! cp -a "${bastille_releasesdir}/${RELEASE}/${files}" "${bastille_jail_path}/${files}"; then
if [ "$?" -ne 0 ]; then
## notify and clean stale files/directories ## notify and clean stale files/directories
bastille destroy "${NAME}" bastille destroy "${NAME}"
error_exit "Failed to copy release files. Please retry create!" error_exit "Failed to copy release files. Please retry create!"
@@ -287,27 +361,40 @@ create_jail() {
fi fi
done done
else else
info "Creating a thickjail. This may take a while..."
if [ "${bastille_zfs_enable}" = "YES" ]; then if [ "${bastille_zfs_enable}" = "YES" ]; then
if [ -n "${bastille_zfs_zpool}" ]; 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 clone -p "${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${RELEASE}"@"${SNAP_NAME}" \
ZFS_OPTIONS=$(echo ${bastille_zfs_options} | sed 's/-o//g') "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NAME}/root"
## take a temp snapshot of the base release # Check and apply required settings.
SNAP_NAME="bastille-$(date +%Y-%m-%d-%H%M%S)" post_create_jail
zfs snapshot "${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${RELEASE}"@"${SNAP_NAME}" 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 ## sane bastille zfs options
zfs send -R "${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${RELEASE}"@"${SNAP_NAME}" | \ ZFS_OPTIONS=$(echo ${bastille_zfs_options} | sed 's/-o//g')
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 ## take a temp snapshot of the base release
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${RELEASE}"@"${SNAP_NAME}" SNAP_NAME="bastille-$(date +%Y-%m-%d-%H%M%S)"
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NAME}/root"@"${SNAP_NAME}" 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 if [ "$?" -ne 0 ]; then
## notify and clean stale files/directories ## notify and clean stale files/directories
@@ -326,23 +413,33 @@ create_jail() {
fi fi
fi fi
## create home directory if missing if [ -z "${LINUX_JAIL}" ]; then
if [ ! -d "${bastille_jail_path}/usr/home" ]; then ## create home directory if missing
mkdir -p "${bastille_jail_path}/usr/home" if [ ! -d "${bastille_jail_path}/usr/home" ]; then
fi mkdir -p "${bastille_jail_path}/usr/home"
## link home properly fi
if [ ! -L "home" ]; then ## link home properly
ln -s usr/home home if [ ! -L "home" ]; then
fi ln -s usr/home home
fi
## TZ: configurable (default: Etc/UTC) ## TZ: configurable (default: empty to use host's time zone)
ln -s "/usr/share/zoneinfo/${bastille_tzdata}" etc/localtime 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 # Post-creation jail misc configuration
# Create a dummy fstab file # Create a dummy fstab file
touch "etc/fstab" touch "etc/fstab"
# Disables adjkerntz, avoids spurious error messages # Disables adjkerntz, avoids spurious error messages
sed -i '' 's|[0-9],[0-9]\{2\}.*[0-9]-[0-9].*root.*kerntz -a|#& # Disabled by bastille|' "etc/crontab" sed -i '' 's|[0-9],[0-9]\{2\}.*[0-9]-[0-9].*root.*kerntz -a|#& # Disabled by bastille|' "etc/crontab"
fi
## VNET specific ## VNET specific
if [ -n "${VNET_JAIL}" ]; then if [ -n "${VNET_JAIL}" ]; then
@@ -353,7 +450,10 @@ create_jail() {
fi fi
fi fi
fi fi
else elif [ -n "${LINUX_JAIL}" ]; then
## Generate configuration for Linux jail
generate_linux_jail_conf
elif [ -n "${EMPTY_JAIL}" ]; then
## Generate minimal configuration for empty jail ## Generate minimal configuration for empty jail
generate_minimal_conf generate_minimal_conf
fi fi
@@ -377,33 +477,57 @@ create_jail() {
uniq_epair=$(grep vnet.interface "${bastille_jailsdir}/${NAME}/jail.conf" | awk '{print $3}' | sed 's/;//') uniq_epair=$(grep vnet.interface "${bastille_jailsdir}/${NAME}/jail.conf" | awk '{print $3}' | sed 's/;//')
_gateway='' _gateway=''
_gateway6=''
_ifconfig=SYNCDHCP _ifconfig=SYNCDHCP
if [ "${IP}" != "0.0.0.0" ]; then # not using DHCP, so set static address. if [ "${IP}" != "0.0.0.0" ]; then # not using DHCP, so set static address.
_ifconfig="inet ${IP}" if [ -n "${ip6}" ]; then
_ifconfig="inet6 ${IP}"
else
_ifconfig="inet ${IP}"
fi
if [ -n "${bastille_network_gateway}" ]; then if [ -n "${bastille_network_gateway}" ]; then
_gateway="${bastille_network_gateway}" _gateway="${bastille_network_gateway}"
elif [ -n "${bastille_network_gateway6}" ]; then
_gateway6="${bastille_network_gateway6}"
else else
_gateway="$(netstat -rn | awk '/default/ {print $2}')" if [ -z ${ip6} ]; then
_gateway="$(netstat -4rn | awk '/default/ {print $2}')"
else
_gateway="$(netstat -6rn | awk '/default/ {print $2}')"
fi
fi fi
fi fi
bastille template "${NAME}" ${bastille_template_vnet} --arg BASE_TEMPLATE="${bastille_template_base}" --arg HOST_RESOLV_CONF="${bastille_resolv_conf}" --arg EPAIR="${uniq_epair}" --arg GATEWAY="${_gateway}" --arg IFCONFIG="${_ifconfig}" bastille template "${NAME}" ${bastille_template_vnet} --arg BASE_TEMPLATE="${bastille_template_base}" --arg HOST_RESOLV_CONF="${bastille_resolv_conf}" --arg EPAIR="${uniq_epair}" --arg GATEWAY="${_gateway}" --arg GATEWAY6="${_gateway6}" --arg IFCONFIG="${_ifconfig}"
fi fi
elif [ -n "${THICK_JAIL}" ]; then elif [ -n "${THICK_JAIL}" ]; then
if [ -n "${bastille_template_thick}" ]; 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}" bastille template "${NAME}" ${bastille_template_thick} --arg BASE_TEMPLATE="${bastille_template_base}" --arg HOST_RESOLV_CONF="${bastille_resolv_conf}"
fi 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 elif [ -n "${EMPTY_JAIL}" ]; then
if [ -n "${bastille_template_empty}" ]; 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}" bastille template "${NAME}" ${bastille_template_empty} --arg BASE_TEMPLATE="${bastille_template_base}" --arg HOST_RESOLV_CONF="${bastille_resolv_conf}"
fi fi
else # Thin jail. ## Using templating function to fetch necessary packges @hackacad
elif [ -n "${LINUX_JAIL}" ]; then
info "Fetching packages..."
jexec -l "${NAME}" /bin/bash -c "DEBIAN_FRONTEND=noninteractive rm /var/cache/apt/archives/rsyslog*.deb"
jexec -l "${NAME}" /bin/bash -c "DEBIAN_FRONTEND=noninteractive dpkg --force-depends --force-confdef --force-confold -i /var/cache/apt/archives/*.deb"
jexec -l "${NAME}" /bin/bash -c "DEBIAN_FRONTEND=noninteractive dpkg --force-depends --force-confdef --force-confold -i /var/cache/apt/archives/*.deb"
jexec -l "${NAME}" /bin/bash -c "chmod 777 /tmp"
jexec -l "${NAME}" /bin/bash -c "apt update"
else
# Thin jail.
if [ -n "${bastille_template_thin}" ]; then if [ -n "${bastille_template_thin}" ]; then
bastille template "${NAME}" ${bastille_template_thin} --arg BASE_TEMPLATE="${bastille_template_base}" --arg HOST_RESOLV_CONF="${bastille_resolv_conf}" bastille template "${NAME}" ${bastille_template_thin} --arg BASE_TEMPLATE="${bastille_template_base}" --arg HOST_RESOLV_CONF="${bastille_resolv_conf}"
fi fi
fi fi
# Apply values changed by the template. -- cwells # Apply values changed by the template. -- cwells
if [ -z "${EMPTY_JAIL}" ]; then if [ -z "${EMPTY_JAIL}" ] && [ -z "${LINUX_JAIL}" ]; then
bastille restart "${NAME}" bastille restart "${NAME}"
elif [ -n "${EMPTY_JAIL}" ]; then elif [ -n "${EMPTY_JAIL}" ]; then
# Don't restart empty jails unless a template defined. # Don't restart empty jails unless a template defined.
@@ -428,34 +552,59 @@ fi
## reset this options ## reset this options
EMPTY_JAIL="" EMPTY_JAIL=""
THICK_JAIL="" THICK_JAIL=""
CLONE_JAIL=""
VNET_JAIL="" VNET_JAIL=""
LINUX_JAIL=""
## handle combined options then shift # Handle and parse options
if [ "${1}" = "-T" -o "${1}" = "--thick" -o "${1}" = "thick" ] && \ while [ $# -gt 0 ]; do
[ "${2}" = "-V" -o "${2}" = "--vnet" -o "${2}" = "vnet" ]; then
THICK_JAIL="1"
VNET_JAIL="1"
shift 2
else
## handle single options
case "${1}" in case "${1}" in
-E|--empty|empty) -E|--empty|empty)
shift
EMPTY_JAIL="1" EMPTY_JAIL="1"
shift
;;
-L|--linux|linux)
LINUX_JAIL="1"
shift
;; ;;
-T|--thick|thick) -T|--thick|thick)
shift
THICK_JAIL="1" THICK_JAIL="1"
shift
;; ;;
-V|--vnet|vnet) -V|--vnet|vnet)
shift
VNET_JAIL="1" 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." error_notify "Unknown Option."
usage usage
;; ;;
*)
break
;;
esac esac
done
## validate for combined options
if [ -n "${EMPTY_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}" ] || [ -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 fi
NAME="$1" NAME="$1"
@@ -478,17 +627,51 @@ if [ -n "${NAME}" ]; then
validate_name validate_name
fi fi
if [ -n "${LINUX_JAIL}" ]; then
case "${RELEASE}" in
bionic|ubuntu_bionic|ubuntu|ubuntu-bionic)
## check for FreeBSD releases name
NAME_VERIFY=ubuntu_bionic
;;
focal|ubuntu_focal|ubuntu-focal)
## check for FreeBSD releases name
NAME_VERIFY=ubuntu_focal
;;
debian_stretch|stretch|debian-stretch)
## check for FreeBSD releases name
NAME_VERIFY=stretch
;;
debian_buster|buster|debian-buster)
## check for FreeBSD releases name
NAME_VERIFY=buster
;;
debian_bullseye|bullseye|debian-bullseye)
## check for FreeBSD releases name
NAME_VERIFY=bullseye
;;
*)
error_notify "Unknown Linux."
usage
;;
esac
fi
if [ -z "${EMPTY_JAIL}" ]; then if [ -z "${EMPTY_JAIL}" ]; then
## verify release ## verify release
case "${RELEASE}" in case "${RELEASE}" in
2.[0-9]*)
## check for MidnightBSD releases name
NAME_VERIFY=$(echo "${RELEASE}")
validate_release
;;
*-CURRENT|*-CURRENT-I386|*-CURRENT-i386|*-current) *-CURRENT|*-CURRENT-I386|*-CURRENT-i386|*-current)
## check for FreeBSD releases name ## check for FreeBSD releases name
NAME_VERIFY=$(echo "${RELEASE}" | grep -iwE '^([1-9]{2,2})\.[0-9](-CURRENT|-CURRENT-i386)$' | tr '[:lower:]' '[:upper:]' | sed 's/I/i/g') NAME_VERIFY=$(echo "${RELEASE}" | grep -iwE '^([1-9]{2,2})\.[0-9](-CURRENT|-CURRENT-i386)$' | tr '[:lower:]' '[:upper:]' | sed 's/I/i/g')
validate_release validate_release
;; ;;
*-RELEASE|*-RELEASE-I386|*-RELEASE-i386|*-release|*-RC1|*-rc1|*-RC2|*-rc2) *-RELEASE|*-RELEASE-I386|*-RELEASE-i386|*-release|*-RC1|*-rc1|*-RC2|*-rc2|*-BETA1|*-BETA2|*-BETA3|*-BETA4|*-BETA5)
## check for FreeBSD releases name ## check for FreeBSD releases name
NAME_VERIFY=$(echo "${RELEASE}" | grep -iwE '^([1-9]{2,2})\.[0-9](-RELEASE|-RELEASE-i386|-RC[1-2])$' | tr '[:lower:]' '[:upper:]' | sed 's/I/i/g') NAME_VERIFY=$(echo "${RELEASE}" | grep -iwE '^([1-9]{2,2})\.[0-9](-RELEASE|-RELEASE-i386|-RC[1-2]|-BETA[1-5])$' | tr '[:lower:]' '[:upper:]' | sed 's/I/i/g')
validate_release validate_release
;; ;;
*-stable-LAST|*-STABLE-last|*-stable-last|*-STABLE-LAST) *-stable-LAST|*-STABLE-last|*-stable-last|*-STABLE-LAST)
@@ -516,6 +699,28 @@ if [ -z "${EMPTY_JAIL}" ]; then
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_VERIFY=$(echo "${RELEASE}" | grep -iwE '(current-build-latest)' | sed 's/CURRENT/current/g' | sed 's/build/BUILD/g' | sed 's/latest/LATEST/g')
validate_release validate_release
;; ;;
ubuntu_bionic|bionic|ubuntu-bionic)
UBUNTU="1"
NAME_VERIFY=Ubuntu_1804
validate_release
;;
ubuntu_focal|focal|ubuntu-focal)
UBUNTU="1"
NAME_VERIFY=Ubuntu_2004
validate_release
;;
debian_stretch|stretch|debian-stretch)
NAME_VERIFY=Debian9
validate_release
;;
debian_buster|buster|debian-buster)
NAME_VERIFY=Debian10
validate_release
;;
debian_bullseye|bullseye|debian-bullseye)
NAME_VERIFY=Debian11
validate_release
;;
*) *)
error_notify "Unknown Release." error_notify "Unknown Release."
usage usage
@@ -577,9 +782,15 @@ fi
if [ -z ${bastille_template_empty+x} ]; then if [ -z ${bastille_template_empty+x} ]; then
bastille_template_empty='default/empty' bastille_template_empty='default/empty'
fi fi
if [ -z ${bastille_template_linux+x} ]; then
bastille_template_linux='default/linux'
fi
if [ -z ${bastille_template_thick+x} ]; then if [ -z ${bastille_template_thick+x} ]; then
bastille_template_thick='default/thick' bastille_template_thick='default/thick'
fi fi
if [ -z ${bastille_template_clone+x} ]; then
bastille_template_clone='default/clone'
fi
if [ -z ${bastille_template_thin+x} ]; then if [ -z ${bastille_template_thin+x} ]; then
bastille_template_thin='default/thin' bastille_template_thin='default/thin'
fi fi
+37 -10
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> # Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@@ -32,7 +32,7 @@
. /usr/local/etc/bastille/bastille.conf . /usr/local/etc/bastille/bastille.conf
usage() { usage() {
error_exit "Usage: bastille destroy [option] | [container|release]" error_exit "Usage: bastille destroy [force] | [container|release]"
} }
destroy_jail() { destroy_jail() {
@@ -40,7 +40,7 @@ destroy_jail() {
bastille_jail_base="${bastille_jailsdir}/${TARGET}" ## dir bastille_jail_base="${bastille_jailsdir}/${TARGET}" ## dir
bastille_jail_log="${bastille_logsdir}/${TARGET}_console.log" ## file 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 if [ "${FORCE}" = "1" ]; then
bastille stop "${TARGET}" bastille stop "${TARGET}"
else else
@@ -118,6 +118,23 @@ destroy_rel() {
if grep -qwo "${TARGET}" "${bastille_jailsdir}/${_jail}/fstab" 2>/dev/null; then if grep -qwo "${TARGET}" "${bastille_jailsdir}/${_jail}/fstab" 2>/dev/null; then
error_notify "Notice: (${_jail}) depends on ${TARGET} base." error_notify "Notice: (${_jail}) depends on ${TARGET} base."
BASE_HASCHILD="1" 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 fi
done done
fi fi
@@ -200,34 +217,44 @@ case "${TARGET}" in
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '^([1-9]{2,2})\.[0-9](-CURRENT|-CURRENT-i386)$' | tr '[:lower:]' '[:upper:]' | sed 's/I/i/g') NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '^([1-9]{2,2})\.[0-9](-CURRENT|-CURRENT-i386)$' | tr '[:lower:]' '[:upper:]' | sed 's/I/i/g')
destroy_rel destroy_rel
;; ;;
*-RELEASE|*-RELEASE-I386|*-RELEASE-i386|*-release|*-RC1|*-rc1|*-RC2|*-rc2) *-RELEASE|*-RELEASE-I386|*-RELEASE-i386|*-release|*-RC1|*-rc1|*-RC2|*-rc2|*-RC3|*-rc3|*-RC4|*-rc4|*-RC5|*-rc5|*-BETA1|*-BETA2|*-BETA3|*-BETA4|*-BETA5)
## check for FreeBSD releases name ## check for FreeBSD releases name
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '^([1-9]{2,2})\.[0-9](-RELEASE|-RELEASE-i386|-RC[1-2])$' | tr '[:lower:]' '[:upper:]' | sed 's/I/i/g') NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '^([1-9]{2,2})\.[0-9](-RELEASE|-RELEASE-i386|-RC[1-5]|-BETA[1-5])$' | tr '[:lower:]' '[:upper:]' | sed 's/I/i/g')
destroy_rel destroy_rel
;; ;;
*-stable-LAST|*-STABLE-last|*-stable-last|*-STABLE-LAST) *-stable-LAST|*-STABLE-last|*-stable-last|*-STABLE-LAST)
## check for HardenedBSD releases name ## 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 destroy_rel
;; ;;
*-stable-build-[0-9]*|*-STABLE-BUILD-[0-9]*) *-stable-build-[0-9]*|*-STABLE-BUILD-[0-9]*)
## check for HardenedBSD(specific stable build releases) ## 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 destroy_rel
;; ;;
*-stable-build-latest|*-stable-BUILD-LATEST|*-STABLE-BUILD-LATEST) *-stable-build-latest|*-stable-BUILD-LATEST|*-STABLE-BUILD-LATEST)
## check for HardenedBSD(latest stable build release) ## 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 destroy_rel
;; ;;
current-build-[0-9]*|CURRENT-BUILD-[0-9]*) current-build-[0-9]*|CURRENT-BUILD-[0-9]*)
## check for HardenedBSD(specific current build releases) ## 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 destroy_rel
;; ;;
current-build-latest|current-BUILD-LATEST|CURRENT-BUILD-LATEST) current-build-latest|current-BUILD-LATEST|CURRENT-BUILD-LATEST)
## check for HardenedBSD(latest current build release) ## check for HardenedBSD(latest current build release)
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '(current-build-latest)$' | sed 's/CURRENT/current/g' | sed 's/build/BUILD/g' | sed 's/latest/LATEST/g') NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '(current-build-latest)$' | sed 's/CURRENT/current/;s/build/BUILD/g;s/latest/LATEST/g')
destroy_rel
;;
Ubuntu_1804|Ubuntu_2004|UBUNTU_1804|UBUNTU_2004)
## check for Linux releases
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '(Ubuntu_1804)$|(Ubuntu_2004)$' | sed 's/UBUNTU/Ubuntu/g;s/ubuntu/Ubuntu/g')
destroy_rel
;;
Debian9|Debian10|Debian11|DEBIAN9|DEBIAN10|DEBIAN11)
## check for Linux releases
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '(Debian9)$|(Debian10)$|(Debian11)$' | sed 's/DEBIAN/Debian/g')
destroy_rel destroy_rel
;; ;;
*) *)
+1 -1
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> # Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
+303 -62
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> # Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@@ -32,7 +32,27 @@
. /usr/local/etc/bastille/bastille.conf . /usr/local/etc/bastille/bastille.conf
usage() { usage() {
error_exit "Usage: bastille export TARGET [option] | PATH" # Build an independent usage for the export command
# Valid compress/options for ZFS systems are raw, .gz, .tgz, .txz and .xz
# Valid compress/options for non ZFS configured systems are .tgz and .txz
# If no compression option specified, user must redirect standard output
error_notify "Usage: bastille export | option(s) | TARGET | PATH"
cat << EOF
Options:
--gz -- Export a ZFS jail using GZIP(.gz) compressed image.
-r | --raw -- Export a ZFS jail to an uncompressed RAW image.
-s | --safe -- Safely stop and start a ZFS jail before the exporting process.
--tgz -- Export a jail using simple .tgz compressed archive instead.
--txz -- Export a jail using simple .txz compressed archive instead.
-v | --verbose -- Be more verbose during the ZFS send operation.
--xz -- Export a ZFS jail using XZ(.xz) compressed image.
Note: If no export option specified, the container should be redirected to standard output.
EOF
exit 1
} }
# Handle special-case commands first # Handle special-case commands first
@@ -47,90 +67,306 @@ if [ "${TARGET}" = "ALL" ]; then
error_exit "Batch export is unsupported." error_exit "Batch export is unsupported."
fi fi
if [ $# -gt 2 ] || [ $# -lt 0 ]; then if [ $# -gt 5 ] || [ $# -lt 1 ]; then
usage usage
fi fi
OPTION="${1}" zfs_enable_check() {
EXPATH="${2}" # Temporarily disable ZFS so we can create a standard backup archive
SAFE_EXPORT= if [ "${bastille_zfs_enable}" = "YES" ]; then
bastille_zfs_enable="NO"
fi
}
# Handle some options TARGET="${1}"
if [ -n "${OPTION}" ]; then GZIP_EXPORT=
if [ "${OPTION}" = "-t" -o "${OPTION}" = "--txz" ]; then XZ_EXPORT=
if [ "${bastille_zfs_enable}" = "YES" ]; then SAFE_EXPORT=
# Temporarily disable ZFS so we can create a standard backup archive USER_EXPORT=
bastille_zfs_enable="NO" RAW_EXPORT=
fi DIR_EXPORT=
elif [ "${OPTION}" = "-s" -o "${OPTION}" = "--safe" ]; then TXZ_EXPORT=
SAFE_EXPORT="1" TGZ_EXPORT=
elif echo "${OPTION}" | grep -q "\/"; then OPT_ZSEND="-R"
if [ -d "${OPTION}" ]; then COMP_OPTION="0"
EXPATH="${OPTION}"
else opt_count() {
error_exit "Error: Path not found." COMP_OPTION=$(expr ${COMP_OPTION} + 1)
fi }
else
error_notify "Invalid option!" if [ -n "${bastille_export_options}" ]; then
usage # Overrides the case options by the user defined option(s) automatically.
# Add bastille_export_options="--optionA --optionB" to bastille.conf, or simply `export bastille_export_options="--optionA --optionB"` environment variable.
# To restore the standard case options, empty bastille_export_options="" in bastille.conf, or `unset bastille_export_options` environment variable.
# Reference "/bastille/issues/443"
DEFAULT_EXPORT_OPTS="${bastille_export_options}"
info "Default export option(s): '${DEFAULT_EXPORT_OPTS}'"
for opt in ${DEFAULT_EXPORT_OPTS}; do
case "${opt}" in
--gz)
GZIP_EXPORT="1"
opt_count
shift;;
--xz)
XZ_EXPORT="1"
opt_count
shift;;
--tgz)
TGZ_EXPORT="1"
opt_count
zfs_enable_check
shift;;
--txz)
TXZ_EXPORT="1"
opt_count
zfs_enable_check
shift;;
--safe)
SAFE_EXPORT="1"
shift;;
--raw)
RAW_EXPORT="1"
opt_count
shift ;;
--verbose)
OPT_ZSEND="-Rv"
shift;;
-*|--*) error_notify "Unknown Option."
usage;;
esac
done
else
# Handle and parse option args
while [ $# -gt 0 ]; do
case "${1}" in
--gz)
GZIP_EXPORT="1"
TARGET="${2}"
opt_count
shift
;;
--xz)
XZ_EXPORT="1"
TARGET="${2}"
opt_count
shift
;;
--tgz)
TGZ_EXPORT="1"
TARGET="${2}"
opt_count
zfs_enable_check
shift
;;
--txz)
TXZ_EXPORT="1"
TARGET="${2}"
opt_count
zfs_enable_check
shift
;;
-s|--safe)
SAFE_EXPORT="1"
TARGET="${2}"
shift
;;
-r|--raw)
RAW_EXPORT="1"
TARGET="${2}"
opt_count
shift
;;
-v|--verbose)
OPT_ZSEND="-Rv"
TARGET="${2}"
shift
;;
-*|--*)
error_notify "Unknown Option."
usage
;;
*)
if echo "${1}" | grep -q "\/"; then
DIR_EXPORT="${1}"
else
if [ $# -gt 2 ] || [ $# -lt 1 ]; then
usage
fi
fi
shift
;;
esac
done
fi
# Validate for combined options
if [ "${COMP_OPTION}" -gt "1" ]; then
error_exit "Error: Only one compression format can be used during export."
fi
if [ -n "${TXZ_EXPORT}" -o -n "${TGZ_EXPORT}" ] && [ -n "${SAFE_EXPORT}" ]; then
error_exit "Error: Simple archive modes with safe ZFS export can't be used together."
fi
if [ -z "${bastille_zfs_enable}" ]; then
if [ -n "${GZIP_EXPORT}" -o -n "${RAW_EXPORT}" -o -n "${SAFE_EXPORT}" -o "${OPT_ZSEND}" = "-Rv" ]; then
error_exit "Options --gz, --raw, --safe, --verbose are valid for ZFS configured systems only."
fi
fi
if [ -n "${SAFE_EXPORT}" ]; then
# Check if container is running, otherwise just ignore
if [ -z "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
SAFE_EXPORT=
fi fi
fi fi
# Export directory check # Export directory check
if [ -n "${EXPATH}" ]; then if [ -n "${DIR_EXPORT}" ]; then
if [ -d "${EXPATH}" ]; then if [ -d "${DIR_EXPORT}" ]; then
# Set the user defined export directory # Set the user defined export directory
bastille_backupsdir="${EXPATH}" bastille_backupsdir="${DIR_EXPORT}"
else else
error_exit "Error: Path not found." error_exit "Error: Path not found."
fi fi
fi fi
create_zfs_snap(){ # Fallback to default if missing config parameters
if [ -z "${bastille_compress_xz_options}" ]; then
bastille_compress_xz_options="-0 -v"
fi
if [ -z "${bastille_compress_gz_options}" ]; then
bastille_compress_gz_options="-1 -v"
fi
create_zfs_snap() {
# Take a recursive temporary snapshot # Take a recursive temporary snapshot
info "Creating temporary ZFS snapshot for export..." if [ -z "${USER_EXPORT}" ]; then
zfs snapshot -r "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_export_${DATE}" info "Creating temporary ZFS snapshot for export..."
fi
zfs snapshot -r "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_${TARGET}_${DATE}"
} }
jail_export() clean_zfs_snap() {
{ # Cleanup the recursive temporary snapshot
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}/root@bastille_${TARGET}_${DATE}"
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_${TARGET}_${DATE}"
}
export_check() {
# Inform the user about the exporting method
if [ -z "${USER_EXPORT}" ]; then
if [ -n "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
if [ -n "${SAFE_EXPORT}" ]; then
EXPORT_AS="Safely exporting"
else
EXPORT_AS="Hot exporting"
fi
else
EXPORT_AS="Exporting"
fi
if [ "${FILE_EXT}" = ".xz" -o "${FILE_EXT}" = ".gz" -o "${FILE_EXT}" = "" ]; then
EXPORT_TYPE="image"
else
EXPORT_TYPE="archive"
fi
if [ -n "${RAW_EXPORT}" ]; then
EXPORT_INFO="to a raw ${EXPORT_TYPE}"
else
EXPORT_INFO="to a compressed ${FILE_EXT} ${EXPORT_TYPE}"
fi
info "${EXPORT_AS} '${TARGET}' ${EXPORT_INFO}..."
fi
# Safely stop and snapshot the jail
if [ -n "${SAFE_EXPORT}" ]; then
bastille stop ${TARGET}
create_zfs_snap
bastille start ${TARGET}
else
create_zfs_snap
fi
if [ "${bastille_zfs_enable}" = "YES" ]; then
if [ -z "${USER_EXPORT}" ]; then
info "Sending ZFS data stream..."
fi
fi
}
jail_export() {
# Attempt to export the container # Attempt to export the container
DATE=$(date +%F-%H%M%S) DATE=$(date +%F-%H%M%S)
if [ "${bastille_zfs_enable}" = "YES" ]; then if [ "${bastille_zfs_enable}" = "YES" ]; then
if [ -n "${bastille_zfs_zpool}" ]; then if [ -n "${bastille_zfs_zpool}" ]; then
FILE_EXT="xz" if [ -n "${RAW_EXPORT}" ]; then
FILE_EXT=""
export_check
if [ -n "${SAFE_EXPORT}" ]; then # Export the raw container recursively and cleanup temporary snapshots
info "Safely exporting '${TARGET}' to a compressed .${FILE_EXT} archive." zfs send ${OPT_ZSEND} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_${TARGET}_${DATE}" \
bastille stop ${TARGET} > "${bastille_backupsdir}/${TARGET}_${DATE}"
create_zfs_snap clean_zfs_snap
bastille start ${TARGET} elif [ -n "${GZIP_EXPORT}" ]; then
FILE_EXT=".gz"
export_check
# Export the raw container recursively and cleanup temporary snapshots
zfs send ${OPT_ZSEND} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_${TARGET}_${DATE}" | \
gzip ${bastille_compress_gz_options} > "${bastille_backupsdir}/${TARGET}_${DATE}${FILE_EXT}"
clean_zfs_snap
elif [ -n "${XZ_EXPORT}" ]; then
FILE_EXT=".xz"
export_check
# Export the container recursively and cleanup temporary snapshots
zfs send ${OPT_ZSEND} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_${TARGET}_${DATE}" | \
xz ${bastille_compress_xz_options} > "${bastille_backupsdir}/${TARGET}_${DATE}${FILE_EXT}"
clean_zfs_snap
else else
info "Hot exporting '${TARGET}' to a compressed .${FILE_EXT} archive." FILE_EXT=""
create_zfs_snap USER_EXPORT="1"
fi export_check
info "Sending ZFS data stream..." # Quietly export the container recursively, user must redirect standard output
# Export the container recursively and cleanup temporary snapshots if ! zfs send ${OPT_ZSEND} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_${TARGET}_${DATE}"; then
zfs send -R "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_export_${DATE}" | \ clean_zfs_snap
xz ${bastille_compress_xz_options} > "${bastille_backupsdir}/${TARGET}_${DATE}.${FILE_EXT}" error_notify "\nError: An export option is required, see 'bastille export, otherwise the user must redirect to standard output."
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}/root@bastille_export_${DATE}" fi
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_export_${DATE}" fi
fi fi
else else
# Create standard backup archive if [ -n "${TGZ_EXPORT}" ]; then
FILE_EXT="txz" FILE_EXT=".tgz"
info "Exporting '${TARGET}' to a compressed .${FILE_EXT} archive..."
cd "${bastille_jailsdir}" && tar -cf - "${TARGET}" | xz ${bastille_compress_xz_options} > "${bastille_backupsdir}/${TARGET}_${DATE}.${FILE_EXT}" # Create standard tgz backup archive
info "Exporting '${TARGET}' to a compressed ${FILE_EXT} archive..."
cd "${bastille_jailsdir}" && tar -cf - "${TARGET}" | gzip ${bastille_compress_gz_options} > "${bastille_backupsdir}/${TARGET}_${DATE}${FILE_EXT}"
elif [ -n "${TXZ_EXPORT}" ]; then
FILE_EXT=".txz"
# Create standard txz backup archive
info "Exporting '${TARGET}' to a compressed ${FILE_EXT} archive..."
cd "${bastille_jailsdir}" && tar -cf - "${TARGET}" | xz ${bastille_compress_xz_options} > "${bastille_backupsdir}/${TARGET}_${DATE}${FILE_EXT}"
else
error_exit "Error: export option required"
fi
fi fi
if [ "$?" -ne 0 ]; then if [ "$?" -ne 0 ]; then
error_exit "Failed to export '${TARGET}' container." error_exit "Failed to export '${TARGET}' container."
else else
# Generate container checksum file if [ -z "${USER_EXPORT}" ]; then
cd "${bastille_backupsdir}" # Generate container checksum file
sha256 -q "${TARGET}_${DATE}.${FILE_EXT}" > "${TARGET}_${DATE}.sha256" cd "${bastille_backupsdir}"
info "Exported '${bastille_backupsdir}/${TARGET}_${DATE}.${FILE_EXT}' successfully." sha256 -q "${TARGET}_${DATE}${FILE_EXT}" > "${TARGET}_${DATE}.sha256"
info "Exported '${bastille_backupsdir}/${TARGET}_${DATE}${FILE_EXT}' successfully."
fi
exit 0 exit 0
fi fi
} }
@@ -140,12 +376,17 @@ if [ ! -d "${bastille_backupsdir}" ]; then
error_exit "Backups directory/dataset does not exist. See 'bastille bootstrap'." error_exit "Backups directory/dataset does not exist. See 'bastille bootstrap'."
fi fi
# Check if is a ZFS system if [ -n "${TARGET}" ]; then
if [ "${bastille_zfs_enable}" != "YES" ]; then if [ ! -d "${bastille_jailsdir}/${TARGET}" ]; then
# Check if container is running and ask for stop in UFS systems error_exit "[${TARGET}]: Not found."
if [ -n "$(jls name | awk "/^${TARGET}$/")" ]; then
error_exit "${TARGET} is running. See 'bastille stop'."
fi fi
fi
jail_export # 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 "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
error_exit "${TARGET} is running. See 'bastille stop'."
fi
fi
jail_export
fi
+2 -2
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> # Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@@ -47,7 +47,7 @@ if [ $# -ne 0 ]; then
fi fi
for _jail in ${JAILS}; do 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 if [ ! -x "${bastille_jail_path}/usr/local/bin/htop" ]; then
error_notify "htop not found on ${_jail}." error_notify "htop not found on ${_jail}."
elif [ -x "${bastille_jail_path}/usr/local/bin/htop" ]; then elif [ -x "${bastille_jail_path}/usr/local/bin/htop" ]; then
+219 -84
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> # Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@@ -32,7 +32,20 @@
. /usr/local/etc/bastille/bastille.conf . /usr/local/etc/bastille/bastille.conf
usage() { usage() {
error_exit "Usage: bastille import file [option]" # Build an independent usage for the import command
# If no file/extension specified, will import from standard input
error_notify "Usage: bastille import [option(s)] FILE"
cat << EOF
Options:
-f | --force -- Force an archive import regardless if the checksum file does not match or missing.
-v | --verbose -- Be more verbose during the ZFS receive operation.
Tip: If no option specified, container should be imported from standard input.
EOF
exit 1
} }
# Handle special-case commands first # Handle special-case commands first
@@ -42,39 +55,70 @@ help|-h|--help)
;; ;;
esac esac
if [ $# -gt 2 ] || [ $# -lt 1 ]; then if [ $# -gt 3 ] || [ $# -lt 1 ]; then
usage usage
fi fi
TARGET="${1}" TARGET="${1}"
OPTION="${2}" OPT_FORCE=
shift USER_IMPORT=
OPT_ZRECV="-u"
# Handle and parse option args
while [ $# -gt 0 ]; do
case "${1}" in
-f|--force)
OPT_FORCE="1"
TARGET="${2}"
shift
;;
-v|--verbose)
OPT_ZRECV="-u -v"
TARGET="${2}"
shift
;;
-*|--*)
error_notify "Unknown Option."
usage
;;
*)
if [ $# -gt 1 ] || [ $# -lt 1 ]; then
usage
fi
shift
;;
esac
done
# Fallback to default if missing config parameters
if [ -z "${bastille_decompress_xz_options}" ]; then
bastille_decompress_xz_options="-c -d -v"
fi
if [ -z "${bastille_decompress_gz_options}" ]; then
bastille_decompress_gz_options="-k -d -c -v"
fi
validate_archive() { validate_archive() {
# Compare checksums on the target archive # Compare checksums on the target archive
# Skip validation for unsupported archives # Skip validation for unsupported archive
if [ "${FILE_EXT}" != ".tar.gz" ] && [ "${FILE_EXT}" != ".tar" ]; then if [ -f "${bastille_backupsdir}/${TARGET}" ]; then
if [ -f "${bastille_backupsdir}/${TARGET}" ]; then if [ -f "${bastille_backupsdir}/${FILE_TRIM}.sha256" ]; then
if [ -f "${bastille_backupsdir}/${FILE_TRIM}.sha256" ]; then info "Validating file: ${TARGET}..."
info "Validating file: ${TARGET}..." SHA256_DIST=$(cat "${bastille_backupsdir}/${FILE_TRIM}.sha256")
SHA256_DIST=$(cat "${bastille_backupsdir}/${FILE_TRIM}.sha256") SHA256_FILE=$(sha256 -q "${bastille_backupsdir}/${TARGET}")
SHA256_FILE=$(sha256 -q "${bastille_backupsdir}/${TARGET}") if [ "${SHA256_FILE}" != "${SHA256_DIST}" ]; then
if [ "${SHA256_FILE}" != "${SHA256_DIST}" ]; then error_exit "Failed validation for ${TARGET}."
error_exit "Failed validation for ${TARGET}."
else
info "File validation successful!"
fi
else else
# Check if user opt to force import info "File validation successful!"
if [ "${OPTION}" = "-f" -o "${OPTION}" = "force" ]; then fi
warn "Warning: Skipping archive validation!" else
else # Check if user opt to force import
error_exit "Checksum file not found. See 'bastille import TARGET -f'." if [ -n "${OPT_FORCE}" ]; then
fi warn "Warning: Skipping archive validation!"
else
error_exit "Checksum file not found. See 'bastille import [option(s)] FILE'."
fi fi
fi fi
else
warn "Warning: Skipping archive validation!"
fi fi
} }
@@ -129,6 +173,7 @@ generate_config() {
# Attempt to read previous config file and set required variables accordingly # 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 # If we can't get a valid interface, fallback to lo1 and warn user
info "Generating jail.conf..." info "Generating jail.conf..."
DEVFS_RULESET=4
if [ "${FILE_EXT}" = ".zip" ]; then if [ "${FILE_EXT}" = ".zip" ]; then
# Gather some bits from foreign/iocage config files # Gather some bits from foreign/iocage config files
@@ -136,63 +181,88 @@ generate_config() {
if [ -n "${JSON_CONFIG}" ]; then if [ -n "${JSON_CONFIG}" ]; then
IPV4_CONFIG=$(grep -wo '\"ip4_addr\": \".*\"' "${JSON_CONFIG}" | tr -d '" ' | sed 's/ip4_addr://') 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://') 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 fi
elif [ "${FILE_EXT}" = ".tar.gz" ]; then elif [ "${FILE_EXT}" = ".tar.gz" ]; then
# Gather some bits from foreign/ezjail config files # Gather some bits from foreign/ezjail config files
PROP_CONFIG="${bastille_jailsdir}/${TARGET_TRIM}/prop.ezjail-${FILE_TRIM}-*" PROP_CONFIG="${bastille_jailsdir}/${TARGET_TRIM}/prop.ezjail-${FILE_TRIM}-*"
if [ -n "${PROP_CONFIG}" ]; then if [ -n "${PROP_CONFIG}" ]; then
IPVX_CONFIG=$(grep -wo "jail_${TARGET_TRIM}_ip=.*" ${PROP_CONFIG} | tr -d '" ' | sed "s/jail_${TARGET_TRIM}_ip=//") 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 fi
# Always assume it's thin for ezjail
IS_THIN_JAIL=1
fi fi
# If there are multiple IP/NIC let the user configure network # See if we need to generate a vnet network section
if [ -n "${IPV4_CONFIG}" ]; then if [ "${IS_VNET_JAIL:-0}" = "1" ]; then
if ! echo "${IPV4_CONFIG}" | grep -q '.*,.*'; then NETBLOCK=$(generate_vnet_jail_netblock "${TARGET_TRIM}" "" "${VNET_DEFAULT_INTERFACE}")
NETIF_CONFIG=$(echo "${IPV4_CONFIG}" | grep '.*|' | sed 's/|.*//g') else
if [ -z "${NETIF_CONFIG}" ]; then # If there are multiple IP/NIC let the user configure network
config_netif 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 fi
IPX_ADDR="ip4.addr" elif [ -n "${IPV6_CONFIG}" ]; then
IP_CONFIG="${IPV4_CONFIG}" if ! echo "${IPV6_CONFIG}" | grep -q '.*,.*'; then
IP6_MODE="disable" NETIF_CONFIG=$(echo "${IPV6_CONFIG}" | grep '.*|' | sed 's/|.*//g')
fi if [ -z "${NETIF_CONFIG}" ]; then
elif [ -n "${IPV6_CONFIG}" ]; then config_netif
if ! echo "${IPV6_CONFIG}" | grep -q '.*,.*'; then fi
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" IPX_ADDR="ip6.addr"
IP_CONFIG="${IPV6_CONFIG}"
IP6_MODE="new" IP6_MODE="new"
fi 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 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 fi
# Let the user configure network manually if [ "${IS_THIN_JAIL:-0}" = "1" ]; then
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 [ -z "${CONFIG_RELEASE}" ]; then if [ -z "${CONFIG_RELEASE}" ]; then
# Fallback to host version # Fallback to host version
CONFIG_RELEASE=$(freebsd-version | sed 's/\-[pP].*//') CONFIG_RELEASE=$(freebsd-version | sed 's/\-[pP].*//')
@@ -213,7 +283,7 @@ generate_config() {
# Generate a basic jail configuration file on foreign imports # Generate a basic jail configuration file on foreign imports
cat << EOF > "${bastille_jailsdir}/${TARGET_TRIM}/jail.conf" cat << EOF > "${bastille_jailsdir}/${TARGET_TRIM}/jail.conf"
${TARGET_TRIM} { ${TARGET_TRIM} {
devfs_ruleset = 4; devfs_ruleset = ${DEVFS_RULESET};
enforce_statfs = 2; enforce_statfs = 2;
exec.clean; exec.clean;
exec.consolelog = ${bastille_logsdir}/${TARGET_TRIM}_console.log; exec.consolelog = ${bastille_logsdir}/${TARGET_TRIM}_console.log;
@@ -225,9 +295,7 @@ ${TARGET_TRIM} {
path = ${bastille_jailsdir}/${TARGET_TRIM}/root; path = ${bastille_jailsdir}/${TARGET_TRIM}/root;
securelevel = 2; securelevel = 2;
interface = ${NETIF_CONFIG}; ${NETBLOCK}
${IPX_ADDR} = ${IP_CONFIG};
ip6 = ${IP6_MODE};
} }
EOF EOF
} }
@@ -290,6 +358,13 @@ update_symlinks() {
for _link in ${SYMLINKS}; do for _link in ${SYMLINKS}; do
if [ -L "${_link}" ]; then if [ -L "${_link}" ]; then
ln -sf /.bastille/${_link} ${_link} 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 fi
done done
} }
@@ -313,23 +388,34 @@ remove_zfs_datasets() {
jail_import() { jail_import() {
# Attempt to import container from file # Attempt to import container from file
FILE_TRIM=$(echo "${TARGET}" | sed 's/\.xz//g;s/\.txz//g;s/\.zip//g;s/\.tar\.gz//g;s/\.tar//g') FILE_TRIM=$(echo "${TARGET}" | sed 's/\.xz//g;s/\.gz//g;s/\.tgz//g;s/\.txz//g;s/\.zip//g;s/\.tar\.gz//g;s/\.tar//g')
FILE_EXT=$(echo "${TARGET}" | sed "s/${FILE_TRIM}//g") FILE_EXT=$(echo "${TARGET}" | sed "s/${FILE_TRIM}//g")
validate_archive
if [ -d "${bastille_jailsdir}" ]; then if [ -d "${bastille_jailsdir}" ]; then
if [ "${bastille_zfs_enable}" = "YES" ]; then if [ "${bastille_zfs_enable}" = "YES" ]; then
if [ -n "${bastille_zfs_zpool}" ]; then if [ -n "${bastille_zfs_zpool}" ]; then
if [ "${FILE_EXT}" = ".xz" ]; then if [ "${FILE_EXT}" = ".xz" ]; then
validate_archive
# Import from compressed xz on ZFS systems # Import from compressed xz on ZFS systems
info "Importing '${TARGET_TRIM}' from compressed ${FILE_EXT} archive." info "Importing '${TARGET_TRIM}' from compressed ${FILE_EXT} image."
info "Receiving ZFS data stream..." info "Receiving ZFS data stream..."
xz ${bastille_decompress_xz_options} "${bastille_backupsdir}/${TARGET}" | \ xz ${bastille_decompress_xz_options} "${bastille_backupsdir}/${TARGET}" | \
zfs receive -u "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}" zfs receive ${OPT_ZRECV} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}"
# Update ZFS mountpoint property if required
update_zfsmount
elif [ "${FILE_EXT}" = ".gz" ]; then
validate_archive
# Import from compressed xz on ZFS systems
info "Importing '${TARGET_TRIM}' from compressed ${FILE_EXT} image."
info "Receiving ZFS data stream..."
gzip ${bastille_decompress_gz_options} "${bastille_backupsdir}/${TARGET}" | \
zfs receive ${OPT_ZRECV} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}"
# Update ZFS mountpoint property if required # Update ZFS mountpoint property if required
update_zfsmount update_zfsmount
elif [ "${FILE_EXT}" = ".txz" ]; then elif [ "${FILE_EXT}" = ".txz" ]; then
validate_archive
# Prepare the ZFS environment and restore from existing .txz file # Prepare the ZFS environment and restore from existing .txz file
create_zfs_datasets create_zfs_datasets
@@ -340,7 +426,20 @@ jail_import() {
if [ "$?" -ne 0 ]; then if [ "$?" -ne 0 ]; then
remove_zfs_datasets remove_zfs_datasets
fi fi
elif [ "${FILE_EXT}" = ".tgz" ]; then
validate_archive
# Prepare the ZFS environment and restore from existing .tgz file
create_zfs_datasets
# Extract required files to the new datasets
info "Extracting files from '${TARGET}' archive..."
tar --exclude='root' -xf "${bastille_backupsdir}/${TARGET}" --strip-components 1 -C "${bastille_jailsdir}/${TARGET_TRIM}"
tar -xf "${bastille_backupsdir}/${TARGET}" --strip-components 2 -C "${bastille_jailsdir}/${TARGET_TRIM}/root" "${TARGET_TRIM}/root"
if [ "$?" -ne 0 ]; then
remove_zfs_datasets
fi
elif [ "${FILE_EXT}" = ".zip" ]; then elif [ "${FILE_EXT}" = ".zip" ]; then
validate_archive
# Attempt to import a foreign/iocage container # Attempt to import a foreign/iocage container
info "Importing '${TARGET_TRIM}' from foreign compressed ${FILE_EXT} archive." info "Importing '${TARGET_TRIM}' from foreign compressed ${FILE_EXT} archive."
# Sane bastille ZFS options # Sane bastille ZFS options
@@ -353,9 +452,9 @@ jail_import() {
rm -f "${FILE_TRIM}" "${FILE_TRIM}_root" rm -f "${FILE_TRIM}" "${FILE_TRIM}_root"
fi fi
info "Receiving ZFS data stream..." info "Receiving ZFS data stream..."
zfs receive -u "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}" < "${FILE_TRIM}" zfs receive ${OPT_ZRECV} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}" < "${FILE_TRIM}"
zfs set ${ZFS_OPTIONS} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}" zfs set ${ZFS_OPTIONS} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}"
zfs receive -u "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}/root" < "${FILE_TRIM}_root" zfs receive ${OPT_ZRECV} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}/root" < "${FILE_TRIM}_root"
# Update ZFS mountpoint property if required # Update ZFS mountpoint property if required
update_zfsmount update_zfsmount
@@ -403,6 +502,27 @@ jail_import() {
else else
update_config update_config
fi fi
elif [ -z "${FILE_EXT}" ]; then
if echo "${TARGET}" | grep -q '_[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}-[0-9]\{6\}$'; then
validate_archive
# Based on the file name, looks like we are importing a raw bastille image
# Import from uncompressed image file
info "Importing '${TARGET_TRIM}' from uncompressed image archive."
info "Receiving ZFS data stream..."
zfs receive ${OPT_ZRECV} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}" < "${bastille_backupsdir}/${TARGET}"
# Update ZFS mountpoint property if required
update_zfsmount
else
# Based on the file name, looks like we are importing from previous redirected bastille image
# Quietly import from previous redirected bastille image
if ! zfs receive ${OPT_ZRECV} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}"; then
exit 1
else
# Update ZFS mountpoint property if required
update_zfsmount
fi
fi
else else
error_exit "Unknown archive format." error_exit "Unknown archive format."
fi fi
@@ -412,6 +532,9 @@ jail_import() {
if [ "${FILE_EXT}" = ".txz" ]; then if [ "${FILE_EXT}" = ".txz" ]; then
info "Extracting files from '${TARGET}' archive..." info "Extracting files from '${TARGET}' archive..."
tar -Jxf "${bastille_backupsdir}/${TARGET}" -C "${bastille_jailsdir}" tar -Jxf "${bastille_backupsdir}/${TARGET}" -C "${bastille_jailsdir}"
elif [ "${FILE_EXT}" = ".tgz" ]; then
info "Extracting files from '${TARGET}' archive..."
tar -xf "${bastille_backupsdir}/${TARGET}" -C "${bastille_jailsdir}"
elif [ "${FILE_EXT}" = ".tar.gz" ]; then elif [ "${FILE_EXT}" = ".tar.gz" ]; then
# Attempt to import/configure foreign/ezjail container # Attempt to import/configure foreign/ezjail container
info "Extracting files from '${TARGET}' archive..." info "Extracting files from '${TARGET}' archive..."
@@ -442,7 +565,9 @@ jail_import() {
# This is required on foreign imports only # This is required on foreign imports only
update_jailconf update_jailconf
update_fstab update_fstab
info "Container '${TARGET_TRIM}' imported successfully." if [ -z "${USER_IMPORT}" ]; then
info "Container '${TARGET_TRIM}' imported successfully."
fi
exit 0 exit 0
fi fi
else else
@@ -465,22 +590,32 @@ fi
# Check if archive exist then trim archive name # Check if archive exist then trim archive name
if [ -f "${bastille_backupsdir}/${TARGET}" ]; then if [ -f "${bastille_backupsdir}/${TARGET}" ]; then
# Filter unsupported/unknown archives # Filter unsupported/unknown archives
if echo "${TARGET}" | grep -q '_[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}-[0-9]\{6\}.xz$\|_[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}-[0-9]\{6\}.txz$\|_[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}.zip$\|-[0-9]\{12\}.[0-9]\{2\}.tar.gz$\|@[0-9]\{12\}.[0-9]\{2\}.tar$'; then if echo "${TARGET}" | grep -q '_[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}-[0-9]\{6\}$\|_[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}-[0-9]\{6\}.xz$\|_[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}-[0-9]\{6\}$\|_[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}-[0-9]\{6\}.gz$\|_[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}-[0-9]\{6\}$\|_[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}-[0-9]\{6\}.tgz$\|_[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}-[0-9]\{6\}.txz$\|_[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}.zip$\|-[0-9]\{12\}.[0-9]\{2\}.tar.gz$\|@[0-9]\{12\}.[0-9]\{2\}.tar$'; then
if ls "${bastille_backupsdir}" | awk "/^${TARGET}$/" >/dev/null; then if ls "${bastille_backupsdir}" | awk "/^${TARGET}$/" >/dev/null; then
TARGET_TRIM=$(echo "${TARGET}" | sed "s/_[0-9]*-[0-9]*-[0-9]*-[0-9]*.xz//;s/_[0-9]*-[0-9]*-[0-9]*-[0-9]*.txz//;s/_[0-9]*-[0-9]*-[0-9]*.zip//;s/-[0-9]\{12\}.[0-9]\{2\}.tar.gz//;s/@[0-9]\{12\}.[0-9]\{2\}.tar//") TARGET_TRIM=$(echo "${TARGET}" | sed "s/_[0-9]*-[0-9]*-[0-9]*-[0-9]*.xz//;s/_[0-9]*-[0-9]*-[0-9]*-[0-9]*.gz//;s/_[0-9]*-[0-9]*-[0-9]*-[0-9]*.tgz//;s/_[0-9]*-[0-9]*-[0-9]*-[0-9]*.txz//;s/_[0-9]*-[0-9]*-[0-9]*.zip//;s/-[0-9]\{12\}.[0-9]\{2\}.tar.gz//;s/@[0-9]\{12\}.[0-9]\{2\}.tar//;s/_[0-9]*-[0-9]*-[0-9]*-[0-9]*//")
fi fi
else else
error_exit "Unrecognized archive name." error_exit "Unrecognized archive name."
fi fi
else else
error_exit "Archive '${TARGET}' not found." if echo "${TARGET}" | grep -q '_[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}-[0-9]\{6\}.*$'; then
error_exit "Archive '${TARGET}' not found."
else
# Assume user will import from standard input
TARGET_TRIM=${TARGET}
USER_IMPORT="1"
fi
fi fi
# Check if a running jail matches name or already exist # 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." error_exit "A running jail matches name."
elif [ -d "${bastille_jailsdir}/${TARGET_TRIM}" ]; then elif [ -n "${TARGET_TRIM}" ]; then
error_exit "Container: ${TARGET_TRIM} already exists." if [ -d "${bastille_jailsdir}/${TARGET_TRIM}" ]; then
error_exit "Container: ${TARGET_TRIM} already exists."
fi
fi fi
jail_import if [ -n "${TARGET}" ]; then
jail_import
fi
+1 -1
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> # Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved. # All rights reserved.
# Ressource limits added by Sven R github.com/hackacad # Ressource limits added by Sven R github.com/hackacad
# #
+112 -7
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> # Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@@ -32,15 +32,15 @@
. /usr/local/etc/bastille/bastille.conf . /usr/local/etc/bastille/bastille.conf
usage() { usage() {
error_exit "Usage: bastille list [-j] [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 if [ $# -eq 0 ]; then
jls -N /usr/sbin/jls -N
fi fi
if [ "$1" == "-j" ]; then if [ "$1" == "-j" ]; then
jls -N --libxo json /usr/sbin/jls -N --libxo json
exit 0 exit 0
fi fi
@@ -50,12 +50,117 @@ if [ $# -gt 0 ]; then
help|-h|--help) help|-h|--help)
usage usage
;; ;;
all|-a|--all)
if [ -d "${bastille_jailsdir}" ]; then
DEFAULT_VALUE="-"
SPACER=2
MAX_LENGTH_JAIL_NAME=$(find ""${bastille_jailsdir}/*/jail.conf"" -maxdepth 1 -type f -print0 2> /dev/null | xargs -r0 -P0 grep -h -m 1 -e "^.* {$" | awk '{ print length($1) }' | sort -nr | head -n 1)
MAX_LENGTH_JAIL_NAME=${MAX_LENGTH_JAIL_NAME:-3}
if [ ${MAX_LENGTH_JAIL_NAME} -lt 3 ]; then MAX_LENGTH_JAIL_NAME=3; fi
MAX_LENGTH_JAIL_IP=$(find ""${bastille_jailsdir}/*/jail.conf"" -maxdepth 1 -type f -print0 2> /dev/null | xargs -r0 -P0 sed -n "s/^[ ]*ip[4,6].addr[ ]*=[ ]*\(.*\);$/\1 /p" | sed 's/\// /g' | awk '{ print length($1) }' | sort -nr | head -n 1)
MAX_LENGTH_JAIL_IP=${MAX_LENGTH_JAIL_IP:-10}
MAX_LENGTH_JAIL_VNET_IP=$(find ""${bastille_jailsdir}/*/jail.conf"" -maxdepth 1 -type f -print0 2> /dev/null | xargs -r0 -P0 grep -l "vnet;" | grep -h "ifconfig_vnet0=" $(sed -n "s/\(.*\)jail.conf$/\1root\/etc\/rc.conf/p") | sed -n "s/^ifconfig_vnet0=\"\(.*\)\"$/\1/p"| sed "s/\// /g" | awk '{ if ($1 ~ /^[inet|inet6]/) print length($2); else print 15 }' | sort -nr | head -n 1)
MAX_LENGTH_JAIL_VNET_IP=${MAX_LENGTH_JAIL_VNET_IP:-10}
if [ ${MAX_LENGTH_JAIL_VNET_IP} -gt ${MAX_LENGTH_JAIL_IP} ]; then MAX_LENGTH_JAIL_IP=${MAX_LENGTH_JAIL_VNET_IP}; fi
if [ ${MAX_LENGTH_JAIL_IP} -lt 10 ]; then MAX_LENGTH_JAIL_IP=10; fi
MAX_LENGTH_JAIL_HOSTNAME=$(find ""${bastille_jailsdir}/*/jail.conf"" -maxdepth 1 -type f -print0 2> /dev/null | xargs -r0 -P0 grep -h -m 1 -e "^[ ]*host.hostname[ ]*=[ ]*\(.*\);" | awk '{ print length(substr($3, 1, length($3)-1)) }' | sort -nr | head -n 1)
MAX_LENGTH_JAIL_HOSTNAME=${MAX_LENGTH_JAIL_HOSTNAME:-8}
if [ ${MAX_LENGTH_JAIL_HOSTNAME} -lt 8 ]; then MAX_LENGTH_JAIL_HOSTNAME=8; fi
MAX_LENGTH_JAIL_PORTS=$(find ""${bastille_jailsdir}/*/rdr.conf"" -maxdepth 1 -type f -print0 2> /dev/null | xargs -r0 -P0 -n1 awk '{ lines++; chars += length($0)} END { chars += lines - 1; print chars }' | sort -nr | head -n 1)
MAX_LENGTH_JAIL_PORTS=${MAX_LENGTH_JAIL_PORTS:-15}
if [ ${MAX_LENGTH_JAIL_PORTS} -lt 15 ]; then MAX_LENGTH_JAIL_PORTS=15; fi
if [ ${MAX_LENGTH_JAIL_PORTS} -gt 30 ]; then MAX_LENGTH_JAIL_PORTS=30; fi
MAX_LENGTH_JAIL_RELEASE=$(find ""${bastille_jailsdir}/*/fstab"" -maxdepth 1 -type f -print0 2> /dev/null | xargs -r0 -P0 grep -h "/releases/.*/root/.bastille.*nullfs" | grep -hE "^USERLAND_VERSION=" $(sed -n "s/^\(.*\) \/.*$/\1\/bin\/freebsd-version/p" | awk '!_[$0]++') | sed "s/[\"\'\^]//g;s/ .*$//g" | sed -n "s/^USERLAND_VERSION=\(.*\)$/\1/p" | awk '{ print length($0) }' | sort -nr | head -n 1)
MAX_LENGTH_JAIL_RELEASE=${MAX_LENGTH_JAIL_RELEASE:-7}
MAX_LENGTH_THICK_JAIL_RELEASE=$(find ""${bastille_jailsdir}/*/root/bin/freebsd-version"" -maxdepth 1 -type f -print0 2> /dev/null | xargs -r0 -P0 grep -hE "^USERLAND_VERSION=" | sed "s/[\"\'\^]//g;s/ .*$//g" | sed -n "s/^USERLAND_VERSION=\(.*\)$/\1/p" | awk '{ print length($0) }' | sort -nr | head -n 1)
MAX_LENGTH_THICK_JAIL_RELEASE=${MAX_LENGTH_THICK_JAIL_RELEASE:-7}
MAX_LENGTH_LINUX_JAIL_RELEASE=$(find ""${bastille_jailsdir}/*/fstab"" -maxdepth 1 -type f -print0 2> /dev/null | xargs -r0 -P0 grep -h "/jails/.*/root/proc.*linprocfs" | grep -hE "^NAME=|^VERSION_ID=|^VERSION_CODENAME=" $(sed -n "s/^linprocfs *\(.*\)\/.*$/\1\/etc\/os-release/p") 2> /dev/null | sed "s/\"//g" | sed "s/ GNU\/Linux//g" | sed "N;N;s/\n/;/g" | sed -n "s/^NAME=\(.*\);VERSION_ID=\(.*\);VERSION_CODENAME=\(.*\)$/\1 \2 (\3)/p" | awk '{ print length($0) }' | sort -nr | head -n 1)
MAX_LENGTH_LINUX_JAIL_RELEASE=${MAX_LENGTH_LINUX_JAIL_RELEASE:-7}
if [ ${MAX_LENGTH_THICK_JAIL_RELEASE} -gt ${MAX_LENGTH_JAIL_RELEASE} ]; then MAX_LENGTH_JAIL_RELEASE=${MAX_LENGTH_THICK_JAIL_RELEASE}; fi
if [ ${MAX_LENGTH_LINUX_JAIL_RELEASE} -gt ${MAX_LENGTH_JAIL_RELEASE} ]; then MAX_LENGTH_JAIL_RELEASE=${MAX_LENGTH_LINUX_JAIL_RELEASE}; fi
if [ ${MAX_LENGTH_JAIL_RELEASE} -lt 7 ]; then MAX_LENGTH_JAIL_RELEASE=7; fi
printf " JID%*sState%*sIP Address%*sPublished Ports%*sHostname%*sRelease%*sPath\n" "$((${MAX_LENGTH_JAIL_NAME} + ${SPACER} - 3))" "" "$((${SPACER}))" "" "$((${MAX_LENGTH_JAIL_IP} + ${SPACER} - 10))" "" "$((${MAX_LENGTH_JAIL_PORTS} + ${SPACER} - 15))" "" "$((${MAX_LENGTH_JAIL_HOSTNAME} + ${SPACER} - 8))" "" "$((${MAX_LENGTH_JAIL_RELEASE} + ${SPACER} - 7))" ""
JAIL_LIST=$(ls "${bastille_jailsdir}" | sed "s/\n//g")
for _JAIL in ${JAIL_LIST}; do
if [ -f "${bastille_jailsdir}/${_JAIL}/jail.conf" ]; then
JAIL_NAME=$(grep -h -m 1 -e "^.* {$" "${bastille_jailsdir}/${_JAIL}/jail.conf" 2> /dev/null | awk '{ print $1 }')
IS_FREEBSD_JAIL=0
if [ -f "${bastille_jailsdir}/${JAIL_NAME}/root/bin/freebsd-version" -o -f "${bastille_jailsdir}/${JAIL_NAME}/root/.bastille/bin/freebsd-version" -o "$(grep -c "/releases/.*/root/.bastille.*nullfs" "${bastille_jailsdir}/${JAIL_NAME}/fstab" 2> /dev/null)" -gt 0 ]; then IS_FREEBSD_JAIL=1; fi
IS_FREEBSD_JAIL=${IS_FREEBSD_JAIL:-0}
IS_LINUX_JAIL=0
if [ "$(grep -c "^linprocfs" "${bastille_jailsdir}/${JAIL_NAME}/fstab" 2> /dev/null)" -gt 0 ]; then IS_LINUX_JAIL=1; fi
IS_LINUX_JAIL=${IS_LINUX_JAIL:-0}
if [ "$(/usr/sbin/jls name | awk "/^${JAIL_NAME}$/")" ]; then
JAIL_STATE="Up"
if [ "$(awk '$1 == "vnet;" { print $1 }' "${bastille_jailsdir}/${JAIL_NAME}/jail.conf" 2> /dev/null)" ]; then
JAIL_IP=$(jexec -l ${JAIL_NAME} ifconfig -n vnet0 inet 2> /dev/null | sed -n "/.inet /{s///;s/ .*//;p;}")
if [ ! ${JAIL_IP} ]; then JAIL_IP=$(jexec -l ${JAIL_NAME} ifconfig -n vnet0 inet6 2> /dev/null | awk '/inet6 / && (!/fe80::/ || !/%vnet0/)' | sed -n "/.inet6 /{s///;s/ .*//;p;}"); fi
else
JAIL_IP=$(/usr/sbin/jls -j ${JAIL_NAME} ip4.addr 2> /dev/null)
if [ ${JAIL_IP} = "-" ]; then JAIL_IP=$(/usr/sbin/jls -j ${JAIL_NAME} ip6.addr 2> /dev/null); fi
fi
JAIL_HOSTNAME=$(/usr/sbin/jls -j ${JAIL_NAME} host.hostname 2> /dev/null)
JAIL_PORTS=$(pfctl -a "rdr/${JAIL_NAME}" -Psn 2> /dev/null | awk '{ printf "%s/%s:%s"",",$7,$14,$18 }' | sed "s/,$//")
JAIL_PATH=$(/usr/sbin/jls -j ${JAIL_NAME} path 2> /dev/null)
if [ ${IS_FREEBSD_JAIL} -eq 1 ]; then
JAIL_RELEASE=$(jexec -l ${JAIL_NAME} freebsd-version -u 2> /dev/null)
fi
if [ ${IS_LINUX_JAIL} -eq 1 ]; then
JAIL_RELEASE=$(grep -hE "^NAME=.*$|^VERSION_ID=.*$|^VERSION_CODENAME=.*$" "${JAIL_PATH}/etc/os-release" 2> /dev/null | sed "s/\"//g" | sed "s/ GNU\/Linux//g" | awk -F'=' '{ a[$1] = $2; o++ } o%3 == 0 { print a["VERSION_CODENAME"] " (" a["NAME"] " " a["VERSION_ID"] ")" }')
fi
else
JAIL_STATE=$(if [ "$(sed -n "/^${JAIL_NAME} {$/,/^}$/p" "${bastille_jailsdir}/${JAIL_NAME}/jail.conf" 2> /dev/null | awk '$0 ~ /^'${JAIL_NAME}' \{|\}/ { printf "%s",$0 }')" == "${JAIL_NAME} {}" ]; then echo "Down"; else echo "n/a"; fi)
if [ "$(awk '$1 == "vnet;" { print $1 }' "${bastille_jailsdir}/${JAIL_NAME}/jail.conf" 2> /dev/null)" ]; then
JAIL_IP=$(sed -n 's/^ifconfig_vnet0="\(.*\)"$/\1/p' "${bastille_jailsdir}/${JAIL_NAME}/root/etc/rc.conf" 2> /dev/null | sed "s/\// /g" | awk '{ if ($1 ~ /^[inet|inet6]/) print $2; else print $1 }')
else
JAIL_IP=$(sed -n "s/^[ ]*ip[4,6].addr[ ]*=[ ]*\(.*\);$/\1/p" "${bastille_jailsdir}/${JAIL_NAME}/jail.conf" 2> /dev/null | sed "s/\// /g" | awk '{ print $1 }')
fi
JAIL_HOSTNAME=$(sed -n "s/^[ ]*host.hostname[ ]*=[ ]*\(.*\);$/\1/p" "${bastille_jailsdir}/${JAIL_NAME}/jail.conf" 2> /dev/null)
if [ -f "${bastille_jailsdir}/${JAIL_NAME}/rdr.conf" ]; then JAIL_PORTS=$(awk '$1 ~ /^[tcp|udp]/ { printf "%s/%s:%s,",$1,$2,$3 }' "${bastille_jailsdir}/${JAIL_NAME}/rdr.conf" 2> /dev/null | sed "s/,$//"); else JAIL_PORTS=""; fi
JAIL_PATH=$(sed -n "s/^[ ]*path[ ]*=[ ]*\(.*\);$/\1/p" "${bastille_jailsdir}/${JAIL_NAME}/jail.conf" 2> /dev/null)
if [ ${JAIL_PATH} ]; then
if [ ${IS_FREEBSD_JAIL} -eq 1 ]; then
if [ -f "${JAIL_PATH}/bin/freebsd-version" ]; then
JAIL_RELEASE=$(grep -hE "^USERLAND_VERSION=" "${JAIL_PATH}/bin/freebsd-version" 2> /dev/null | sed "s/[\"\'\^]//g;s/ .*$//g" | sed -n "s/^USERLAND_VERSION=\(.*\)$/\1/p")
else
JAIL_RELEASE=$(grep -h "/releases/.*/root/.bastille.*nullfs" "${bastille_jailsdir}/${JAIL_NAME}/fstab" 2> /dev/null | grep -hE "^USERLAND_VERSION=" $(sed -n "s/^\(.*\) \/.*$/\1\/bin\/freebsd-version/p" | awk '!_[$0]++') | sed "s/[\"\'\^]//g;s/ .*$//g" | sed -n "s/^USERLAND_VERSION=\(.*\)$/\1/p")
fi
fi
if [ ${IS_LINUX_JAIL} -eq 1 ]; then
JAIL_RELEASE=$(grep -hE "^NAME=.*$|^VERSION_ID=.*$|^VERSION_CODENAME=.*$" "${JAIL_PATH}/etc/os-release" 2> /dev/null | sed "s/\"//g" | sed "s/ GNU\/Linux//g" | awk -F'=' '{ a[$1] = $2; o++ } o%3 == 0 { print a["VERSION_CODENAME"] " (" a["NAME"] " " a["VERSION_ID"] ")" }')
fi
else
JAIL_RELEASE=""
fi
fi
if [ ${#JAIL_PORTS} -gt ${MAX_LENGTH_JAIL_PORTS} ]; then JAIL_PORTS="$(echo ${JAIL_PORTS} | cut -c-$((${MAX_LENGTH_JAIL_PORTS} - 3)))..."; fi
JAIL_NAME=${JAIL_NAME:-${DEFAULT_VALUE}}
JAIL_STATE=${JAIL_STATE:-${DEFAULT_VALUE}}
JAIL_IP=${JAIL_IP:-${DEFAULT_VALUE}}
JAIL_PORTS=${JAIL_PORTS:-${DEFAULT_VALUE}}
JAIL_HOSTNAME=${JAIL_HOSTNAME:-${DEFAULT_VALUE}}
JAIL_RELEASE=${JAIL_RELEASE:-${DEFAULT_VALUE}}
JAIL_PATH=${JAIL_PATH:-${DEFAULT_VALUE}}
printf " ${JAIL_NAME}%*s${JAIL_STATE}%*s${JAIL_IP}%*s${JAIL_PORTS}%*s${JAIL_HOSTNAME}%*s${JAIL_RELEASE}%*s${JAIL_PATH}\n" "$((${MAX_LENGTH_JAIL_NAME} - ${#JAIL_NAME} + ${SPACER}))" "" "$((5 - ${#JAIL_STATE} + ${SPACER}))" "" "$((${MAX_LENGTH_JAIL_IP} - ${#JAIL_IP} + ${SPACER}))" "" "$((${MAX_LENGTH_JAIL_PORTS} - ${#JAIL_PORTS} + ${SPACER}))" "" "$((${MAX_LENGTH_JAIL_HOSTNAME} - ${#JAIL_HOSTNAME} + ${SPACER}))" "" "$((${MAX_LENGTH_JAIL_RELEASE} - ${#JAIL_RELEASE} + ${SPACER}))" ""
fi
done
else
error_exit "unfortunately there are no jails here (${bastille_jailsdir})"
fi
;;
release|releases) release|releases)
if [ -d "${bastille_releasesdir}" ]; then if [ -d "${bastille_releasesdir}" ]; then
REL_LIST=$(ls "${bastille_releasesdir}" | sed "s/\n//g") REL_LIST=$(ls "${bastille_releasesdir}" | sed "s/\n//g")
for _REL in ${REL_LIST}; do for _REL in ${REL_LIST}; do
if [ -f "${bastille_releasesdir}/${_REL}/root/.profile" ]; then if [ -f "${bastille_releasesdir}/${_REL}/root/.profile" -o -d "${bastille_releasesdir}/${_REL}/debootstrap" ]; then
echo "${_REL}" if [ "$2" == "-p" -a -f "${bastille_releasesdir}/${_REL}/bin/freebsd-version" ]; then
REL_PATCH_LEVEL=$(sed -n "s/^USERLAND_VERSION=\"\(.*\)\"$/\1/p" "${bastille_releasesdir}/${_REL}/bin/freebsd-version" 2> /dev/null)
REL_PATCH_LEVEL=${REL_PATCH_LEVEL:-${_REL}}
echo "${REL_PATCH_LEVEL}"
else
echo "${_REL}"
fi
fi fi
done done
fi fi
@@ -80,7 +185,7 @@ if [ $# -gt 0 ]; then
rctl -h jail: rctl -h jail:
;; ;;
import|imports|export|exports|backup|backups) import|imports|export|exports|backup|backups)
ls "${bastille_backupsdir}" | grep -Ev "*.sha256" ls "${bastille_backupsdir}" | grep -v ".sha256$"
exit 0 exit 0
;; ;;
*) *)
+8 -7
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> # Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@@ -93,24 +93,25 @@ for _jail in ${JAILS}; do
info "[${_jail}]:" info "[${_jail}]:"
## aggregate variables into FSTAB entry ## aggregate variables into FSTAB entry
_jailpath="${bastille_jailsdir}/${_jail}/root/${_jailpath}" _fullpath="${bastille_jailsdir}/${_jail}/root/${_jailpath}"
_fstab_entry="${_hostpath} ${_jailpath} ${_type} ${_perms} ${_checks}" _fstab_entry="${_hostpath} ${_fullpath} ${_type} ${_perms} ${_checks}"
## Create mount point if it does not exist. -- cwells ## Create mount point if it does not exist. -- cwells
if [ ! -d "${bastille_jailsdir}/${_jail}/root/${_jailpath}" ]; then if [ ! -d "${_fullpath}" ]; then
if ! mkdir -p "${bastille_jailsdir}/${_jail}/root/${_jailpath}"; then if ! mkdir -p "${_fullpath}"; then
error_exit "Failed to create mount point inside jail." error_exit "Failed to create mount point inside jail."
fi fi
fi fi
## if entry doesn't exist, add; else show existing entry ## 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 if ! echo "${_fstab_entry}" >> "${bastille_jailsdir}/${_jail}/fstab"; then
error_exit "Failed to create fstab entry: ${_fstab_entry}" error_exit "Failed to create fstab entry: ${_fstab_entry}"
fi fi
echo "Added: ${_fstab_entry}" echo "Added: ${_fstab_entry}"
else else
egrep "[[:blank:]]${_jailpath}[[:blank:]]" "${bastille_jailsdir}/${_jail}/fstab" warn "Mountpoint already present in ${bastille_jailsdir}/${_jail}/fstab"
egrep "[[:blank:]]${_fullpath}[[:blank:]]" "${bastille_jailsdir}/${_jail}/fstab"
fi fi
mount -F "${bastille_jailsdir}/${_jail}/fstab" -a mount -F "${bastille_jailsdir}/${_jail}/fstab" -a
echo echo
+12 -3
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> # Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@@ -31,7 +31,7 @@
. /usr/local/share/bastille/common.sh . /usr/local/share/bastille/common.sh
usage() { usage() {
error_exit "Usage: bastille pkg TARGET command [args]" error_exit "Usage: bastille pkg [-H|--host] TARGET command [args]"
} }
# Handle special-case commands first. # Handle special-case commands first.
@@ -47,6 +47,15 @@ fi
for _jail in ${JAILS}; do for _jail in ${JAILS}; do
info "[${_jail}]:" info "[${_jail}]:"
jexec -l "${_jail}" /usr/sbin/pkg "$@" bastille_jail_path=$(/usr/sbin/jls -j "${_jail}" path)
if [ -f "/usr/sbin/mport" ]; then
jexec -l -U root "${_jail}" /usr/sbin/mport "$@"
elif [ -f "${bastille_jail_path}/usr/bin/apt" ]; then
jexec -l "${_jail}" /usr/bin/apt "$@"
elif [ "${USE_HOST_PKG}" = 1 ]; then
/usr/sbin/pkg -j "${_jail}" "$@"
else
jexec -l -U root "${_jail}" /usr/sbin/pkg "$@"
fi
echo echo
done done
+51 -29
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> # Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@@ -47,37 +47,42 @@ if [ $# -lt 2 ]; then
fi fi
TARGET="${1}" TARGET="${1}"
JAIL_NAME=""
JAIL_IP=""
EXT_IF=""
shift shift
# Can only redirect to single jail check_jail_validity() {
if [ "${TARGET}" = 'ALL' ]; then # Can only redirect to single jail
error_exit "Can only redirect to a single jail." if [ "${TARGET}" = 'ALL' ]; then
fi error_exit "Can only redirect to a single jail."
# 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}"
fi fi
fi
# Check if rdr-anchor is defined in pf.conf # Check if jail name is valid
if ! (pfctl -sn | grep rdr-anchor | grep 'rdr/\*' >/dev/null); then JAIL_NAME=$(/usr/sbin/jls -j "${TARGET}" name 2>/dev/null)
error_exit "rdr-anchor not found in pf.conf" if [ -z "${JAIL_NAME}" ]; then
fi error_exit "Jail not found: ${TARGET}"
fi
# Check if ext_if is defined in pf.conf # Check if jail ip4 address (ip4.addr) is valid (non-VNET only)
EXT_IF=$(grep '^[[:space:]]*ext_if[[:space:]]*=' /etc/pf.conf) if [ "$(bastille config $TARGET get vnet)" != 'enabled' ]; then
if [ -z "${EXT_IF}" ]; then JAIL_IP=$(/usr/sbin/jls -j "${TARGET}" ip4.addr 2>/dev/null)
error_exit "ext_if not defined in pf.conf" if [ -z "${JAIL_IP}" -o "${JAIL_IP}" = "-" ]; then
fi error_exit "Jail IP not found: ${TARGET}"
fi
fi
# Check if rdr-anchor is defined in pf.conf
if ! (pfctl -sn | grep rdr-anchor | grep 'rdr/\*' >/dev/null); then
error_exit "rdr-anchor not found in pf.conf"
fi
# Check if ext_if is defined in pf.conf
EXT_IF=$(grep '^[[:space:]]*ext_if[[:space:]]*=' /etc/pf.conf)
if [ -z "${EXT_IF}" ]; then
error_exit "ext_if not defined in pf.conf"
fi
}
# function: write rule to rdr.conf # function: write rule to rdr.conf
persist_rdr_rule() { persist_rdr_rule() {
@@ -96,17 +101,34 @@ load_rdr_rule() {
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case "$1" in case "$1" in
list) 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 shift
;; ;;
clear) 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 shift
;; ;;
tcp|udp) tcp|udp)
if [ $# -lt 3 ]; then if [ $# -lt 3 ]; then
usage usage
fi fi
check_jail_validity
persist_rdr_rule $1 $2 $3 persist_rdr_rule $1 $2 $3
load_rdr_rule $1 $2 $3 load_rdr_rule $1 $2 $3
shift 3 shift 3
+17 -8
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> # Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@@ -76,13 +76,22 @@ update_fstab() {
# Update fstab to use the new name # Update fstab to use the new name
FSTAB_CONFIG="${bastille_jailsdir}/${NEWNAME}/fstab" FSTAB_CONFIG="${bastille_jailsdir}/${NEWNAME}/fstab"
if [ -f "${FSTAB_CONFIG}" ]; then 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}") # Skip if fstab is empty, e.g newly created thick or clone jails
FSTAB_CURRENT=$(grep -w ".*/releases/.*/jails/${TARGET}/root/.bastille" "${FSTAB_CONFIG}") if [ -s "${FSTAB_CONFIG}" ]; then
FSTAB_NEWCONF="${bastille_releasesdir}/${FSTAB_RELEASE} ${bastille_jailsdir}/${NEWNAME}/root/.bastille nullfs ro 0 0" 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}")
if [ -n "${FSTAB_CURRENT}" ] && [ -n "${FSTAB_NEWCONF}" ]; then FSTAB_CURRENT=$(grep -w ".*/releases/.*/jails/${TARGET}/root/.bastille" "${FSTAB_CONFIG}")
# If both variables are set, update as needed FSTAB_NEWCONF="${bastille_releasesdir}/${FSTAB_RELEASE} ${bastille_jailsdir}/${NEWNAME}/root/.bastille nullfs ro 0 0"
if ! grep -qw "${bastille_releasesdir}/${FSTAB_RELEASE}.*${bastille_jailsdir}/${NEWNAME}/root/.bastille" "${FSTAB_CONFIG}"; then if [ -n "${FSTAB_CURRENT}" ] && [ -n "${FSTAB_NEWCONF}" ]; then
sed -i '' "s|${FSTAB_CURRENT}|${FSTAB_NEWCONF}|" "${FSTAB_CONFIG}" # 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 fi
fi fi
+1 -1
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> # Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
+2 -2
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> # Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@@ -41,7 +41,7 @@ help|-h|--help)
;; ;;
esac esac
if [ $# -ne 2 ]; then if [ $# -lt 1 -o $# -gt 2 ]; then
usage usage
fi fi
+5 -10
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> # Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@@ -62,11 +62,11 @@ fi
for _jail in ${JAILS}; do for _jail in ${JAILS}; do
## test if running ## test if running
if [ "$(jls name | awk "/^${_jail}$/")" ]; then if [ "$(/usr/sbin/jls name | awk "/^${_jail}$/")" ]; then
error_notify "[${_jail}]: Already started." error_notify "[${_jail}]: Already started."
## test if not running ## 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 # Verify that the configured interface exists. -- cwells
if [ "$(bastille config $_jail get vnet)" != 'enabled' ]; then if [ "$(bastille config $_jail get vnet)" != 'enabled' ]; then
_interface=$(bastille config $_jail get interface) _interface=$(bastille config $_jail get interface)
@@ -83,6 +83,8 @@ for _jail in ${JAILS}; do
error_notify "Error: IP address (${ip}) already in use." error_notify "Error: IP address (${ip}) already in use."
continue continue
fi fi
## add ip4.addr to firewall table:jails
pfctl -q -t jails -T add "${ip}"
fi fi
## start the container ## start the container
@@ -102,13 +104,6 @@ for _jail in ${JAILS}; do
bastille rdr "${_jail}" ${_rules} bastille rdr "${_jail}" ${_rules}
done < "${bastille_jailsdir}/${_jail}/rdr.conf" done < "${bastille_jailsdir}/${_jail}/rdr.conf"
fi fi
## add ip4.addr to 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 add "$(jls -j ${_jail} ip4.addr)"
fi
fi
fi fi
echo echo
done done
+9 -6
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> # Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@@ -48,16 +48,19 @@ fi
for _jail in ${JAILS}; do for _jail in ${JAILS}; do
## test if running ## test if running
if [ "$(jls name | awk "/^${_jail}$/")" ]; then if [ "$(/usr/sbin/jls name | awk "/^${_jail}$/")" ]; then
## remove ip4.addr from firewall table:jails ## remove ip4.addr from firewall table:jails
if [ -n "${bastille_network_loopback}" ]; then if [ -n "${bastille_network_loopback}" ]; then
if grep -qw "interface.*=.*${bastille_network_loopback}" "${bastille_jailsdir}/${_jail}/jail.conf"; then if grep -qw "interface.*=.*${bastille_network_loopback}" "${bastille_jailsdir}/${_jail}/jail.conf"; then
pfctl -q -t jails -T delete "$(jls -j ${_jail} ip4.addr)" pfctl -q -t jails -T delete "$(/usr/sbin/jls -j ${_jail} ip4.addr)"
fi fi
fi fi
if [ "$(bastille rdr ${_jail} list)" ]; then # Check if pfctl is present
bastille rdr ${_jail} clear if which -s pfctl; then
if [ "$(bastille rdr ${_jail} list)" ]; then
bastille rdr ${_jail} clear
fi
fi fi
## remove rctl limits ## remove rctl limits
+1 -1
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> # Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
+9 -5
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> # Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@@ -173,7 +173,7 @@ if [ "${TARGET}" = '--convert' ]; then
fi fi
case ${TEMPLATE} in case ${TEMPLATE} in
http?://github.com/*/*|http?://gitlab.com/*/*) http?://*/*/*)
TEMPLATE_DIR=$(echo "${TEMPLATE}" | awk -F / '{ print $4 "/" $5 }') TEMPLATE_DIR=$(echo "${TEMPLATE}" | awk -F / '{ print $4 "/" $5 }')
if [ ! -d "${bastille_templatesdir}/${TEMPLATE_DIR}" ]; then if [ ! -d "${bastille_templatesdir}/${TEMPLATE_DIR}" ]; then
info "Bootstrapping ${TEMPLATE}..." info "Bootstrapping ${TEMPLATE}..."
@@ -186,7 +186,11 @@ case ${TEMPLATE} in
;; ;;
*/*) */*)
if [ ! -d "${bastille_templatesdir}/${TEMPLATE}" ]; then 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 fi
;; ;;
*) *)
@@ -222,9 +226,9 @@ for _jail in ${JAILS}; do
info "Applying template: ${TEMPLATE}..." info "Applying template: ${TEMPLATE}..."
## jail-specific variables. ## 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 if [ "$(bastille config $TARGET get vnet)" != 'enabled' ]; then
_jail_ip=$(jls -j "${_jail}" ip4.addr 2>/dev/null) _jail_ip=$(/usr/sbin/jls -j "${_jail}" ip4.addr 2>/dev/null)
if [ -z "${_jail_ip}" -o "${_jail_ip}" = "-" ]; then if [ -z "${_jail_ip}" -o "${_jail_ip}" = "-" ]; then
error_notify "Jail IP not found: ${_jail}" error_notify "Jail IP not found: ${_jail}"
_jail_ip='' # In case it was -. -- cwells _jail_ip='' # In case it was -. -- cwells
@@ -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}"
@@ -0,0 +1,14 @@
PRE mkdir -p home
PRE mkdir -p tmp
FSTAB devfs root/dev devfs rw 0 0
FSTAB tmpfs dev/shm tmpfs rw,size=1g,mode=1777 0 0
FSTAB fdescfs dev/fd fdescfs rw,linrdlnk 0 0
FSTAB linprocfs proc linprocfs rw 0 0
FSTAB linsysfs sys linsysfs rw 0 0
FSTAB /tmp tmp nullfs rw 0 0
FSTAB /home home nullfs rw 0 0
CMD mkdir etc/apt/apt.conf.d/00aptitude
CMD echo "APT::Cache-Start 251658240;" > etc/apt/apt.conf.d/00aptitude
@@ -5,9 +5,11 @@ INCLUDE ${BASE_TEMPLATE} --arg HOST_RESOLV_CONF="${HOST_RESOLV_CONF}"
ARG EPAIR ARG EPAIR
ARG GATEWAY ARG GATEWAY
ARG GATEWAY6
ARG IFCONFIG="SYNCDHCP" ARG IFCONFIG="SYNCDHCP"
SYSRC ifconfig_${EPAIR}_name=vnet0 SYSRC ifconfig_${EPAIR}_name=vnet0
SYSRC ifconfig_vnet0="${IFCONFIG}" SYSRC ifconfig_vnet0="${IFCONFIG}"
# GATEWAY will be empty for a DHCP config. -- cwells # GATEWAY will be empty for a DHCP config. -- cwells
CMD if [ -n "${GATEWAY}" ]; then /usr/sbin/sysrc defaultrouter="${GATEWAY}"; fi CMD if [ -n "${GATEWAY}" ]; then /usr/sbin/sysrc defaultrouter="${GATEWAY}"; fi
CMD if [ -n "${GATEWAY6}" ]; then /usr/sbin/sysrc ipv6_defaultrouter="${GATEWAY6}"; fi
+1 -1
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> # Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
+1 -1
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> # Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
+63 -5
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> # Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@@ -32,7 +32,7 @@
. /usr/local/etc/bastille/bastille.conf . /usr/local/etc/bastille/bastille.conf
usage() { usage() {
error_exit "Usage: bastille update [release|container] | [option]" error_exit "Usage: bastille update [release|container|template] | [force]"
} }
# Handle special-case commands first. # Handle special-case commands first.
@@ -64,13 +64,25 @@ if [ "${TARGET}" = "ALL" ]; then
error_exit "Batch upgrade is unsupported." error_exit "Batch upgrade is unsupported."
fi fi
if [ -f "/bin/midnightbsd-version" ]; then
echo -e "${COLOR_RED}Not yet supported on MidnightBSD.${COLOR_RESET}"
exit 1
fi
if freebsd-version | grep -qi HBSD; then if freebsd-version | grep -qi HBSD; then
error_exit "Not yet supported on HardenedBSD." error_exit "Not yet supported on HardenedBSD."
fi 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() { jail_check() {
# Check if the jail is thick and is running # 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}'." error_exit "[${TARGET}]: Not started. See 'bastille start ${TARGET}'."
else else
if grep -qw "${bastille_jailsdir}/${TARGET}/root/.bastille" "${bastille_jailsdir}/${TARGET}/fstab"; then if grep -qw "${bastille_jailsdir}/${TARGET}/root/.bastille" "${bastille_jailsdir}/${TARGET}/fstab"; then
@@ -98,15 +110,61 @@ jail_update() {
release_update() { release_update() {
# Update a release base(affects child containers) # Update a release base(affects child containers)
if [ -d "${bastille_releasesdir}/${TARGET}" ]; then 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}" \ 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 else
error_exit "${TARGET} not found. See 'bastille bootstrap'." error_exit "${TARGET} not found. See 'bastille bootstrap'."
fi 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 # 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 release_update
else else
jail_update jail_update
+8 -3
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> # Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@@ -32,7 +32,7 @@
. /usr/local/etc/bastille/bastille.conf . /usr/local/etc/bastille/bastille.conf
usage() { usage() {
error_exit "Usage: bastille upgrade release newrelease | target newrelease | target install | [option]" error_exit "Usage: bastille upgrade release newrelease | target newrelease | target install | [force]"
} }
# Handle special-case commands first. # Handle special-case commands first.
@@ -55,6 +55,11 @@ if [ "${TARGET}" = "ALL" ]; then
error_exit "Batch upgrade is unsupported." error_exit "Batch upgrade is unsupported."
fi fi
if [ -f "/bin/midnightbsd-version" ]; then
echo -e "${COLOR_RED}Not yet supported on MidnightBSD.${COLOR_RESET}"
exit 1
fi
if freebsd-version | grep -qi HBSD; then if freebsd-version | grep -qi HBSD; then
error_exit "Not yet supported on HardenedBSD." error_exit "Not yet supported on HardenedBSD."
fi fi
@@ -71,7 +76,7 @@ esac
jail_check() { jail_check() {
# Check if the jail is thick and is running # 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}'." error_exit "[${TARGET}]: Not started. See 'bastille start ${TARGET}'."
else else
if grep -qw "${bastille_jailsdir}/${TARGET}/root/.bastille" "${bastille_jailsdir}/${TARGET}/fstab"; then if grep -qw "${bastille_jailsdir}/${TARGET}/root/.bastille" "${bastille_jailsdir}/${TARGET}/fstab"; then
+40 -20
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> # Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@@ -36,6 +36,10 @@ bastille_usage() {
} }
verify_release() { verify_release() {
if [ -f "/bin/midnightbsd-version" ]; then
echo -e "${COLOR_RED}Not yet supported on MidnightBSD.${COLOR_RESET}"
exit 1
fi
if freebsd-version | grep -qi HBSD; then if freebsd-version | grep -qi HBSD; then
error_exit "Not yet supported on HardenedBSD." error_exit "Not yet supported on HardenedBSD."
fi fi
@@ -47,6 +51,22 @@ verify_release() {
fi 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() { verify_template() {
_template_path=${bastille_templatesdir}/${BASTILLE_TEMPLATE} _template_path=${bastille_templatesdir}/${BASTILLE_TEMPLATE}
_hook_validate=0 _hook_validate=0
@@ -65,42 +85,42 @@ verify_template() {
echo echo
error_exit "Template validation failed." error_exit "Template validation failed."
## if INCLUDE; recursive verify ## if INCLUDE; recursive verify
elif [ ${_hook} = 'INCLUDE' ]; then elif [ "${_hook}" = 'INCLUDE' ]; then
info "[${_hook}]:" info "[${_hook}]:"
cat "${_path}" cat "${_path}"
echo echo
while read _include; do while read _include; do
info "[${_hook}]:[${_include}]:" info "[${_hook}]:[${_include}]:"
TEMPLATE_INCLUDE="${_include}"
case ${_include} in handle_template_include
http?://github.com/*/*|http?://gitlab.com/*/*)
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
done < "${_path}" done < "${_path}"
## if tree; tree -a bastille_template/_dir ## if tree; tree -a bastille_template/_dir
elif [ ${_hook} = 'OVERLAY' ]; then elif [ "${_hook}" = 'OVERLAY' ]; then
info "[${_hook}]:" info "[${_hook}]:"
cat "${_path}" cat "${_path}"
echo echo
while read _dir; do while read _dir; do
info "[${_hook}]:[${_dir}]:" info "[${_hook}]:[${_dir}]:"
if [ -x /usr/local/bin/tree ]; then if [ -x "/usr/local/bin/tree" ]; then
/usr/local/bin/tree -a "${_template_path}/${_dir}" /usr/local/bin/tree -a "${_template_path}/${_dir}"
else else
find "${_template_path}/${_dir}" -print | sed -e 's;[^/]*/;|___;g;s;___|; |;g' find "${_template_path}/${_dir}" -print | sed -e 's;[^/]*/;|___;g;s;___|; |;g'
fi fi
echo echo
done < "${_path}" 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 else
info "[${_hook}]:" info "[${_hook}]:"
cat "${_path}" cat "${_path}"
@@ -110,7 +130,7 @@ verify_template() {
done done
## remove bad templates ## remove bad templates
if [ ${_hook_validate} -lt 1 ]; then if [ "${_hook_validate}" -lt 1 ]; then
error_notify "No valid template hooks found." error_notify "No valid template hooks found."
error_notify "Template discarded." error_notify "Template discarded."
rm -rf "${bastille_template}" rm -rf "${bastille_template}"
@@ -118,7 +138,7 @@ verify_template() {
fi fi
## if validated; ready to use ## if validated; ready to use
if [ ${_hook_validate} -gt 0 ]; then if [ "${_hook_validate}" -gt 0 ]; then
info "Template ready to use." info "Template ready to use."
fi fi
} }
+1 -1
View File
@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com> # Copyright (c) 2018-2022, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without