Skip to contentSkip to conversation

Extend Xen-API with function to reset the policy

PATCH In review Stefan Berger 2 participants 4 messages Dec 10, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Extend Xen-API with function to reset the policy

This patch extends the Xen-API and the legacy XML-RPC interface with a function to reset the policy on the system (through an update with the default policy). I adapted the code in 'xm resetpolicy' to use this now.

This patch also extends libxen and the documentation to reflect the new function.

---
 xen-unstable.hg/docs/xen-api/xenapi-datamodel.tex           |   39 +++++++
 xen-unstable.hg/tools/libxen/include/xen/api/xen_xspolicy.h |   13 ++
 xen-unstable.hg/tools/libxen/src/xen_xspolicy.c             |   18 +++
 xen-unstable.hg/tools/python/xen/util/acmpolicy.py          |   15 ++
 xen-unstable.hg/tools/python/xen/util/xsm/acm/acm.py        |   15 ++
 xen-unstable.hg/tools/python/xen/util/xsm/dummy/dummy.py    |    4 
 xen-unstable.hg/tools/python/xen/xend/XendXSPolicy.py       |   32 ++++++
 xen-unstable.hg/tools/python/xen/xend/XendXSPolicyAdmin.py  |   17 +++
 xen-unstable.hg/tools/python/xen/xm/resetpolicy.py          |   61 ------------
 9 files changed, 153 insertions(+), 61 deletions(-)
xen-unstable.hg/tools/python/xen/util/acmpolicy.py +12 -3
Index: root/xen-unstable.hg/tools/python/xen/util/acmpolicy.py
===================================================================
@@ -86,7 +86,7 @@ DEFAULT_policy = \
 "  <SecurityLabelTemplate>\n" +\
 "    <SubjectLabels bootstrap=\"SystemManagement\">\n" +\
 "      <VirtualMachineLabel>\n" +\
-"        <Name>SystemManagement</Name>\n" +\
+"        <Name%s>SystemManagement</Name>\n" +\
 "        <SimpleTypeEnforcementTypes>\n" +\
 "          <Type>SystemManagement</Type>\n" +\
 "        </SimpleTypeEnforcementTypes>\n" +\
@@ -99,8 +99,11 @@ DEFAULT_policy = \
 "</SecurityPolicyDefinition>\n"
 
 
-def get_DEFAULT_policy():
-    return DEFAULT_policy
+def get_DEFAULT_policy(dom0label=""):
+    fromnode = ""
+    if dom0label != "":
+        fromnode = " from=\"%s\"" % dom0label
+    return DEFAULT_policy % fromnode
 
 def initialize():
     xoptions = XendOptions.instance()
@@ -375,6 +378,12 @@ class ACMPolicy(XSPolicy):
 
     force_default_policy = classmethod(force_default_policy)
 
+    def get_reset_policy_xml(klass):
+        dom0_label = security.get_ssid(0)[1]
+        return get_DEFAULT_policy(dom0_label)
+
+    get_reset_policy_xml = classmethod(get_reset_policy_xml)
+
     def __do_update_version_check(self, acmpol_new):
         acmpol_old = self
 
