Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit 838cee7

Browse files
committed
virt-install: Add --security option for specifying <seclabel> XML
1 parent 1747089 commit 838cee7

4 files changed

Lines changed: 61 additions & 0 deletions

File tree

man/en/virt-install.pod.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ an optimal cpu pinning using NUMA data, if available.
118118
Human readable text description of the virtual machine. This will be stored
119119
in the guests XML configuration for access by other applications.
120120

121+
=item --security type=TYPE[,label=LABEL]
122+
123+
Configure domain security driver settings. Type can be either 'static' or
124+
'dynamic'. 'static' configuration requires a security LABEL. Specifying
125+
LABEL without TYPE implies static configuration.
126+
121127
=back
122128

123129

tests/clitest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,10 @@
368368
"--hvm --nodisks --pxe --sound",
369369
# --soundhw option
370370
"--hvm --nodisks --pxe --soundhw default --soundhw ac97",
371+
# --security dynamic
372+
"--hvm --nodisks --pxe --security type=dynamic",
373+
# --security implicit static
374+
"--hvm --nodisks --pxe --security label=foobar.label",
371375
],
372376

373377
"invalid": [
@@ -379,6 +383,8 @@
379383
"--hvm --nodisks --pxe --watchdog default,action=foobar",
380384
# Busted --soundhw
381385
"--hvm --nodisks --pxe --soundhw default --soundhw foobar",
386+
# Busted --security
387+
"--hvm --nodisks --pxe --security type=foobar",
382388
],
383389
}, # category "misc"
384390

virt-install

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,40 @@ def get_watchdog(watchdogs, guest):
177177
except Exception, e:
178178
fail(_("Error in watchdog device parameters: %s") % str(e))
179179

180+
def get_security(security, guest):
181+
seclist = cli.listify(security)
182+
secopts = seclist and seclist[0] or None
183+
if not secopts:
184+
return
185+
186+
# Parse security opts
187+
opts = cli.parse_optstr(secopts)
188+
secmodel = virtinst.Seclabel(guest.conn)
189+
190+
def get_and_clear(dictname):
191+
val = None
192+
if opts.has_key(dictname):
193+
val = opts[dictname]
194+
del(opts[dictname])
195+
return val
196+
197+
mode = get_and_clear("type")
198+
label = get_and_clear("label")
199+
200+
if label:
201+
secmodel.label = label
202+
if not mode:
203+
mode = secmodel.SECLABEL_TYPE_STATIC
204+
if mode:
205+
secmodel.type = mode
206+
207+
# If extra parameters, then user passed some garbage param
208+
if opts:
209+
raise ValueError(_("Unknown option(s) %s") % opts.keys())
210+
211+
secmodel.get_xml_config()
212+
guest.seclabel = secmodel
213+
180214
def parse_disk_option(guest, path, size):
181215
"""helper to properly parse --disk options"""
182216
abspath = None
@@ -554,6 +588,9 @@ def parse_args():
554588
action="callback", callback=cli.check_before_store,
555589
help=_("Human readable description of the VM to store in "
556590
"the generated XML."))
591+
geng.add_option("", "--security", type="string", dest="security",
592+
action="callback", callback=cli.check_before_store,
593+
help=_("Set domain security driver configuration."))
557594
parser.add_option_group(geng)
558595

559596
insg = OptionGroup(parser, _("Installation Method Options"))
@@ -790,6 +827,7 @@ def main():
790827
cli.get_uuid(options.uuid, guest)
791828
cli.get_vcpus(options.vcpus, options.check_cpu, guest, conn)
792829
cli.get_cpuset(options.cpuset, guest.memory, guest, conn)
830+
get_security(options.security, guest)
793831

794832
get_watchdog(options.watchdog, guest)
795833
cli.get_sound(options.sound, options.soundhw, guest)

virtinst/Seclabel.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
1818
# MA 02110-1301 USA.
1919

20+
import CapabilitiesParser
21+
2022
class Seclabel(object):
2123
"""
2224
Class for generating <seclabel> XML
@@ -28,15 +30,24 @@ class Seclabel(object):
2830

2931
def __init__(self, conn):
3032
self.conn = conn
33+
self._caps = CapabilitiesParser.parse(conn.getCapabilities())
3134

3235
self._type = self.SECLABEL_TYPE_DYNAMIC
3336
self._model = None
3437
self._label = None
3538
self._imagelabel = None
3639

40+
model = self._caps.host.secmodel.model
41+
if not model:
42+
raise ValueError("Hypervisor does not have any security driver"
43+
"enabled")
44+
self.model = model
45+
3746
def get_type(self):
3847
return self._type
3948
def set_type(self, val):
49+
if val not in self.SECLABEL_TYPES:
50+
raise ValueError("Unknown security type '%s'" % val)
4051
self._type = val
4152
type = property(get_type, set_type)
4253

0 commit comments

Comments
 (0)