Skip to content

Issues with api_key_generator.py for Tanner_API/Tanner_Web #441

@cafiore7

Description

@cafiore7

When the tanner_api Docker container spins up it outputs the following error and exits

tanner_api    | Traceback (most recent call last):
tanner_api    |   File "/opt/tanner/tanner-env/bin/tannerapi", line 4, in <module>
tanner_api    |     __import__('pkg_resources').run_script('Tanner==0.6.0', 'tannerapi')
tanner_api    |   File "/opt/tanner/tanner-env/lib/python3.9/site-packages/pkg_resources/__init__.py", line 651, in run_script
tanner_api    |     self.require(requires)[0].run_script(script_name, ns)
tanner_api    |   File "/opt/tanner/tanner-env/lib/python3.9/site-packages/pkg_resources/__init__.py", line 1455, in run_script
tanner_api    |     exec(script_code, namespace, namespace)
tanner_api    |   File "/opt/tanner/tanner-env/lib/python3.9/site-packages/Tanner-0.6.0-py3.9.egg/EGG-INFO/scripts/tannerapi", line 20, in <module>
tanner_api    |   File "/opt/tanner/tanner-env/lib/python3.9/site-packages/Tanner-0.6.0-py3.9.egg/EGG-INFO/scripts/tannerapi", line 16, in main
tanner_api    |   File "/opt/tanner/tanner-env/lib/python3.9/site-packages/Tanner-0.6.0-py3.9.egg/tanner/api/server.py", line 116, in start
tanner_api    |   File "/opt/tanner/tanner-env/lib/python3.9/site-packages/Tanner-0.6.0-py3.9.egg/tanner/utils/api_key_generator.py", line 8, in generate
tanner_api    | AttributeError: 'str' object has no attribute 'decode'
tanner_api exited with code 1

In the tanner documentation we can see that the api_key is appended to certain endpoints for metrics

I believe this error is due to the api_key_generator.py script using outdated syntax from a previous version of python. specifically

  1. The jwt.encode() function returns a string (not bytes) in the latest versions of PyJWT (>=2.0).
  2. Since it's already a string, calling .decode("utf-8") on it causes an error in Python 3.

One solution to this might be to change the script to something like

import jwt
from tanner.config import TannerConfig

def generate():
    key = TannerConfig.get("API", "auth_signature")
    encoded = jwt.encode({"user": "tanner_owner"}, key, algorithm="HS256")

    if isinstance(encoded, bytes):  
        return encoded.decode("utf-8")  # Only decode if it's bytes
    return encoded  # Return directly if it's already a string

Screenshot:

Image

There is another open issue with tanner that I believe is related to this, submitted approx. 3 weeks ago without response

Please see the the following screenshots showing that...

The Tanner web instance is up:

Image

The Snare instance is up and connected:

Image

We can get to the primary page for the Snare instance:

Image

The Snare-Stats Page returns a 500 error:

Image

The Sessions Page Returns a 500 error:

Image

Note I have not tried switching to Python 2 as the Tanner project states it was tested on Python 3.7, additionally Python 2 is severely deprecated

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions