Skip to content

Commit

Permalink
fix: do not assume admin privileges on keystone
Browse files Browse the repository at this point in the history
Avoid issues when running cASO with a low privileges account that cannot
list all projects and scope the tokens to the projects that are to be
accounted. This allows to run cASO and generate records for non-admin
users.

Closes #124
  • Loading branch information
enolfc authored and alvarolopez committed Sep 27, 2024
1 parent 41c0821 commit 0aba824
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
28 changes: 24 additions & 4 deletions caso/extract/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
from caso import keystone_client
from caso import loading

from keystoneauth1.exceptions.catalog import EmptyCatalog
from keystoneauth1.exceptions.http import Forbidden

cli_opts = [
cfg.ListOpt(
"projects",
Expand Down Expand Up @@ -119,12 +122,20 @@ def __init__(self):
def projects(self):
"""Get list of configured projects."""
projects = CONF.projects
aux = [i.id for i in self.keystone.projects.list(tags=CONF.caso_tag)]
aux = []
try:
aux = [i.id for i in self.keystone.projects.list(tags=CONF.caso_tag)]
except Forbidden as e:
LOG.warning(f"Unable to get projects from Keystone, ignoring - {e}")

Check warning on line 129 in caso/extract/manager.py

View check run for this annotation

Codecov / codecov/patch

caso/extract/manager.py#L128-L129

Added lines #L128 - L129 were not covered by tests
return set(projects + aux)

def _get_keystone_client(self):
def _get_keystone_client(self, project=None, system_scope="all"):
"""Get a Keystone Client to get the projects that we will use."""
client = keystone_client.get_client(CONF, system_scope="all")
if project:
system_scope = None
client = keystone_client.get_client(

Check warning on line 136 in caso/extract/manager.py

View check run for this annotation

Codecov / codecov/patch

caso/extract/manager.py#L135-L136

Added lines #L135 - L136 were not covered by tests
CONF, project=project, system_scope=system_scope
)
return client

def get_lastrun(self, project):
Expand Down Expand Up @@ -197,7 +208,16 @@ def voms_map(self):

def get_project_vo(self, project_id):
"""Get the VO where the project should be mapped."""
project = self.keystone.projects.get(project_id)
try:
project = self.keystone.projects.get(project_id)
except (EmptyCatalog, Forbidden):

Check warning on line 213 in caso/extract/manager.py

View check run for this annotation

Codecov / codecov/patch

caso/extract/manager.py#L213

Added line #L213 was not covered by tests
# we may need scoping here, retrying
LOG.warning(

Check warning on line 215 in caso/extract/manager.py

View check run for this annotation

Codecov / codecov/patch

caso/extract/manager.py#L215

Added line #L215 was not covered by tests
f"Scoping the keystone client to the current project {project_id}"
)
self.keystone = self._get_keystone_client(project_id)
project = self.keystone.projects.get(project_id)

Check warning on line 219 in caso/extract/manager.py

View check run for this annotation

Codecov / codecov/patch

caso/extract/manager.py#L218-L219

Added lines #L218 - L219 were not covered by tests

project.get()
vo = project.to_dict().get(CONF.vo_property, None)
if vo is None:
Expand Down
4 changes: 3 additions & 1 deletion caso/extract/openstack/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ def _get_keystone_session(self):

def _get_keystone_client(self):
"""Get a Keystone Client for the configured project in the object."""
client = keystone_client.get_client(CONF, system_scope="all")
client = keystone_client.get_client(

Check warning on line 95 in caso/extract/openstack/base.py

View check run for this annotation

Codecov / codecov/patch

caso/extract/openstack/base.py#L95

Added line #L95 was not covered by tests
CONF, project=self.project, system_scope="all"
)
return client

def _get_cinder_client(self):
Expand Down

0 comments on commit 0aba824

Please # to comment.