lyft / confidant

Confidant: your secret keeper. https://lyft.github.io/confidant

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: a bytes-like object is required, not 'str'

jrosco opened this issue · comments

commented

Seeing the following error running Confidant version 5.2.0 using Docker image lyft/confidant:5.1.0

Environment:

Running build from Docker container
Running version 5.2.0
Using the following SAML Environment Vars set (these settings work in version 4)

USER_AUTH_MODULE=saml
SAML_SP_CERT_FILE=/srv/certificates/saml.sp.cert
SAML_SP_KEY_FILE=/srv/certificates/saml.sp.key
SAML_SECURITY_SLO_RESP_SIGNED=false
SAML_SECURITY_ASSERTIONS_SIGNED=true
SAML_IDP_CERT_FILE=/srv/certificates/saml.idp.cert
SAML_SECURITY_MESSAGES_SIGNED=false

Seeing a type error TypeError: a bytes-like object is required, not 'str' Error
(see below log)

ERROR:confidant.app:Exception on /v1/login [GET]
Traceback (most recent call last):
  File "/venv/lib/python3.6/site-packages/flask/app.py", line 2446, in wsgi_app
    response = self.full_dispatch_request()
  File "/venv/lib/python3.6/site-packages/flask/app.py", line 1951, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/venv/lib/python3.6/site-packages/flask/app.py", line 1820, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/venv/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/venv/lib/python3.6/site-packages/flask/app.py", line 1949, in full_dispatch_request
    rv = self.dispatch_request()
  File "/venv/lib/python3.6/site-packages/flask/app.py", line 1935, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/srv/confidant/confidant/routes/v1.py", line 38, in login
    return authnz.log_in()
  File "/srv/confidant/confidant/authnz/__init__.py", line 139, in log_in
    return user_mod.log_in()
  File "/srv/confidant/confidant/authnz/userauth.py", line 558, in log_in
    return flask.redirect(self.login_redirect_url(return_to=self_page))
  File "/srv/confidant/confidant/authnz/userauth.py", line 816, in login_redirect_url
    auth = self._saml_auth()
  File "/srv/confidant/confidant/authnz/userauth.py", line 723, in _saml_auth
    auth = OneLogin_Saml2_Auth(req_dict, self.saml_config)
  File "/venv/lib/python3.6/site-packages/onelogin/saml2/auth.py", line 54, in __init__
    self.__settings = OneLogin_Saml2_Settings(old_settings, custom_base_path)
  File "/venv/lib/python3.6/site-packages/onelogin/saml2/settings.py", line 128, in __init__
    self.format_sp_key()
  File "/venv/lib/python3.6/site-packages/onelogin/saml2/settings.py", line 759, in format_sp_key
    self.__sp['privateKey'] = OneLogin_Saml2_Utils.format_private_key(self.__sp['privateKey'])
  File "/venv/lib/python3.6/site-packages/onelogin/saml2/utils.py", line 167, in format_private_key
    private_key = key.replace('\x0D', '')
TypeError: a bytes-like object is required, not 'str'

This might be a bug in the SAML2 python Lib https://github.com/onelogin/python3-saml/blob/master/src/onelogin/saml2/utils.py#L154

:param key A private key
:type: string

It asks for a String but complains TypeError: a bytes-like object is required, not 'str' or something with the format of my keys.

Let me track down if this is something we can workaround from the confidant side.

I think this is due to how we're loading the key into the settings. Sorry to fix one step of this at a time, it's not something I can easily test directly.

commented

@ryan-lane Sure, no worries. I'm happy to help work through these issues.

@jrosco released in 6.2.0. Sorry it took us so long on this, we were focusing on getting 6.0.0 and 6.1.0 out.