Browse Source

Inject /v3 in token path for v3 plugins

Without this, it's possible to get HTTP 404 errors from keystone if
OS_AUTH_URL isn't versioned (e.g., https://keystone.example.com/ instead
of https://keystone.example.com/v3), even if OS_IDENTITY_API is set to
3.

This commit works around this issue by checking the AUTH_URL before
building the token_url and appending '/v3' to the URL before sending the
request.

Closes-Bug: 1876317

Change-Id: Ic75f0c9b36022b884105b87bfe05f4f8292d53b2
(cherry picked from commit ad46262148e7b099e6c7239887e20ade5b8e6ac8)
(cherry picked from commit 3ba2a3acf2a897de046873f3585463638e3567f6)
tags/3.17.3^0
Lance Bragstad 3 months ago
committed by Raildo Mascena
parent
commit
7d7b9564ba
3 changed files with 35 additions and 1 deletions
  1. +5
    -1
      keystoneauth1/identity/v3/base.py
  2. +24
    -0
      keystoneauth1/tests/unit/identity/test_identity_v3.py
  3. +6
    -0
      releasenotes/notes/bug-1876317-1db97d1b12a3e4b4.yaml

+ 5
- 1
keystoneauth1/identity/v3/base.py View File

@@ -173,9 +173,13 @@ class Auth(BaseAuth):
if self.system_scope == 'all':
body['auth']['scope'] = {'system': {'all': True}}

token_url = self.token_url

if not self.auth_url.rstrip('/').endswith('v3'):
token_url = '%s/v3/auth/tokens' % self.auth_url.rstrip('/')

# NOTE(jamielennox): we add nocatalog here rather than in token_url
# directly as some federation plugins require the base token_url
token_url = self.token_url
if not self.include_catalog:
token_url += '?nocatalog'



+ 24
- 0
keystoneauth1/tests/unit/identity/test_identity_v3.py View File

@@ -798,3 +798,27 @@ class V3IdentityPlugin(utils.TestCase):
self.assertRequestHeaderEqual("Content-Type", "application/json")
self.assertRequestHeaderEqual("Accept", "application/json")
self.assertEqual(s.auth.auth_ref.auth_token, self.TEST_TOKEN)

def test_authenticate_with_unversioned_endpoint(self):
self.stub_auth(json=self.TEST_RESPONSE_DICT)
# We use the root url here because it doesn't reference the API version
# (e.g., '/v3'). We want to make sure the authentication plugin handles
# this and appends /v3 if it's not present.
a = v3.Password(self.TEST_ROOT_URL,
username=self.TEST_USER,
password=self.TEST_PASS)
self.assertFalse(a.has_scope_parameters)
s = session.Session(auth=a)

self.assertEqual({'X-Auth-Token': self.TEST_TOKEN},
s.get_auth_headers())

req = {'auth': {'identity':
{'methods': ['password'],
'password': {'user': {'name': self.TEST_USER,
'password': self.TEST_PASS}}}}}

self.assertRequestBodyIs(json=req)
self.assertRequestHeaderEqual('Content-Type', 'application/json')
self.assertRequestHeaderEqual('Accept', 'application/json')
self.assertEqual(s.auth.auth_ref.auth_token, self.TEST_TOKEN)

+ 6
- 0
releasenotes/notes/bug-1876317-1db97d1b12a3e4b4.yaml View File

@@ -0,0 +1,6 @@
---
fixes:
- |
[`bug 1876317 <https://bugs.launchpad.net/keystoneauth/+bug/1876317>`_]
The v3 authentication plugins now attempt to add /v3 to the token path if
it's not present on the authentication URL.

Loading…
Cancel
Save