Skip to contentSkip to conversation

Implement legacy XML-RPC interface for ACM commands

PATCH Superseded Stefan Berger 2 participants 4 messages Dec 3, 2007 – Dec 4, 2007

lore
Share & tools
lore
#0 lore raw

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

This patch implements a (non Xen-API) legacy XML-RPC interface for the ACM commands and funnels the calls into code introduced by the Xen-API support for ACM security management. Since some of the functionality has changed, also the xm applications have changed. In particular the following old commands have been removed along with some tools the have become obsolete now:

- loadpolicy (included in: setpolicy)
- makepolicy (included in: setpolicy)
- cfgbootpolicy (included in: setpolicy)

and the following commands been introduced:

- setpolicy
- getpolicy
- resetpolicy

All tools have been adapted to work in Xen-API and legacy XML-RPC mode. Both modes support the same functionality.

An update to the documentation will follow as well as new test cases.

I have run this and the 2nd patch with the xm-test suite on the tip of the staging tree and they caused no regressions.

---
 xen-unstable.hg/docs/man/xm.pod.1                                                 |   61 
 xen-unstable.hg/tools/python/xen/util/acmpolicy.py                                |   30 
 xen-unstable.hg/tools/python/xen/util/xsm/acm/acm.py                              |  319 +-
 xen-unstable.hg/tools/python/xen/util/xsm/dummy/dummy.py                          |   66 
 xen-unstable.hg/tools/python/xen/util/xsm/flask/flask.py                          |    3 
 xen-unstable.hg/tools/python/xen/xend/XendConfig.py                               |   23 
 xen-unstable.hg/tools/python/xen/xend/XendDomainInfo.py                           |   16 
 xen-unstable.hg/tools/python/xen/xend/XendXSPolicyAdmin.py                        |   12 
 xen-unstable.hg/tools/python/xen/xend/server/XMLRPCServer.py                      |    6 
 xen-unstable.hg/tools/python/xen/xm/activatepolicy.py                             |  111 
 xen-unstable.hg/tools/python/xen/xm/addlabel.py                                   |  112 
 xen-unstable.hg/tools/python/xen/xm/cfgbootpolicy.py                              |  227 -
 xen-unstable.hg/tools/python/xen/xm/create.py                                     |  124 
 xen-unstable.hg/tools/python/xen/xm/dry-run.py                                    |  107 
 xen-unstable.hg/tools/python/xen/xm/getlabel.py                                   |   62 
 xen-unstable.hg/tools/python/xen/xm/getpolicy.py                                  |  101 
 xen-unstable.hg/tools/python/xen/xm/labels.py                                     |   34 
 xen-unstable.hg/tools/python/xen/xm/loadpolicy.py                                 |   70 
 xen-unstable.hg/tools/python/xen/xm/main.py                                       |   33 
 xen-unstable.hg/tools/python/xen/xm/makepolicy.py                                 |   51 
 xen-unstable.hg/tools/python/xen/xm/resetpolicy.py                                |  162 +
 xen-unstable.hg/tools/python/xen/xm/resources.py                                  |    8 
 xen-unstable.hg/tools/python/xen/xm/rmlabel.py                                    |   94 
 xen-unstable.hg/tools/python/xen/xm/setpolicy.py                                  |  176 -
 xen-unstable.hg/tools/security/Makefile                                           |    9 
 xen-unstable.hg/tools/security/policies/example/client_v1-security_policy.xml     |    4 
 xen-unstable.hg/tools/security/policies/example/ste/client_v1-security_policy.xml |  149 -
 xen-unstable.hg/tools/security/secpol_xml2bin.c                                   | 1457 ----------
 xen-unstable.hg/tools/security/secpol_xml2bin.h                                   |  166 -
 xen-unstable.hg/tools/xm-test/lib/XmTestLib/acm.py                                |   58 
 xen-unstable.hg/tools/xm-test/tests/security-acm/01_security-acm_basic.py         |    6 
 xen-unstable.hg/tools/xm-test/tests/security-acm/acm_utils.py                     |    2 
 32 files changed, 1000 insertions(+), 2859 deletions(-)
