Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

salt_cherrypy with Python3 and complex CORS OPTION requests return HTTP 500 #55087

Closed
niflostancu opened this issue Oct 22, 2019 · 1 comment · Fixed by #55207
Closed

salt_cherrypy with Python3 and complex CORS OPTION requests return HTTP 500 #55087

niflostancu opened this issue Oct 22, 2019 · 1 comment · Fixed by #55207
Labels
Bug broken, incorrect, or confusing behavior fixed-pls-verify fix is linked, bug author to confirm fix P4 Priority 4
Milestone

Comments

@niflostancu
Copy link
Contributor

niflostancu commented Oct 22, 2019

Description of Issue

I am trying to use salt_cherrypy from a browser application (uses complex CORS), but the OPTION requests return 500 error and the following exception from CherryPy:
ValueError: Page handlers MUST return bytes. Use tools.encode if you wish to return unicode at salt/netapi/rest_cherrypy/app.py:824 (see below for full traceback).

A related issue on CherryPy might be cherrypy/cherrypy#1123

Setup

Relevant master config (SSL from letsencrypt):

rest_cherrypy:
  port: 8000
  ssl_crt: /etc/letsencrypt/live/***/fullchain.pem
  ssl_key: /etc/letsencrypt/live/***/privkey.pem

Steps to Reproduce Issue

Running (JavaScript, browser fetch API):

fetch("https://saltstack.domain:8000/login", 
     method: "POST",
     headers: {"Accept": "application/json", "Content-Type": "application/json"},
     body: JSON.stringify({username: "***", password: "***", eauth: "file"},     
)

Results in HTTP 500 on the OPTION request on the browser + the following log from salt-api:

[ERROR   ] [22/Oct/2019:08:57:17]  Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/cherrypy/_cprequest.py", line 104, in run
    hook()
  File "/usr/lib/python3/dist-packages/cherrypy/_cprequest.py", line 63, in __call__
    return self.callback(**self.kwargs)
  File "/usr/lib/python3/dist-packages/salt/netapi/rest_cherrypy/app.py", line 824, in cors_tool
    cherrypy.response.body = ''
  File "/usr/lib/python3/dist-packages/cherrypy/__init__.py", line 231, in __setattr__
    setattr(child, name, value)
  File "/usr/lib/python3/dist-packages/cherrypy/_cprequest.py", line 816, in __set__
    raise ValueError(self.unicode_err)
ValueError: Page handlers MUST return bytes. Use tools.encode if you wish to return unicode.

Workaround

I manually modified salt/netapi/rest_cherrypy/app.py:824 into:

        cherrypy.response.body = bytes('', 'UTF-8')

And the error was fixed.
Can this be fixed on master or should I come with a pull request (it's a pretty trivial change)?

Versions Report

Salt Version:
           Salt: 2019.2.1

Dependency Versions:
           cffi: Not Installed
       cherrypy: 3.5.0
       dateutil: 2.4.2
      docker-py: Not Installed
          gitdb: 0.6.4
      gitpython: 1.0.1
          ioflo: Not Installed
         Jinja2: 2.8
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 3.5.2 (default, Oct  8 2019, 13:06:37)
   python-gnupg: 0.3.8
         PyYAML: 3.11
          PyZMQ: 15.2.0
           RAET: Not Installed
          smmap: 0.9.0
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4

System Versions:
           dist: Ubuntu 16.04 xenial
         locale: UTF-8
        machine: x86_64
        release: 4.15.0-65-generic
         system: Linux
        version: Ubuntu 16.04 xenial

Thanks.

@niflostancu niflostancu changed the title salt_cherrypy with Python3 and complex CORS complains about encoding in response salt_cherrypy with Python3 and complex CORS OPTION requests return HTTP 500 Oct 22, 2019
@xeacott
Copy link
Contributor

xeacott commented Oct 25, 2019

Go ahead and generate a PR and target master. We'll continue the conversation in there. I also do not know if there are tests for this module but a PR would require a partner test with the change, regardless of how trivial the change is but please submit one!

@xeacott xeacott added Bug broken, incorrect, or confusing behavior fixed-pls-verify fix is linked, bug author to confirm fix P4 Priority 4 labels Oct 25, 2019
@xeacott xeacott added this to the Approved milestone Oct 25, 2019
niflostancu added a commit to niflostancu/salt that referenced this issue Dec 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior fixed-pls-verify fix is linked, bug author to confirm fix P4 Priority 4
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants