Skip to contentSkip to conversation

Implement legacy XML-RPC interface for ACM commands

PATCH Superseded Stefan Berger 1 participant 1 message Dec 3, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 Implement legacy XML-RPC interface for ACM commands

This patch moves the directory of files where xend is writing policies and resource labels into to /var/lib/xend/security/policies.

---
 xen-unstable.hg/tools/python/xen/util/acmpolicy.py                     |  109 +++++++++-
 xen-unstable.hg/tools/python/xen/util/xsm/acm/acm.py                   |   11 -
 xen-unstable.hg/tools/python/xen/xend/XendOptions.py                   |    8 
 xen-unstable.hg/tools/python/xen/xend/XendXSPolicyAdmin.py             |   23 +-
 xen-unstable.hg/tools/python/xen/xm/setpolicy.py                       |   11 -
 xen-unstable.hg/tools/security/Makefile                                |    2 
 xen-unstable.hg/tools/security/policies/DEFAULT-UL-security_policy.xml |   41 +++
 xen-unstable.hg/tools/security/policies/default-security_policy.xml    |   30 --
 xen-unstable.hg/tools/security/policies/default-ul-security_policy.xml |   41 ---
 9 files changed, 174 insertions(+), 102 deletions(-)
xen-unstable.hg/tools/python/xen/xend/XendOptions.py +8 -0
Index: root/xen-unstable.hg/tools/python/xen/xend/XendOptions.py
===================================================================
@@ -120,6 +120,9 @@ class XendOptions:
     """Default xend QCoW storage repository location."""
     xend_storage_path_default = '/var/lib/xend/storage'
 
+    """Default xend security state storage path."""
+    xend_security_path_default = '/var/lib/xend/security'
+
     """Default script to configure a backend network interface"""
     vif_script = osdep.vif_script
 
@@ -245,6 +248,11 @@ class XendOptions:
         """
         return self.get_config_string("xend-storage-path", self.xend_storage_path_default)        
 
+    def get_xend_security_path(self):
+        """ Get the path for security state
+        """
+        return self.get_config_string("xend-security-path", self.xend_security_path_default)
+
     def get_network_script(self):
         """@return the script used to alter the network configuration when
         Xend starts and stops, or None if no such script is specified."""
xen-unstable.hg/tools/python/xen/xend/XendXSPolicyAdmin.py +24 -14
Index: root/xen-unstable.hg/tools/python/xen/xend/XendXSPolicyAdmin.py
===================================================================
@@ -22,10 +22,10 @@ from xml.dom import minidom, Node
 
 from xen.xend.XendLogging import log
 from xen.xend import uuid
-from xen.util import xsconstants, dictio, bootloader
+from xen.util import xsconstants, bootloader
 import xen.util.xsm.acm.acm as security
 from xen.util.xspolicy import XSPolicy
-from xen.util.acmpolicy import ACMPolicy
+from xen.util.acmpolicy import ACMPolicy, initialize
 from xen.xend.XendError import SecurityError
 
 
@@ -48,6 +48,7 @@ class XSPolicyAdmin:
         self.xsobjs = {}
 
         act_pol_name = self.get_hv_loaded_policy_name()
+        initialize()
 
         ref = uuid.createString()
         try:
@@ -59,6 +60,7 @@ class XSPolicyAdmin:
 
         log.debug("XSPolicyAdmin: Known policies: %s" % self.policies)
 
+
     def isXSEnabled(self):
         """ Check whether 'security' is enabled on this system.
             This currently only checks for ACM-enablement.
@@ -99,12 +101,23 @@ class XSPolicyAdmin:
             # This is meant as an update to a currently loaded policy
             if flags & xsconstants.XS_INST_LOAD == 0:
                 raise SecurityError(-xsconstants.XSERR_POLICY_LOADED)
-            if flags & xsconstants.XS_INST_BOOT == 0:
-                self.rm_bootpolicy()
+
+            # Remember old flags, so they can be restored if update fails
+            old_flags = self.get_policy_flags(loadedpol)
+
+            # Remove policy from bootloader in case of new name of policy
+            self.rm_bootpolicy()
+
             rc, errors = loadedpol.update(xmltext)
             if rc == 0:
                 irc = self.activate_xspolicy(loadedpol, flags)
                 # policy is loaded; if setting the boot flag fails it's ok.
