Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration for use of service tokens #740

Merged
merged 7 commits into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions charmhelpers/contrib/openstack/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ def _resolve(key):
int_host = format_ipv6_addr(int_host) or int_host
svc_protocol = _resolve('service_protocol') or 'http'
auth_protocol = _resolve('auth_protocol') or 'http'
admin_role = _resolve('admin_role') or 'Admin'
wolsen marked this conversation as resolved.
Show resolved Hide resolved
int_protocol = _resolve('internal_protocol') or 'http'
api_version = _resolve('api_version') or '2.0'
ctxt.update({'service_port': _resolve('service_port'),
Expand All @@ -511,6 +512,7 @@ def _resolve(key):
'admin_tenant_name': _resolve('service_tenant'),
'admin_user': _resolve('service_username'),
'admin_password': _resolve('service_password'),
'admin_role': admin_role,
'service_protocol': svc_protocol,
'auth_protocol': auth_protocol,
'internal_protocol': int_protocol,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ signing_dir = {{ signing_dir }}
{% if service_type -%}
service_type = {{ service_type }}
{% endif -%}
service_token_roles = {{ admin_role }}
service_token_roles_required = True
{% endif -%}
11 changes: 11 additions & 0 deletions charmhelpers/contrib/openstack/templates/section-service-user
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% if auth_host -%}
[service_user]
send_service_user_token = true
auth_type = password
auth_url = {{ auth_protocol }}://{{ auth_host }}:{{ auth_port }}
project_domain_id = default
user_domain_id = default
project_name = {{ admin_tenant_name }}
username = {{ admin_user }}
password = {{ admin_password }}
{% endif -%}
45 changes: 45 additions & 0 deletions tests/contrib/openstack/test_os_contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ def relation_units(self, relation_id):
}
IDENTITY_SERVICE_RELATION_VERSIONED.update(IDENTITY_SERVICE_RELATION_HTTPS)

IDENTITY_SERVICE_RELATION_ADMIN_ROLE = {
'admin_role': 'Role',
}
IDENTITY_SERVICE_RELATION_ADMIN_ROLE.update(IDENTITY_SERVICE_RELATION_HTTPS)

IDENTITY_CREDENTIALS_RELATION_VERSIONED = {
'api_version': '3',
'service_tenant_id': 'svc-proj-id',
Expand Down Expand Up @@ -1062,6 +1067,7 @@ def test_identity_service_context_with_data(self, *args):
result = identity_service()
expected = {
'admin_password': 'foo',
'admin_role': 'Admin',
'admin_tenant_name': 'admin',
'admin_tenant_id': None,
'admin_domain_id': None,
Expand Down Expand Up @@ -1118,6 +1124,7 @@ def test_identity_service_context_with_altname(self, *args):
result = identity_service()
expected = {
'admin_password': 'foo',
'admin_role': 'Admin',
'admin_tenant_name': 'admin',
'admin_tenant_id': None,
'admin_domain_id': None,
Expand Down Expand Up @@ -1149,6 +1156,7 @@ def test_identity_service_context_with_cache(self, *args):
result = identity_service()
expected = {
'admin_password': 'foo',
'admin_role': 'Admin',
'admin_tenant_name': 'admin',
'admin_tenant_id': None,
'admin_domain_id': None,
Expand Down Expand Up @@ -1179,6 +1187,7 @@ def test_identity_service_context_with_data_http(self, *args):
result = identity_service()
expected = {
'admin_password': 'foo',
'admin_role': 'Admin',
'admin_tenant_name': 'admin',
'admin_tenant_id': '123456',
'admin_domain_id': None,
Expand Down Expand Up @@ -1208,6 +1217,7 @@ def test_identity_service_context_with_data_https(self, *args):
result = identity_service()
expected = {
'admin_password': 'foo',
'admin_role': 'Admin',
'admin_tenant_name': 'admin',
'admin_tenant_id': None,
'admin_domain_id': None,
Expand Down Expand Up @@ -1238,6 +1248,7 @@ def test_identity_service_app_context_with_data_http(self, *args):
result = identity_service()
expected = {
'admin_password': 'foo',
'admin_role': 'Admin',
'admin_domain_name': 'admin_domain',
'admin_tenant_name': 'services',
'admin_tenant_id': 'svc-proj-id',
Expand Down Expand Up @@ -1279,6 +1290,7 @@ def test_identity_service_app_context_with_app_data_nones(self, *args):
result = identity_service()
expected = {
'admin_password': 'foo',
'admin_role': 'Admin',
'admin_domain_name': 'admin_domain',
'admin_tenant_name': 'services',
'admin_tenant_id': 'svc-proj-id',
Expand Down Expand Up @@ -1314,6 +1326,7 @@ def test_identity_service_context_with_data_versioned(self, *args):
result = identity_service()
expected = {
'admin_password': 'foo',
'admin_role': 'Admin',
'admin_domain_name': 'admin_domain',
'admin_tenant_name': 'admin',
'admin_tenant_id': 'svc-proj-id',
Expand All @@ -1336,6 +1349,37 @@ def test_identity_service_context_with_data_versioned(self, *args):
result.pop('keystone_authtoken')
self.assertEquals(result, expected)

@patch.object(context, 'filter_installed_packages', return_value=[])
@patch.object(context, 'os_release', return_value='rocky')
def test_identity_service_context_with_admin_role(self, *args):
'''Test shared-db context with admin role supplied from keystone'''
relation = FakeRelation(
relation_data=IDENTITY_SERVICE_RELATION_ADMIN_ROLE)
self.relation_get.side_effect = relation.get
identity_service = context.IdentityServiceContext()
result = identity_service()
expected = {
'admin_password': 'foo',
'admin_role': 'Role',
'admin_tenant_name': 'admin',
'admin_tenant_id': None,
'admin_domain_id': None,
'admin_user': 'adam',
'auth_host': 'keystone-host.local',
'auth_port': '35357',
'auth_protocol': 'https',
'service_host': 'keystonehost.local',
'service_port': '5000',
'service_protocol': 'https',
'service_type': 'volume',
'internal_host': 'keystone-internal.local',
'internal_port': '5000',
'internal_protocol': 'https',
'api_version': '2.0',
}
result.pop('keystone_authtoken')
self.assertEquals(result, expected)

def test_identity_credentials_context_with_data_versioned(self):
'''Test identity-credentials context with api version supplied from keystone'''
relation = FakeRelation(
Expand Down Expand Up @@ -1372,6 +1416,7 @@ def test_identity_service_context_with_ipv6(self, format_ipv6_addr, *args):
result = identity_service()
expected = {
'admin_password': 'foo',
'admin_role': 'Admin',
'admin_tenant_name': 'admin',
'admin_tenant_id': '123456',
'admin_domain_id': None,
Expand Down