xen-unstable.hg/tools/python/xen/xend/server/XMLRPCServer.py +6 -0
Index: root/xen-unstable.hg/tools/python/xen/xend/server/XMLRPCServer.py
===================================================================
@@ -207,6 +207,12 @@ class XMLRPCServer:
         self.server.register_function(domain_create, 'xend.domain.create')
         self.server.register_function(domain_restore, 'xend.domain.restore')
 
+        # A couple of the security functions
+        from xen.util.xsm import xsm as security
+        for name in security.xmlrpc_exports:
+            fn = getattr(security, name)
+            self.server.register_function(fn, "xend.security.%s" % name)
+
         self.server.register_introspection_functions()
         self.ready = True
 
xen-unstable.hg/tools/python/xen/xm/addlabel.py +60 -52

147 lines not on this page · raw message

xen-unstable.hg/tools/python/xen/xm/rmlabel.py +58 -36

121 lines not on this page · raw message

xen-unstable.hg/tools/python/xen/util/xsm/acm/acm.py +236 -83

539 lines not on this page · raw message

xen-unstable.hg/tools/python/xen/xm/resources.py +1 -7
Index: root/xen-unstable.hg/tools/python/xen/xm/resources.py
===================================================================
@@ -19,8 +19,6 @@
 """List the resource label information from the global resource label file
 """
 import sys
-from xen.util import dictio
-import xen.util.xsm.xsm as security
 from xen.util import xsconstants
 from xen.xm.opts import OptionError
 from xen.xm import main as xm_main
@@ -55,11 +53,7 @@ def main (argv):
         for key, value in access_control.items():
             access_control[key] = tuple(value.split(':'))
     else:
-        try:
-            filename = security.res_label_filename
-            access_control = dictio.dict_read("resources", filename)
-        except:
-            raise OptionError("Resource file not found")
+        access_control = server.xend.security.get_labeled_resources()
 
     print_resource_data(access_control)
 
xen-unstable.hg/tools/python/xen/xm/getlabel.py +26 -36

89 lines not on this page · raw message

