Compare commits

..

154 Commits

Author SHA1 Message Date
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
Christer Edwards
c6491710fc Merge pull request #419 from JRGTH/master
Code review/cleanup routine
2021-07-14 14:18:32 -06:00
JRGTH
f39168b9c2 Be more specific with export/import command options 2021-07-14 15:02:12 -04:00
JRGTH
e564d50b2c Code review/cleanup routine 2021-07-14 13:57:09 -04:00
Christer Edwards
fb74bcb047 Merge pull request #418 from cedwards/fix-410-cmd-use-jail-env
fix issue #410 so CMD properly uses jailed env (root)
2021-07-13 21:39:14 -06:00
Christer Edwards
43a33739a3 fix issue #410 so CMD properly uses jailed env (root) 2021-07-13 21:38:03 -06:00
Christer Edwards
4d75ee6b2b Merge pull request #415 from JRGTH/master
Revision for create cmd and cleanup, fixed regressions and enhanced usage
2021-07-13 20:58:38 -06:00
JRGTH
c80b9da9ef Revert changes, colors will be disabled by env variable 2021-07-13 09:05:15 -04:00
JRGTH
64cc7747c8 Disable colors if "NO_COLOR" env variable present 2021-07-13 09:02:55 -04:00
JRGTH
50c09d0359 Feature to disable output colors 2021-07-13 04:49:25 -04:00
Christer Edwards
eeecffa93a Merge pull request #417 from cedwards/docs_quickfix
documentation fix for pkg (remove quotes)
2021-07-12 19:11:46 -06:00
Christer Edwards
4eb95f18ee documentation fix for pkg (remove quotes) 2021-07-12 19:10:33 -06:00
JRGTH
b1258378ab Revision for create cmd, fixed regressions and enhanced usage
This update fixes for previous regressions in the `create.sh` file and code cleanup, also enhances the usage display.
2021-07-12 14:54:00 -04:00
JRGTH
4999f0968f Merge remote-tracking branch 'upstream/master' 2021-07-12 14:52:36 -04:00
JRGTH
92e9579e04 Revert first as conflict with older one 2021-07-12 14:52:25 -04:00
JRGTH
a932abe0e3 Revision for create cmd, fixed regressions and enhanced usage.
This update fixes for previous regressions and code cleanup, also enhances the usage display.
2021-07-12 14:45:37 -04:00
Christer Edwards
8005dd2081 Merge pull request #414 from hackacad/linux_compat
Fix VNET issue causes by Linux compat
2021-07-12 08:14:35 -06:00
Bike Dude
9ff87f2904 reset LINUX_JAIL option 2021-07-12 10:02:51 +02:00
Bike Dude
9bb11c5d54 linux vs. /usr/home fix 2021-07-12 09:42:07 +02:00
Bike Dude
d20f5829c3 fix vnet issue 2021-07-12 09:25:52 +02:00
Christer Edwards
6977a42432 Merge pull request #411 from JRGTH/master
New features and improvements re-revised/re-tested for upcoming release
2021-07-11 19:12:12 -06:00
Christer Edwards
f8b50561ec Merge pull request #413 from hackacad/posix
fix list.sh for BSD grep
2021-07-11 14:34:10 -06:00
Christer Edwards
b997be51ae Merge pull request #340 from hackacad/linux_compat
Linux compat RC1
2021-07-11 14:31:29 -06:00
Bike Dude
f4738cb65d posix 2021-07-11 12:50:08 +02:00
Bike Dude
1b319c9bb9 posix 2021-07-11 10:46:21 +02:00
JRGTH
ee2c25697c Cleanup obsolete code 2021-07-10 09:01:28 -04:00
JRGTH
0a7db32490 Restored usage after file debug 2021-07-10 08:52:08 -04:00
JRGTH
f0c3620fac Add export/import standard I/O redirection
This update enhances the export and import command to fully support jail export/import user standard input/output redirection
2021-07-10 08:35:50 -04:00
Bike Dude
778b82949a posix 2021-07-09 22:32:09 +02:00
Bike Dude
140f02e140 fix 2021-07-09 18:04:28 +02:00
Bike Dude
a1d6e7b50d posix 2021-07-09 15:39:03 +02:00
JRGTH
d73645facb Add the new tgz compress format to UFS systems too 2021-07-08 17:41:27 -04:00
JRGTH
17ea19bf65 Deprecate command parameters not starting with dash here too 2021-07-08 15:37:36 -04:00
JRGTH
5c4d69775f Deprecate command parameters not starting with dash 2021-07-08 15:29:31 -04:00
JRGTH
b0f947ca00 Standardized options position in export/import commands, improve option checks 2021-07-08 13:48:02 -04:00
Bike Dude
b768daf616 docs for 0.9 Linux support 2021-07-07 16:30:49 +02:00
JRGTH
9e3ad27ecf Re-added new and improved create.sh file 2021-07-07 05:22:35 -04:00
JRGTH
8938d03f47 Revert to original file before re-add new 2021-07-07 05:21:28 -04:00
JRGTH
961731b063 New features and improvements revised and re-added 2021-07-07 05:05:38 -04:00
JRGTH
2f63bf3bbc Merge remote-tracking branch 'upstream/master' 2021-07-07 04:53:57 -04:00
JRGTH
b517d3aece File reverted due conflicts 2021-07-07 04:53:33 -04:00
Christer Edwards
9f8b2514b3 Merge pull request #394 from adyxax/network-access-on-startup
Fixes #338 Network access on jail startup
2021-07-04 08:48:59 -06:00
Christer Edwards
ada9352e1f Merge pull request #384 from gtz42/master
Don't include jail path twice
2021-07-04 08:41:03 -06:00
Christer Edwards
091a0f336c Merge pull request #390 from aeifn/master
Lint bootstrap.sh
2021-07-04 08:40:11 -06:00
Egor Kuzmichev
ad4c92055f Update bootstrap.sh
https://github.com/BastilleBSD/bastille/pull/390#discussion_r650394708

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

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

Due the above mentioned issues, the optional distfiles will be copied to the newly created thinjail if they exist on the base release, thus being secure and more granular management.
2021-03-20 06:12:07 -04:00
Bike Dude
b5044a2ddb IPv6 hint for pf.conf 2021-03-18 14:01:57 +01:00
Bike Dude
15ef005337 IPv6 hint for pf.conf 2021-03-18 14:00:21 +01:00
Daniel Dowse
296236f793 Tabs to spaces 2021-03-03 18:56:24 +01:00
Daniel Dowse
dd3b2e8e62 If dual stack ip6 gw will be last will be the last output line of netstat ... comand in _gateway 2021-03-03 15:20:55 +01:00
Daniel Dowse
8cb20e4457 Help output to show real value for options instead of [options] 2021-03-03 00:30:17 +01:00
Christer Edwards
2e5d5b4be1 Merge pull request #356 from cedwards/default-template-fix
revert default template link; error->notify for bootstrap
2021-02-28 13:10:13 -07:00
Christer Edwards
f5e93e4b1a revert default template link; error->notify for bootstrap 2021-02-28 13:08:42 -07:00
Lucas Holt
54697cf77a Fix the file test for FreeBSD/HBSD 2021-02-27 00:13:01 -05:00
Lucas Holt
1710a09f6a Add preliminary support for MidnightBSD. 2021-02-26 16:55:56 -05:00
Christer Edwards
3fe03807ef Merge pull request #350 from zilti/master
Added option to have CP be quiet
2021-02-23 09:51:28 -07:00
Christer Edwards
c7a84a4a4e Merge pull request #351 from tuffnatty/patch-1
Reflect bastille_zfs_mountpoint deprecation in README.md
2021-02-19 09:52:40 -07:00
Daniel Ziltener
2aa92042fd Adjustment for consistency 2021-02-19 17:11:19 +01:00
Phil Krylov
39990b584b Reflect bastille_zfs_mountpoint deprecation in README.md 2021-02-19 17:34:34 +03:00
Daniel Ziltener
214a3e9894 Added option to have CP be quiet 2021-02-18 20:13:28 +01:00
Jose
674e8ff087 More validation/checks for export command 2021-02-18 06:48:43 -04:00
Christer Edwards
f7ef58cc19 Merge pull request #344 from hackacad/include_beta
allow boostrapping BETA build
2021-02-15 13:33:43 -07:00
Bike Dude
e35024508e allow boostrapping BETA build 2021-02-14 17:35:23 +01:00
Bike Dude
baa362c69b allow boostrapping BETA build 2021-02-14 17:29:29 +01:00
Bike Dude
440db5f82a typo 2021-02-14 17:27:09 +01:00
Bike Dude
4373b8b8d9 lint 2021-02-10 15:07:53 +01:00
Bike Dude
056b0237ad Ubuntu Focal support
incl. minor fixes
2021-02-10 14:33:04 +01:00
Bike Dude
0b80c59744 minor fixes 2021-02-10 10:27:49 +01:00
Bike Dude
373eafa4d6 POC RC1
POC for Bastille Linux Compat
2021-02-10 10:09:15 +01:00
Bike Dude
e7959a3f67 Alpha1
w/o bastille console
2021-02-09 22:00:07 +01:00
Bike Dude
519fe77fbb debug
v0.1
2021-02-08 22:11:33 +01:00
Jose
211a268c36 Use which since shell built-in and search for paths 2021-02-08 05:31:16 -04:00
Jose
75ed5b3ce4 Add quick check for pfctl command 2021-02-08 04:17:32 -04:00
Jose
80639062d7 Fix and improve the convert command 2021-02-05 13:59:09 -04:00
Jose
b31c8d514b Simplify options parsing and better handling for combined options 2021-02-03 20:39:30 -04:00
Jose
5583ab1d78 Add support bastille RAW image exports/imports, also extended help usage 2021-02-03 18:31:41 -04:00
Christer Edwards
af8d766b0e Merge pull request #333 from BastilleBSD/issue-332
fixes issue #332
2021-01-29 12:32:33 -07:00
Christer Edwards
9a5a1f960e fixes issue #332 2021-01-29 09:27:39 -07:00
Christer Edwards
ec24d7a897 Merge pull request #329 from BastilleBSD/docs-fix
minor fixes to previous doc updates
2021-01-27 13:55:12 -07:00
Christer Edwards
a450dd1de8 minor fixes to previous doc updates 2021-01-27 13:53:23 -07:00
Christer Edwards
4b27614ad7 Merge pull request #328 from BastilleBSD/docs-fix
fix formatting in network documentation
2021-01-27 13:49:50 -07:00
Christer Edwards
c3130f0eec fix formatting in network documentation 2021-01-27 13:46:05 -07:00
Christer Edwards
b5f1f15c45 Merge pull request #327 from fbarthez/patch-1
Minor md syntax fixes, adding missing spaces
2021-01-27 13:39:47 -07:00
Fabian Peters
c141f31dbd Minor md syntax fixes, adding missing spaces 2021-01-27 19:28:38 +01:00
Christer Edwards
584839fd78 Merge pull request #319 from hackacad/pf_keep
Update README / pf.conf
2021-01-19 12:59:08 -07:00
Bike Dude
627d1af284 update pf.conf 2021-01-19 20:10:53 +01:00
Bike Dude
8311a66b94 update pf.conf 2021-01-19 18:27:45 +01:00
Christer Edwards
113beb54e7 Merge pull request #317 from cedwards/release-prep-20210115
version bump for 0.8.20210115
2021-01-15 20:31:11 -07:00
Christer Edwards
2c5fff7ec7 version bump for 0.8.20210115 2021-01-15 20:28:34 -07:00
Christer Edwards
ae5feaa3df Merge pull request #316 from cedwards/2021-updates
update 2021 copyright
2021-01-15 20:11:04 -07:00
Christer Edwards
6fa744bbda update 2021 copyright 2021-01-15 20:00:26 -07:00
Christer Edwards
5b8fcf5a4d Merge pull request #311 from JRGTH/master
Don't start empty jails, don't apply template if Bastillefile is empty
2021-01-15 19:51:40 -07:00
Jose
15c1505187 Revert jail enable|disable feature by now, requested for later review 2021-01-15 22:28:08 -04:00
Christer Edwards
49e24c9ec9 Merge pull request #313 from cedwards/rdr-standardization
rdr now persists rules by default; rdr.sh cleanup
2021-01-14 19:16:35 -07:00
Jose
2474382756 Improve interface validation on vnet jail creation 2021-01-12 23:15:39 -04:00
Jose
87944a0fd0 Don't allow underscore in jail name beginning, remove jail from bastille_list on destroy 2021-01-10 18:55:02 -04:00
Jose
6aa84cb3f5 Small cosmetic/typo corrections 2021-01-10 02:26:40 -04:00
Jose
ed8ff8bd80 Fix to properly upgrade base releases 2021-01-09 21:24:05 -04:00
Christer Edwards
74fdcbdcb5 rdr now persists rules by default; rdr.sh cleanup 2021-01-09 15:42:24 -07:00
Jose
996e7e2b40 Option to enable/disable jail auto-start using sysrc 2021-01-09 16:18:11 -04:00
Jose
665cc19ce6 Properly link shared ports on thin jails 2021-01-08 22:37:18 -04:00
Jose
d2fcc011be Feature option for safe ZFS jail exports, config update 2021-01-08 20:30:03 -04:00
Jose
b528289815 Don't start empty jails unless templates defined, code improvements 2021-01-08 20:26:31 -04:00
Christer Edwards
110346f9f7 Merge pull request #312 from yaazkal/patch-2
export: Clarifies that UFS jails must be stopped
2021-01-08 17:13:23 -07:00
yaazkal
099f09c8b0 export: Clarifies that UFS jails must be stopped 2021-01-08 17:54:31 -05:00
Jose
083e019081 Don't start empty jails, don't apply template if Bastillefile is empty 2021-01-08 02:05:30 -04:00
Christer Edwards
4824d95d68 Merge pull request #307 from cedwards/rdr-fix-20210101
fix %s->%d regression
2021-01-05 18:30:46 -07:00
Christer Edwards
cc870b2667 fix %s->%d regression 2021-01-05 18:24:02 -07:00
Christer Edwards
67362ff309 Merge pull request #306 from cedwards/rdr-fix-20210101
add required 'pass' to rdr rules
2021-01-05 18:07:05 -07:00
Christer Edwards
6f043d62e5 add required 'pass' to rdr rules 2021-01-05 18:00:28 -07:00
Bike Dude
03ab9fd203 Thick Upgrade 2021-01-05 20:38:08 +01:00
44 changed files with 1123 additions and 345 deletions

