bsdci / libioc

A Python library to manage jails with ioc{age,ell}
https://bsd.ci/libioc
Other
38 stars 11 forks source link

warn when interfaces is set with the wrong format #550

Open igalic opened 6 years ago

igalic commented 6 years ago

when creating a vnet jail, it expects interfaces to be set to a specific format: interfaces="vnet0:bridge0"

failing to do so, will ensure that the jail doesn't start, but it also doesn't tell us why! it's very easy to accidentally, or intuitively! reverse this notation

there's no clue as to what is wrong, barely a hint, even starting the jail with -d spam

gronke commented 6 years ago

libiocage cannot do much about checking existence of interfaces or their order, because:

When it comes to invalid configuration, libiocage already does validate the inputs:

# ioc set interfaces="INVALID" myjail 
Invalid value for property 'interfaces' of jail myjail: Invalid NIC pair (should be <nic>:<bridge>)
Invalid value for property 'interfaces': 

Surprisingly the error message appears twice, which needs to be fixed.

igalic commented 6 years ago

this makes sense!

you can create a jail with an interfaces that doesn't exist! after all, vnet0 is just a name, and it's created on the fly

however, you cannot start the jail without the bridge existing, so we should check if the bridge that was passed to interfaces exists before startup, or else, fail with a better error

igalic commented 6 years ago
root@container-host1 /u/l/s/libiocage# ioc create better-error vnet=yes interfaces=bridge0:vnet0 ip4_addr='vnet0|dhcp'
better-error successfully created from 11.2-RELEASE!
root@container-host1 /u/l/s/libiocage# ioc start better-error
[+] JailResolverConfig: OK [0.005s]
[-] JailLaunch@better-error: FAILED [1.123s]
Launching jail better-error failed
Destroying jail better-error failed
root@container-host1 /u/l/s/libiocage# 

the same thing ran with -d spam

/etc/rc.conf was read from /etc/rc.conf
Updated /etc/rc.conf data from /etc/rc.conf
Querying all running jails status
Configuring nameserver for Jail 'better-error'
[-] JailResolverConfig: ...
resolv.conf copied from host


[+] JailResolverConfig: OK [0.005s]

Starting VNET/VIMAGE
no static routes configured
[-] JailLaunch@better-error: ...
/etc/rc.conf was read from /jails/jails/better-error/root/etc/rc.conf
Updated /etc/rc.conf data from /jails/jails/better-error/root/etc/rc.conf
/etc/rc.conf was not modified - skipping write
Setting fstab auto-creation placeholder
fstab loaded from /jails/jails/better-error/fstab
Setting fstab auto-creation placeholder
fstab loaded from /jails/jails/better-error/fstab
/jails/jails/better-error/fstab written
Clearing resource limits
Reading devfs.rules from /etc/devfs.rules
Executing (interactive): /usr/sbin/jail -c vnet name=default-better-error host.hostname=better-error host.domainname=local path=/jails/jails/better-error/root securelevel=2 host.hostuuid=better-error devfs_ruleset=6 enforce_statfs=2 children.max=0 allow.set_hostname=1 allow.sysvipc=0 exec.prestart="/jails/jails/better-error/launch-scripts/prestart.sh" exec.prestop="/jails/jails/better-error/launch-scripts/prestop.sh" exec.poststop="/jails/jails/better-error/launch-scripts/poststop.sh" exec.jail_user=root sysvmsg=new sysvsem=new sysvshm=new allow.raw_sockets=0 allow.chflags=0 allow.mount=0 allow.mount.devfs=0 allow.mount.nullfs=0 allow.mount.procfs=0 allow.mount.fdescfs=0 allow.mount.zfs=0 allow.quotas=0 allow.socket_af=0 exec.timeout=600 stop.timeout=30 mount.fstab=/jails/jails/better-error/fstab mount.devfs=1 mount.fdescfs=0 allow.mount.tmpfs=0 allow.dying persist exec.poststart="/jails/jails/better-error/launch-scripts/poststart.sh"
  running exec.created hook on the host
  ifconfig: interface vnet0 does not exist
  jail: /bin/sh -c "/jails/jails/better-error/launch-scripts/poststart.sh": failed
Jail 'better-error' was not started
Launching jail better-error failed
Clearing resource limits
Writing jail.conf file to /jails/jails/better-error/launch-scripts/jail.conf
Executing (interactive): /usr/sbin/jail -v -r -f /jails/jails/better-error/launch-scripts/jail.conf default-better-error
  jail: "default-better-error" not found
Destroying jail better-error failed
Manually executing prestop and poststop hooks


[-] JailLaunch@better-error: FAILED [1.154s]

and here's the error we're looking for:

 ifconfig: interface vnet0 does not exist
gronke commented 6 years ago

So we can improve the error message here. For instance we could implement explicit handling of stderr output in an additional thread, so that the error can be reasonably parsed and further explained to the user. If this output is seen, we could say things like:

The bridge 'vnet0' does not exist on this host. It was configured in the 'myjail' jail's interface config property value 'bridge0:vnet0'.

or even

The bridge 'vnet0' does not exist on this host. It was configured in the 'myjail' jail's interface config property value 'bridge0:vnet0'. The device 'bridge0' exists on this hosts, so maybe the order ':' was swapped.

I would not like to introduce an early check for this occasion, because a failure can be fixed once, while the code would become more complex (and slower) when mitigating the issue early on.

igalic commented 6 years ago

yeah

we need to do better, wrt error messages. both of these would be an excellent step forward!

so, yeah, i guess we finally should start catching both, stdout and stderr

igalic commented 5 years ago

could this now (partially) be fixed with #589?