certtools / intelmq-api

FastAPI-based API for the IntelMQ project
https://docs.intelmq.org/latest/user/api/
1 stars 7 forks source link

Broken on Ubuntu 22.04 due to upstream Ubuntu issue with python3-hug #40

Closed monoidic closed 1 year ago

monoidic commented 1 year ago

I attempted to install IntelMQ along with the manager and API on Ubuntu 22.04 using the native .deb packages and ran into the following error:

[Wed Jan 04 14:44:37.429885 2023] [wsgi:error] [pid 9227:tid 140271430239808] [client [redacted]] Traceback (most recent call last):, referer: [redacted]/management.html
[Wed Jan 04 14:44:37.429908 2023] [wsgi:error] [pid 9227:tid 140271430239808] [client [redacted]]   File "/usr/lib/python3/dist-packages/intelmq_api/intelmq-api.wsgi", line 11, in application, referer: [redacted]/management.html
[Wed Jan 04 14:44:37.429912 2023] [wsgi:error] [pid 9227:tid 140271430239808] [client [redacted]]     from intelmq_api.serve import __hug_wsgi__, referer: [redacted]/management.html
[Wed Jan 04 14:44:37.429916 2023] [wsgi:error] [pid 9227:tid 140271430239808] [client [redacted]]   File "/usr/lib/python3/dist-packages/intelmq_api/serve.py", line 31, in <module>, referer: [redacted]/management.html
[Wed Jan 04 14:44:37.429919 2023] [wsgi:error] [pid 9227:tid 140271430239808] [client [redacted]]     api.http.add_middleware(hug.middleware.CORSMiddleware(api, allow_origins=api_config.allow_origins)), referer: [redacted]/management.html
[Wed Jan 04 14:44:37.429922 2023] [wsgi:error] [pid 9227:tid 140271430239808] [client [redacted]]   File "falcon/middleware.py", line 39, in falcon.middleware.CORSMiddleware.__init__, referer: [redacted]/management.html
[Wed Jan 04 14:44:37.429933 2023] [wsgi:error] [pid 9227:tid 140271430239808] [client [redacted]] TypeError: __init__() got multiple values for keyword argument 'allow_origins', referer: [redacted]/management.html

While digging into this, I found that upstream, hug has version 2.0.0 of falcon pinned as a dependency, however, on Ubuntu 22.04, python3-hug depends on python3-falcon, which is at version 3.0.1. This causes an issue in hug/__init__.py in the following code:

from falcon import *
from hug import (
    ...
    middleware,
    ...
)

Since falcon 3.0.1 has a falcon.middleware module, it is imported by the * import, and the from hug import middleware reimports that same module instead of hug's own hug.middleware

This is, of course, not at all an issue on your end. It can, at least seemingly, be worked around by locally patching it like this:

from hug import middleware as _middleware
from falcon import *
middleware = _middleware
del _middleware

However, I have not audited this whatsoever beyond "I can seemingly use intelmq-manager". Does anyone have any ideas on how to solve or work around this problem? The two major ones that I can see right now are trying to get Canonical to fix their packaging of hug, and just going forward with the intelmq-api FastAPI rewrite that's being worked on by kamil-certat (assuming it does not have any similar issues with 22.04)

monoidic commented 1 year ago

Ubuntu bug report: https://bugs.launchpad.net/ubuntu/+source/python-falcon/+bug/2002297

sebix commented 1 year ago

Unfortunately hug has been abandoned upstream which was very surprising for many users of this library. hug was well supported and actively maintained, by very skilled and widely known python devs. That suddenly stopped 2020.

Fortunately @kamil-certat took the initiative and re-wrote the API to fastapi in #39 which solves this issue. At least if fastapi doesn't get abandoned as well =)

sebix commented 1 year ago

The upcoming version uses fastapi and not hug anymore thanks to @kamil-certat's #39

sebix commented 1 year ago

Fixed by version 3.2.0