xen-unstable.hg/tools/python/xen/util/xsm/acm/acm.py +15 -0
Index: root/xen-unstable.hg/tools/python/xen/util/xsm/acm/acm.py
===================================================================
@@ -86,6 +86,7 @@ xmlrpc_exports = [
   'list_labels',
   'get_labeled_resources',
   'set_policy',
+  'reset_policy',
   'get_policy',
   'activate_policy',
   'rm_bootpolicy',
@@ -567,6 +568,20 @@ def set_policy(xs_type, xml, flags, over
         err(str(e))
 
 
+def reset_policy():
+    """
+       Xend exports this function via XML-RPC
+    """
+    from xen.xend import XendXSPolicyAdmin
+    xspoladmin = XendXSPolicyAdmin.XSPolicyAdminInstance()
+    try:
+        acmpol, rc, errors = \
+             xspoladmin.reset_acmpolicy()
+        return rc, base64.b64encode(errors)
+    except Exception, e:
+        err(str(e))
+
+
 def get_policy():
     """
         Xend exports this function via XML-RPC
xen-unstable.hg/tools/python/xen/xend/XendXSPolicyAdmin.py +17 -0
Index: root/xen-unstable.hg/tools/python/xen/xend/XendXSPolicyAdmin.py
===================================================================
@@ -179,6 +179,23 @@ class XSPolicyAdmin:
             self.xsobjs[ref]  = acmpol
         return (acmpol, xsconstants.XSERR_SUCCESS, errors)
 
+
+    def reset_acmpolicy(self):
+        """
+           Attempt to reset the system's policy by udating it with
+           the DEFAULT policy.
+        """
+        from xen.xend import XendDomain
+        domains = XendDomain.instance()
+        try:
+            domains.domains_lock.acquire()
+            xml = ACMPolicy.get_reset_policy_xml()
+            flags = xsconstants.XS_INST_BOOT | xsconstants.XS_INST_LOAD
+            return self.__add_acmpolicy_to_system(xml, flags, True)
+        finally:
+            domains.domains_lock.release()
+
+
     def make_boot_policy(self, acmpol):
         if acmpol.is_default_policy():
             return xsconstants.XSERR_SUCCESS
xen-unstable.hg/tools/libxen/include/xen/api/xen_xspolicy.h +13 -0
Index: root/xen-unstable.hg/tools/libxen/include/xen/api/xen_xspolicy.h
===================================================================
@@ -240,6 +240,19 @@ xen_xspolicy_set_xspolicy(xen_session *s
                           bool overwrite);
 
 
+
+/**
+ * Attempt to reset the system's policy to the DEFAULT policy for the
+ * respective policy type. This is done by updating the system and therefore
+ * underlies the same restrictions of a policy update. This operation may
+ * for example fail if other domains than Domain-0 are running and have
+ * different labels than Domain-0.
+ */
+bool
+xen_xspolicy_reset_xspolicy(xen_session *session, xen_xs_policystate **result,
+                            xs_type type);
+
+
 /**
  * Remove any policy from having the system booted with.
  */
xen-unstable.hg/tools/libxen/src/xen_xspolicy.c +18 -0
Index: root/xen-unstable.hg/tools/libxen/src/xen_xspolicy.c
===================================================================
@@ -225,6 +225,24 @@ xen_xspolicy_set_xspolicy(xen_session *s
 
 
 bool
+xen_xspolicy_reset_xspolicy(xen_session *session, xen_xs_policystate **result,
+                            xs_type type)
+{
+    abstract_value param_values[] =
+        {
+            { .type = &abstract_type_int,
+              .u.int_val = type },
+        };
+
+    abstract_type result_type = xen_xs_policystate_abstract_type_;
+
+    *result = NULL;
+    XEN_CALL_("XSPolicy.reset_xspolicy");
+    return session->ok;
+}
+
+
+bool
 xen_xspolicy_get_xspolicy(xen_session *session, xen_xs_policystate **result)
 {
     abstract_value param_values[] =
xen-unstable.hg/tools/python/xen/xend/XendXSPolicy.py +32 -0
Index: root/xen-unstable.hg/tools/python/xen/xend/XendXSPolicy.py
===================================================================
@@ -43,6 +43,7 @@ class XendXSPolicy(XendBase):
     def getFuncs(self):
         funcs = [ 'get_xstype',
                   'set_xspolicy',
+                  'reset_xspolicy',
                   'get_xspolicy',
                   'rm_xsbootpolicy',
                   'get_resource_label',
@@ -104,6 +105,36 @@ class XendXSPolicy(XendBase):
             raise SecurityError(-xsconstants.XSERR_POLICY_TYPE_UNSUPPORTED)
         return polstate
 
+
+    def reset_xspolicy(self, xstype):
+        xstype = int(xstype)
+        polstate = { 'xs_ref': "", 'repr'   : "", 'type'   : 0,
+                     'flags' : 0 , 'version': 0 , 'errors' : "", 'xserr' : 0 }
+        if xstype == xsconstants.XS_POLICY_ACM:
+            poladmin = XSPolicyAdminInstance()
+            try:
+                (xspol, rc, errors) = poladmin.reset_acmpolicy()
+                if rc != 0:
+                    polstate.update( { 'xserr' : rc,
+                                       'errors': base64.b64encode(errors) } )
+                else:
+                    ref = xspol.get_ref()
+                    polstate = {
+                      'xs_ref' : ref,
+                      'flags'  : poladmin.get_policy_flags(xspol),
+                      'type'   : xstype,
+                      'repr'   : "",
+                      'version': xspol.get_version(),
+                      'errors' : base64.b64encode(errors),
+                      'xserr'  : rc,
+                    }
+            except Exception, e:
+                raise
+        else:
+            raise SecurityError(-xsconstants.XSERR_POLICY_TYPE_UNSUPPORTED)
+        return polstate
+
+
     def activate_xspolicy(self, flags):
         flags = int(flags)
         rc = -xsconstants.XSERR_GENERAL_FAILURE
@@ -162,6 +193,7 @@ class XendXSPolicy(XendBase):
     get_xstype      = classmethod(get_xstype)
     get_xspolicy    = classmethod(get_xspolicy)
     set_xspolicy    = classmethod(set_xspolicy)
+    reset_xspolicy  = classmethod(reset_xspolicy)
     rm_xsbootpolicy = classmethod(rm_xsbootpolicy)
     set_resource_label = classmethod(set_resource_label)
     get_resource_label = classmethod(get_resource_label)
xen-unstable.hg/tools/python/xen/xm/resetpolicy.py +3 -58

86 lines not on this page · raw message

"Try to halt all guests.")

xen-unstable.hg/docs/xen-api/xenapi-datamodel.tex +39 -0
Index: root/xen-unstable.hg/docs/xen-api/xenapi-datamodel.tex
===================================================================
@@ -14735,6 +14735,45 @@ xs\_policystate
 State information about the policy. In case an error occurred, the 'xs\_err'
 field contains the error code. The 'errors' may contain further information
 about the error.
+ \vspace{0.3cm}
+\vspace{0.3cm}
+\vspace{0.3cm}
+\subsubsection{RPC name:~reset\_xspolicy}
+
+{\bf Overview:}
+Attempt to reset the system's policy by installing the default policy.
+Since this function is implemented as an update to the current policy, it
+underlies the same restrictions. This function may fail if for example
+other domains than Domain-0 are running and use a different label than
+Domain-0
+
+\noindent {\bf Signature:}
+\begin{verbatim} xs_policystate reset_xspolicy (session_id s, xs_type type)
+\end{verbatim}
+
+\noindent{\bf Arguments:}
+
+\vspace{0.3cm}
+
+\begin{tabular}{|c|c|p{7cm}|}
+ \hline
+{\bf type} & {\bf name} & {\bf description} \\ \hline
+{\tt xs\_type } & type & the type of policy \\ \hline
+
+\end{tabular}
+
+\vspace{0.3cm}
+
+
+ \noindent {\bf Return Type:}
+{\tt
+xs\_policystate
+}
+
+
+State information about the policy. In case an error occurred, the 'xs\_err'
+field contains the error code. The 'errors' may contain further information
+about the error.
 \vspace{0.3cm}
 \vspace{0.3cm}
 \vspace{0.3cm}
xen-unstable.hg/tools/python/xen/util/xsm/dummy/dummy.py +4 -0
Index: root/xen-unstable.hg/tools/python/xen/util/xsm/dummy/dummy.py
===================================================================
@@ -21,6 +21,7 @@ xmlrpc_exports = [
   'list_labels',
   'get_labeled_resources',
   'set_policy',
+  'reset_policy',
   'get_policy',
   'activate_policy',
   'rm_bootpolicy',
@@ -102,6 +103,9 @@ def get_labeled_resources():
 def set_policy(xs_type, xml, flags, overwrite):
     err("Command not supported under xsm 'dummy' module.")
 
+def reset_policy():
+    err("Command not supported under xsm 'dummy' module.")
+
 def get_policy():
     return "", 0
 

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

#1 lore raw
Quoted 5 lines · Stefan Berger
xen-unstable.hg/docs/xen-api/xenapi-datamodel.tex +0 -0
@@ -14735,6 +14735,45 @@ xs\_policystate
 State information about the policy. In case an error occurred, the 'xs\_err'
 field contains the error code. The 'errors' may contain further information

xen-unstable.hg/docs/xen-api/xenapi-datamodel.tex xs\_policystate · line 14746

Quoted 10 lines
xen-unstable.hg/docs/xen-api/xenapi-datamodel.tex +9 -0
 about the error.
+ \vspace{0.3cm}
+\vspace{0.3cm}
+\vspace{0.3cm}
+\subsubsection{RPC name:~reset\_xspolicy}
+
+{\bf Overview:}
+Attempt to reset the system's policy by installing the default policy.
+Since this function is implemented as an update to the current policy, it
+underlies the same restrictions. This function may fail if for example

This might have happened before, but I just noticed that the API docs are being modified without any version control - or any indication of when new things were added.

Programming against such API docs is generally a horrible experience as you never have any idea what is there and what isn't.

Can we please start a changelog for the API, and version it appropriately?

thanks
john

#2 lore raw

[email protected] wrote on 12/10/2007 03:47:40 PM:

Quoted 8 lines · Stefan Berger

xen-unstable.hg/docs/xen-api/xenapi-datamodel.tex xs\_policystate · line 14735

Quoted 5 lines
xen-unstable.hg/docs/xen-api/xenapi-datamodel.tex +0 -0
@@ -14735,6 +14735,45 @@ xs\_policystate
 State information about the policy. In case an error occurred, 

the 'xs\_err'

Quoted 1 line
xen-unstable.hg/docs/xen-api/xenapi-datamodel.tex +0 -0
 field contains the error code. The 'errors' may contain further 

information

Quoted 8 lines

xen-unstable.hg/docs/xen-api/xenapi-datamodel.tex xs\_policystate

Quoted 8 lines
xen-unstable.hg/docs/xen-api/xenapi-datamodel.tex +7 -0
 about the error.
+ \vspace{0.3cm}
+\vspace{0.3cm}
+\vspace{0.3cm}
+\subsubsection{RPC name:~reset\_xspolicy}
+
+{\bf Overview:}
+Attempt to reset the system's policy by installing the default 

policy.

Quoted 1 line

xen-unstable.hg/docs/xen-api/xenapi-datamodel.tex xs\_policystate · line 14745

Quoted 1 line
xen-unstable.hg/docs/xen-api/xenapi-datamodel.tex +1 -0
+Since this function is implemented as an update to the current 

policy, it

Quoted 1 line

xen-unstable.hg/docs/xen-api/xenapi-datamodel.tex xs\_policystate · line 14746

Quoted 1 line
xen-unstable.hg/docs/xen-api/xenapi-datamodel.tex +1 -0
+underlies the same restrictions. This function may fail if for 

example

Quoted 10 lines

This might have happened before, but I just noticed that the API docs are being modified without any version control - or any indication of when new things were added.

Programming against such API docs is generally a horrible experience as you never have any idea what is there and what isn't.

Can we please start a changelog for the API, and version it appropriately?

Ok, I will do start a change log, increase the revision to 1.0.1 and adjust the date.

Thanks.

Stefan

Quoted 8 lines

thanks
john

_______________________________________________
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 2 lines · Stefan Berger

Ok, I will do start a change log, increase the revision to 1.0.1 and adjust the date.

Thanks a lot! Below are the only changes to that file in particular since 3.1 branched. I think my changes were clarification only, so it's just yours that need to be clearly labelled as 1.0.1.

regards
john

changeset:   16168:51f521303df7
user:        Keir Fraser <[email protected]>
date:        Thu Oct 11 09:41:16 2007 +0100
summary:     [vTPM] Add set/get_other_config to Xen-API.
changeset:   16081:2e5e948bf69d
user:        Keir Fraser <[email protected]>
date:        Wed Oct 03 14:04:51 2007 +0100
summary:     Extend 'xm dumppolicy' to support Xen-API
changeset:   15692:fdc602720f11
user:        [email protected]
date:        Thu Jul 19 17:00:31 2007 +0100
summary:     Update xen-api docs.
changeset:   15654:bd2f9628114e
user:        [email protected]
date:        Thu Jul 12 10:06:44 2007 +0100
summary:     [Docs] Documentation of extension of the Xen-API for managing security policies
changeset:   15593:73290f6fe70a
user:        [email protected]
date:        Tue Jul 10 10:22:41 2007 +0100
summary:     Xen API specification improvements.