SaltGUI: Job listing breaks after using x509v2 states on salt 3006.1
Describe the bug I am testing the new x509v2 saltstates here https://docs.saltproject.io/en/master/ref/states/all/salt.states.x509_v2.html .
It seems like as soon as I issue any certs using states like x509.pem_managed or x509.certificate_managed saltgui only shows “(error)” for anything listing jobs. Inside the api log on debug I get:
2023-07-13 01:55:32,312 [salt.loaded.int.netapi.rest_cherrypy.app:917 ][DEBUG ][46961] Could not serialize the return data from Salt.
Traceback (most recent call last):
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/netapi/rest_cherrypy/app.py", line 913, in hypermedia_handler
response = out(ret)
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/json.py", line 137, in dumps
return json_module.dumps(obj, **kwargs)
File "/opt/saltstack/salt/lib/python3.10/json/__init__.py", line 238, in dumps
**kw).encode(obj)
File "/opt/saltstack/salt/lib/python3.10/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/opt/saltstack/salt/lib/python3.10/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/opt/saltstack/salt/lib/python3.10/json/encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type bytes is not JSON serializable
To Reproduce
- Install saltgui as stated in the readme.
- Follow the example https://docs.saltproject.io/en/master/ref/states/all/salt.states.x509_v2.html
- Once you apply x509.pem_managed or x509.certificate_managed states the jobs list will break in saltgui.
Expected behaviour The jobs listing not breaking.
Screenshots
Additional context I’ll do more testing this week to try and narrow this down…maybe its just a bug in the new x509v2 code? Figured I’d open it here since its where I noticed the issue, as the states run and generate certs, but seem to break the job cache lists?
Thanks again for this great ui! Please let me know if there is anything I can do or research to help!
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 36 (20 by maintainers)
I’d like too I just haven’t had time to thoroughly post the issue.
The workaround should go in
netapi/rest_cherrypy/app.py
(forget aboutjson_out.py
)add the following function (anywhere in that file):
add the following code in function
hypermedia_handler
, just beforeresponse = out(ret)
:Restart both salt-api and salt-master.
The result no longer crashes the salt-api, and thus SaltGUI can present the results. In this case, the presence of the public_key in the function arguments means that the display on the screen for an individual job is lousy and will need improvement. see https://github.com/erwindon/SaltGUI/pull/533
In theory I should be able to trigger this with a curl command similar to what saltgui is requesting correct?
Is this the related issue you were referring to? https://github.com/saltstack/salt/issues/59620
I also notice in trace log_level I can see a byte string for the ‘public_key’ is in bytes in the salt-api logs:
that would help me too since I could not reproduce the effect even with the info from https://github.com/erwindon/SaltGUI/issues/532#issuecomment-1634839759
indeed! see https://github.com/saltstack/salt/issues but you need to provide a really simple reproducer with the ticket. something that does not need other sls includefiles or directories like /etc/clusterca, output for one minion only, etc. I would appreciate it when you post the url of that ticket here. btw, I will close this ticket after that since there is nothing I can change in SaltGUI that helps against this
I can trim down a salt state to trigger this easily if needed. I realized my state was based around having pillar and such already configured.
HTTP code 500 indicated the the server crashed (here for this request only) typically that means a python exception was raised while working on the request but an error the backend-code itself is not that fatal, by failure in the conversion to json is since that happens only in salt-api (and not in salt commands) the dev-team does not always spot it
Ack sorry. Here’s the right one?
that is the full filename for me too
no you need to select the “500” line. the line with “events?token=” is just the event-stream (see page “Events”) that one works fine, it was just interrupted
I am currently trying to narrow this down to where it starts failing…
@tazaki
I’m sure this error is in salt-api itself. It would also appear if you use the salt-api with another application (e.g. in a shell script using curl/wget)
salt-api uses a REST interface that has a JSON encoding style. but internally, saltstack uses Python code which has the ability to use data that cannot be converted to JSON when that data ends up in a response that triggers the error you see.
We have seen this type of error before in the
/stats
api while also using settingcollect_stats=true
. in that specific case, the return data had a bytes-string as the value for some field. I think that one was solved btwcan you supply me with a minimal states-file that triggers the error? can you see which api-call triggers the error? should be visible in the debug-view of the browser in section “network”.