2018-11-24 20:07:20 -07:00
|
|
|
========
|
|
|
|
|
Template
|
|
|
|
|
========
|
2023-02-25 00:37:46 -08:00
|
|
|
Looking for ready made CI/CD validated `Bastille Templates`_?
|
2018-11-24 20:07:20 -07:00
|
|
|
|
|
|
|
|
Bastille supports a templating system allowing you to apply files, pkgs and
|
2019-11-20 19:16:21 -07:00
|
|
|
execute commands inside the containers automatically.
|
2018-11-24 20:07:20 -07:00
|
|
|
|
2021-07-14 15:49:12 -06:00
|
|
|
Currently supported template hooks are: `CMD`, `CP`, `INCLUDE`, `LIMITS`, `MOUNT`,
|
|
|
|
|
`PKG`, `RDR`, `SERVICE`, `SYSRC`.
|
2018-11-24 20:07:20 -07:00
|
|
|
|
|
|
|
|
Templates are created in `${bastille_prefix}/templates` and can leverage any of
|
2020-07-13 19:27:23 -06:00
|
|
|
the template hooks.
|
2018-11-24 20:07:20 -07:00
|
|
|
|
2021-07-14 15:49:12 -06:00
|
|
|
Bastille 0.7.x+
|
|
|
|
|
---------------
|
2020-07-13 19:27:23 -06:00
|
|
|
Bastille 0.7.x introduces a template syntax that is more flexible and allows
|
|
|
|
|
any-order scripting. Previous versions had a hard template execution order and
|
|
|
|
|
instructions were spread across multiple files. The new syntax is done in a
|
|
|
|
|
`Bastillefile` and the template hook (see below) files are replaced with
|
|
|
|
|
template hook commands.
|
2018-11-24 20:07:20 -07:00
|
|
|
|
2020-07-13 19:27:23 -06:00
|
|
|
Template Automation Hooks
|
|
|
|
|
-------------------------
|
2018-11-24 20:07:20 -07:00
|
|
|
|
2020-01-26 12:43:45 -07:00
|
|
|
+---------+-------------------+-----------------------------------------+
|
|
|
|
|
| HOOK | format | example |
|
|
|
|
|
+=========+===================+=========================================+
|
2021-07-14 15:49:12 -06:00
|
|
|
| CMD | /bin/sh command | /usr/bin/chsh -s /usr/local/bin/zsh |
|
|
|
|
|
+---------+-------------------+-----------------------------------------+
|
|
|
|
|
| CP | path(s) | etc root usr (one per line) |
|
2020-01-26 12:43:45 -07:00
|
|
|
+---------+-------------------+-----------------------------------------+
|
|
|
|
|
| INCLUDE | template path/URL | http?://TEMPLATE_URL or project/path |
|
|
|
|
|
+---------+-------------------+-----------------------------------------+
|
2021-07-14 15:49:12 -06:00
|
|
|
| LIMITS | resource value | memoryuse 1G |
|
2020-01-26 12:43:45 -07:00
|
|
|
+---------+-------------------+-----------------------------------------+
|
2021-07-14 15:49:12 -06:00
|
|
|
| MOUNT | fstab syntax | /host/path container/path nullfs ro 0 0 |
|
2020-01-26 12:43:45 -07:00
|
|
|
+---------+-------------------+-----------------------------------------+
|
|
|
|
|
| PKG | port/pkg name(s) | vim-console zsh git-lite tree htop |
|
|
|
|
|
+---------+-------------------+-----------------------------------------+
|
2021-07-14 15:49:12 -06:00
|
|
|
| RDR | tcp port port | tcp 2200 22 (hostport jailport) |
|
2020-01-26 12:43:45 -07:00
|
|
|
+---------+-------------------+-----------------------------------------+
|
|
|
|
|
| SERVICE | service command | 'nginx start' OR 'postfix reload' |
|
|
|
|
|
+---------+-------------------+-----------------------------------------+
|
2021-07-14 15:49:12 -06:00
|
|
|
| SYSRC | sysrc command(s) | nginx_enable=YES |
|
2020-01-26 12:43:45 -07:00
|
|
|
+---------+-------------------+-----------------------------------------+
|
2018-11-24 20:07:20 -07:00
|
|
|
|
2020-01-26 15:18:29 +01:00
|
|
|
Note: SYSRC requires that NO quotes be used or that quotes (`"`) be escaped
|
|
|
|
|
ie; (`\\"`)
|
2018-11-24 20:07:20 -07:00
|
|
|
|
2020-07-13 19:27:23 -06:00
|
|
|
Place these uppercase template hook commands into a `Bastillefile` in any order
|
|
|
|
|
and automate container setup as needed.
|
|
|
|
|
|
2018-11-24 20:07:20 -07:00
|
|
|
In addition to supporting template hooks, Bastille supports overlaying
|
2019-11-20 19:16:21 -07:00
|
|
|
files into the container. This is done by placing the files in their full path,
|
2018-11-24 20:07:20 -07:00
|
|
|
using the template directory as "/".
|
|
|
|
|
|
2020-07-13 19:27:23 -06:00
|
|
|
An example here may help. Think of `bastille/templates/username/template`, our
|
2019-11-20 18:54:05 -07:00
|
|
|
example template, as the root of our filesystem overlay. If you create an
|
2020-07-13 19:27:23 -06:00
|
|
|
`etc/hosts` or `etc/resolv.conf` *inside* the template directory, these
|
2019-11-20 19:16:21 -07:00
|
|
|
can be overlayed into your container.
|
2018-11-24 20:07:20 -07:00
|
|
|
|
|
|
|
|
Note: due to the way FreeBSD segregates user-space, the majority of your
|
|
|
|
|
overlayed template files will be in `usr/local`. The few general
|
|
|
|
|
exceptions are the `etc/hosts`, `etc/resolv.conf`, and
|
|
|
|
|
`etc/rc.conf.local`.
|
|
|
|
|
|
2020-01-26 12:43:45 -07:00
|
|
|
After populating `usr/local` with custom config files that your container will
|
2019-11-20 18:54:05 -07:00
|
|
|
use, be sure to include `usr` in the template OVERLAY definition. eg;
|
2018-11-24 20:07:20 -07:00
|
|
|
|
|
|
|
|
.. code-block:: shell
|
|
|
|
|
|
2023-10-25 10:30:00 +02:00
|
|
|
echo "CP usr /" >> /usr/local/bastille/templates/username/template/Bastillefile
|
2018-11-24 20:07:20 -07:00
|
|
|
|
2020-01-26 12:43:45 -07:00
|
|
|
The above example "usr" will include anything under "usr" inside the template.
|
|
|
|
|
You do not need to list individual files. Just include the top-level directory
|
|
|
|
|
name. List these top-level directories one per line.
|
2018-11-24 20:07:20 -07:00
|
|
|
|
|
|
|
|
Applying Templates
|
|
|
|
|
------------------
|
|
|
|
|
|
2019-11-20 19:16:21 -07:00
|
|
|
Containers must be running to apply templates.
|
2018-11-24 20:07:20 -07:00
|
|
|
|
|
|
|
|
Bastille includes a `template` command. This command requires a target and a
|
|
|
|
|
template name. As covered in the previous section, template names correspond to
|
|
|
|
|
directory names in the `bastille/templates` directory.
|
|
|
|
|
|
|
|
|
|
.. code-block:: shell
|
|
|
|
|
|
2020-07-13 19:27:23 -06:00
|
|
|
ishmael ~ # bastille template ALL username/template
|
2019-11-20 18:54:05 -07:00
|
|
|
[proxy01]:
|
2018-11-24 20:07:20 -07:00
|
|
|
Copying files...
|
|
|
|
|
Copy complete.
|
|
|
|
|
Installing packages.
|
|
|
|
|
pkg already bootstrapped at /usr/local/sbin/pkg
|
|
|
|
|
vulnxml file up-to-date
|
|
|
|
|
0 problem(s) in the installed packages found.
|
2019-11-20 18:54:05 -07:00
|
|
|
Updating bastillebsd.org repository catalogue...
|
2018-11-24 20:07:20 -07:00
|
|
|
[cdn] Fetching meta.txz: 100% 560 B 0.6kB/s 00:01
|
|
|
|
|
[cdn] Fetching packagesite.txz: 100% 121 KiB 124.3kB/s 00:01
|
|
|
|
|
Processing entries: 100%
|
2019-11-20 18:54:05 -07:00
|
|
|
bastillebsd.org repository update completed. 499 packages processed.
|
2018-11-24 20:07:20 -07:00
|
|
|
All repositories are up to date.
|
|
|
|
|
Checking integrity... done (0 conflicting)
|
|
|
|
|
The most recent version of packages are already installed
|
|
|
|
|
Updating services.
|
|
|
|
|
cron_flags: -J 60 -> -J 60
|
|
|
|
|
sendmail_enable: NONE -> NONE
|
|
|
|
|
syslogd_flags: -ss -> -ss
|
|
|
|
|
Executing final command(s).
|
|
|
|
|
chsh: user information updated
|
|
|
|
|
Template Complete.
|
2020-04-14 11:52:29 +02:00
|
|
|
|
2019-11-20 18:54:05 -07:00
|
|
|
[web01]:
|
2018-11-24 20:07:20 -07:00
|
|
|
Copying files...
|
|
|
|
|
Copy complete.
|
|
|
|
|
Installing packages.
|
|
|
|
|
pkg already bootstrapped at /usr/local/sbin/pkg
|
|
|
|
|
vulnxml file up-to-date
|
|
|
|
|
0 problem(s) in the installed packages found.
|
2019-11-20 18:54:05 -07:00
|
|
|
Updating pkg.bastillebsd.org repository catalogue...
|
2018-11-24 20:07:20 -07:00
|
|
|
[poudriere] Fetching meta.txz: 100% 560 B 0.6kB/s 00:01
|
|
|
|
|
[poudriere] Fetching packagesite.txz: 100% 121 KiB 124.3kB/s 00:01
|
|
|
|
|
Processing entries: 100%
|
2019-11-20 18:54:05 -07:00
|
|
|
pkg.bastillebsd.org repository update completed. 499 packages processed.
|
|
|
|
|
Updating bastillebsd.org repository catalogue...
|
2018-11-24 20:07:20 -07:00
|
|
|
[poudriere] Fetching meta.txz: 100% 560 B 0.6kB/s 00:01
|
|
|
|
|
[poudriere] Fetching packagesite.txz: 100% 121 KiB 124.3kB/s 00:01
|
|
|
|
|
Processing entries: 100%
|
2019-11-20 18:54:05 -07:00
|
|
|
bastillebsd.org repository update completed. 499 packages processed.
|
2018-11-24 20:07:20 -07:00
|
|
|
All repositories are up to date.
|
|
|
|
|
Checking integrity... done (0 conflicting)
|
|
|
|
|
The most recent version of packages are already installed
|
|
|
|
|
Updating services.
|
|
|
|
|
cron_flags: -J 60 -> -J 60
|
|
|
|
|
sendmail_enable: NONE -> NONE
|
|
|
|
|
syslogd_flags: -ss -> -ss
|
|
|
|
|
Executing final command(s).
|
|
|
|
|
chsh: user information updated
|
|
|
|
|
Template Complete.
|
2023-02-25 00:37:46 -08:00
|
|
|
|
|
|
|
|
.. _Bastille Templates: https://gitlab.com/BastilleBSD-Templates
|