Bug 1490392

Summary: xmlrpclib does not support SSL context, needed for SSL verification
Product: Red Hat Enterprise Linux 7 Reporter: Rik Theys <rik.theys>
Component: pythonAssignee: Charalampos Stratakis <cstratak>
Status: CLOSED ERRATA QA Contact: Mirek Długosz <mzalewsk>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.4CC: aladen, cstratak, dcallagh, fedoraproject.org, jkejda, pviktori, rduda
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: python-2.7.5-62.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-04-10 15:00:08 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1527012    

Description Rik Theys 2017-09-11 12:56:18 UTC
Description of problem:
RHEL 7.4 enabled SSL verification by default for Python 2.7.

This feature was backported from python 2.7.9. However, python 2.7.9 supports "context" parameters for the xmlrpclib.ServerProxy class, which was not backported.

This means that with the new default of verifying SSL certificates, it is not possible to specify a custom CAfile for xmlrpclib connections as the context parameter is unknown.

It is also not known to the SafeTransport class, so this workaround can also not be used.


Version-Release number of selected component (if applicable):
python-2.7.5-58.el7.x86_64

How reproducible:
always

Steps to Reproduce:
1. Try to connect to an https xmlrpc server with a custom CA store
2.
3.

Actual results:

Python 2.7.5 (default, Aug  4 2017, 00:39:18) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>> import xmlrpclib
>>> ctx = ssl.create_default_context(purpose=ssl.Purpose.SERVER_AUTH, cafile="test.crt")
>>> s = xmlrpclib.ServerProxy("https://internal.server.com", context=ctx)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __init__() got an unexpected keyword argument 'context'
>>> s = xmlrpclib.ServerProxy("https://internal.server.com", transport=xmlrpclib.SafeTransport(context=ctx))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __init__() got an unexpected keyword argument 'context'
>>> 


Expected results:
That the context parameter is known by either the ServerProxy class or the SafeTransport class.


Additional info:

Comment 2 Charalampos Stratakis 2017-09-14 15:35:16 UTC
Hello.

It is possible to disable the certificate verification by using the config file /etc/python/cert-verification.cfg as it is described here [0].

I believe that is the upstream issue for that bug [1]. Will dig a bit further.

[0] https://access.redhat.com/articles/2039753

[1] https://bugs.python.org/issue22960

Comment 3 Rik Theys 2017-09-14 18:43:30 UTC
Hi,

I am aware that I can disable it system-wide, but it would disable it for all scripts.

The bug you refer to has been fixed and newer versions of the 2.7 series support additional "context" parameters to most functions that could use https.

It seems only the certificate validation feature was backported, but not the extra parameters on those functions.

As you see in the documentation for current 2.7 versions, xmlrpclib.ServerProxy supports a "context" parameter:

https://docs.python.org/2.7/library/xmlrpclib.html

Regards,

Rik

Comment 5 Dan Callaghan 2017-10-17 09:00:27 UTC
I don't think this patch was backported properly. With python-2.7.5-62.el7.x86_64 I get this exception:

Python 2.7.5 (default, Oct 11 2017, 10:12:42) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import xmlrpclib
>>> s = xmlrpclib.ServerProxy('https://beaker.engineering.redhat.com/')
>>> s.auth.who_am_i()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/xmlrpclib.py", line 1233, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib64/python2.7/xmlrpclib.py", line 1591, in __request
    verbose=self.__verbose
  File "/usr/lib64/python2.7/xmlrpclib.py", line 1273, in request
    return self.single_request(host, handler, request_body, verbose)
  File "/usr/lib64/python2.7/xmlrpclib.py", line 1293, in single_request
    h = self.make_connection(host)
  File "/usr/lib64/python2.7/xmlrpclib.py", line 1509, in make_connection
    self._connection = host, HTTPS(chost, None, context=context, **(x509 or {}))
NameError: global name 'context' is not defined

A Beaker user reported this as it breaks beaker-client which uses xmlrpclib.

Comment 6 Dan Callaghan 2017-10-17 09:03:18 UTC
I am guessing in this hunk of the offending patch:

 63 @@ -1493,7 +1497,7 @@ class SafeTransport(Transport):
 64                  )
 65          else:
 66              chost, self._extra_headers, x509 = self.get_host_info(host)
 67 -            self._connection = host, HTTPS(chost, None, **(x509 or {}))
 68 +            self._connection = host, HTTPS(chost, None, context=context, **(x509 or {}))
 69              return self._connection[1]
 70  
 71  ##

it was supposed to be context=self.context. If you hunt upstream you might find a fixup commit which changes that. I notice that on my Fedora box (with latest Python 2.7.x) that line does indeed have context=self.context.

Comment 7 Charalampos Stratakis 2017-10-17 09:14:43 UTC
Good catch. The exact next commit after the initial patch is :

https://github.com/python/cpython/commit/ee44314f9309b7b89dd5a7d897f0f917e9e47b1a#diff-1abc359a7923ab5abc19d0ccde812440

Comment 11 errata-xmlrpc 2018-04-10 15:00:08 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2018:0833