Introduce a branded zone as a testing aid
authorDanek Duvall <danek.duvall@sun.com>
Wed, 05 Sep 2007 15:23:09 -0700
changeset 97 9a488b15900f
parent 96 1b7002fbb8b7
child 98 2ac7781efe22
Introduce a branded zone as a testing aid
src/Makefile
src/brand/Makefile
src/brand/SUNWipkg.xml
src/brand/config.xml
src/brand/pkgcreatezone
src/brand/platform.xml
--- a/src/Makefile	Wed Sep 05 15:23:08 2007 -0700
+++ b/src/Makefile	Wed Sep 05 15:23:09 2007 -0700
@@ -144,6 +144,7 @@
 	$(ROOTPYBUNDLEMODS)
 
 all := TARGET = all
+link := TARGET = link
 
 all: $(PROGS) binary-modules
 
@@ -166,6 +167,7 @@
 	ln -s $(PWD)/publish.py /usr/bin/pkgsend
 	ln -s $(PWD)/depot.py /usr/lib/pkg.depotd
 	ln -s $(PWD)/modules /usr/lib/python2.4/vendor-packages/pkg
+	@cd brand; pwd; $(MAKE) $(TARGET)
 
 # Invoke all known modules with tests.
 # XXX Invoke the bundle tests.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/brand/Makefile	Wed Sep 05 15:23:09 2007 -0700