xen-unstable.hg/tools/python/xen/xm/labels.py +6 -28
Index: root/xen-unstable.hg/tools/python/xen/xm/labels.py
===================================================================
@@ -20,9 +20,7 @@
 """
 import sys
 import traceback
-import string
-from xen.util.xsm.xsm import XSMError, err, list_labels, active_policy
-from xen.util.xsm.xsm import vm_label_re, res_label_re, all_label_re
+from xen.util.xsm.xsm import XSMError, err
 from xen.xm.opts import OptionError
 from xen.util.acmpolicy import ACMPolicy
 from xen.util import xsconstants
@@ -58,32 +56,12 @@ def main(argv):
         labels_xapi(policy, ptype)
 
 def labels(policy, ptype):
-    if not policy:
-        policy = active_policy
-        if active_policy in ['NULL', 'INACTIVE', 'DEFAULT']:
-            raise OptionError('No policy active, you must specify a <policy>')
-        if active_policy in ['INACCESSIBLE']:
-            raise OptionError('Cannot access the policy. Try as root.')
-
-    if not ptype or ptype == 'dom':
-        condition = vm_label_re
-    elif ptype == 'res':
-        condition = res_label_re
-    elif ptype == 'any':
-        condition = all_label_re
-    else:
-        err("Unknown label type \'" + ptype + "\'")
 
-    try:
-        labels = list_labels(policy, condition)
-        labels.sort()
-        for label in labels:
-            print label
-
-    except XSMError:
-        sys.exit(-1)
-    except:
-        traceback.print_exc(limit = 1)
+    labels = server.xend.security.list_labels(policy, ptype)
+    labels.sort()
+    for label in labels:
+        print label
+
 
 def labels_xapi(policy, ptype):
     policystate = server.xenapi.XSPolicy.get_xspolicy()
xen-unstable.hg/tools/python/xen/xm/main.py +9 -24
Index: root/xen-unstable.hg/tools/python/xen/xm/main.py
===================================================================
@@ -187,16 +187,12 @@ SUBCOMMAND_HELP = {
     'dry-run'       :  ('<ConfigFile>',
                         'Test if a domain can access its resources.'),
     'resources'     :  ('', 'Show info for each labeled resource.'),
-    'cfgbootpolicy' :  ('<policy> [boot-title]',
-                        'Add policy to boot configuration.'),
     'dumppolicy'    :  ('', 'Print hypervisor ACM state information.'),
-    'loadpolicy'    :  ('<policy.bin>', 'Load binary policy into hypervisor.'),
-    'makepolicy'    :  ('<policy>', 'Build policy and create .bin/.map '
-                        'files.'),
     'setpolicy'     :  ('<policytype> <policyfile> [options]',
                         'Set the policy of the system.'),
+    'resetpolicy'   :  ('',
+                        'Set the policy of the system to the default policy.'),
     'getpolicy'     :  ('[options]', 'Get the policy of the system.'),
-    'activatepolicy':  ('[options]', 'Activate the xend-managed policy.'),
     'labels'        :  ('[policy] [type=dom|res|any]',
                         'List <type> labels for (active) policy.'),
     'serve'         :  ('', 'Proxy Xend XMLRPC over stdio.'),
@@ -350,12 +346,9 @@ acm_commands = [
     "getlabel",
     "dry-run",
     "resources",
-    "makepolicy",
-    "loadpolicy",
-    "cfgbootpolicy",
     "dumppolicy",
-    "activatepolicy",
     "setpolicy",
+    "resetpolicy",
     "getpolicy",
     ]
 
@@ -942,18 +935,13 @@ def xm_label_list(doms):
     format = '%(name)-40s %(domid)5s %(mem)5d %(vcpus)5d %(state)10s ' \
              '%(cpu_time)8.1f %(seclabel)10s'
 
-    import xen.util.xsm.xsm as security
-        
     for dom in doms:
         d = parse_doms_info(dom)
-        if security.active_policy not in ['INACTIVE', 'NULL', 'DEFAULT']:
-            if not d['seclabel']:
-                d['seclabel'] = ACM_LABEL_UNLABELED_DISPLAY
-        elif security.active_policy in ['DEFAULT']:
-            d['seclabel'] = 'DEFAULT'
-        else:
-            d['seclabel'] = 'INACTIVE'
-
+        if d['seclabel'] == "" and serverType != SERVER_XEN_API:
+            seclab = server.xend.security.get_domain_label(d['name'])
+            if len(seclab) > 0 and seclab[0] == '\'':
+                seclab = seclab[1:]
+            d['seclabel'] = seclab
         output.append((format % d, d['seclabel']))
         
     #sort by labels
@@ -2471,9 +2459,6 @@ IMPORTED_COMMANDS = [
     'new',    
     'migrate',
     'labels',
-    'cfgbootpolicy',
-    'makepolicy',
-    'loadpolicy',
     'dumppolicy',        
     'addlabel',
     'rmlabel',
@@ -2482,7 +2467,7 @@ IMPORTED_COMMANDS = [
     'resources',
     'getpolicy',
     'setpolicy',
-    'activatepolicy',
+    'resetpolicy',
     ]
 
 for c in IMPORTED_COMMANDS:
xen-unstable.hg/tools/python/xen/xm/loadpolicy.py deleted +0 -70

70 lines not on this page · raw message

xen-unstable.hg/tools/python/xen/xm/makepolicy.py deleted +0 -51

51 lines not on this page · raw message

xen-unstable.hg/tools/security/Makefile +2 -7
Index: root/xen-unstable.hg/tools/security/Makefile
===================================================================
@@ -15,12 +15,10 @@ LDFLAGS    += $(shell xml2-config --libs
 
 SRCS_TOOL     = secpol_tool.c
 OBJS_TOOL    := $(patsubst %.c,%.o,$(filter %.c,$(SRCS_TOOL)))
-SRCS_XML2BIN  = secpol_xml2bin.c secpol_xml2bin.h
-OBJS_XML2BIN := $(patsubst %.c,%.o,$(filter %.c,$(SRCS_XML2BIN)))
 
-ACM_INST_TOOLS    = xensec_tool xensec_xml2bin xensec_gen
+ACM_INST_TOOLS    = xensec_tool xensec_gen
 ACM_EZPOLICY      = xensec_ezpolicy
-ACM_OBJS          = $(OBJS_TOOL) $(OBJS_XML2BIN) $(OBJS_GETD)
+ACM_OBJS          = $(OBJS_TOOL) $(OBJS_GETD)
 ACM_SCRIPTS       = python/xensec_tools/acm_getlabel
 
 ACM_CONFIG_DIR    = /etc/xen/acm-security
@@ -86,9 +84,6 @@ build: $(ACM_INST_TOOLS) $(ACM_NOINST_TO
 xensec_tool: $(OBJS_TOOL)
 	$(CC) -g $(CFLAGS) $(LDFLAGS) -O0 -o $@ $^ -L$(XEN_LIBXC) -lxenctrl
 
-xensec_xml2bin: $(OBJS_XML2BIN)
-	$(CC) -g $(CFLAGS) $(LDFLAGS) -O0 -o $@ $^
-
 xensec_gen: xensec_gen.py
 	cp -f $^ $@
 
xen-unstable.hg/tools/security/secpol_xml2bin.c deleted +0 -1457

1,457 lines not on this page · raw message

xen-unstable.hg/tools/security/secpol_xml2bin.h deleted +0 -166

166 lines not on this page · raw message

xen-unstable.hg/tools/python/xen/util/acmpolicy.py +23 -7
Index: root/xen-unstable.hg/tools/python/xen/util/acmpolicy.py
===================================================================
@@ -51,6 +51,19 @@ ACM_SCHEMA_FILE = ACM_POLICIES_DIR + "se
 ACM_LABEL_UNLABELED = "__UNLABELED__"
 ACM_LABEL_UNLABELED_DISPLAY = "unlabeled"
 
+"""
+   Error codes reported in when trying to test for a new policy
+   These error codes are reported in an array of tuples where
+   each error code is followed by a parameter describing the error
+   more closely, such as a domain id.
+"""
+ACM_EVTCHN_SHARING_VIOLATION = 0x100
+ACM_GNTTAB_SHARING_VIOLATION = 0x101
+ACM_DOMAIN_LOOKUP            = 0x102
+ACM_CHWALL_CONFLICT          = 0x103
+ACM_SSIDREF_IN_USE           = 0x104
+
+
 class ACMPolicy(XSPolicy):
     """
      ACMPolicy class. Implements methods for getting information from
