From owner-freebsd-jail@freebsd.org Thu Jul 7 18:27:00 2016 Return-Path: Delivered-To: freebsd-jail@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5401BB75577 for ; Thu, 7 Jul 2016 18:27:00 +0000 (UTC) (envelope-from list1@gjunka.com) Received: from msa1.earth.yoonka.com (yoonka.com [185.24.122.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "msa1.earth.yoonka.com", Issuer "msa1.earth.yoonka.com" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 0AC761F2B for ; Thu, 7 Jul 2016 18:26:59 +0000 (UTC) (envelope-from list1@gjunka.com) Received: from crayon2.yoonka.com (crayon2.yoonka.com [10.70.7.20]) (authenticated bits=0) by msa1.earth.yoonka.com (8.15.2/8.15.2) with ESMTPSA id u67IQoDA064384 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO) for ; Thu, 7 Jul 2016 18:26:50 GMT (envelope-from list1@gjunka.com) Subject: Re: Effective rule sets in a jail? To: freebsd-jail@freebsd.org References: <2aeb6798-11ee-27c0-610a-d745aa322f97@gjunka.com> <577E0A78.1040600@quip.cz> <2c9d10fd-35ba-5470-026d-a1483e47fcf2@gjunka.com> <577E1AFB.90100@quip.cz> <6ccead58-a38a-80a4-b5b8-a509c4271b8f@gjunka.com> <577E29A8.5000504@quip.cz> <4d3f5584-7dd1-e6fc-540f-9ed3f1fb63f4@gjunka.com> <20160707153148.7da31609@eto-mona.office.smartweb.sk> From: Grzegorz Junka Message-ID: <8d24b89f-3a83-ac6b-5051-c50accb24e9d@gjunka.com> Date: Thu, 7 Jul 2016 18:26:50 +0000 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 MIME-Version: 1.0 In-Reply-To: <20160707153148.7da31609@eto-mona.office.smartweb.sk> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-jail@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Discussion about FreeBSD jail\(8\)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Jul 2016 18:27:00 -0000 On 07/07/2016 13:31, Martin "eto" Misuth wrote: > IMHO, regarding jails, better mental model would be like this: > - any single jail can have one and only one devfs ruleset number assigned > - however, different standalone jails can have different devfs ruleset > number assigned > - nested jails inherit ruleset number from their parent jail > > Regarding rulesets "inheritance"/"merging" you are probably looking into the > wrong place. devfs ruleset system is completely orthogonal to jails, as it > is used for other things as well. > > You can "merge" devfs rulesets in devfs /etc/devfs.rules. > > Look into /etc/defaults/devfs.rules how initial rulesets are built. > > First everything is hidden by ruleset 1 aka "devfsrules_hide_all". This is "by > default deny" policy, which should, according to me, used whenever one can. > > Then, new rulesets are created by unhiding various groups of devices. > Like for example you have minimal sub-ruleset 2 aka "devfsrules_unhide_basic". > That one is required to get minimal working /dev. Otherwise most programs break. > > Finally ruleset 4 aka "devfsrules_jail" is built, which can be used by jails. > > I personally "classify" jail types into groups. Let's call such group a jail > "class" (for the purpose of classification). > > Thus to get what you want, you should create custom ruleset per jail "class" and > assign it to your jails based on their "class". > > [devfsrules_jail_class_no_zfs=16] > add include $devfsrules_hide_all > add include $devfsrules_unhide_basic > add include $devfsrules_unhide_login > > Class might be not good word for this, as it is quite "loaded" by now, but I am > using it that way. > > Some jails might end up so special, they require completely fine tuned ruleset. > Those cannot be completely "classified" at all like this for example: > > [devfsrules_jail_proxy=333] > add include $devfsrules_hide_all > add include $devfsrules_unhide_basic > add include $devfsrules_unhide_login > add include $devfsrules_unhide_jail_proxy_tuns > > "devfsrules_unhide_jail_proxy_tuns" sub-rule in this case unhides > several tun interfaces used solely by this jail only. > > devfs.conf files are "parsed" by /etc/rc.d/devfs rc script which is run quite > early after boot. If you look at it you will see it is using /etc/rc.subr > devfs_* subroutines of rc.d framework which invoke /sbin/devfs helper program. > > Theoretically if /etc/rc.d/devfs and /etc/rc.subr are not enough for > you, you could write helper script to invoke /sbin/devfs to setup most > convoluted rule ids directly by hand. > > eto > _______________________________________________ > freebsd-jail@freebsd.org mailing list > https://lists.freebsd.org/mailman/listinfo/freebsd-jail > To unsubscribe, send any mail to "freebsd-jail-unsubscribe@freebsd.org" That's great! Thanks for the comprehensive explanation, I wish it was in the man already so I wouldn't need to enquiry additionally here. It makes sense, as I mentioned in my previous email, I got confused and messed jail inheritance with the inheritance of devfs rule sets, they are orthogonal as you stated. I amended my rules to include the basic ones from rule 4 to the more specific one for one particular jail and it works. Thanks again! Grzegorz