@@ -0,0 +1,71 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+
+
+MACH:sh = uname -p
+
+PYTHON = /usr/bin/python
+
+ROOT = ../../proto/root_${MACH}
+ROOTUSRLIB = $(ROOT)/usr/lib
+ROOTBRAND = $(ROOTUSRLIB)/brand
+ROOTBRANDPKG = $(ROOTBRAND)/ipkg
+
+LINKBRANDPKG = /usr/lib/brand/ipkg
+
+ROOTDIRS = \
+	$(ROOT) \
+	$(ROOTUSRLIB) \
+	$(ROOTBRAND) \
+	$(ROOTBRANDPKG)
+
+ROOTFILES = \
+	$(ROOTBRANDPKG)/config.xml \
+	$(ROOTBRANDPKG)/platform.xml
+
+all := TARGET = all
+
+all:
+
+clean:
+
+clobber: clean
+	rm -fr $(ROOTBRAND)
+
+install: $(ROOTFILES)
+
+# XXX link is a developer target to connect the local machine to the current
+# repository's working copy's versions of the commands and modules.
+PWD:sh = pwd
+link:
+	mkdir -p /usr/lib/brand/ipkg
+	ln -s $(PWD)/config.xml /usr/lib/brand/ipkg/config.xml
+	ln -s $(PWD)/platform.xml /usr/lib/brand/ipkg/platform.xml
+	ln -s $(PWD)/SUNWipkg.xml /etc/zones/SUNWipkg.xml
+
+$(ROOT) $(ROOTUSRLIB) $(ROOTBRAND) $(ROOTBRANDPKG):
+	mkdir -p $(ROOTBRANDPKG)
+
+$(ROOTBRANDPKG)/%: $(ROOTBRANDPKG) %
+	rm -f $@; install -f $(ROOTBRANDPKG) -m 0444 $<
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/brand/SUNWipkg.xml	Wed Sep 05 15:23:09 2007 -0700
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+
+<!--
+ Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ Use is subject to license terms.
+
+ CDDL HEADER START
+
+ The contents of this file are subject to the terms of the
+ Common Development and Distribution License (the "License").
+ You may not use this file except in compliance with the License.
+
+ You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ or http://www.opensolaris.org/os/licensing.
+ See the License for the specific language governing permissions
+ and limitations under the License.
+
+ When distributing Covered Code, include this CDDL HEADER in each
+ file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ If applicable, add the following below this CDDL HEADER, with the
+ fields enclosed by brackets "[]" replaced with your own identifying
+ information: Portions Copyright [yyyy] [name of copyright owner]
+
+ CDDL HEADER END
+
+    DO NOT EDIT THIS FILE.  Use zonecfg(1M) instead.
+-->
+
+<!DOCTYPE zone PUBLIC "-//Sun Microsystems Inc//DTD Zones//EN" "file:///usr/share/lib/xml/dtd/zonecfg.dtd.1">
+
+<zone name="default" zonepath="" autoboot="false" brand="ipkg">
+</zone>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/brand/config.xml	Wed Sep 05 15:23:09 2007 -0700
@@ -0,0 +1,95 @@
+<?xml version="1.0"?>
+
+<!--
+ CDDL HEADER START
+
+ The contents of this file are subject to the terms of the
+ Common Development and Distribution License (the "License").
+ You may not use this file except in compliance with the License.
+
+ You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ or http://www.opensolaris.org/os/licensing.
+ See the License for the specific language governing permissions
+ and limitations under the License.
+
+ When distributing Covered Code, include this CDDL HEADER in each
+ file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ If applicable, add the following below this CDDL HEADER, with the
+ fields enclosed by brackets "[]" replaced with your own identifying
+ information: Portions Copyright [yyyy] [name of copyright owner]
+
+ CDDL HEADER END
+
+ Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ Use is subject to license terms.
+
+ DO NOT EDIT THIS FILE.
+-->
+
+<!DOCTYPE brand PUBLIC "-//Sun Microsystems Inc//DTD Brands//EN"
+    "file:///usr/share/lib/xml/dtd/brand.dtd.1">
+
+<brand name="ipkg">
+	<modname></modname>
+
+	<initname>/sbin/init</initname>
+	<login_cmd>/usr/bin/login -z %Z -f %u</login_cmd>
+	<user_cmd>/usr/bin/getent passwd %u</user_cmd>
+
+	<!-- We may not be able to do the create in pkg(1) proper. -->
+	<install>/usr/lib/pkg/pkgcreatezone -z %z -R %R %*</install>
+	<installopts></installopts>
+	<boot></boot>
+	<halt></halt>
+	<verify_cfg></verify_cfg>
+	<verify_adm></verify_adm>
+	<postclone></postclone>
+	<postinstall></postinstall>
+
+	<privilege set="default" name="contract_event" />
+	<privilege set="default" name="contract_observer" />
+	<privilege set="default" name="file_chown" />
+	<privilege set="default" name="file_chown_self" />
+	<privilege set="default" name="file_dac_execute" />
+	<privilege set="default" name="file_dac_read" />
+	<privilege set="default" name="file_dac_search" />
+	<privilege set="default" name="file_dac_write" />
+	<privilege set="default" name="file_owner" />
+	<privilege set="default" name="file_setid" />
+	<privilege set="default" name="ipc_dac_read" />
+	<privilege set="default" name="ipc_dac_write" />
+	<privilege set="default" name="ipc_owner" />
+	<privilege set="default" name="net_bindmlp" />
+	<privilege set="default" name="net_icmpaccess" />
+	<privilege set="default" name="net_mac_aware" />
+	<privilege set="default" name="net_privaddr" />
+	<privilege set="default" name="net_rawaccess" ip-type="exclusive" />
+	<privilege set="default" name="proc_chroot" />
+	<privilege set="default" name="sys_audit" />
+	<privilege set="default" name="proc_audit" />
+	<privilege set="default" name="proc_lock_memory" />
+	<privilege set="default" name="proc_owner" />
+	<privilege set="default" name="proc_setid" />
+	<privilege set="default" name="proc_taskid" />
+	<privilege set="default" name="sys_acct" />
+	<privilege set="default" name="sys_admin" />
+	<privilege set="default" name="sys_ip_config" ip-type="exclusive" />
+	<privilege set="default" name="sys_mount" />
+	<privilege set="default" name="sys_nfs" />
+	<privilege set="default" name="sys_resource" />
+
+	<privilege set="prohibited" name="dtrace_kernel" />
+	<privilege set="prohibited" name="proc_zone" />
+	<privilege set="prohibited" name="sys_config" />
+	<privilege set="prohibited" name="sys_devices" />
+	<privilege set="prohibited" name="sys_ip_config" ip-type="shared" />
+	<privilege set="prohibited" name="sys_linkdir" />
+	<privilege set="prohibited" name="sys_net_config" />
+	<privilege set="prohibited" name="sys_res_config" />
+	<privilege set="prohibited" name="sys_suser_compat" />
+
+	<privilege set="required" name="proc_exec" />
+	<privilege set="required" name="proc_fork" />
+	<privilege set="required" name="sys_ip_config" ip-type="exclusive" />
+	<privilege set="required" name="sys_mount" />
+</brand>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/brand/pkgcreatezone	Wed Sep 05 15:23:09 2007 -0700
@@ -0,0 +1,78 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+usage() {
+	print "Usage: $0 [-h] -R <zoneroot> -z <zonename>"
+	exit $ZONE_SUBPROC_USAGE
+}
+
+trap_cleanup() {
+	print "Installation cancelled due to interrupt."
+	exit $int_code
+}
+
+ZONE_SUBPROC_OK=0
+ZONE_SUBPROC_USAGE=253
+ZONE_SUBPROC_NOTCOMPLETE=254
+ZONE_SUBPROC_FATAL=255
+
+int_code=$ZONE_SUBPROC_NOTCOMPLETE
+
+trap trap_cleanup INT
+
+while getopts "z:R:h" opt; do
+	case $opt in
+		h)	usage ;;
+		R)	zoneroot="$OPTARG" ;;
+		z)	zonename="$OPTARG" ;;
+		*)	usage ;;
+	esac
+done
+shift $((OPTIND-1))
+
+if [[ -z $zoneroot || -z $zonename ]]; then
+	print "No zone root or name"
+	exit $ZONE_SUBPROC_USAGE
+fi
+
+print "Preparing image"
+mkdir -p -m 0700 $zoneroot
+rootdir=$zoneroot/root
+pkg image -F $rootdir
+print "Retrieving catalog"
+pkg -R $rootdir refresh
+print "Installing SUNWcs SUNWesu SUNWadmr SUNWts"
+pkg -R $rootdir install SUNWcs@ SUNWesu SUNWadmr SUNWts@
+print "Setting up SMF profile links"
+# This was formerly done in SUNWcsr/postinstall
+ln -s ns_files.xml $rootdir/var/svc/profile/name_service.xml
+ln -s generic_open.xml $rootdir/var/svc/profile/generic.xml
+ln -s inetd_generic.xml $rootdir/var/svc/profile/inetd_services.xml
+ln -s platform_none.xml $rootdir/var/svc/profile/platform.xml
+print "Copying SMF seed repository"
+# This was formerly done in i.manifest
+cp $rootdir/lib/svc/seed/nonglobal.db $rootdir/etc/svc/repository.db
+print "Done (${SECONDS}s)"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/brand/platform.xml	Wed Sep 05 15:23:09 2007 -0700
@@ -0,0 +1,124 @@
+<?xml version="1.0"?>
+
+<!--
+ CDDL HEADER START
+
+ The contents of this file are subject to the terms of the
+ Common Development and Distribution License (the "License").
+ You may not use this file except in compliance with the License.
+
+ You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ or http://www.opensolaris.org/os/licensing.
+ See the License for the specific language governing permissions
+ and limitations under the License.
+
+ When distributing Covered Code, include this CDDL HEADER in each
+ file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ If applicable, add the following below this CDDL HEADER, with the
+ fields enclosed by brackets "[]" replaced with your own identifying
+ information: Portions Copyright [yyyy] [name of copyright owner]
+
+ CDDL HEADER END
+
+ Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ Use is subject to license terms.
+
+ DO NOT EDIT THIS FILE.
+-->
+
+<!DOCTYPE platform PUBLIC "-//Sun Microsystems Inc//Zones Platform//EN"
+    "file:///usr/share/lib/xml/dtd/zone_platform.dtd.1">
+
+<platform name="ipkg" allow-exclusive-ip="true">
+
+	<!-- Global filesystems to mount when booting the zone -->
+	<global_mount special="/dev" directory="/dev" type="dev"
+	    opt="attrdir=%R/dev"/>
+
+	<!-- Local filesystems to mount when booting the zone -->
+	<mount special="/proc" directory="/proc" type="proc" />
+	<mount special="ctfs" directory="/system/contract" type="ctfs" />
+	<mount special="mnttab" directory="/etc/mnttab" type="mntfs" />
+	<mount special="objfs" directory="/system/object" type="objfs" />
+	<mount special="swap" directory="/etc/svc/volatile" type="tmpfs" />
+
+	<!-- Devices to create under /dev -->
+	<device match="arp" />
+	<device match="conslog" />
+	<device match="cpu/self/cpuid" />
+	<device match="crypto" />
+	<device match="cryptoadm" />
+	<device match="dsk" />
+	<device match="dtrace/*" />
+	<device match="dtrace/provider/*" />
+	<device match="fd" />
+	<device match="kstat" />
+	<device match="lo0" />
+	<device match="lo1" />
+	<device match="lo2" />
+	<device match="lo3" />
+	<device match="log" />
+	<device match="logindmux" />
+	<device match="null" />
+	<device match="openprom" arch="sparc" />
+	<device match="poll" />
+	<device match="pool" />
+	<device match="ptmx" />
+	<device match="pts/*" />
+	<device match="random" />
+	<device match="rdsk" />
+	<device match="rmt" />
+	<device match="sad/user" />
+	<device match="swap" />
+	<device match="sysevent" />
+	<device match="tcp" />
+	<device match="tcp6" />
+	<device match="term" />
+	<device match="ticlts" />
+	<device match="ticots" />
+	<device match="ticotsord" />
+	<device match="tty" />
+	<device match="udp" />
+	<device match="udp6" />
+	<device match="urandom" />
+	<device match="zero" />
+	<device match="zfs" />
+
+	<!-- Devices to create in exclusive IP zone only -->
+	<device match="icmp" ip-type="exclusive" />
+	<device match="icmp6" ip-type="exclusive" />
+	<device match="ip" ip-type="exclusive" />
+	<device match="ip6" ip-type="exclusive" />
+	<device match="ipauth" ip-type="exclusive" />
+	<device match="ipf" ip-type="exclusive" />
+	<device match="ipl" ip-type="exclusive" />
+	<device match="iplookup" ip-type="exclusive" />
+	<device match="ipnat" ip-type="exclusive" />
+	<device match="ipscan" ip-type="exclusive" />
+	<device match="ipsecah" ip-type="exclusive" />
+	<device match="ipsecesp" ip-type="exclusive" />
+	<device match="ipstate" ip-type="exclusive" />
+	<device match="ipsync" ip-type="exclusive" />
+	<device match="keysock" ip-type="exclusive" />
+	<device match="rawip" ip-type="exclusive" />
+	<device match="rawip6" ip-type="exclusive" />
+	<device match="rts" ip-type="exclusive" />
+	<device match="sctp" ip-type="exclusive" />
+	<device match="sctp6" ip-type="exclusive" />
+	<device match="spdsock" ip-type="exclusive" />
+
+	<!-- Renamed devices to create under /dev -->
+	<device match="zcons/%z/zoneconsole" name="zconsole" />
+
+	<!-- Symlinks to create under /dev -->
+	<symlink source="console" target="zconsole" />
+	<symlink source="dtremote" target="/dev/null" />
+	<symlink source="msglog" target="zconsole" />
+	<symlink source="stderr" target="./fd/2" />
+	<symlink source="stdin" target="./fd/0" />
+	<symlink source="stdout" target="./fd/1" />
+	<symlink source="syscon" target="zconsole" />
+	<symlink source="sysmsg" target="zconsole" />
+	<symlink source="systty" target="zconsole" />
+
+</platform>