+            else:
+                old_flags = old_flags & xsconstants.XS_INST_BOOT
+                log.info("OLD FLAGS TO RESTORE: %s" % str(old_flags))
+                if old_flags != 0:
+                    self.activate_xspolicy(loadedpol, xsconstants.XS_INST_BOOT)
+
             return (loadedpol, rc, errors)
 
         try:
@@ -161,15 +174,11 @@ class XSPolicyAdmin:
         return (acmpol, xsconstants.XSERR_SUCCESS, errors)
 
     def make_boot_policy(self, acmpol):
-        spolfile = acmpol.get_filename(".bin")
-        dpolfile = "/boot/" + acmpol.get_filename(".bin","",dotted=True)
-        if not os.path.isfile(spolfile):
-            log.error("binary policy file does not exist.")
-            return -xsconstants.XSERR_FILE_ERROR
-        try:
-            shutil.copyfile(spolfile, dpolfile)
-        except:
-            return -xsconstants.XSERR_FILE_ERROR
+        if acmpol.is_default_policy():
+            return xsconstants.XSERR_SUCCESS
+        rc = acmpol.copy_policy_file(".bin","/boot")
+        if rc != xsconstants.XSERR_SUCCESS:
+            return rc
 
         try:
             filename = acmpol.get_filename(".bin","",dotted=True)
@@ -231,7 +240,8 @@ class XSPolicyAdmin:
         flags = 0
 
         filename = acmpol.get_filename(".bin","", dotted=True)
-        if bootloader.loads_default_policy(filename):
+        if bootloader.loads_default_policy(filename) or \
+           acmpol.is_default_policy():
             flags |= xsconstants.XS_INST_BOOT
 
         if acmpol.isloaded():
xen-unstable.hg/tools/python/xen/util/acmpolicy.py +100 -9

168 lines not on this page · raw message

xen-unstable.hg/tools/python/xen/util/xsm/acm/acm.py +5 -6
Index: root/xen-unstable.hg/tools/python/xen/util/xsm/acm/acm.py
===================================================================
@@ -35,7 +35,8 @@ from xen.util import dictio, xsconstants
 from xen.xend.XendConstants import *
 
 #global directories and tools for security management
-security_dir_prefix = "/etc/xen/acm-security"
+install_policy_dir_prefix = "/etc/xen/acm-security/policies"
+security_dir_prefix = XendOptions.instance().get_xend_security_path()
 policy_dir_prefix = security_dir_prefix + "/policies"
 res_label_filename = policy_dir_prefix + "/resource_labels"
 boot_filename = "/boot/grub/menu.lst"
