latenighttales / alcali

Featureful Saltstack GUI
https://alcali.dev
MIT License
356 stars 61 forks source link

Can't login as superuser: AttributeError: 'str' object has no attribute 'decode' #340

Closed ggiesen closed 3 years ago

ggiesen commented 3 years ago

Describe the bug When login in as an admin user created using manage.py, I get tracebacks from alcali:

2021-05-17 01:07:31 -0500] [3437990] [DEBUG] POST /api/token/
Internal Server Error: /api/token/
Traceback (most recent call last):
  File "/opt/alcali/.venv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/opt/alcali/.venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/opt/alcali/.venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/opt/alcali/.venv/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/opt/alcali/.venv/lib/python3.6/site-packages/django/views/generic/base.py", line 71, in view
    return self.dispatch(request, *args, **kwargs)
  File "/opt/alcali/.venv/lib/python3.6/site-packages/rest_framework/views.py", line 505, in dispatch
    response = self.handle_exception(exc)
  File "/opt/alcali/.venv/lib/python3.6/site-packages/rest_framework/views.py", line 465, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/opt/alcali/.venv/lib/python3.6/site-packages/rest_framework/views.py", line 476, in raise_uncaught_exception
    raise exc
  File "/opt/alcali/.venv/lib/python3.6/site-packages/rest_framework/views.py", line 502, in dispatch
    response = handler(request, *args, **kwargs)
  File "/opt/alcali/.venv/lib/python3.6/site-packages/rest_framework_simplejwt/views.py", line 27, in post
    serializer.is_valid(raise_exception=True)
  File "/opt/alcali/.venv/lib/python3.6/site-packages/rest_framework/serializers.py", line 234, in is_valid
    self._validated_data = self.run_validation(self.initial_data)
  File "/opt/alcali/.venv/lib/python3.6/site-packages/rest_framework/serializers.py", line 436, in run_validation
    value = self.validate(value)
  File "/opt/alcali/code/api/serializers.py", line 152, in validate
    data = super().validate(attrs)
  File "/opt/alcali/.venv/lib/python3.6/site-packages/rest_framework_simplejwt/serializers.py", line 75, in validate
    data['refresh'] = str(refresh)
  File "/opt/alcali/.venv/lib/python3.6/site-packages/rest_framework_simplejwt/tokens.py", line 82, in __str__
    return token_backend.encode(self.payload)
  File "/opt/alcali/.venv/lib/python3.6/site-packages/rest_framework_simplejwt/backends.py", line 43, in encode
    return token.decode('utf-8')
AttributeError: 'str' object has no attribute 'decode'

To Reproduce Steps to reproduce the behavior:

  1. Create admin user:

(.venv) [alcali@host code]$ ./manage.py createsuperuser

  1. Start alcali:

(.venv) [alcali@host code]$ /opt/alcali/.venv/bin/gunicorn config.wsgi:application --bind 0.0.0.0:5001 -w 8 -t 300 --log-level debug

  1. Attempt to log into Alcali at http://192.0.2.1:5001/#/login

  2. See error

Expected behavior To be logged into alcali

Additional context Running on CentOS 8

(.venv) [alcali@host code]$ pip freeze
ansi2html==1.5.2
asgiref==3.3.4
certifi==2020.12.5
chardet==3.0.4
Django==3.0.5
django-auth-ldap==2.1.1
django-cors-headers==3.2.1
django-currentuser==0.5.0
djangorestframework==3.11.0
djangorestframework-simplejwt==4.4.0
gunicorn==20.0.4
idna==2.10
psycopg2==2.8.6
pyasn1==0.4.8
pyasn1-modules==0.2.8
PyJWT==2.1.0
python-dotenv==0.12.0
python-ldap==3.2.0
pytz==2021.1
requests==2.23.0
salt-pepper==0.7.5
six==1.16.0
sqlparse==0.4.1
typing-extensions==3.10.0.0
urllib3==1.25.11
whitenoise==5.0.1
(.venv) [alcali@host code]$ cat .env
# Salt managed configuration
DB_BACKEND="postgresql"
DB_NAME="salt"
DB_USER="salt"
DB_PASS="roloocieng7ieSuh3ab6ohwahrae3qua"
DB_HOST="localhost"
DB_PORT="5432"
MASTER_MINION_ID="master"
SECRET_KEY="9QdeFV44Ep63xvUNGqzmtuMGzvzs6ckHHaHp5eECMFyR6uzTcHeDPYlRUk5jfsyg"
ALLOWED_HOSTS="*"
SALT_URL="https://127.0.0.1:8080"
SALT_AUTH="rest"
AUTH_BACKEND="ldap"
AUTH_LDAP_SERVER_URI="ldaps://ldap-server.example.com"
AUTH_LDAP_START_TLS="True"
AUTH_LDAP_BIND_DN="CN=Service Account,OU=Service Accounts,DC=example,DC=com"
AUTH_LDAP_BIND_PASSWORD="phoo7Aesi5eim1us"
AUTH_LDAP_USER_BASE_CN="DC=example,DC=com"
DJANGO_DEBUG="True"
(.venv) [alcali@host code]$ cat /etc/salt/master.d/alcali.conf
rest_cherrypy:
  port: 8080
  host: 0.0.0.0
  debug: True
  ssl_crt: /etc/pki/tls/certs/cert.crt
  ssl_key: /etc/pki/tls/private/cert.key

external_auth:
  rest:
    ^url: http://127.0.0.1:5001/api/token/verify/
    admin:
      - .*
      - '@runner'
      - '@wheel'
ggiesen commented 3 years ago

Solved this. I had set the formula to use the master branch assuming it'd be the most recent version (it was not). I set to v3003.1.0 and resolved the issue.