Skip to content

Commit 8c95d65

Browse files
committed
issue2551137, 2551138 - roundup-server SSL issues.
Python3 no longer supports socket._fileobject, so fake it using SocketIO and layering io.BufferedReader as in: https://bugs.launchpad.net/python-glanceclient/+bug/1812525 Also handle SSL.ZeroReturnError exception by ignoring it. This exception is thrown when the SSL layer has been closed and a read happens. There is a warning in openssl as well as python docs that the underlying (unencrypted) socket may not be closed. In manual testing, netstat -anp didn't show any unclosed socket so.... Could it leak a fd still, unknown. This also seesm to have fixed an error when running under python2 where socket shutdown throws an error. Maybe ignoring ZeroErrorREturn handled that case? Also added doc to man page recommending not using -s and using a real web server instead. Also added doc on format of pem file passed to -e. No automated testing on this, so no test updates 8-(.
1 parent aeb5f5a commit 8c95d65

File tree

3 files changed

+53
-5
lines changed

3 files changed

+53
-5
lines changed

CHANGES.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ Fixed:
3030
- added more testing of BasicDatabase to support use of SQLite
3131
for that purpose. Had to fix memory, rdbms and dbm edge cases
3232
due to new tests. (John Rouillard)
33+
- issue2551138 - roundup-server with ssl under python2 throws
34+
traceback on socket close. Not sure how this got fixed,
35+
but after fixing issue2551137 it was not an issue anymore.
36+
- issue2551137 - roundup-server won't run with ssl under python3
37+
Fixed by using SocketIO and manually adding buffering io and
38+
catching SSL.ZeroReturnError indicating SSL has been shut down.
3339

3440
Features:
3541

roundup/scripts/roundup_server.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ def readline(self, *args):
161161
return self.__fileobj.readline(*args)
162162
except SSL.WantReadError:
163163
time.sleep(.1)
164+
except SSL.ZeroReturnError:
165+
# Raised here on every request.
166+
# SSL connection has been closed.
167+
# But maybe not the underlying socket.
168+
# FIXME: Does this lead to a socket leak??
169+
# if so how to fix?
170+
pass
164171

165172
def read(self, *args):
166173
""" SSL.Connection can return WantRead """
@@ -169,6 +176,15 @@ def read(self, *args):
169176
return self.__fileobj.read(*args)
170177
except SSL.WantReadError:
171178
time.sleep(.1)
179+
except SSL.ZeroReturnError:
180+
# Put here to match readline() handling above.
181+
# Even though this never was the source of the
182+
# exception logged during use.
183+
# SSL connection has been closed.
184+
# But maybe not the underlying socket.
185+
# FIXME: Does this lead to a socket leak??
186+
# if so how to fix?
187+
pass
172188

173189
def __getattr__(self, attrib):
174190
return getattr(self.__fileobj, attrib)
@@ -180,8 +196,26 @@ def __init__(self, conn):
180196
self.__conn = conn
181197

182198
def makefile(self, mode, bufsize):
183-
fo = socket._fileobject(self.__conn, mode, bufsize)
184-
return RetryingFile(fo)
199+
fo = None
200+
try:
201+
# see below of url used for this
202+
fo = socket.SocketIO(self.__conn, mode)
203+
except AttributeError:
204+
# python 2 in use
205+
buffer = socket._fileobject(self.__conn, mode, bufsize)
206+
207+
if fo:
208+
# python3 set up buffering
209+
# verify mode is rb and bufsize is -1
210+
# implement subset of socket::makefile
211+
# https://bugs.launchpad.net/python-glanceclient/+bug/1812525
212+
if mode == 'rb' and bufsize == -1:
213+
buffering = io.DEFAULT_BUFFER_SIZE
214+
buffer = io.BufferedReader(fo, buffering)
215+
else:
216+
buffer = fo
217+
218+
return RetryingFile(buffer)
185219

186220
def __getattr__(self, attrib):
187221
return getattr(self.__conn, attrib)

share/man/man1/roundup-server.1

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,19 @@ front end server to authenticate a user and pass the user identity to
4545
roundup.
4646
.TP
4747
\fB-s\fP
48-
Enables use of SSL.
48+
Enables use of SSL. SSL only works when running the server using
49+
python 3. In most cases, you will want to run a real web server
50+
(Apache, Nginx) as a proxy to roundup-server running without SSL.
51+
The real web server can filter/rate limit/firewall requests to
52+
roundup-server.
4953
.TP
5054
\fB-e\fP \fIfile\fP
51-
Sets a filename containing the PEM file to use for SSL. If left blank, a
52-
temporary self-signed certificate will be used.
55+
Sets a filename containing the PEM file to use for SSL. The PEM file
56+
must include both the private key and certificate with appropriate
57+
headers (e.g. "-----BEGIN PRIVATE KEY-----", "-----END PRIVATE
58+
KEY-----" and "-----BEGIN CERTIFICATE-----", "-----END
59+
CERTIFICATE-----". If no file is specified, a temporary self-signed
60+
certificate will be used.
5361
.TP
5462
\fB-N\fP
5563
Log client machine names instead of IP addresses (much slower).

0 commit comments

Comments
 (0)