Project

General

Profile

Bug #42651

mgr/dashboard: error when editing rbd image whose name contains non-ASCII chars.

Added by Alfonso Martínez 11 months ago. Updated 4 months ago.

Status:
Resolved
Priority:
Normal
Assignee:
Category:
dashboard/rbd
Target version:
% Done:

0%

Source:
Tags:
Backport:
Regression:
No
Severity:
3 - minor
Reviewed:
Affected Versions:
ceph-qa-suite:
Pull request ID:
Crash signature:

Description

Verified for this environment:
OS: CentOS 7
Python version: 2.7.5

After creating rbd image with name like "año" (non-ASCII chars: ñ),
if you try to edit image, you get an error:

2019-10-30T19:34:33.269+0000 7f8ca4be6700  0 mgr[dashboard] [30/Oct/2019:19:34:33]  Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/cherrypy/_cprequest.py", line 102, in run
    hook()
  File "/usr/lib/python2.7/site-packages/cherrypy/_cprequest.py", line 62, in __call__
    return self.callback(**self.kwargs)
  File "/ceph/src/pybind/mgr/dashboard/tools.py", line 53, in request_begin
    req.method, user, req.path_info)
  File "/usr/lib64/python2.7/logging/__init__.py", line 1137, in debug
    self._log(DEBUG, msg, args, **kwargs)
  File "/usr/lib64/python2.7/logging/__init__.py", line 1268, in _log
    self.handle(record)
  File "/usr/lib64/python2.7/logging/__init__.py", line 1278, in handle
    self.callHandlers(record)
  File "/usr/lib64/python2.7/logging/__init__.py", line 1318, in callHandlers
    hdlr.handle(record)
  File "/usr/lib64/python2.7/logging/__init__.py", line 749, in handle
    self.emit(record)
  File "/ceph/src/pybind/mgr/mgr_module.py", line 65, in emit
    self._module._ceph_log(ceph_level, self.format(record))
  File "/usr/lib64/python2.7/logging/__init__.py", line 724, in format
    return fmt.format(record)
  File "/usr/lib64/python2.7/logging/__init__.py", line 464, in format
    record.message = record.getMessage()
  File "/usr/lib64/python2.7/logging/__init__.py", line 328, in getMessage
    msg = msg % self.args
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 21: ordinal not in range(128)

It seems that this line is the origin:
https://github.com/ceph/ceph/blob/master/src/pybind/mgr/dashboard/tools.py#L52

logger.debug('[%s:%s] [%s] [%s] %s', req.remote.ip, req.remote.port,
                     req.method, user, req.path_info)

History

#1 Updated by Ricardo Dias 11 months ago

The issue can be reproduced with the following example:

from __future__ import unicode_literals
import logging

logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.DEBUG)

log.debug("%s", b"ñ")

And it can be fixed by changing the last line to:

log.debug("%s", b"ñ".decode('utf-8'))

This means that maybe we should add some `.decode('utf-8')` to the strings passed to that logger call.

AFAICT this issue only happens in python2, if octopus will only support python3 then we just need to fix the nautilus version.

#2 Updated by Lenz Grimmer 11 months ago

  • Assignee set to Kiefer Chang

#3 Updated by Ernesto Puerta 11 months ago

  • Assignee deleted (Kiefer Chang)
An extra couple of ideas:

#4 Updated by Ernesto Puerta 11 months ago

  • Assignee set to Kiefer Chang

#5 Updated by Kiefer Chang 10 months ago

AFAICT this issue only happens in python2, if octopus will only support python3 then we just need to fix the nautilus version.

Confirmed that this doesn't happen in python3.

#6 Updated by Kiefer Chang 10 months ago

(In python2)

With

diff --git a/src/pybind/mgr/dashboard/tools.py b/src/pybind/mgr/dashboard/tools.py
index 7eb23e535b..af03000b2a 100644
--- a/src/pybind/mgr/dashboard/tools.py
+++ b/src/pybind/mgr/dashboard/tools.py
@@ -44,7 +44,7 @@ class RequestLoggingTool(cherrypy.Tool):
         user = JwtManager.get_username()
         # Log the request.
         logger.debug('[%s:%s] [%s] [%s] %s', req.remote.ip, req.remote.port,
-                     req.method, user, req.path_info)
+                     req.method, user, req.path_info.decode('utf-8'))
         # Audit the request.
         if Settings.AUDIT_API_ENABLED and req.method not in ['GET']:
             url = build_url(req.remote.ip, scheme=req.scheme,

I'm getting encoding error:

2019-11-12 09:25:32.402 7faeec78a700  0 mgr[dashboard] [12/Nov/2019:09:25:32]
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/cherrypy/_cprequest.py", line 104, in run
    hook()
  File "/usr/lib/python2.7/site-packages/cherrypy/_cprequest.py", line 63, in __call__
    return self.callback(**self.kwargs)
  File "/ceph/src/pybind/mgr/dashboard/tools.py", line 47, in request_begin
    req.method, user, req.path_info.decode('utf-8'))
  File "/usr/lib64/python2.7/logging/__init__.py", line 1155, in debug
    self._log(DEBUG, msg, args, **kwargs)
  File "/usr/lib64/python2.7/logging/__init__.py", line 1286, in _log
    self.handle(record)
  File "/usr/lib64/python2.7/logging/__init__.py", line 1296, in handle
    self.callHandlers(record)
  File "/usr/lib64/python2.7/logging/__init__.py", line 1336, in callHandlers
    hdlr.handle(record)
  File "/usr/lib64/python2.7/logging/__init__.py", line 759, in handle
    self.emit(record)
  File "/ceph/src/pybind/mgr/mgr_module.py", line 65, in emit
    self._module._ceph_log(ceph_level, self.format(record))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf1' in position 59: ordinal not in range(128)

Start mgr daemon with PYTHONIOENCODING=utf-8 doesn't help either.

But with

diff --git a/src/pybind/mgr/dashboard/tools.py b/src/pybind/mgr/dashboard/tools.py
index 7eb23e535b..a5166e8a98 100644
--- a/src/pybind/mgr/dashboard/tools.py
+++ b/src/pybind/mgr/dashboard/tools.py
@@ -43,6 +43,8 @@ class RequestLoggingTool(cherrypy.Tool):
         req = cherrypy.request
         user = JwtManager.get_username()
         # Log the request.
+        if user is not None:
+            user = user.encode('utf-8')
         logger.debug('[%s:%s] [%s] [%s] %s', req.remote.ip, req.remote.port,
                      req.method, user, req.path_info)
         # Audit the request.

The exception is gone and the message is logged (but año becomes a\xc3\xb1o). The only variable in `unicode` type in this line is user, others are in `str`

#7 Updated by Kiefer Chang 10 months ago

  • Status changed from New to In Progress

#8 Updated by Kiefer Chang 10 months ago

  • Pull request ID set to 31586

#9 Updated by Nathan Cutler 10 months ago

Kiefer Chang wrote:

AFAICT this issue only happens in python2, if octopus will only support python3 then we just need to fix the nautilus version.

Confirmed that this doesn't happen in python3.

Please add this info to the actual commit message, so it's available in the git history.

#10 Updated by Lenz Grimmer 4 months ago

  • Status changed from In Progress to Resolved
  • Target version changed from v15.0.0 to v14.2.10

Also available in: Atom PDF