@@ -228,7 +241,7 @@ class ACMPolicy(XSPolicy):
                 return -xsconstants.XSERR_BAD_LABEL, errors
 
             #Get binary and map from the new policy
-            rc, map, bin_pol = acmpol_new.policy_create_map_and_bin()
+            rc, pol_map, bin_pol = acmpol_new.policy_create_map_and_bin()
             if rc != xsconstants.XSERR_SUCCESS:
                 log.error("Could not build the map and binary policy.")
                 return rc, errors
@@ -356,7 +369,7 @@ class ACMPolicy(XSPolicy):
             pass
         return ssidref
 
-    def set_vm_bootlabel(self, vm_label):
+    def set_vm_bootlabel(self, vm_label, remove=False):
         parms="<>"
         if vm_label != "":
             ssidref = self.vmlabel_to_ssidref(vm_label)
@@ -367,6 +380,10 @@ class ACMPolicy(XSPolicy):
                          self.get_name(),vm_label)
         else:
             ssidref = 0 #Identifier for removal
+
+        if remove == True:
+            parms = "<>"
+
         try:
             def_title = bootloader.get_default_title()
             bootloader.set_kernel_attval(def_title, "ssidref", parms)
@@ -387,7 +404,7 @@ class ACMPolicy(XSPolicy):
         if name:
             p = name.split(".")
             path = ""
-            if dotted == True:
+            if dotted:
                 sep = "."
             else:
                 sep = "/"
@@ -513,8 +530,8 @@ class ACMPolicy(XSPolicy):
         self.set_frompolicy_name(curpol.policy_dom_get_hdr_item("PolicyName"))
         version = curpol.policy_dom_get_hdr_item("Version")
         self.set_frompolicy_version(version)
