python tools and support for resource labeling
PATCH RESEND 1/1 python tools and support for resource labeling
(same patch as the one sent previously, updated to patch cleanly against the current changeset)
This patch adds new xm subcommands to support working with resource labels. The new subcommands are 'xm resources', 'xm rmlabel', 'xm getlabel' and 'xm dry-run'. In addition, the 'xm addlabel' subcommand now uses an updated syntax to support labeling both domains and resources. See the xm man page for details on each subcommand.
Beyond the new subcommands, this patch allows users to immediately see when security checks will fail by pushing some basic security checking into the beginning of 'xm create' and 'xm block-attach'. ACM security attributes for block devices are added to XenStore in order to support the final security enforcement, which will be performed in the kernel and included in a separate patch.
--- tools/python/xen/util/dictio.py | 50 +++++++++++ tools/python/xen/util/security.py | 98 ++++++++++++++++++++++ tools/python/xen/xend/server/blkif.py | 12 ++ tools/python/xen/xm/addlabel.py | 150 ++++++++++++++++++++++++++-------- tools/python/xen/xm/create.py | 121 ++++++++++++++++++++++++++- tools/python/xen/xm/dry-run.py | 56 ++++++++++++ tools/python/xen/xm/getlabel.py | 114 +++++++++++++++++++++++++ tools/python/xen/xm/main.py | 30 ++++++ tools/python/xen/xm/resources.py | 56 ++++++++++++ tools/python/xen/xm/rmlabel.py | 118 ++++++++++++++++++++++++++ 10 files changed, 764 insertions(+), 41 deletions(-)
tools/python/xen/util/dictio.py new file +50 -0
@@ -0,0 +1,50 @@ +#=========================================================================== +# This library is free software; you can redistribute it and/or +# modify it under the terms of version 2.1 of the GNU Lesser General Public +# License as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +#============================================================================ +# Copyright (C) 2006 International Business Machines Corp. +# Author: Bryan D. Payne <[email protected]> +#============================================================================ + + +def dict_read(dictname, filename): + """Loads <filename> and returns the dictionary named <dictname> from + the file. + """ + dict = {} + + # read in the config file + globs = {} + locs = {} + execfile(filename, globs, locs) + + for (k, v) in locs.items(): + if k == dictname: + dict = v + break + + return dict + +def dict_write(dict, dictname, filename): + """Writes <dict> to <filename> using the name <dictname>. If the file + contains any other data, it will be overwritten. + """ + prefix = dictname + " = {\n" + suffix = "}\n" + fd = open(filename, "wb") + fd.write(prefix) + for key in dict: + line = " '" + str(key) + "': " + str(dict[key]) + ",\n" + fd.write(line) + fd.write(suffix) + fd.close()
tools/python/xen/util/security.py +98 -0
116 lines not on this page · raw message
tools/python/xen/xend/server/blkif.py +10 -2
@@ -21,6 +21,7 @@ import re import string from xen.util import blkif +from xen.util import security from xen.xend import sxp from xen.xend.XendError import VmError
@@ -40,15 +41,22 @@ class BlkifController(DevController): def getDeviceDetails(self, config): """@see DevController.getDeviceDetails""" + uname = sxp.child_value(config, 'uname') dev = sxp.child_value(config, 'dev') - (typ, params) = string.split(sxp.child_value(config, 'uname'), ':', 1) + (typ, params) = string.split(uname, ':', 1) back = { 'dev' : dev, 'type' : typ, 'params' : params, 'mode' : sxp.child_value(config, 'mode', 'r') - } + } + + if security.on(): + (label, ssidref, policy) = security.get_res_security_details(uname) + back.update({'acm_label' : label, + 'acm_ssidref': str(ssidref), + 'acm_policy' : policy}) if 'ioemu:' in dev: (dummy, dev1) = string.split(dev, ':', 1)
tools/python/xen/xm/addlabel.py +115 -35
174 lines not on this page · raw message
tools/python/xen/xm/create.py +118 -3
139 lines not on this page · raw message
tools/python/xen/xm/dry-run.py new file +56 -0
56 lines not on this page · raw message
tools/python/xen/xm/getlabel.py new file +114 -0
114 lines not on this page · raw message
tools/python/xen/xm/main.py +29 -1
@@ -30,6 +30,7 @@ import socket import warnings warnings.filterwarnings('ignore', category=FutureWarning) import xmlrpclib +import traceback import xen.xend.XendProtocol
@@ -119,7 +120,11 @@ vnet_list_help = "vnet-list [-l|--long] vnet_create_help = "vnet-create <config> create a vnet from a config file" vnet_delete_help = "vnet-delete <vnetid> delete a vnet" vtpm_list_help = "vtpm-list <DomId> [--long] list virtual TPM devices" -addlabel_help = "addlabel <ConfigFile> <label> Add security label to ConfigFile" +addlabel_help = "addlabel <label> dom <configfile> Add security label to domain\n <label> res <resource> or resource" +rmlabel_help = "rmlabel dom <configfile> Remove security label from domain\n res <resource> or resource" +getlabel_help = "getlabel dom <configfile> Show security label for domain\n res <resource> or resource" +dry_run_help = "dry-run <configfile> Tests if domain can access its resources" +resources_help = "resources Show info for each labeled resource" cfgbootpolicy_help = "cfgbootpolicy <policy> Add policy to boot configuration " dumppolicy_help = "dumppolicy Print hypervisor ACM state information" loadpolicy_help = "loadpolicy <policy> Load binary policy into hypervisor"
@@ -203,6 +208,10 @@ vnet_commands = [ acm_commands = [ "labels", "addlabel", + "rmlabel", + "getlabel", + "dry-run", + "resources", "makepolicy", "loadpolicy", "cfgbootpolicy",
@@ -992,6 +1001,21 @@ def xm_block_attach(args): if len(args) == 5: vbd.append(['backend', args[4]]) + # verify that policy permits attaching this resource + try: + if security.on(): + dominfo = server.xend.domain(dom) + label = security.get_security_printlabel(dominfo) + else: + label = None + security.res_security_check(args[1], label) + except security.ACMError, e: + print e.value + sys.exit(1) + except: + traceback.print_exc(limit=1) + sys.exit(1) + server.xend.domain.device_create(dom, vbd)
@@ -1124,6 +1148,10 @@ subcommands = [ 'shutdown', 'labels', 'addlabel', + 'rmlabel', + 'getlabel', + 'dry-run', + 'resources', 'cfgbootpolicy', 'makepolicy', 'loadpolicy',
tools/python/xen/xm/resources.py new file +56 -0
56 lines not on this page · raw message
tools/python/xen/xm/rmlabel.py new file +118 -0
118 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel