jails mount devfs with ruleset inside jail (podman in jail)

The OCI Containers chapter, podman with JAIL, and jail with mount.devfs inside jail posts were helpful in getting podman installed inside a jail, but haven't been enough to get it working.

I'm trying to spawn a FreeBSD container from within a jail:

Code:
# podman run -it --rm ghcr.io/freebsd/freebsd-notoolchain:15.1
Error: ocijail: mounting {"destination":"/dev","options":["ruleset=4"],"source":"devfs","type":"devfs"}: Operation not permitted: OCI permission denied

This does not appear to be an ocijail problem, I can replicate this attempting to mount devfs with a ruleset from within the jail:

Code:
# mkdir tmp
# mount -t devfs -o ruleset=4 devfs tmp
mount: devfs: Operation not permitted
# mount | grep tmp
#

Without -o ruleset=4 works:

Code:
# mount -t devfs devfs tmp
# mount | grep tmp
devfs on /root/tmp (devfs)

My jail.conf (originally Bastille-configured):

Code:
forgejorunner {
  enforce_statfs = 1;
  devfs_ruleset = 13;
  exec.clean;
  exec.consolelog = /var/log/bastille/forgejorunner_console.log;
  host.hostname = forgejorunner;
  mount.devfs;
  mount.fstab = /usr/local/bastille/jails/forgejorunner/fstab;
  path = /usr/local/bastille/jails/forgejorunner/root;
  securelevel = 1;
  children.max = 10;
  osrelease = "15.1-RELEASE-p4";

  vnet;
  vnet.interface = e0b_fjrun;

  exec.created += "zfs jail forgejorunner zroot/data/forgejo-runner";

  exec.prestart += "epair0=\$(ifconfig epair create) && ifconfig \${epair0} up name e0a_fjrun && ifconfig \${epair0%a}b up name e0b_fjrun";
  exec.prestart += "ifconfig vm-public addm e0a_fjrun";
  exec.prestart += "ifconfig e0a_fjrun ether 58:9c:fc:e9:7e:9a";
  exec.prestart += "ifconfig e0b_fjrun ether 58:9c:fc:e9:7e:9b";
  exec.prestart += "ifconfig e0a_fjrun description \"vnet0 host interface for Bastille jail forgejorunner\"";

  exec.start = '/bin/sh /etc/rc';

  exec.stop = '/bin/sh /etc/rc.shutdown';

  exec.poststop += "ifconfig e0a_fjrun destroy";

  exec.release += "zfs unjail forgejorunner zroot/data/forgejo-runner";

  allow.chflags;
  allow.extattr;
  allow.mount;
  allow.mount.devfs;
  allow.mount.fdescfs;
  allow.mount.linprocfs;
  allow.mount.linsysfs;
  allow.mount.nullfs;
  allow.mount.procfs;
  allow.mount.tmpfs;
  allow.mount.zfs;
  allow.raw_sockets;
  allow.socket_af;
  allow.sysvipc;
}

devfs ruleset 13:

Code:
[bastille_vnet=13]
add include $devfsrules_hide_all
add include $devfsrules_unhide_basic
add include $devfsrules_unhide_login
add include $devfsrules_jail
add include $devfsrules_jail_vnet
add path 'bpf*' unhide
add path 'tun*' unhide
add path 'tailscale*' unhide

Setting the forgejorunner jail's devfs ruleset to 0 did not help, nor did further reducing securelevel not enforce_statfs
 
Digging around in the devfs source and I can mount devfs with a ruleset that matches the jail's ruleset:

Code:
# mount -t devfs -o ruleset=13 devfs tmp
# mount | grep tmp
devfs on /root/tmp (devfs)

(Since two rulesets could be vastly different I understand the reason for this restriction)
 
I found --privileged can work around the apparently-static ruleset:

Code:
# podman run --privileged -it --rm ghcr.io/freebsd/freebsd-notoolchain:15.1
# hostname
569fbc186d10
 
Keep in mind --privileged also skips the ruleset completely, so the container gets the jail's whole /dev. For a Forgejo runner that executes other people's workflows that's worth thinking twice about.
 
Back
Top