mirror of
https://github.com/virt-manager/virt-manager.git
synced 2026-08-09 04:28:17 -05:00
virtinst: Support multiple seclabels
libvirt has supported this for a while. Wire it all up through the cli, and fix some bad assumptions along the way.
This commit is contained in:
@@ -70,4 +70,5 @@
|
||||
</panic>
|
||||
</devices>
|
||||
<seclabel type="dynamic" model="selinux"/>
|
||||
<seclabel type="none" model="dac"/>
|
||||
</domain>
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
+ <target dev="vdf" bus="virtio"/>
|
||||
+ </disk>
|
||||
</devices>
|
||||
<seclabel type="dynamic" model="selinux" relabel="yes"/>
|
||||
</domain>
|
||||
|
||||
Domain 'test-for-virtxml' defined successfully.
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
+ <target dev="sdb"/>
|
||||
+ </disk>
|
||||
</devices>
|
||||
<seclabel type="dynamic" model="selinux" relabel="yes"/>
|
||||
</domain>
|
||||
|
||||
Domain 'test-for-virtxml' defined successfully.
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
+ <target dev="sdb"/>
|
||||
+ </disk>
|
||||
</devices>
|
||||
<seclabel type="dynamic" model="selinux" relabel="yes"/>
|
||||
</domain>
|
||||
|
||||
Domain 'test-for-virtxml' defined successfully.
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
+ </source>
|
||||
+ </hostdev>
|
||||
</devices>
|
||||
<seclabel type="dynamic" model="selinux" relabel="yes"/>
|
||||
</domain>
|
||||
|
||||
Domain 'test-for-virtxml' defined successfully.
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
</panic>
|
||||
+ <sound model="pcspk"/>
|
||||
</devices>
|
||||
<seclabel type="dynamic" model="selinux" relabel="yes"/>
|
||||
</domain>
|
||||
|
||||
Domain 'test-for-virtxml' defined successfully.
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
<on_reboot>restart</on_reboot>
|
||||
<on_crash>restart</on_crash>
|
||||
@@
|
||||
<address type="isa" iobase="0x505"/>
|
||||
</panic>
|
||||
</devices>
|
||||
<seclabel type="dynamic" model="selinux" relabel="yes"/>
|
||||
+ <clock offset="utc"/>
|
||||
</domain>
|
||||
|
||||
|
||||
@@ -22,9 +22,9 @@
|
||||
<timer name="rtc" tickpolicy="catchup"/>
|
||||
<timer name="pit" tickpolicy="delay"/>
|
||||
@@
|
||||
<address type="isa" iobase="0x505"/>
|
||||
</panic>
|
||||
</devices>
|
||||
<seclabel type="dynamic" model="selinux" relabel="yes"/>
|
||||
+ <cpu mode="host-passthrough"/>
|
||||
</domain>
|
||||
|
||||
|
||||
@@ -12,4 +12,4 @@
|
||||
<source file="/tmp/foobar"/>
|
||||
|
||||
Domain 'test-for-virtxml' defined successfully.
|
||||
Changes will take effect after the next domain shutdown.
|
||||
Changes will take effect after the next domain shutdown.
|
||||
@@ -12,9 +12,9 @@
|
||||
<currentMemory unit="KiB">204800</currentMemory>
|
||||
<blkiotune>
|
||||
@@
|
||||
<address type="isa" iobase="0x505"/>
|
||||
</panic>
|
||||
</devices>
|
||||
<seclabel type="dynamic" model="selinux" relabel="yes"/>
|
||||
+ <title>This is my,funky=new title</title>
|
||||
</domain>
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<address type="isa" iobase="0x505"/>
|
||||
</panic>
|
||||
</devices>
|
||||
+ <seclabel relabel="yes">
|
||||
- <seclabel type="dynamic" model="selinux" relabel="yes"/>
|
||||
+ <seclabel type="dynamic" model="selinux" relabel="yes">
|
||||
+ <label>foo,bar,baz,UNKNOWN=val</label>
|
||||
+ </seclabel>
|
||||
</domain>
|
||||
|
||||
+3
-1
@@ -380,6 +380,7 @@ c.add_compare(""" \
|
||||
--description \"foobar & baz\" \
|
||||
--boot uefi \
|
||||
--security type=dynamic \
|
||||
--security type=none,model=dac \
|
||||
--numatune 1,2,3,5-7,^6 \
|
||||
--memorybacking hugepages=on \
|
||||
--features apic=off \
|
||||
@@ -849,7 +850,8 @@ c.add_compare("--edit --cpu host-passthrough,clearxml=yes", "edit-clear-cpu")
|
||||
c.add_compare("--edit --clock offset=utc,clearxml=yes", "edit-clear-clock")
|
||||
|
||||
c = vixml.add_category("add/rm devices", "test-for-virtxml --print-diff --define", compare_check=support.SUPPORT_CONN_INPUT_KEYBOARD)
|
||||
c.add_invalid("--add-device --security foo") # --add-device without a device
|
||||
c.add_valid("--add-device --security model=dac") # --add-device works for seclabel
|
||||
c.add_invalid("--add-device --pm suspend_to_disk=yes") # --add-device without a device
|
||||
c.add_invalid("--remove-device --clock utc") # --remove-device without a dev
|
||||
c.add_compare("--add-device --host-device net_00_1c_25_10_b1_e4", "add-host-device")
|
||||
c.add_compare("--add-device --sound pcspk", "add-sound")
|
||||
|
||||
@@ -248,6 +248,8 @@
|
||||
|
||||
<memballoon model='virtio'/>
|
||||
</devices>
|
||||
|
||||
<seclabel model='selinux' type='dynamic'/>
|
||||
</domain>
|
||||
|
||||
|
||||
@@ -685,6 +687,9 @@ Foo bar baz & yeah boii < > yeahfoo
|
||||
<!-- memballoon device -->
|
||||
<memballoon model='virtio'/>
|
||||
</devices>
|
||||
|
||||
<seclabel model='selinux' type='dynamic'/>
|
||||
<seclabel model='dac' type='none'/>
|
||||
</domain>
|
||||
|
||||
|
||||
|
||||
@@ -68,8 +68,4 @@
|
||||
<console type="pty"/>
|
||||
<memballoon model='virtio'/>
|
||||
</devices>
|
||||
<seclabel type="static" model="selinux">
|
||||
<label>foolabel</label>
|
||||
<imagelabel>imagelabel</imagelabel>
|
||||
</seclabel>
|
||||
</domain>
|
||||
|
||||
@@ -76,10 +76,6 @@
|
||||
<console type="pty"/>
|
||||
<memballoon model="none"/>
|
||||
</devices>
|
||||
<seclabel type="static" model="apparmor" relabel="yes">
|
||||
<label>barlabel</label>
|
||||
<imagelabel>fooimage</imagelabel>
|
||||
</seclabel>
|
||||
<title>Hey title changed!</title>
|
||||
<description>Hey desc changed&</description>
|
||||
<blkiotune>
|
||||
|
||||
@@ -19,12 +19,12 @@
|
||||
<acpi/>
|
||||
</features>
|
||||
<clock offset="utc"/>
|
||||
<seclabel type="static" model="testSecurity">
|
||||
<label>frob</label>
|
||||
</seclabel>
|
||||
<cpu mode="custom" match="exact">
|
||||
<model fallback="allow">foobar</model>
|
||||
<topology sockets="1" cores="4" threads="1"/>
|
||||
<feature policy="forbid" name="x2apic"/>
|
||||
</cpu>
|
||||
<seclabel type="static" model="testSecurity">
|
||||
<label>frob</label>
|
||||
</seclabel>
|
||||
</domain>
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<domain type="kvm">
|
||||
<name>TestGuest</name>
|
||||
<currentMemory>204800</currentMemory>
|
||||
<memory>409600</memory>
|
||||
<uuid>12345678-1234-1234-1234-123456789012</uuid>
|
||||
<os>
|
||||
<type arch="i686" machine="foobar">hvm</type>
|
||||
<boot dev="hd"/>
|
||||
</os>
|
||||
<devices>
|
||||
<emulator>/usr/lib/xen/bin/qemu-dm</emulator>
|
||||
</devices>
|
||||
<seclabel type="static" model="selinux">
|
||||
<label>foolabel</label>
|
||||
<imagelabel>imagelabel</imagelabel>
|
||||
</seclabel>
|
||||
<seclabel type='none' relabel='no'/>
|
||||
<seclabel type='dynamic' model='dac' relabel='yes'/>
|
||||
</domain>
|
||||
@@ -0,0 +1,19 @@
|
||||
<domain type="kvm">
|
||||
<name>TestGuest</name>
|
||||
<currentMemory>204800</currentMemory>
|
||||
<memory>409600</memory>
|
||||
<uuid>12345678-1234-1234-1234-123456789012</uuid>
|
||||
<os>
|
||||
<type arch="i686" machine="foobar">hvm</type>
|
||||
<boot dev="hd"/>
|
||||
</os>
|
||||
<devices>
|
||||
<emulator>/usr/lib/xen/bin/qemu-dm</emulator>
|
||||
</devices>
|
||||
<seclabel type="none" model="apparmor" relabel="no">
|
||||
<label>barlabel</label>
|
||||
<imagelabel>fooimage</imagelabel>
|
||||
<baselabel>baselabel</baselabel>
|
||||
</seclabel>
|
||||
<seclabel type="dynamic" model="dac" relabel="yes"/>
|
||||
</domain>
|
||||
+21
-12
@@ -132,13 +132,6 @@ class XMLParseTest(unittest.TestCase):
|
||||
check("suspend_to_mem", False, True)
|
||||
check("suspend_to_disk", None, False)
|
||||
|
||||
check = self._make_checker(guest.seclabel)
|
||||
check("type", "static", "static")
|
||||
check("model", "selinux", "apparmor")
|
||||
check("label", "foolabel", "barlabel")
|
||||
check("imagelabel", "imagelabel", "fooimage")
|
||||
check("relabel", None, True)
|
||||
|
||||
check = self._make_checker(guest.os)
|
||||
check("os_type", "hvm", "xen")
|
||||
check("arch", "i686", None)
|
||||
@@ -228,6 +221,21 @@ class XMLParseTest(unittest.TestCase):
|
||||
self._alter_compare(guest.get_xml_config(), outfile,
|
||||
support_check=conn.SUPPORT_CONN_VMPORT)
|
||||
|
||||
def testSeclabel(self):
|
||||
guest, outfile = self._get_test_content("change-seclabel")
|
||||
|
||||
check = self._make_checker(guest.seclabel[0])
|
||||
check("type", "static", "none")
|
||||
check("model", "selinux", "apparmor")
|
||||
check("label", "foolabel", "barlabel")
|
||||
check("imagelabel", "imagelabel", "fooimage")
|
||||
check("baselabel", None, "baselabel")
|
||||
check("relabel", None, False)
|
||||
|
||||
guest.remove_child(guest.seclabel[1])
|
||||
|
||||
self._alter_compare(guest.get_xml_config(), outfile)
|
||||
|
||||
def testAlterMinimalGuest(self):
|
||||
guest, outfile = self._get_test_content("change-minimal-guest")
|
||||
|
||||
@@ -241,12 +249,13 @@ class XMLParseTest(unittest.TestCase):
|
||||
check("offset", None, "utc")
|
||||
self.assertTrue(guest.clock.get_xml_config().startswith("<clock"))
|
||||
|
||||
check = self._make_checker(guest.seclabel)
|
||||
check("model", None, "testSecurity")
|
||||
check("type", None, "static")
|
||||
check("label", None, "frob")
|
||||
seclabel = virtinst.Seclabel(guest.conn)
|
||||
guest.add_child(seclabel)
|
||||
seclabel.model = "testSecurity"
|
||||
seclabel.type = "static"
|
||||
seclabel.label = "frob"
|
||||
self.assertTrue(
|
||||
guest.seclabel.get_xml_config().startswith("<seclabel"))
|
||||
guest.seclabel[0].get_xml_config().startswith("<seclabel"))
|
||||
|
||||
check = self._make_checker(guest.cpu)
|
||||
check("model", None, "foobar")
|
||||
|
||||
@@ -201,14 +201,16 @@ def action_edit(guest, options, parsermap, parserobj):
|
||||
|
||||
|
||||
def action_add_device(guest, options, parsermap, parserobj):
|
||||
if not parserobj.objclass:
|
||||
if (not parserobj.objclass or
|
||||
guest.child_class_is_singleton(parserobj.objclass)):
|
||||
fail(_("Cannot use --add-device with --%s") % parserobj.cli_arg_name)
|
||||
return cli.parse_option_strings(parsermap, options, guest, None)
|
||||
|
||||
|
||||
def action_remove_device(guest, options, parsermap, parserobj):
|
||||
ignore = parsermap
|
||||
if not parserobj.objclass:
|
||||
if (not parserobj.objclass or
|
||||
guest.child_class_is_singleton(parserobj.objclass)):
|
||||
fail(_("Cannot use --remove-device with --%s") %
|
||||
parserobj.cli_arg_name)
|
||||
|
||||
|
||||
+4
-2
@@ -685,7 +685,7 @@ def add_device_options(devg, sound_back_compat=False):
|
||||
|
||||
|
||||
def add_guest_xml_options(geng):
|
||||
geng.add_argument("--security",
|
||||
geng.add_argument("--security", action="append",
|
||||
help=_("Set domain security driver configuration."))
|
||||
geng.add_argument("--numatune",
|
||||
help=_("Tune NUMA policy for the domain process."))
|
||||
@@ -1482,8 +1482,10 @@ class ParserSecurity(VirtCLIParser):
|
||||
self.objclass = Seclabel
|
||||
|
||||
self.set_param("type", "type")
|
||||
self.set_param("label", "label", can_comma=True)
|
||||
self.set_param("model", "model")
|
||||
self.set_param("relabel", "relabel", is_onoff=True)
|
||||
self.set_param("label", "label", can_comma=True)
|
||||
self.set_param("baselabel", "label", can_comma=True)
|
||||
|
||||
|
||||
######################
|
||||
|
||||
+1
-1
@@ -197,10 +197,10 @@ class Guest(XMLBuilder):
|
||||
on_reboot = XMLProperty("./on_reboot", default_cb=lambda s: "restart")
|
||||
on_crash = XMLProperty("./on_crash", default_cb=lambda s: "restart")
|
||||
|
||||
seclabel = XMLChildProperty(Seclabel)
|
||||
os = XMLChildProperty(OSXML, is_single=True)
|
||||
features = XMLChildProperty(DomainFeatures, is_single=True)
|
||||
clock = XMLChildProperty(Clock, is_single=True)
|
||||
seclabel = XMLChildProperty(Seclabel, is_single=True)
|
||||
cpu = XMLChildProperty(CPU, is_single=True)
|
||||
numatune = XMLChildProperty(DomainNumatune, is_single=True)
|
||||
pm = XMLChildProperty(PM, is_single=True)
|
||||
|
||||
@@ -89,4 +89,5 @@ class Seclabel(XMLBuilder):
|
||||
|
||||
label = XMLProperty("./label")
|
||||
imagelabel = XMLProperty("./imagelabel")
|
||||
baselabel = XMLProperty("./baselabel")
|
||||
relabel = XMLProperty("./@relabel", is_yesno=True)
|
||||
|
||||
Reference in New Issue
Block a user