Skip to content

Commit 02447bf

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Ensure OAuth1 authorized roles are respected" into stable/stein
2 parents af99274 + 330911c commit 02447bf

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

keystone/models/token_model.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"""Unified in-memory token model."""
1414

1515
from oslo_log import log
16+
from oslo_serialization import jsonutils
1617
from oslo_serialization import msgpackutils
1718
from oslo_utils import reflection
1819
import six
@@ -325,6 +326,21 @@ def _get_trust_roles(self):
325326

326327
return roles
327328

329+
def _get_oauth_roles(self):
330+
roles = []
331+
access_token_roles = self.access_token['role_ids']
332+
access_token_roles = [
333+
{'role_id': r} for r in jsonutils.loads(access_token_roles)]
334+
effective_access_token_roles = (
335+
PROVIDERS.assignment_api.add_implied_roles(access_token_roles)
336+
)
337+
user_roles = [r['id'] for r in self._get_project_roles()]
338+
for role in effective_access_token_roles:
339+
if role['role_id'] in user_roles:
340+
role = PROVIDERS.role_api.get_role(role['role_id'])
341+
roles.append({'id': role['id'], 'name': role['name']})
342+
return roles
343+
328344
def _get_federated_roles(self):
329345
roles = []
330346
group_ids = [group['id'] for group in self.federated_groups]
@@ -428,6 +444,8 @@ def roles(self):
428444
roles = self._get_system_roles()
429445
elif self.trust_scoped:
430446
roles = self._get_trust_roles()
447+
elif self.oauth_scoped:
448+
roles = self._get_oauth_roles()
431449
elif self.is_federated and not self.unscoped:
432450
roles = self._get_federated_roles()
433451
elif self.domain_scoped:

keystone/tests/unit/test_v3_oauth1.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,19 @@ def test_oauth_flow(self):
308308
self.keystone_token = content.result['token']
309309
self.assertIsNotNone(self.keystone_token_id)
310310

311+
# add a new role assignment to ensure it is ignored in the access token
312+
new_role = {'id': uuid.uuid4().hex, 'name': uuid.uuid4().hex}
313+
PROVIDERS.role_api.create_role(new_role['id'], new_role)
314+
PROVIDERS.assignment_api.add_role_to_user_and_project(
315+
user_id=self.user_id,
316+
project_id=self.project_id,
317+
role_id=new_role['id'])
318+
content = self.post(url, headers=headers, body=body)
319+
token = content.result['token']
320+
token_roles = [r['id'] for r in token['roles']]
321+
self.assertIn(self.role_id, token_roles)
322+
self.assertNotIn(new_role['id'], token_roles)
323+
311324

312325
class AccessTokenCRUDTests(OAuthFlowTests):
313326
def test_delete_access_token_dne(self):
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
security:
3+
- |
4+
[`bug 1873290 <https://bugs.launchpad.net/keystone/+bug/1873290>`_]
5+
[`bug 1872735 <https://bugs.launchpad.net/keystone/+bug/1872735>`_]
6+
Fixed the token model to respect the roles authorized OAuth1 access tokens.
7+
Previously, the list of roles authorized for an OAuth1 access token were
8+
ignored, so when an access token was used to request a keystone token, the
9+
keystone token would contain every role assignment the creator had for the
10+
project. This also fixed EC2 credentials to respect those roles as well.
11+
fixes:
12+
- |
13+
[`bug 1873290 <https://bugs.launchpad.net/keystone/+bug/1873290>`_]
14+
[`bug 1872735 <https://bugs.launchpad.net/keystone/+bug/1872735>`_]
15+
Fixed the token model to respect the roles authorized OAuth1 access tokens.
16+
Previously, the list of roles authorized for an OAuth1 access token were
17+
ignored, so when an access token was used to request a keystone token, the
18+
keystone token would contain every role assignment the creator had for the
19+
project. This also fixed EC2 credentials to respect those roles as well.

0 commit comments

Comments
 (0)