From: Stefan Berger Subject: [PATCH] [xend / libxen] Add support for labeling of virtual network interfaces Date: Thu, 19 Jul 2007 11:57:28 -0400 Message-ID: <1184860648.14055.28.camel@gsal-3.watson.ibm.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-UI30neFB3wZFmbyg07Ew" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel Cc: Keir Fraser , sailer@us.ibm.com List-Id: xen-devel@lists.xenproject.org --=-UI30neFB3wZFmbyg07Ew Content-Type: text/plain Content-Transfer-Encoding: 7bit This patch adds labeling of virtual network interfaces to xend and makes this manageable through the Xen-API. It's a feature that is only usable if ACM is enabled in Xen and xend is used through the xen-api. A labeled virtual network interface will be plugged into a bridge where other domains with the same-labeled network interface are connected to, so that only same-colored domains can communicate with each other. The bridge should be connected to the outside world using VLAN for isolation, extending the isolation beyond the local machine. If a virtual machine is labeled with a VM label that only has one Simple Type Enforcement Type then it is not necessary to label the virtual network interface, but the color of the network interface is determined from the VM's label. If, however, a virtual machine is labeled with a VM label that has multiple Simple Type Enforcement Types, then the explicit labeling of each virtual network interface is required. To specify the label of a network interface, the vif line in the VM's configuration file has been extended with parameters similar use for specifying the label of the VM: vif = ['policy=,label='] This labels the VIF of the virtual machine for usage under the policy 'policy name' and labels it with the label 'resource label'. Signed-off-by: Stefan Berger --=-UI30neFB3wZFmbyg07Ew Content-Disposition: attachment; filename=xend-xspolicy-xapi-viflabeling.diff Content-Type: text/x-patch; name=xend-xspolicy-xapi-viflabeling.diff; charset=UTF-8 Content-Transfer-Encoding: 7bit --- xen-unstable.hg/docs/xen-api/xenapi-datamodel.tex | 74 +++++++++++++ xen-unstable.hg/tools/libxen/include/xen/api/xen_vif.h | 14 ++ xen-unstable.hg/tools/libxen/src/xen_vif.c | 39 ++++++ xen-unstable.hg/tools/python/xen/util/security.py | 48 ++++++-- xen-unstable.hg/tools/python/xen/xend/XendAPI.py | 19 +++ xen-unstable.hg/tools/python/xen/xend/XendConfig.py | 10 + xen-unstable.hg/tools/python/xen/xend/XendDomain.py | 23 ++++ xen-unstable.hg/tools/python/xen/xend/XendDomainInfo.py | 2 xen-unstable.hg/tools/python/xen/xend/XendXSPolicyAdmin.py | 12 ++ xen-unstable.hg/tools/python/xen/xend/server/netif.py | 43 +++++++ xen-unstable.hg/tools/python/xen/xm/addlabel.py | 41 +++++++ xen-unstable.hg/tools/python/xen/xm/create.dtd | 3 xen-unstable.hg/tools/python/xen/xm/create.py | 3 xen-unstable.hg/tools/python/xen/xm/getlabel.py | 26 ++++ xen-unstable.hg/tools/python/xen/xm/rmlabel.py | 38 ++++++ xen-unstable.hg/tools/python/xen/xm/xenapi_create.py | 13 ++ 16 files changed, 386 insertions(+), 22 deletions(-) Index: root/xen-unstable.hg/tools/python/xen/xend/XendConfig.py =================================================================== --- root.orig/xen-unstable.hg/tools/python/xen/xend/XendConfig.py +++ root/xen-unstable.hg/tools/python/xen/xend/XendConfig.py @@ -1085,6 +1085,12 @@ class XendConfig(dict): self.device_duplicate_check(dev_type, dev_info, target) + if dev_type == 'vif': + if dev_info.get('policy') and dev_info.get('label'): + dev_info['security_label'] = "%s:%s:%s" % \ + (xsconstants.ACM_POLICY_ID, + dev_info['policy'],dev_info['label']) + # create uuid if it doesn't exist dev_uuid = dev_info.get('uuid', None) if not dev_uuid: @@ -1159,6 +1165,10 @@ class XendConfig(dict): network = XendAPIStore.get( cfg_xenapi.get('network'), 'network') dev_info['bridge'] = network.get_name_label() + + if cfg_xenapi.get('security_label'): + dev_info['security_label'] = \ + cfg_xenapi.get('security_label') dev_uuid = cfg_xenapi.get('uuid', None) if not dev_uuid: Index: root/xen-unstable.hg/tools/python/xen/xend/XendDomainInfo.py =================================================================== --- root.orig/xen-unstable.hg/tools/python/xen/xend/XendDomainInfo.py +++ root/xen-unstable.hg/tools/python/xen/xend/XendDomainInfo.py @@ -2419,6 +2419,8 @@ class XendDomainInfo: config['io_read_kbs'] = 0.0 config['io_write_kbs'] = 0.0 + config['security_label'] = config.get('security_label', '') + if dev_class == 'vbd': if self._stateGet() not in (XEN_API_VM_POWER_STATE_HALTED,): Index: root/xen-unstable.hg/tools/python/xen/xm/create.dtd =================================================================== --- root.orig/xen-unstable.hg/tools/python/xen/xm/create.dtd +++ root/xen-unstable.hg/tools/python/xen/xm/create.dtd @@ -74,7 +74,8 @@ mtu CDATA #REQUIRED device CDATA #REQUIRED qos_algorithm_type CDATA #REQUIRED - network CDATA #IMPLIED> + network CDATA #IMPLIED + security_label CDATA #IMPLIED> Index: root/xen-unstable.hg/tools/python/xen/xm/xenapi_create.py =================================================================== --- root.orig/xen-unstable.hg/tools/python/xen/xm/xenapi_create.py +++ root/xen-unstable.hg/tools/python/xen/xm/xenapi_create.py @@ -440,7 +440,9 @@ class xenapi_create: vif.attributes["qos_algorithm_type"].value, "qos_algorithm_params": get_child_nodes_as_dict(vif, - "qos_algorithm_param", "key", "value") + "qos_algorithm_param", "key", "value"), + "security_label": + vif.attributes["security_label"].value } return server.xenapi.VIF.create(vif_record) @@ -748,6 +750,15 @@ class sxp2xml: vif.attributes["device"] = dev vif.attributes["qos_algorithm_type"] = "" + policy = get_child_by_name(vif_sxp, "policy") + label = get_child_by_name(vif_sxp, "label") + + if label and policy: + vif.attributes["security_label"] \ + = "%s:%s:%s" % (xsconstants.ACM_POLICY_ID, policy, label) + else: + vif.attributes["security_label"] = "" + if get_child_by_name(vif_sxp, "bridge") is not None: vif.attributes["network"] \ = get_child_by_name(vif_sxp, "bridge") Index: root/xen-unstable.hg/tools/python/xen/xend/XendAPI.py =================================================================== --- root.orig/xen-unstable.hg/tools/python/xen/xend/XendAPI.py +++ root/xen-unstable.hg/tools/python/xen/xend/XendAPI.py @@ -2084,6 +2084,25 @@ class XendAPI(object): def VIF_get_security_label(self, session, vif_ref): return self._VIF_get(vif_ref, 'security_label') + def _VIF_set(self, ref, prop, val, old_val): + return XendDomain.instance().set_dev_property_by_uuid( + 'vif', ref, prop, val, old_val) + + def VIF_set_security_label(self, session, vif_ref, sec_lab, old_lab): + xendom = XendDomain.instance() + dom = xendom.get_vm_with_dev_uuid('vif', vif_ref) + if not dom: + return xen_api_error(['HANDLE_INVALID', 'VIF', vif_ref]) + + if dom._stateGet() == XEN_API_VM_POWER_STATE_RUNNING: + raise SecurityError(-xsconstants.XSERR_RESOURCE_IN_USE) + + rc = self._VIF_set(vif_ref, 'security_label', sec_lab, old_lab) + if rc == False: + raise SecurityError(-xsconstants.XSERR_BAD_LABEL) + return xen_api_success(xsconstants.XSERR_SUCCESS) + + # Xen API: Class VIF_metrics # ---------------------------------------------------------------- Index: root/xen-unstable.hg/tools/python/xen/xend/XendDomain.py =================================================================== --- root.orig/xen-unstable.hg/tools/python/xen/xend/XendDomain.py +++ root/xen-unstable.hg/tools/python/xen/xend/XendDomain.py @@ -688,6 +688,29 @@ class XendDomain: return value + def set_dev_property_by_uuid(self, klass, dev_uuid, field, value, + old_val = None): + rc = True + self.domains_lock.acquire() + + try: + try: + dom = self.get_vm_with_dev_uuid(klass, dev_uuid) + if dom: + o_val = dom.get_dev_property(klass, dev_uuid, field) + log.info("o_val=%s, old_val=%s" % (o_val, old_val)) + if old_val and old_val != o_val: + return False + + dom.set_dev_property(klass, dev_uuid, field, value) + self.managed_config_save(dom) + except ValueError, e: + pass + finally: + self.domains_lock.release() + + return rc + def is_valid_vm(self, vm_ref): return (self.get_vm_by_uuid(vm_ref) != None) Index: root/xen-unstable.hg/tools/python/xen/xm/addlabel.py =================================================================== --- root.orig/xen-unstable.hg/tools/python/xen/xm/addlabel.py +++ root/xen-unstable.hg/tools/python/xen/xm/addlabel.py @@ -34,6 +34,7 @@ def help(): Format: xm addlabel