-        (maj, min) = self.__convVersionToTuple(version)
-        self.set_policy_version("%s.%s" % (maj, min+1))
+        (maj, minor) = self.__convVersionToTuple(version)
+        self.set_policy_version("%s.%s" % (maj, minor+1))
 
     #
     # Get all types that are part of a node
@@ -877,8 +894,7 @@ class ACMPolicy(XSPolicy):
         """
             Determine whether this policy is the active one.
         """
-        security.refresh_security_policy()
-        if self.get_name() == security.active_policy:
+        if self.get_name() == security.get_active_policy_name():
             return True
         return False
 
xen-unstable.hg/tools/python/xen/xm/setpolicy.py +94 -82

115 lines not on this page · raw message

xen-unstable.hg/tools/python/xen/xm/activatepolicy.py deleted +0 -111

111 lines not on this page · raw message

xen-unstable.hg/tools/xm-test/lib/XmTestLib/acm.py +11 -47

58 lines not on this page · raw message

xen-unstable.hg/tools/xm-test/tests/security-acm/01_security-acm_basic.py +0 -6
Index: root/xen-unstable.hg/tools/xm-test/tests/security-acm/01_security-acm_basic.py
===================================================================

Lines of this file are not shown. View the raw message.

xen-unstable.hg/tools/python/xen/xm/getpolicy.py +71 -30

101 lines not on this page · raw message

xen-unstable.hg/tools/python/xen/xm/create.py +1 -123

124 lines not on this page · raw message

xen-unstable.hg/tools/python/xen/util/xsm/flask/flask.py +3 -0
Index: root/xen-unstable.hg/tools/python/xen/util/xsm/flask/flask.py
===================================================================

Lines of this file are not shown. View the raw message.

xen-unstable.hg/tools/python/xen/util/xsm/dummy/dummy.py +65 -1

66 lines not on this page · raw message

xen-unstable.hg/tools/python/xen/xm/cfgbootpolicy.py deleted +0 -227

227 lines not on this page · raw message

xen-unstable.hg/tools/python/xen/xend/XendConfig.py +17 -6
Index: root/xen-unstable.hg/tools/python/xen/xend/XendConfig.py
===================================================================

Lines of this file are not shown. View the raw message.

xen-unstable.hg/tools/xm-test/tests/security-acm/acm_utils.py +1 -1
Index: root/xen-unstable.hg/tools/xm-test/tests/security-acm/acm_utils.py
===================================================================

Lines of this file are not shown. View the raw message.

xen-unstable.hg/tools/python/xen/xm/dry-run.py +105 -2

107 lines not on this page · raw message

xen-unstable.hg/tools/python/xen/xend/XendDomainInfo.py +10 -6
Index: root/xen-unstable.hg/tools/python/xen/xend/XendDomainInfo.py
===================================================================

Lines of this file are not shown. View the raw message.

xen-unstable.hg/tools/python/xen/xm/resetpolicy.py new file +162 -0

162 lines not on this page · raw message

xen-unstable.hg/tools/python/xen/xend/XendXSPolicyAdmin.py +7 -5
Index: root/xen-unstable.hg/tools/python/xen/xend/XendXSPolicyAdmin.py
===================================================================

Lines of this file are not shown. View the raw message.

xen-unstable.hg/docs/man/xm.pod.1 +24 -37

61 lines not on this page · raw message

xen-unstable.hg/tools/security/policies/example/client_v1-security_policy.xml +2 -2
Index: root/xen-unstable.hg/tools/security/policies/example/client_v1-security_policy.xml
===================================================================

Lines of this file are not shown. View the raw message.

xen-unstable.hg/tools/security/policies/example/ste/client_v1-security_policy.xml deleted +0 -149

149 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

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

Part of the diff is not shown here. View the raw message.

#1 lore raw

Both these patches are reported as corrupt by 'patch'. This one on line 1159 of the patch; the other one on line 99. In both cases the immediately preceding chunk fails to apply.

-- Keir

Quoted 27 lines · Stefan Berger

This patch implements a (non Xen-API) legacy XML-RPC interface for the ACM commands and funnels the calls into code introduced by the Xen-API support for ACM security management. Since some of the functionality has changed, also the xm applications have changed. In particular the following old commands have been removed along with some tools the have become obsolete now:

