BastilleBSD Documentation

repository·master·Indexed 22 days ago

https://github.com/bastillebsd/bastille

An open-source system for automating the deployment and management of containerized applications on FreeBSD using jails. Bastille supports various jail types (vnet, bridged vnet, thin, thick, empty, clone, and Linux) and provides features for automation via templates, jail cloning, custom releases, and advanced networking including IPv6 and dynamic firewalls. It is written in Bourne Shell with zero external dependencies and offers full support for ZFS and PkgBase.

Tokens
59.7K
Snippets
226
Records
265
Agent score
75%

What's inside Bastille

  1. HardenedBSD and FreeBSD tool compatibility limitations

    master

    While Bastille supports mixing and matching different BSD distributions, users must be aware of tool dependencies:

    • HardenedBSD jails/releases require tools found specifically in the HardenedBSD base.
    • FreeBSD jails/releases require tools found specifically in the FreeBSD base.

    Users are responsible for ensuring the correct environment and tools are present when mixing distributions.

  2. Configure jail dependencies (Depend)

    master

    You can define dependencies between jails to ensure a specific startup and shutdown order. If jail1 depends on jail2, Bastille will verify that jail2 is running (starting it if necessary) before starting jail1.

    Startup Behavior: When starting jail1, Bastille checks its depend property. If jail2 is not running, it is started first.

    Shutdown Behavior: When stopping jail2, any jail that depends on it (e.g., jail1) will be stopped first.

    Note on Restarting: If you bastille restart jail2, any jail that depends on jail2 will be stopped, but it will not be automatically restarted, because jail2 does not depend on the dependent jail.

    Example: To make nextcloud depend on mariadb and nginx:

    bastille config nextcloud set depend "mariadb nginx"
  3. Understand kernel securelevels in Bastille

    master

    Bastille containers run at securelevel = 2 by default. The securelevel determines the restrictions placed on the kernel to prevent tampering.

    Security Levels:

    • -1 (Default initial): Permanently insecure mode.
    • 0: Insecure mode. Immutable/append-only flags can be turned off.
    • 1: Secure mode. System immutable/append-only flags cannot be turned off; kernel modules cannot be loaded/unloaded; /dev/mem and /dev/kmem cannot be opened for writing.
    • 2 (Bastille Default): Highly secure mode. Adds restrictions where disks may not be opened for writing (except by mount(2)), preventing tampering via unmounting. Time changes are also clamped to $\le 1$ second.
    • 3: Network secure mode. Adds restrictions where IP packet filter rules and dummynet/pf configurations cannot be adjusted.

    Note: Bastille does not automate securelevel changes. It is recommended to leave this at the default 2 and only change it manually on a case-by-case basis.

  4. Configure a Bastille template structure

    master

    To create a valid Bastille template, you must organize your files in a directory structure where a Bastillefile is present at the root of the template path.

    Required Structure:

    • project/template/Bastillefile

    The Bastillefile is where you define the template hooks (see the 'Template' documentation for supported hooks).

  5. How to target jails and releases in Bastille

    master

    Bastille uses a subcommand TARGET ARGS syntax. Every command requires a target, which is typically a jail or a release.

    Targeting Jails

    You can target a jail using any of the following:

    • The exact jail name.
    • The Jail ID (JID).
    • A tag assigned to the jail.
    • The starting few characters of a jail name.

    Note on Tags: If you use a tag as the TARGET, Bastille targets all jails with that tag. However, if a jail exists with the exact same name as the tag, Bastille will target that specific jail instead of the tag.

    Targeting Releases

    To target a release, provide the exact release name. Do not include the point-release version (e.g., use 13.2-RELEASE, not 13.2-RELEASE-pX).

    Targeting Multiple Jails

    • All running jails: Use the keyword ALL or all.
    • Specific groups: You can group multiple jails by enclosing them in quotes.
    # Target all running jails
    bastille cmd all "sockstat -4"
    
    # Target multiple specific jails
    bastille cmd "jail1 jail2 jail3" echo Hello!
    
    # Target a release
    bastille bootstrap 13.2-RELEASE
  6. How interface types behave in classic vs VNET jails

    master

    The behavior of adding an interface depends on whether the jail is a classic jail or a VNET jail:

    • Classic Jails: You can add an interface multiple times as long as you provide a different IP each time. This adds the IP as an alias on that interface.
    • VNET Jails:
      • You can add a physical interface using -V or --vnet.
      • You can add a bridge interface using -B or --bridge.
      • If you use the -v | --vlan <VLANID> switch, Bastille will add the VLAN ID to the jail as a vnetX.X interface (where X is the specified interface).
      • You can use -M | --static-mac to ensure a persistent MAC address.
  7. Understand Bastille Jail Network Modes

    master

    Bastille supports several networking modes depending on whether you are using standard jails or VNET jails (created with -V or --vnet).

    VNET Modes

    • VNET (-V): Bastille creates a bridge interface (e.g., em0bridge) and attaches the jail to it using host/jail epairs. This makes the jail appear as a physical device on your local network with its own MAC address and IP.
    • Bridged VNET (-B): Identical to VNET, but you must manually create the bridge interface first. Bastille will then attach the host/jail epairs to your existing bridge.

    Standard (Non-VNET) Modes

    • Alias/Shared Interface: The jail's IP is added as an alias to the specified host interface. The jail shares the host's MAC address but has its own IP within the local subnet.
    • NAT/Loopback Interface: Used for IPs not reachable in the local subnet. Bastille adds the IP as an alias and updates the pf firewall table to allow outbound access. If no interface is specified, Bastille attempts to use bastille0 (created via bastille setup).
    • Inherit: The jail inherits the entire host network stack. The configuration is set to ip4=inherit.
    • IP Hostname: An advanced mode where the jail uses the IP addresses associated with its hostname. This follows standard FreeBSD jail(8) behavior.
    # Example: Creating a VNET jail
    bastille create myjail 13.2-RELEASE -V 192.168.1.50/24 vtnet0
  8. Understand Bastille terminology: Containers vs Jails

    master
    In Bastille documentation and usage, the terms container and jail are used interchangeably. Both terms refer specifically to a FreeBSD jail. You can treat them as synonymous when following guides or executing commands.
  9. Network interface limitations when cloning vnet jails

    master

    When cloning a vnet jail that has multiple network interfaces, Bastille applies specific networking constraints to prevent IP conflicts between the original jail and the new clone:

    1. The default interface of the cloned jail is assigned the IP address provided in the bastille clone command.
    2. All additional interfaces will have their network information cleared (set to ifconfig_inet="").
  10. Advanced Port Redirection (RDR) syntax

    master

    The RDR hook supports two modes of port redirection:

    1. Simple: tcp hostport jailport (e.g., tcp 2200 22 forwards host port 2200 to jail port 22).
    2. Advanced: [ipv4|ip46|dual] interface source-ip dest-ip proto hostport jailport.

    Example of Advanced RDR: RDR ipv4 vtnet0 192.168.0.1 any tcp 2022 22 This forwards port 22 in the jail to port 2022 on the host, but only for connections originating from 192.168.0.1 on interface vtnet0.

    RDR ipv4 vtnet0 192.168.0.1 any tcp 2022 22
  11. Create different types of jails

    master

    Bastille supports several jail types depending on how they interact with the bootstrapped release:

    • Thin jails (Default): Lightweight jails that use symlinks to the bootstrapped release. They are created quickly.
    • Thick jails (--thick or -T): These copy the entire release into the jail, making the jail a completely independent, full BSD install.
    • Clone jails (--clone or -C): Clones of the bootstrapped release. Note that changes to the release will affect these jails.
    • Empty jails (--empty or -E): Creates a completely empty jail. Use with caution.
    • Linux jails (--linux or -L): Jails that run Linux instead of BSD.
  12. Understand loopback vs shared networking limitations

    master

    When configuring default interfaces for jails (used when the interface is not explicitly provided during the create command), you must choose between loopback and shared networking.

    Key Constraints:

    • Mutual Exclusivity: You CANNOT run both loopback and shared interfaces. Configuring one will disable the other.
    • Loopback: The default option. It creates a bastille0 loopback interface (lo) that jails link to. It is the simplest networking option and is not attached to a specific physical interface.
    • Shared: Used when you want jails to link to an actual, specific physical interface rather than a loopback interface.
    • Override Behavior: If you specify an interface explicitly during the create command, these setup options (loopback or shared) have no effect; the specified interface will be used instead.