Using request() methods on session objects with Token plugins break

Bug #1910788 reported by Lance Bragstad
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
keystoneauth
Invalid
Undecided
Unassigned

Bug Description

If you instantiate a Session object with an existing token using the Token authentication plugin, requests invoked via the session object fail.

For example:

    auth = keystoneauth1.identity.v3.TokenMethod(token=context.auth_token)
    #auth = glance_context._ContextAuthPlugin(context.auth_token))
    return ks_session.Session(auth=auth)

Will result in the following when you try to call session.post(..):

mo] Caught error: 'TokenMethod' object has no attribute 'get_headers': AttributeError: 'TokenMethod' object has no attribute 'get_headers'
Jan 08 17:35:57 guaranine <email address hidden>[174194]: ERROR glance.common.wsgi Traceback (most recent call last):
Jan 08 17:35:57 guaranine <email address hidden>[174194]: ERROR glance.common.wsgi File "/opt/stack/glance/glance/common/wsgi.py", line 1347, in __call__
Jan 08 17:35:57 guaranine <email address hidden>[174194]: ERROR glance.common.wsgi action_result = self.dispatch(self.controller, action,
Jan 08 17:35:57 guaranine <email address hidden>[174194]: ERROR glance.common.wsgi File "/opt/stack/glance/glance/common/wsgi.py", line 1391, in dispatch
Jan 08 17:35:57 guaranine <email address hidden>[174194]: ERROR glance.common.wsgi return method(*args, **kwargs)
Jan 08 17:35:57 guaranine <email address hidden>[174194]: ERROR glance.common.wsgi File "/opt/stack/glance/glance/common/utils.py", line 416, in wrapped
Jan 08 17:35:57 guaranine <email address hidden>[174194]: ERROR glance.common.wsgi return func(self, req, *args, **kwargs)
Jan 08 17:35:57 guaranine <email address hidden>[174194]: ERROR glance.common.wsgi File "/opt/stack/glance/glance/api/v2/images.py", line 337, in import_image
Jan 08 17:35:57 guaranine <email address hidden>[174194]: ERROR glance.common.wsgi return self._proxy_import_to_host(image, req, body)
Jan 08 17:35:57 guaranine <email address hidden>[174194]: ERROR glance.common.wsgi File "/opt/stack/glance/glance/api/v2/images.py", line 233, in _proxy_import_to_host
Jan 08 17:35:57 guaranine <email address hidden>[174194]: ERROR glance.common.wsgi r = client.post(url, json=body)
Jan 08 17:35:57 guaranine <email address hidden>[174194]: ERROR glance.common.wsgi File "/usr/local/lib/python3.8/dist-packages/keystoneauth1/session.py", line 1139, in post
Jan 08 17:35:57 guaranine <email address hidden>[174194]: ERROR glance.common.wsgi return self.request(url, 'POST', **kwargs)
Jan 08 17:35:57 guaranine <email address hidden>[174194]: ERROR glance.common.wsgi File "/usr/local/lib/python3.8/dist-packages/keystoneauth1/session.py", line 780, in request
Jan 08 17:35:57 guaranine <email address hidden>[174194]: ERROR glance.common.wsgi auth_headers = self.get_auth_headers(auth)
Jan 08 17:35:57 guaranine <email address hidden>[174194]: ERROR glance.common.wsgi File "/usr/local/lib/python3.8/dist-packages/keystoneauth1/session.py", line 1191, in get_auth_headers
Jan 08 17:35:57 guaranine <email address hidden>[174194]: ERROR glance.common.wsgi return auth.get_headers(self, **kwargs)
Jan 08 17:35:57 guaranine <email address hidden>[174194]: ERROR glance.common.wsgi AttributeError: 'TokenMethod' object has no attribute 'get_headers'
Jan 08 17:35:57 guaranine <email address hidden>[174194]: ERROR glance.common.wsgi

Revision history for this message
Lance Bragstad (lbragstad) wrote :

I can recreate this using the following code:

╭─ubuntu@ubuntu20 ~
╰─➤ $ cat ksa.py 1 ↵
import os
import sys

from keystoneauth1 import session
from keystoneauth1.identity import v3

token = os.environ.get('TOKEN')
if not token:
    print('No token provided.')
    sys.exit(1)

a = v3.TokenMethod(token=token)
s = session.Session(auth=a)

print(s.get('http://192.168.1.150/identity/v3/'))

╭─ubuntu@ubuntu20 ~
╰─➤ $ python3 ksa.py
Traceback (most recent call last):
  File "ksa.py", line 15, in <module>
    print(s.get('http://192.168.1.150/identity/v3/'))
  File "/home/ubuntu/keystoneauth/keystoneauth1/session.py", line 1131, in get
    return self.request(url, 'GET', **kwargs)
  File "/home/ubuntu/keystoneauth/keystoneauth1/session.py", line 780, in request
    auth_headers = self.get_auth_headers(auth)
  File "/home/ubuntu/keystoneauth/keystoneauth1/session.py", line 1191, in get_auth_headers
    return auth.get_headers(self, **kwargs)
AttributeError: 'TokenMethod' object has no attribute 'get_headers'

I'm using keystoneauth1 version 4.3.0

Revision history for this message
Lance Bragstad (lbragstad) wrote :

One possible workaround is to use the Token plugin directly instead of the method:

╭─ubuntu@ubuntu20 ~
╰─➤ $ cat ksa.py import os
import sys

from keystoneauth1 import session
from keystoneauth1.identity import v3

token = os.environ.get('TOKEN')
if not token:
    print('No token provided.')
    sys.exit(1)

a = v3.Token('http://192.168.1.150/identity/', token)
s = session.Session(auth=a)

print(s.get('http://192.168.1.150/identity/v3/'))

╭─ubuntu@ubuntu20 ~
╰─➤ $ python3 ksa.py
<Response [200]>

Revision history for this message
Lance Bragstad (lbragstad) wrote :

Actually - I don't think this is supposed to work this way.

The AuthMethod implementation doesn't inherit any of the plugin interfaces, which is why this breaks. Instead, I think the workaround in comment #2 is how this is supposed to work.

Changed in keystoneauth:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.