View File

@@ -7,13 +7,21 @@ Christer Edwards [christer.edwards@gmail.com]
## Contributors (code)
- Barry McCormick
- Brian Downs
- Carsten Bäcker
- Chris Wells
- Dave Cottlehuber
- Giacomo Olgeni
- Gleb Popov
- JP Mens
- Jose Rivera
- Juan David Hurtado G.
- Lars E.
- Marius van Witzenburg
- Matt Audesse
- Paul C.
- Petru T. Garstea
- Sven R.
- Tobias Tom
### Special thanks
Software doesn't happen in a vacuum. Thank you to the following people who may

View File

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

129
README.md
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
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/*"
block in all
pass out quick modulate state
pass out quick keep state
antispoof for $ext_if inet
pass in inet proto tcp from any to any port ssh flags S/SA keep state
## 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 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_zpool="" ## default: ""
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"
```
@@ -234,8 +236,8 @@ not using ZFS and can safely ignore these settings.
bastille bootstrap
------------------
Before you can begin creating containers, Bastille needs to "bootstrap" a
release. Current supported releases are 11.3-RELEASE, 12.0-RELEASE and
12.1-RELEASE.
release. Current supported releases are 11.4-RELEASE, 12.2-RELEASE and
13.0-RELEASE.
**Important: If you need ZFS support see the above section BEFORE
bootstrapping.**
@@ -243,14 +245,14 @@ bootstrapping.**
To `bootstrap` a release, run the bootstrap sub-command with the
release version as the argument.
**FreeBSD 11.3-RELEASE**
**FreeBSD 11.4-RELEASE**
```shell
ishmael ~ # bastille bootstrap 11.3-RELEASE
ishmael ~ # bastille bootstrap 11.4-RELEASE
```
**FreeBSD 12.1-RELEASE**
**FreeBSD 12.2-RELEASE**
```shell
ishmael ~ # bastille bootstrap 12.1-RELEASE
ishmael ~ # bastille bootstrap 12.2-RELEASE
```
**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
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 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
---------------
@@ -306,24 +339,24 @@ IP at container creation.
**ip4**
```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).
NAME: folsom.
IP: 10.17.89.10.
RELEASE: 12.1-RELEASE.
RELEASE: 12.2-RELEASE.
syslogd_flags: -s -> -ss
sendmail_enable: NO -> NONE
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.
**ip6**
```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).
NAME: folsom.
@@ -335,12 +368,12 @@ sendmail_enable: NO -> NONE
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.
**VNET**
```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: (em0).
@@ -356,7 +389,7 @@ ifconfig_e0b_bastille0_name: -> vnet0
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.
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").
```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.
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
execute commands inside the container automatically.
Currently supported template hooks are: `ARG`, `LIMITS`, `INCLUDE`, `PRE`,
`FSTAB`, `PKG`, `OVERLAY`, `SYSRC`, `SERVICE`, `CMD`, `RENDER`.
Planned template hooks include: `PF`, `LOG`
Currently supported template hooks are: `ARG`, `LIMITS`, `INCLUDE`,
`MOUNT`, `PKG`, `CP`, `SYSRC`, `SERVICE`, `RDR`, `CMD`, `RENDER`.
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,
@@ -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;
```shell
echo "zsh vim-console git-lite htop" > /usr/local/bastille/templates/username/base-template/PKG
echo "/usr/bin/chsh -s /usr/local/bin/zsh" > /usr/local/bastille/templates/username/base-template/CMD
echo "usr" > /usr/local/bastille/templates/username/base-template/OVERLAY
echo "PKG zsh vim-console git-lite htop" >> /usr/local/bastille/templates/username/base-template/Bastillefile
echo "CMD /usr/bin/chsh -s /usr/local/bin/zsh" >> /usr/local/bastille/templates/username/base-template/Bastillefile
echo "CP usr" > /usr/local/bastille/templates/username/base-template/Bastillefile
```
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 |
| CMD | /bin/sh command | /usr/bin/chsh -s /usr/local/bin/zsh |
| RENDER | paths (one/line) | /usr/local/etc/nginx |
| 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 |
| RDR | protocol port port | tcp 2200 22 |
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;
```shell
echo "etc" > /usr/local/bastille/templates/username/base/OVERLAY
echo "usr" >> /usr/local/bastille/templates/username/base/OVERLAY
echo "CP etc" >> /usr/local/bastille/templates/username/base/Bastillefile
echo "CP usr" >> /usr/local/bastille/templates/username/base/Bastillefile
```
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
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
ishmael ~ # bastille update 11.2-RELEASE
ishmael ~ # bastille update 11.4-RELEASE
Targeting specified release.
11.2-RELEASE
11.4-RELEASE
Looking up update.FreeBSD.org mirrors... 2 mirrors found.
Fetching metadata signature for 11.2-RELEASE from update4.freebsd.org... done.
Fetching metadata signature for 11.4-RELEASE from update4.freebsd.org... done.
Fetching metadata index... done.
Inspecting system... done.
Preparing to download files... done.
No updates needed to update system to 11.2-RELEASE-p4.
No updates needed to update system to 11.4-RELEASE-p4.
No updates are available to install.
```
@@ -916,11 +953,21 @@ bastille upgrade
This sub-command lets you upgrade a release to a new release. Depending on the
workflow this can be similar to a `bootstrap`.
For standard containers you need to upgrade the shared base jail:
```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
---------------
@@ -1028,11 +1075,7 @@ Example (create, start, console)
This example creates, starts and consoles into the container.
```shell
ishmael ~ # bastille create alcatraz 11.2-RELEASE 10.17.89.7
RELEASE: 11.2-RELEASE.
NAME: alcatraz.
IP: 10.17.89.7.
ishmael ~ # bastille create alcatraz 11.4-RELEASE 10.17.89.7
```
```shell
@@ -1044,7 +1087,7 @@ alcatraz: created
```shell
ishmael ~ # bastille console 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!

View File

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

View File

@@ -165,23 +165,14 @@ Create the firewall rules:
set skip on lo
table <jails> persist
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
## dynamic rdr anchor (see below)
nat on $ext_if from <jails> to any -> ($ext_if:0)
rdr-anchor "rdr/*"
block in all
pass out quick modulate state
pass out quick keep state
antispoof for $ext_if inet
pass in inet proto tcp from any to any port ssh flags S/SA modulate state
# 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 include the last line (`port ssh`) or you'll end up locked out.
@@ -192,30 +183,26 @@ to containers are:
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
interface for outbound access.
The `rdr pass ...` will redirect traffic from the host firewall on port X to
the ip of Container Y. The example shown redirects web traffic (80 & 443) to the
containers at `10.17.89.45`.
.. code-block:: shell
## dynamic rdr anchor (see below)
rdr-anchor "rdr/*"
The `rdr-anchor "rdr/*"` enables dynamic rdr rules to be setup using the
`bastille rdr` command at runtime - eg.
.. code-block:: shell
bastille rdr <jail> tcp 2001 22 # Redirects tcp port 2001 on host to 22 on jail
bastille rdr <jail> udp 2053 53 # Same for udp
bastille rdr <jail> list # List dynamic rdr rules
bastille rdr <jail> clear # Clear dynamic rdr rules
Note that if you are redirecting ports where the host is also listening
(eg. ssh) you should make sure that the host service is not listening on
the cloned interface - eg. for ssh set sshd_flags in rc.conf
Note that if you are redirecting ports where the host is also listening (eg.
ssh) you should make sure that the host service is not listening on the cloned
interface - eg. for ssh set sshd_flags in rc.conf
sshd_flags="-o ListenAddress=<hostname>"

View File

@@ -11,7 +11,8 @@ container backups.
ishmael ~ # bastille export azkaban
The export sub-command supports both UFS and ZFS storage. ZFS based containers
will use ZFS snapshots. UFS based containers will use `txz` archives.
will use ZFS snapshots. UFS based containers will use `txz` archives and they
can be exported only when the jail is not running.
.. code-block:: shell

View File

@@ -6,7 +6,7 @@ To manage binary packages within the container use `bastille pkg`.
.. code-block:: shell
ishmael ~ # bastille pkg folsom 'install vim-console git-lite zsh'
ishmael ~ # bastille pkg folsom install vim-console git-lite zsh
[folsom]:
The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]: y

View File

@@ -7,14 +7,14 @@ Templates](https://gitlab.com/BastilleBSD-Templates)?
Bastille supports a templating system allowing you to apply files, pkgs and
execute commands inside the containers automatically.
Currently supported template hooks are: `LIMITS`, `INCLUDE`, `PRE`, `FSTAB`,
`PKG`, `OVERLAY`, `SYSRC`, `SERVICE`, `CMD`.
Currently supported template hooks are: `CMD`, `CP`, `INCLUDE`, `LIMITS`, `MOUNT`,
`PKG`, `RDR`, `SERVICE`, `SYSRC`.
Templates are created in `${bastille_prefix}/templates` and can leverage any of
the template hooks.
Bastille 0.7.x
--------------
Bastille 0.7.x+
---------------
Bastille 0.7.x introduces a template syntax that is more flexible and allows
any-order scripting. Previous versions had a hard template execution order and
instructions were spread across multiple files. The new syntax is done in a
@@ -27,23 +27,23 @@ Template Automation Hooks
+---------+-------------------+-----------------------------------------+
| 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 |
+---------+-------------------+-----------------------------------------+
| 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 |
+---------+-------------------+-----------------------------------------+
| OVERLAY | path(s) | etc root usr (one per line) |
+---------+-------------------+-----------------------------------------+
| SYSRC | sysrc command(s) | nginx_enable=YES |
| RDR | tcp port port | tcp 2200 22 (hostport jailport) |
+---------+-------------------+-----------------------------------------+
| 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
@@ -71,7 +71,7 @@ use, be sure to include `usr` in the template OVERLAY definition. eg;
.. 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.
You do not need to list individual files. Just include the top-level directory

View File

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

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2020, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -70,7 +70,7 @@ bastille_perms_check() {
bastille_perms_check
## version
BASTILLE_VERSION="0.8.20210101"
BASTILLE_VERSION="0.9.20210714"
usage() {
cat << EOF
@@ -135,10 +135,10 @@ version|-v|--version)
help|-h|--help)
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
;;
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
if [ $# -eq 0 ]; then # No target was given, so show the command's help. -- cwells
PARAMS='help'

View File

@@ -33,6 +33,7 @@ bastille_resolv_conf="/etc/resolv.conf" ## default
## bootstrap urls
bastille_url_freebsd="http://ftp.freebsd.org/pub/FreeBSD/releases/" ## default: "http://ftp.freebsd.org/pub/FreeBSD/releases/"
bastille_url_hardenedbsd="http://installer.hardenedbsd.org/pub/hardenedbsd/" ## default: "https://installer.hardenedbsd.org/pub/HardenedBSD/releases/"
bastille_url_midnightbsd="https://www.midnightbsd.org/ftp/MidnightBSD/releases/" ## default: "https://www.midnightbsd.org/pub/MidnightBSD/releases/"
## ZFS options
bastille_zfs_enable="" ## default: ""
@@ -43,6 +44,8 @@ bastille_zfs_options="-o compress=lz4 -o atime=off" ## default
## Export/Import options
bastille_compress_xz_options="-0 -v" ## default "-0 -v"
bastille_decompress_xz_options="-c -d -v" ## default "-c -d -v"
bastille_compress_gz_options="-1 -v" ## default "-1 -v"
bastille_decompress_gz_options="-k -d -c -v" ## default "-k -d -c -v"
## Networking
bastille_network_loopback="bastille0" ## default: "bastille0"
@@ -51,7 +54,7 @@ bastille_network_gateway="" ## default
## Default Templates
bastille_template_base="default/base" ## default: "default/base"
bastille_template_empty="default/empty" ## default: "default/empty"
bastille_template_empty="" ## default: "default/empty"
bastille_template_thick="default/thick" ## default: "default/thick"
bastille_template_thin="default/thin" ## default: "default/thin"
bastille_template_vnet="default/vnet" ## default: "default/vnet"

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2020, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# 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.
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)"
read answer
read answer
case $answer in
no|No|n|N|"")
error_exit "ERROR: Missing ZFS parameters. See bastille_zfs_enable."
;;
yes|Yes|y|Y)
continue
;;
yes|Yes|y|Y) ;;
esac
fi
@@ -85,7 +83,7 @@ validate_release_url() {
info "Bootstrapping ${PLATFORM_OS} distfiles..."
# Alternate RELEASE/ARCH fetch support
if [ "${OPTION}" = "--i386" -o "${OPTION}" = "--32bit" ]; then
if [ "${OPTION}" = "--i386" ] || [ "${OPTION}" = "--32bit" ]; then
ARCH="i386"
RELEASE="${RELEASE}-${ARCH}"
fi
@@ -178,7 +176,6 @@ bootstrap_directories() {
else
mkdir -p "${bastille_templatesdir}"
fi
ln -s "${bastille_sharedir}/templates/default" "${bastille_templatesdir}/default"
fi
## ${bastille_releasesdir}
@@ -216,7 +213,7 @@ bootstrap_release() {
## check if release already bootstrapped, else continue bootstrapping
if [ -z "${bastille_bootstrap_archives}" ]; then
error_exit "Bootstrap appears complete."
error_notify "Bootstrap appears complete."
else
info "Bootstrapping additional distfiles..."
fi
@@ -254,12 +251,12 @@ bootstrap_release() {
fi
if [ -d "${bastille_cachedir}/${RELEASE}" ]; then
if [ ! "$(ls -A "${bastille_cachedir}/${RELEASE}")" ]; then
rm -rf "${bastille_cachedir}/${RELEASE}"
rm -rf "${bastille_cachedir:?}/${RELEASE}"
fi
fi
if [ -d "${bastille_releasesdir}/${RELEASE}" ]; then
if [ ! "$(ls -A "${bastille_releasesdir}/${RELEASE}")" ]; then
rm -rf "${bastille_releasesdir}/${RELEASE}"
rm -rf "${bastille_releasesdir:?}/${RELEASE}"
fi
fi
error_exit "Bootstrap failed."
@@ -267,8 +264,7 @@ bootstrap_release() {
## fetch for missing dist files
if [ ! -f "${bastille_cachedir}/${RELEASE}/${_archive}.txz" ]; then
fetch "${UPSTREAM_URL}/${_archive}.txz" -o "${bastille_cachedir}/${RELEASE}/${_archive}.txz"
if [ "$?" -ne 0 ]; then
if ! fetch "${UPSTREAM_URL}/${_archive}.txz" -o "${bastille_cachedir}/${RELEASE}/${_archive}.txz"; then
## alert only if unable to fetch additional dist files
error_notify "Failed to fetch ${_archive}.txz."
fi
@@ -329,15 +325,15 @@ bootstrap_template() {
_template=${bastille_templatesdir}/${_user}/${_repo}
## support for non-git
if [ ! -x "$(which git)" ]; then
if ! which -s git; then
error_notify "Git not found."
error_exit "Not yet implemented."
elif [ -x "$(which git)" ]; then
else
if [ ! -d "${_template}/.git" ]; then
$(which git) clone "${_url}" "${_template}" ||\
git clone "${_url}" "${_template}" ||\
error_notify "Clone unsuccessful."
elif [ -d "${_template}/.git" ]; then
cd "${_template}" && $(which git) pull ||\
git -C "${_template}" pull ||\
error_notify "Template update unsuccessful."
fi
fi
@@ -353,7 +349,7 @@ OPTION="${2}"
# Alternate RELEASE/ARCH fetch support(experimental)
if [ -n "${OPTION}" ] && [ "${OPTION}" != "${HW_MACHINE}" ] && [ "${OPTION}" != "update" ]; then
# Supported architectures
if [ "${OPTION}" = "--i386" -o "${OPTION}" = "--32bit" ]; then
if [ "${OPTION}" = "--i386" ] || [ "${OPTION}" = "--32bit" ]; then
HW_MACHINE="i386"
HW_MACHINE_ARCH="i386"
else
@@ -363,6 +359,13 @@ fi
## Filter sane release names
case "${1}" in
2.[0-9]*)
## check for MidnightBSD releases name
NAME_VERIFY=$(echo "${RELEASE}")
UPSTREAM_URL="${bastille_url_midnightbsd}${HW_MACHINE_ARCH}/${NAME_VERIFY}"
PLATFORM_OS="MidnightBSD"
validate_release_url
;;
*-CURRENT|*-current)
## check for FreeBSD releases name
NAME_VERIFY=$(echo "${RELEASE}" | grep -iwE '^([1-9]{2,2})\.[0-9](-CURRENT)$' | tr '[:lower:]' '[:upper:]')
@@ -370,9 +373,9 @@ case "${1}" in
PLATFORM_OS="FreeBSD"
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
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}"
PLATFORM_OS="FreeBSD"
validate_release_url
@@ -420,17 +423,94 @@ current-build-latest|current-BUILD-LATEST|CURRENT-BUILD-LATEST)
PLATFORM_OS="HardenedBSD"
validate_release_url
;;
http?://github.com/*/*|http?://gitlab.com/*/*)
http?://*/*/*)
BASTILLE_TEMPLATE_URL=${1}
BASTILLE_TEMPLATE_USER=$(echo "${1}" | awk -F / '{ print $4 }')
BASTILLE_TEMPLATE_REPO=$(echo "${1}" | awk -F / '{ print $5 }')
bootstrap_template
;;
#adding Ubuntu Bionic as valid "RELEASE" for POC @hackacad
ubuntu_bionic|bionic|ubuntu-bionic)
#check and install OS dependencies @hackacad
if [ ! "$(sysrc -f /boot/loader.conf -n linprocfs_load)" = "YES" ] && [ ! "$(sysrc -f /boot/loader.conf -n linsysfs_load)" = "YES" ] && [ ! "$(sysrc -f /boot/loader.conf -n tmpfs_load)" = "YES" ]; then
warn "linprocfs_load, linsysfs_load, tmpfs_load not enabled in /boot/loader.conf or linux_enable not active. Should I do that for you? (N|y)"
read answer
case $answer in
[Nn][Oo]|[Nn]|"")
error_exit "Exiting."
;;
[Yy][Ee][Ss]|[Yy])
info "Loading modules"
kldload linux linux64 linprocfs linsysfs tmpfs
info "Persisting modules"
sysrc linux_enable=YES
sysrc -f /boot/loader.conf linprocfs_load=YES
sysrc -f /boot/loader.conf linsysfs_load=YES
sysrc -f /boot/loader.conf tmpfs_load=YES
;;
esac
fi
if which -s debootstrap; then
debootstrap --foreign --arch=amd64 --no-check-gpg bionic "${bastille_releasesdir}"/Ubuntu_1804
else
warn "Debootstrap not found. Should it be installed? (N|y)"
read answer
case $answer in
[Nn][Oo]|[Nn]|"")
error_exit "Exiting. You need to install debootstap before boostrapping a Linux jail."
;;
[Yy][Ee][Ss]|[Yy])
pkg install -y debootstrap
debootstrap --foreign --arch=amd64 --no-check-gpg bionic "${bastille_releasesdir}"/Ubuntu_1804
;;
esac
fi
echo "APT::Cache-Start 251658240;" > "${bastille_releasesdir}"/Ubuntu_1804/etc/apt/apt.conf.d/00aptitude
;;
ubuntu_focal|focal|ubuntu-focal)
#check and install OS dependencies @hackacad
#ToDo: add function 'linux_pre' for sysrc etc.
if [ ! "$(sysrc -f /boot/loader.conf -n linprocfs_load)" = "YES" ] && [ ! "$(sysrc -f /boot/loader.conf -n linsysfs_load)" = "YES" ] && [ ! "$(sysrc -f /boot/loader.conf -n tmpfs_load)" = "YES" ]; then
warn "linprocfs_load, linsysfs_load, tmpfs_load not enabled in /boot/loader.conf or linux_enable not active. Should I do that for you? (N|y)"
read answer
case $answer in
[Nn][Oo]|[Nn]|"")
error_exit "Exiting."
;;
[Yy][Ee][Ss]|[Yy])
info "Loading modules"
kldload linux linux64 linprocfs linsysfs tmpfs
info "Persisting modules"
sysrc linux_enable=YES
sysrc -f /boot/loader.conf linprocfs_load=YES
sysrc -f /boot/loader.conf linsysfs_load=YES
sysrc -f /boot/loader.conf tmpfs_load=YES
;;
esac
fi
if which -s debootstrap; then
debootstrap --foreign --arch=amd64 --no-check-gpg focal "${bastille_releasesdir}"/Ubuntu_2004
else
warn "Debootstrap not found. Should it be installed? (N|y)"
read answer
case $answer in
[Nn][Oo]|[Nn]|"")
error_exit "Exiting. You need to install debootstap before boostrapping a Linux jail."
;;
[Yy][Ee][Ss]|[Yy])
pkg install -y debootstrap
debootstrap --foreign --arch=amd64 --no-check-gpg focal "${bastille_releasesdir}"/Ubuntu_2004
;;
esac
fi
;;
*)
usage
;;
esac
case "${OPTION}" in
update)
bastille update "${RELEASE}"

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2020, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2020, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -47,6 +47,6 @@ fi
for _jail in ${JAILS}; do
info "[${_jail}]:"
jexec -l "${_jail}" "$@"
jexec -l -U root "${_jail}" "$@"
echo
done

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2020, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# 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
# 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 ! export | grep -q "NO_COLOR"; then
enable_color
fi
# Notify message on error, but do not exit
error_notify() {

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2020, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -76,7 +76,7 @@ for _jail in ${JAILS}; do
MATCH_FOUND=$?
if [ "${ACTION}" = 'get' ]; then
if [ $MATCH_FOUND -ne 0 ]; then
if [ "${MATCH_FOUND}" -ne 0 ]; then
warn "not set"
elif ! echo "${MATCH_LINE}" | grep '=' > /dev/null 2>&1; then
echo "enabled"
@@ -99,7 +99,7 @@ for _jail in ${JAILS}; do
LINE=" ${PROPERTY};"
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}"
else # Replace the existing value. -- cwells
sed -i '' -E "s/ *${ESCAPED_PROPERTY}[ =;].*/${LINE}/" "${FILE}"

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2020, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -32,7 +32,7 @@
. /usr/local/etc/bastille/bastille.conf
usage() {
error_exit "Usage: bastille console TARGET [user]'"
error_exit "Usage: bastille console TARGET [user]"
}
# Handle special-case commands first.
@@ -53,7 +53,7 @@ validate_user() {
USER_SHELL="$(jexec -l "${_jail}" getent passwd "${USER}" | cut -d: -f7)"
if [ -n "${USER_SHELL}" ]; then
if jexec -l "${_jail}" grep -qwF "${USER_SHELL}" /etc/shells; then
jexec -l "${_jail}" /usr/bin/login -f "${USER}"
jexec -l "${_jail}" $LOGIN -f "${USER}"
else
echo "Invalid shell for user ${USER}"
fi
@@ -76,11 +76,12 @@ check_fib() {
for _jail in ${JAILS}; do
info "[${_jail}]:"
LOGIN="$(jexec -l "${_jail}" which login)"
if [ -n "${USER}" ]; then
validate_user
else
check_fib
${_setfib} jexec -l "${_jail}" /usr/bin/login -f root
LOGIN="$(jexec -l "${_jail}" which login)"
${_setfib} jexec -l "${_jail}" $LOGIN -f root
fi
echo
done

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2020, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -57,6 +57,7 @@ convert_symlinks() {
done
# Copy new files to destination jail
info "Copying required base files to container..."
for _link in ${SYMLINKS}; do
if [ ! -d "${_link}" ]; then
if [ -d "${bastille_releasesdir}/${RELEASE}/${_link}" ]; then
@@ -100,13 +101,15 @@ revert_convert() {
start_convert() {
# Attempt container conversion and handle some errors
DATE=$(date)
if [ -d "${bastille_jailsdir}/${TARGET}" ]; then
info "Converting '${TARGET}' into a thickjail. This may take a while..."
# Set some variables
RELEASE=$(grep -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")
SYMLINKS="bin boot lib libexec rescue sbin usr/bin usr/include usr/lib usr/lib32 usr/libdata usr/libexec usr/ports usr/sbin usr/share usr/src"
HASPORTS=$(grep -w ${bastille_releasesdir}/${RELEASE}/usr/ports ${bastille_jailsdir}/${TARGET}/fstab)
if [ -n "${RELEASE}" ]; then
cd "${bastille_jailsdir}/${TARGET}/root"
@@ -115,7 +118,12 @@ start_convert() {
convert_symlinks
# Comment the line containing .bastille and rename mountpoint
sed -i '' -E "s|${FSTABMOD}|# Converted from thin to thick container on $(date)|g" "${bastille_jailsdir}/${TARGET}/fstab"
sed -i '' -E "s|${FSTABMOD}|# Converted from thin to thick container on ${DATE}|g" "${bastille_jailsdir}/${TARGET}/fstab"
if [ -n "${HASPORTS}" ]; then
sed -i '' -E "s|${HASPORTS}|# Ports copied from base to container on ${DATE}|g" "${bastille_jailsdir}/${TARGET}/fstab"
info "Copying ports to container..."
cp -a "${bastille_releasesdir}/${RELEASE}/usr/ports" "${bastille_jailsdir}/${TARGET}/root/usr"
fi
mv "${bastille_jailsdir}/${TARGET}/root/.bastille" "${bastille_jailsdir}/${TARGET}/root/.bastille.old"
info "Conversion of '${TARGET}' completed successfully!"

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2020, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -32,27 +32,41 @@
. /usr/local/etc/bastille/bastille.conf
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.
case "$1" in
help|-h|--help)
usage
;;
-q|--quiet)
OPTION="${1}"
CPSOURCE="${2}"
CPDEST="${3}"
;;
esac
if [ $# -ne 2 ]; then
usage
fi
CPSOURCE="${1}"
CPDEST="${2}"
case "${OPTION}" in
-q|--quiet)
OPTION="-a"
;;
*)
OPTION="-av"
;;
esac
for _jail in ${JAILS}; do
info "[${_jail}]:"
bastille_jail_path="${bastille_jailsdir}/${_jail}/root"
cp -av "${CPSOURCE}" "${bastille_jail_path}/${CPDEST}"
cp "${OPTION}" "${CPSOURCE}" "${bastille_jail_path}/${CPDEST}"
RETURN="$?"
if [ "${TARGET}" = "ALL" ]; then
# Display the return status for reference

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2020, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -32,7 +32,20 @@
. /usr/local/etc/bastille/bastille.conf
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.
EOF
exit 1
}
running_jail() {
@@ -46,7 +59,9 @@ running_jail() {
validate_name() {
local NAME_VERIFY=${NAME}
local NAME_SANITY=$(echo "${NAME_VERIFY}" | tr -c -d 'a-zA-Z0-9-_')
if [ "${NAME_VERIFY}" != "${NAME_SANITY}" ]; then
if [ -n "$(echo "${NAME_SANITY}" | awk "/^[-_].*$/" )" ]; then
error_exit "Container names may not begin with (-|_) characters!"
elif [ "${NAME_VERIFY}" != "${NAME_SANITY}" ]; then
error_exit "Container names may not contain special characters!"
fi
}
@@ -139,6 +154,30 @@ ${NAME} {
EOF
}
generate_linux_jail_conf() {
cat << EOF > "${bastille_jail_conf}"
${NAME} {
host.hostname = ${NAME};
mount.fstab = ${bastille_jail_fstab};
path = ${bastille_jail_path};
devfs_ruleset = 4;
exec.start = '/bin/true';
exec.stop = '/bin/true';
persist;
mount.devfs;
allow.mount;
allow.mount.devfs;
interface = ${bastille_jail_conf_interface};
${IPX_ADDR} = ${IP};
ip6 = ${IP6_MODE};
}
EOF
}
generate_vnet_jail_conf() {
## determine number of containers + 1
## iterate num and grep all jail configs
@@ -174,7 +213,7 @@ ${NAME} {
vnet;
vnet.interface = e0b_${uniq_epair};
exec.prestart += "jib addm ${uniq_epair} ${INTERFACE}";
exec.prestart += "jib addm ${uniq_epair} ${bastille_jail_conf_interface}";
exec.poststop += "jib destroy ${uniq_epair}";
}
EOF
@@ -203,8 +242,51 @@ create_jail() {
mkdir -p "${bastille_jailsdir}/${NAME}/root"
fi
fi
## PoC for Linux jails @hackacad
if [ -n "${LINUX_JAIL}" ]; then
if [ ! -d "${bastille_jail_base}" ]; then
mkdir -p "${bastille_jail_base}"
fi
mkdir -p "${bastille_jail_path}/dev"
mkdir -p "${bastille_jail_path}/proc"
mkdir -p "${bastille_jail_path}/sys"
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 [ -z "${EMPTY_JAIL}" ]; then
if [ ! -d "${bastille_jail_template}" ]; then
mkdir -p "${bastille_jail_template}"
fi
if [ ! -f "${bastille_jail_fstab}" ]; then
touch "${bastille_jail_fstab}"
fi
echo -e "devfs ${bastille_jail_path}/dev devfs rw 0 0" > "${bastille_jail_fstab}"
echo -e "tmpfs ${bastille_jail_path}/dev/shm tmpfs rw,size=1g,mode=1777 0 0" > "${bastille_jail_fstab}"
echo -e "fdescfs ${bastille_jail_path}/dev/fd fdescfs rw,linrdlnk 0 0" > "${bastille_jail_fstab}"
echo -e "linprocfs ${bastille_jail_path}/proc linprocfs rw 0 0" > "${bastille_jail_fstab}"
echo -e "linsysfs ${bastille_jail_path}/sys linsysfs rw 0 0" > "${bastille_jail_fstab}"
echo -e "/tmp ${bastille_jail_path}/tmp nullfs rw 0 0" > "${bastille_jail_fstab}"
## 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 [ -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
fi
if [ -z "${EMPTY_JAIL}" ] && [ -z "${LINUX_JAIL}" ]; then
if [ ! -d "${bastille_jail_base}" ]; then
mkdir -p "${bastille_jail_base}"
fi
@@ -235,7 +317,7 @@ create_jail() {
if [ -n "${INTERFACE}" ]; then
local bastille_jail_conf_interface=${INTERFACE}
fi
## generate the jail configuration file
if [ -n "${VNET_JAIL}" ]; then
generate_vnet_jail_conf
@@ -248,19 +330,19 @@ create_jail() {
## MAKE SURE WE'RE IN THE RIGHT PLACE
cd "${bastille_jail_path}"
echo
info "NAME: ${NAME}."
info "IP: ${IP}."
if [ -n "${INTERFACE}" ]; then
info "INTERFACE: ${INTERFACE}."
fi
info "RELEASE: ${RELEASE}."
echo
if [ -z "${THICK_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"
for _link in ${LINK_LIST}; do
ln -sf /.bastille/${_link} ${_link}
done
# Properly link shared ports on thin jails in read-write.
if [ -d "${bastille_releasesdir}/${RELEASE}/usr/ports" ]; then
if [ ! -d "${bastille_jail_path}/usr/ports" ]; then
mkdir ${bastille_jail_path}/usr/ports
fi
echo -e "${bastille_releasesdir}/${RELEASE}/usr/ports ${bastille_jail_path}/usr/ports nullfs rw 0 0" >> "${bastille_jail_fstab}"
fi
fi
if [ -z "${THICK_JAIL}" ]; then
@@ -269,8 +351,7 @@ create_jail() {
FILE_LIST=".cshrc .profile COPYRIGHT dev etc media mnt net proc root tmp var usr/obj usr/tests"
for files in ${FILE_LIST}; do
if [ -f "${bastille_releasesdir}/${RELEASE}/${files}" ] || [ -d "${bastille_releasesdir}/${RELEASE}/${files}" ]; then
cp -a "${bastille_releasesdir}/${RELEASE}/${files}" "${bastille_jail_path}/${files}"
if [ "$?" -ne 0 ]; then
if ! cp -a "${bastille_releasesdir}/${RELEASE}/${files}" "${bastille_jail_path}/${files}"; then
## notify and clean stale files/directories
bastille destroy "${NAME}"
error_exit "Failed to copy release files. Please retry create!"
@@ -317,23 +398,25 @@ create_jail() {
fi
fi
## create home directory if missing
if [ ! -d "${bastille_jail_path}/usr/home" ]; then
mkdir -p "${bastille_jail_path}/usr/home"
fi
## link home properly
if [ ! -L "home" ]; then
ln -s usr/home home
fi
if [ -z "${LINUX_JAIL}" ]; then
## create home directory if missing
if [ ! -d "${bastille_jail_path}/usr/home" ]; then
mkdir -p "${bastille_jail_path}/usr/home"
fi
## link home properly
if [ ! -L "home" ]; then
ln -s usr/home home
fi
## TZ: configurable (default: Etc/UTC)
ln -s "/usr/share/zoneinfo/${bastille_tzdata}" etc/localtime
## TZ: configurable (default: Etc/UTC)
ln -s "/usr/share/zoneinfo/${bastille_tzdata}" etc/localtime
# Post-creation jail misc configuration
# Create a dummy fstab file
touch "etc/fstab"
# 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"
# Post-creation jail misc configuration
# Create a dummy fstab file
touch "etc/fstab"
# 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"
fi
## VNET specific
if [ -n "${VNET_JAIL}" ]; then
@@ -344,7 +427,10 @@ create_jail() {
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_conf
fi
@@ -353,41 +439,72 @@ create_jail() {
chmod 0700 "${bastille_jailsdir}/${NAME}"
# Jail must be started before applying the default template. -- cwells
bastille start "${NAME}"
if [ -z "${EMPTY_JAIL}" ]; then
bastille start "${NAME}"
elif [ -n "${EMPTY_JAIL}" ]; then
# Don't start empty jails unless a template defined.
if [ -n "${bastille_template_empty}" ]; then
bastille start "${NAME}"
fi
fi
if [ -n "${VNET_JAIL}" ]; then
if [ -n ${bastille_template_vnet} ]; then
if [ -n "${bastille_template_vnet}" ]; then
## rename interface to generic vnet0
uniq_epair=$(grep vnet.interface "${bastille_jailsdir}/${NAME}/jail.conf" | awk '{print $3}' | sed 's/;//')
_gateway=''
_ifconfig=SYNCDHCP
if [ "${IP}" != "0.0.0.0" ]; then # not using DHCP, so set static address.
_ifconfig="inet ${IP}"
if [ -n "${ip6}" ]; then
_ifconfig="inet6 ${IP}"
else
_ifconfig="inet ${IP}"
fi
if [ -n "${bastille_network_gateway}" ]; then
_gateway="${bastille_network_gateway}"
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
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}"
fi
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}"
fi
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}"
fi
else # Thin jail.
if [ -n ${bastille_template_thin} ]; then
## 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
bastille template "${NAME}" ${bastille_template_thin} --arg BASE_TEMPLATE="${bastille_template_base}" --arg HOST_RESOLV_CONF="${bastille_resolv_conf}"
fi
fi
# Apply values changed by the template. -- cwells
bastille restart "${NAME}"
if [ -z "${EMPTY_JAIL}" ] && [ -z "${LINUX_JAIL}" ]; then
bastille restart "${NAME}"
elif [ -n "${EMPTY_JAIL}" ]; then
# Don't restart empty jails unless a template defined.
if [ -n "${bastille_template_empty}" ]; then
bastille restart "${NAME}"
fi
fi
}
# Handle special-case commands first.
@@ -406,33 +523,46 @@ fi
EMPTY_JAIL=""
THICK_JAIL=""
VNET_JAIL=""
LINUX_JAIL=""
## handle combined options then shift
if [ "${1}" = "-T" -o "${1}" = "--thick" -o "${1}" = "thick" ] && \
[ "${2}" = "-V" -o "${2}" = "--vnet" -o "${2}" = "vnet" ]; then
THICK_JAIL="1"
VNET_JAIL="1"
shift 2
else
## handle single options
# Handle and parse options
while [ $# -gt 0 ]; do
case "${1}" in
-E|--empty|empty)
shift
EMPTY_JAIL="1"
shift
;;
-L|--linux|linux)
LINUX_JAIL="1"
shift
;;
-T|--thick|thick)
shift
THICK_JAIL="1"
shift
;;
-V|--vnet|vnet)
shift
VNET_JAIL="1"
shift
;;
-*)
-*|--*)
error_notify "Unknown Option."
usage
;;
*)
break
;;
esac
done
## validate for combined options
if [ -n "${EMPTY_JAIL}" ]; then
if [ -n "${THICK_JAIL}" ] || [ -n "${VNET_JAIL}" ] || [ -n "${LINUX_JAIL}" ]; then
error_exit "Error: Empty jail option can't be used with other options."
fi
elif [ -n "${LINUX_JAIL}" ]; then
if [ -n "${EMPTY_JAIL}" ] || [ -n "${VNET_JAIL}" ] || [ -n "${THICK_JAIL}" ]; then
error_exit "Error: Linux jail option can't be used with other options."
fi
fi
NAME="$1"
@@ -455,17 +585,39 @@ if [ -n "${NAME}" ]; then
validate_name
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
;;
*)
error_notify "Unknown Linux."
usage
;;
esac
fi
if [ -z "${EMPTY_JAIL}" ]; then
## verify release
case "${RELEASE}" in
2.[0-9]*)
## check for MidnightBSD releases name
NAME_VERIFY=$(echo "${RELEASE}")
validate_release
;;
*-CURRENT|*-CURRENT-I386|*-CURRENT-i386|*-current)
## 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')
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
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
;;
*-stable-LAST|*-STABLE-last|*-stable-last|*-STABLE-LAST)
@@ -493,6 +645,14 @@ 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')
validate_release
;;
ubuntu_bionic|bionic|ubuntu-bionic)
NAME_VERIFY=Ubuntu_1804
validate_release
;;
ubuntu_focal|focal|ubuntu-focal)
NAME_VERIFY=Ubuntu_2004
validate_release
;;
*)
error_notify "Unknown Release."
usage
@@ -520,6 +680,15 @@ if [ -z "${EMPTY_JAIL}" ]; then
if [ -n "${INTERFACE}" ]; then
validate_netif
validate_netconf
elif [ -n "${VNET_JAIL}" ]; then
if [ -z "${INTERFACE}" ]; then
if [ -z "${bastille_network_shared}" ]; then
# User must specify interface on vnet jails.
error_exit "Error: Network interface not defined."
else
validate_netconf
fi
fi
else
validate_netconf
fi
@@ -545,6 +714,9 @@ fi
if [ -z ${bastille_template_empty+x} ]; then
bastille_template_empty='default/empty'
fi
if [ -z ${bastille_template_linux+x} ]; then
bastille_template_linux='default/linux'
fi
if [ -z ${bastille_template_thick+x} ]; then
bastille_template_thick='default/thick'
fi

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2020, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -32,7 +32,7 @@
. /usr/local/etc/bastille/bastille.conf
usage() {
error_exit "Usage: bastille destroy [option] | [container|release]"
error_exit "Usage: bastille destroy [force] | [container|release]"
}
destroy_jail() {
@@ -76,6 +76,12 @@ destroy_jail() {
rm -rf "${bastille_jail_base}"
fi
# Remove target from bastille_list if exist
# Mute sysrc output here as it may be undesirable on large startup list
if [ -n "$(sysrc -qn bastille_list | tr -s " " "\n" | awk "/^${TARGET}$/")" ]; then
sysrc bastille_list-="${TARGET}" > /dev/null
fi
## archive jail log
if [ -f "${bastille_jail_log}" ]; then
mv "${bastille_jail_log}" "${bastille_jail_log}"-"$(date +%F)"
@@ -194,9 +200,9 @@ 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')
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
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
;;
*-stable-LAST|*-STABLE-last|*-stable-last|*-STABLE-LAST)

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2020, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2020, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -32,7 +32,27 @@
. /usr/local/etc/bastille/bastille.conf
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.
Tip: If no option specified, container should be exported to standard output.
EOF
exit 1
}
# Handle special-case commands first
@@ -47,74 +67,258 @@ if [ "${TARGET}" = "ALL" ]; then
error_exit "Batch export is unsupported."
fi
if [ $# -gt 2 ] || [ $# -lt 0 ]; then
if [ $# -gt 5 ] || [ $# -lt 1 ]; then
usage
fi
OPTION="${1}"
EXPATH="${2}"
zfs_enable_check() {
# Temporarily disable ZFS so we can create a standard backup archive
if [ "${bastille_zfs_enable}" = "YES" ]; then
bastille_zfs_enable="NO"
fi
}
# Handle some options
if [ -n "${OPTION}" ]; then
if [ "${OPTION}" = "-t" -o "${OPTION}" = "--txz" ]; then
if [ "${bastille_zfs_enable}" = "YES" ]; then
# Temporarily disable ZFS so we can create a standard backup archive
bastille_zfs_enable="NO"
fi
elif echo "${OPTION}" | grep -q "\/"; then
if [ -d "${OPTION}" ]; then
EXPATH="${OPTION}"
else
error_exit "Error: Path not found."
fi
else
error_notify "Invalid option!"
usage
TARGET="${1}"
GZIP_EXPORT=
SAFE_EXPORT=
USER_EXPORT=
RAW_EXPORT=
DIR_EXPORT=
TXZ_EXPORT=
TGZ_EXPORT=
OPT_ZSEND="-R"
COMP_OPTION="0"
opt_count() {
COMP_OPTION=$(expr ${COMP_OPTION} + 1)
}
# 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
# 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 "$(jls name | awk "/^${TARGET}$/")" ]; then
SAFE_EXPORT=
fi
fi
# Export directory check
if [ -n "${EXPATH}" ]; then
if [ -d "${EXPATH}" ]; then
if [ -n "${DIR_EXPORT}" ]; then
if [ -d "${DIR_EXPORT}" ]; then
# Set the user defined export directory
bastille_backupsdir="${EXPATH}"
bastille_backupsdir="${DIR_EXPORT}"
else
error_exit "Error: Path not found."
fi
fi
jail_export()
{
# Fallback to default if missing config parameters
if [ -z "${bastille_compress_xz_options}" ]; then
bastille_compress_xz_options="-0 -v"
fi
if [ -z "${bastille_compress_gz_options}" ]; then
bastille_compress_gz_options="-1 -v"
fi
create_zfs_snap() {
# Take a recursive temporary snapshot
if [ -z "${USER_EXPORT}" ]; then
info "Creating temporary ZFS snapshot for export..."
fi
zfs snapshot -r "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_export_${DATE}"
}
clean_zfs_snap() {
# Cleanup the recursive temporary snapshot
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}/root@bastille_export_${DATE}"
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_export_${DATE}"
}
export_check() {
# Inform the user about the exporting method
if [ -z "${USER_EXPORT}" ]; then
if [ -n "$(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
DATE=$(date +%F-%H%M%S)
if [ "${bastille_zfs_enable}" = "YES" ]; then
if [ -n "${bastille_zfs_zpool}" ]; then
FILE_EXT="xz"
info "Exporting '${TARGET}' to a compressed .${FILE_EXT} archive."
info "Sending ZFS data stream..."
# Take a recursive temporary snapshot
zfs snapshot -r "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_export_${DATE}"
if [ -n "${RAW_EXPORT}" ]; then
FILE_EXT=""
export_check
# Export the container recursively and cleanup temporary snapshots
zfs send -R "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_export_${DATE}" | \
xz ${bastille_compress_xz_options} > "${bastille_backupsdir}/${TARGET}_${DATE}.${FILE_EXT}"
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}/root@bastille_export_${DATE}"
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_export_${DATE}"
# Export the raw container recursively and cleanup temporary snapshots
zfs send ${OPT_ZSEND} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_export_${DATE}" \
> "${bastille_backupsdir}/${TARGET}_${DATE}"
clean_zfs_snap
elif [ -n "${GZIP_EXPORT}" ]; then
FILE_EXT=".gz"
export_check
# Export the raw container recursively and cleanup temporary snapshots
zfs send ${OPT_ZSEND} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_export_${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_export_${DATE}" | \
xz ${bastille_compress_xz_options} > "${bastille_backupsdir}/${TARGET}_${DATE}${FILE_EXT}"
clean_zfs_snap
else
FILE_EXT=""
USER_EXPORT="1"
export_check
# Quietly export the container recursively, user must redirect standard output
zfs send ${OPT_ZSEND} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_export_${DATE}"
clean_zfs_snap
fi
fi
else
# Create standard backup archive
FILE_EXT="txz"
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}"
if [ -n "${TGZ_EXPORT}" ]; then
FILE_EXT=".tgz"
# Create standard tgz backup archive
info "Exporting '${TARGET}' to a compressed ${FILE_EXT} archive..."
cd "${bastille_jailsdir}" && tar -cf - "${TARGET}" | gzip ${bastille_compress_gz_options} > "${bastille_backupsdir}/${TARGET}_${DATE}${FILE_EXT}"
elif [ -n "${TXZ_EXPORT}" ]; then
FILE_EXT=".txz"
# Create standard txz backup archive
info "Exporting '${TARGET}' to a compressed ${FILE_EXT} archive..."
cd "${bastille_jailsdir}" && tar -cf - "${TARGET}" | xz ${bastille_compress_xz_options} > "${bastille_backupsdir}/${TARGET}_${DATE}${FILE_EXT}"
else
error_exit "Error: export option required"
fi
fi
if [ "$?" -ne 0 ]; then
error_exit "Failed to export '${TARGET}' container."
else
# Generate container checksum file
cd "${bastille_backupsdir}"
sha256 -q "${TARGET}_${DATE}.${FILE_EXT}" > "${TARGET}_${DATE}.sha256"
info "Exported '${bastille_backupsdir}/${TARGET}_${DATE}.${FILE_EXT}' successfully."
if [ -z "${USER_EXPORT}" ]; then
# Generate container checksum file
cd "${bastille_backupsdir}"
sha256 -q "${TARGET}_${DATE}${FILE_EXT}" > "${TARGET}_${DATE}.sha256"
info "Exported '${bastille_backupsdir}/${TARGET}_${DATE}${FILE_EXT}' successfully."
fi
exit 0
fi
}
@@ -124,12 +328,17 @@ if [ ! -d "${bastille_backupsdir}" ]; then
error_exit "Backups directory/dataset does not exist. See 'bastille bootstrap'."
fi
# Check if is a ZFS system
if [ "${bastille_zfs_enable}" != "YES" ]; then
# Check if container is running and ask for stop in UFS systems
if [ -n "$(jls name | awk "/^${TARGET}$/")" ]; then
error_exit "${TARGET} is running. See 'bastille stop'."
if [ -n "${TARGET}" ]; then
if [ ! -d "${bastille_jailsdir}/${TARGET}" ]; then
error_exit "[${TARGET}]: Not found."
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 "$(jls name | awk "/^${TARGET}$/")" ]; then
error_exit "${TARGET} is running. See 'bastille stop'."
fi
fi
jail_export
fi

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2020, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2020, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -32,7 +32,20 @@
. /usr/local/etc/bastille/bastille.conf
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
@@ -42,39 +55,70 @@ help|-h|--help)
;;
esac
if [ $# -gt 2 ] || [ $# -lt 1 ]; then
if [ $# -gt 3 ] || [ $# -lt 1 ]; then
usage
fi
TARGET="${1}"
OPTION="${2}"
shift
OPT_FORCE=
USER_IMPORT=
OPT_ZRECV="-u"
# Handle and parse option args
while [ $# -gt 0 ]; do
case "${1}" in
-f|--force)
OPT_FORCE="1"
TARGET="${2}"
shift
;;
-v|--verbose)
OPT_ZRECV="-u -v"
TARGET="${2}"
shift
;;
-*|--*)
error_notify "Unknown Option."
usage
;;
*)
if [ $# -gt 1 ] || [ $# -lt 1 ]; then
usage
fi
shift
;;
esac
done
# Fallback to default if missing config parameters
if [ -z "${bastille_decompress_xz_options}" ]; then
bastille_decompress_xz_options="-c -d -v"
fi
if [ -z "${bastille_decompress_gz_options}" ]; then
bastille_decompress_gz_options="-k -d -c -v"
fi
validate_archive() {
# Compare checksums on the target archive
# Skip validation for unsupported archives
if [ "${FILE_EXT}" != ".tar.gz" ] && [ "${FILE_EXT}" != ".tar" ]; then
if [ -f "${bastille_backupsdir}/${TARGET}" ]; then
if [ -f "${bastille_backupsdir}/${FILE_TRIM}.sha256" ]; then
info "Validating file: ${TARGET}..."
SHA256_DIST=$(cat "${bastille_backupsdir}/${FILE_TRIM}.sha256")
SHA256_FILE=$(sha256 -q "${bastille_backupsdir}/${TARGET}")
if [ "${SHA256_FILE}" != "${SHA256_DIST}" ]; then
error_exit "Failed validation for ${TARGET}."
else
info "File validation successful!"
fi
# Skip validation for unsupported archive
if [ -f "${bastille_backupsdir}/${TARGET}" ]; then
if [ -f "${bastille_backupsdir}/${FILE_TRIM}.sha256" ]; then
info "Validating file: ${TARGET}..."
SHA256_DIST=$(cat "${bastille_backupsdir}/${FILE_TRIM}.sha256")
SHA256_FILE=$(sha256 -q "${bastille_backupsdir}/${TARGET}")
if [ "${SHA256_FILE}" != "${SHA256_DIST}" ]; then
error_exit "Failed validation for ${TARGET}."
else
# Check if user opt to force import
if [ "${OPTION}" = "-f" -o "${OPTION}" = "force" ]; then
warn "Warning: Skipping archive validation!"
else
error_exit "Checksum file not found. See 'bastille import TARGET -f'."
fi
info "File validation successful!"
fi
else
# Check if user opt to force import
if [ -n "${OPT_FORCE}" ]; then
warn "Warning: Skipping archive validation!"
else
error_exit "Checksum file not found. See 'bastille import [option(s)] FILE'."
fi
fi
else
warn "Warning: Skipping archive validation!"
fi
}
@@ -313,23 +357,34 @@ remove_zfs_datasets() {
jail_import() {
# 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")
validate_archive
if [ -d "${bastille_jailsdir}" ]; then
if [ "${bastille_zfs_enable}" = "YES" ]; then
if [ -n "${bastille_zfs_zpool}" ]; then
if [ "${FILE_EXT}" = ".xz" ]; then
validate_archive
# Import from compressed xz on ZFS systems
info "Importing '${TARGET_TRIM}' from compressed ${FILE_EXT} archive."
info "Importing '${TARGET_TRIM}' from compressed ${FILE_EXT} image."
info "Receiving ZFS data stream..."
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_zfsmount
elif [ "${FILE_EXT}" = ".txz" ]; then
validate_archive
# Prepare the ZFS environment and restore from existing .txz file
create_zfs_datasets
@@ -340,7 +395,20 @@ jail_import() {
if [ "$?" -ne 0 ]; then
remove_zfs_datasets
fi
elif [ "${FILE_EXT}" = ".tgz" ]; then
validate_archive
# Prepare the ZFS environment and restore from existing .tgz file
create_zfs_datasets
# Extract required files to the new datasets
info "Extracting files from '${TARGET}' archive..."
tar --exclude='root' -xf "${bastille_backupsdir}/${TARGET}" --strip-components 1 -C "${bastille_jailsdir}/${TARGET_TRIM}"
tar -xf "${bastille_backupsdir}/${TARGET}" --strip-components 2 -C "${bastille_jailsdir}/${TARGET_TRIM}/root" "${TARGET_TRIM}/root"
if [ "$?" -ne 0 ]; then
remove_zfs_datasets
fi
elif [ "${FILE_EXT}" = ".zip" ]; then
validate_archive
# Attempt to import a foreign/iocage container
info "Importing '${TARGET_TRIM}' from foreign compressed ${FILE_EXT} archive."
# Sane bastille ZFS options
@@ -353,9 +421,9 @@ jail_import() {
rm -f "${FILE_TRIM}" "${FILE_TRIM}_root"
fi
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 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_zfsmount
@@ -403,6 +471,27 @@ jail_import() {
else
update_config
fi
elif [ -z "${FILE_EXT}" ]; then
if echo "${TARGET}" | grep -q '_[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}-[0-9]\{6\}$'; then
validate_archive
# Based on the file name, looks like we are importing a raw bastille image
# Import from uncompressed image file
info "Importing '${TARGET_TRIM}' from uncompressed image archive."
info "Receiving ZFS data stream..."
zfs receive ${OPT_ZRECV} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}" < "${bastille_backupsdir}/${TARGET}"
# Update ZFS mountpoint property if required
update_zfsmount
else
# Based on the file name, looks like we are importing from previous redirected bastille image
# Quietly import from previous redirected bastille image
if ! zfs receive ${OPT_ZRECV} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}"; then
exit 1
else
# Update ZFS mountpoint property if required
update_zfsmount
fi
fi
else
error_exit "Unknown archive format."
fi
@@ -412,6 +501,9 @@ jail_import() {
if [ "${FILE_EXT}" = ".txz" ]; then
info "Extracting files from '${TARGET}' archive..."
tar -Jxf "${bastille_backupsdir}/${TARGET}" -C "${bastille_jailsdir}"
elif [ "${FILE_EXT}" = ".tgz" ]; then
info "Extracting files from '${TARGET}' archive..."
tar -xf "${bastille_backupsdir}/${TARGET}" -C "${bastille_jailsdir}"
elif [ "${FILE_EXT}" = ".tar.gz" ]; then
# Attempt to import/configure foreign/ezjail container
info "Extracting files from '${TARGET}' archive..."
@@ -442,7 +534,9 @@ jail_import() {
# This is required on foreign imports only
update_jailconf
update_fstab
info "Container '${TARGET_TRIM}' imported successfully."
if [ -z "${USER_IMPORT}" ]; then
info "Container '${TARGET_TRIM}' imported successfully."
fi
exit 0
fi
else
@@ -465,22 +559,32 @@ fi
# Check if archive exist then trim archive name
if [ -f "${bastille_backupsdir}/${TARGET}" ]; then
# Filter unsupported/unknown archives
if echo "${TARGET}" | grep -q '_[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}-[0-9]\{6\}.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
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
else
error_exit "Unrecognized archive name."
fi
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
# Check if a running jail matches name or already exist
if [ -n "$(jls name | awk "/^${TARGET_TRIM}$/")" ]; then
error_exit "A running jail matches name."
elif [ -d "${bastille_jailsdir}/${TARGET_TRIM}" ]; then
error_exit "Container: ${TARGET_TRIM} already exists."
elif [ -n "${TARGET_TRIM}" ]; then
if [ -d "${bastille_jailsdir}/${TARGET_TRIM}" ]; then
error_exit "Container: ${TARGET_TRIM} already exists."
fi
fi
jail_import
if [ -n "${TARGET}" ]; then
jail_import
fi

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2020, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
# Ressource limits added by Sven R github.com/hackacad
#

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2020, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -32,7 +32,7 @@
. /usr/local/etc/bastille/bastille.conf
usage() {
error_exit "Usage: bastille list [-j] [release|template|(jail|container)|log|limit|(import|export|backup)]"
error_exit "Usage: bastille list [-j|-a] [release|template|(jail|container)|log|limit|(import|export|backup)]"
}
if [ $# -eq 0 ]; then
@@ -50,6 +50,84 @@ if [ $# -gt 0 ]; then
help|-h|--help)
usage
;;
all|-a|--all)
if [ -d "${bastille_jailsdir}" ]; then
DEFAULT_VALUE="-"
SPACER=2
MAX_LENGTH_JAIL_NAME=$(find "${bastille_jailsdir}" -maxdepth 2 -type f -name jail.conf | sed "s/^.*\/\(.*\)\/jail.conf$/\1/" | awk '{ print length($0) }' | sort -nr | head -n 1)
MAX_LENGTH_JAIL_NAME=${MAX_LENGTH_JAIL_NAME:-3}
if [ ${MAX_LENGTH_JAIL_NAME} -lt 3 ]; then MAX_LENGTH_JAIL_NAME=3; fi
MAX_LENGTH_JAIL_IP=$(find "${bastille_jailsdir}" -maxdepth 2 -type f -name jail.conf -exec sed -n "s/^[ ]*ip[4,6].addr[ ]*=[ ]*\(.*\);$/\1/p" {} \; | sed 's/\// /g' | awk '{ print length($1) }' | sort -nr | head -n 1)
MAX_LENGTH_JAIL_IP=${MAX_LENGTH_JAIL_IP:-10}
MAX_LENGTH_JAIL_VNET_IP=$(find "${bastille_jailsdir}" -maxdepth 2 -type f -name jail.conf -exec grep -l "vnet;" {} + | sed 's/\(.*\)jail.conf$/grep "ifconfig_vnet0=" \1root\/etc\/rc.conf/' | sh | sed -n 's/^ifconfig_vnet0="\(.*\)"$/\1/p' | sed 's/\// /g' | awk '{ if ($1 ~ /^[inet|inet6]/) print length($2); else print 15 }' | sort -nr | head -n 1)
MAX_LENGTH_JAIL_VNET_IP=${MAX_LENGTH_JAIL_VNET_IP:-10}
if [ ${MAX_LENGTH_JAIL_VNET_IP} -gt ${MAX_LENGTH_JAIL_IP} ]; then MAX_LENGTH_JAIL_IP=${MAX_LENGTH_JAIL_VNET_IP}; fi
if [ ${MAX_LENGTH_JAIL_IP} -lt 10 ]; then MAX_LENGTH_JAIL_IP=10; fi
MAX_LENGTH_JAIL_HOSTNAME=$(find "${bastille_jailsdir}" -maxdepth 2 -type f -name jail.conf -exec sed -n "s/^[ ]*host.hostname[ ]*=[ ]*\(.*\);$/\1/p" {} \; | awk '{ print length($0) }' | sort -nr | head -n 1)
MAX_LENGTH_JAIL_HOSTNAME=${MAX_LENGTH_JAIL_HOSTNAME:-8}
if [ ${MAX_LENGTH_JAIL_HOSTNAME} -lt 8 ]; then MAX_LENGTH_JAIL_HOSTNAME=8; fi
MAX_LENGTH_JAIL_PORTS=$(find "${bastille_jailsdir}" -maxdepth 2 -type f -name rdr.conf -exec awk '{ lines++; chars += length($0)} END { chars += lines - 1; print chars }' {} \; | sort -nr | head -n 1)
MAX_LENGTH_JAIL_PORTS=${MAX_LENGTH_JAIL_PORTS:-15}
if [ ${MAX_LENGTH_JAIL_PORTS} -lt 15 ]; then MAX_LENGTH_JAIL_PORTS=15; fi
if [ ${MAX_LENGTH_JAIL_PORTS} -gt 30 ]; then MAX_LENGTH_JAIL_PORTS=30; fi
MAX_LENGTH_JAIL_RELEASE=$(find "${bastille_jailsdir}" -maxdepth 2 -type f -name fstab 2> /dev/null -exec grep "/releases/.*/root/.bastille nullfs" {} \; | sed -n "s/^\(.*\) \/.*$/grep \"\^USERLAND_VERSION=\" \1\/bin\/freebsd-version 2\> \/dev\/null/p" | awk '!_[$0]++' | sh | sed -n "s/^USERLAND_VERSION=\"\(.*\)\"$/\1/p" | awk '{ print length($0) }' | sort -nr | head -n 1)
MAX_LENGTH_JAIL_RELEASE=${MAX_LENGTH_JAIL_RELEASE:-7}
MAX_LENGTH_THICK_JAIL_RELEASE=$(find ""${bastille_jailsdir}/*/root/bin"" -maxdepth 1 -type f -name freebsd-version 2> /dev/null -exec grep "^USERLAND_VERSION=" {} \; | sed -n "s/^USERLAND_VERSION=\"\(.*\)\"$/\1/p" | awk '{ print length($0) }' | sort -nr | head -n 1)
MAX_LENGTH_THICK_JAIL_RELEASE=${MAX_LENGTH_THICK_JAIL_RELEASE:-7}
if [ ${MAX_LENGTH_THICK_JAIL_RELEASE} -gt ${MAX_LENGTH_JAIL_RELEASE} ]; then MAX_LENGTH_JAIL_RELEASE=${MAX_LENGTH_THICK_JAIL_RELEASE}; fi
if [ ${MAX_LENGTH_JAIL_RELEASE} -lt 7 ]; then MAX_LENGTH_JAIL_RELEASE=7; fi
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
if [ "$(jls name | awk "/^${_JAIL}$/")" ]; then
JAIL_STATE="Up"
if [ "$(awk '$1 == "vnet;" { print $1 }' "${bastille_jailsdir}/${_JAIL}/jail.conf")" ]; then
JAIL_IP=$(jexec -l ${_JAIL} ifconfig -n vnet0 inet 2> /dev/null | sed -n "/.inet /{s///;s/ .*//;p;}")
if [ ! ${JAIL_IP} ]; then JAIL_IP=$(jexec -l ${_JAIL} ifconfig -n vnet0 inet6 2> /dev/null | awk '/inet6 / && (!/fe80::/ || !/%vnet0/)' | sed -n "/.inet6 /{s///;s/ .*//;p;}"); fi
else
JAIL_IP=$(jls -j ${_JAIL} ip4.addr 2> /dev/null)
if [ ${JAIL_IP} = "-" ]; then JAIL_IP=$(jls -j ${_JAIL} ip6.addr 2> /dev/null); fi
fi
JAIL_HOSTNAME=$(jls -j ${_JAIL} host.hostname 2> /dev/null)
JAIL_PORTS=$(pfctl -a "rdr/${_JAIL}" -Psn 2> /dev/null | awk '{ printf "%s/%s:%s"",",$7,$14,$18 }' | sed "s/,$//")
JAIL_PATH=$(jls -j ${_JAIL} path 2> /dev/null)
JAIL_RELEASE=$(jexec -l ${_JAIL} freebsd-version -u 2> /dev/null)
else
JAIL_STATE=$(if [ "$(sed -n "/^${_JAIL} {$/,/^}$/p" "${bastille_jailsdir}/${_JAIL}/jail.conf" | awk '$0 ~ /^'${_JAIL}' \{|\}/ { printf "%s",$0 }')" == "${_JAIL} {}" ]; then echo "Down"; else echo "n/a"; fi)
if [ "$(awk '$1 == "vnet;" { print $1 }' "${bastille_jailsdir}/${_JAIL}/jail.conf")" ]; then
JAIL_IP=$(sed -n 's/^ifconfig_vnet0="\(.*\)"$/\1/p' "${bastille_jailsdir}/${_JAIL}/root/etc/rc.conf" | sed "s/\// /g" | awk '{ if ($1 ~ /^[inet|inet6]/) print $2; else print $1 }')
else
JAIL_IP=$(sed -n "s/^[ ]*ip[4,6].addr[ ]*=[ ]*\(.*\);$/\1/p" "${bastille_jailsdir}/${_JAIL}/jail.conf" | sed "s/\// /g" | awk '{ print $1 }')
fi
JAIL_HOSTNAME=$(sed -n "s/^[ ]*host.hostname[ ]*=[ ]*\(.*\);$/\1/p" "${bastille_jailsdir}/${_JAIL}/jail.conf")
if [ -f "${bastille_jailsdir}/${_JAIL}/rdr.conf" ]; then JAIL_PORTS=$(awk '$1 ~ /^[tcp|udp]/ { printf "%s/%s:%s,",$1,$2,$3 }' "${bastille_jailsdir}/${_JAIL}/rdr.conf" | sed "s/,$//"); else JAIL_PORTS=""; fi
JAIL_PATH=$(sed -n "s/^[ ]*path[ ]*=[ ]*\(.*\);$/\1/p" "${bastille_jailsdir}/${_JAIL}/jail.conf")
if [ ${JAIL_PATH} ]; then
if [ -f "${JAIL_PATH}/bin/freebsd-version" ]; then
JAIL_RELEASE=$(sed -n "s/^USERLAND_VERSION=\"\(.*\)\"$/\1/p" "${JAIL_PATH}/bin/freebsd-version")
else
JAIL_RELEASE=$(grep "/releases/.*/root/.bastille nullfs" "${bastille_jailsdir}/${_JAIL}/fstab" 2> /dev/null | sed -n "s/^\(.*\) \/.*$/grep \"\^USERLAND_VERSION=\" \1\/bin\/freebsd-version 2\> \/dev\/null/p" | awk '!_[$0]++' | sh | sed -n "s/^USERLAND_VERSION=\"\(.*\)\"$/\1/p")
fi
else
JAIL_RELEASE=""
fi
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}%*s${JAIL_STATE}%*s${JAIL_IP}%*s${JAIL_PORTS}%*s${JAIL_HOSTNAME}%*s${JAIL_RELEASE}%*s${JAIL_PATH}\n" "$((${MAX_LENGTH_JAIL_NAME} - ${#_JAIL} + ${SPACER}))" "" "$((5 - ${#JAIL_STATE} + ${SPACER}))" "" "$((${MAX_LENGTH_JAIL_IP} - ${#JAIL_IP} + ${SPACER}))" "" "$((${MAX_LENGTH_JAIL_PORTS} - ${#JAIL_PORTS} + ${SPACER}))" "" "$((${MAX_LENGTH_JAIL_HOSTNAME} - ${#JAIL_HOSTNAME} + ${SPACER}))" "" "$((${MAX_LENGTH_JAIL_RELEASE} - ${#JAIL_RELEASE} + ${SPACER}))" ""
fi
done
else
error_exit "unfortunately there are no jails here (${bastille_jailsdir})"
fi
;;
release|releases)
if [ -d "${bastille_releasesdir}" ]; then
REL_LIST=$(ls "${bastille_releasesdir}" | sed "s/\n//g")
@@ -80,7 +158,7 @@ if [ $# -gt 0 ]; then
rctl -h jail:
;;
import|imports|export|exports|backup|backups)
ls "${bastille_backupsdir}" | grep -Ev "*.sha256"
ls "${bastille_backupsdir}" | grep -v ".sha256$"
exit 0
;;
*)

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2020, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -97,8 +97,8 @@ for _jail in ${JAILS}; do
_fstab_entry="${_hostpath} ${_jailpath} ${_type} ${_perms} ${_checks}"
## Create mount point if it does not exist. -- cwells
if [ ! -d "${bastille_jailsdir}/${_jail}/root/${_jailpath}" ]; then
if ! mkdir -p "${bastille_jailsdir}/${_jail}/root/${_jailpath}"; then
if [ ! -d "${_jailpath}" ]; then
if ! mkdir -p "${_jailpath}"; then
error_exit "Failed to create mount point inside jail."
fi
fi
@@ -110,6 +110,7 @@ for _jail in ${JAILS}; do
fi
echo "Added: ${_fstab_entry}"
else
warn "Mountpoint already present in ${bastille_jailsdir}/${_jail}/fstab"
egrep "[[:blank:]]${_jailpath}[[:blank:]]" "${bastille_jailsdir}/${_jail}/fstab"
fi
mount -F "${bastille_jailsdir}/${_jail}/fstab" -a

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2020, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -47,6 +47,10 @@ fi
for _jail in ${JAILS}; do
info "[${_jail}]:"
jexec -l "${_jail}" /usr/sbin/pkg "$@"
if [ -f "/usr/sbin/pkg" ]; then
jexec -l "${_jail}" /usr/sbin/pkg "$@"
else
jexec -l "${_jail}" /usr/sbin/mport "$@"
fi
echo
done

View File

@@ -1,5 +1,8 @@
#!/bin/sh
#
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
@@ -29,7 +32,7 @@
. /usr/local/etc/bastille/bastille.conf
usage() {
error_exit "Usage: bastille rdr TARGET [clear] | [list] | [tcp <host_port> <jail_port>] | [udp <host_port> <jail_port>]"
error_exit "Usage: bastille rdr TARGET [clear|list|(tcp|udp host_port jail_port)]"
}
# Handle special-case commands first.
@@ -51,13 +54,13 @@ if [ "${TARGET}" = 'ALL' ]; then
error_exit "Can only redirect to a single jail."
fi
# Check jail name valid
# 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 jail ip4 address valid
# 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
@@ -65,17 +68,31 @@ if [ "$(bastille config $TARGET get vnet)" != 'enabled' ]; then
fi
fi
# Check rdr-anchor is setup in pf.conf
# 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 ext_if is setup in pf.conf
# Check if ext_if is defined in pf.conf
EXT_IF=$(grep '^[[:space:]]*ext_if[[:space:]]*=' /etc/pf.conf)
if [ -z "${JAIL_NAME}" ]; then
if [ -z "${EXT_IF}" ]; then
error_exit "ext_if not defined in pf.conf"
fi
# function: write rule to rdr.conf
persist_rdr_rule() {
if ! grep -qs "$1 $2 $3" "${bastille_jailsdir}/${JAIL_NAME}/rdr.conf"; then
echo "$1 $2 $3" >> "${bastille_jailsdir}/${JAIL_NAME}/rdr.conf"
fi
}
# function: load rdr rule via pfctl
load_rdr_rule() {
( pfctl -a "rdr/${JAIL_NAME}" -Psn;
printf '%s\nrdr pass on $ext_if inet proto %s to port %s -> %s port %s\n' "$EXT_IF" "$1" "$2" "$JAIL_IP" "$3" ) \
| pfctl -a "rdr/${JAIL_NAME}" -f-
}
while [ $# -gt 0 ]; do
case "$1" in
list)
@@ -86,22 +103,12 @@ while [ $# -gt 0 ]; do
pfctl -a "rdr/${JAIL_NAME}" -Fn
shift
;;
tcp)
tcp|udp)
if [ $# -lt 3 ]; then
usage
fi
( pfctl -a "rdr/${JAIL_NAME}" -Psn;
printf '%s\nrdr on $ext_if inet proto tcp to port %s -> %s port %s\n' "$EXT_IF" "$2" "$JAIL_IP" "$3" ) \
| pfctl -a "rdr/${JAIL_NAME}" -f-
shift 3
;;
udp)
if [ $# -lt 3 ]; then
usage
fi
( pfctl -a "rdr/${JAIL_NAME}" -Psn;
printf '%s\nrdr on $ext_if inet proto udp to port %s -> %s port %s\n' "$EXT_IF" "$2" "$JAIL_IP" "$3" ) \
| pfctl -a "rdr/${JAIL_NAME}" -f-
persist_rdr_rule $1 $2 $3
load_rdr_rule $1 $2 $3
shift 3
;;
*)

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2020, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -38,7 +38,9 @@ usage() {
validate_name() {
local NAME_VERIFY=${NEWNAME}
local NAME_SANITY=$(echo "${NAME_VERIFY}" | tr -c -d 'a-zA-Z0-9-_')
if [ "${NAME_VERIFY}" != "${NAME_SANITY}" ]; then
if [ -n "$(echo "${NAME_SANITY}" | awk "/^[-_].*$/" )" ]; then
error_exit "Container names may not begin with (-|_) characters!"
elif [ "${NAME_VERIFY}" != "${NAME_SANITY}" ]; then
error_exit "Container names may not contain special characters!"
fi
}

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2020, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2020, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -41,7 +41,7 @@ help|-h|--help)
;;
esac
if [ $# -ne 2 ]; then
if [ $# -lt 1 -o $# -gt 2 ]; then
usage
fi

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2020, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -83,6 +83,8 @@ for _jail in ${JAILS}; do
error_notify "Error: IP address (${ip}) already in use."
continue
fi
## add ip4.addr to firewall table:jails
pfctl -q -t jails -T add "${ip}"
fi
## start the container
@@ -102,13 +104,6 @@ for _jail in ${JAILS}; do
bastille rdr "${_jail}" ${_rules}
done < "${bastille_jailsdir}/${_jail}/rdr.conf"
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
echo
done

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2020, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -55,9 +55,12 @@ for _jail in ${JAILS}; do
pfctl -q -t jails -T delete "$(jls -j ${_jail} ip4.addr)"
fi
fi
if [ "$(bastille rdr ${_jail} list)" ]; then
bastille rdr ${_jail} clear
# Check if pfctl is present
if which -s pfctl; then
if [ "$(bastille rdr ${_jail} list)" ]; then
bastille rdr ${_jail} clear
fi
fi
## remove rctl limits

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2020, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2020, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -42,9 +42,6 @@ post_command_hook() {
case $_cmd in
rdr)
if ! grep -qs "${_args}" "${bastille_jailsdir}/${_jail}/rdr.conf"; then
echo "${_args}" >> "${bastille_jailsdir}/${_jail}/rdr.conf"
fi
echo -e ${_args}
esac
}
@@ -176,7 +173,7 @@ if [ "${TARGET}" = '--convert' ]; then
fi
case ${TEMPLATE} in
http?://github.com/*/*|http?://gitlab.com/*/*)
http?://*/*/*)
TEMPLATE_DIR=$(echo "${TEMPLATE}" | awk -F / '{ print $4 "/" $5 }')
if [ ! -d "${bastille_templatesdir}/${TEMPLATE_DIR}" ]; then
info "Bootstrapping ${TEMPLATE}..."

View File

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

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2020, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2020, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2020, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -32,7 +32,7 @@
. /usr/local/etc/bastille/bastille.conf
usage() {
error_exit "Usage: bastille update [release|container] | [option]"
error_exit "Usage: bastille update [release|container] | [force]"
}
# Handle special-case commands first.
@@ -64,6 +64,11 @@ if [ "${TARGET}" = "ALL" ]; then
error_exit "Batch upgrade is unsupported."
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
error_exit "Not yet supported on HardenedBSD."
fi

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2020, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -32,7 +32,7 @@
. /usr/local/etc/bastille/bastille.conf
usage() {
error_exit "Usage: bastille 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.
@@ -55,6 +55,11 @@ if [ "${TARGET}" = "ALL" ]; then
error_exit "Batch upgrade is unsupported."
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
error_exit "Not yet supported on HardenedBSD."
fi
@@ -91,7 +96,9 @@ release_upgrade() {
# Upgrade a release
if [ -d "${bastille_releasesdir}/${TARGET}" ]; then
release_check
freebsd-update ${OPTION} -b "${bastille_releasesdir}/${TARGET}" -r "${NEWRELEASE}" upgrade
env PAGER="/bin/cat" freebsd-update ${OPTION} --not-running-from-cron -b "${bastille_releasesdir}/${TARGET}" --currently-running "${TARGET}" -r "${NEWRELEASE}" upgrade
echo
echo -e "${COLOR_YELLOW}Please run 'bastille upgrade ${TARGET} install' to finish installing updates.${COLOR_RESET}"
else
error_exit "${TARGET} not found. See 'bastille bootstrap'."
fi
@@ -121,9 +128,22 @@ jail_updates_install() {
fi
}
release_updates_install() {
# Finish installing upgrade on a release
if [ -d "${bastille_releasesdir}/${TARGET}" ]; then
env PAGER="/bin/cat" freebsd-update ${OPTION} --not-running-from-cron -b "${bastille_releasesdir}/${TARGET}" install
else
error_exit "${TARGET} not found. See 'bastille bootstrap'."
fi
}
# Check what we should upgrade
if echo "${TARGET}" | grep -q "[0-9]\{2\}.[0-9]-RELEASE"; then
release_upgrade
if [ "${NEWRELEASE}" = "install" ]; then
release_updates_install
else
release_upgrade
fi
elif [ "${NEWRELEASE}" = "install" ]; then
jail_updates_install
else

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2020, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -36,6 +36,10 @@ bastille_usage() {
}
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
error_exit "Not yet supported on HardenedBSD."
fi
@@ -65,7 +69,7 @@ verify_template() {
echo
error_exit "Template validation failed."
## if INCLUDE; recursive verify
elif [ ${_hook} = 'INCLUDE' ]; then
elif [ "${_hook}" = 'INCLUDE' ]; then
info "[${_hook}]:"
cat "${_path}"
echo
@@ -73,7 +77,7 @@ verify_template() {
info "[${_hook}]:[${_include}]:"
case ${_include} in
http?://github.com/*/*|http?://gitlab.com/*/*)
http?://*/*/*)
bastille bootstrap "${_include}"
;;
*/*)
@@ -88,13 +92,13 @@ verify_template() {
done < "${_path}"
## if tree; tree -a bastille_template/_dir
elif [ ${_hook} = 'OVERLAY' ]; then
elif [ "${_hook}" = 'OVERLAY' ]; then
info "[${_hook}]:"
cat "${_path}"
echo
while read _dir; do
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}"
else
find "${_template_path}/${_dir}" -print | sed -e 's;[^/]*/;|___;g;s;___|; |;g'
@@ -110,7 +114,7 @@ verify_template() {
done
## remove bad templates
if [ ${_hook_validate} -lt 1 ]; then
if [ "${_hook_validate}" -lt 1 ]; then
error_notify "No valid template hooks found."
error_notify "Template discarded."
rm -rf "${bastille_template}"
@@ -118,7 +122,7 @@ verify_template() {
fi
## if validated; ready to use
if [ ${_hook_validate} -gt 0 ]; then
if [ "${_hook_validate}" -gt 0 ]; then
info "Template ready to use."
fi
}

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2018-2020, Christer Edwards <christer.edwards@gmail.com>
# Copyright (c) 2018-2021, Christer Edwards <christer.edwards@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without