Skip to content

rest_cherrypy's POST /keys does not allow selection of keysize #56425

Closed

Description

@johnnybubonic

Description of Issue

The documentation for /keys POST method states that:

Accepts all the same parameters as the key.gen_accept.

However, it seems to be impossible to specify a keysize larger than 2048.

Here's a snippet I'm using:

import requests

user = 'someuser'
password = 'somepasswd'

api_uri = 'https://my_api.tld'
api = requests.Session()
auth = api.post('{0}/login'.format(api_uri),
                headers = {'Accept': 'application/x-yaml'},
                data = {'username': user,
                        'password': password,
                        'eauth': 'ldap'})
# ...
keypair = api.post('{0}/keys'.format(api_uri),
                   data = {'mid': 'testminion',
                           'username': user,
                           'password': password,
                           # 'keysize': 4096,  # "A"
                           'keysize': '4096',  # "B"
                           'eauth': 'ldap'})
with open('/tmp/keys.tar', 'wb') as fh:
    fh.write(keypair.content)
# ...

Now, /tmp/keys.tar is indeed a tarball that contains a private and public key with method "B" - but it is always only 2048 bits (checked with openssl rsa -text -noout -in minion.pem).

With method "A", though, not only is a keypair not created, but the API throws the following exception:

[22/Mar/2020:02:21:01] HTTP 
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/cherrypy/_cprequest.py", line 670, in respond
    response.body = self.handler()
  File "/usr/lib/python3.6/site-packages/cherrypy/lib/encoding.py", line 217, in __call__
    self.body = self.oldhandler(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/cherrypy/_cpdispatch.py", line 60, in __call__
    return self.callable(*self.args, **self.kwargs)
  File "/usr/lib/python3.6/site-packages/salt/netapi/rest_cherrypy/app.py", line 1717, in POST
    pub_key = ret.get('pub', '')
AttributeError: 'str' object has no attribute 'get'

returning the following with a 500:

<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
    <title>500 Internal Server Error</title>
    <style type="text/css">
    #powered_by {
        margin-top: 20px;
        border-top: 2px solid black;
        font-style: italic;
    }

    #traceback {
        color: red;
    }
    </style>
</head>
    <body>
        <h2>500 Internal Server Error</h2>
        <p>The server encountered an unexpected condition which prevented it from fulfilling the request.</p>
        <pre id="traceback"></pre>
    <div id="powered_by">
      <span>
        Powered by <a href="http://www.cherrypy.org">CherryPy 5.6.0</a>
      </span>
    </div>
    </body>
</html>

Setup

N/A

Steps to Reproduce Issue

See above

Versions Report

Salt Version:
           Salt: 3000
 
Dependency Versions:
           cffi: 1.9.1
       cherrypy: unknown
       dateutil: Not Installed
      docker-py: Not Installed
          gitdb: 2.0.5
      gitpython: 2.1.11
         Jinja2: 2.10.3
        libgit2: Not Installed
       M2Crypto: 0.35.2
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.6.2
   mysql-python: 1.3.12
      pycparser: 2.14
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 3.6.8 (default, Aug  7 2019, 17:28:10)
   python-gnupg: Not Installed
         PyYAML: 3.12
          PyZMQ: 15.3.0
          smmap: 2.0.5
        timelib: Not Installed
        Tornado: 4.5.3
            ZMQ: 4.1.4
 
System Versions:
           dist: centos 7.7.1908 Core
         locale: UTF-8
        machine: x86_64
        release: 3.10.0-1062.12.1.el7.x86_64
         system: Linux
        version: CentOS Linux 7.7.1908 Core

And, in my attempts to be clever, I tried:

# (...)
resp = api.post('{0}/'.format(api_uri),
                data = {'client': 'local',
                        'fun': 'cmd.run',
                        'arg': ['testminion'],
                        'kwarg': {'keysize': '4096'}})
# (...)

(EDIT: Yes, I just realized this makes no sense; I was tired. Whoops!)

but this only returns another 500 with:

{"status": 500, "return": "An unexpected error occurred"}

Activity

  1. johnnybubonic commented on Mar 22, 2020

    @johnnybubonic
    Author

    additionally, more of a feature request than an issue, but the files in the tarball have a timestamp of UNIX Epoch. they should probably match time of request or time of generation.

    I have a PR in for this since it was a pretty trivial change and required no knowledge of Salt internals.

  2. Ch3LL commented on Mar 23, 2020

    @Ch3LL
    Contributor

    thanks for the pr!

  3. added
    bug
    severity-low
    P4
    on Mar 23, 2020
  4. added this to the Approved milestone on Mar 23, 2020
  5. removed
    P4
    on Jun 3, 2020
  6. added a commit that references this issue on Aug 7, 2026
  7. added a commit that references this issue on Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugseverity-low

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions