Create a Jail

From HateotU

Create a Jail

Replace <jailname> with the Name of your Jail

Create ZFS Pool

  • Create a new zfs pool
zfs create zfs0/<jailname>
  • Set the mountpoint option for the new zfs pool
zfs set mountpoint=/export/jails/<jailname> zfs0/<jailname>
  • Mount the new Pool
zfs mount -a

If You're not using ZFS, creat a new Folder

mkdir /export/jails/<jailname>

Install the Jail

cd /export/jails/
bsdinstall jail <jailname>/
  • Follow the steps on the screen until the installation is finished

/etc/jail.conf

vi /etc/jail.conf
  • If there are already Jails installed at the host, create a new section for your Jail at the End of the file
<jailname> {
        host.hostname = "<jailname>.hateotu.de";
        ip4.addr = <ip the new Jail should have>;
}
  • If there are no Jails installed, and so, the file is empty, paste the following content into the file
allow.raw_sockets = 0;
exec.clean;
exec.system_user = "root";
exec.jail_user = "root";
exec.start += "/bin/sh /etc/rc";
exec.stop = "/bin/sh /etc/rc.shutdown";
exec.consolelog = "/var/log/jail_${name}_console.log";
interface="bge0";
mount.devfs;
mount.fstab = "/etc/fstab.$name";
allow.mount;
allow.set_hostname = 0;
allow.sysvipc = 0;
path = "/export/jails/${name}";
<jailname> {
        host.hostname = "<jailname>.hateotu.de";
        ip4.addr = <ip the new Jail should have>;
}
  • If the Jail needs special options to be set, you should enter them into the section of the Jail under the IP Adress:
<jailname> {
        host.hostname = "<jailname>.hateotu.de";
        ip4.addr = <ip the new Jail should have>;
        <option> = <value>
}

Get things ready

  • Create a fstab file for the Jail
touch /etc/fstab.<jailname>

Work with the Jail

  • To start the Jail, type
service jail start <jailname>
  • To stop the Jail, type
service jail stop <jailname>
  • To restart the Jail, type
service jail restart <jailname>
  • To open a shell on your Jail, type:
jexec <jailname> <shell>

Die Jail als Saltstack-Minion einrichten

  • Saltstack aus den Paketquellen installieren
pkg install py27-salt
  • Konfigurations-Datei erstellen (Beispiel-Datei als Konfigurationsdatei verwenden)
cp /usr/local/etc/salt/minion.sample /usr/local/etc/salt/minion
  • Den salt_minion service aktivieren, dazu folgende Zeile in /etc/rc.conf ergänzen:
salt_minion_enable="YES"
  • Die IP des Saltstack-Masters in /usr/local/etc/salt/minion eintragen, Dazu die kommentierte Zeile "#master 0.0.0.0" durch folgende Zeile ersetzen:
master: 10.204.3.219
  • Den salt_minion service starten
service salt_minion start
  • Nun den Fingerpring des aktuellen minions anzeigen
salt-call --local key.finger
  • Auf dem Saltstack-Master (saltstack.hateotu.de) anmelden
  • Den Befehl
salt-key -L

ausführen, um eine Liste aller Hosts, die der Master kennt zu erhalten. Dort sollte nun der Hostname des neu eingerichteten Clients unter "Unaccepted Keys" auftauchen (sollte der einzige noch nicht akzeptierte Host sein).

  • Den Fingerprint des Hosts überprüfen:
salt-key -F master
  • Der bei dem Host angezeigte Fingerprint muss mit dem Fingerprint des Minions übereinstimmen.
  • Den Host hinzufügen
salt-key -A
  • Dann bestätigen, dass es sich tatsächlich um den richtigen Host handelt
  • Noch einmal schauen, ob der Host akzeptiert ist:
salt-key -L
  • Nun sollte der Host unter "Accepted Keys" stehen.
  • Abschließend wird noch getestet, ob der Master Befehle auf dem Minion ausführen kann. Dafür einfach folgenden Befehl auf dem Master ausführen:
salt <hostname> test.ping
  • Um die Änderungen auf alle Clients (Minions) zu übernehmen, muss folgender Befehl ausgeführt werden:
salt -b 1 '*' state.apply

Einen DNS-Eintrag anlegen

Nach erfolgreicher Installation sollte auf https://incognito.hateotu.de ein DNS-Eintrag für den FQDN der neuen Jail angelegt werden. Dafür muss das Menü "Services" -> "DNS Resolver" geöffnet werden. Dort dann unter "Host Overrides" auf "Add" klicken. Im nun aufgehenden Dialog den Hostname der Jail angeben (ohne hateotu.de). Also Domain hateotu.de verwendet. Dann die IP der Jail angeben (vorher in /etc/jail.conf konfiguriert). Nachdem die Einträge abgeschlossen sind, muss noch gespeichert werden. Danach den Dienst neu starten (pfsense weist darauf hin), und der neue Eintrag ist verfügbar.