Merge ~rodrigo-barbieri2010/ubuntu/+source/horizon:lp1827120_wallaby into ~ubuntu-openstack-dev/ubuntu/+source/horizon:stable/wallaby

Proposed by Rodrigo Barbieri
Status: Merged
Merged at revision: 9cf115ef338359e8af3b92eb68b1a86ec850fd08
Proposed branch: ~rodrigo-barbieri2010/ubuntu/+source/horizon:lp1827120_wallaby
Merge into: ~ubuntu-openstack-dev/ubuntu/+source/horizon:stable/wallaby
Diff against target: 155 lines (+133/-0)
3 files modified
debian/changelog (+7/-0)
debian/patches/lp1827120.patch (+125/-0)
debian/patches/series (+1/-0)
Reviewer Review Type Date Requested Status
Ubuntu OpenStack uploaders Pending
Review via email: mp+434097@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/changelog b/debian/changelog
2index af4151a..c0f05a0 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,3 +1,10 @@
6+horizon (4:19.3.0-0ubuntu2~cloud0) focal-wallaby; urgency=medium
7+
8+ * d/p/lp1827120.patch: Fix missing project_id in application credential
9+ create when user has both project+domain admin role (LP#1827120).
10+
11+ -- Rodrigo Barbieri <rodrigo.barbieri@canonical.com> Mon, 05 Dec 2022 14:24:41 +0000
12+
13 horizon (4:19.3.0-0ubuntu1~cloud0) focal-wallaby; urgency=medium
14
15 * New stable point release for OpenStack Wallaby (LP: #1985087).
16diff --git a/debian/patches/lp1827120.patch b/debian/patches/lp1827120.patch
17new file mode 100644
18index 0000000..f66cf3c
19--- /dev/null
20+++ b/debian/patches/lp1827120.patch
21@@ -0,0 +1,125 @@
22+From 2f8aaa03e8ed4c2c8e3628f1f723f304b24b1f82 Mon Sep 17 00:00:00 2001
23+From: Rodrigo Barbieri <rodrigo.barbieri2010@gmail.com>
24+Date: Wed, 7 Sep 2022 10:52:48 -0300
25+Subject: [PATCH] Fix app cred create without project_id for domain admins
26+
27+Users with domain admin role that are not cloud admins are
28+not able to get scoped context and create an application
29+credential with project_id, so this change forces the
30+scoped context in that particular case.
31+
32+Closes-bug: #1827120
33+Change-Id: I076a97a6f943ab74a2db8bc5179a7db194009db4
34+(cherry picked from commit 6eeaf9852478e25ff77c21117664ac126c5357a4)
35+(cherry picked from commit 778a52e66aeab883b31db729e04944eeecfec6a2)
36+(cherry picked from commit 13e821a079134a458b24593d9593e0e5318e6cd6)
37+(cherry picked from commit 084ee8aaea703d99720c0cdc2751b6479dab3b2f)
38+---
39+ openstack_dashboard/api/keystone.py | 17 +++++--
40+ .../test/unit/api/test_keystone.py | 44 +++++++++++++++++++
41+ 2 files changed, 58 insertions(+), 3 deletions(-)
42+
43+diff --git a/openstack_dashboard/api/keystone.py b/openstack_dashboard/api/keystone.py
44+index 6195ee79c..3d21c808c 100644
45+--- a/openstack_dashboard/api/keystone.py
46++++ b/openstack_dashboard/api/keystone.py
47+@@ -120,7 +120,7 @@ def _get_endpoint_url(request, endpoint_type, catalog=None):
48+ return url
49+
50+
51+-def keystoneclient(request, admin=False):
52++def keystoneclient(request, admin=False, force_scoped=False):
53+ """Returns a client connected to the Keystone backend.
54+
55+ Several forms of authentication are supported:
56+@@ -152,7 +152,8 @@ def keystoneclient(request, admin=False):
57+
58+ # If user is Cloud Admin, Domain Admin or Mixed Domain Admin and there
59+ # is no domain context specified, use domain scoped token
60+- if is_domain_admin(request) and not is_domain_context_specified:
61++ if (is_domain_admin(request) and not is_domain_context_specified and
62++ not force_scoped):
63+ domain_token = request.session.get('domain_token')
64+ if domain_token:
65+ token_id = getattr(domain_token, 'auth_token', None)
66+@@ -998,7 +999,17 @@ def application_credential_create(request, name, secret=None,
67+ roles=None, unrestricted=False,
68+ access_rules=None):
69+ user = request.user.id
70+- manager = keystoneclient(request).application_credentials
71++ # NOTE(ganso): users with domain admin role that are not cloud admins are
72++ # not able to get scoped context and create an application credential with
73++ # project_id, so only in this particular case we force a scoped context
74++ force_scoped = False
75++ if (request.user.project_id and request.session.get("domain_token") and
76++ not policy.check(
77++ (("identity", "identity:update_domain"),), request)):
78++ force_scoped = True
79++
80++ manager = keystoneclient(
81++ request, force_scoped=force_scoped).application_credentials
82+ try:
83+ return manager.create(name=name, user=user, secret=secret,
84+ description=description, expires_at=expires_at,
85+diff --git a/openstack_dashboard/test/unit/api/test_keystone.py b/openstack_dashboard/test/unit/api/test_keystone.py
86+index 82221b757..3b682815e 100644
87+--- a/openstack_dashboard/test/unit/api/test_keystone.py
88++++ b/openstack_dashboard/test/unit/api/test_keystone.py
89+@@ -20,6 +20,7 @@ from unittest import mock
90+
91+ from django.test.utils import override_settings
92+ from openstack_dashboard import api
93++from openstack_dashboard import policy
94+ from openstack_dashboard.test import helpers as test
95+
96+
97+@@ -142,3 +143,46 @@ class APIVersionTests(test.APIMockTestCase):
98+ keystoneclient.session.get_endpoint_data.assert_called_once_with(
99+ service_type='identity')
100+ self.assertEqual((3, 10), api_version)
101++
102++
103++class ApplicationCredentialsAPITests(test.APIMockTestCase):
104++
105++ @mock.patch.object(policy, 'check')
106++ @mock.patch.object(api.keystone, 'keystoneclient')
107++ def test_application_credential_create_domain_token_removed(
108++ self, mock_keystoneclient, mock_policy):
109++ self.request.session['domain_token'] = 'some_token'
110++ mock_policy.return_value = False
111++ api.keystone.application_credential_create(self.request, None)
112++ mock_keystoneclient.assert_called_once_with(
113++ self.request, force_scoped=True)
114++
115++ @mock.patch.object(policy, 'check')
116++ @mock.patch.object(api.keystone, 'keystoneclient')
117++ def test_application_credential_create_domain_token_not_removed_policy_true(
118++ self, mock_keystoneclient, mock_policy):
119++ self.request.session['domain_token'] = 'some_token'
120++ mock_policy.return_value = True
121++ api.keystone.application_credential_create(self.request, None)
122++ mock_keystoneclient.assert_called_once_with(
123++ self.request, force_scoped=False)
124++
125++ @mock.patch.object(policy, 'check')
126++ @mock.patch.object(api.keystone, 'keystoneclient')
127++ def test_application_credential_create_domain_token_not_removed_no_token(
128++ self, mock_keystoneclient, mock_policy):
129++ mock_policy.return_value = True
130++ api.keystone.application_credential_create(self.request, None)
131++ mock_keystoneclient.assert_called_once_with(
132++ self.request, force_scoped=False)
133++
134++ @mock.patch.object(policy, 'check')
135++ @mock.patch.object(api.keystone, 'keystoneclient')
136++ def test_application_credential_create_domain_token_not_removed_no_project(
137++ self, mock_keystoneclient, mock_policy):
138++ self.request.session['domain_token'] = 'some_token'
139++ mock_policy.return_value = True
140++ self.request.user.project_id = None
141++ api.keystone.application_credential_create(self.request, None)
142++ mock_keystoneclient.assert_called_once_with(
143++ self.request, force_scoped=False)
144+--
145+2.34.1
146+
147diff --git a/debian/patches/series b/debian/patches/series
148index 88198a3..f7cdd35 100644
149--- a/debian/patches/series
150+++ b/debian/patches/series
151@@ -2,3 +2,4 @@ fix-horizon-test-settings.patch
152 fix-dashboard-manage.patch
153 ubuntu_settings.patch
154 embedded-xstatic.patch
155+lp1827120.patch

Subscribers

People subscribed via source and target branches