@@ -323,7 +324,7 @@ def label2ssidref(labelname, policyname,
     maps current policy to default directory
     to find mapping file    """
 
-    if policyname in ['NULL', 'INACTIVE', 'DEFAULT', 'INACCESSIBLE' ]:
+    if policyname in ['NULL', 'INACTIVE', 'INACCESSIBLE' ]:
         err("Cannot translate labels for \'" + policyname + "\' policy.")
 
     allowed_types = ['ANY']
@@ -447,10 +448,8 @@ def get_ssid(domain):
     except:
         err("Cannot determine security information.")
 
-    if active_policy in ["DEFAULT"]:
-        label = "DEFAULT"
-    else:
-        label = ssidref2label(ssid_info["ssidref"])
+    label = ssidref2label(ssid_info["ssidref"])
+
     return(ssid_info["policyreference"],
            label,
            ssid_info["policytype"],
xen-unstable.hg/tools/python/xen/xm/setpolicy.py +8 -3
Index: root/xen-unstable.hg/tools/python/xen/xm/setpolicy.py
===================================================================
@@ -25,6 +25,7 @@ import base64
 import struct
 import xen.util.xsm.xsm as security
 from xen.util import xsconstants
+from xen.util.xsm.acm.acm import install_policy_dir_prefix
 from xen.util.acmpolicy import ACMPolicy, \
    ACM_EVTCHN_SHARING_VIOLATION,\
    ACM_GNTTAB_SHARING_VIOLATION, \
@@ -32,7 +33,6 @@ from xen.util.acmpolicy import ACMPolicy
    ACM_CHWALL_CONFLICT, \
    ACM_SSIDREF_IN_USE
 from xen.xm.opts import OptionError
-from xen.util.xsm.acm.acm import policy_dir_prefix
 from xen.xm import main as xm_main
 from xen.xm.getpolicy import getpolicy
 from xen.xm.main import server
@@ -86,7 +86,7 @@ def setpolicy(policytype, policy_name, f
     if policytype.upper() == xsconstants.ACM_POLICY_ID:
         xs_type = xsconstants.XS_POLICY_ACM
 
-        for prefix in [ './', policy_dir_prefix+"/" ]:
+        for prefix in [ './', install_policy_dir_prefix+"/" ]:
             policy_file = prefix + "/".join(policy_name.split(".")) + \
                           "-security_policy.xml"
 
@@ -99,9 +99,12 @@ def setpolicy(policytype, policy_name, f
             f.close()
         except:
             raise OptionError("Could not read policy file from current"
-                              " directory or '%s'." % policy_dir_prefix)
+                              " directory or '%s'." %
+                              install_policy_dir_prefix)
 
         if xm_main.serverType == xm_main.SERVER_XEN_API:
+            if xs_type != int(server.xenapi.XSPolicy.get_xstype()):
+                raise security.XSMError("ACM policy type not supported.")
 
             try:
                 policystate = server.xenapi.XSPolicy.set_xspolicy(xs_type,
@@ -124,6 +127,8 @@ def setpolicy(policytype, policy_name, f
                 getpolicy(False)
         else:
             # Non-Xen-API call.
+            if xs_type != server.xend.security.get_xstype():
+                raise security.XSMError("ACM policy type not supported.")
 
             rc, errors = server.xend.security.set_policy(xs_type,
                                                          xml,
xen-unstable.hg/tools/security/policies/default-security_policy.xml deleted +0 -30
Index: root/xen-unstable.hg/tools/security/policies/default-security_policy.xml
===================================================================
@@ -1,30 +0,0 @@
-<?xml version="1.0" ?>
-<SecurityPolicyDefinition xmlns="http://www.ibm.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ibm.com ../../security_policy.xsd">
-  <PolicyHeader>
-    <PolicyName>DEFAULT</PolicyName>
-    <Version>1.0</Version>
-  </PolicyHeader>
-  <SimpleTypeEnforcement>
-    <SimpleTypeEnforcementTypes>
-      <Type>SystemManagement</Type>
-    </SimpleTypeEnforcementTypes>
-  </SimpleTypeEnforcement>
-  <ChineseWall>
-    <ChineseWallTypes>
-      <Type>SystemManagement</Type>
-    </ChineseWallTypes>
-  </ChineseWall>
-  <SecurityLabelTemplate>
-    <SubjectLabels bootstrap="SystemManagement">
-      <VirtualMachineLabel>
-        <Name>SystemManagement</Name>
-        <SimpleTypeEnforcementTypes>
-          <Type>SystemManagement</Type>
-        </SimpleTypeEnforcementTypes>
-        <ChineseWallTypes>
-          <Type/>
-        </ChineseWallTypes>
-      </VirtualMachineLabel>
-    </SubjectLabels>
-  </SecurityLabelTemplate>
-</SecurityPolicyDefinition>
xen-unstable.hg/tools/security/Makefile +1 -1
Index: root/xen-unstable.hg/tools/security/Makefile
===================================================================
@@ -32,7 +32,7 @@ ACM_SECGEN_CGIDIR = $(ACM_SECGEN_HTMLDIR
 
 ACM_SCHEMA        = security_policy.xsd
 ACM_EXAMPLES      = client_v1 test
-ACM_DEF_POLICIES  = default default-ul
+ACM_DEF_POLICIES  = DEFAULT-UL
 ACM_POLICY_SUFFIX = security_policy.xml
 
 ifeq ($(ACM_SECURITY),y)
xen-unstable.hg/tools/security/policies/DEFAULT-UL-security_policy.xml new file +41 -0

41 lines not on this page · raw message

xen-unstable.hg/tools/security/policies/default-ul-security_policy.xml deleted +0 -41

41 lines not on this page · raw message

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel