go-freebsd-jail
FreeBSD jail management for Go with native libjail bindings — create, update, remove, list, exec, VNET networking and jail.conf parsing.
Why
Manage jails from Go through jail_set(2), jail_get(2) and jail_remove(2) instead of driving jail(8) — with an idempotent CreateOrUpdate for declarative, reconcile-style management.
How
- A small C shim over libjail’s
jailparam_*API returns the jail id, errno and libjail’s error message together, so nothing is lost crossing the cgo boundary. - Go config structs become a flat parameter list; reserved parameters can’t be overridden through raw params, and input is validated before any syscall.
execdeliberately shells out tojexecinstead of callingjail_attachin-process — attaching a multithreaded Go runtime to a jail isn’t safe.- The
vnetpackage uses go-freebsd-ifc to build the epair and bridge on the host;jailconfrenders and parsesjail.conf. - Sentinel errors plus structured operation and validation errors. Builds on any OS — non-FreeBSD stubs return
ErrNotSupported. End-to-end tests run as root using/rescueas a minimal jail root.
jid, err := jail.Create(jail.Config{
Name: "web", Path: "/jails/web", Hostname: "web.local", Persist: true,
VNET: true, VNETInterface: []string{"epair0b"},
})
$ git clone https://github.com/zombocoder/go-freebsd-jail← all projects