- loadpolicy (included in: setpolicy)
- makepolicy (included in: setpolicy)
- cfgbootpolicy (included in: setpolicy)

and the following commands been introduced:

- setpolicy
- getpolicy
- resetpolicy

All tools have been adapted to work in Xen-API and legacy XML-RPC mode. Both modes support the same functionality.

An update to the documentation will follow as well as new test cases.

I have run this and the 2nd patch with the xm-test suite on the tip of the staging tree and they caused no regressions.

#2 lore raw

[email protected] wrote on 12/04/2007 06:33:42 AM:

Quoted 1 line

Both these patches are reported as corrupt by 'patch'. This one on line

1159

Quoted 2 lines

of the patch; the other one on line 99. In both cases the immediately preceding chunk fails to apply.

I just took the ones I posted with the mail program and they worked find. Also the ones I received back from the email list are ok.
If it's just two hunks that are corrupted, can you delete those hunks and commit it and I'll diff the trees and resend the missing parts?

Stefan

Quoted 8 lines

-- Keir

Quoted 3 lines · Stefan Berger

This patch implements a (non Xen-API) legacy XML-RPC interface for the ACM commands and funnels the calls into code introduced by the Xen-API support for ACM security management. Since some of the functionality

has

Quoted 2 lines
Quoted 2 lines

changed, also the xm applications have changed. In particular the following old commands have been removed along with some tools the

have

Quoted 6 lines
Quoted 6 lines

become obsolete now:

- loadpolicy (included in: setpolicy)
- makepolicy (included in: setpolicy)
- cfgbootpolicy (included in: setpolicy)

Quoted 7 lines
Quoted 7 lines

and the following commands been introduced:

- setpolicy
- getpolicy
- resetpolicy

All tools have been adapted to work in Xen-API and legacy XML-RPC

mode.

Quoted 12 lines
Quoted 9 lines

Both modes support the same functionality.

An update to the documentation will follow as well as new test cases.

I have run this and the 2nd patch with the xm-test suite on the tip of the staging tree and they caused no regressions.

Quoted 4 lines

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

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

#3 lore raw
Quoted 11 lines · Stefan Berger

[email protected] wrote on 12/04/2007 06:33:42 AM:

Quoted 4 lines
Quoted 1 line

Both these patches are reported as corrupt by 'patch'. This one on line

1159

Quoted 2 lines

of the patch; the other one on line 99. In both cases the immediately preceding chunk fails to apply.

I just took the ones I posted with the mail program and they worked find. Also the ones I received back from the email list are ok.
If it's just two hunks that are corrupted, can you delete those hunks and commit it and I'll diff the trees and resend the missing parts?

The errors I get are below, and occur with patch version 2.5.4 and 2.5.9. I suppose it could conceivably be metamail screwing up the patches when I extract them from the raw emails. Perhaps try resending the pair of patches in a zip file?

-- Keir

viper:xen64.hg$ patch -p2 <../tmp/security_commands_through_xend.diff patching file tools/python/xen/xend/server/XMLRPCServer.py patching file tools/python/xen/xm/addlabel.py
patching file tools/python/xen/xm/rmlabel.py
patching file tools/python/xen/util/xsm/acm/acm.py patching file tools/python/xen/xm/resources.py
patching file tools/python/xen/xm/getlabel.py
patching file tools/python/xen/xm/labels.py
patching file tools/python/xen/xm/main.py
Hunk #4 FAILED at 2459.
1 out of 4 hunks FAILED -- saving rejects to file tools/python/xen/xm/main.py.rej
missing header for unified diff at line 1159 of patch can't find file to patch at input line 1159
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
| 'rmlabel',
--------------------------
File to patch:

viper:xen64.hg$ patch -p2 <../tmp/xend_acm_new_storage_path.diff patching file tools/python/xen/xend/XendOptions.py patching file tools/python/xen/xend/XendXSPolicyAdmin.py Hunk #4 FAILED at 101.
1 out of 4 hunks FAILED -- saving rejects to file tools/python/xen/xend/XendXSPolicyAdmin.py.rej
missing header for unified diff at line 99 of patch can't find file to patch at input line 99
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
| try:
--------------------------
File to patch:

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